Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BEEFY: add support for slashing validators signing forking commitments #1903

Closed
Show file tree
Hide file tree
Changes from 179 commits
Commits
Show all changes
205 commits
Select commit Hold shift + click to select a range
d8964df
sc-consensus-beefy: add BEEFY fisherman to gossip network
acatangiu Jul 5, 2023
a2678a0
sp-consensus-beefy: add invalid fork vote proof and equivalent BeefyApi
acatangiu Jul 5, 2023
17398d8
pallet-beefy: add stubs for reporting invalid fork votes
acatangiu Jul 5, 2023
df31624
sc-consensus-beefy: fisherman reports invalid votes and justifications
acatangiu Jul 5, 2023
938cde1
don't check GRANDPA finality
Lederstrumpf Jul 20, 2023
fb08553
change primitive: vote -> commitment
Lederstrumpf Jul 20, 2023
39799b2
add check_signed_commitment/report_invalid_payload
Lederstrumpf Jul 27, 2023
4aa602a
update comments
Lederstrumpf Aug 2, 2023
e0e13d9
add dummy for report of invalid fork commitments
Lederstrumpf Aug 2, 2023
165d7fc
account for #14471
Lederstrumpf Aug 1, 2023
c7df83b
account for #14373
Lederstrumpf Aug 7, 2023
754ae80
EquivocationOffence.{offender->offenders}
Lederstrumpf Aug 7, 2023
6ed4e99
EquivocationProof->VoteEquivocationProof
Lederstrumpf Aug 7, 2023
1e41551
Invalid{""->Vote}EquivocationProof
Lederstrumpf Aug 7, 2023
de2ae90
check_{""->vote}_equivocation_proof
Lederstrumpf Aug 7, 2023
273f34b
InvalidForkCommitmentProof->ForkEquivocationProof
Lederstrumpf Aug 7, 2023
eb1e549
renames across submit_report_...
Lederstrumpf Aug 7, 2023
3369783
convert EquivocationEvidenceFor to enum (minimal)
Lederstrumpf Aug 7, 2023
7abbddc
handle ForkEquivocationProof enum variant
Lederstrumpf Aug 7, 2023
8acea22
reduce find_mmr_root_digest trait constraint
Lederstrumpf Aug 8, 2023
103fc53
fix fork equiv. call interfaces (vecs of sigs)
Lederstrumpf Aug 8, 2023
1509a26
check proof's payload against correct header's
Lederstrumpf Aug 8, 2023
a62cc7f
rm superfluous report_fork_equiv.correct_header
Lederstrumpf Aug 8, 2023
5445977
remove duplic. in check_{signed_commitment, proof}
Lederstrumpf Aug 8, 2023
d35a97c
update outdated comments
Lederstrumpf Aug 8, 2023
4e3e1cc
remove report_invalid_payload
Lederstrumpf Aug 8, 2023
f27a876
.+report.+{""->_vote}_equivocations
Lederstrumpf Aug 8, 2023
f641759
move correct_header hash check into primitives
Lederstrumpf Aug 9, 2023
5c4104c
create_beefy_worker: only push block if at genesis
Lederstrumpf Aug 9, 2023
a0d8b87
create_beefy_worker: opt. instantiate with TestApi
Lederstrumpf Aug 9, 2023
9126904
push to reported_fork_equivocations
Lederstrumpf Aug 9, 2023
02da07e
add generate_fork_equivocation_proof_vote to tests
Lederstrumpf Aug 9, 2023
a3b4d3f
test: Alice snitches on Bob's vote equivocation
Lederstrumpf Aug 9, 2023
d44e3c8
store reference to key_store in fisherman
Lederstrumpf Aug 10, 2023
c27579c
test: Alice doesn't snitch *own* vote equivocation
Lederstrumpf Aug 10, 2023
5516837
un-stub submit_unsigned_fork_equivocation_report
Lederstrumpf Aug 10, 2023
60a71c7
Alice reports Bob & Charlie's signed commitment
Aug 24, 2023
ec99b1a
cleanup
Lederstrumpf Aug 24, 2023
ea7dd35
remove superfluous None check
Lederstrumpf Aug 24, 2023
3185776
fixup! check proof's payload against correct header's
Lederstrumpf Aug 28, 2023
59c1c2a
fmt
Lederstrumpf Aug 28, 2023
ab3eb02
missing keystore
Lederstrumpf Aug 29, 2023
844ed67
graft https://github.com/paritytech/polkadot/pull/7634
Lederstrumpf Aug 29, 2023
6ebebed
impl equiv. runtime interfaces kusama/westend
Lederstrumpf Aug 29, 2023
efe4b2a
clone beefy pallet equivocation tests
Lederstrumpf Aug 31, 2023
d0dba3b
test renames
Lederstrumpf Aug 31, 2023
b438866
test fork equivocation (via vote) reports
Lederstrumpf Aug 31, 2023
bd856ac
handle fork equivocations in validate_unsigned & pre_dispatch
Lederstrumpf Aug 31, 2023
9e1e7b1
clone tests for fork equivocations via commitments
Lederstrumpf Aug 31, 2023
f5b1ec5
bump number of beefy authorities in tests
Lederstrumpf Sep 1, 2023
7504b96
test fork equivocation (via commitment) reports
Lederstrumpf Sep 1, 2023
036fa2f
cleanup & TODOs
Lederstrumpf Sep 3, 2023
53e8ae0
test that overlapping reports stack correctly
Lederstrumpf Sep 3, 2023
8a14649
note re. temporary equivocation proof structure
Lederstrumpf Sep 4, 2023
4074a27
Merge remote-tracking branch 'origin/master' into rhmb/beefy-slashing…
Lederstrumpf Sep 5, 2023
e5537dd
fmt
Lederstrumpf Sep 5, 2023
c815af6
cleanup & remove TODO
Lederstrumpf Sep 5, 2023
35330bb
Merge remote-tracking branch 'origin/master' into rhmb/beefy-slashing…
Lederstrumpf Sep 5, 2023
bb2e791
add reference to #1441
Lederstrumpf Sep 7, 2023
936406b
Merge remote-tracking branch 'origin/master' into rhmb/beefy-slashing…
Lederstrumpf Sep 7, 2023
16c12eb
Merge remote-tracking branch 'origin/master' into rhmb/beefy-slashing…
Lederstrumpf Oct 17, 2023
8b48fec
fixup! Merge remote-tracking branch 'origin/master' into rhmb/beefy-s…
Lederstrumpf Oct 17, 2023
ddd22d2
use ckb-merkle-mountain-range fork
Lederstrumpf Sep 12, 2023
5a4f840
integrate new proof data structure into api
Lederstrumpf Sep 14, 2023
c0db0ca
adjust tests for new proof data structure
Lederstrumpf Sep 14, 2023
a65014d
fix Proof type parameter usage
Lederstrumpf Oct 9, 2023
e642dc4
stubs for tests
Lederstrumpf Oct 9, 2023
e882e01
integrate ancestry proof into equivocation proofs
Lederstrumpf Oct 10, 2023
f348a86
fix proof serde tests
Lederstrumpf Oct 10, 2023
05b82fa
add generate_ancestry_proof to pallet-mmr
Lederstrumpf Oct 12, 2023
9e2ec2a
pallet beefy: ancestry proof gen. & reporting
Lederstrumpf Oct 16, 2023
a6927af
fisher & worker: ancestry proof gen. & reporting
Lederstrumpf Oct 16, 2023
03208f1
tests: report_fork_equivocation_vote_old_set_works
Lederstrumpf Oct 16, 2023
9208734
verify prev_root is at correct block number
Lederstrumpf Oct 17, 2023
852d110
fisherman: retrieve first_mmr_block_num
Lederstrumpf Oct 17, 2023
9e91cf3
impl ancestry in all applicable beefy pallet tests
Lederstrumpf Oct 17, 2023
36e8acf
ckb: disable default-features
Lederstrumpf Oct 25, 2023
3198cb7
implement mmr_api v3 on rococo/westend
Lederstrumpf Oct 25, 2023
16a80f8
fmt
Lederstrumpf Oct 25, 2023
70b970b
require at least header OR ancestry proof, not both
Lederstrumpf Nov 2, 2023
04db083
remove headers from equiv. proofs in frame tests
Lederstrumpf Nov 2, 2023
933cb64
refactor fisherman: cleanup
Lederstrumpf Nov 8, 2023
223370a
handle "equivocations" on future blocks
Lederstrumpf Nov 8, 2023
ab891da
update documentation comment
Lederstrumpf Nov 8, 2023
ab83492
refactor `check_fork_equivocation_proof`
Lederstrumpf Nov 8, 2023
912d5dc
recurse De Morgan's Laws
Lederstrumpf Nov 8, 2023
6efed14
loosen proof failure condition
Lederstrumpf Nov 8, 2023
ccac61f
refactor fork equivocation check
Lederstrumpf Nov 8, 2023
dc56cab
refactor flow
Lederstrumpf Nov 9, 2023
55f8932
split up fork equiv. proof check
Lederstrumpf Nov 9, 2023
f71b3ad
refactor: comments & conciseness
Lederstrumpf Nov 9, 2023
a737d2c
Revert "integrate new proof data structure into api"
Lederstrumpf Nov 9, 2023
ba66fde
Revert "fix Proof type parameter usage"
Lederstrumpf Nov 9, 2023
5d263a4
Revert "adjust tests for new proof data structure"
Lederstrumpf Nov 9, 2023
442d3e9
cleanup api change reversion
Lederstrumpf Nov 21, 2023
4200f5b
bump ckb-merkle-mountain-range 0.5.2 -> 0.6.0
Lederstrumpf Nov 21, 2023
e1269fd
segregate Proofs and NodeProofs
Lederstrumpf Nov 21, 2023
7222fa5
primitives::{Proof->LeafProof}
Lederstrumpf Nov 21, 2023
2e3cb9f
bump mmr-lib
Lederstrumpf Nov 21, 2023
9a32a60
fix kitchensink runtime MmrApi impl
Lederstrumpf Nov 21, 2023
828502c
test-runtime: impl MmrApi
Lederstrumpf Nov 21, 2023
b185596
Merge remote-tracking branch 'origin/master' into rhmb/beefy-slashing…
Lederstrumpf Nov 21, 2023
9da3ea5
account for #1189
Lederstrumpf Nov 22, 2023
12b8eec
Revert "fix proof serde tests"
Lederstrumpf Nov 22, 2023
28cf54a
fix docs
Lederstrumpf Nov 23, 2023
f8bf630
refactor check_fork_equivocation_proof
Lederstrumpf Nov 27, 2023
87652dc
test slashing of future block commitments/votes
Lederstrumpf Nov 27, 2023
5ac0893
fisher: don't fail on key ownership proof errors
Lederstrumpf Nov 27, 2023
5f47c9d
report_fork_equivocation: Result<{()->bool}, ..>
Lederstrumpf Nov 28, 2023
96de837
test all combinations of header & ancestry proofs
Lederstrumpf Nov 28, 2023
c46ebe7
slash commitments to future blocks
Lederstrumpf Nov 28, 2023
784aef1
only report equivocation if non-zero signers
Lederstrumpf Nov 28, 2023
d7c5373
improve docs & naming
Lederstrumpf Nov 28, 2023
86629c2
Merge remote-tracking branch 'origin/master' into rhmb/beefy-slashing…
Lederstrumpf Nov 28, 2023
b9e8052
account for #2446
Lederstrumpf Nov 28, 2023
9a974f9
bump `BeefyApi` version
Lederstrumpf Nov 28, 2023
dbb62dc
Merge remote-tracking branch 'origin/master' into rhmb/beefy-slashing…
Lederstrumpf Dec 7, 2023
3196327
fix `should_initialize_voter_at_custom_genesis`
Lederstrumpf Dec 14, 2023
ef5ad84
forward-port `{correct→canonical}_header`
Lederstrumpf Dec 14, 2023
bebd108
`{expected→canonical}_...` renames
Lederstrumpf Dec 14, 2023
9d917f9
impl serde for `application_crypto::Signature`
Lederstrumpf Dec 18, 2023
a123e78
impl serde for `sp_core::bandersnatch::Signature`
Lederstrumpf Dec 18, 2023
7a28ac3
stub for `check_versioned_finality_proof`
Lederstrumpf Dec 18, 2023
940d846
update docs
Lederstrumpf Jan 4, 2024
e680e6b
Doc: payload checking reports equivocations too
Lederstrumpf Jan 4, 2024
0f8c8bd
Revert "impl serde for `sp_core::bandersnatch::Signature`"
Lederstrumpf Jan 4, 2024
abea602
Revert "impl serde for `application_crypto::Signature`"
Lederstrumpf Jan 4, 2024
10d9ed5
Revert "stub for `check_versioned_finality_proof`"
Lederstrumpf Jan 4, 2024
20968b1
fixup! Doc: payload checking reports equivocations too
Lederstrumpf Jan 4, 2024
370f765
filter invalidly signed commitments at call site
Lederstrumpf Jan 4, 2024
28502cd
Apply suggestions from code review
Lederstrumpf Jan 11, 2024
d18897d
migrate BeefyFisherman trait fns into Fisherman
Lederstrumpf Jan 11, 2024
8a2a4af
consistent lexical ordering of generic parameters
Lederstrumpf Jan 11, 2024
3904ce5
Merge remote-tracking branch 'origin/master' into rhmb/beefy-slashing…
Lederstrumpf Jan 11, 2024
35b302d
account for #2856
Lederstrumpf Jan 11, 2024
ddee581
fix sc_consensus_beefy integration tests
Lederstrumpf Jan 11, 2024
30ea46c
fix sc_consensus_beefy::communication::gossip "unit" tests
Lederstrumpf Jan 11, 2024
0283226
fmt
Lederstrumpf Jan 11, 2024
a639db6
revert removal of header hash verification
Lederstrumpf Jan 11, 2024
ba13cf2
fix missed rename
Lederstrumpf Jan 15, 2024
7078598
distinguish weights for report_{fork,vote}_equivocation
Lederstrumpf Jan 15, 2024
fa73cb5
clippy lints
Lederstrumpf Jan 15, 2024
c01784c
tighten equivocation reporting: future -> unfinalized blocks
Lederstrumpf Jan 16, 2024
dc84223
Revert "tighten equivocation reporting: future -> unfinalized blocks"
Lederstrumpf Jan 16, 2024
816b726
use `expect_validator_set_nonblocking`
Lederstrumpf Jan 16, 2024
d4902be
Check equivocations on all votes & proofs for non-active rounds
Lederstrumpf Jan 16, 2024
3e9a4a7
Check equivocations on all votes & proofs
Lederstrumpf Jan 18, 2024
6be328f
add CanonicalHashHeaderPayload struct
Lederstrumpf Jan 25, 2024
e401534
update TODO
Lederstrumpf Jan 25, 2024
4dbfcf3
filter signatories without key ownership proofs
Lederstrumpf Jan 25, 2024
e7718fc
debug->warn
Lederstrumpf Jan 25, 2024
fb183c9
check session index first as cheap failfast
Lederstrumpf Feb 12, 2024
20b828b
deduplicate ancestry proof generation
Lederstrumpf Feb 13, 2024
09f9556
{canonical->finalized} hash for anc. proof gen
Lederstrumpf Feb 13, 2024
7c529a6
fixup! filter invalidly signed commitments at call site
Lederstrumpf Feb 22, 2024
c64286c
Merge remote-tracking branch 'origin/master' into rhmb/beefy-slashing…
Lederstrumpf Feb 27, 2024
b21c6e1
merge fixes
Lederstrumpf Feb 27, 2024
1848306
Merge remote-tracking branch 'origin/master' into rhmb/beefy-slashing…
Lederstrumpf Feb 27, 2024
be3cbd8
merge fixes
Lederstrumpf Feb 27, 2024
11095c7
clippy
Lederstrumpf Feb 27, 2024
e208014
align set_id in beefy key ownership tests
Lederstrumpf Feb 27, 2024
ab3f417
sp beefy: feature gate Block trait requirement
Lederstrumpf Mar 1, 2024
914caf9
constrain NodeHash as HashOutput
Lederstrumpf Mar 3, 2024
730df52
straight plumbing impl using wrapper for mmr_root
Lederstrumpf Mar 3, 2024
42b6e4f
use Hashing trait generic
Lederstrumpf Mar 3, 2024
6199919
remove canonical root from outer wrapper
Lederstrumpf Mar 3, 2024
4a6633f
remove generic from beefy pallet CheckFEP type
Lederstrumpf Mar 4, 2024
b0c3ce3
add CheckForkEquivocationProof type to runtimes
Lederstrumpf Mar 4, 2024
b4aa158
remove Hasher generic from outer call
Lederstrumpf Mar 4, 2024
e4caca4
replace trait generic & pallet_mmr dependency
Lederstrumpf Mar 4, 2024
c42d22a
remove all pallet_mmr::Config deps of pallet_beefy
Lederstrumpf Mar 4, 2024
95ab3fe
move all fork equiv. checking to assoc fn of trait
Lederstrumpf Mar 4, 2024
a543c28
remove contrived degree of freedom: BlockNumber
Lederstrumpf Mar 4, 2024
e17b7ca
remove contrived degree of freedom: Signature
Lederstrumpf Mar 4, 2024
6081f25
cleanup return type
Lederstrumpf Mar 4, 2024
a814740
remove contrived degree of freedom: Hasher
Lederstrumpf Mar 4, 2024
ee4c6c5
consistent Hash/HashT usage
Lederstrumpf Mar 4, 2024
5502a8e
remove redundant mmr_size alias
Lederstrumpf Mar 4, 2024
3913df6
Merge remote-tracking branch 'origin/master' into rhmb/beefy-slashing…
Lederstrumpf Mar 4, 2024
d27fc06
reuse verify_with_validator_set
Lederstrumpf Mar 12, 2024
7dd7c3d
deduplicate OpaqueKeyOwnershipProof decoding
Lederstrumpf Mar 14, 2024
bb6bd8d
specific mock impl for CheckForkEquivocationProof
Lederstrumpf Mar 14, 2024
e291372
add missing versioning on westend's BeefyApi
Lederstrumpf Mar 14, 2024
d8625d8
{canonical→best}_root
Lederstrumpf Mar 17, 2024
c0ccc9c
Merge remote-tracking branch 'origin/master' into rhmb/beefy-slashing…
Lederstrumpf Mar 26, 2024
f8928dd
Merge remote-tracking branch 'upstream/master' into beefy-slashing-fi…
serban300 Apr 16, 2024
8d7e6df
Fix correct_beefy_payload() test
serban300 Apr 16, 2024
c23f4d2
Address review comments
serban300 Apr 17, 2024
dd6ff56
fix CI
serban300 Apr 17, 2024
cf51037
taplo
serban300 Apr 17, 2024
114a894
Fix tests
serban300 Apr 18, 2024
c8e6802
fix rustdoc
serban300 Apr 18, 2024
6aacc7d
Use master branch of https://github.com/paritytech/merkle-mountain-ra…
serban300 Apr 18, 2024
04b7412
Merge remote-tracking branch 'upstream/master' into beefy-slashing-fi…
serban300 Apr 19, 2024
1f75173
Cosmetics
serban300 Apr 20, 2024
a84681f
Merge remote-tracking branch 'origin/master' into rhmb/beefy-slashing…
Lederstrumpf Apr 25, 2024
938a211
destructure `KnownSignature` for incumbent tuple interface
Lederstrumpf Apr 25, 2024
d4b479d
Use KnownSignature instead of tuple
serban300 Apr 26, 2024
06492da
enforce unique equivocator identities in evidence
Lederstrumpf Apr 25, 2024
c34617a
bump key ownership proof gen. failures to warnings
Lederstrumpf Apr 26, 2024
f603af5
Merge remote-tracking branch 'upstream/master' into beefy-slashing-fi…
serban300 May 1, 2024
b65b7a5
clarify `ForkEquivocationProof::check`'s params
Lederstrumpf May 16, 2024
9deeef3
Merge remote-tracking branch 'origin/master' into rhmb/beefy-slashing…
Lederstrumpf May 20, 2024
3913018
account for #4430
Lederstrumpf May 20, 2024
ada8bdb
add fisherman to `OnDemandJustificationsEngine`
Lederstrumpf May 30, 2024
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
10 changes: 7 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 25 additions & 6 deletions polkadot/node/service/src/fake_runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ sp_api::impl_runtime_apis! {
}
}

impl beefy_primitives::BeefyApi<Block, BeefyId> for Runtime {
impl beefy_primitives::BeefyApi<Block, BeefyId, Hash> for Runtime {
fn beefy_genesis() -> Option<BlockNumber> {
unimplemented!()
}
Expand All @@ -240,8 +240,8 @@ sp_api::impl_runtime_apis! {
unimplemented!()
}

fn submit_report_equivocation_unsigned_extrinsic(
_: beefy_primitives::EquivocationProof<
fn submit_report_vote_equivocation_unsigned_extrinsic(
_: beefy_primitives::VoteEquivocationProof<
BlockNumber,
BeefyId,
BeefySignature,
Expand All @@ -251,6 +251,13 @@ sp_api::impl_runtime_apis! {
unimplemented!()
}

fn submit_report_fork_equivocation_unsigned_extrinsic(
_: beefy_primitives::ForkEquivocationProof<BeefyId, <Block as BlockT>::Header, Hash>,
_: Vec<beefy_primitives::OpaqueKeyOwnershipProof>,
) -> Option<()> {
unimplemented!()
}

fn generate_key_ownership_proof(
_: beefy_primitives::ValidatorSetId,
_: BeefyId,
Expand All @@ -271,11 +278,11 @@ sp_api::impl_runtime_apis! {
fn generate_proof(
_: Vec<BlockNumber>,
_: Option<BlockNumber>,
) -> Result<(Vec<sp_mmr_primitives::EncodableOpaqueLeaf>, sp_mmr_primitives::Proof<Hash>), sp_mmr_primitives::Error> {
) -> Result<(Vec<sp_mmr_primitives::EncodableOpaqueLeaf>, sp_mmr_primitives::LeafProof<Hash>), sp_mmr_primitives::Error> {
unimplemented!()
}

fn verify_proof(_: Vec<sp_mmr_primitives::EncodableOpaqueLeaf>, _: sp_mmr_primitives::Proof<Hash>)
fn verify_proof(_: Vec<sp_mmr_primitives::EncodableOpaqueLeaf>, _: sp_mmr_primitives::LeafProof<Hash>)
-> Result<(), sp_mmr_primitives::Error>
{
unimplemented!()
Expand All @@ -284,7 +291,19 @@ sp_api::impl_runtime_apis! {
fn verify_proof_stateless(
_: Hash,
_: Vec<sp_mmr_primitives::EncodableOpaqueLeaf>,
_: sp_mmr_primitives::Proof<Hash>
_: sp_mmr_primitives::LeafProof<Hash>
) -> Result<(), sp_mmr_primitives::Error> {
unimplemented!()
}

fn generate_ancestry_proof(
_: u32,
_: Option<BlockNumber>,
) -> Result<sp_mmr_primitives::AncestryProof<Hash>, sp_mmr_primitives::Error> {
unimplemented!()
}
fn verify_ancestry_proof(
_: sp_mmr_primitives::AncestryProof<Hash>,
) -> Result<(), sp_mmr_primitives::Error> {
unimplemented!()
}
Expand Down
46 changes: 36 additions & 10 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,7 @@ impl pallet_beefy::Config for Runtime {
type MaxNominators = ConstU32<0>;
type MaxSetIdSessionEntries = BeefySetIdSessionEntries;
type OnNewValidatorSet = MmrLeaf;
type CheckForkEquivocationProof = MmrLeaf;
type WeightInfo = ();
type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, BeefyId)>>::Proof;
type EquivocationReportSystem =
Expand Down Expand Up @@ -1988,8 +1989,8 @@ sp_api::impl_runtime_apis! {
}
}

#[api_version(3)]
impl beefy_primitives::BeefyApi<Block, BeefyId> for Runtime {
#[api_version(4)]
impl beefy_primitives::BeefyApi<Block, BeefyId, Hash> for Runtime {
fn beefy_genesis() -> Option<BlockNumber> {
Beefy::genesis_block()
}
Expand All @@ -1998,8 +1999,8 @@ sp_api::impl_runtime_apis! {
Beefy::validator_set()
}

fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: beefy_primitives::EquivocationProof<
fn submit_report_vote_equivocation_unsigned_extrinsic(
vote_equivocation_proof: beefy_primitives::VoteEquivocationProof<
BlockNumber,
BeefyId,
BeefySignature,
Expand All @@ -2008,12 +2009,24 @@ sp_api::impl_runtime_apis! {
) -> Option<()> {
let key_owner_proof = key_owner_proof.decode()?;

Beefy::submit_unsigned_equivocation_report(
equivocation_proof,
Beefy::submit_unsigned_vote_equivocation_report(
vote_equivocation_proof,
key_owner_proof,
)
}

fn submit_report_fork_equivocation_unsigned_extrinsic(
fork_equivocation_proof: beefy_primitives::ForkEquivocationProof<BeefyId, Header, Hash>,
key_owner_proofs: Vec<beefy_primitives::OpaqueKeyOwnershipProof>,
) -> Option<()> {
let key_owner_proofs = key_owner_proofs.iter().cloned().map(|p| p.decode()).collect::<Option<Vec<_>>>()?;
serban300 marked this conversation as resolved.
Show resolved Hide resolved

Beefy::submit_unsigned_fork_equivocation_report(
fork_equivocation_proof,
key_owner_proofs,
)
}

fn generate_key_ownership_proof(
_set_id: beefy_primitives::ValidatorSetId,
authority_id: BeefyId,
Expand All @@ -2026,7 +2039,7 @@ sp_api::impl_runtime_apis! {
}
}

#[api_version(2)]
#[api_version(3)]
impl mmr::MmrApi<Block, mmr::Hash, BlockNumber> for Runtime {
fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
Ok(Mmr::mmr_root())
Expand All @@ -2039,7 +2052,7 @@ sp_api::impl_runtime_apis! {
fn generate_proof(
block_numbers: Vec<BlockNumber>,
best_known_block_number: Option<BlockNumber>,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::Proof<mmr::Hash>), mmr::Error> {
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::LeafProof<mmr::Hash>), mmr::Error> {
Mmr::generate_proof(block_numbers, best_known_block_number).map(
|(leaves, proof)| {
(
Expand All @@ -2053,7 +2066,7 @@ sp_api::impl_runtime_apis! {
)
}

fn verify_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::Proof<mmr::Hash>)
fn verify_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::LeafProof<mmr::Hash>)
-> Result<(), mmr::Error>
{
let leaves = leaves.into_iter().map(|leaf|
Expand All @@ -2066,11 +2079,24 @@ sp_api::impl_runtime_apis! {
fn verify_proof_stateless(
root: mmr::Hash,
leaves: Vec<mmr::EncodableOpaqueLeaf>,
proof: mmr::Proof<mmr::Hash>
proof: mmr::LeafProof<mmr::Hash>
) -> Result<(), mmr::Error> {
let nodes = leaves.into_iter().map(|leaf|mmr::DataOrHash::Data(leaf.into_opaque_leaf())).collect();
pallet_mmr::verify_leaves_proof::<mmr::Hashing, _>(root, nodes, proof)
}

fn generate_ancestry_proof(
prev_best_block: BlockNumber,
best_known_block_number: Option<BlockNumber>
) -> Result<mmr::AncestryProof<mmr::Hash>, mmr::Error> {
Mmr::generate_ancestry_proof(prev_best_block, best_known_block_number)
}

fn verify_ancestry_proof(
ancestry_proof: sp_mmr_primitives::AncestryProof<mmr::Hash>,
) -> Result<(), mmr::Error> {
Mmr::verify_ancestry_proof(ancestry_proof)
}
}

impl fg_primitives::GrandpaApi<Block> for Runtime {
Expand Down
32 changes: 26 additions & 6 deletions polkadot/runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ sp_api::impl_runtime_apis! {
}
}

impl beefy_primitives::BeefyApi<Block, BeefyId> for Runtime {
impl beefy_primitives::BeefyApi<Block, BeefyId, Hash> for Runtime {
fn beefy_genesis() -> Option<BlockNumber> {
// dummy implementation due to lack of BEEFY pallet.
None
Expand All @@ -969,8 +969,8 @@ sp_api::impl_runtime_apis! {
None
}

fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: beefy_primitives::EquivocationProof<
fn submit_report_vote_equivocation_unsigned_extrinsic(
_vote_equivocation_proof: beefy_primitives::VoteEquivocationProof<
BlockNumber,
BeefyId,
BeefySignature,
Expand All @@ -980,6 +980,13 @@ sp_api::impl_runtime_apis! {
None
}

fn submit_report_fork_equivocation_unsigned_extrinsic(
_fork_equivocation_proof: beefy_primitives::ForkEquivocationProof<BeefyId, Header, Hash>,
_key_owner_proofs: Vec<beefy_primitives::OpaqueKeyOwnershipProof>,
) -> Option<()> {
None
}

fn generate_key_ownership_proof(
_set_id: beefy_primitives::ValidatorSetId,
_authority_id: BeefyId,
Expand All @@ -1000,11 +1007,11 @@ sp_api::impl_runtime_apis! {
fn generate_proof(
_block_numbers: Vec<BlockNumber>,
_best_known_block_number: Option<BlockNumber>,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::Proof<Hash>), mmr::Error> {
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::LeafProof<Hash>), mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}

fn verify_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::Proof<Hash>)
fn verify_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::LeafProof<Hash>)
-> Result<(), mmr::Error>
{
Err(mmr::Error::PalletNotIncluded)
Expand All @@ -1013,7 +1020,20 @@ sp_api::impl_runtime_apis! {
fn verify_proof_stateless(
_root: Hash,
_leaves: Vec<mmr::EncodableOpaqueLeaf>,
_proof: mmr::Proof<Hash>
_proof: mmr::LeafProof<Hash>
) -> Result<(), mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}

fn generate_ancestry_proof(
_prev_best_block: BlockNumber,
_best_known_block_number: Option<BlockNumber>
) -> Result<mmr::AncestryProof<Hash>, mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}

fn verify_ancestry_proof(
_ancestry_proof: mmr::AncestryProof<Hash>,
) -> Result<(), mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}
Expand Down
42 changes: 34 additions & 8 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ impl pallet_beefy::Config for Runtime {
type MaxNominators = MaxNominators;
type MaxSetIdSessionEntries = BeefySetIdSessionEntries;
type OnNewValidatorSet = BeefyMmrLeaf;
type CheckForkEquivocationProof = BeefyMmrLeaf;
type WeightInfo = ();
type KeyOwnerProof = sp_session::MembershipProof;
type EquivocationReportSystem =
Expand Down Expand Up @@ -2013,7 +2014,7 @@ sp_api::impl_runtime_apis! {
}
}

impl beefy_primitives::BeefyApi<Block, BeefyId> for Runtime {
impl beefy_primitives::BeefyApi<Block, BeefyId, Hash> for Runtime {
serban300 marked this conversation as resolved.
Show resolved Hide resolved
fn beefy_genesis() -> Option<BlockNumber> {
Beefy::genesis_block()
}
Expand All @@ -2022,8 +2023,8 @@ sp_api::impl_runtime_apis! {
Beefy::validator_set()
}

fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: beefy_primitives::EquivocationProof<
fn submit_report_vote_equivocation_unsigned_extrinsic(
vote_equivocation_proof: beefy_primitives::VoteEquivocationProof<
BlockNumber,
BeefyId,
BeefySignature,
Expand All @@ -2032,12 +2033,24 @@ sp_api::impl_runtime_apis! {
) -> Option<()> {
let key_owner_proof = key_owner_proof.decode()?;

Beefy::submit_unsigned_equivocation_report(
equivocation_proof,
Beefy::submit_unsigned_vote_equivocation_report(
vote_equivocation_proof,
key_owner_proof,
)
}

fn submit_report_fork_equivocation_unsigned_extrinsic(
fork_equivocation_proof: beefy_primitives::ForkEquivocationProof<BeefyId, Header, Hash>,
key_owner_proofs: Vec<beefy_primitives::OpaqueKeyOwnershipProof>,
) -> Option<()> {
let key_owner_proofs = key_owner_proofs.iter().cloned().map(|p| p.decode()).collect::<Option<Vec<_>>>()?;

Beefy::submit_unsigned_fork_equivocation_report(
fork_equivocation_proof,
key_owner_proofs,
)
}

fn generate_key_ownership_proof(
_set_id: beefy_primitives::ValidatorSetId,
authority_id: BeefyId,
Expand All @@ -2062,7 +2075,7 @@ sp_api::impl_runtime_apis! {
fn generate_proof(
block_numbers: Vec<BlockNumber>,
best_known_block_number: Option<BlockNumber>,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::Proof<mmr::Hash>), mmr::Error> {
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::LeafProof<mmr::Hash>), mmr::Error> {
Mmr::generate_proof(block_numbers, best_known_block_number).map(
|(leaves, proof)| {
(
Expand All @@ -2076,7 +2089,7 @@ sp_api::impl_runtime_apis! {
)
}

fn verify_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::Proof<mmr::Hash>)
fn verify_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::LeafProof<mmr::Hash>)
-> Result<(), mmr::Error>
{
let leaves = leaves.into_iter().map(|leaf|
Expand All @@ -2089,11 +2102,24 @@ sp_api::impl_runtime_apis! {
fn verify_proof_stateless(
root: mmr::Hash,
leaves: Vec<mmr::EncodableOpaqueLeaf>,
proof: mmr::Proof<mmr::Hash>
proof: mmr::LeafProof<mmr::Hash>
) -> Result<(), mmr::Error> {
let nodes = leaves.into_iter().map(|leaf|mmr::DataOrHash::Data(leaf.into_opaque_leaf())).collect();
pallet_mmr::verify_leaves_proof::<mmr::Hashing, _>(root, nodes, proof)
}

fn generate_ancestry_proof(
prev_best_block: BlockNumber,
best_known_block_number: Option<BlockNumber>
) -> Result<mmr::AncestryProof<mmr::Hash>, mmr::Error> {
Mmr::generate_ancestry_proof(prev_best_block, best_known_block_number)
}

fn verify_ancestry_proof(
ancestry_proof: sp_mmr_primitives::AncestryProof<mmr::Hash>,
) -> Result<(), mmr::Error> {
Mmr::verify_ancestry_proof(ancestry_proof)
}
}

impl pallet_beefy_mmr::BeefyMmrApi<Block, Hash> for RuntimeApi {
Expand Down
Loading
Loading