diff --git a/channeldb/channel.go b/channeldb/channel.go index f51c737b..73f74917 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -144,7 +144,11 @@ type OpenChannel struct { OurCommitTx *wire.MsgTx OurCommitSig []byte - // The outpoint of the final funding transaction. + // StateHintObsfucator are the btyes selected by the initiator (derived + // from their shachain root) to obsfucate the state-hint encoded within + // the commitment transaction. + StateHintObsfucator [4]byte + // ChanType denotes which type of channel this is. ChanType ChannelType @@ -1265,6 +1269,10 @@ func putChanElkremState(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error return err } + if _, err := b.Write(channel.StateHintObsfucator[:]); err != nil { + return err + } + return nodeChanBucket.Put(elkremKey, b.Bytes()) } @@ -1320,6 +1328,11 @@ func fetchChanElkremState(nodeChanBucket *bolt.Bucket, channel *OpenChannel) err } channel.RemoteElkrem = remoteE + _, err = io.ReadFull(elkremStateBytes, channel.StateHintObsfucator[:]) + if err != nil { + return err + } + return nil } diff --git a/channeldb/channel_test.go b/channeldb/channel_test.go index ce3a2e64..01551e87 100644 --- a/channeldb/channel_test.go +++ b/channeldb/channel_test.go @@ -132,6 +132,9 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) { } } + var obsfucator [4]byte + copy(obsfucator[:], key[:]) + return &OpenChannel{ IsInitiator: true, ChanType: SingleFunder, @@ -147,6 +150,7 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) { OurCommitSig: bytes.Repeat([]byte{1}, 71), LocalElkrem: sender, RemoteElkrem: receiver, + StateHintObsfucator: obsfucator, FundingOutpoint: testOutpoint, OurMultiSigKey: privKey.PubKey(), TheirMultiSigKey: privKey.PubKey(), @@ -207,7 +211,8 @@ func TestOpenChannelPutGetDelete(t *testing.T) { t.Fatalf("chan id's don't match") } if state.MinFeePerKb != newState.MinFeePerKb { - t.Fatalf("fee/kb doens't match") + t.Fatalf("fee/kb doesn't match") + } if state.IsInitiator != newState.IsInitiator { t.Fatalf("initiator status doesn't match") } @@ -322,6 +327,10 @@ func TestOpenChannelPutGetDelete(t *testing.T) { t.Fatalf("htlcs don't match: %v vs %v", spew.Sdump(state.Htlcs[0]), spew.Sdump(newState.Htlcs[0])) } + if !bytes.Equal(state.StateHintObsfucator[:], + newState.StateHintObsfucator[:]) { + t.Fatalf("obsfuctators don't match") + } // Finally to wrap up the test, delete the state of the channel within // the database. This involves "closing" the channel which removes all