channeldb: also pass in current tx and sig into RecordChannelDelta

This commit is contained in:
Olaoluwa Osuntokun 2016-09-05 16:52:54 -07:00
parent 6684f6aedf
commit c1b98da530
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 9 additions and 4 deletions

@ -274,7 +274,9 @@ type ChannelDelta struct {
// append-only log which records all state transitions. Additionally, the
// internal balances and update counter of the target OpenChannel are updated
// accordingly based on the passed delta.
func (c *OpenChannel) RecordChannelDelta(delta *ChannelDelta) error {
func (c *OpenChannel) RecordChannelDelta(newCommitment *wire.MsgTx,
newSig []byte, delta *ChannelDelta) error {
return c.Db.store.Update(func(tx *bolt.Tx) error {
chanBucket, err := tx.CreateBucketIfNotExists(openChannelBucket)
if err != nil {
@ -287,8 +289,11 @@ func (c *OpenChannel) RecordChannelDelta(delta *ChannelDelta) error {
return ErrNoActiveChannels
}
// TODO(roasbeef): revisit in-line mutation
c.OurCommitTx = newCommitment
c.OurBalance = delta.LocalBalance
c.TheirBalance = delta.RemoteBalance
c.OurCommitSig = newSig
c.NumUpdates = uint64(delta.UpdateNum)
// First we'll write out the current latest dynamic channel

@ -364,6 +364,8 @@ func TestChannelStateUpdateLog(t *testing.T) {
// Additionally, modify the signature and commitment transaction.
newSequence := uint32(129498)
newSig := bytes.Repeat([]byte{3}, 71)
newTx := channel.OurCommitTx.Copy()
newTx.TxIn[0].Sequence = newSequence
delta := &ChannelDelta{
RevocationHash: key,
RevocationKey: pubKey,
@ -372,9 +374,7 @@ func TestChannelStateUpdateLog(t *testing.T) {
Htlcs: htlcs,
UpdateNum: 1,
}
channel.OurCommitTx.TxIn[0].Sequence = newSequence
channel.OurCommitSig = newSig
if err := channel.RecordChannelDelta(delta); err != nil {
if err := channel.RecordChannelDelta(newTx, newSig, delta); err != nil {
t.Fatalf("unable to record channel delta: %v", err)
}