What changed, and why it matters
This commit is a straightforward internal code reorganization. It moves the existing logic for saving a new remote commitment-chain update from one place in the code to another, without changing what the logic actually does. There is no user-facing behavior change and no security fix or vulnerability introduced.
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 change refactors OpenChannel.AppendRemoteCommitChain to delegate its work to a new ChannelStateDB.AppendRemoteCommitChain method. The exact same KV transaction body is preserved, including the borked-channel check, HTLC acknowledgment calls, and bucket fetch. A corresponding method is added to the OpenChannelCommitmentStore interface in chanstate/interface.go. This is purely architectural decoupling (removing a direct backend dependency from OpenChannel).
Changed components
channeldb/channel.gochanstate/interface.goInspect captured patch +21 / −5
diff --git a/channeldb/channel.go b/channeldb/channel.go
index f509d50..601fe47 100644
--- a/channeldb/channel.go
+++ b/channeldb/channel.go
@@ -2933,11 +2933,20 @@ func (c *OpenChannel) AppendRemoteCommitChain(diff *CommitDiff) error {
return ErrNoRestoredChannelMutation
}
- return kvdb.Update(c.Db.backend, func(tx kvdb.RwTx) error {
+ return c.Db.AppendRemoteCommitChain(c, diff)
+}
+
+// AppendRemoteCommitChain appends a new CommitDiff to the remote party's
+// commitment chain.
+func (c *ChannelStateDB) AppendRemoteCommitChain(channel *OpenChannel,
+ diff *CommitDiff) error {
+
+ return kvdb.Update(c.backend, func(tx kvdb.RwTx) error {
// First, we'll grab the writable bucket where this channel's
// data resides.
chanBucket, err := fetchChanBucketRw(
- tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
+ tx, channel.IdentityPub, &channel.FundingOutpoint,
+ channel.ChainHash,
)
if err != nil {
return err
@@ -2945,7 +2954,7 @@ func (c *OpenChannel) AppendRemoteCommitChain(diff *CommitDiff) error {
// 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
}
@@ -2958,7 +2967,7 @@ func (c *OpenChannel) AppendRemoteCommitChain(diff *CommitDiff) error {
// Mark all of these as being fully processed in our forwarding
// package, which prevents us from reprocessing them after
// startup.
- err = c.Packager.AckAddHtlcs(tx, diff.AddAcks...)
+ err = channel.Packager.AckAddHtlcs(tx, diff.AddAcks...)
if err != nil {
return err
}
@@ -2968,7 +2977,9 @@ func (c *OpenChannel) AppendRemoteCommitChain(diff *CommitDiff) error {
// prevents the same fails and settles from being retransmitted
// after restarts. The actual fail or settle we need to
// propagate to the remote party is now in the commit diff.
- err = c.Packager.AckSettleFails(tx, diff.SettleFailAcks...)
+ err = channel.Packager.AckSettleFails(
+ tx, diff.SettleFailAcks...,
+ )
if err != nil {
return err
}
diff --git a/chanstate/interface.go b/chanstate/interface.go
index 3e26f2d..323aa9c 100644
--- a/chanstate/interface.go
+++ b/chanstate/interface.go
@@ -232,6 +232,11 @@ type OpenChannelCommitmentStore[Channel any] interface {
UpdateChannelCommitment(channel Channel,
newCommitment *ChannelCommitment,
unsignedAckedUpdates []LogUpdate) (map[uint64]bool, error)
+
+ // AppendRemoteCommitChain appends a new CommitDiff to the remote
+ // party's commitment chain. This is used after preparing a new remote
+ // commitment state, before transmitting it to the remote party.
+ AppendRemoteCommitChain(channel Channel, diff *CommitDiff) error
}
// ClosedChannelStore owns closed-channel summaries and lifecycle mutations.
Why this scored 15/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.