Skip to content

Commit

Permalink
skip liquidation task loop if last committed block height is the same…
Browse files Browse the repository at this point in the history
… (backport #2124) (#2125)

Co-authored-by: jayy04 <[email protected]>
  • Loading branch information
2 people authored and dydxwill committed Aug 26, 2024
1 parent 06cba16 commit b839bb3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
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 @@ -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)
}
})
}
}
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 @@ -30,7 +30,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 @@ -54,6 +56,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

0 comments on commit b839bb3

Please sign in to comment.