From 12e59514345c5630127e8e35c8c79d38ce641696 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 14 Nov 2017 20:29:26 -0800 Subject: [PATCH] channeldb: extend ChannelConfig with new HtlcBasePoint key --- channeldb/channel.go | 12 ++++++++++-- channeldb/channel_test.go | 29 ++--------------------------- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/channeldb/channel.go b/channeldb/channel.go index 174f7698..a4608387 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -177,19 +177,25 @@ type ChannelConfig struct { // unique revocation key for each state. RevocationBasePoint *btcec.PublicKey - // PaymentBasePoint is the based public key to be used when deriving + // PaymentBasePoint is the base public key to be used when deriving // the key used within the non-delayed pay-to-self output on the // commitment transaction for a node. This will be combined with a // tweak derived from the per-commitment point to ensure unique keys // for each commitment transaction. PaymentBasePoint *btcec.PublicKey - // DelayBasePoint is the based public key to be used when deriving the + // DelayBasePoint is the base public key to be used when deriving the // key used within the delayed pay-to-self output on the commitment // transaction for a node. This will be combined with a tweak derived // from the per-commitment point to ensure unique keys for each // commitment transaction. DelayBasePoint *btcec.PublicKey + + // HtlcBasePoint is the base public key to be used when deriving the + // local HTLC key. The derived key (combined with the tweak derived + // from the per-commitment point) is used within the "to self" clause + // within any HTLC output scripts. + HtlcBasePoint *btcec.PublicKey } // ChannelCommitment is a snapshot of the commitment state at a particular @@ -1447,6 +1453,7 @@ func putChanInfo(chanBucket *bolt.Bucket, channel *OpenChannel) error { c.DustLimit, c.MaxPendingAmount, c.ChanReserve, c.MinHTLC, c.MaxAcceptedHtlcs, c.CsvDelay, c.MultiSigKey, c.RevocationBasePoint, c.PaymentBasePoint, c.DelayBasePoint, + c.HtlcBasePoint, ) } if err := writeChanConfig(&w, &channel.LocalChanCfg); err != nil { @@ -1547,6 +1554,7 @@ func fetchChanInfo(chanBucket *bolt.Bucket, channel *OpenChannel) error { &c.MinHTLC, &c.MaxAcceptedHtlcs, &c.CsvDelay, &c.MultiSigKey, &c.RevocationBasePoint, &c.PaymentBasePoint, &c.DelayBasePoint, + &c.HtlcBasePoint, ) } if err := readChanConfig(r, &channel.LocalChanCfg); err != nil { diff --git a/channeldb/channel_test.go b/channeldb/channel_test.go index 0dabf9a9..0a35dcd9 100644 --- a/channeldb/channel_test.go +++ b/channeldb/channel_test.go @@ -139,6 +139,7 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) { RevocationBasePoint: privKey.PubKey(), PaymentBasePoint: privKey.PubKey(), DelayBasePoint: privKey.PubKey(), + HtlcBasePoint: privKey.PubKey(), } remoteCfg := ChannelConfig{ ChannelConstraints: ChannelConstraints{ @@ -153,6 +154,7 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) { RevocationBasePoint: privKey.PubKey(), PaymentBasePoint: privKey.PubKey(), DelayBasePoint: privKey.PubKey(), + HtlcBasePoint: privKey.PubKey(), } chanID := lnwire.NewShortChanIDFromInt(uint64(rand.Int63())) @@ -246,33 +248,6 @@ func TestOpenChannelPutGetDelete(t *testing.T) { // The decoded channel state should be identical to what we stored // above. if !reflect.DeepEqual(state, newState) { - state.LocalChanCfg.MultiSigKey.Curve = nil - state.LocalChanCfg.RevocationBasePoint.Curve = nil - state.LocalChanCfg.PaymentBasePoint.Curve = nil - state.LocalChanCfg.DelayBasePoint.Curve = nil - - state.RemoteChanCfg.MultiSigKey.Curve = nil - state.RemoteChanCfg.RevocationBasePoint.Curve = nil - state.RemoteChanCfg.PaymentBasePoint.Curve = nil - state.RemoteChanCfg.DelayBasePoint.Curve = nil - - state.IdentityPub.Curve = nil - state.RemoteNextRevocation.Curve = nil - state.RemoteCurrentRevocation.Curve = nil - - newState.LocalChanCfg.MultiSigKey.Curve = nil - newState.LocalChanCfg.RevocationBasePoint.Curve = nil - newState.LocalChanCfg.PaymentBasePoint.Curve = nil - newState.LocalChanCfg.DelayBasePoint.Curve = nil - - newState.RemoteChanCfg.MultiSigKey.Curve = nil - newState.RemoteChanCfg.RevocationBasePoint.Curve = nil - newState.RemoteChanCfg.PaymentBasePoint.Curve = nil - newState.RemoteChanCfg.DelayBasePoint.Curve = nil - - newState.IdentityPub.Curve = nil - newState.RemoteCurrentRevocation.Curve = nil - newState.RemoteNextRevocation.Curve = nil t.Fatalf("channel state doesn't match:: %v vs %v", spew.Sdump(state), spew.Sdump(newState)) }