What changed, and why it matters
This commit is a straightforward internal code reorganization. It moves the definition of a small data structure called ShutdownInfo (which tracks who started closing a Lightning channel and what address should receive funds) from one package to another, while keeping the actual save/load encoding code in the original place. There is no change to user-facing behavior, no bug fix, and no security patch.
No security action needed. Treat as normal refactoring during code review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors ShutdownInfo, NewShutdownInfo, and ShutdownInfo.Closer out of channeldb/channel.go into a new chanstate/shutdown.go file. channeldb now uses a type alias (type ShutdownInfo = cstate.ShutdownInfo) and delegates the constructor via a variable alias. The TLV encode/decode helpers remain in channeldb, with the method-style encode converted to a package-level function encodeShutdownInfo to avoid exposing the moved type’s method set from channeldb. This is purely structural decoupling of state types from the KV persistence layer.
Changed components
channeldb/channel.gochanstate/shutdown.goInspect captured patch +46 / −32
diff --git a/channeldb/channel.go b/channeldb/channel.go
index 605edab..00f94e6 100644
--- a/channeldb/channel.go
+++ b/channeldb/channel.go
@@ -1846,7 +1846,7 @@ func (c *OpenChannel) MarkShutdownSent(info *ShutdownInfo) error {
// shutdownInfoKey.
func (c *OpenChannel) storeShutdownInfo(info *ShutdownInfo) error {
var b bytes.Buffer
- err := info.encode(&b)
+ err := encodeShutdownInfo(info, &b)
if err != nil {
return err
}
@@ -4816,40 +4816,13 @@ func DKeyLocator(r io.Reader, val interface{}, buf *[8]byte, l uint64) error {
// ShutdownInfo contains various info about the shutdown initiation of a
// channel.
-type ShutdownInfo struct {
- // DeliveryScript is the address that we have included in any previous
- // Shutdown message for a particular channel and so should include in
- // any future re-sends of the Shutdown message.
- DeliveryScript tlv.RecordT[tlv.TlvType0, lnwire.DeliveryAddress]
-
- // LocalInitiator is true if we sent a Shutdown message before ever
- // receiving a Shutdown message from the remote peer.
- LocalInitiator tlv.RecordT[tlv.TlvType1, bool]
-}
+type ShutdownInfo = cstate.ShutdownInfo
// NewShutdownInfo constructs a new ShutdownInfo object.
-func NewShutdownInfo(deliveryScript lnwire.DeliveryAddress,
- locallyInitiated bool) *ShutdownInfo {
-
- return &ShutdownInfo{
- DeliveryScript: tlv.NewRecordT[tlv.TlvType0](deliveryScript),
- LocalInitiator: tlv.NewPrimitiveRecord[tlv.TlvType1](
- locallyInitiated,
- ),
- }
-}
-
-// Closer identifies the ChannelParty that initiated the coop-closure process.
-func (s ShutdownInfo) Closer() lntypes.ChannelParty {
- if s.LocalInitiator.Val {
- return lntypes.Local
- }
-
- return lntypes.Remote
-}
+var NewShutdownInfo = cstate.NewShutdownInfo
-// encode serialises the ShutdownInfo to the given io.Writer.
-func (s *ShutdownInfo) encode(w io.Writer) error {
+// encodeShutdownInfo serialises the ShutdownInfo to the given io.Writer.
+func encodeShutdownInfo(s *ShutdownInfo, w io.Writer) error {
records := []tlv.Record{
s.DeliveryScript.Record(),
s.LocalInitiator.Record(),
diff --git a/chanstate/shutdown.go b/chanstate/shutdown.go
new file mode 100644
index 0000000..4c1dca3
--- /dev/null
+++ b/chanstate/shutdown.go
@@ -0,0 +1,41 @@
+package chanstate
+
+import (
+ "github.com/lightningnetwork/lnd/lntypes"
+ "github.com/lightningnetwork/lnd/lnwire"
+ "github.com/lightningnetwork/lnd/tlv"
+)
+
+// ShutdownInfo contains various info about the shutdown initiation of a
+// channel.
+type ShutdownInfo struct {
+ // DeliveryScript is the address that we have included in any previous
+ // Shutdown message for a particular channel and so should include in
+ // any future re-sends of the Shutdown message.
+ DeliveryScript tlv.RecordT[tlv.TlvType0, lnwire.DeliveryAddress]
+
+ // LocalInitiator is true if we sent a Shutdown message before ever
+ // receiving a Shutdown message from the remote peer.
+ LocalInitiator tlv.RecordT[tlv.TlvType1, bool]
+}
+
+// NewShutdownInfo constructs a new ShutdownInfo object.
+func NewShutdownInfo(deliveryScript lnwire.DeliveryAddress,
+ locallyInitiated bool) *ShutdownInfo {
+
+ return &ShutdownInfo{
+ DeliveryScript: tlv.NewRecordT[tlv.TlvType0](deliveryScript),
+ LocalInitiator: tlv.NewPrimitiveRecord[tlv.TlvType1](
+ locallyInitiated,
+ ),
+ }
+}
+
+// Closer identifies the ChannelParty that initiated the coop-closure process.
+func (s ShutdownInfo) Closer() lntypes.ChannelParty {
+ if s.LocalInitiator.Val {
+ return lntypes.Local
+ }
+
+ return lntypes.Remote
+}
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.