autonomys / subspace

Subspace Network reference implementation
https://subspace.network
368 stars 242 forks source link

Refactoring the XDM relayer #2977

Closed NingLin-P closed 3 weeks ago

NingLin-P commented 3 weeks ago

This PR is a refactoring of the XDM relayer, the change set is quite large so I didn't organize the change commit by commit but the logic after refactoring should be clear and easy to review.

The relayer works as follows:

  1. For every imported consensus block
    • Skip if it is in major sync
    • Skip if the block is not the best block
  2. Get the finalized_block as imported_block - confirmation_depth_k
    • The finalized_block won't be processed directly but instead the relayer will process finalized_block - 1 and finalized_block is used to generate the MMR proof of finalized_block - 1
  3. Fetch and filter XDM in finalized_block - 1
    • The relayer will check against the current best block state to see if the XDM in finalized_block - 1 is already relayed
  4. Construct XDM proof which consists of:
    • The MMR proof of finalized_block - 1
    • The message proof
    • If the src chain is a domain there is also a storage proof of the LastConfirmedDomainBlockReceipt
  5. Gossip/submit the XDM to the network

A few notable logical changes:

Code contributor checklist: