Module Evm_node_lib_dev.Filter_helpers

A bloom filter can be seen as a probabilistic set. As such, the order of its elements is not important.

Blocks contain a bloom filter with the union of all topics in their logs, together with the address of the contract that produced them. The getLogs RPC defines a filter (not to be confused with bloom filter) which may contain a pattern of topics to be matched with a log.

A pattern is defined as: pattern := TOPIC | NULL | TOPIC list

Where NULL is a wildcard, and a list of topics matches against any of the elements in the list (Or).

To speed up the filtering, we compute a bloom filter corresponding to the filter's pattern. The goal is to check if this bloom is contained in the block's bloom, and only fetching the block in that case. Therefore, our filter must always be included in filters corresponding to blocks that have at least a log that matches with the pattern. For this reason, we decide to ignore Or patterns in the bloom filter "heuristic" (including all topics would break the previous property). The same is done for addresses, as a filter can match against a list of them. If this becomes a serious bottleneck, we could keep a collection of bloom filters to represent the disjunction.

Saner representation of an input filter: from_block and to_block are defined by: A filter's from_block and to_block if provided, or a filter's block_hash if provided (from_block = to_block = block_n), or from_block = to_block = latest block's number.

A bloom filter is computed using the topics and address.

type Tezos_base.TzPervasives.error +=
  1. | Incompatible_block_params
  2. | Block_range_too_large of {
    1. limit : int;
    }
  3. | Topic_list_too_large
  4. | Receipt_not_found of Evm_node_lib_dev_encoding.Ethereum_types.hash
  5. | Too_many_logs of {
    1. limit : int;
    }
val emit_and_return_none : 'a Tezos_base.TzPervasives.Internal_event.Simple.t -> 'a -> ('b option, 'c) Stdlib.result Lwt.t
val validate_topics : Evm_node_lib_dev_encoding.Ethereum_types.Filter.t -> (unit, Tezos_base.TzPervasives.error list) Stdlib.result Lwt.t
val validate_bloom_filter : Evm_node_lib_dev_encoding.Ethereum_types.Filter.t -> (bloom_filter, Tezos_base.TzPervasives.error list) Stdlib.result Lwt.t
val match_filter_topics : bloom_filter -> Evm_node_lib_dev_encoding.Ethereum_types.hash list -> bool
val split_in_chunks : chunk_size:int -> base:Z.t -> length:int -> Z.t list list

split_in_chunks ~chunk_size ~base ~length returns a list of lists (chunks) containing the consecutive numbers from base to base + length - 1. Each chunk is at most of length chunk_size. Only the last chunk can be shorter than chunk_size.

Example split_in_chunks ~chunk_size:2 ~base:1 ~length:5 is <<1, 2>, <3,4>, <5>>.