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

Configure indexer reorg check interval #472

Merged
merged 2 commits into from
Feb 10, 2025
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
24 changes: 14 additions & 10 deletions pkg/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,21 @@ func indexLogs(
blockTracker IBlockTracker,
reorgHandler ChainReorgHandler,
) {
// L3 Orbit works with Arbitrum Elastic Block Time, which under maximum load produces a block every 0.25s.
// With a maximum throughput of 7M gas per second and a median transaction size of roughly 200k gas,
// checking for a reorg every 60 blocks (15 seconds) means that, theoretically, a maximum of 495 messages could be affected.
const reorgCheckInterval = 60

var (
errStorage storer.LogStorageError
storedBlockNumber uint64
storedBlockHash []byte
lastBlockSeen uint64
reorgCheckInterval uint64 = 10 // TODO(borja): Adapt based on blocks per batch
reorgCheckAt uint64
reorgDetectedAt uint64
reorgBeginsAt uint64
reorgFinishesAt uint64
reorgInProgress bool
errStorage storer.LogStorageError
storedBlockNumber uint64
storedBlockHash []byte
lastBlockSeen uint64
reorgCheckAt uint64
reorgDetectedAt uint64
reorgBeginsAt uint64
reorgFinishesAt uint64
reorgInProgress bool
)

// We don't need to listen for the ctx.Done() here, since the eventChannel will be closed when the parent context is canceled
Expand Down
10 changes: 7 additions & 3 deletions pkg/indexer/reorgHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ var (
ErrGetBlock = errors.New("failed to get block")
)

// TODO(borja): Make this configurable?
const BLOCK_RANGE_SIZE uint64 = 1000
// The indexer performs a reorg check every 60 blocks.
// Setting BLOCK_RANGE_SIZE to 600 (10 cycles of 60 blocks)
// allows us to retrieve a single page of blocks from the database,
// which will likely contain the reorg point.
const BLOCK_RANGE_SIZE uint64 = 600

func NewChainReorgHandler(
ctx context.Context,
Expand All @@ -42,7 +45,8 @@ func NewChainReorgHandler(
}
}

// TODO(borja): When reorg range has been calculated, alert clients (TBD)
// TODO(borja): When reorg range has been calculated, alert clients.
// Tracked in https://github.com/xmtp/xmtpd/issues/437
func (r *ReorgHandler) FindReorgPoint(detectedAt uint64) (uint64, []byte, error) {
startBlock, endBlock := blockRange(detectedAt)

Expand Down
4 changes: 2 additions & 2 deletions pkg/indexer/reorgHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func Test_blockRange(t *testing.T) {
}{
{
name: "block range with subtraction",
from: 1001,
from: 601,
wantStartBlock: 1,
wantEndBlock: 1001,
wantEndBlock: 601,
},
{
name: "block range without subtraction",
Expand Down
Loading