grandpa: don't send equivocation reports for local identities (#7372)

* grandpa: don't send equivocation reports for local identities

* grandpa: add test for self-report

* grandpa: fix test compilation

this works on rust nightly but breaks on ci which is using rust stable
This commit is contained in:
André Silva
2020-10-26 12:47:39 +00:00
committed by GitHub
parent 568dd6fd42
commit f2925f96a2
2 changed files with 61 additions and 7 deletions
@@ -1813,3 +1813,49 @@ fn imports_justification_for_regular_blocks_on_import() {
client.justification(&BlockId::Hash(block_hash)).unwrap().is_some(),
);
}
#[test]
fn grandpa_environment_doesnt_send_equivocation_reports_for_itself() {
let alice = Ed25519Keyring::Alice;
let voters = make_ids(&[alice]);
let environment = {
let mut net = GrandpaTestNet::new(TestApi::new(voters), 1);
let peer = net.peer(0);
let network_service = peer.network_service().clone();
let link = peer.data.lock().take().unwrap();
let (keystore, _keystore_path) = create_keystore(alice);
test_environment(&link, Some(keystore), network_service.clone(), ())
};
let signed_prevote = {
let prevote = finality_grandpa::Prevote {
target_hash: H256::random(),
target_number: 1,
};
let signed = alice.sign(&[]).into();
(prevote, signed)
};
let mut equivocation = finality_grandpa::Equivocation {
round_number: 1,
identity: alice.public().into(),
first: signed_prevote.clone(),
second: signed_prevote.clone(),
};
// reporting the equivocation should fail since the offender is a local
// authority (i.e. we have keys in our keystore for the given id)
let equivocation_proof = sp_finality_grandpa::Equivocation::Prevote(equivocation.clone());
assert!(matches!(
environment.report_equivocation(equivocation_proof),
Err(Error::Safety(_))
));
// if we set the equivocation offender to another id for which we don't have
// keys it should work
equivocation.identity = Default::default();
let equivocation_proof = sp_finality_grandpa::Equivocation::Prevote(equivocation);
assert!(environment.report_equivocation(equivocation_proof).is_ok());
}