Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
309923a
chanstate: make store channel types generic
ziggie1984 May 14, 2026
03a5fa0
chanstate: move channel type flags
ziggie1984 May 14, 2026
761a1af
chanstate: move open channel errors
ziggie1984 May 14, 2026
985fd07
chanstate: move shutdown metadata
ziggie1984 May 14, 2026
b46067d
chanstate: add open channel lifecycle store
ziggie1984 May 14, 2026
210273b
chanstate: add open channel status store
ziggie1984 May 14, 2026
5cd0337
chanstate: add open channel close stores
ziggie1984 May 14, 2026
b12f407
chanstate: add pending channel setup store
ziggie1984 May 14, 2026
923ff92
chanstate: move commitment value types
ziggie1984 May 14, 2026
f18af1c
chanstate: move log update type
ziggie1984 May 14, 2026
d4d80a5
chanstate: add commitment store facet
ziggie1984 May 14, 2026
33824d5
chanstate: move commitment diff types
ziggie1984 May 14, 2026
9a4313b
chanstate: add remote commit chain store
ziggie1984 May 14, 2026
c13cab7
chanstate: add commit lookup store
ziggie1984 May 14, 2026
e2316c9
chanstate: add revocation insert store
ziggie1984 May 14, 2026
9588e3e
chanstate: move forwarding package types
ziggie1984 May 14, 2026
d53c2f5
chanstate: add commit tail store
ziggie1984 May 14, 2026
5d77721
chanstate: add forwarding package store
ziggie1984 May 14, 2026
773af30
chanstate: add commitment read stores
ziggie1984 May 14, 2026
15085f3
channeldb: move revocation log reads
ziggie1984 May 14, 2026
f0147ba
chanstate: move revocation log types
ziggie1984 May 14, 2026
f8bb680
chanstate: add previous state lookup
ziggie1984 May 14, 2026
1127e35
channeldb: move revocation tail helper
ziggie1984 May 14, 2026
6af06f5
channeldb: store channel state by interface
ziggie1984 May 14, 2026
d33c055
channeldb: split out channel kv helpers
ziggie1984 May 14, 2026
7b8211d
channeldb: add channel store accessors
ziggie1984 May 15, 2026
52e4766
channeldb: derive channel packagers
ziggie1984 May 15, 2026
a67ec68
chanstate: move channel snapshot type
ziggie1984 May 15, 2026
35b8cd9
chanstate: move taproot channel helpers
ziggie1984 May 15, 2026
3bc1671
channeldb: add store status check
ziggie1984 May 15, 2026
377c1a5
chanstate: move open channel type
ziggie1984 May 15, 2026
c7b1455
chanstate: remove store generics
ziggie1984 May 15, 2026
d331829
chanstate: fix htlc copy
ziggie1984 May 15, 2026
fb6b334
chanstate: use channel types in consumers
ziggie1984 May 15, 2026
623f007
chanstate: use channel types in interfaces
ziggie1984 May 15, 2026
4431e27
chanstate: use channel types in fitness
ziggie1984 May 15, 2026
622fcb1
chanstate: use htlc type in beacon
ziggie1984 May 15, 2026
7c34c9b
chanstate: use channel type in status manager
ziggie1984 May 15, 2026
ba8003a
chanstate: use channel type in lnpeer
ziggie1984 May 15, 2026
d72416e
chanstate: use channel types in backups
ziggie1984 May 15, 2026
aa59dcf
chanstate: use channel type in backup notifier
ziggie1984 May 15, 2026
e616615
chanstate: use channel type in wallet rpc
ziggie1984 May 15, 2026
b9f0016
chanstate: use channel types in switch config
ziggie1984 May 15, 2026
712ddc1
chanstate: use channel types in local chans
ziggie1984 May 15, 2026
f0b1e46
chanstate: use channel type in gossiper
ziggie1984 May 15, 2026
77b6816
chanstate: use channel types in watchtower
ziggie1984 May 15, 2026
fb69b4d
chanstate: use channel types in link config
ziggie1984 May 15, 2026
08bec14
funding: use channel state open channel
ziggie1984 May 16, 2026
6bd7997
server: use channel state open channel
ziggie1984 May 16, 2026
bc7a6c1
rpcserver: use channel state open channel
ziggie1984 May 16, 2026
3b1b833
chanrestore: use channel state open channel
ziggie1984 May 16, 2026
e439965
contractcourt: use channel state open channel
ziggie1984 May 16, 2026
53cc997
lnwallet: use channel state open channel
ziggie1984 May 16, 2026
d5d739b
peer: use channel state open channel
ziggie1984 May 16, 2026
f101356
htlcswitch: use channel state open channel
ziggie1984 May 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions chanbackup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/fn/v2"
)

Expand All @@ -14,19 +15,19 @@ import (
// commitment transaction broadcast.
type LiveChannelSource interface {
// FetchAllChannels returns all known live channels.
FetchAllChannels() ([]*channeldb.OpenChannel, error)
FetchAllChannels() ([]*chanstate.OpenChannel, error)

// FetchChannel attempts to locate a live channel identified by the
// passed chanPoint. Optionally an existing db tx can be supplied.
FetchChannel(chanPoint wire.OutPoint) (*channeldb.OpenChannel, error)
FetchChannel(chanPoint wire.OutPoint) (*chanstate.OpenChannel, error)
}

// assembleChanBackup attempts to assemble a static channel backup for the
// passed open channel. The backup includes all information required to restore
// the channel, as well as addressing information so we can find the peer and
// reconnect to them to initiate the protocol.
func assembleChanBackup(ctx context.Context, addrSource channeldb.AddrSource,
openChan *channeldb.OpenChannel) (*Single, error) {
openChan *chanstate.OpenChannel) (*Single, error) {

log.Debugf("Crafting backup for ChannelPoint(%v)",
openChan.FundingOutpoint)
Expand Down Expand Up @@ -55,7 +56,7 @@ func assembleChanBackup(ctx context.Context, addrSource channeldb.AddrSource,
// in loss of funds! This may happen if an outdated channel backup is attempted
// to be used to force close the channel.
func buildCloseTxInputs(
targetChan *channeldb.OpenChannel) fn.Option[CloseTxInputs] {
targetChan *chanstate.OpenChannel) fn.Option[CloseTxInputs] {

log.Debugf("Crafting CloseTxInputs for ChannelPoint(%v)",
targetChan.FundingOutpoint)
Expand Down
14 changes: 8 additions & 6 deletions chanbackup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/chanstate"
"github.com/stretchr/testify/require"
)

type mockChannelSource struct {
chans map[wire.OutPoint]*channeldb.OpenChannel
chans map[wire.OutPoint]*chanstate.OpenChannel

failQuery bool

Expand All @@ -22,17 +22,19 @@ type mockChannelSource struct {

func newMockChannelSource() *mockChannelSource {
return &mockChannelSource{
chans: make(map[wire.OutPoint]*channeldb.OpenChannel),
chans: make(map[wire.OutPoint]*chanstate.OpenChannel),
addrs: make(map[[33]byte][]net.Addr),
}
}

func (m *mockChannelSource) FetchAllChannels() ([]*channeldb.OpenChannel, error) {
func (m *mockChannelSource) FetchAllChannels() (
[]*chanstate.OpenChannel, error) {

if m.failQuery {
return nil, fmt.Errorf("fail")
}

chans := make([]*channeldb.OpenChannel, 0, len(m.chans))
chans := make([]*chanstate.OpenChannel, 0, len(m.chans))
for _, channel := range m.chans {
chans = append(chans, channel)
}
Expand All @@ -41,7 +43,7 @@ func (m *mockChannelSource) FetchAllChannels() ([]*channeldb.OpenChannel, error)
}

func (m *mockChannelSource) FetchChannel(chanPoint wire.OutPoint) (
*channeldb.OpenChannel, error) {
*chanstate.OpenChannel, error) {

if m.failQuery {
return nil, fmt.Errorf("fail")
Expand Down
4 changes: 2 additions & 2 deletions chanbackup/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sync/atomic"

"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnutils"
)
Expand All @@ -31,7 +31,7 @@ type Swapper interface {
// ChannelWithAddrs bundles an open channel along with all the addresses for
// the channel peer.
type ChannelWithAddrs struct {
*channeldb.OpenChannel
*chanstate.OpenChannel

// Addrs is the set of addresses that we can use to reach the target
// peer.
Expand Down
8 changes: 4 additions & 4 deletions chanbackup/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnencrypt"
Expand Down Expand Up @@ -169,7 +169,7 @@ type Single struct {
//
// NOTE: Of the items in the ChannelConstraints, we only write the CSV
// delay.
LocalChanCfg channeldb.ChannelConfig
LocalChanCfg chanstate.ChannelConfig

// RemoteChanCfg is the remote channel confirmation. We store this as
// well since we'll need some of their keys to re-derive things like
Expand All @@ -178,7 +178,7 @@ type Single struct {
//
// NOTE: Of the items in the ChannelConstraints, we only write the CSV
// delay.
RemoteChanCfg channeldb.ChannelConfig
RemoteChanCfg chanstate.ChannelConfig

// ShaChainRootDesc describes how to derive the private key that was
// used as the shachain root for this channel.
Expand Down Expand Up @@ -234,7 +234,7 @@ type CloseTxInputs struct {
// connect to the channel peer. If possible, we include the data needed to
// produce a force close transaction from the most recent state using externally
// provided private key.
func NewSingle(channel *channeldb.OpenChannel,
func NewSingle(channel *chanstate.OpenChannel,
nodeAddrs []net.Addr) Single {

var shaChainRootDesc keychain.KeyDescriptor
Expand Down
22 changes: 11 additions & 11 deletions chanbackup/single_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnencrypt"
Expand Down Expand Up @@ -135,7 +135,7 @@ func assertSingleEqual(t *testing.T, a, b Single) {
}
}

func genRandomOpenChannelShell() (*channeldb.OpenChannel, error) {
func genRandomOpenChannelShell() (*chanstate.OpenChannel, error) {
var testPriv [32]byte
if _, err := rand.Read(testPriv[:]); err != nil {
return nil, err
Expand All @@ -162,11 +162,11 @@ func genRandomOpenChannelShell() (*channeldb.OpenChannel, error) {
isInitiator = true
}

chanType := channeldb.ChannelType(rand.Intn(1 << 12))
chanType := chanstate.ChannelType(rand.Intn(1 << 12))

localCfg := channeldb.ChannelConfig{
ChannelStateBounds: channeldb.ChannelStateBounds{},
CommitmentParams: channeldb.CommitmentParams{
localCfg := chanstate.ChannelConfig{
ChannelStateBounds: chanstate.ChannelStateBounds{},
CommitmentParams: chanstate.CommitmentParams{
CsvDelay: uint16(rand.Int63()),
},
MultiSigKey: keychain.KeyDescriptor{
Expand Down Expand Up @@ -201,8 +201,8 @@ func genRandomOpenChannelShell() (*channeldb.OpenChannel, error) {
},
}

remoteCfg := channeldb.ChannelConfig{
CommitmentParams: channeldb.CommitmentParams{
remoteCfg := chanstate.ChannelConfig{
CommitmentParams: chanstate.CommitmentParams{
CsvDelay: uint16(rand.Int63()),
},
MultiSigKey: keychain.KeyDescriptor{
Expand All @@ -222,14 +222,14 @@ func genRandomOpenChannelShell() (*channeldb.OpenChannel, error) {
},
}

var localCommit channeldb.ChannelCommitment
var localCommit chanstate.ChannelCommitment
if chanType.IsTaproot() {
var commitSig [64]byte
if _, err := rand.Read(commitSig[:]); err != nil {
return nil, err
}

localCommit = channeldb.ChannelCommitment{
localCommit = chanstate.ChannelCommitment{
CommitTx: sampleCommitTx,
CommitSig: commitSig[:],
CommitHeight: rand.Uint64(),
Expand All @@ -245,7 +245,7 @@ func genRandomOpenChannelShell() (*channeldb.OpenChannel, error) {
tapscriptRootOption = fn.Some(tapscriptRoot)
}

return &channeldb.OpenChannel{
return &chanstate.OpenChannel{
ChainHash: chainHash,
ChanType: chanType,
IsInitiator: isInitiator,
Expand Down
3 changes: 2 additions & 1 deletion chanfitness/chaneventstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channelnotifier"
"github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/peernotifier"
"github.com/lightningnetwork/lnd/routing/route"
Expand Down Expand Up @@ -84,7 +85,7 @@ type Config struct {
// GetOpenChannels provides a list of existing open channels which is
// used to populate the ChannelEventStore with a set of channels on
// startup.
GetOpenChannels func() ([]*channeldb.OpenChannel, error)
GetOpenChannels func() ([]*chanstate.OpenChannel, error)

// Clock is the time source that the subsystem uses, provided here
// for ease of testing.
Expand Down
5 changes: 3 additions & 2 deletions chanfitness/chaneventstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/subscribe"
Expand Down Expand Up @@ -35,7 +36,7 @@ func TestStartStoreError(t *testing.T) {
name string
ChannelEvents func() (subscribe.Subscription, error)
PeerEvents func() (subscribe.Subscription, error)
GetChannels func() ([]*channeldb.OpenChannel, error)
GetChannels func() ([]*chanstate.OpenChannel, error)
}{
{
name: "Channel events fail",
Expand All @@ -50,7 +51,7 @@ func TestStartStoreError(t *testing.T) {
name: "Get open channels fails",
ChannelEvents: okSubscribeFunc,
PeerEvents: okSubscribeFunc,
GetChannels: func() ([]*channeldb.OpenChannel, error) {
GetChannels: func() ([]*chanstate.OpenChannel, error) {
return nil, errors.New("intentional test err")
},
},
Expand Down
7 changes: 4 additions & 3 deletions chanfitness/chaneventstore_testctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channelnotifier"
"github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/peernotifier"
"github.com/lightningnetwork/lnd/routing/route"
Expand Down Expand Up @@ -72,7 +73,7 @@ func newChanEventStoreTestCtx(t *testing.T) *chanEventStoreTestCtx {
SubscribePeerEvents: func() (subscribe.Subscription, error) {
return testCtx.peerSubscription, nil
},
GetOpenChannels: func() ([]*channeldb.OpenChannel, error) {
GetOpenChannels: func() ([]*chanstate.OpenChannel, error) {
return nil, nil
},
WriteFlapCount: func(updates map[route.Vertex]*channeldb.FlapCount) error {
Expand Down Expand Up @@ -181,7 +182,7 @@ func (c *chanEventStoreTestCtx) closeChannel(channel wire.OutPoint,
peer *btcec.PublicKey) {

update := channelnotifier.ClosedChannelEvent{
CloseSummary: &channeldb.ChannelCloseSummary{
CloseSummary: &chanstate.ChannelCloseSummary{
ChanPoint: channel,
RemotePub: peer,
},
Expand Down Expand Up @@ -221,7 +222,7 @@ func (c *chanEventStoreTestCtx) sendChannelOpenedUpdate(pubkey *btcec.PublicKey,
channel wire.OutPoint) {

update := channelnotifier.OpenChannelEvent{
Channel: &channeldb.OpenChannel{
Channel: &chanstate.OpenChannel{
FundingOutpoint: channel,
IdentityPub: pubkey,
},
Expand Down
3 changes: 2 additions & 1 deletion channel_notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/lightningnetwork/lnd/chanbackup"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channelnotifier"
"github.com/lightningnetwork/lnd/chanstate"
)

// channelNotifier is an implementation of the chanbackup.ChannelNotifier
Expand Down Expand Up @@ -46,7 +47,7 @@ func (c *channelNotifier) SubscribeChans(ctx context.Context,
// sendChanOpenUpdate is a closure that sends a ChannelEvent to the
// chanUpdates channel to inform subscribers about new pending or
// confirmed channels.
sendChanOpenUpdate := func(newOrPendingChan *channeldb.OpenChannel) {
sendChanOpenUpdate := func(newOrPendingChan *chanstate.OpenChannel) {
_, nodeAddrs, err := c.addrs.AddrsForNode(
ctx, newOrPendingChan.IdentityPub,
)
Expand Down
Loading
Loading