Snapshot Generation
Snapshot Computation Modules
As briefly introduced in the section on Snapshotter implementations that leverage Git Submodules for specific computation logic, the modules are specified in the configuration for project types under the key processor
.
loading...
Let's take the example of the snapshot builder configured for the project type zkevm:owlto_bridge
and locate it in the snapshotter-computes
repo, in the zkevm_quests
branch
loading...
As observed, it implements the compute()
interface expected from Snapshotter implementations inheriting GenericProcessorSnapshot
.
loading...
Base Snapshots
Callback workers calculate base snapshots against an epochId
, corresponding to collections of state observations and event logs between the blocks at heights in the range begin, end
. They invoke the use case-specific computation logic as configured in the computation modules section.
The data sources are specified against the projects
key in the configuration shown in the section above.
Data Source Specification: Non-bulk Mode
- If
bulk_mode
is set toFalse
and an empty array is assigned to theprojects
:
The Snapshotter node attempts to retrieve data sources corresponding to the projects
key from the protocol state.
loading...
- If the
projects
key is non-existent- data sources can also be dynamically added on the protocol state contract which the processor distributor syncs with
loading...
- Else, we can have a static list of contracts
Data Source Specification: Bulk Mode
- If
bulk_mode
is set totrue
:
In this case, the projects
key is not checked by the snapshotter and is usually left as an empty array.
Bulk Mode is highly effective in situations where:
- The list of data sources to be tracked is continually expanding, or
- Snapshots don't need to be submitted for every epoch for all the data sources because:
- The state change between epochs may not be of interest.
- Once a certain state change is observed, no further changes need to be recorded. Example use cases include monitoring on-chain activities and tracking task or quest completion statuses on the blockchain.
loading...
This allows for flexibility to filter through all transactions and blocks without the need for predefined data sources.
The Processor Distributor
generates a SnapshotProcessMessage
with bulk mode enabled for each project type. When snapshot workers receive this message, they leverage common preloaders to filter out relevant data.
loading...
Since common datapoints like block details, transaction receipts, etc., are preloaded, this approach can efficiently scale to accommodate a large number of project types with little to no increase in RPC (Remote Procedure Call) calls.
Whenever a data source is added or removed by the signaling ecosystem, the protocol state smart contract emits a ProjectUpdated
event with the following data model.
loading...
Format of specifying data sources against projects
- EVM-compatible wallet address strings
"<addr1>_<addr2>"
strings that denote the relationship between two EVM addresses (for eg ERC20 balance ofaddr2
against a token contractaddr1
)
Project ID generation
loading...
Example of snapshot computation
Base snapshot of trade events for the Uniswap V2 and V3 dashboard data markets:
loading...
Aggregate Snapshots
Aggregate and higher-order snapshots that build on base snapshots are configured in their specific repositories, such as the following in our Uniswap Dashboard use case. This is where you can observe the dependency graph of snapshot composition in action.
The order and dependencies of these compositions are specified according to the aggregate_on
key.
SingleProject
aggregation type
loading...
- This type specifies the generation of an aggregation snapshot for a single project across a span of epochs relative to the current
epochId
.- The
filters.projectId
key specifies the substring that should be contained within a project ID on which the base snapshot computation is completed for the epoch. - For example, a base snapshot built on a project ID like
pairContract_trade_volume:0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc:UNISWAPV2
triggers the workerAggregateTradeVolumeProcessor
as defined in theprocessor
config, against the pair contract0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc
.
- The
- The span of epochs on which corresponding base snapshots will be aggregated is determined by the logic contained in the module specified in the
processor
key.
The following implementation aggregates trade volume snapshots across a span of 24 hours worth of epochs, if available. Otherwise, it aggregates the entire span of epochs available on the protocol against the data market and reports it back.
loading...
MultiProject
aggregation type
loading...
projects_to_wait_for
specifies the exact project IDs on which this higher-order aggregation will be generated.- The aggregation snapshot build for this is triggered once a snapshot build has been achieved for an
epochId
.
The configuration above generates a dataset that can be further used to render a dashboard containing trade information across a large number of Uniswap V2 pair contracts.
Project ID Generation
In the case of 'MultiProject` aggregations, their project IDs are generated with a combination of the hash of the dependee project IDs along with the namespace and project type string.
The following is the section where the relevant project IDs are generated according to their configuration type.
loading...