Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
021f712
Update contract weights (#12192)
athei Sep 7, 2022
5e2ffeb
Move Get and bounded types to sp-core (#12203)
KiChjang Sep 7, 2022
c0e1cdb
Add `--header` to `benchmark overhead + storage` (#12204)
ggwpez Sep 7, 2022
2619394
Remove Ord impl for Weights V2 and add comparison fns (#12183)
KiChjang Sep 8, 2022
8075aa4
pallet-identity: Be more paranoid ;) (#12170)
bkchr Sep 8, 2022
e202092
Upgrade wasmtime to 0.40.0 (#12096)
bkchr Sep 8, 2022
0478535
Use parameter_types instead of thread_local for test-setup (#12036)
tifecool Sep 8, 2022
cd66db5
Fully remove `rusty-cachier` from the `node-bench-regression-guard` j…
rcny Sep 8, 2022
b8c3d8c
Upgrade wasm crate dependencies (#12173)
athei Sep 8, 2022
f9fdee1
Removing without_storage_info from scored-pool pallet. (#11996)
hbulgarini Sep 8, 2022
c8bfc91
Update ss58-registry (#12220)
MOZGIII Sep 8, 2022
5a48536
Add missing metadata specs to crate manifests (#12221)
Sep 8, 2022
51f60d0
construct_runtime: Fix generation of types behind features (#12229)
bkchr Sep 10, 2022
7de3d78
Remove native call (#12201)
bkchr Sep 12, 2022
d5de897
Fuzz testing for nomination pools (#12002)
kianenigma Sep 12, 2022
c997a62
Add `ConstFeeMultiplier` to the transaction payment pallet (#12222)
mrshiposha Sep 12, 2022
7cb78ff
Don't run `cargo-check-benches` for `master` based downstream staging…
rcny Sep 12, 2022
dd1f1b5
Expose some of the staking miner types over metadata (#12245)
kianenigma Sep 12, 2022
f1c60e5
extract some grandpa types to Primitives crate (#12208)
yjhmelody Sep 12, 2022
5527263
BREAKING: Rename Call & Event (#11981)
Szegoo Sep 12, 2022
379813c
Update README (#12247)
nuke-web3 Sep 13, 2022
5daa20c
Add inspect trait for asset roles (#11738)
girazoki Sep 13, 2022
c1103fd
Move bitswap to its own crate (#12242)
altonen Sep 13, 2022
9df9448
benches: disable caching per default (#12232)
ggwpez Sep 13, 2022
bb7fb64
Make `BasePath::new_temp_dir` return the same path for the program li…
bkchr Sep 13, 2022
3449fb0
Remove CanAuthorWith trait (#12213)
michalkucharczyk Sep 13, 2022
23bb5a6
Create sp-weights crate to store weight primitives (#12219)
KiChjang Sep 13, 2022
b5e2542
fix sp-weight std (#12265)
shawntabrizi Sep 14, 2022
7c2c0c1
Improve base weights consistency and make sure they're never zero (#1…
koute Sep 14, 2022
dc22e48
Fix Rust features (#11976)
ggwpez Sep 14, 2022
1dcb9ce
Clean up the logging output (#12253)
bkchr Sep 14, 2022
fd54957
Bump wasm-instrument (#12234)
athei Sep 15, 2022
3bef1ba
Include Bitswap into request response protocols (#12262)
altonen Sep 15, 2022
12b5b5a
Use `--locked` for Cargo in CI everywhere (#12270)
rcny Sep 15, 2022
8bd5510
Replace 'blake2-rfc' with rust-crypto 'blake2' crate (#12266)
davxy Sep 15, 2022
21adbaf
Expose tracks as a constant. (#12273)
gavofyork Sep 15, 2022
d65f4bb
client/beefy: fix voter initialization (#12274)
acatangiu Sep 16, 2022
7202ca6
Fix warp sync (#12281)
arkpar Sep 16, 2022
4d04aba
Add special tag to exclude runtime storage items from benchmarking (#…
sam0x17 Sep 16, 2022
03eb807
[Feature] Part 1: add TargetList for validator ranking (#12034)
ruseinov Sep 18, 2022
91b97b0
[Fix] Benchmark issue in staking (#12290)
ruseinov Sep 18, 2022
ee3c159
support upgrade hooks to directly pass data (#12185)
NingLin-P Sep 19, 2022
b541b2d
contracts: Use `WeakBoundedVec` for instrumented code (#12186)
athei Sep 19, 2022
c24431e
Fix CI (#12297)
ggwpez Sep 19, 2022
df3722c
Fix `cargo-check-benches` job (#12301)
rcny Sep 20, 2022
625de4f
[ci] Revert cancel-pipeline job (#12309)
alvicsam Sep 20, 2022
e7c515d
Proper naming wrt expectations (#12311)
sandreim Sep 20, 2022
97ad64b
Import target block body during warp sync (#12300)
dmitry-markin Sep 20, 2022
de5a7f6
rpc: Implement `chainSpec` RPC API (#12261)
lexnv Sep 20, 2022
006dbc0
Use temporary db for benchmarking (#12254)
michalkucharczyk Sep 20, 2022
a47f200
BREAKING: Rename Origin (#12258)
Szegoo Sep 20, 2022
409167e
Use `array-bytes` for All Array/Bytes/Hex Operations (#12190)
aurexav Sep 21, 2022
4e53bdc
Bound staking storage items (#12230)
Ank4n Sep 21, 2022
9df7ac8
Introduce 'intermediate_insert' method to hide implementation details…
davxy Sep 21, 2022
ae4ba19
Bump `wasmtime` to 1.0.0 (#12317)
koute Sep 21, 2022
be97615
Format templates and fix `--steps` default value (#12286)
ggwpez Sep 21, 2022
493b58b
Make automatic storage deposits resistant against changing deposit pr…
athei Sep 21, 2022
1253de6
pallet-utility: Disallow none origin (#12321)
bkchr Sep 22, 2022
cc4d5cc
Migrate remaining old decl_* macros to the new pallet attribute macro…
koushiro Sep 22, 2022
1f720c1
Rename anonymous to pure proxy (#12283)
shawntabrizi Sep 22, 2022
bffd6a3
Fast Unstake Pallet (#12129)
kianenigma Sep 23, 2022
397da27
bench: Use `_` instead of `::` in auto-generated file names (#12332)
ggwpez Sep 23, 2022
8161ee1
[Feature] Sequential migration execution for try-runtime (#12319)
ruseinov Sep 23, 2022
b34936a
[Fix] parameter_types! dead code errors (#12340)
ruseinov Sep 23, 2022
ffcd523
Independence of Slot-based algorithms from system Timestamp (#12224)
davxy Sep 23, 2022
fb77921
Const impls of base arithmetics for `Weights` with `u64` (#12322)
mustermeiszer Sep 24, 2022
9476d21
Add base-weight to `System::Extrinsic*` events (#12329)
ggwpez Sep 24, 2022
d0214e7
re add the migration checks for staking (#12330)
Ank4n Sep 24, 2022
4219b3a
Allow specifying immediate finalize for `manual-seal` (#12106)
cmichi Sep 25, 2022
badc92a
Removed OuterCall alias & doc fixes (#12349)
Szegoo Sep 25, 2022
fbd7e5a
[Enhancement] Remove optional Pool subscription from fast-unstake (#1…
ruseinov Sep 26, 2022
a0ec652
Remove discarded blocks and states from database by default (#11983)
hzy1919 Sep 26, 2022
0dbeaa0
re-export weight file for fast-unstsake pallet (#12352)
kianenigma Sep 26, 2022
f360c87
Move transactions protocol to its own crate (#12264)
altonen Sep 26, 2022
519fbaa
export more types from fast-untsake 🤦‍♂️ (#12353)
kianenigma Sep 27, 2022
1763ff2
Fix compilation on 1.66 nightly (#12363)
bkchr Sep 27, 2022
edca891
Relax Slots-based engines from Epochs (#12360)
davxy Sep 27, 2022
2a6c314
Pallet staking events to named enum (#12342)
Szegoo Sep 27, 2022
74daaf1
[fix] Bound staking ledger correctly with MaxUnlockingChunks from con…
Ank4n Sep 27, 2022
94b9646
[Feature] Add deposit to fast-unstake (#12366)
ruseinov Sep 27, 2022
2ee4cb4
Add missing CountedStorageMap in pallet::storage error info (#12356)
liuchengxu Sep 27, 2022
17c07af
Add storage size component to weights (#12277)
KiChjang Sep 28, 2022
01a905e
pallet-utility: Only disallow the `None` origin (#12351)
bkchr Sep 28, 2022
1b1a5e1
Fix staking migration (#12373)
ggwpez Sep 28, 2022
0ec4373
Support running the pallet benchmarks analysis without running the be…
koute Sep 28, 2022
d66adfa
fix: typo in AllPalletsWithSystem deprecated msg (#12379)
Sep 28, 2022
96de768
New Pallet: Root offences (#11943)
Szegoo Sep 28, 2022
e7f994d
bounding staking: `BoundedElectionProvider` trait (#12362)
Ank4n Sep 28, 2022
427fd09
BEEFY: impl TypeInfo for SignedCommitment (#12382)
serban300 Sep 29, 2022
61b9a4d
Properly set the max proof size weight on defaults and tests (#12383)
KiChjang Sep 29, 2022
c2026ca
Carry over where clauses defined in Config to Call and Hook (#12388)
KiChjang Sep 30, 2022
dbb72f3
unsafe_pruning flag removed (#12385)
michalkucharczyk Sep 30, 2022
952030c
pallet-mmr: generate historical proofs (#12324)
serban300 Sep 30, 2022
37664fe
Remove contracts RPCs (#12358)
athei Oct 2, 2022
9472af8
Beefy on-demand justifications as a custom RequestResponse protocol (…
acatangiu Oct 3, 2022
2579550
Fix `Weight::is_zero` (#12396)
ggwpez Oct 3, 2022
1b23ec9
Remove unnecessary Clone trait bounds on CountedStorageMap (#12402)
KiChjang Oct 3, 2022
6d7f76b
docs/CODEOWNERS: add @acatangiu as MMR owner (#12406)
acatangiu Oct 4, 2022
594d71a
Add @koute to `docs/CODEOWNERS` and update stale paths (#12408)
koute Oct 4, 2022
e77cbe3
BEEFY: Simplify hashing for pallet-beefy-mmr (#12393)
serban300 Oct 4, 2022
0051950
client/beefy: small code improvements (#12414)
acatangiu Oct 4, 2022
07e5ec5
[Fix] Rename VoterBagsList -> VoterList to match pdot (#12416)
ruseinov Oct 4, 2022
d11dd02
Use saturating add for alliance::disband witness data (#12418)
muharem Oct 4, 2022
91d072d
Bump prost to 0.11+ (#12419)
chevdor Oct 4, 2022
241b0d0
Improved election pallet testing (#12327)
Szegoo Oct 4, 2022
7a8de49
Adapt `pallet-contracts` to WeightV2 (#12421)
athei Oct 5, 2022
2cd4088
MMR: impl `TypeInfo` for some structures (#12423)
serban300 Oct 5, 2022
4cd3248
Don't send back empty proofs if light request fails (#12372)
tomaka Oct 5, 2022
87224cf
Implement `Clone` and `Default` for `Config` (#12397)
s0me0ne-unkn0wn Oct 5, 2022
eefba93
Bound uses of `Call` (#11649)
gavofyork Oct 5, 2022
fc67cbb
update kvdb & co (#12312)
ordian Oct 5, 2022
f447bee
Use `Option<Weight>` for contract dry-runs (#12429)
athei Oct 6, 2022
3cb5a40
Add pluggable BEEFY payload constructors (#12428)
acatangiu Oct 6, 2022
a84def9
Maximum value for `MultiplierUpdate` (#12282)
Szegoo Oct 6, 2022
f77f788
macro stubs for all pallet:: macros to improve documentation visibili…
sam0x17 Oct 6, 2022
4a5a9de
Upgrade pin-project (#12426)
bkchr Oct 7, 2022
a8e951d
Extend the lower bounds of some of the benchmarks to also include `0`…
koute Oct 7, 2022
1a5cdc8
BEEFY: Define a `BeefyVerify` trait for signatures (#12299)
serban300 Oct 7, 2022
b7c0562
fix comment math (#12452)
nuke-web3 Oct 8, 2022
460fff9
Remove "to_block" field from BlockRequests (#12447)
tomaka Oct 8, 2022
73c4f94
Vesting pallet - make WithdrawReasons configurable (#12109)
Lezek123 Oct 9, 2022
0c1ccda
Move block announcement protocol config out of `Protocol` (#12441)
altonen Oct 10, 2022
df81976
Dont ignore errors in pallet benchmarking (#12449)
ggwpez Oct 10, 2022
9672c36
Update UI tests for Rust 1.64 (#12440)
rcny Oct 10, 2022
488fc24
rpc: Implement `transaction` RPC API (#12328)
lexnv Oct 11, 2022
60be7b8
Remove the unused light client requests (#12470)
tomaka Oct 11, 2022
6072b90
Fix flaky service test (#12472)
altonen Oct 11, 2022
1bf2e6d
Rename `from_components` to `from_parts` (#12473)
KiChjang Oct 11, 2022
ccc8f6c
Avoid Unstable Sort (#12455)
shawntabrizi Oct 11, 2022
94b731c
Finalized block event triggers tx maintanance (#12305)
michalkucharczyk Oct 11, 2022
88db102
tx-pool: failing tests fixed (#12481)
michalkucharczyk Oct 12, 2022
06a9f0a
Clarify the "direction" field of block requests (#12438)
tomaka Oct 12, 2022
f8a0b7a
BlockId::Number refactor: trivial changes to BlockId::Hash (#12471)
michalkucharczyk Oct 12, 2022
b324e51
Dont use benchmark range on constant functions (#12456)
shawntabrizi Oct 12, 2022
94941a8
Punish peers for duplicate GRANDPA neighbor messages (#12462)
dmitry-markin Oct 13, 2022
983b6b0
Introduce mockable `ChainSync` object for testing (#12480)
altonen Oct 13, 2022
1f39c90
pallet-mmr: RPC API and Runtime API work with block numbers (#12345)
Szegoo Oct 13, 2022
fd00b14
Enable the `wasmtime`-based WASM executor by default (#12486)
koute Oct 13, 2022
6e04e48
Trivial BlockId::Number => Hash (#12490)
michalkucharczyk Oct 13, 2022
f313987
BlockId removal: refactor: Backend::state_at (#12488)
michalkucharczyk Oct 14, 2022
0ee0327
Try-runtime CLI fix weight parsing (#12491)
ggwpez Oct 14, 2022
6f453b5
Export fn code_hash (#12479)
kvinwang Oct 17, 2022
30a7a5b
Introduce `ChainSyncInterface` (#12489)
altonen Oct 17, 2022
951f075
sp-api: Remove invalid unsafe trait bounds (#12502)
bkchr Oct 17, 2022
273e264
pallet-mmr: fix offchain db for sync from zero (#12498)
acatangiu Oct 17, 2022
acacb53
Fix: typo (#12505)
omahs Oct 17, 2022
444cf9d
Upgrade libp2p to 0.49.0 (#12256)
dmitry-markin Oct 17, 2022
ed2466e
Execute try-state at end of each test to ensure pallet data integrity…
Ank4n Oct 17, 2022
e8a4408
Bump clap to 4.0.x and adjust to best practices (#12381)
skunert Oct 18, 2022
b9a555d
implement storage decode length for BTreeSet (#12503)
dharjeezy Oct 18, 2022
415648d
Decrease default --out-peers from 25 to 15 (#12434)
tomaka Oct 18, 2022
4c45673
Prepare for latest clippy (nightly 09-10-2022) (#12466)
bkchr Oct 18, 2022
281bcd4
derive Serialize/Deserialize for BeefyAuthoritySet (#12516)
serban300 Oct 18, 2022
e34b840
BlockId removal: refactor: StorageProvider (#12510)
michalkucharczyk Oct 18, 2022
487ac5c
Use `ArgAction::Set` for enable-offchain-indexing flag (#12521)
skunert Oct 18, 2022
49734dd
frame/utils: introduce `substrate-rpc-client` crate for RPC utils (#1…
niklasad1 Oct 18, 2022
399ab89
Force base weights to be the minimum only when the intercept is negat…
koute Oct 20, 2022
7a4e516
Update `pallet-multisig` benches (#12558)
ggwpez Oct 26, 2022
7eab46f
resolve conflicts version 31
devdanco Nov 14, 2022
6304e5a
Update TargetedFeeAdjustment struct
devdanco Nov 18, 2022
1dfd9b4
Merge branch 'mangata-dev' into mangata-dev-v0.9.31
devdanco Nov 28, 2022
c2f6367
add feature to crate
devdanco Nov 28, 2022
1f23be6
update orml version in test
devdanco Nov 28, 2022
f61d829
remove unnecessary try-runtime feature
devdanco Nov 30, 2022
3696593
feat: resolve confclits and fix fmt
devdanco Dec 12, 2022
b31aa9d
fix: benchmarking types
devdanco Dec 13, 2022
7b6b521
Merge branch 'mangata-dev' into mangata-dev-v0.9.31
devdanco Dec 20, 2022
c5a1bbe
feat: resolve conflicts after storage queue
devdanco Dec 21, 2022
34c492c
fix: tests
devdanco Dec 21, 2022
a73d548
Added pre and post upgrade hooks for try0runtime and remove pallet-tr…
Dec 23, 2022
f84f481
Minor try-runtime bug
Dec 23, 2022
61bcb2e
fix: inject inherets
devdanco Dec 30, 2022
3d36c5e
update reference
devdanco Dec 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move block announcement protocol config out of Protocol (paritytech…
…#12441)

* Move Role(s) to `sc-network-common`

* Introduce `NotificationHandshake` type

* Move block announce protocol config creation to `ChainSync`

* Include block announcement into `notification_protocols`

* Apply review comments

* Remove unneeded include

* Add missing include

* Apply review comments
  • Loading branch information
altonen authored Oct 10, 2022
commit 0c1ccdaa53556a106aa69c23f19527e435970237
2 changes: 1 addition & 1 deletion client/finality-grandpa/src/communication/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ use parity_scale_codec::{Decode, Encode};
use prometheus_endpoint::{register, CounterVec, Opts, PrometheusError, Registry, U64};
use rand::seq::SliceRandom;
use sc_network::{PeerId, ReputationChange};
use sc_network_common::protocol::event::ObservedRole;
use sc_network_common::protocol::role::ObservedRole;
use sc_network_gossip::{MessageIntent, ValidatorContext};
use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG};
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
Expand Down
5 changes: 1 addition & 4 deletions client/finality-grandpa/src/communication/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ use parity_scale_codec::Encode;
use sc_network::{config::Role, Multiaddr, PeerId, ReputationChange};
use sc_network_common::{
config::MultiaddrWithPeerId,
protocol::{
event::{Event as NetworkEvent, ObservedRole},
ProtocolName,
},
protocol::{event::Event as NetworkEvent, role::ObservedRole, ProtocolName},
service::{
NetworkBlock, NetworkEventStream, NetworkNotification, NetworkPeers,
NetworkSyncForkRequest, NotificationSender, NotificationSenderError,
Expand Down
1 change: 1 addition & 0 deletions client/finality-grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ pub fn grandpa_peers_set_config(
fallback_names: grandpa_protocol_name::LEGACY_NAMES.iter().map(|&n| n.into()).collect(),
// Notifications reach ~256kiB in size at the time of writing on Kusama and Polkadot.
max_notification_size: 1024 * 1024,
handshake: None,
set_config: sc_network_common::config::SetConfig {
in_peers: 0,
out_peers: 0,
Expand Down
2 changes: 1 addition & 1 deletion client/network-gossip/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ mod tests {
use quickcheck::{Arbitrary, Gen, QuickCheck};
use sc_network_common::{
config::MultiaddrWithPeerId,
protocol::event::ObservedRole,
protocol::role::ObservedRole,
service::{
NetworkBlock, NetworkEventStream, NetworkNotification, NetworkPeers,
NotificationSender, NotificationSenderError,
Expand Down
2 changes: 1 addition & 1 deletion client/network-gossip/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use ahash::AHashSet;
use libp2p::PeerId;
use lru::LruCache;
use prometheus_endpoint::{register, Counter, PrometheusError, Registry, U64};
use sc_network_common::protocol::{event::ObservedRole, ProtocolName};
use sc_network_common::protocol::{role::ObservedRole, ProtocolName};
use sp_runtime::traits::{Block as BlockT, Hash, HashFor};
use std::{collections::HashMap, iter, sync::Arc, time, time::Instant};

Expand Down
2 changes: 1 addition & 1 deletion client/network-gossip/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use libp2p::PeerId;
use sc_network_common::protocol::event::ObservedRole;
use sc_network_common::protocol::role::ObservedRole;
use sp_runtime::traits::Block as BlockT;

/// Validates consensus messages.
Expand Down
2 changes: 1 addition & 1 deletion client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ sp-runtime = { version = "6.0.0", path = "../../primitives/runtime" }

[dev-dependencies]
assert_matches = "1.3"
async-std = "1.11.0"
async-std = { version = "1.11.0", features = ["attributes"] }
rand = "0.7.2"
tempfile = "3.1.0"
sc-network-light = { version = "0.10.0-dev", path = "./light" }
Expand Down
28 changes: 28 additions & 0 deletions client/network/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use crate::protocol;

use codec::Encode;
use libp2p::{multiaddr, Multiaddr, PeerId};
use std::{fmt, str, str::FromStr};

Expand Down Expand Up @@ -199,6 +200,30 @@ impl Default for SetConfig {
}
}

/// Custom handshake for the notification protocol
#[derive(Debug, Clone)]
pub struct NotificationHandshake(Vec<u8>);

impl NotificationHandshake {
/// Create new `NotificationHandshake` from an object that implements `Encode`
pub fn new<H: Encode>(handshake: H) -> Self {
Self(handshake.encode())
}

/// Create new `NotificationHandshake` from raw bytes
pub fn from_bytes(bytes: Vec<u8>) -> Self {
Self(bytes)
}
}

impl std::ops::Deref for NotificationHandshake {
type Target = Vec<u8>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

/// Extension to [`SetConfig`] for sets that aren't the default set.
///
/// > **Note**: As new fields might be added in the future, please consider using the `new` method
Expand All @@ -218,6 +243,8 @@ pub struct NonDefaultSetConfig {
/// If a fallback is used, it will be reported in
/// `sc_network::protocol::event::Event::NotificationStreamOpened::negotiated_fallback`
pub fallback_names: Vec<protocol::ProtocolName>,
/// Handshake of the protocol
pub handshake: Option<NotificationHandshake>,
/// Maximum allowed size of single notifications.
pub max_notification_size: u64,
/// Base configuration.
Expand All @@ -231,6 +258,7 @@ impl NonDefaultSetConfig {
notifications_protocol,
max_notification_size,
fallback_names: Vec::new(),
handshake: None,
set_config: SetConfig {
in_peers: 0,
out_peers: 0,
Expand Down
1 change: 1 addition & 0 deletions client/network/common/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::{
use libp2p::core::upgrade;

pub mod event;
pub mod role;

/// The protocol name transmitted on the wire.
#[derive(Debug, Clone)]
Expand Down
24 changes: 1 addition & 23 deletions client/network/common/src/protocol/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
//! events that happen on the network like DHT get/put results received.

use super::ProtocolName;
use crate::protocol::role::ObservedRole;
use bytes::Bytes;
use libp2p::{core::PeerId, kad::record::Key};

Expand Down Expand Up @@ -97,26 +98,3 @@ pub enum Event {
messages: Vec<(ProtocolName, Bytes)>,
},
}

/// Role that the peer sent to us during the handshake, with the addition of what our local node
/// knows about that peer.
///
/// > **Note**: This enum is different from the `Role` enum. The `Role` enum indicates what a
/// > node says about itself, while `ObservedRole` is a `Role` merged with the
/// > information known locally about that node.
#[derive(Debug, Clone)]
pub enum ObservedRole {
/// Full node.
Full,
/// Light node.
Light,
/// Third-party authority.
Authority,
}

impl ObservedRole {
/// Returns `true` for `ObservedRole::Light`.
pub fn is_light(&self) -> bool {
matches!(self, Self::Light)
}
}
121 changes: 121 additions & 0 deletions client/network/common/src/protocol/role.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// This file is part of Substrate.

// Copyright (C) 2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use codec::{self, Encode, EncodeLike, Input, Output};

/// Role that the peer sent to us during the handshake, with the addition of what our local node
/// knows about that peer.
///
/// > **Note**: This enum is different from the `Role` enum. The `Role` enum indicates what a
/// > node says about itself, while `ObservedRole` is a `Role` merged with the
/// > information known locally about that node.
#[derive(Debug, Clone)]
pub enum ObservedRole {
/// Full node.
Full,
/// Light node.
Light,
/// Third-party authority.
Authority,
}

impl ObservedRole {
/// Returns `true` for `ObservedRole::Light`.
pub fn is_light(&self) -> bool {
matches!(self, Self::Light)
}
}

/// Role of the local node.
#[derive(Debug, Clone)]
pub enum Role {
/// Regular full node.
Full,
/// Actual authority.
Authority,
}

impl Role {
/// True for [`Role::Authority`].
pub fn is_authority(&self) -> bool {
matches!(self, Self::Authority)
}
}

impl std::fmt::Display for Role {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Full => write!(f, "FULL"),
Self::Authority => write!(f, "AUTHORITY"),
}
}
}

bitflags::bitflags! {
/// Bitmask of the roles that a node fulfills.
pub struct Roles: u8 {
/// No network.
const NONE = 0b00000000;
/// Full node, does not participate in consensus.
const FULL = 0b00000001;
/// Light client node.
const LIGHT = 0b00000010;
/// Act as an authority
const AUTHORITY = 0b00000100;
}
}

impl Roles {
/// Does this role represents a client that holds full chain data locally?
pub fn is_full(&self) -> bool {
self.intersects(Self::FULL | Self::AUTHORITY)
}

/// Does this role represents a client that does not participates in the consensus?
pub fn is_authority(&self) -> bool {
*self == Self::AUTHORITY
}

/// Does this role represents a client that does not hold full chain data locally?
pub fn is_light(&self) -> bool {
!self.is_full()
}
}

impl<'a> From<&'a Role> for Roles {
fn from(roles: &'a Role) -> Self {
match roles {
Role::Full => Self::FULL,
Role::Authority => Self::AUTHORITY,
}
}
}

impl Encode for Roles {
fn encode_to<T: Output + ?Sized>(&self, dest: &mut T) {
dest.push_byte(self.bits())
}
}

impl EncodeLike for Roles {}

impl codec::Decode for Roles {
fn decode<I: Input>(input: &mut I) -> Result<Self, codec::Error> {
Self::from_bits(input.read_byte()?).ok_or_else(|| codec::Error::from("Invalid bytes"))
}
}
28 changes: 27 additions & 1 deletion client/network/common/src/sync/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
//! Network packet message types. These get serialized and put into the lower level protocol
//! payload.

use crate::protocol::role::Roles;

use bitflags::bitflags;
use codec::{Decode, Encode, Error, Input, Output};
pub use generic::{BlockAnnounce, FromBlock};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor};

/// Type alias for using the block request type using block type parameters.
pub type BlockRequest<B> =
Expand Down Expand Up @@ -218,3 +220,27 @@ pub mod generic {
}
}
}

/// Handshake sent when we open a block announces substream.
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct BlockAnnouncesHandshake<B: BlockT> {
/// Roles of the node.
pub roles: Roles,
/// Best block number.
pub best_number: NumberFor<B>,
/// Best block hash.
pub best_hash: B::Hash,
/// Genesis block hash.
pub genesis_hash: B::Hash,
}

impl<B: BlockT> BlockAnnouncesHandshake<B> {
pub fn build(
roles: Roles,
best_number: NumberFor<B>,
best_hash: B::Hash,
genesis_hash: B::Hash,
) -> Self {
Self { genesis_hash, roles, best_number, best_hash }
}
}
5 changes: 3 additions & 2 deletions client/network/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate::{
discovery::{DiscoveryBehaviour, DiscoveryConfig, DiscoveryOut},
peer_info,
protocol::{message::Roles, CustomMessageOutcome, NotificationsSink, Protocol},
protocol::{CustomMessageOutcome, NotificationsSink, Protocol},
request_responses,
};

Expand All @@ -41,7 +41,8 @@ use sc_consensus::import_queue::{IncomingBlock, RuntimeOrigin};
use sc_network_common::{
config::ProtocolId,
protocol::{
event::{DhtEvent, ObservedRole},
event::DhtEvent,
role::{ObservedRole, Roles},
ProtocolName,
},
request_responses::{IfDisconnected, ProtocolConfig, RequestFailure},
Expand Down
29 changes: 4 additions & 25 deletions client/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

pub use sc_network_common::{
config::ProtocolId,
protocol::role::Role,
request_responses::{
IncomingRequest, OutgoingResponse, ProtocolConfig as RequestResponseConfig,
},
Expand Down Expand Up @@ -93,6 +94,9 @@ where
/// Registry for recording prometheus metrics to.
pub metrics_registry: Option<Registry>,

/// Block announce protocol configuration
pub block_announce_config: NonDefaultSetConfig,

/// Request response configuration for the block request protocol.
///
/// [`RequestResponseConfig::name`] is used to tag outgoing block requests with the correct
Expand Down Expand Up @@ -130,31 +134,6 @@ where
pub request_response_protocol_configs: Vec<RequestResponseConfig>,
}

/// Role of the local node.
#[derive(Debug, Clone)]
pub enum Role {
/// Regular full node.
Full,
/// Actual authority.
Authority,
}

impl Role {
/// True for [`Role::Authority`].
pub fn is_authority(&self) -> bool {
matches!(self, Self::Authority { .. })
}
}

impl fmt::Display for Role {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Full => write!(f, "FULL"),
Self::Authority { .. } => write!(f, "AUTHORITY"),
}
}
}

/// Sync operation mode.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum SyncMode {
Expand Down
Loading