State Sync Mechanism
Validators on the Heimdall layer pickup the StateSynced event and pass it on to the Bor layer (read more about the architecture here: https://hackmd.io/DFYomMhJSrWmHOqE3rj68w#Architecture).
The receiver contract inherits IStateReceiver, and custom logic sits inside onStateReceive function.
Things required from dapps/users to work with state-sync:
- Call the smart contract function present here: https://github.com/maticnetwork/contracts/blob/19163ddecf91db17333859ae72dd73c91bee6191/contracts/root/stateSyncer/StateSender.sol#L33
- Which emits an event called
StateSynced(uint256 indexed id, address indexed contractAddress, bytes data);
- All the validators on the heimdall chain receive this event and one of them, whoever wishes to get the tx fees for state sync sends this transaction to heimdall
- Once
state-sync
transaction on heimdall has been included in a block it is added to pending state-sync list. - After every sprint on
bor
thebor
node fetches the pending state-sync events from heimdall via an API call. - The receiver contract inherits
IStateReceiver
interface, and custom logic of decoding the data bytes and performing any action sits insideonStateReceive
function: https://github.com/maticnetwork/genesis-contracts/blob/master/contracts/IStateReceiver.sol