mirror of
https://github.com/lightningnetwork/lnd.git
synced 2026-08-13 12:32:48 +02:00
In this commit, we implement the server-side handler for the DeleteForwardingHistory RPC, connecting the proto definition to the database layer through the ForwardingLogDB interface on RouterBackend. The handler resolves the time specification from the request oneof: an absolute Unix timestamp is used directly, while a relative duration string is parsed via parseDuration and resolved against the current clock time. We use the injected clock (RouterBackend.Clock) rather than time.Now to keep the handler testable. A configurable minimum age guard (MinFwdHistoryAge, defaulting to 1h) prevents accidental deletion of recent events. The minimum age can be overridden via --routerrpc.min-fwd-history-age for environments such as integration tests that need a shorter threshold. The context is threaded through to DeleteForwardingEvents so that client cancellation or deadline expiry aborts the deletion between batches. Batches already committed at cancellation time are permanent, but the operation is safe to re-run since deletion is idempotent.
92 lines
3.6 KiB
Go
92 lines
3.6 KiB
Go
//go:build integration
|
|
|
|
package lncfg
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/lightningnetwork/lnd/fn/v2"
|
|
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
|
|
)
|
|
|
|
// IsDevBuild returns a bool to indicate whether we are in a development
|
|
// environment.
|
|
//
|
|
// NOTE: always return true here.
|
|
func IsDevBuild() bool {
|
|
return true
|
|
}
|
|
|
|
// DevConfig specifies configs used for integration tests. These configs can
|
|
// only be used in tests and must NOT be exported for production usage.
|
|
//
|
|
//nolint:ll
|
|
type DevConfig struct {
|
|
ProcessChannelReadyWait time.Duration `long:"processchannelreadywait" description:"Time to sleep before processing remote node's channel_ready message."`
|
|
ReservationTimeout time.Duration `long:"reservationtimeout" description:"The maximum time we keep a pending channel open flow in memory."`
|
|
ZombieSweeperInterval time.Duration `long:"zombiesweeperinterval" description:"The time interval at which channel opening flows are evaluated for zombie status."`
|
|
UnsafeDisconnect bool `long:"unsafedisconnect" description:"Allows the rpcserver to intentionally disconnect from peers with open channels."`
|
|
MaxWaitNumBlocksFundingConf uint32 `long:"maxwaitnumblocksfundingconf" description:"Maximum blocks to wait for funding confirmation before discarding non-initiated channels."`
|
|
UnsafeConnect bool `long:"unsafeconnect" description:"Allow the rpcserver to connect to a peer even if there's already a connection."`
|
|
ForceChannelCloseConfs uint32 `long:"force-channel-close-confs" description:"Force a specific number of confirmations for channel closes (dev/test only)"`
|
|
MinFwdHistoryAge time.Duration `long:"min-fwd-history-age" description:"Minimum age of forwarding events before they can be deleted via DeleteForwardingHistory (dev/test only, default: 1h)"`
|
|
}
|
|
|
|
// ChannelReadyWait returns the config value `ProcessChannelReadyWait`.
|
|
func (d *DevConfig) ChannelReadyWait() time.Duration {
|
|
return d.ProcessChannelReadyWait
|
|
}
|
|
|
|
// GetReservationTimeout returns the config value for `ReservationTimeout`.
|
|
func (d *DevConfig) GetReservationTimeout() time.Duration {
|
|
if d.ReservationTimeout == 0 {
|
|
return chanfunding.DefaultReservationTimeout
|
|
}
|
|
|
|
return d.ReservationTimeout
|
|
}
|
|
|
|
// GetZombieSweeperInterval returns the config value for`ZombieSweeperInterval`.
|
|
func (d *DevConfig) GetZombieSweeperInterval() time.Duration {
|
|
if d.ZombieSweeperInterval == 0 {
|
|
return DefaultZombieSweeperInterval
|
|
}
|
|
|
|
return d.ZombieSweeperInterval
|
|
}
|
|
|
|
// GetUnsafeDisconnect returns the config value `UnsafeDisconnect`.
|
|
func (d *DevConfig) GetUnsafeDisconnect() bool {
|
|
return d.UnsafeDisconnect
|
|
}
|
|
|
|
// GetMaxWaitNumBlocksFundingConf returns the config value for
|
|
// `MaxWaitNumBlocksFundingConf`.
|
|
func (d *DevConfig) GetMaxWaitNumBlocksFundingConf() uint32 {
|
|
if d.MaxWaitNumBlocksFundingConf == 0 {
|
|
return DefaultMaxWaitNumBlocksFundingConf
|
|
}
|
|
|
|
return d.MaxWaitNumBlocksFundingConf
|
|
}
|
|
|
|
// GetUnsafeConnect returns the config value `UnsafeConnect`.
|
|
func (d *DevConfig) GetUnsafeConnect() bool {
|
|
return d.UnsafeConnect
|
|
}
|
|
|
|
// GetMinFwdHistoryAge returns the minimum age for forwarding history deletion.
|
|
// Returns 0 if unset, which causes the caller to use the default (1h).
|
|
func (d *DevConfig) GetMinFwdHistoryAge() time.Duration {
|
|
return d.MinFwdHistoryAge
|
|
}
|
|
|
|
// ChannelCloseConfs returns the forced confirmation count if set, or None if
|
|
// the default behavior should be used.
|
|
func (d *DevConfig) ChannelCloseConfs() fn.Option[uint32] {
|
|
if d.ForceChannelCloseConfs == 0 {
|
|
return fn.None[uint32]()
|
|
}
|
|
|
|
return fn.Some(d.ForceChannelCloseConfs)
|
|
}
|