substrate
substrate copied to clipboard
Beefy on-demand justifications as a custom RequestResponse protocol
Description
Run a dedicated BEEFY justifications sync protocol as a libp2p RequestResponse protocol - where node can request BEEFY justifications for certain blocks from connected peers, and also answer any requests it gets.
PR defines BEEFY own RequestResponse sub-protocol and adds support for:
- handling incoming requests:
BeefyJustifsRequestHandlerinincoming_requests_handler.rs - requesting justifications from peers:
OnDemandJustificationsEngineinoutgoing_requests_engine.rs
BeefyJustifsRequestHandler
Run as independent async task, accepts incoming requests, decodes and validates request for BEEFY justification for block b.
It then uses client backend to retrieve justification if available, encode and provide it as custom protocol response.
OnDemandJustificationsEngine
Simple async state machine that be either:
- "idle" - no on-demand justifications required
- "requesting justification for block
b" - self driving future that sequentially sends requests to all relevant peers until one provides valid justification or no more peers available. relevant peers are those seen (through gossip) voting for block numbers >=b, meaning they should have justification forb.
main worker/voter
- Requests justifications from
OnDemandJustificationsEnginefor every mandatory block it's currently working/voting/blocked on. - Drives the
OnDemandJustificationsEngineinner future in its main loop.
Tests
Added integration test that verifies all components and full workflow:
- 1 out of 4 voters is held behind so that it misses voting for a number of mandatory blocks,
- when started, late voter must get justifications for past mandatory blocks and can only do so through on-demand requests,
- other 3 voters need to provide on-demand justifications responses for late voter to catch up,
- by end of test, late voter is up-to-date and actively participating in voting.
Fixes
Fixes https://github.com/paritytech/substrate/issues/12093 (more details there).
polkadot companion: https://github.com/paritytech/polkadot/pull/6035
@altonen @dmitry-markin it would be nice if you take a look here at the networking related code.
PR is ready for review :+1:
bot merge
Error: Statuses failed for b904741ee799b63d2e3fd78cc637670d37744d12
bot merge
Waiting for commit status.
I know that I'm very late to the party. I still left some comments on stuff that could be improved. Sorry!
Better late than never 😛 thanks for the improvement ideas! Opened https://github.com/paritytech/substrate/pull/12414 for them.