Skip to content

Commit 8c845c5

Browse files
andresilvaark0f
authored andcommitted
grandpa: allow authority set hard forks to be forced (paritytech#10444)
* grandpa: allow authority set hard forks to be forced * grandpa: fix authority set hard forks in warp proof provider * grandpa: make AuthoritySetHardFork public * grandpa: extend comment
1 parent 7e0f23f commit 8c845c5

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

client/finality-grandpa/src/lib.rs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,24 @@ where
541541
)
542542
}
543543

544+
/// A descriptor for an authority set hard fork. These are authority set changes
545+
/// that are not signalled by the runtime and instead are defined off-chain
546+
/// (hence the hard fork).
547+
pub struct AuthoritySetHardFork<Block: BlockT> {
548+
/// The new authority set id.
549+
pub set_id: SetId,
550+
/// The block hash and number at which the hard fork should be applied.
551+
pub block: (Block::Hash, NumberFor<Block>),
552+
/// The authorities in the new set.
553+
pub authorities: AuthorityList,
554+
/// The latest block number that was finalized before this authority set
555+
/// hard fork. When defined, the authority set change will be forced, i.e.
556+
/// the node won't wait for the block above to be finalized before enacting
557+
/// the change, and the given finalized number will be used as a base for
558+
/// voting.
559+
pub last_finalized: Option<NumberFor<Block>>,
560+
}
561+
544562
/// Make block importer and link half necessary to tie the background voter to
545563
/// it. A vector of authority set hard forks can be passed, any authority set
546564
/// change signaled at the given block (either already signalled or in a further
@@ -550,7 +568,7 @@ pub fn block_import_with_authority_set_hard_forks<BE, Block: BlockT, Client, SC>
550568
client: Arc<Client>,
551569
genesis_authorities_provider: &dyn GenesisAuthoritySetProvider<Block>,
552570
select_chain: SC,
553-
authority_set_hard_forks: Vec<(SetId, (Block::Hash, NumberFor<Block>), AuthorityList)>,
571+
authority_set_hard_forks: Vec<AuthoritySetHardFork<Block>>,
554572
telemetry: Option<TelemetryHandle>,
555573
) -> Result<(GrandpaBlockImport<BE, Block, Client, SC>, LinkHalf<Block, Client, SC>), ClientError>
556574
where
@@ -580,19 +598,24 @@ where
580598

581599
let (justification_sender, justification_stream) = GrandpaJustificationStream::channel();
582600

583-
// create pending change objects with 0 delay and enacted on finality
584-
// (i.e. standard changes) for each authority set hard fork.
601+
// create pending change objects with 0 delay for each authority set hard fork.
585602
let authority_set_hard_forks = authority_set_hard_forks
586603
.into_iter()
587-
.map(|(set_id, (hash, number), authorities)| {
604+
.map(|fork| {
605+
let delay_kind = if let Some(last_finalized) = fork.last_finalized {
606+
authorities::DelayKind::Best { median_last_finalized: last_finalized }
607+
} else {
608+
authorities::DelayKind::Finalized
609+
};
610+
588611
(
589-
set_id,
612+
fork.set_id,
590613
authorities::PendingChange {
591-
next_authorities: authorities,
614+
next_authorities: fork.authorities,
592615
delay: Zero::zero(),
593-
canon_hash: hash,
594-
canon_height: number,
595-
delay_kind: authorities::DelayKind::Finalized,
616+
canon_hash: fork.block.0,
617+
canon_height: fork.block.1,
618+
delay_kind,
596619
},
597620
)
598621
})

client/finality-grandpa/src/warp_proof.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use sp_runtime::codec::{self, Decode, Encode};
2020

2121
use crate::{
22-
best_justification, find_scheduled_change, AuthoritySetChanges, BlockNumberOps,
23-
GrandpaJustification, SharedAuthoritySet,
22+
best_justification, find_scheduled_change, AuthoritySetChanges, AuthoritySetHardFork,
23+
BlockNumberOps, GrandpaJustification, SharedAuthoritySet,
2424
};
2525
use sc_client_api::Backend as ClientBackend;
2626
use sc_network::warp_request_handler::{EncodedProof, VerificationResult, WarpSyncProvider};
@@ -255,12 +255,15 @@ where
255255
pub fn new(
256256
backend: Arc<Backend>,
257257
authority_set: SharedAuthoritySet<Block::Hash, NumberFor<Block>>,
258-
hard_forks: Vec<(SetId, (Block::Hash, NumberFor<Block>), AuthorityList)>,
258+
hard_forks: Vec<AuthoritySetHardFork<Block>>,
259259
) -> Self {
260260
NetworkProvider {
261261
backend,
262262
authority_set,
263-
hard_forks: hard_forks.into_iter().map(|(s, hn, list)| (hn, (s, list))).collect(),
263+
hard_forks: hard_forks
264+
.into_iter()
265+
.map(|fork| (fork.block, (fork.set_id, fork.authorities)))
266+
.collect(),
264267
}
265268
}
266269
}

0 commit comments

Comments
 (0)