Before libp2p 0.50.0 we used a quorum of one to fetch records from the DHT. In the pr that upgraded
to libp2p 0.50.0 we accidentally changed this behavior. This pr brings back the old behavior of
using a qorum of one and thus, a faster discovery. After finding the first value, we directly finish
the query. There was also another behavior change in libp2p, they stopped automatic caching on
remote nodes. This pr also brings back the remote caching on nodes that are nearest to the key from
our point of view of the network.
The pr that changed the behavior in libp2p: https://github.com/libp2p/rust-libp2p/pull/2712
* upgrade libp2p to 0.50.0
* on_swarm_event and on_connection_handler_event
* replace `Swarm::new` with `Swarm::with_threadpool_executor`
* on_swarm_event and on_connection_handler_event part 2
* on_swarm_event and on_connection_handler_event part 3
* on_swarm_event and on_connection_handler_event part 4
* update libp2p
* libp2p 0.50.0
* rename OutboundQueryCompleted to OutboundQueryProgressed
refs https://github.com/libp2p/rust-libp2p/pull/2712
* remove unused var
* accumulate outbound_query_records until query is finished
* format code
* use p_handler instead of new_handler
https://github.com/paritytech/substrate/pull/12734#discussion_r1027640610
* pass ListenFailure to kademlia
https://github.com/paritytech/substrate/pull/12734#discussion_r1034716664
* use tokio executor in tests
https://github.com/paritytech/substrate/pull/12734#discussion_r1039291776
* use chrono Local::now
instead of deprecated Local::today
* remove unused vars from request_responses tests
* attempt to fix pallet UI tests
* restart CI
* restart CI
* restart CI
* restart CI
* restart CI
* restart CI
* restart CI
* restart CI
* sc-network-test::Peer: block push methods return hashes vec
This commit reworks the block generation/push methods in
sc-network-test::Peer.
Now methods are providing the vector of hashes that were built.
This allows to get rid of redundant `block_hash_from_id` call, as all
hashes are known just after being built.
Similar approach was taken in BeefyTestNet::generate_blocks_and_sync
method.
This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)
* fix
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Bastian Köcher <git@kchr.de>
* Move import queue out of `sc-network`
Add supplementary asynchronous API for the import queue which means
it can be run as an independent task and communicated with through
the `ImportQueueService`.
This commit removes removes block and justification imports from
`sc-network` and provides `ChainSync` with a handle to import queue so
it can import blocks and justifications. Polling of the import queue is
moved complete out of `sc-network` and `sc_consensus::Link` is
implemented for `ChainSyncInterfaceHandled` so the import queue
can still influence the syncing process.
* Fix tests
* Apply review comments
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update client/network/sync/src/lib.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Bastian Köcher <git@kchr.de>
* implement crate publishing from CI
* fix indentation
* use resource_group for job exclusivity
ensure that at most one instance of the publish-crates job is running at any given time to prevent race conditions
* correct publish = false
* Remove YAML anchors as GitLab's `extends:` doesn't need it
* Temporarily force cache upload for the new jobs
* Revert `RUSTY_CACHIER_FORCE_UPLOAD`
* pin libp2p-tcp=0.37.0 for sc-telemetry
* Revert "pin libp2p-tcp=0.37.0 for sc-telemetry"
This reverts commit 29146bfad6c31e8cf0e2f17ad92a71bb81a373af.
* always collect generated crates
* increase timeout for publish-crates-template
* Force upload the new job cache again
* Revert "Force upload the new job cache again"
This reverts commit 5a5feee1b2c51fdef768b25a76be4c3949ec1c99.
* reformat
* improve timeout explanation
* s/usual/average
Co-authored-by: Vladimir Istyufeev <vladimir@parity.io>
* Replace deprecated libp2p feature specs with correct ones
* Bump tokio to 1.21.2
* Replace async-std libp2p primitives with tokio ones
* minor: rustfmt
* Fix TestNet to run initialization in the tokio context
* Convert telemetry test from async-std to tokio
* Convert notifications tests from async-std to tokio
* Convert chain sync tests from async-std to tokio
* Ditch async-std completely
* Make executor mandatory
* Bump tokio to 1.22.0
* minor: rustfmt
* Explicitly use tokio runtime in tests
* Move more tests to explicit tokio runtime
* Explicitly set multithreaded runtime in tokio test
* minor: rustfmt
* minor: fix comment
* Replace async-std with tokio in MMR tests
* Do not update peer information if ancestor search is in progress
If block announcement is received from a peer while ancestor search
for that same peer is still in progress, do not update the peer's best
hash and best number as that causes the ancestor search to yield
different information from what was expected and can cause, for example,
a fork of lower height not be be downloaded.
* Block until peers are in sync
* BlockId removal: refactor: Backend::block_indexed_body
It changes the arguments of `Backend::block_indexed_body` method from: `BlockId<Block>` to: `&Block::Hash`
This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)
* trigger CI job
* BlockId removal: refactor: Backend::justifications
It changes the arguments of `Backend::justifications` method from: `BlockId<Block>` to: `&Block::Hash`
This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)
* trigger CI job
* trigger CI job
* bug fix
* match -> if
Co-authored-by: Adrian Catangiu <adrian@parity.io>
Co-authored-by: Adrian Catangiu <adrian@parity.io>
It changes the arguments of `Backend::body` method from: `BlockId<Block>` to: `&Block::Hash`
This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)
Co-authored-by: parity-processbot <>
Introduce a middleware called `NetworkServiceProvider` which the
`ChainSync` can use to communicate with `NetworkService`. `ChainSync` is
given a `NetworkServiceHandle` which it uses to call `NetworkServiceProvider`
which then dispatches the calls to `NetworkService` on behalf of `ChainSync`.
This change will allow `ChainSync` to disconnect and report peers and
in the future it'll be possible to send requests and notifications
through the `NetworkServiceProvider`.
`NetworkServiceProvider` is needed only until the `ChainSync` object
has been removed from `Protocol`. After that, a normal `NetworkService`
handle can be passed onto `ChainSync` and these changes can be
deprecated.
Co-authored-by: parity-processbot <>
* Refactor service tests in `sc-network`
Create a separate directory for the tests and move common network
instantion related code to `mod.rs` from where it can be used by both
service and chainsync tests.
Use the builder pattern when creating the `TestNetwork` object to reduce
code duplication between the test files.
* Update client/network/src/service/tests/mod.rs
Co-authored-by: Dmitrii Markin <dmitry@markin.tech>
Co-authored-by: Dmitrii Markin <dmitry@markin.tech>
Co-authored-by: parity-processbot <>
* BlockId removal: refactor: Finalizer
It changes the arguments of methods of `Finalizer` trait from:
block: `BlockId<Block>` to: hash: `&Block::Hash`
This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)
* minor corrections
* failing test corrected
* minor rework
* BlockId removal: refactor: ProofProvider
It changes the arguments of methods of `ProofProvider` trait from:
block: `BlockId<Block>` to: hash: `&Block::Hash`
This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)
* LightClientRequestHandler: excessive BlockIdTo bound removed
* imports cleanup
* formatting
* args tyeps cleanup
* cargo upgrade libp2p
* Get rid of `NetworkBehaviourEventProcess` in handling of `CustomMessageOutcome`
* Get rid of `NetworkBehaviourEventProcess` in handling of `request_responses::Event`
* Get rid of `NetworkBehaviourEventProcess` in handling of `peer_info::PeerInfoEvent`
* Get rid of `NetworkBehaviourEventProcess` in handling of `DiscoveryOut`
* Get rid of `poll()` method in `Bahaviour`
* minor: comments
* Upgrade libp2p to 0.49.0 (unreleased)
* Support multiple Kad protocol names
* Make borrow checker happy
* minor: wording
* Make substrate build with libp2p-0.49.0
* rustfmt
* Get rid of MdnsWrapper
* Resolve deprecation warnings
* Fix documentation
* Apply suggestions from code review: fix typos
Co-authored-by: Aaro Altonen <48052676+altonen@users.noreply.github.com>
* Apply suggestion: simplify kad protocol name matching
Co-authored-by: Aaro Altonen <48052676+altonen@users.noreply.github.com>
* Introduce `ChainSyncInterface`
`ChainSyncInterface` provides an asynchronous interface for other
subsystems to submit calls to `ChainSync`. This allows `NetworkService`
to delegate calls to `ChainSync` while still providing the same API
for other subsystems (for now). This makes it possible to move the
syncing code in piecemeal fashion out of `protocol.rs` as the calls
are just forwarded to `ChainSync`.
* Apply review comments
* Fix tests
* Introduce mockable `ChainSync` object for testing
`mockall` allows to mock `ChainSync` and to verify that the calls made
to `ChaiSync` are firstly executed at all, that they're executed in
correct order and with correct parameters.
This allows to verify, e.g., that delegating calls directly to
`ChainSync` from `NetworkService` still calls the correct functions with
correct arguments even if `Protocol` middleman is removed.
* Add Cargo.lock
* Fix tests
* Update client/network/Cargo.toml
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update Cargo.lock
* Fix clippy and documentation
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: parity-processbot <>
Sometimes `NotificationStreamOpenened` would be received for the
other protocol before `SyncConnected` was received so when the
connection was closed, an incorrect event was read from the event
stream.
* client/beefy: create communication module and move gossip there
* client/beefy: move beefy_protocol_name module to communication
* client/beefy: move notification module under communication
* client/beefy: add incoming request_response protocol handler
* client/beefy: keep track of connected peers and their progress
* client/beefy: add logic for generating Justif requests
* client/beefy: cancel outdated on-demand justification requests
* try Andre's suggestion for JustificationEngine
* justif engine add justifs validation
* client/beefy: impl OnDemandJustificationsEngine async next()
* move beefy proto name test
* client/beefy: initialize OnDemandJustificationsEngine
* client/tests: allow for custom req-resp protocols
* client/beefy: on-demand-justif: implement simple peer selection strategy
* client/beefy: fix voter initialization
Fix corner case where voter gets a single burst of finality
notifications just when it starts.
The notification stream was consumed by "wait_for_pallet" logic,
then main loop would subscribe to finality notifications, but by that
time some notifications might've been lost.
Fix this by subscribing the main loop to notifications before waiting
for pallet to become available. Share the same stream with the main loop
so that notifications for blocks before pallet available are ignored,
while _all_ notifications after pallet available are processed.
Add regression test for this.
Signed-off-by: acatangiu <adrian@parity.io>
* client/beefy: make sure justif requests are always out for mandatory blocks
* client/beefy: add test for on-demand justifications sync
* client/beefy: tweak main loop event processing order
* client/beefy: run on-demand-justif-handler under same async task as voter
* client/beefy: add test for known-peers
* client/beefy: reorg request-response module
* client/beefy: add issue references for future work todos
* client/beefy: consolidate on-demand-justifications engine state machine
Signed-off-by: acatangiu <adrian@parity.io>
* client/beefy: fix for polkadot companion
* client/beefy: implement review suggestions
* cargo fmt and clippy
* fix merge damage
* fix rust-doc
* fix merge damage
* fix merge damage
* client/beefy: add test for justif proto name
Signed-off-by: acatangiu <adrian@parity.io>
* Use `array-bytes` for All Array/Bytes/Hex Operations
Signed-off-by: Xavier Lau <xavier@inv.cafe>
* Reorder
* Self Review
* Format
* Fix Tests
* Bump `array-bytes`
* Optimize large test res
Signed-off-by: Xavier Lau <xavier@inv.cafe>
Co-authored-by: parity-processbot <>
* BREAKING: Rename Origin
* more renaming
* a bit more renaming
* fix
* more fixing
* fix in frame_support
* even more fixes
* fix
* small fix
* ...
* update .stderr
* docs
* update docs
* update docs
* docs
* Receive and import target block body
* Request target block
* minor: wording
* Check for block body in the test
* Import target block justifications
* Fix: do not fail block validation if no justifications received
* Fix: import target blocks without justifications
Co-authored-by: arkpar <arkady.paronyan@gmail.com>