What changed, and why it matters
This commit is a straightforward internal code reorganization. It moves the database logic for advancing a Lightning channel's commitment chain from one object (OpenChannel) to another (ChannelStateDB) and adds the corresponding method to an interface. There is no visible change in behavior, no bug fix, and no security-related content in the commit message or diff.
No security action required. Review as normal refactoring if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors AdvanceCommitChainTail. The OpenChannel receiver now only performs locking and the restored-channel mutation guard before delegating to ChannelStateDB.AdvanceCommitChainTail, which contains the existing kvdb.Update transaction body. The method is also added to the chanstate.OpenChannelCommitmentStore generic interface. The logic inside the transaction (revocation state persistence, commitment pointer swap, revocation log write, forwarding package storage, and in-memory update) is unchanged.
Changed components
channeldb/channel.gochanstate/interface.goInspect captured patch +29 / −8
diff --git a/channeldb/channel.go b/channeldb/channel.go
index 1c70f48..33598c0 100644
--- a/channeldb/channel.go
+++ b/channeldb/channel.go
@@ -3206,11 +3206,24 @@ func (c *OpenChannel) AdvanceCommitChainTail(fwdPkg *FwdPkg,
return ErrNoRestoredChannelMutation
}
+ return c.Db.AdvanceCommitChainTail(
+ c, fwdPkg, updates, ourOutputIndex, theirOutputIndex,
+ )
+}
+
+// AdvanceCommitChainTail records the new state transition within the
+// revocation log and promotes the pending remote commitment to the current
+// remote commitment.
+func (c *ChannelStateDB) AdvanceCommitChainTail(channel *OpenChannel,
+ fwdPkg *FwdPkg, updates []LogUpdate, ourOutputIndex,
+ theirOutputIndex uint32) error {
+
var newRemoteCommit *ChannelCommitment
- err := kvdb.Update(c.Db.backend, func(tx kvdb.RwTx) error {
+ err := kvdb.Update(c.backend, func(tx kvdb.RwTx) error {
chanBucket, err := fetchChanBucketRw(
- tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
+ tx, channel.IdentityPub, &channel.FundingOutpoint,
+ channel.ChainHash,
)
if err != nil {
return err
@@ -3218,7 +3231,7 @@ func (c *OpenChannel) AdvanceCommitChainTail(fwdPkg *FwdPkg,
// If the channel is marked as borked, then for safety reasons,
// we shouldn't attempt any further updates.
- isBorked, err := c.isBorked(chanBucket)
+ isBorked, err := channel.isBorked(chanBucket)
if err != nil {
return err
}
@@ -3229,7 +3242,8 @@ func (c *OpenChannel) AdvanceCommitChainTail(fwdPkg *FwdPkg,
// Persist the latest preimage state to disk as the remote peer
// has just added to our local preimage store, and given us a
// new pending revocation key.
- if err := putChanRevocationState(chanBucket, c); err != nil {
+ err = putChanRevocationState(chanBucket, channel)
+ if err != nil {
return err
}
@@ -3268,8 +3282,8 @@ func (c *OpenChannel) AdvanceCommitChainTail(fwdPkg *FwdPkg,
// With the commitment pointer swapped, we can now add the
// revoked (prior) state to the revocation log.
err = putRevocationLog(
- logBucket, &c.RemoteCommitment, ourOutputIndex,
- theirOutputIndex, c.Db.parent.noRevLogAmtData,
+ logBucket, &channel.RemoteCommitment, ourOutputIndex,
+ theirOutputIndex, c.parent.noRevLogAmtData,
)
if err != nil {
return err
@@ -3278,7 +3292,7 @@ func (c *OpenChannel) AdvanceCommitChainTail(fwdPkg *FwdPkg,
// Lastly, we write the forwarding package to disk so that we
// can properly recover from failures and reforward HTLCs that
// have not received a corresponding settle/fail.
- if err := c.Packager.AddFwdPkg(tx, fwdPkg); err != nil {
+ if err := channel.Packager.AddFwdPkg(tx, fwdPkg); err != nil {
return err
}
@@ -3350,7 +3364,7 @@ func (c *OpenChannel) AdvanceCommitChainTail(fwdPkg *FwdPkg,
// With the db transaction complete, we'll swap over the in-memory
// pointer of the new remote commitment, which was previously the tip
// of the commit chain.
- c.RemoteCommitment = *newRemoteCommit
+ channel.RemoteCommitment = *newRemoteCommit
return nil
}
diff --git a/chanstate/interface.go b/chanstate/interface.go
index 7d89279..8a68fd4 100644
--- a/chanstate/interface.go
+++ b/chanstate/interface.go
@@ -253,6 +253,13 @@ type OpenChannelCommitmentStore[Channel any] interface {
// InsertNextRevocation inserts the next commitment point into the
// persisted channel state.
InsertNextRevocation(channel Channel, revKey *btcec.PublicKey) error
+
+ // AdvanceCommitChainTail records the new state transition within the
+ // revocation log and promotes the pending remote commitment to the
+ // current remote commitment.
+ AdvanceCommitChainTail(channel Channel, fwdPkg *FwdPkg,
+ updates []LogUpdate, ourOutputIndex,
+ theirOutputIndex uint32) error
}
// ClosedChannelStore owns closed-channel summaries and lifecycle mutations.
Why this scored 11/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.