multi: add keep-failed-payment-attempts flag
This commit is contained in:
1 parent
e6277986fd
commit
8291e8a170
7 files changed
+52
-14
No files matched your search
@@ -251,6 +251,7 @@ type DB struct {
|
|||||||
graph *ChannelGraph
|
graph *ChannelGraph
|
||||||
clock clock.Clock
|
clock clock.Clock
|
||||||
dryRun bool
|
dryRun bool
|
||||||
|
keepFailedPaymentAttempts bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open opens or creates channeldb. Any necessary schemas migrations due
|
// Open opens or creates channeldb. Any necessary schemas migrations due
|
||||||
@@ -305,6 +306,7 @@ func CreateWithBackend(backend kvdb.Backend, modifiers ...OptionModifier) (*DB,
|
|||||||
},
|
},
|
||||||
clock: opts.clock,
|
clock: opts.clock,
|
||||||
dryRun: opts.dryRun,
|
dryRun: opts.dryRun,
|
||||||
|
keepFailedPaymentAttempts: opts.keepFailedPaymentAttempts,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the parent pointer (only used in tests).
|
// Set the parent pointer (only used in tests).
|
||||||
|
|||||||
@@ -61,6 +61,10 @@ type Options struct {
|
|||||||
// dryRun will fail to commit a successful migration when opening the
|
// dryRun will fail to commit a successful migration when opening the
|
||||||
// database if set to true.
|
// database if set to true.
|
||||||
dryRun bool
|
dryRun bool
|
||||||
|
|
||||||
|
// keepFailedPaymentAttempts determines whether failed htlc attempts
|
||||||
|
// are kept on disk or removed to save space.
|
||||||
|
keepFailedPaymentAttempts bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultOptions returns an Options populated with default values.
|
// DefaultOptions returns an Options populated with default values.
|
||||||
@@ -164,3 +168,11 @@ func OptionDryRunMigration(dryRun bool) OptionModifier {
|
|||||||
o.dryRun = dryRun
|
o.dryRun = dryRun
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OptionKeepFailedPaymentAttempts controls whether failed payment attempts are
|
||||||
|
// kept on disk after a payment settles.
|
||||||
|
func OptionKeepFailedPaymentAttempts(keepFailedPaymentAttempts bool) OptionModifier {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.keepFailedPaymentAttempts = keepFailedPaymentAttempts
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -199,6 +199,10 @@ const (
|
|||||||
// defaultCoinSelectionStrategy is the coin selection strategy that is
|
// defaultCoinSelectionStrategy is the coin selection strategy that is
|
||||||
// used by default to fund transactions.
|
// used by default to fund transactions.
|
||||||
defaultCoinSelectionStrategy = "largest"
|
defaultCoinSelectionStrategy = "largest"
|
||||||
|
|
||||||
|
// defaultKeepFailedPaymentAttempts is the default setting for whether
|
||||||
|
// to keep failed payments in the database.
|
||||||
|
defaultKeepFailedPaymentAttempts = false
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -362,6 +366,8 @@ type Config struct {
|
|||||||
|
|
||||||
ChannelCommitBatchSize uint32 `long:"channel-commit-batch-size" description:"The maximum number of channel state updates that is accumulated before signing a new commitment."`
|
ChannelCommitBatchSize uint32 `long:"channel-commit-batch-size" description:"The maximum number of channel state updates that is accumulated before signing a new commitment."`
|
||||||
|
|
||||||
|
KeepFailedPaymentAttempts bool `long:"keep-failed-payment-attempts" description:"Keeps persistent record of all failed payment attempts for successfully settled payments."`
|
||||||
|
|
||||||
DefaultRemoteMaxHtlcs uint16 `long:"default-remote-max-htlcs" description:"The default max_htlc applied when opening or accepting channels. This value limits the number of concurrent HTLCs that the remote party can add to the commitment. The maximum possible value is 483."`
|
DefaultRemoteMaxHtlcs uint16 `long:"default-remote-max-htlcs" description:"The default max_htlc applied when opening or accepting channels. This value limits the number of concurrent HTLCs that the remote party can add to the commitment. The maximum possible value is 483."`
|
||||||
|
|
||||||
NumGraphSyncPeers int `long:"numgraphsyncpeers" description:"The number of peers that we should receive new graph updates from. This option can be tuned to save bandwidth for light clients or routing nodes."`
|
NumGraphSyncPeers int `long:"numgraphsyncpeers" description:"The number of peers that we should receive new graph updates from. This option can be tuned to save bandwidth for light clients or routing nodes."`
|
||||||
@@ -625,6 +631,7 @@ func DefaultConfig() Config {
|
|||||||
PendingCommitInterval: defaultPendingCommitInterval,
|
PendingCommitInterval: defaultPendingCommitInterval,
|
||||||
ChannelCommitBatchSize: defaultChannelCommitBatchSize,
|
ChannelCommitBatchSize: defaultChannelCommitBatchSize,
|
||||||
CoinSelectionStrategy: defaultCoinSelectionStrategy,
|
CoinSelectionStrategy: defaultCoinSelectionStrategy,
|
||||||
|
KeepFailedPaymentAttempts: defaultKeepFailedPaymentAttempts,
|
||||||
RemoteSigner: &lncfg.RemoteSigner{
|
RemoteSigner: &lncfg.RemoteSigner{
|
||||||
Timeout: lncfg.DefaultRemoteSignerRPCTimeout,
|
Timeout: lncfg.DefaultRemoteSignerRPCTimeout,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -852,6 +852,7 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
|
|||||||
channeldb.OptionSetBatchCommitInterval(cfg.DB.BatchCommitInterval),
|
channeldb.OptionSetBatchCommitInterval(cfg.DB.BatchCommitInterval),
|
||||||
channeldb.OptionDryRunMigration(cfg.DryRunMigration),
|
channeldb.OptionDryRunMigration(cfg.DryRunMigration),
|
||||||
channeldb.OptionSetUseGraphCache(!cfg.DB.NoGraphCache),
|
channeldb.OptionSetUseGraphCache(!cfg.DB.NoGraphCache),
|
||||||
|
channeldb.OptionKeepFailedPaymentAttempts(cfg.KeepFailedPaymentAttempts),
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want to pre-allocate the channel graph cache according to what we
|
// We want to pre-allocate the channel graph cache according to what we
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ var (
|
|||||||
func TestControlTowerSubscribeUnknown(t *testing.T) {
|
func TestControlTowerSubscribeUnknown(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
db, err := initDB()
|
db, err := initDB(false)
|
||||||
require.NoError(t, err, "unable to init db")
|
require.NoError(t, err, "unable to init db")
|
||||||
|
|
||||||
pControl := NewControlTower(channeldb.NewPaymentControl(db))
|
pControl := NewControlTower(channeldb.NewPaymentControl(db))
|
||||||
@@ -65,7 +65,7 @@ func TestControlTowerSubscribeUnknown(t *testing.T) {
|
|||||||
func TestControlTowerSubscribeSuccess(t *testing.T) {
|
func TestControlTowerSubscribeSuccess(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
db, err := initDB()
|
db, err := initDB(false)
|
||||||
require.NoError(t, err, "unable to init db")
|
require.NoError(t, err, "unable to init db")
|
||||||
|
|
||||||
pControl := NewControlTower(channeldb.NewPaymentControl(db))
|
pControl := NewControlTower(channeldb.NewPaymentControl(db))
|
||||||
@@ -165,16 +165,24 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
|
|||||||
func TestPaymentControlSubscribeFail(t *testing.T) {
|
func TestPaymentControlSubscribeFail(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
t.Run("register attempt", func(t *testing.T) {
|
t.Run("register attempt, keep failed payments", func(t *testing.T) {
|
||||||
testPaymentControlSubscribeFail(t, true)
|
testPaymentControlSubscribeFail(t, true, true)
|
||||||
})
|
})
|
||||||
t.Run("no register attempt", func(t *testing.T) {
|
t.Run("register attempt, delete failed payments", func(t *testing.T) {
|
||||||
testPaymentControlSubscribeFail(t, false)
|
testPaymentControlSubscribeFail(t, true, false)
|
||||||
|
})
|
||||||
|
t.Run("no register attempt, keep failed payments", func(t *testing.T) {
|
||||||
|
testPaymentControlSubscribeFail(t, false, true)
|
||||||
|
})
|
||||||
|
t.Run("no register attempt, delete failed payments", func(t *testing.T) {
|
||||||
|
testPaymentControlSubscribeFail(t, false, false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testPaymentControlSubscribeFail(t *testing.T, registerAttempt bool) {
|
func testPaymentControlSubscribeFail(t *testing.T, registerAttempt,
|
||||||
db, err := initDB()
|
keepFailedPaymentAttempts bool) {
|
||||||
|
|
||||||
|
db, err := initDB(keepFailedPaymentAttempts)
|
||||||
require.NoError(t, err, "unable to init db")
|
require.NoError(t, err, "unable to init db")
|
||||||
|
|
||||||
pControl := NewControlTower(channeldb.NewPaymentControl(db))
|
pControl := NewControlTower(channeldb.NewPaymentControl(db))
|
||||||
@@ -228,8 +236,8 @@ func testPaymentControlSubscribeFail(t *testing.T, registerAttempt bool) {
|
|||||||
subscriber2, err := pControl.SubscribePayment(info.PaymentIdentifier)
|
subscriber2, err := pControl.SubscribePayment(info.PaymentIdentifier)
|
||||||
require.NoError(t, err, "expected subscribe to succeed, but got")
|
require.NoError(t, err, "expected subscribe to succeed, but got")
|
||||||
|
|
||||||
// We expect all subscribers to now report the final outcome followed by
|
// We expect both subscribers to now report the final outcome followed
|
||||||
// no other events.
|
// by no other events.
|
||||||
subscribers := []*ControlTowerSubscriber{
|
subscribers := []*ControlTowerSubscriber{
|
||||||
subscriber1, subscriber2,
|
subscriber1, subscriber2,
|
||||||
}
|
}
|
||||||
@@ -286,13 +294,17 @@ func testPaymentControlSubscribeFail(t *testing.T, registerAttempt bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initDB() (*channeldb.DB, error) {
|
func initDB(keepFailedPaymentAttempts bool) (*channeldb.DB, error) {
|
||||||
tempPath, err := ioutil.TempDir("", "routingdb")
|
tempPath, err := ioutil.TempDir("", "routingdb")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := channeldb.Open(tempPath)
|
db, err := channeldb.Open(
|
||||||
|
tempPath, channeldb.OptionKeepFailedPaymentAttempts(
|
||||||
|
keepFailedPaymentAttempts,
|
||||||
|
),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func (ps paymentState) terminated() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// needWaitForShards returns a bool to specify whether we need to wait for the
|
// needWaitForShards returns a bool to specify whether we need to wait for the
|
||||||
// outcome of the shanrdHandler.
|
// outcome of the shardHandler.
|
||||||
func (ps paymentState) needWaitForShards() bool {
|
func (ps paymentState) needWaitForShards() bool {
|
||||||
// If we have in flight shards and the payment is in final stage, we
|
// If we have in flight shards and the payment is in final stage, we
|
||||||
// need to wait for the outcomes from the shards. Or if we have no more
|
// need to wait for the outcomes from the shards. Or if we have no more
|
||||||
@@ -279,7 +279,7 @@ lifecycle:
|
|||||||
continue lifecycle
|
continue lifecycle
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this route will consume the last remeining amount to send
|
// If this route will consume the last remaining amount to send
|
||||||
// to the receiver, this will be our last shard (for now).
|
// to the receiver, this will be our last shard (for now).
|
||||||
lastShard := rt.ReceiverAmt() == currentState.remainingAmt
|
lastShard := rt.ReceiverAmt() == currentState.remainingAmt
|
||||||
|
|
||||||
|
|||||||
@@ -311,6 +311,10 @@
|
|||||||
; a new commitment.
|
; a new commitment.
|
||||||
; channel-commit-batch-size=10
|
; channel-commit-batch-size=10
|
||||||
|
|
||||||
|
; Keeps persistent record of all failed payment attempts for successfully
|
||||||
|
; settled payments.
|
||||||
|
; keep-failed-payment-attempts=false
|
||||||
|
|
||||||
; The default max_htlc applied when opening or accepting channels. This value
|
; The default max_htlc applied when opening or accepting channels. This value
|
||||||
; limits the number of concurrent HTLCs that the remote party can add to the
|
; limits the number of concurrent HTLCs that the remote party can add to the
|
||||||
; commitment. The maximum possible value is 483.
|
; commitment. The maximum possible value is 483.
|
||||||
|
|||||||
Reference in new issue
Block a user