-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sleep time between retries #73
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
31efe71
docs(README.md): update README with additional information about the …
markettes d9ea1c9
refactor(liquidator.go): add sleepBetweenRetries parameter to perform…
markettes 1d95004
docs(README.md): update sleep between retries coefficient and maximum…
markettes c4744ba
refactor(liquidator.go): optimize sleep duration calculation and limi…
markettes 0ddd649
refactor(liquidator.go): improve calculation of newSleepBetweenRetrie…
markettes 8dde11a
chore(flags.go): add additional logging statements for backoffLimit, …
markettes faefb8d
fix(.env): update BACKOFFCOEFFICIENT to 0.90 and BACKOFFLIMIT to 0.4 …
markettes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
LNDCONNECTURIS=lndconnect://127.0.0.1:10003?cert=MIICJTCCAcygAwIBAgIQLYfp6m1vP9wFBXOcE-UsaDAKBggqhkjOPQQDAjAxMR8wHQYDVQQKExZsbmQgYXV0b2dlbmVyYXRlZCBjZXJ0MQ4wDAYDVQQDEwVjYXJvbDAeFw0yMzAzMjkxNTM4MjBaFw0yNDA1MjMxNTM4MjBaMDExHzAdBgNVBAoTFmxuZCBhdXRvZ2VuZXJhdGVkIGNlcnQxDjAMBgNVBAMTBWNhcm9sMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEcXT4dekJnAiZWd8Pk3FgL1BSFXMRwLGSAlk7Di5hIJnIA1B_o8RWKzlPz7u3Aw5mmWHh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BGxvb3ASAmluEgNvdXQaGgoLc3VnZ2VzdGlvbnMSBHJlYWQSBXdyaXRlGhUKBHN3YXASB2V4ZWN1dGUSBHJlYWQaDQoFdGVybXMSBHJlYWQAAAYgHb_8HcZwROzXASOxItpkbD3XAWHy1Ye32vlc1ccLeg8 | ||
OTEL_RESOURCE_ATTRIBUTES=service.name=liquidator,service.version=0.1.0 | ||
OTEL_EXPORTER_OTLP_ENDPOINT=host.docker.internal:4317 | ||
OTEL_EXPORTER_OTLP_ENDPOINT=host.docker.internal:4317 | ||
SLEEPMAX=500ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,12 +30,15 @@ import ( | |
) | ||
|
||
var ( | ||
prometheusMetrics *metrics | ||
rulesCache cache.Cache | ||
retries int | ||
backoffCoefficient float64 | ||
backoffLimit float64 | ||
limitFees float64 | ||
prometheusMetrics *metrics | ||
rulesCache cache.Cache | ||
retries int | ||
backoffCoefficient float64 | ||
backoffLimit float64 | ||
limitFees float64 | ||
sleepBetweenRetries time.Duration | ||
sleepBetweenRetriesBackoff float64 | ||
sleepMax time.Duration | ||
) | ||
|
||
// Entrypoint of liquidator main logic | ||
|
@@ -475,7 +478,7 @@ func manageChannelLiquidity(info ManageChannelLiquidityInfo) error { | |
|
||
retryCounter := 1 | ||
|
||
err := performReverseSwap(info, channel, swapAmount, rule, span, loopdCtx, retryCounter, swapAmountTarget) | ||
err := performReverseSwap(info, channel, swapAmount, rule, span, loopdCtx, retryCounter, swapAmountTarget, sleepBetweenRetries) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -495,7 +498,7 @@ func manageChannelLiquidity(info ManageChannelLiquidityInfo) error { | |
|
||
retryCounter := 1 | ||
|
||
err := performSwap(info, channel, swapAmount, rule, span, loopdCtx, retryCounter, swapAmountTarget) | ||
err := performSwap(info, channel, swapAmount, rule, span, loopdCtx, retryCounter, swapAmountTarget, sleepBetweenRetries) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -507,7 +510,7 @@ func manageChannelLiquidity(info ManageChannelLiquidityInfo) error { | |
|
||
} | ||
|
||
func performSwap(info ManageChannelLiquidityInfo, channel *lnrpc.Channel, swapAmount int64, rule nodeguard.LiquidityRule, span trace.Span, loopdCtx context.Context, retryCounter int, swapAmountTarget int64) error { | ||
func performSwap(info ManageChannelLiquidityInfo, channel *lnrpc.Channel, swapAmount int64, rule nodeguard.LiquidityRule, span trace.Span, loopdCtx context.Context, retryCounter int, swapAmountTarget int64, sleepBetweenRetries time.Duration) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
//Perform the swap | ||
swapRequest := provider.SubmarineSwapRequest{ | ||
SatsAmount: swapAmount, | ||
|
@@ -606,15 +609,22 @@ func performSwap(info ManageChannelLiquidityInfo, channel *lnrpc.Channel, swapAm | |
//Retry the swap | ||
retryCounter++ | ||
log.WithField("span", span).Infof("retrying swap for channel %v, retry number: %v/%v on node %v", channel.GetChanId(), retryCounter, retries, info.nodeInfo.GetIdentityPubkey()) | ||
err := performSwap(info, channel, swapAmount, rule, span, loopdCtx, retryCounter, swapAmountTarget) | ||
time.Sleep(sleepBetweenRetries) | ||
err := performSwap(info, channel, swapAmount, rule, span, loopdCtx, retryCounter, swapAmountTarget, sleepBetweenRetries) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
limitSwapAmount := float64(helper.AbsInt64((channel.RemoteBalance - swapAmountTarget))) * backoffLimit | ||
if limitSwapAmount < float64(swapAmount)*backoffCoefficient { | ||
time.Sleep(sleepBetweenRetries) | ||
newSwapAmount := int64(float64(swapAmount) * backoffCoefficient) | ||
err := performSwap(info, channel, newSwapAmount, rule, span, loopdCtx, 0, swapAmountTarget) | ||
newSecondsAmount := sleepBetweenRetries.Seconds() * sleepBetweenRetriesBackoff | ||
newSleepBetweenRetries := time.Duration(newSecondsAmount) * time.Second | ||
if newSleepBetweenRetries > sleepMax { | ||
newSleepBetweenRetries = sleepMax | ||
} | ||
err := performSwap(info, channel, newSwapAmount, rule, span, loopdCtx, 0, swapAmountTarget, newSleepBetweenRetries) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -636,7 +646,7 @@ func performSwap(info ManageChannelLiquidityInfo, channel *lnrpc.Channel, swapAm | |
return nil | ||
} | ||
|
||
func performReverseSwap(info ManageChannelLiquidityInfo, channel *lnrpc.Channel, swapAmount int64, rule nodeguard.LiquidityRule, span trace.Span, loopdCtx context.Context, retryCounter int, swapAmountTarget int64) error { | ||
func performReverseSwap(info ManageChannelLiquidityInfo, channel *lnrpc.Channel, swapAmount int64, rule nodeguard.LiquidityRule, span trace.Span, loopdCtx context.Context, retryCounter int, swapAmountTarget int64, sleepBetweenRetries time.Duration) error { | ||
// Check if it is a reverse swap to a wallet or to an address | ||
var address string | ||
if rule.IsReverseSwapWalletRule { | ||
|
@@ -672,7 +682,8 @@ func performReverseSwap(info ManageChannelLiquidityInfo, channel *lnrpc.Channel, | |
limitSwapAmount := float64(helper.AbsInt64((channel.RemoteBalance - swapAmountTarget))) * backoffLimit | ||
if limitSwapAmount < float64(swapAmount)*backoffCoefficient { | ||
newSwapAmount := int64(float64(swapAmount) * backoffCoefficient) | ||
err = performReverseSwap(info, channel, newSwapAmount, rule, span, loopdCtx, 0, swapAmountTarget) | ||
time.Sleep(sleepBetweenRetries) | ||
err = performReverseSwap(info, channel, newSwapAmount, rule, span, loopdCtx, 0, swapAmountTarget, sleepBetweenRetries) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -698,15 +709,22 @@ func performReverseSwap(info ManageChannelLiquidityInfo, channel *lnrpc.Channel, | |
//Retry the swap | ||
retryCounter++ | ||
log.WithField("span", span).Infof("retrying reverse swap for channel %v, retry number: %v/%v on node %v", channel.GetChanId(), retryCounter, retries, info.nodeInfo.GetIdentityPubkey()) | ||
err := performReverseSwap(info, channel, swapAmount, rule, span, loopdCtx, retryCounter, swapAmountTarget) | ||
time.Sleep(sleepBetweenRetries) | ||
err := performReverseSwap(info, channel, swapAmount, rule, span, loopdCtx, retryCounter, swapAmountTarget, sleepBetweenRetries) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
limitSwapAmount := float64(helper.AbsInt64((channel.RemoteBalance - swapAmountTarget))) * backoffLimit | ||
if limitSwapAmount < float64(swapAmount)*backoffCoefficient { | ||
time.Sleep(sleepBetweenRetries) | ||
newSwapAmount := int64(float64(swapAmount) * backoffCoefficient) | ||
err := performReverseSwap(info, channel, newSwapAmount, rule, span, loopdCtx, 0, swapAmountTarget) | ||
newMsAmount := float64((sleepBetweenRetries.Milliseconds())) * sleepBetweenRetriesBackoff | ||
newSleepBetweenRetries := time.Duration(newMsAmount) * time.Millisecond | ||
if newSleepBetweenRetries > sleepMax { | ||
newSleepBetweenRetries = sleepMax | ||
} | ||
err := performReverseSwap(info, channel, newSwapAmount, rule, span, loopdCtx, 0, swapAmountTarget, newSleepBetweenRetries) | ||
if err != nil { | ||
return err | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not useful, I would reduce code and actually control this via config rather making code more complex.