channeldb: modify RevocationLogTail to return a ChannelCommitment

This commit is contained in:
Olaoluwa Osuntokun 2017-11-09 20:48:23 -08:00
parent 374cab7467
commit 5bdff9585b
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -1022,24 +1022,22 @@ func (c *OpenChannel) AdvanceCommitChainTail() error {
// commitment chain. The ChannelDelta returned by this method will always lag // commitment chain. The ChannelDelta returned by this method will always lag
// one state behind the most current (unrevoked) state of the remote node's // one state behind the most current (unrevoked) state of the remote node's
// commitment chain. // commitment chain.
func (c *OpenChannel) RevocationLogTail() (*ChannelDelta, error) { func (c *OpenChannel) RevocationLogTail() (*ChannelCommitment, error) {
// If we haven't created any state updates yet, then we'll exit erly as // If we haven't created any state updates yet, then we'll exit erly as
// there's nothing to be found on disk in the revocation bucket. // there's nothing to be found on disk in the revocation bucket.
if c.NumUpdates == 0 { if c.RemoteCommitment.CommitHeight == 0 {
return nil, nil return nil, nil
} }
var delta *ChannelDelta var commit ChannelCommitment
if err := c.Db.View(func(tx *bolt.Tx) error { if err := c.Db.View(func(tx *bolt.Tx) error {
chanBucket := tx.Bucket(openChannelBucket) chanBucket, err := readChanBucket(tx, c.IdentityPub,
&c.FundingOutpoint, c.ChainHash)
nodePub := c.IdentityPub.SerializeCompressed() if err != nil {
nodeChanBucket := chanBucket.Bucket(nodePub) return err
if nodeChanBucket == nil {
return ErrNoActiveChannels
} }
logBucket := nodeChanBucket.Bucket(channelLogBucket) logBucket := chanBucket.Bucket(revocationLogBucket)
if logBucket == nil { if logBucket == nil {
return ErrNoPastDeltas return ErrNoPastDeltas
} }
@ -1055,7 +1053,7 @@ func (c *OpenChannel) RevocationLogTail() (*ChannelDelta, error) {
// Once we have the entry, we'll decode it into the channel // Once we have the entry, we'll decode it into the channel
// delta pointer we created above. // delta pointer we created above.
var dbErr error var dbErr error
delta, dbErr = deserializeChannelDelta(logEntryReader) commit, dbErr = deserializeChanCommit(logEntryReader)
if dbErr != nil { if dbErr != nil {
return dbErr return dbErr
} }
@ -1065,7 +1063,7 @@ func (c *OpenChannel) RevocationLogTail() (*ChannelDelta, error) {
return nil, err return nil, err
} }
return delta, nil return &commit, nil
} }
// CommitmentHeight returns the current commitment height. The commitment // CommitmentHeight returns the current commitment height. The commitment