What changed, and why it matters
This commit is a straightforward internal code reorganization in LND's channel database. It moves two existing database-read helpers from the OpenChannel type to the ChannelStateDB type, leaving thin wrapper methods behind. There is no change to what data is read, how it is validated, or how it is exposed to users or the network. It is best described as a refactoring/cleanup change.
No security action required. Review as normal refactoring; verify that callers still use OpenChannel wrappers and that ChannelStateDB is always non-nil when these methods are invoked.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors channeldb/channel.go so that revocationLogTailCommitHeight and FindPreviousState perform their kvdb.View reads on ChannelStateDB rather than directly on OpenChannel. OpenChannel retains public wrapper methods that delegate to c.Db.
Changed components
channeldb/channel.goOpenChannel revocation log helpersChannelStateDBInspect captured patch +26 / −5
diff --git a/channeldb/channel.go b/channeldb/channel.go
index 97ae6a5..b89d5f2 100644
--- a/channeldb/channel.go
+++ b/channeldb/channel.go
@@ -3549,17 +3549,26 @@ func (c *OpenChannel) revocationLogTailCommitHeight() (uint64, error) {
c.RLock()
defer c.RUnlock()
+ return c.Db.revocationLogTailCommitHeight(c)
+}
+
+// revocationLogTailCommitHeight returns the commit height at the end of the
+// revocation log.
+func (c *ChannelStateDB) revocationLogTailCommitHeight(
+ channel *OpenChannel) (uint64, error) {
+
var height uint64
// If we haven't created any state updates yet, then we'll exit early as
// there's nothing to be found on disk in the revocation bucket.
- if c.RemoteCommitment.CommitHeight == 0 {
+ if channel.RemoteCommitment.CommitHeight == 0 {
return height, nil
}
- if err := kvdb.View(c.Db.backend, func(tx kvdb.RTx) error {
+ if err := kvdb.View(c.backend, func(tx kvdb.RTx) error {
chanBucket, err := fetchChanBucket(
- tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
+ tx, channel.IdentityPub, &channel.FundingOutpoint,
+ channel.ChainHash,
)
if err != nil {
return err
@@ -3646,12 +3655,24 @@ func (c *OpenChannel) FindPreviousState(
c.RLock()
defer c.RUnlock()
+ return c.Db.FindPreviousState(c, updateNum)
+}
+
+// FindPreviousState scans through the append-only log in an attempt to recover
+// the previous channel state indicated by the update number. This method is
+// intended to be used for obtaining the relevant data needed to claim all
+// funds rightfully spendable in the case of an on-chain broadcast of the
+// commitment transaction.
+func (c *ChannelStateDB) FindPreviousState(channel *OpenChannel,
+ updateNum uint64) (*RevocationLog, *ChannelCommitment, error) {
+
commit := &ChannelCommitment{}
rl := &RevocationLog{}
- err := kvdb.View(c.Db.backend, func(tx kvdb.RTx) error {
+ err := kvdb.View(c.backend, func(tx kvdb.RTx) error {
chanBucket, err := fetchChanBucket(
- tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
+ tx, channel.IdentityPub, &channel.FundingOutpoint,
+ channel.ChainHash,
)
if err != nil {
return err
Why this scored 12/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.