-
Notifications
You must be signed in to change notification settings - Fork 115
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
skip liquidation task loop if last committed block height is the same #2124
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,9 @@ type SubTaskRunner interface { | |
) error | ||
} | ||
|
||
type SubTaskRunnerImpl struct{} | ||
type SubTaskRunnerImpl struct { | ||
lastLoopBlockHeight uint32 | ||
} | ||
|
||
// Ensure SubTaskRunnerImpl implements the SubTaskRunner interface. | ||
var _ SubTaskRunner = (*SubTaskRunnerImpl)(nil) | ||
|
@@ -50,6 +52,19 @@ func (s *SubTaskRunnerImpl) RunLiquidationDaemonTaskLoop( | |
return err | ||
} | ||
|
||
// Skip the loop if no new block has been committed. | ||
// Note that lastLoopBlockHeight is initialized to 0, so the first loop will always run. | ||
if lastCommittedBlockHeight == s.lastLoopBlockHeight { | ||
daemonClient.logger.Info( | ||
"Skipping liquidation daemon task loop as no new block has been committed", | ||
"blockHeight", lastCommittedBlockHeight, | ||
) | ||
return nil | ||
} | ||
|
||
// Update the last loop block height. | ||
s.lastLoopBlockHeight = lastCommittedBlockHeight | ||
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. Playing devil's advocate: are we sure this is thread-safe? Could two liquidation daemon loop overlap? Should we add a 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. no daemon loops don't overlap since we are not spawning new go routines
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. Nit: I wonder if here's the best place to assign 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. good question. thought about it a little bit more putting it here strictly guarantees that loop doesn't run for the same block height, regardless of errors. If we defer the statement to the end (e.g. after 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.
No strong preference though, the current implementation also works. Up to you. Approved to unblock 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. ohh you mean yeah I think it's basically the same - let's keep it as is to unstuck the testnet first |
||
|
||
// 1. Fetch all information needed to calculate total net collateral and margin requirements. | ||
subaccounts, | ||
perpInfos, | ||
|
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.
IIUC if application restarts,
lastLoopBlockHeight
is by default0
and we always continue below logic. If so could we document?