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:
Olaoluwa Osuntokun 2016-10-25 16:40:47 -07:00
parent cb328e65c4
commit e1d9d9c8d2
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
4 changed files with 28 additions and 28 deletions

View File

@ -386,8 +386,8 @@ type LightningChannel struct {
RemoteDeliveryScript []byte
FundingWitnessScript []byte
fundingTxIn *wire.TxIn
fundingP2WSH []byte
fundingTxIn *wire.TxIn
fundingP2WSH []byte
// ForceCloseSignal is a channel that is closed to indicate that a
// local system has initiated a force close by broadcasting the current
@ -432,7 +432,7 @@ func NewLightningChannel(signer Signer, bio BlockChainIO,
Capacity: state.Capacity,
LocalDeliveryScript: state.OurDeliveryScript,
RemoteDeliveryScript: state.TheirDeliveryScript,
FundingWitnessScript: state.FundingWitnessScript,
FundingWitnessScript: state.FundingWitnessScript,
ForceCloseSignal: make(chan struct{}),
UnilateralCloseSignal: make(chan struct{}),
}
@ -467,7 +467,7 @@ func NewLightningChannel(signer Signer, bio BlockChainIO,
lc.fundingTxIn = wire.NewTxIn(state.FundingOutpoint, nil, nil)
lc.fundingP2WSH = fundingPkScript
lc.signDesc = &SignDescriptor{
PubKey: lc.channelState.OurMultiSigKey,
PubKey: lc.channelState.OurMultiSigKey,
WitnessScript: lc.channelState.FundingWitnessScript,
Output: &wire.TxOut{
PkScript: lc.fundingP2WSH,
@ -1528,7 +1528,7 @@ func (lc *LightningChannel) ForceClose() (*ForceCloseSummary, error) {
// needs to sweep this output. The hash cache, and input index are not
// set as the caller will decide these values once sweeping the output.
selfSignDesc := &SignDescriptor{
PubKey: selfKey,
PubKey: selfKey,
WitnessScript: selfScript,
Output: &wire.TxOut{
PkScript: delayScript,

View File

@ -229,7 +229,7 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
}
aliceChannelState := &channeldb.OpenChannel{
TheirLNID: testHdSeed,
IdentityPub: aliceKeyPub,
ChanID: prevOut,
OurCommitKey: aliceKeyPub,
TheirCommitKey: bobKeyPub,
@ -240,7 +240,7 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
FundingOutpoint: prevOut,
OurMultiSigKey: aliceKeyPub,
TheirMultiSigKey: bobKeyPub,
FundingWitnessScript: witnessScript,
FundingWitnessScript: witnessScript,
LocalCsvDelay: csvTimeoutAlice,
RemoteCsvDelay: csvTimeoutBob,
TheirCurrentRevocation: bobRevokeKey,
@ -249,7 +249,7 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
Db: dbAlice,
}
bobChannelState := &channeldb.OpenChannel{
TheirLNID: testHdSeed,
IdentityPub: bobKeyPub,
ChanID: prevOut,
OurCommitKey: bobKeyPub,
TheirCommitKey: aliceKeyPub,
@ -260,7 +260,7 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
FundingOutpoint: prevOut,
OurMultiSigKey: bobKeyPub,
TheirMultiSigKey: aliceKeyPub,
FundingWitnessScript: witnessScript,
FundingWitnessScript: witnessScript,
LocalCsvDelay: csvTimeoutBob,
RemoteCsvDelay: csvTimeoutAlice,
TheirCurrentRevocation: aliceRevokeKey,
@ -688,12 +688,13 @@ func TestStateUpdatePersistence(t *testing.T) {
// Now fetch both of the channels created above from disk to simulate a
// node restart with persistence.
id := wire.ShaHash(testHdSeed)
aliceChannels, err := aliceChannel.channelState.Db.FetchOpenChannels(&id)
alicePub := aliceChannel.channelState.IdentityPub
aliceChannels, err := aliceChannel.channelState.Db.FetchOpenChannels(alicePub)
if err != nil {
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 {
t.Fatalf("unable to fetch channel: %v", err)
}

View File

@ -54,6 +54,8 @@ var (
0x6a, 0x49, 0x18, 0x83, 0x31, 0x98, 0x47, 0x53,
}
_, testPub = btcec.PrivKeyFromBytes(btcec.S256(), testHdSeed[:])
// The number of confirmations required to consider any created channel
// open.
numReqConfs = uint16(1)
@ -101,7 +103,7 @@ type bobNode struct {
deliveryAddress btcutil.Address
revocation [32]byte
delay uint32
id [wire.HashSize]byte
id *btcec.PublicKey
availableOutputs []*wire.TxIn
changeOutputs []*wire.TxOut
@ -241,7 +243,7 @@ func newBobNode(miner *rpctest.Harness, amt btcutil.Amount) (*bobNode, error) {
id[0] = 0xff
return &bobNode{
id: id,
id: pubKey,
privKey: privKey,
channelKey: pubKey,
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.
fundingSha := fundingTx.TxSha()
nodeID := wire.ShaHash(bobNode.id)
channels, err := wallet.ChannelDB.FetchOpenChannels(&nodeID)
channels, err := wallet.ChannelDB.FetchOpenChannels(bobNode.id)
if err != nil {
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.
fundingAmount := btcutil.Amount(8 * 1e8)
_, err := wallet.InitChannelReservation(fundingAmount, fundingAmount,
testHdSeed, numReqConfs, 4)
testPub, numReqConfs, 4)
if err != nil {
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.
amt := btcutil.Amount(900 * 1e8)
failedReservation, err := wallet.InitChannelReservation(amt, amt,
testHdSeed, numReqConfs, 4)
testPub, numReqConfs, 4)
if err == nil {
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.
fundingAmount := btcutil.Amount(44 * 1e8)
chanReservation, err := wallet.InitChannelReservation(fundingAmount,
fundingAmount, testHdSeed, numReqConfs, 4)
fundingAmount, testPub, numReqConfs, 4)
if err != nil {
t.Fatalf("unable to initialize funding reservation: %v", err)
}
// Attempt to create another channel with 44 BTC, this should fail.
_, err = wallet.InitChannelReservation(fundingAmount,
fundingAmount, testHdSeed, numReqConfs, 4)
fundingAmount, testPub, numReqConfs, 4)
if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok {
t.Fatalf("coin selection succeded should have insufficient funds: %v",
err)
@ -580,7 +581,7 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
// Request to fund a new channel should now succeeed.
_, err = wallet.InitChannelReservation(fundingAmount, fundingAmount,
testHdSeed, numReqConfs, 4)
testPub, numReqConfs, 4)
if err != nil {
t.Fatalf("unable to initialize funding reservation: %v", err)
}
@ -720,8 +721,7 @@ func testSingleFunderReservationWorkflowInitiator(miner *rpctest.Harness,
// TODO(roasbeef): de-duplicate
fundingTx := chanReservation.FinalFundingTx()
fundingSha := fundingTx.TxSha()
nodeID := wire.ShaHash(bobNode.id)
channels, err := lnwallet.ChannelDB.FetchOpenChannels(&nodeID)
channels, err := lnwallet.ChannelDB.FetchOpenChannels(bobNode.id)
if err != nil {
t.Fatalf("unable to retrieve channel from DB: %v", err)
}

View File

@ -92,8 +92,7 @@ type initFundingReserveMsg struct {
minFeeRate btcutil.Amount
// The ID of the remote node we would like to open a channel with.
// TODO(roasbeef): switch to just reg pubkey?
nodeID [32]byte
nodeID *btcec.PublicKey
// The delay on the "pay-to-self" output(s) of the commitment transaction.
csvDelay uint32
@ -473,8 +472,8 @@ out:
// transaction, and that the signature we records for our version of the
// commitment transaction is valid.
func (l *LightningWallet) InitChannelReservation(capacity,
ourFundAmt btcutil.Amount, theirID [32]byte, numConfs uint16,
csvDelay uint32) (*ChannelReservation, error) {
ourFundAmt btcutil.Amount, theirID *btcec.PublicKey,
numConfs uint16, csvDelay uint32) (*ChannelReservation, error) {
errChan := make(chan error, 1)
respChan := make(chan *ChannelReservation, 1)
@ -512,7 +511,7 @@ func (l *LightningWallet) handleFundingReserveRequest(req *initFundingReserveMsg
reservation.Lock()
defer reservation.Unlock()
reservation.partialState.TheirLNID = req.nodeID
reservation.partialState.IdentityPub = req.nodeID
ourContribution := reservation.ourContribution
ourContribution.CsvDelay = req.csvDelay
reservation.partialState.LocalCsvDelay = req.csvDelay