staticaddr: remove dead code across managers

Remove unused errChan fields from the loopin, openchannel, and withdraw
managers. These channels were declared and initialized but never read
from or written to.

Remove the unused activeLoopIns map from the loopin manager. The map
was only written to but never read, making it dead code.

Remove the stale withdraw.Store interface whose method signatures no
longer match the concrete SqlStore API used by the manager.

Remove unused config fields from openchannel.Config (Server,
AddressManager, ChainNotifier, Signer) and deposit.ManagerConfig
(AddressClient, SwapClient, ChainParams) along with their daemon
wiring. Also remove the now-orphaned openchannel.AddressManager
interface.

Remove the unused GetStaticAddress and Close methods from
address.SqlStore and the GetStaticAddress method from the address.Store
interface, as the codebase only uses GetAllStaticAddresses.
This commit is contained in:
Slyghtning 2026-03-05 09:59:55 +01:00
parent f80aee4dae
commit 0b295123e7
No known key found for this signature in database
GPG key ID: F82D456EA023C9BF
10 changed files with 2 additions and 112 deletions

View file

@ -610,12 +610,9 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
// Static address deposit manager setup.
depositStore := deposit.NewSqlStore(baseDb)
depoCfg := &deposit.ManagerConfig{
AddressClient: staticAddressClient,
AddressManager: staticAddressManager,
SwapClient: swapClient,
Store: depositStore,
WalletKit: d.lnd.WalletKit,
ChainParams: d.lnd.ChainParams,
ChainNotifier: d.lnd.ChainNotifier,
Signer: d.lnd.Signer,
}
@ -646,14 +643,10 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
// Static address deposit open channel manager setup.
openChannelCfg := &openchannel.Config{
Server: staticAddressClient,
AddressManager: staticAddressManager,
DepositManager: depositManager,
WithdrawalManager: withdrawalManager,
WalletKit: d.lnd.WalletKit,
ChainParams: d.lnd.ChainParams,
ChainNotifier: d.lnd.ChainNotifier,
Signer: d.lnd.Signer,
LightningClient: d.lnd.Client,
}
openChannelManager = openchannel.NewManager(openChannelCfg)

View file

@ -15,11 +15,6 @@ type Store interface {
// into the store.
CreateStaticAddress(ctx context.Context, addrParams *Parameters) error
// GetStaticAddress fetches static address parameters for a given
// address ID.
GetStaticAddress(ctx context.Context, pkScript []byte) (*Parameters,
error)
// GetAllStaticAddresses retrieves all static addresses from the store.
GetAllStaticAddresses(ctx context.Context) ([]*Parameters,
error)

View file

@ -41,18 +41,6 @@ func (s *SqlStore) CreateStaticAddress(ctx context.Context,
return s.baseDB.Queries.CreateStaticAddress(ctx, createArgs)
}
// GetStaticAddress retrieves static address parameters for a given pkScript.
func (s *SqlStore) GetStaticAddress(ctx context.Context,
pkScript []byte) (*Parameters, error) {
staticAddress, err := s.baseDB.Queries.GetStaticAddress(ctx, pkScript)
if err != nil {
return nil, err
}
return s.toAddressParameters(staticAddress)
}
// GetAllStaticAddresses returns all address known to the server.
func (s *SqlStore) GetAllStaticAddresses(ctx context.Context) ([]*Parameters,
error) {
@ -75,11 +63,6 @@ func (s *SqlStore) GetAllStaticAddresses(ctx context.Context) ([]*Parameters,
return result, nil
}
// Close closes the database connection.
func (s *SqlStore) Close() {
s.baseDB.DB.Close()
}
// toAddressParameters transforms a database representation of a static address
// to an AddressParameters struct.
func (s *SqlStore) toAddressParameters(row sqlc.StaticAddress) (

View file

@ -8,13 +8,10 @@ import (
"sync"
"time"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/fsm"
staticaddressrpc "github.com/lightninglabs/loop/swapserverrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lnwallet"
)
@ -40,17 +37,10 @@ const (
// ManagerConfig holds the configuration for the address manager.
type ManagerConfig struct {
// AddressClient is the client that communicates with the loop server
// to manage static addresses.
AddressClient staticaddressrpc.StaticAddressServerClient
// AddressManager is the address manager that is used to fetch static
// address parameters.
AddressManager AddressManager
// SwapClient provides loop rpc functionality.
SwapClient *loop.Client
// Store is the database store that is used to store static address
// related records.
Store Store
@ -59,10 +49,6 @@ type ManagerConfig struct {
// lnd's wallet.
WalletKit lndclient.WalletKitClient
// ChainParams is the chain configuration(mainnet, testnet...) this
// manager uses.
ChainParams *chaincfg.Params
// ChainNotifier is the chain notifier that is used to listen for new
// blocks.
ChainNotifier lndclient.ChainNotifierClient

View file

@ -345,11 +345,9 @@ func newManagerTestContext(t *testing.T) *ManagerTestContext {
)
cfg := &ManagerConfig{
AddressClient: mockStaticAddressClient,
AddressManager: mockAddressManager,
Store: mockStore,
WalletKit: mockLnd.WalletKit,
ChainParams: mockLnd.ChainParams,
ChainNotifier: mockChainNotifier,
Signer: mockLnd.Signer,
}

View file

@ -134,13 +134,8 @@ type Manager struct {
// has been canceled.
exitChan chan struct{}
// errChan forwards errors from the loop-in manager to the server.
errChan chan error
// currentHeight stores the currently best known block height.
currentHeight atomic.Uint32
activeLoopIns map[lntypes.Hash]*FSM
}
// NewManager creates a new deposit withdrawal manager.
@ -154,8 +149,6 @@ func NewManager(cfg *Config, currentHeight uint32) (*Manager, error) {
cfg: cfg,
newLoopInChan: make(chan *newSwapRequest),
exitChan: make(chan struct{}),
errChan: make(chan error),
activeLoopIns: make(map[lntypes.Hash]*FSM),
}
m.currentHeight.Store(currentHeight)
@ -566,19 +559,12 @@ func (m *Manager) recoverLoopIns(ctx context.Context) error {
}
// Create a state machine for a given loop-in.
var (
recovery = true
fsm *FSM
)
fsm, err = NewFSM(ctx, loopIn, m.cfg, recovery)
recovery := true
fsm, err := NewFSM(ctx, loopIn, m.cfg, recovery)
if err != nil {
return err
}
// Add the FSM to the active loop-ins map before sending
// the recover event to avoid a data race.
m.activeLoopIns[loopIn.SwapHash] = fsm
// Send the OnRecover event to the state machine.
go func() {
err := fsm.SendEvent(ctx, OnRecover, nil)
@ -825,8 +811,6 @@ func (m *Manager) startLoopInFsm(ctx context.Context,
return nil, err
}
m.activeLoopIns[loopIn.SwapHash] = loopInFsm
return loopIn, nil
}

View file

@ -6,24 +6,11 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/loop/fsm"
"github.com/lightninglabs/loop/staticaddr/address"
"github.com/lightninglabs/loop/staticaddr/deposit"
"github.com/lightninglabs/loop/staticaddr/script"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
)
// AddressManager handles fetching of address parameters.
type AddressManager interface {
// GetStaticAddressParameters returns the static address parameters.
GetStaticAddressParameters(ctx context.Context) (*address.Parameters,
error)
// GetStaticAddress returns the deposit address for the given
// client and server public keys.
GetStaticAddress(ctx context.Context) (*script.StaticAddress, error)
}
type DepositManager interface {
// AllOutpointsActiveDeposits returns all deposits that are in the
// given state. If the state filter is fsm.StateTypeNone, all deposits

View file

@ -19,7 +19,6 @@ import (
"github.com/lightninglabs/loop/staticaddr/deposit"
"github.com/lightninglabs/loop/staticaddr/staticutil"
"github.com/lightninglabs/loop/staticaddr/withdraw"
serverrpc "github.com/lightninglabs/loop/swapserverrpc"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
@ -48,14 +47,6 @@ var (
// Config is the configuration struct for the open channel manager.
type Config struct {
// Server is the client that calls the swap server rpcs to negotiate
// static address withdrawals.
Server serverrpc.StaticAddressServerClient
// AddressManager gives the withdrawal manager access to static address
// parameters.
AddressManager AddressManager
// DepositManager gives the withdrawal manager access to the deposits
// enabling it to create and manage withdrawals.
DepositManager DepositManager
@ -72,13 +63,6 @@ type Config struct {
// manager uses.
ChainParams *chaincfg.Params
// ChainNotifier is the chain notifier that is used to listen for new
// blocks.
ChainNotifier lndclient.ChainNotifierClient
// Signer is the signer client that is used to sign transactions.
Signer lndclient.SignerClient
// LightningClient is the lnd client that is used to open channels.
LightningClient lndclient.LightningClient
}
@ -104,9 +88,6 @@ type Manager struct {
// exitChan signals subroutines that the open channel is exiting.
exitChan chan struct{}
// errChan forwards errors from the open channel to the server.
errChan chan error
}
// NewManager creates a new manager instance.
@ -115,7 +96,6 @@ func NewManager(cfg *Config) *Manager {
cfg: cfg,
exitChan: make(chan struct{}),
newOpenChannelRequestChan: make(chan newOpenChannelRequest),
errChan: make(chan error),
}
return m

View file

@ -10,18 +10,6 @@ import (
"github.com/lightninglabs/loop/staticaddr/script"
)
// Store is the database interface that is used to store and retrieve
// static address withdrawals.
type Store interface {
// CreateWithdrawal inserts a withdrawal into the store.
CreateWithdrawal(ctx context.Context, tx *wire.MsgTx,
confirmationHeight uint32, deposits []*deposit.Deposit,
changePkScript []byte) error
// GetAllWithdrawals retrieves all withdrawals.
GetAllWithdrawals(ctx context.Context) ([]Withdrawal, error)
}
// AddressManager handles fetching of address parameters.
type AddressManager interface {
// GetStaticAddressParameters returns the static address parameters.

View file

@ -129,9 +129,6 @@ type Manager struct {
// exitChan signals subroutines that the withdrawal manager is exiting.
exitChan chan struct{}
// errChan forwards errors from the withdrawal manager to the server.
errChan chan error
// initiationHeight stores the currently best known block height.
initiationHeight atomic.Uint32
@ -152,7 +149,6 @@ func NewManager(cfg *ManagerConfig, currentHeight uint32) (*Manager, error) {
finalizedWithdrawalTxns: make(map[chainhash.Hash]*wire.MsgTx),
exitChan: make(chan struct{}),
newWithdrawalRequestChan: make(chan newWithdrawalRequest),
errChan: make(chan error),
}
m.initiationHeight.Store(currentHeight)