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
…#2124)

(cherry picked from commit 2d6050f)
  • Loading branch information
jayy04 authored and mergify[bot] committed Aug 21, 2024
1 parent 59a959d commit d1c18f0
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 d1c18f0

Please sign in to comment.