channeldb: remove theirCommitTx, store latest commit sig

This commit is contained in:
Olaoluwa Osuntokun 2016-07-05 16:44:39 -07:00
parent 927db9cfd5
commit 06af4b130f
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 44 additions and 56 deletions

@ -115,11 +115,10 @@ type OpenChannel struct {
OurBalance btcutil.Amount
TheirBalance btcutil.Amount
// Commitment transactions for both sides (they're asymmetric). Our
// commitment transaction includes a valid sigScript, and is ready for
// broadcast.
TheirCommitTx *wire.MsgTx
// Our current commitment transaction along with their signature for
// our commitment transaction.
OurCommitTx *wire.MsgTx
OurCommitSig []byte
// The outpoint of the final funding transaction.
FundingOutpoint *wire.OutPoint
@ -150,7 +149,7 @@ type OpenChannel struct {
TotalNetFees uint64 // TODO(roasbeef): total fees paid too?
CreationTime time.Time // TODO(roasbeef): last update time?
// isPrevState denotes if this instane of an OpenChannel is a previous,
// isPrevState denotes if this instance of an OpenChannel is a previous,
// revoked channel state. If so, then the FullSynv, and UpdateState
// methods are disabled in order to prevent overiding the latest channel
// state.
@ -845,11 +844,11 @@ func putChanCommitTxns(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error
var b bytes.Buffer
if err := channel.TheirCommitTx.Serialize(&b); err != nil {
if err := channel.OurCommitTx.Serialize(&b); err != nil {
return err
}
if err := channel.OurCommitTx.Serialize(&b); err != nil {
if err := wire.WriteVarBytes(&b, 0, channel.OurCommitSig); err != nil {
return err
}
@ -875,7 +874,8 @@ func deleteChanCommitTxns(nodeChanBucket *bolt.Bucket, chanID []byte) error {
func fetchChanCommitTxns(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error {
var bc bytes.Buffer
if err := writeOutpoint(&bc, channel.ChanID); err != nil {
var err error
if err = writeOutpoint(&bc, channel.ChanID); err != nil {
return err
}
txnsKey := make([]byte, len(commitTxnsKey)+bc.Len())
@ -884,13 +884,13 @@ func fetchChanCommitTxns(nodeChanBucket *bolt.Bucket, channel *OpenChannel) erro
txnBytes := bytes.NewReader(nodeChanBucket.Get(txnsKey))
channel.TheirCommitTx = wire.NewMsgTx()
if err := channel.TheirCommitTx.Deserialize(txnBytes); err != nil {
channel.OurCommitTx = wire.NewMsgTx()
if err = channel.OurCommitTx.Deserialize(txnBytes); err != nil {
return err
}
channel.OurCommitTx = wire.NewMsgTx()
if err := channel.OurCommitTx.Deserialize(txnBytes); err != nil {
channel.OurCommitSig, err = wire.ReadVarBytes(txnBytes, 0, 80, "")
if err != nil {
return err
}

@ -149,8 +149,8 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
Capacity: btcutil.Amount(10000),
OurBalance: btcutil.Amount(3000),
TheirBalance: btcutil.Amount(9000),
TheirCommitTx: testTx,
OurCommitTx: testTx,
OurCommitSig: bytes.Repeat([]byte{1}, 71),
LocalElkrem: sender,
RemoteElkrem: receiver,
FundingOutpoint: testOutpoint,
@ -158,6 +158,7 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
TheirMultiSigKey: privKey.PubKey(),
FundingRedeemScript: script,
TheirCurrentRevocation: privKey.PubKey(),
TheirCurrentRevocationHash: key,
OurDeliveryScript: script,
TheirDeliveryScript: script,
LocalCsvDelay: 5,
@ -215,19 +216,6 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
}
var b1, b2 bytes.Buffer
if err := state.TheirCommitTx.Serialize(&b1); err != nil {
t.Fatalf("unable to serialize transaction")
}
if err := newState.TheirCommitTx.Serialize(&b2); err != nil {
t.Fatalf("unable to serialize transaction")
}
if !bytes.Equal(b1.Bytes(), b2.Bytes()) {
t.Fatalf("theirCommitTx doesn't match")
}
b1.Reset()
b2.Reset()
if err := state.OurCommitTx.Serialize(&b1); err != nil {
t.Fatalf("unable to serialize transaction")
}
@ -237,9 +225,9 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
if !bytes.Equal(b1.Bytes(), b2.Bytes()) {
t.Fatalf("ourCommitTx doesn't match")
}
b1.Reset()
b2.Reset()
if !bytes.Equal(newState.OurCommitSig, state.OurCommitSig) {
t.Fatalf("commit sigs don't match")
}
// TODO(roasbeef): replace with a single equal?
if !reflect.DeepEqual(state.FundingOutpoint, newState.FundingOutpoint) {