channeldb: also pass in current tx and sig into RecordChannelDelta
This commit is contained in:
parent
6684f6aedf
commit
c1b98da530
@ -274,7 +274,9 @@ type ChannelDelta struct {
|
|||||||
// append-only log which records all state transitions. Additionally, the
|
// append-only log which records all state transitions. Additionally, the
|
||||||
// internal balances and update counter of the target OpenChannel are updated
|
// internal balances and update counter of the target OpenChannel are updated
|
||||||
// accordingly based on the passed delta.
|
// 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 {
|
return c.Db.store.Update(func(tx *bolt.Tx) error {
|
||||||
chanBucket, err := tx.CreateBucketIfNotExists(openChannelBucket)
|
chanBucket, err := tx.CreateBucketIfNotExists(openChannelBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -287,8 +289,11 @@ func (c *OpenChannel) RecordChannelDelta(delta *ChannelDelta) error {
|
|||||||
return ErrNoActiveChannels
|
return ErrNoActiveChannels
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(roasbeef): revisit in-line mutation
|
||||||
|
c.OurCommitTx = newCommitment
|
||||||
c.OurBalance = delta.LocalBalance
|
c.OurBalance = delta.LocalBalance
|
||||||
c.TheirBalance = delta.RemoteBalance
|
c.TheirBalance = delta.RemoteBalance
|
||||||
|
c.OurCommitSig = newSig
|
||||||
c.NumUpdates = uint64(delta.UpdateNum)
|
c.NumUpdates = uint64(delta.UpdateNum)
|
||||||
|
|
||||||
// First we'll write out the current latest dynamic channel
|
// 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.
|
// Additionally, modify the signature and commitment transaction.
|
||||||
newSequence := uint32(129498)
|
newSequence := uint32(129498)
|
||||||
newSig := bytes.Repeat([]byte{3}, 71)
|
newSig := bytes.Repeat([]byte{3}, 71)
|
||||||
|
newTx := channel.OurCommitTx.Copy()
|
||||||
|
newTx.TxIn[0].Sequence = newSequence
|
||||||
delta := &ChannelDelta{
|
delta := &ChannelDelta{
|
||||||
RevocationHash: key,
|
RevocationHash: key,
|
||||||
RevocationKey: pubKey,
|
RevocationKey: pubKey,
|
||||||
@ -372,9 +374,7 @@ func TestChannelStateUpdateLog(t *testing.T) {
|
|||||||
Htlcs: htlcs,
|
Htlcs: htlcs,
|
||||||
UpdateNum: 1,
|
UpdateNum: 1,
|
||||||
}
|
}
|
||||||
channel.OurCommitTx.TxIn[0].Sequence = newSequence
|
if err := channel.RecordChannelDelta(newTx, newSig, delta); err != nil {
|
||||||
channel.OurCommitSig = newSig
|
|
||||||
if err := channel.RecordChannelDelta(delta); err != nil {
|
|
||||||
t.Fatalf("unable to record channel delta: %v", err)
|
t.Fatalf("unable to record channel delta: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user