channeldb: add new RemoteCommitChainTip method
In this commit, we add a new method: RemoteCommitChainTip. This method allows callers to poll the database state to check if we have an un-acked commitment for the remote party. If so, then it should be retransmitted once a communication channel has been re-established with the channel peer. This method will return ErrNoPendingCommit if we don’t currently have a dangling commitment.
This commit is contained in:
parent
893cda3ac2
commit
b89c14616c
@ -871,32 +871,40 @@ func (c *OpenChannel) AppendRemoteCommitChain(diff *CommitDiff) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchCommitDiff...
|
// RemoteCommitChainTip returns the "tip" of the current remote commitment
|
||||||
func FetchCommitDiff(db *DB, fundingOutpoint *wire.OutPoint) (*CommitDiff, error) {
|
// chain. This value will be non-nil iff, we've created a new commitment for
|
||||||
var diff *CommitDiff
|
// the remote party that they haven't yet ACK'd. In this case, their commitment
|
||||||
err := db.View(func(tx *bolt.Tx) error {
|
// chain will have a length of two: their current unrevoked commitment, and
|
||||||
bucket := tx.Bucket(commitDiffBucket)
|
// this new pending commitment. Once they revoked their prior state, we'll swap
|
||||||
if bucket == nil {
|
// these pointers, causing the tip and the tail to point to the same entry.
|
||||||
return errors.New("commit diff bucket haven't been found")
|
func (c *OpenChannel) RemoteCommitChainTip() (*CommitDiff, error) {
|
||||||
}
|
var cd *CommitDiff
|
||||||
|
err := c.Db.View(func(tx *bolt.Tx) error {
|
||||||
var outpoint bytes.Buffer
|
chanBucket, err := readChanBucket(tx, c.IdentityPub,
|
||||||
if err := writeOutpoint(&outpoint, fundingOutpoint); err != nil {
|
&c.FundingOutpoint, c.ChainHash)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
key := []byte("cdf")
|
tipBytes := chanBucket.Get(commitDiffKey)
|
||||||
key = append(key, outpoint.Bytes()...)
|
if tipBytes == nil {
|
||||||
data := bucket.Get(key)
|
return ErrNoPendingCommit
|
||||||
if data == nil {
|
|
||||||
return errors.New("unable to find commit diff")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
diff = &CommitDiff{}
|
tipReader := bytes.NewReader(tipBytes)
|
||||||
return diff.encode(bytes.NewReader(data))
|
dcd, err := deserializeCommitDiff(tipReader)
|
||||||
})
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return diff, err
|
cd = dcd
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return cd, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// InsertNextRevocation inserts the _next_ commitment point (revocation) into
|
// InsertNextRevocation inserts the _next_ commitment point (revocation) into
|
||||||
|
Loading…
Reference in New Issue
Block a user