Preliminary terminology
- A
StateSenderis a contract deployed on L1 (Ethereum) responsible for emitting state-sync events. - A
StateReceiveris a contract deployed on L2 (Bor) responsible for receiving state-sync events. - A
EventRecordis a record of the state-sync event stored in the heimdall state.
Overview
Clerk module manages generic event records from the Ethereum blockchain related to state-sync events.These are specially designed events that are emitted by the StateSender contract on the L1 chain to notify the L2 nodes (Bor in case of PoS) about the state changes in the L1. Once the bridge processes the events, the clerk module listens to these events and stores them in the database for further processing.
State-Sync Mechanism
It’s a mechanism for state-management between the Ethereum and Bor chain. The events generated are called state-sync events. This is a way to move data from the L1 chain to the L2 chain.
How it works
AnEventRecord is defined by the data structure :
idis the unique identifier for the event record, Generated by theStateSendercontract.contractis the address of the contract on the L2 chain on which the event will be processed.datais the data of the event which will be processed by the contract.txHashis the transaction hash of the event on the L1 chain.logIndexis the log index of the event on the L1 chain.borChainIDis the chain id of the bor chain.recordTimeis the time at which the event was recorded in heimdall state.
MsgEventRecord which is responsible for validating events from StateSender contract and storing the EventRecord on the heimdall state for bor to use.
TxHash and LogIndex to ensure that the event exists on L1 and the data is not tampered with, It throws Older invalid tx found error if the event is already processed.
Once the event is validated by the Handler,
it will go to SideHandleMsgEventRecord in each validator node and after verifying the event,
the validators will vote with either a YES return an error for failed verification.
Only when there is a majority of YES votes, The event will be processed by PostHandleMsgEventRecord which will persist the event in the state via keeper.
Adding an event manually
A validator can use the CLI to add an event to the state if it is missing and was not processed by the bridge:Query commands
One can run the following query commands from the clerk module :record- Query for a specific event record by its ID.record-list- Query a list of event records by page and limit.is-old-tx- Query if the event record is already processed.latest-record-id- Query the latest record (state-sync) id from L1.