channeldb: add new AppendRemoteCommitChain method
In this commit, we add a new method AppendRemoteCommitChain. This method is meant to be used once we extend a new state to the remote party, but before we actually transmit the CommitSig message. With this method, we store a fully valid CommitDiff on disk which can be used in the case that we need to retransmit the state to the party as they didn’t fully receive it.
This commit is contained in:
parent
10a54a45fd
commit
893cda3ac2
@ -843,28 +843,31 @@ func deserializeCommitDiff(r io.Reader) (*CommitDiff, error) {
|
|||||||
return &d, nil
|
return &d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddCommitDiff...
|
// AppendRemoteCommitChain appends a new CommitDiff to the end of the
|
||||||
func AddCommitDiff(db *DB, fundingOutpoint *wire.OutPoint,
|
// commitment chain for the remote party. This method is to be used once we
|
||||||
diff *CommitDiff) error {
|
// have prepared a new commitment state for the remote party, but before we
|
||||||
return db.Update(func(tx *bolt.Tx) error {
|
// transmit it to the remote party. The contents of the argument should be
|
||||||
bucket, err := tx.CreateBucketIfNotExists(commitDiffBucket)
|
// sufficient to retransmit the updates and signature needed to reconstruct the
|
||||||
|
// state in full, in the case that we need to retransmit.
|
||||||
|
func (c *OpenChannel) AppendRemoteCommitChain(diff *CommitDiff) error {
|
||||||
|
return c.Db.Update(func(tx *bolt.Tx) error {
|
||||||
|
// First, we'll grab the writeable bucket where this channel's
|
||||||
|
// data resides.
|
||||||
|
chanBucket, err := updateChanBucket(tx, c.IdentityPub,
|
||||||
|
&c.FundingOutpoint, c.ChainHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(roasbeef): use seqno to derive key for later LCP
|
||||||
|
|
||||||
|
// With the bucket retrieved, we'll now serialize the commit
|
||||||
|
// diff itself, and write it to disk.
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
if err := diff.decode(&b); err != nil {
|
if err := serializeCommitDiff(&b, diff); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return chanBucket.Put(commitDiffKey, b.Bytes())
|
||||||
var outpoint bytes.Buffer
|
|
||||||
if err := writeOutpoint(&outpoint, fundingOutpoint); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
key := []byte("cdf")
|
|
||||||
key = append(key, outpoint.Bytes()...)
|
|
||||||
return bucket.Put(key, b.Bytes())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user