Skip to main content

sanitize_chain

Function sanitize_chain 

Source
pub fn sanitize_chain<TxReq, H>(
    blocks: Vec<SimBlock<TxReq>>,
    parent: &SealedHeader<H>,
    chain_id: u64,
    max_simulate_blocks: u64,
) -> Result<Vec<SimBlock<TxReq>>, EthApiError>
where H: BlockHeader,
Available on crate feature rpc only.
Expand description

Sanitizes and gap-fills the chain of SimBlocks for eth_simulateV1.

Walks the provided block-state calls in order and:

  • validates that each block number and timestamp strictly increases relative to the parent and prior simulated block;
  • inserts empty filler blocks for every gap in block numbers, so a request like [block at number N + k] over a parent at N expands to k - 1 empty blocks followed by the requested one (per the execution-apis spec: “If the block number is increased more than 1 compared to the previous block, new empty blocks are generated in between.”);
  • assigns default block numbers (prev_number + 1) and timestamps (prev_timestamp + chain block time) when missing, so every returned entry has explicit number and time overrides. The block time defaults to Chain::average_blocktime_hint for the chain id, falling back to SIMULATE_FALLBACK_TIMESTAMP_INCREMENT when no hint is registered. Sub-second chain hints are rounded up because block timestamps are second-granular;
  • enforces the global max_simulate_blocks cap on the total number of blocks (including generated fillers).