mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 22:51:03 +00:00
Reduce consensus gossip spam (#1538)
* core: keep known gossip messages for twice their expiration * core: test expiration of known gossip messages * core: only broadcast grandpa votes if authority in current set * core: only broadcast grandpa commits if authority in current set
This commit is contained in:
@@ -395,14 +395,16 @@ pub(crate) struct CommitsOut<Block, N> {
|
||||
network: N,
|
||||
set_id: u64,
|
||||
_marker: ::std::marker::PhantomData<Block>,
|
||||
is_voter: bool,
|
||||
}
|
||||
|
||||
impl<Block, N> CommitsOut<Block, N> {
|
||||
/// Create a new commit output stream.
|
||||
pub(crate) fn new(network: N, set_id: u64) -> Self {
|
||||
pub(crate) fn new(network: N, set_id: u64, is_voter: bool) -> Self {
|
||||
CommitsOut {
|
||||
network,
|
||||
set_id,
|
||||
is_voter,
|
||||
_marker: Default::default(),
|
||||
}
|
||||
}
|
||||
@@ -413,6 +415,10 @@ impl<Block: BlockT, N: Network> Sink for CommitsOut<Block, N> {
|
||||
type SinkError = Error;
|
||||
|
||||
fn start_send(&mut self, input: (u64, Commit<Block>)) -> StartSend<Self::SinkItem, Error> {
|
||||
if !self.is_voter {
|
||||
return Ok(AsyncSink::Ready);
|
||||
}
|
||||
|
||||
let (round, commit) = input;
|
||||
let (precommits, auth_data) = commit.precommits.into_iter()
|
||||
.map(|signed| (signed.precommit, (signed.signature, signed.id)))
|
||||
|
||||
@@ -528,10 +528,13 @@ impl<B, E, Block: BlockT<Hash=H256>, N, RA> voter::Environment<Block::Hash, Numb
|
||||
self.voters.clone(),
|
||||
);
|
||||
|
||||
let local_key = self.config.local_key.as_ref()
|
||||
.filter(|pair| self.voters.contains_key(&pair.public().into()));
|
||||
|
||||
let (out_rx, outgoing) = ::communication::outgoing_messages::<Block, _>(
|
||||
round,
|
||||
self.set_id,
|
||||
self.config.local_key.clone(),
|
||||
local_key.cloned(),
|
||||
self.voters.clone(),
|
||||
self.network.clone(),
|
||||
);
|
||||
@@ -1407,6 +1410,7 @@ pub fn block_import<B, E, Block: BlockT<Hash=H256>, RA, PRA>(
|
||||
}
|
||||
|
||||
fn committer_communication<Block: BlockT<Hash=H256>, B, E, N, RA>(
|
||||
local_key: Option<Arc<ed25519::Pair>>,
|
||||
set_id: u64,
|
||||
voters: &Arc<HashMap<Ed25519AuthorityId, u64>>,
|
||||
client: &Arc<Client<B, E, Block, RA>>,
|
||||
@@ -1442,9 +1446,14 @@ fn committer_communication<Block: BlockT<Hash=H256>, B, E, N, RA>(
|
||||
commit_in,
|
||||
);
|
||||
|
||||
let is_voter = local_key
|
||||
.map(|pair| voters.contains_key(&pair.public().into()))
|
||||
.unwrap_or(false);
|
||||
|
||||
let commit_out = ::communication::CommitsOut::<Block, _>::new(
|
||||
network.clone(),
|
||||
set_id,
|
||||
is_voter,
|
||||
);
|
||||
|
||||
let commit_in = commit_in.map_err(Into::into);
|
||||
@@ -1524,6 +1533,7 @@ pub fn run_grandpa<B, E, Block: BlockT<Hash=H256>, N, RA>(
|
||||
);
|
||||
|
||||
let committer_data = committer_communication(
|
||||
config.local_key.clone(),
|
||||
env.set_id,
|
||||
&env.voters,
|
||||
&client,
|
||||
|
||||
Reference in New Issue
Block a user