mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-01 01:01:01 +00:00
Cleaner GRANDPA RPC API for proving finality (#7339)
* grandpa: persist block number for last block of authority set * grandpa: fix authority_set_changes field in tests * grandpa: fix date on copyright notice * grandpa-rpc: implement cleaner api for prove finality rpc * grandpa-rpc: replace the old prove_finality with the new one * grandpa: undo accidental whitespace change * grandpa-rpc: start work on redo of the finality_proof RPC API * grandpa: manual impl of Decode for AuthoritySet * grandpa: add comment about appending changes for forced changes * grandpa: flip order in set changes, tidy up some comments * grandpa: update some of the doc comments * grandpa: store authority set changes when applying forced changes * grandpa: simplify finality_proof.rs * grandpa: move checks and extend tests in finality_proof * grandpa: address first set of review comments * grandpa: check that set changes have well-defined start * grandpa: rework prove_finality and assocated tests * grandpa: make AuthoritySetChanges tuple struct * grandpa: add assertions for tracking auth set changes * grandpa: remove StorageAndProofProvider trait * grandpa: return more informative results for unexpected input to RPC * grandpa: tiny tweak to error msg * grandpa: fix tests * grandpa: add error specific to finality_proof * grandpa: fix review comments * grandpa: proper migration to new AuthoritySet * grandpa: fix long lines * grandpa: fix unused warning after merge Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -22,18 +22,16 @@ use sc_finality_grandpa::FinalityProofProvider;
|
||||
use sp_runtime::traits::{Block as BlockT, NumberFor};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct EncodedFinalityProofs(pub sp_core::Bytes);
|
||||
pub struct EncodedFinalityProof(pub sp_core::Bytes);
|
||||
|
||||
/// Local trait mainly to allow mocking in tests.
|
||||
pub trait RpcFinalityProofProvider<Block: BlockT> {
|
||||
/// Return finality proofs for the given authorities set id, if it is provided, otherwise the
|
||||
/// current one will be used.
|
||||
/// Prove finality for the given block number by returning a Justification for the last block of
|
||||
/// the authority set.
|
||||
fn rpc_prove_finality(
|
||||
&self,
|
||||
begin: Block::Hash,
|
||||
end: Block::Hash,
|
||||
authorities_set_id: u64,
|
||||
) -> Result<Option<EncodedFinalityProofs>, sp_blockchain::Error>;
|
||||
block: NumberFor<Block>,
|
||||
) -> Result<Option<EncodedFinalityProof>, sc_finality_grandpa::FinalityProofError>;
|
||||
}
|
||||
|
||||
impl<B, Block> RpcFinalityProofProvider<Block> for FinalityProofProvider<B, Block>
|
||||
@@ -44,11 +42,9 @@ where
|
||||
{
|
||||
fn rpc_prove_finality(
|
||||
&self,
|
||||
begin: Block::Hash,
|
||||
end: Block::Hash,
|
||||
authorities_set_id: u64,
|
||||
) -> Result<Option<EncodedFinalityProofs>, sp_blockchain::Error> {
|
||||
self.prove_finality(begin, end, authorities_set_id)
|
||||
.map(|x| x.map(|y| EncodedFinalityProofs(y.into())))
|
||||
block: NumberFor<Block>,
|
||||
) -> Result<Option<EncodedFinalityProof>, sc_finality_grandpa::FinalityProofError> {
|
||||
self.prove_finality(block)
|
||||
.map(|x| x.map(|y| EncodedFinalityProof(y.into())))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user