channeldb: add new field to store the state hint obsfucator

This commit is contained in:
Olaoluwa Osuntokun committed 2016-11-15 18:51:54 -08:00
1 parent bc3e16dd13
commit 66571e4464
2 files changed
+24 -2

No files matched your search

+14 -1
View File
@@ -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
}
+10 -1
View File
@@ -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