Skip to content

[CLI] Introduce ability to limit block number fetched by get logs in epoch switching #786

@Mc01

Description

@Mc01

Currently epoch switching is querying all blocks within given epochs for events (getLogs).
Public forno api limits them to 1000. It would be amazing to have configurable block limit for querying.

Potential solution in EpochManager.ts:

// Public RPC nodes cap eth_getLogs to a 1000-block range; an unprocessed epoch
// can span a full day of blocks, so page the GroupProcessed query.
private static readonly GETLOGS_RANGE = 1000

private getGroupProcessedEvents = async (fromBlock: number): Promise<EventLog[]> => {
  const latest = Number(await this.client.getBlockNumber())
  const events: EventLog[] = []
  for (let start = fromBlock; start <= latest; start += EpochManagerWrapper.GETLOGS_RANGE) {
    const toBlock = Math.min(start + EpochManagerWrapper.GETLOGS_RANGE - 1, latest)
    events.push(...(await this.getPastEvents('GroupProcessed', { fromBlock: start, toBlock })))
  }
  return events
}

// replace the call:
const fromBlock = (await this.getFirstBlockAtEpoch(await this.getCurrentEpochNumber())) + 1
const groupProcessedEvents = await this.getGroupProcessedEvents(fromBlock)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions