lnwallet: update to adhere to new channeldb API change
This commit modifies the lnwallet code and related tests in order to adhere to the recent field-name change to channeldb.OpenChannel. Instead of having the field ‘TheirLNID’ which is the sha256 of the node’s public key, we now instead use the public key directly in all contexts.
This commit is contained in:
parent
cb328e65c4
commit
e1d9d9c8d2
@ -229,7 +229,7 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
|
|||||||
}
|
}
|
||||||
|
|
||||||
aliceChannelState := &channeldb.OpenChannel{
|
aliceChannelState := &channeldb.OpenChannel{
|
||||||
TheirLNID: testHdSeed,
|
IdentityPub: aliceKeyPub,
|
||||||
ChanID: prevOut,
|
ChanID: prevOut,
|
||||||
OurCommitKey: aliceKeyPub,
|
OurCommitKey: aliceKeyPub,
|
||||||
TheirCommitKey: bobKeyPub,
|
TheirCommitKey: bobKeyPub,
|
||||||
@ -249,7 +249,7 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
|
|||||||
Db: dbAlice,
|
Db: dbAlice,
|
||||||
}
|
}
|
||||||
bobChannelState := &channeldb.OpenChannel{
|
bobChannelState := &channeldb.OpenChannel{
|
||||||
TheirLNID: testHdSeed,
|
IdentityPub: bobKeyPub,
|
||||||
ChanID: prevOut,
|
ChanID: prevOut,
|
||||||
OurCommitKey: bobKeyPub,
|
OurCommitKey: bobKeyPub,
|
||||||
TheirCommitKey: aliceKeyPub,
|
TheirCommitKey: aliceKeyPub,
|
||||||
@ -688,12 +688,13 @@ func TestStateUpdatePersistence(t *testing.T) {
|
|||||||
|
|
||||||
// Now fetch both of the channels created above from disk to simulate a
|
// Now fetch both of the channels created above from disk to simulate a
|
||||||
// node restart with persistence.
|
// node restart with persistence.
|
||||||
id := wire.ShaHash(testHdSeed)
|
alicePub := aliceChannel.channelState.IdentityPub
|
||||||
aliceChannels, err := aliceChannel.channelState.Db.FetchOpenChannels(&id)
|
aliceChannels, err := aliceChannel.channelState.Db.FetchOpenChannels(alicePub)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to fetch channel: %v", err)
|
t.Fatalf("unable to fetch channel: %v", err)
|
||||||
}
|
}
|
||||||
bobChannels, err := bobChannel.channelState.Db.FetchOpenChannels(&id)
|
bobPub := bobChannel.channelState.IdentityPub
|
||||||
|
bobChannels, err := bobChannel.channelState.Db.FetchOpenChannels(bobPub)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to fetch channel: %v", err)
|
t.Fatalf("unable to fetch channel: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,8 @@ var (
|
|||||||
0x6a, 0x49, 0x18, 0x83, 0x31, 0x98, 0x47, 0x53,
|
0x6a, 0x49, 0x18, 0x83, 0x31, 0x98, 0x47, 0x53,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, testPub = btcec.PrivKeyFromBytes(btcec.S256(), testHdSeed[:])
|
||||||
|
|
||||||
// The number of confirmations required to consider any created channel
|
// The number of confirmations required to consider any created channel
|
||||||
// open.
|
// open.
|
||||||
numReqConfs = uint16(1)
|
numReqConfs = uint16(1)
|
||||||
@ -101,7 +103,7 @@ type bobNode struct {
|
|||||||
deliveryAddress btcutil.Address
|
deliveryAddress btcutil.Address
|
||||||
revocation [32]byte
|
revocation [32]byte
|
||||||
delay uint32
|
delay uint32
|
||||||
id [wire.HashSize]byte
|
id *btcec.PublicKey
|
||||||
|
|
||||||
availableOutputs []*wire.TxIn
|
availableOutputs []*wire.TxIn
|
||||||
changeOutputs []*wire.TxOut
|
changeOutputs []*wire.TxOut
|
||||||
@ -241,7 +243,7 @@ func newBobNode(miner *rpctest.Harness, amt btcutil.Amount) (*bobNode, error) {
|
|||||||
id[0] = 0xff
|
id[0] = 0xff
|
||||||
|
|
||||||
return &bobNode{
|
return &bobNode{
|
||||||
id: id,
|
id: pubKey,
|
||||||
privKey: privKey,
|
privKey: privKey,
|
||||||
channelKey: pubKey,
|
channelKey: pubKey,
|
||||||
deliveryAddress: bobAddr,
|
deliveryAddress: bobAddr,
|
||||||
@ -457,8 +459,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness, wallet *lnwallet
|
|||||||
|
|
||||||
// The resulting active channel state should have been persisted to the DB.
|
// The resulting active channel state should have been persisted to the DB.
|
||||||
fundingSha := fundingTx.TxSha()
|
fundingSha := fundingTx.TxSha()
|
||||||
nodeID := wire.ShaHash(bobNode.id)
|
channels, err := wallet.ChannelDB.FetchOpenChannels(bobNode.id)
|
||||||
channels, err := wallet.ChannelDB.FetchOpenChannels(&nodeID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to retrieve channel from DB: %v", err)
|
t.Fatalf("unable to retrieve channel from DB: %v", err)
|
||||||
}
|
}
|
||||||
@ -513,7 +514,7 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
|
|||||||
// Create a single channel asking for 16 BTC total.
|
// Create a single channel asking for 16 BTC total.
|
||||||
fundingAmount := btcutil.Amount(8 * 1e8)
|
fundingAmount := btcutil.Amount(8 * 1e8)
|
||||||
_, err := wallet.InitChannelReservation(fundingAmount, fundingAmount,
|
_, err := wallet.InitChannelReservation(fundingAmount, fundingAmount,
|
||||||
testHdSeed, numReqConfs, 4)
|
testPub, numReqConfs, 4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to initialize funding reservation 1: %v", err)
|
t.Fatalf("unable to initialize funding reservation 1: %v", err)
|
||||||
}
|
}
|
||||||
@ -523,7 +524,7 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
|
|||||||
// that aren't locked, so this should fail.
|
// that aren't locked, so this should fail.
|
||||||
amt := btcutil.Amount(900 * 1e8)
|
amt := btcutil.Amount(900 * 1e8)
|
||||||
failedReservation, err := wallet.InitChannelReservation(amt, amt,
|
failedReservation, err := wallet.InitChannelReservation(amt, amt,
|
||||||
testHdSeed, numReqConfs, 4)
|
testPub, numReqConfs, 4)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("not error returned, should fail on coin selection")
|
t.Fatalf("not error returned, should fail on coin selection")
|
||||||
}
|
}
|
||||||
@ -543,14 +544,14 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
|
|||||||
// Create a reservation for 44 BTC.
|
// Create a reservation for 44 BTC.
|
||||||
fundingAmount := btcutil.Amount(44 * 1e8)
|
fundingAmount := btcutil.Amount(44 * 1e8)
|
||||||
chanReservation, err := wallet.InitChannelReservation(fundingAmount,
|
chanReservation, err := wallet.InitChannelReservation(fundingAmount,
|
||||||
fundingAmount, testHdSeed, numReqConfs, 4)
|
fundingAmount, testPub, numReqConfs, 4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to initialize funding reservation: %v", err)
|
t.Fatalf("unable to initialize funding reservation: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to create another channel with 44 BTC, this should fail.
|
// Attempt to create another channel with 44 BTC, this should fail.
|
||||||
_, err = wallet.InitChannelReservation(fundingAmount,
|
_, err = wallet.InitChannelReservation(fundingAmount,
|
||||||
fundingAmount, testHdSeed, numReqConfs, 4)
|
fundingAmount, testPub, numReqConfs, 4)
|
||||||
if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok {
|
if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok {
|
||||||
t.Fatalf("coin selection succeded should have insufficient funds: %v",
|
t.Fatalf("coin selection succeded should have insufficient funds: %v",
|
||||||
err)
|
err)
|
||||||
@ -580,7 +581,7 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
|
|||||||
|
|
||||||
// Request to fund a new channel should now succeeed.
|
// Request to fund a new channel should now succeeed.
|
||||||
_, err = wallet.InitChannelReservation(fundingAmount, fundingAmount,
|
_, err = wallet.InitChannelReservation(fundingAmount, fundingAmount,
|
||||||
testHdSeed, numReqConfs, 4)
|
testPub, numReqConfs, 4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to initialize funding reservation: %v", err)
|
t.Fatalf("unable to initialize funding reservation: %v", err)
|
||||||
}
|
}
|
||||||
@ -720,8 +721,7 @@ func testSingleFunderReservationWorkflowInitiator(miner *rpctest.Harness,
|
|||||||
// TODO(roasbeef): de-duplicate
|
// TODO(roasbeef): de-duplicate
|
||||||
fundingTx := chanReservation.FinalFundingTx()
|
fundingTx := chanReservation.FinalFundingTx()
|
||||||
fundingSha := fundingTx.TxSha()
|
fundingSha := fundingTx.TxSha()
|
||||||
nodeID := wire.ShaHash(bobNode.id)
|
channels, err := lnwallet.ChannelDB.FetchOpenChannels(bobNode.id)
|
||||||
channels, err := lnwallet.ChannelDB.FetchOpenChannels(&nodeID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to retrieve channel from DB: %v", err)
|
t.Fatalf("unable to retrieve channel from DB: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -92,8 +92,7 @@ type initFundingReserveMsg struct {
|
|||||||
minFeeRate btcutil.Amount
|
minFeeRate btcutil.Amount
|
||||||
|
|
||||||
// The ID of the remote node we would like to open a channel with.
|
// The ID of the remote node we would like to open a channel with.
|
||||||
// TODO(roasbeef): switch to just reg pubkey?
|
nodeID *btcec.PublicKey
|
||||||
nodeID [32]byte
|
|
||||||
|
|
||||||
// The delay on the "pay-to-self" output(s) of the commitment transaction.
|
// The delay on the "pay-to-self" output(s) of the commitment transaction.
|
||||||
csvDelay uint32
|
csvDelay uint32
|
||||||
@ -473,8 +472,8 @@ out:
|
|||||||
// transaction, and that the signature we records for our version of the
|
// transaction, and that the signature we records for our version of the
|
||||||
// commitment transaction is valid.
|
// commitment transaction is valid.
|
||||||
func (l *LightningWallet) InitChannelReservation(capacity,
|
func (l *LightningWallet) InitChannelReservation(capacity,
|
||||||
ourFundAmt btcutil.Amount, theirID [32]byte, numConfs uint16,
|
ourFundAmt btcutil.Amount, theirID *btcec.PublicKey,
|
||||||
csvDelay uint32) (*ChannelReservation, error) {
|
numConfs uint16, csvDelay uint32) (*ChannelReservation, error) {
|
||||||
|
|
||||||
errChan := make(chan error, 1)
|
errChan := make(chan error, 1)
|
||||||
respChan := make(chan *ChannelReservation, 1)
|
respChan := make(chan *ChannelReservation, 1)
|
||||||
@ -512,7 +511,7 @@ func (l *LightningWallet) handleFundingReserveRequest(req *initFundingReserveMsg
|
|||||||
reservation.Lock()
|
reservation.Lock()
|
||||||
defer reservation.Unlock()
|
defer reservation.Unlock()
|
||||||
|
|
||||||
reservation.partialState.TheirLNID = req.nodeID
|
reservation.partialState.IdentityPub = req.nodeID
|
||||||
ourContribution := reservation.ourContribution
|
ourContribution := reservation.ourContribution
|
||||||
ourContribution.CsvDelay = req.csvDelay
|
ourContribution.CsvDelay = req.csvDelay
|
||||||
reservation.partialState.LocalCsvDelay = req.csvDelay
|
reservation.partialState.LocalCsvDelay = req.csvDelay
|
||||||
|
Loading…
Reference in New Issue
Block a user