Finality loop: get block justification and authorities change by consensus engine ID (#1619)

* SignedBlock: get justification by consensus engine id

* Define ConsensusLogReader

Making the check for authority changes more generic

* cod review changes
This commit is contained in:
Serban Iorga
2022-10-28 13:12:37 +03:00
committed by Bastian Köcher
parent f58e076ca2
commit 01538bc5fa
9 changed files with 90 additions and 66 deletions
+4 -6
View File
@@ -27,7 +27,7 @@ use sp_core::{storage::StorageKey, Pair};
use sp_runtime::{
generic::SignedBlock,
traits::{Block as BlockT, Dispatchable, Member},
EncodedJustification,
ConsensusEngineId, EncodedJustification,
};
use std::{fmt::Debug, time::Duration};
@@ -147,7 +147,7 @@ pub trait BlockWithJustification<Header> {
/// Return encoded block extrinsics.
fn extrinsics(&self) -> Vec<EncodedExtrinsic>;
/// Return block justification, if known.
fn justification(&self) -> Option<&EncodedJustification>;
fn justification(&self, engine_id: ConsensusEngineId) -> Option<&EncodedJustification>;
}
/// Transaction before it is signed.
@@ -237,9 +237,7 @@ impl<Block: BlockT> BlockWithJustification<Block::Header> for SignedBlock<Block>
self.block.extrinsics().iter().map(Encode::encode).collect()
}
fn justification(&self) -> Option<&EncodedJustification> {
self.justifications
.as_ref()
.and_then(|j| j.get(sp_finality_grandpa::GRANDPA_ENGINE_ID))
fn justification(&self, engine_id: ConsensusEngineId) -> Option<&EncodedJustification> {
self.justifications.as_ref().and_then(|j| j.get(engine_id))
}
}
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
use bp_header_chain::find_grandpa_authorities_scheduled_change;
use bp_header_chain::ConsensusLogReader;
use finality_relay::SourceHeader as FinalitySourceHeader;
use sp_runtime::traits::Header as HeaderT;
@@ -44,7 +44,9 @@ impl<Header> From<Header> for SyncHeader<Header> {
}
}
impl<Header: HeaderT> FinalitySourceHeader<Header::Hash, Header::Number> for SyncHeader<Header> {
impl<Header: HeaderT, R: ConsensusLogReader> FinalitySourceHeader<Header::Hash, Header::Number, R>
for SyncHeader<Header>
{
fn hash(&self) -> Header::Hash {
self.0.hash()
}
@@ -54,6 +56,6 @@ impl<Header: HeaderT> FinalitySourceHeader<Header::Hash, Header::Number> for Syn
}
fn is_mandatory(&self) -> bool {
find_grandpa_authorities_scheduled_change(&self.0).is_some()
R::schedules_authorities_change(self.digest())
}
}