Skip to content

Commit f73a311

Browse files
mergify[bot]jayy04
andauthored
skip liquidation task loop if last committed block height is the same (backport #2124) (#2125)
Co-authored-by: jayy04 <103467857+jayy04@users.noreply.github.com>
1 parent d41d7c5 commit f73a311

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

protocol/daemons/liquidation/client/grpc_helper_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,11 @@ func TestSendLiquidatableSubaccountIds(t *testing.T) {
590590
tc.subaccountOpenPositionInfo,
591591
1000,
592592
)
593-
require.Equal(t, tc.expectedError, err)
593+
if tc.expectedError != nil {
594+
require.ErrorContains(t, err, tc.expectedError.Error())
595+
} else {
596+
require.NoError(t, err)
597+
}
594598
})
595599
}
596600
}

protocol/daemons/liquidation/client/sub_task_runner.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ type SubTaskRunner interface {
3030
) error
3131
}
3232

33-
type SubTaskRunnerImpl struct{}
33+
type SubTaskRunnerImpl struct {
34+
lastLoopBlockHeight uint32
35+
}
3436

3537
// Ensure SubTaskRunnerImpl implements the SubTaskRunner interface.
3638
var _ SubTaskRunner = (*SubTaskRunnerImpl)(nil)
@@ -54,6 +56,19 @@ func (s *SubTaskRunnerImpl) RunLiquidationDaemonTaskLoop(
5456
return err
5557
}
5658

59+
// Skip the loop if no new block has been committed.
60+
// Note that lastLoopBlockHeight is initialized to 0, so the first loop will always run.
61+
if lastCommittedBlockHeight == s.lastLoopBlockHeight {
62+
daemonClient.logger.Info(
63+
"Skipping liquidation daemon task loop as no new block has been committed",
64+
"blockHeight", lastCommittedBlockHeight,
65+
)
66+
return nil
67+
}
68+
69+
// Update the last loop block height.
70+
s.lastLoopBlockHeight = lastCommittedBlockHeight
71+
5772
// 1. Fetch all information needed to calculate total net collateral and margin requirements.
5873
subaccounts,
5974
perpInfos,

0 commit comments

Comments
 (0)