Bsc relay has two main functions:
There are two solidity system contracts on BSC (besides these two, there are other system contracts), namely TendermintLightClient.sol and Crosschain.sol. BSC-Relay's "synchronous block header" operation will call BSC's TendermintLightClient.sol, and "synchronous cross-chain package" operation will call BSC's Crosschain.sol. ..
In addition, bsc-relayer also has some other functions, such as local status query, tx tracking and so on. I will not introduce it in detail here for the time being.
Bsc-relayer communicates with BC and Bsc through RPC, and the information of RPC is recorded in config/config.json file.
Bsc-relayer will always poll all cross-chain events of BC blocks at each height. The format of the event is as follows:
These include:
(BSC-related system contract logic will be introduced in subsequent chapters)
Bsc-relayer generates a unique identifier according to the combination of channel id and sequence, and requests corresponding payloads from BC through RPC, which are transmitted to bsc-relayer in the form of bytes.
Bsc-relayer generates tx from the above payload, calls CrossChain.sol, and sends it to BSC through RPC.
The block of Bsc-relayer pulling BC is essentially the block of Tendermint, so we should first introduce the relevant characteristics of Tendermint:
The general meaning of the above is that the data such as the status and signature of one block need to wait until at least the next block, so if it is necessary to verify the block with a height of H, it is necessary to wait until the LastCommit information of the block with a height of H+ 1 (for the record, I don't know much about Tendermint's algorithm, so please point out any inaccuracies in time).
The behavior of bsc-relayer pulling the BC block header is completely self-driven, which is triggered when the following two situations occur:
As can be seen from the above, bsc-relayer will continue to send transactions to bsc, which is equivalent to relaying itself until it runs out of gas. In order to make up for this loss, BSC will issue system rewards to bsc-relayer in the RelayerIncentivize.sol system contract. The reward is much higher than the deduction, otherwise it will be a loss.
As a relay, Bsc-relayer does not participate in the processing of specific data structures, but only acts as a data monitor and porter.
/bnb-chain/bsc-relayer.git