Skip to content

Commit

Permalink
channeldb: extend ChannelConfig with new HtlcBasePoint key
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef committed Nov 17, 2017
1 parent a14a156 commit 12e5951
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
12 changes: 10 additions & 2 deletions channeldb/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
29 changes: 2 additions & 27 deletions channeldb/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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()))
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit 12e5951

Please sign in to comment.