Skip to content
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 (backport #2124) #2129

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion protocol/daemons/liquidation/client/grpc_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,11 @@ func TestSendLiquidatableSubaccountIds(t *testing.T) {
tc.negativeTncSubaccountIds,
tc.subaccountOpenPositionInfo,
)
require.Equal(t, tc.expectedError, err)
if tc.expectedError != nil {
require.ErrorContains(t, err, tc.expectedError.Error())
} else {
require.NoError(t, err)
}
})
}
}
17 changes: 16 additions & 1 deletion protocol/daemons/liquidation/client/sub_task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

// 1. Fetch all information needed to calculate total net collateral and margin requirements.
subaccounts,
perpInfos,
Expand Down
Loading