diff --git a/protocol/daemons/liquidation/client/grpc_helper_test.go b/protocol/daemons/liquidation/client/grpc_helper_test.go index 73d1ad5a72..8454c3f54a 100644 --- a/protocol/daemons/liquidation/client/grpc_helper_test.go +++ b/protocol/daemons/liquidation/client/grpc_helper_test.go @@ -590,7 +590,11 @@ func TestSendLiquidatableSubaccountIds(t *testing.T) { tc.subaccountOpenPositionInfo, 1000, ) - require.Equal(t, tc.expectedError, err) + if tc.expectedError != nil { + require.ErrorContains(t, err, tc.expectedError.Error()) + } else { + require.NoError(t, err) + } }) } } diff --git a/protocol/daemons/liquidation/client/sub_task_runner.go b/protocol/daemons/liquidation/client/sub_task_runner.go index f9600f97e1..f9f2e77675 100644 --- a/protocol/daemons/liquidation/client/sub_task_runner.go +++ b/protocol/daemons/liquidation/client/sub_task_runner.go @@ -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 + // 1. Fetch all information needed to calculate total net collateral and margin requirements. subaccounts, perpInfos,