mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 18:41:05 +00:00
grandpa: fix race condition (#3542)
* grandpa: ignore result of voter command send * grandpa: avoid race condition on environment::finalize_block
This commit is contained in:
@@ -871,6 +871,11 @@ pub(crate) fn finalize_block<B, Block: BlockT<Hash=H256>, E, RA>(
|
|||||||
E: CallExecutor<Block, Blake2Hasher> + Send + Sync,
|
E: CallExecutor<Block, Blake2Hasher> + Send + Sync,
|
||||||
RA: Send + Sync,
|
RA: Send + Sync,
|
||||||
{
|
{
|
||||||
|
// NOTE: lock must be held through writing to DB to avoid race. this lock
|
||||||
|
// also implicitly synchronizes the check for last finalized number
|
||||||
|
// below.
|
||||||
|
let mut authority_set = authority_set.inner().write();
|
||||||
|
|
||||||
let status = client.info().chain;
|
let status = client.info().chain;
|
||||||
if number <= status.finalized_number && client.hash(number)? == Some(hash) {
|
if number <= status.finalized_number && client.hash(number)? == Some(hash) {
|
||||||
// This can happen after a forced change (triggered by the finality tracker when finality is stalled), since
|
// This can happen after a forced change (triggered by the finality tracker when finality is stalled), since
|
||||||
@@ -885,9 +890,6 @@ pub(crate) fn finalize_block<B, Block: BlockT<Hash=H256>, E, RA>(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
// lock must be held through writing to DB to avoid race
|
|
||||||
let mut authority_set = authority_set.inner().write();
|
|
||||||
|
|
||||||
// FIXME #1483: clone only when changed
|
// FIXME #1483: clone only when changed
|
||||||
let old_authority_set = authority_set.clone();
|
let old_authority_set = authority_set.clone();
|
||||||
// holds the old consensus changes in case it is changed below, needed for
|
// holds the old consensus changes in case it is changed below, needed for
|
||||||
|
|||||||
@@ -590,9 +590,8 @@ where
|
|||||||
info!(target: "finality", "Imported justification for block #{} that triggers \
|
info!(target: "finality", "Imported justification for block #{} that triggers \
|
||||||
command {}, signaling voter.", number, command);
|
command {}, signaling voter.", number, command);
|
||||||
|
|
||||||
if let Err(e) = self.send_voter_commands.unbounded_send(command) {
|
// send the command to the voter
|
||||||
return Err(ConsensusError::ClientImport(e.to_string()).into());
|
let _ = self.send_voter_commands.unbounded_send(command);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Err(CommandOrError::Error(e)) => {
|
Err(CommandOrError::Error(e)) => {
|
||||||
return Err(match e {
|
return Err(match e {
|
||||||
|
|||||||
Reference in New Issue
Block a user