substrate icon indicating copy to clipboard operation
substrate copied to clipboard

Beefy on-demand justifications as a custom RequestResponse protocol

Open acatangiu opened this issue 3 years ago • 2 comments

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: BeefyJustifsRequestHandler in incoming_requests_handler.rs
  • requesting justifications from peers: OnDemandJustificationsEngine in outgoing_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 for b.

main worker/voter

  1. Requests justifications from OnDemandJustificationsEngine for every mandatory block it's currently working/voting/blocked on.
  2. Drives the OnDemandJustificationsEngine inner 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

acatangiu avatar Aug 26 '22 16:08 acatangiu

@altonen @dmitry-markin it would be nice if you take a look here at the networking related code.

bkchr avatar Sep 19 '22 09:09 bkchr

PR is ready for review :+1:

acatangiu avatar Sep 19 '22 12:09 acatangiu

bot merge

acatangiu avatar Oct 03 '22 12:10 acatangiu

Error: Statuses failed for b904741ee799b63d2e3fd78cc637670d37744d12

bot merge

acatangiu avatar Oct 03 '22 12:10 acatangiu

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.

acatangiu avatar Oct 04 '22 10:10 acatangiu