lnwallet+channeldb: update callers to shachain API changes
This commit is contained in:
parent
2e25787a74
commit
9adc5f6484
@ -1561,19 +1561,11 @@ func putChanPreimageState(nodeChanBucket *bolt.Bucket, channel *OpenChannel) err
|
|||||||
|
|
||||||
// TODO(roasbeef): shouldn't be storing on disk, should re-derive as
|
// TODO(roasbeef): shouldn't be storing on disk, should re-derive as
|
||||||
// needed
|
// needed
|
||||||
data, err := channel.RevocationProducer.ToBytes()
|
if err := channel.RevocationProducer.Encode(&b); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := wire.WriteVarBytes(&b, 0, data); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err = channel.RevocationStore.ToBytes()
|
if err := channel.RevocationStore.Encode(&b); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := wire.WriteVarBytes(&b, 0, data); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1624,20 +1616,16 @@ func fetchChanPreimageState(nodeChanBucket *bolt.Bucket, channel *OpenChannel) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO(roasbeef): should be rederiving on fly, or encrypting on disk.
|
// TODO(roasbeef): should be rederiving on fly, or encrypting on disk.
|
||||||
producerBytes, err := wire.ReadVarBytes(reader, 0, 1000, "")
|
var root [32]byte
|
||||||
if err != nil {
|
if _, err := io.ReadFull(reader, root[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
channel.RevocationProducer, err = shachain.NewRevocationProducerFromBytes(producerBytes)
|
channel.RevocationProducer, err = shachain.NewRevocationProducerFromBytes(root[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
storeBytes, err := wire.ReadVarBytes(reader, 0, 1000, "")
|
channel.RevocationStore, err = shachain.NewRevocationStoreFromBytes(reader)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
channel.RevocationStore, err = shachain.NewRevocationStoreFromBytes(storeBytes)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,10 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Simulate 1000 channel updates.
|
// Simulate 1000 channel updates.
|
||||||
producer := shachain.NewRevocationProducer((*chainhash.Hash)(&key))
|
producer, err := shachain.NewRevocationProducerFromBytes(key[:])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
store := shachain.NewRevocationStore()
|
store := shachain.NewRevocationStore()
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
preImage, err := producer.AtIndex(uint64(i))
|
preImage, err := producer.AtIndex(uint64(i))
|
||||||
@ -127,7 +130,7 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if store.Store(preImage); err != nil {
|
if store.AddNextEntry(preImage); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -318,30 +321,36 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The local and remote producers should be identical.
|
// The local and remote producers should be identical.
|
||||||
oldProducer, err := state.RevocationProducer.ToBytes()
|
var old bytes.Buffer
|
||||||
|
err = state.RevocationProducer.Encode(&old)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't convert old revocation producer to bytes: %v",
|
t.Fatalf("can't convert old revocation producer to bytes: %v",
|
||||||
err)
|
err)
|
||||||
}
|
}
|
||||||
|
|
||||||
newProducer, err := newState.RevocationProducer.ToBytes()
|
var new bytes.Buffer
|
||||||
|
err = newState.RevocationProducer.Encode(&new)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't convert new revocation producer to bytes: %v",
|
t.Fatalf("can't convert new revocation producer to bytes: %v",
|
||||||
err)
|
err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(oldProducer, newProducer) {
|
if !bytes.Equal(old.Bytes(), new.Bytes()) {
|
||||||
t.Fatal("local producer don't match")
|
t.Fatal("local producer don't match")
|
||||||
}
|
}
|
||||||
oldStore, err := state.RevocationStore.ToBytes()
|
|
||||||
|
old.Reset()
|
||||||
|
new.Reset()
|
||||||
|
|
||||||
|
err = state.RevocationStore.Encode(&old)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to serialize old remote store: %v", err)
|
t.Fatalf("unable to serialize old remote store: %v", err)
|
||||||
}
|
}
|
||||||
newStore, err := newState.RevocationStore.ToBytes()
|
err = newState.RevocationStore.Encode(&new)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to serialize new remote store: %v", err)
|
t.Fatalf("unable to serialize new remote store: %v", err)
|
||||||
}
|
}
|
||||||
if !bytes.Equal(oldStore, newStore) {
|
if !bytes.Equal(old.Bytes(), new.Bytes()) {
|
||||||
t.Fatal("remote store don't match")
|
t.Fatal("remote store don't match")
|
||||||
}
|
}
|
||||||
if !newState.TheirCurrentRevocation.IsEqual(state.TheirCurrentRevocation) {
|
if !newState.TheirCurrentRevocation.IsEqual(state.TheirCurrentRevocation) {
|
||||||
|
@ -1658,7 +1658,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) ([]*P
|
|||||||
// Ensure that the new pre-image can be placed in preimage store.
|
// Ensure that the new pre-image can be placed in preimage store.
|
||||||
// TODO(rosbeef): abstract into func
|
// TODO(rosbeef): abstract into func
|
||||||
store := lc.channelState.RevocationStore
|
store := lc.channelState.RevocationStore
|
||||||
if err := store.Store(&pendingRevocation); err != nil {
|
if err := store.AddNextEntry(&pendingRevocation); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
|
|||||||
fundingTxIn := wire.NewTxIn(prevOut, nil, nil)
|
fundingTxIn := wire.NewTxIn(prevOut, nil, nil)
|
||||||
|
|
||||||
bobRoot := deriveRevocationRoot(bobKeyPriv, bobKeyPub, aliceKeyPub)
|
bobRoot := deriveRevocationRoot(bobKeyPriv, bobKeyPub, aliceKeyPub)
|
||||||
bobPreimageProducer := shachain.NewRevocationProducer(bobRoot)
|
bobPreimageProducer := shachain.NewRevocationProducer(*bobRoot)
|
||||||
bobFirstRevoke, err := bobPreimageProducer.AtIndex(0)
|
bobFirstRevoke, err := bobPreimageProducer.AtIndex(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
@ -211,7 +211,7 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
|
|||||||
bobRevokeKey := DeriveRevocationPubkey(aliceKeyPub, bobFirstRevoke[:])
|
bobRevokeKey := DeriveRevocationPubkey(aliceKeyPub, bobFirstRevoke[:])
|
||||||
|
|
||||||
aliceRoot := deriveRevocationRoot(aliceKeyPriv, aliceKeyPub, bobKeyPub)
|
aliceRoot := deriveRevocationRoot(aliceKeyPriv, aliceKeyPub, bobKeyPub)
|
||||||
alicePreimageProducer := shachain.NewRevocationProducer(aliceRoot)
|
alicePreimageProducer := shachain.NewRevocationProducer(*aliceRoot)
|
||||||
aliceFirstRevoke, err := alicePreimageProducer.AtIndex(0)
|
aliceFirstRevoke, err := alicePreimageProducer.AtIndex(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
|
@ -762,7 +762,7 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
|
|||||||
// key for the first version of our commitment transaction. To do so,
|
// key for the first version of our commitment transaction. To do so,
|
||||||
// we'll first create our root, then produce the first pre-image.
|
// we'll first create our root, then produce the first pre-image.
|
||||||
root := deriveRevocationRoot(masterElkremRoot, ourKey, theirKey)
|
root := deriveRevocationRoot(masterElkremRoot, ourKey, theirKey)
|
||||||
producer := shachain.NewRevocationProducer(root)
|
producer := shachain.NewRevocationProducer(*root)
|
||||||
pendingReservation.partialState.RevocationProducer = producer
|
pendingReservation.partialState.RevocationProducer = producer
|
||||||
firstPreimage, err := producer.AtIndex(0)
|
firstPreimage, err := producer.AtIndex(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -901,7 +901,7 @@ func (l *LightningWallet) handleSingleContribution(req *addSingleContributionMsg
|
|||||||
// Now that we know their commitment key, we can create the revocation
|
// Now that we know their commitment key, we can create the revocation
|
||||||
// key for our version of the initial commitment transaction.
|
// key for our version of the initial commitment transaction.
|
||||||
root := deriveRevocationRoot(masterElkremRoot, ourKey, theirKey)
|
root := deriveRevocationRoot(masterElkremRoot, ourKey, theirKey)
|
||||||
producer := shachain.NewRevocationProducer(root)
|
producer := shachain.NewRevocationProducer(*root)
|
||||||
firstPreimage, err := producer.AtIndex(0)
|
firstPreimage, err := producer.AtIndex(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
req.err <- err
|
req.err <- err
|
||||||
|
Loading…
Reference in New Issue
Block a user