Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Integrate BEEFY #9833

Merged
111 commits merged into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from 109 commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
9aa1f2a
Initial project setup and skeleton (#4)
andresilva Oct 19, 2020
539c62d
CI stuff (#5)
tomusdrw Oct 20, 2020
f3ab45d
Primitives & Light Client examples (#8)
tomusdrw Oct 22, 2020
ea541f9
Update to substrate master (#22)
andresilva Nov 18, 2020
cbda281
Add beefy pallet (#25)
andresilva Nov 20, 2020
89c151d
Signed commitments rpc pubsub (#26)
andresilva Nov 23, 2020
3a4cfa8
Integrate MMR and deposit root into the digest. (#24)
tomusdrw Nov 23, 2020
e34daee
use new mmr root as commitment payload (#27)
andresilva Dec 2, 2020
0b8fb24
Bump serde_json from 1.0.59 to 1.0.60 (#28)
dependabot-preview[bot] Dec 7, 2020
7aef40c
Update to latest substrate. (#32)
tomusdrw Dec 11, 2020
4b021a2
Bump serde from 1.0.117 to 1.0.118 (#29)
dependabot-preview[bot] Dec 14, 2020
741eb29
Remove transition flag (#35)
tomusdrw Jan 4, 2021
04faa42
Bump futures from 0.3.9 to 0.3.12 (#50)
dependabot-preview[bot] Jan 18, 2021
d81a358
Bump log from 0.4.11 to 0.4.13 (#52)
dependabot-preview[bot] Jan 18, 2021
a1ed94a
Bump Substrate and Deps (#57)
adoerr Jan 18, 2021
e1f86a4
Update README (#58)
adoerr Jan 19, 2021
4f9bd95
Add validator set to the pallet. (#65)
tomusdrw Jan 22, 2021
7bd2795
Bump Substrate and Deps (#71)
adoerr Jan 25, 2021
85d81b2
Beefy pallet test (#74)
adoerr Feb 2, 2021
ad86b0e
Beefy node cleanup (#75)
adoerr Feb 3, 2021
162cc4c
Migrate beefy-pallet to FRAMEv2 (#76)
adoerr Feb 4, 2021
bb093c9
Run BEEFY worker as non-validator (#77)
adoerr Feb 5, 2021
a0706aa
Bump Substrate and Deps (#79)
adoerr Feb 8, 2021
152e588
Add BEEFY gadget as extra peer set (#80)
adoerr Feb 8, 2021
442c741
Add ValidatorSetId to BEEFY digest (#85)
adoerr Feb 15, 2021
66b2b8d
Bump Substrate and Deps (#91)
adoerr Feb 27, 2021
5aef902
Bump serde_json from 1.0.63 to 1.0.64 (#93)
dependabot-preview[bot] Mar 1, 2021
639790a
Track BEEFY validator set (#94)
adoerr Mar 3, 2021
314fa20
Ad 92 (#97)
adoerr Mar 4, 2021
4e2f63a
Add error type (#99)
adoerr Mar 5, 2021
ab1039d
Extract worker and round logic (#104)
adoerr Mar 5, 2021
80eaa52
Bump serde from 1.0.123 to 1.0.124 (#106)
dependabot-preview[bot] Mar 8, 2021
64799ea
Rework BeefyAPI (#110)
adoerr Mar 9, 2021
e1b3f9b
Initialize BeefyWorker with current validator set (#111)
adoerr Mar 10, 2021
87e5f0d
Update toolchain (#115)
adoerr Mar 11, 2021
7120b62
Bump Substrate and Deps (#117)
adoerr Mar 15, 2021
c010f95
Delayed BEEFY worker initialization (#121)
adoerr Mar 22, 2021
e343d47
Bump substrate. (#123)
tomusdrw Mar 22, 2021
9e28469
Lower log-level for a missing validator set (#124)
adoerr Mar 23, 2021
c88af04
Setup Prometheus metrics (#125)
adoerr Mar 24, 2021
9450b54
Make Client convenience trait public (#126)
adoerr Mar 25, 2021
58fa17c
Bump serde from 1.0.124 to 1.0.125 (#131)
dependabot-preview[bot] Mar 29, 2021
1983235
Reset rounds on new validator set. (#133)
tomusdrw Apr 1, 2021
0092db3
Bump Substrate and Deps (#134)
adoerr Apr 2, 2021
0c02f26
beefy: authority set changes fixes (#139)
andresilva Apr 6, 2021
6ecfeb8
gadget: remove superfluous signature type (#140)
andresilva Apr 6, 2021
69f1f46
gadget: reduce gossip spam (#141)
andresilva Apr 7, 2021
1d94b0f
gadget: verify SignedCommitment message signature (#142)
andresilva Apr 8, 2021
d3dd36e
Bump futures from 0.3.13 to 0.3.14 (#145)
dependabot-preview[bot] Apr 12, 2021
75ea15d
Milestone 1 (#144)
adoerr Apr 14, 2021
9da8233
Extract BeefyGossipValidator (#147)
adoerr Apr 14, 2021
40e81a6
Add block_delta parameter to start_beefy_gadget (#151)
adoerr Apr 16, 2021
bd3a85f
Add additional metrics (#152)
adoerr Apr 19, 2021
2e9b4bf
don't log under info for every concluded round (#156)
andresilva Apr 20, 2021
6b6a467
don't log error on missing validator keys (#157)
andresilva Apr 20, 2021
11786fc
Fix validator set change handling (#158)
andresilva Apr 21, 2021
5fb0be3
Fix should_vote_on() (#160)
adoerr Apr 26, 2021
8f7f4e2
Make KeyStore optional (#173)
adoerr Apr 30, 2021
532c858
Use builder pattern for NonDefaultSetConfig (#178)
tomaka May 4, 2021
088fa19
Append SignedCommitment to block justifications (#177)
adoerr May 11, 2021
45acbe1
Bump serde from 1.0.125 to 1.0.126 (#184)
dependabot[bot] May 17, 2021
bff1de1
Bump strum from 0.20.0 to 0.21.0 (#195)
dependabot[bot] Jun 7, 2021
31043a7
Make concluded round an info log (#200)
adoerr Jun 12, 2021
386855b
Remove external crypto trait bounds (#207)
adoerr Jun 17, 2021
7da9470
Rename AuthorityId to BeefyId to avoid type conflict in UI (#211)
tomusdrw Jun 17, 2021
600f286
Add trace points; Reduce MAX_LIVE_GOSSIP_ROUNDS (#210)
adoerr Jun 18, 2021
8676c10
Additional initial authority id's (#217)
adoerr Jun 23, 2021
2edf07c
Fix note_round() (#219)
adoerr Jun 25, 2021
e08e656
Use LocalKeystore for tests (#224)
adoerr Jul 1, 2021
b0e0cdb
Cache known votes in gossip (#227)
tomusdrw Jul 5, 2021
9234d02
Some key store sanity checks (#232)
adoerr Jul 7, 2021
9a8773f
Use Binary Merkle Tree instead of a trie (#225)
tomusdrw Jul 8, 2021
5a89c81
Bump Substrate and Deps (#235)
adoerr Jul 13, 2021
3f5de10
BEEFY+MMR pallet (#236)
tomusdrw Jul 14, 2021
40f23ab
Fix noting rounds for non-authorities (#238)
adoerr Jul 14, 2021
03092f8
Bump env_logger from 0.8.4 to 0.9.0 (#242)
dependabot[bot] Jul 19, 2021
66a2ada
gadget: add global timeout for rebroadcasting messages (#243)
andresilva Jul 19, 2021
7114147
Bump Substrate and Deps (#245)
adoerr Jul 23, 2021
90bd59c
Bump futures from 0.3.15 to 0.3.16 (#247)
dependabot[bot] Jul 26, 2021
af8bb2e
Bump libsecp256k1 from 0.5.0 to 0.6.0 (#249)
dependabot[bot] Jul 26, 2021
b0ac09f
Derive `scale_info::TypeInfo` for types used in polkadot (#218)
ascjones Jul 30, 2021
bddaf98
Bump serde from 1.0.126 to 1.0.127 (#260)
dependabot[bot] Aug 2, 2021
ef89227
Bump Substrate and Deps (#262)
adoerr Aug 9, 2021
a0cc00e
Update jsonrpc (#265)
bkchr Aug 13, 2021
ccc148c
bump Substrate and Deps (#268)
adoerr Aug 17, 2021
4274bea
Bump serde from 1.0.127 to 1.0.128 (#272)
dependabot[bot] Aug 23, 2021
6b062b5
Fix spelling (#271)
drewstone Aug 23, 2021
79663a7
Bump serde from 1.0.128 to 1.0.130 (#276)
dependabot[bot] Aug 30, 2021
39fbb7a
Bump scale-info from 0.10.0 to 0.12.0 (#275)
dependabot[bot] Aug 30, 2021
3dd7ea3
Update to scale-info 1.0 (#278)
ascjones Sep 1, 2021
5a271ad
bump substrate (#282)
ordian Sep 5, 2021
81a2d86
Update worker.rs (#287)
drewstone Sep 9, 2021
a54f151
Bump anyhow from 1.0.43 to 1.0.44 (#290)
dependabot[bot] Sep 13, 2021
b2a2f7f
Remove optional `scale-info` feature (#292)
ascjones Sep 15, 2021
fde16c2
prune .git suffix (#294)
JoshOrndorff Sep 16, 2021
ec91dc1
remove unused deps (#295)
gilescope Sep 17, 2021
1afb853
Bump libsecp256k1 from 0.6.0 to 0.7.0 (#296)
dependabot[bot] Sep 20, 2021
9dbda20
Merge BEEFY master
adoerr Sep 21, 2021
2ecebb4
clean compile
adoerr Sep 21, 2021
2068171
use path dependencies
adoerr Sep 21, 2021
aacad37
beefy-gadget license header
adoerr Sep 21, 2021
9ee380b
pallet-beefy license header
adoerr Sep 21, 2021
144ad93
pallet-beefy-mmr license header
adoerr Sep 21, 2021
d256dc4
beefy-primitves license header
adoerr Sep 21, 2021
74eb9cc
carg fmt
adoerr Sep 22, 2021
bedf6f3
more formatting
adoerr Sep 22, 2021
0c57822
shorten line
adoerr Sep 22, 2021
c41f050
Merge Substrate master
adoerr Sep 22, 2021
41d4774
downgrade parity-scale-codec to 2.2.0
adoerr Sep 22, 2021
4b5e690
use path dependency for Prometheus endpoint
adoerr Sep 22, 2021
ea2fd96
remove clippy annotations
adoerr Sep 23, 2021
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
235 changes: 208 additions & 27 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ members = [
"client/api",
"client/authority-discovery",
"client/basic-authorship",
"client/beefy",
"client/beefy/rpc",
"client/block-builder",
"client/chain-spec",
"client/chain-spec/derive",
Expand Down Expand Up @@ -69,6 +71,9 @@ members = [
"frame/authorship",
"frame/babe",
"frame/balances",
"frame/beefy",
"frame/beefy-mmr",
"frame/beefy-mmr/primitives",
"frame/benchmarking",
"frame/bounties",
"frame/collective",
Expand Down Expand Up @@ -138,6 +143,7 @@ members = [
"primitives/arithmetic/fuzzer",
"primitives/authority-discovery",
"primitives/authorship",
"primitives/beefy",
"primitives/block-builder",
"primitives/blockchain",
"primitives/consensus/aura",
Expand Down
38 changes: 38 additions & 0 deletions client/beefy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "beefy-gadget"
version = "4.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]
fnv = "1.0.6"
futures = "0.3"
log = "0.4"
parking_lot = "0.11"
thiserror = "1.0"
wasm-timer = "0.2.5"

codec = { version = "2.2.0", package = "parity-scale-codec", features = ["derive"] }
prometheus = { package = "substrate-prometheus-endpoint", git = "https://github.com/paritytech/substrate", branch = "master" }
adoerr marked this conversation as resolved.
Show resolved Hide resolved

sp-api = { version = "4.0.0-dev", path = "../../primitives/api" }
sp-application-crypto = { version = "4.0.0-dev", path = "../../primitives/application-crypto" }
sp-arithmetic = { version = "4.0.0-dev", path = "../../primitives/arithmetic" }
sp-blockchain = { version = "4.0.0-dev", path = "../../primitives/blockchain" }
sp-core = { version = "4.0.0-dev", path = "../../primitives/core" }
sp-keystore = { version = "0.10.0-dev", path = "../../primitives/keystore" }
sp-runtime = { version = "4.0.0-dev", path = "../../primitives/runtime" }

sc-utils = { version = "4.0.0-dev", path = "../utils" }
sc-client-api = { version = "4.0.0-dev", path = "../api" }
sc-keystore = { version = "4.0.0-dev", path = "../keystore" }
sc-network = { version = "0.10.0-dev", path = "../network" }
sc-network-gossip = { version = "0.10.0-dev", path = "../network-gossip" }

beefy-primitives = { version = "4.0.0-dev", path = "../../primitives/beefy" }

[dev-dependencies]
sc-network-test = { version = "0.8.0", path = "../network/test" }

strum = { version = "0.21", features = ["derive"] }
26 changes: 26 additions & 0 deletions client/beefy/rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "beefy-gadget-rpc"
version = "4.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]
futures = "0.3.16"
log = "0.4"
serde = { version = "1.0.130", features = ["derive"] }

jsonrpc-core = "18.0.0"
jsonrpc-core-client = "18.0.0"
jsonrpc-derive = "18.0.0"
jsonrpc-pubsub = "18.0.0"

codec = { version = "2.2.0", package = "parity-scale-codec", features = ["derive"] }

sc-rpc = { version = "4.0.0-dev", path = "../../rpc" }

sp-core = { version = "4.0.0-dev", path = "../../../primitives/core" }
sp-runtime = { versin = "4.0.0-dev", path = "../../../primitives/runtime" }

beefy-gadget = { version = "4.0.0-dev", path = "../." }
beefy-primitives = { version = "4.0.0-dev", path = "../../../primitives/beefy" }
115 changes: 115 additions & 0 deletions client/beefy/rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// This file is part of Substrate.

// Copyright (C) 2021 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/>.

//! RPC API for BEEFY.

#![warn(missing_docs)]

use std::sync::Arc;

use sp_runtime::traits::Block as BlockT;

use futures::{FutureExt, SinkExt, StreamExt};
use jsonrpc_derive::rpc;
use jsonrpc_pubsub::{manager::SubscriptionManager, typed::Subscriber, SubscriptionId};
use log::warn;

use beefy_gadget::notification::BeefySignedCommitmentStream;

mod notification;

/// Provides RPC methods for interacting with BEEFY.
#[allow(clippy::needless_return)]
#[rpc]
pub trait BeefyApi<Notification, Hash> {
/// RPC Metadata
type Metadata;

/// Returns the block most recently finalized by BEEFY, alongside side its justification.
#[pubsub(
subscription = "beefy_justifications",
subscribe,
name = "beefy_subscribeJustifications"
)]
fn subscribe_justifications(
&self,
metadata: Self::Metadata,
subscriber: Subscriber<Notification>,
);

/// Unsubscribe from receiving notifications about recently finalized blocks.
#[pubsub(
subscription = "beefy_justifications",
unsubscribe,
name = "beefy_unsubscribeJustifications"
)]
fn unsubscribe_justifications(
&self,
metadata: Option<Self::Metadata>,
id: SubscriptionId,
) -> jsonrpc_core::Result<bool>;
}

/// Implements the BeefyApi RPC trait for interacting with BEEFY.
pub struct BeefyRpcHandler<Block: BlockT> {
signed_commitment_stream: BeefySignedCommitmentStream<Block>,
manager: SubscriptionManager,
}

impl<Block: BlockT> BeefyRpcHandler<Block> {
/// Creates a new BeefyRpcHandler instance.
pub fn new<E>(signed_commitment_stream: BeefySignedCommitmentStream<Block>, executor: E) -> Self
where
E: futures::task::Spawn + Send + Sync + 'static,
{
let manager = SubscriptionManager::new(Arc::new(executor));
Self { signed_commitment_stream, manager }
}
}

impl<Block> BeefyApi<notification::SignedCommitment, Block> for BeefyRpcHandler<Block>
where
Block: BlockT,
{
type Metadata = sc_rpc::Metadata;

fn subscribe_justifications(
&self,
_metadata: Self::Metadata,
subscriber: Subscriber<notification::SignedCommitment>,
) {
let stream = self
.signed_commitment_stream
.subscribe()
.map(|x| Ok::<_, ()>(Ok(notification::SignedCommitment::new::<Block>(x))));

self.manager.add(subscriber, |sink| {
stream
.forward(sink.sink_map_err(|e| warn!("Error sending notifications: {:?}", e)))
.map(|_| ())
});
}

fn unsubscribe_justifications(
&self,
_metadata: Option<Self::Metadata>,
id: SubscriptionId,
) -> jsonrpc_core::Result<bool> {
Ok(self.manager.cancel(id))
}
}
39 changes: 39 additions & 0 deletions client/beefy/rpc/src/notification.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This file is part of Substrate.

// Copyright (C) 2021 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::Encode;
use serde::{Deserialize, Serialize};

use sp_runtime::traits::Block as BlockT;

/// An encoded signed commitment proving that the given header has been finalized.
/// The given bytes should be the SCALE-encoded representation of a
/// `beefy_primitives::SignedCommitment`.
#[derive(Clone, Serialize, Deserialize)]
pub struct SignedCommitment(sp_core::Bytes);

impl SignedCommitment {
pub fn new<Block>(
signed_commitment: beefy_gadget::notification::SignedCommitment<Block>,
) -> Self
where
Block: BlockT,
{
SignedCommitment(signed_commitment.encode().into())
}
}
31 changes: 31 additions & 0 deletions client/beefy/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// This file is part of Substrate.

// Copyright (C) 2021 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/>.

//! BEEFY gadget specific errors
//!
//! Used for BEEFY gadget interal error handling only

use std::fmt::Debug;

#[derive(Debug, thiserror::Error, PartialEq)]
pub enum Error {
#[error("Keystore error: {0}")]
Keystore(String),
#[error("Signature error: {0}")]
Signature(String),
}
Loading