Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit c3d51b8

Browse files
committed
remove ApprovalCheckingVotingRule
1 parent b7bc78d commit c3d51b8

File tree

2 files changed

+1
-191
lines changed

2 files changed

+1
-191
lines changed

node/service/src/grandpa_support.rs

+1-174
Original file line numberDiff line numberDiff line change
@@ -23,156 +23,7 @@ use sp_runtime::generic::BlockId;
2323
use sp_runtime::traits::Header as _;
2424

2525
#[cfg(feature = "full-node")]
26-
use {
27-
polkadot_primitives::v1::{Hash, Block as PolkadotBlock, Header as PolkadotHeader},
28-
polkadot_subsystem::messages::ApprovalVotingMessage,
29-
polkadot_overseer::Handle,
30-
futures::channel::oneshot,
31-
};
32-
33-
/// A custom GRANDPA voting rule that acts as a diagnostic for the approval
34-
/// voting subsystem's desired votes.
35-
///
36-
/// The practical effect of this voting rule is to implement a fixed delay of
37-
/// blocks.
38-
#[cfg(feature = "full-node")]
39-
#[derive(Clone)]
40-
pub(crate) struct ApprovalCheckingVotingRule {
41-
overseer: Handle,
42-
}
43-
44-
#[cfg(feature = "full-node")]
45-
impl ApprovalCheckingVotingRule {
46-
/// Create a new approval checking diagnostic voting rule.
47-
pub fn new(overseer: Handle) -> Self {
48-
Self {
49-
overseer,
50-
}
51-
}
52-
}
53-
54-
#[cfg(feature = "full-node")]
55-
#[derive(Debug, PartialEq)]
56-
/// Vote explicitly on the given hash.
57-
enum ParachainVotingRuleTarget<H, N> {
58-
Explicit((H, N)),
59-
/// Vote on the current target.
60-
Current,
61-
/// Vote on the base target - the minimal possible vote.
62-
Base,
63-
}
64-
65-
#[cfg(feature = "full-node")]
66-
fn approval_checking_vote_to_grandpa_vote<H, N: PartialOrd>(
67-
approval_checking_vote: Option<(H, N)>,
68-
current_number: N,
69-
) -> ParachainVotingRuleTarget<H, N> {
70-
match approval_checking_vote {
71-
Some((hash, number)) => if number > current_number {
72-
// respect other voting rule.
73-
ParachainVotingRuleTarget::Current
74-
} else {
75-
ParachainVotingRuleTarget::Explicit((hash, number))
76-
},
77-
// If approval-voting chooses 'None', that means we should vote on the base (last round estimate).
78-
None => ParachainVotingRuleTarget::Base,
79-
}
80-
}
81-
82-
/// The maximum amount of unfinalized blocks we are willing to allow due to approval checking lag.
83-
/// This is a safety net that should be removed at some point in the future.
84-
#[cfg(feature = "full-node")]
85-
const MAX_APPROVAL_CHECKING_FINALITY_LAG: polkadot_primitives::v1::BlockNumber = 50;
86-
87-
#[cfg(feature = "full-node")]
88-
impl<B> grandpa::VotingRule<PolkadotBlock, B> for ApprovalCheckingVotingRule
89-
where B: sp_blockchain::HeaderBackend<PolkadotBlock> + 'static
90-
{
91-
fn restrict_vote(
92-
&self,
93-
backend: Arc<B>,
94-
base: &PolkadotHeader,
95-
best_target: &PolkadotHeader,
96-
current_target: &PolkadotHeader,
97-
) -> grandpa::VotingRuleResult<PolkadotBlock> {
98-
// Query approval checking and issue metrics.
99-
let mut overseer = self.overseer.clone();
100-
101-
let best_hash = best_target.hash();
102-
let best_number = best_target.number.clone();
103-
let best_header = best_target.clone();
104-
105-
let current_hash = current_target.hash();
106-
let current_number = current_target.number.clone();
107-
108-
let base_hash = base.hash();
109-
let base_number = base.number;
110-
111-
Box::pin(async move {
112-
let (tx, rx) = oneshot::channel();
113-
let approval_checking_subsystem_vote = {
114-
overseer.send_msg(
115-
ApprovalVotingMessage::ApprovedAncestor(
116-
best_hash,
117-
base_number,
118-
tx,
119-
),
120-
std::any::type_name::<Self>(),
121-
).await;
122-
123-
rx.await.ok().and_then(|v| v)
124-
};
125-
126-
let approval_checking_subsystem_lag = approval_checking_subsystem_vote.map_or(
127-
best_number - base_number,
128-
|(_h, n)| best_number - n,
129-
);
130-
131-
let min_vote = {
132-
let diff = best_number.saturating_sub(base_number);
133-
if diff >= MAX_APPROVAL_CHECKING_FINALITY_LAG {
134-
// Catch up to the best, with some extra lag.
135-
let target_number = best_number - MAX_APPROVAL_CHECKING_FINALITY_LAG;
136-
if target_number >= current_number {
137-
Some((current_hash, current_number))
138-
} else {
139-
walk_backwards_to_target_block(&*backend, target_number, &best_header).ok()
140-
}
141-
} else {
142-
Some((base_hash, base_number))
143-
}
144-
};
145-
146-
let vote = match approval_checking_vote_to_grandpa_vote(
147-
approval_checking_subsystem_vote,
148-
current_number,
149-
) {
150-
ParachainVotingRuleTarget::Explicit(vote) => {
151-
if min_vote.as_ref().map_or(false, |min| min.1 > vote.1) {
152-
min_vote
153-
} else {
154-
Some(vote)
155-
}
156-
}
157-
ParachainVotingRuleTarget::Current => Some((current_hash, current_number)),
158-
ParachainVotingRuleTarget::Base => min_vote.or(Some((base_hash, base_number))),
159-
};
160-
161-
tracing::trace!(
162-
target: "parachain::approval-voting",
163-
?vote,
164-
?approval_checking_subsystem_vote,
165-
approval_checking_subsystem_lag,
166-
current_number,
167-
best_number,
168-
base_number,
169-
"GRANDPA: voting based on approved ancestor.",
170-
);
171-
172-
vote
173-
})
174-
}
175-
}
26+
use polkadot_primitives::v1::Hash;
17627

17728
/// Returns the block hash of the block at the given `target_number` by walking
17829
/// backwards from the given `current_header`.
@@ -410,7 +261,6 @@ mod tests {
410261
use sp_runtime::{generic::BlockId, traits::Header};
411262
use consensus_common::BlockOrigin;
412263
use std::sync::Arc;
413-
use super::{approval_checking_vote_to_grandpa_vote, ParachainVotingRuleTarget};
414264

415265
#[test]
416266
fn grandpa_pause_voting_rule_works() {
@@ -522,27 +372,4 @@ mod tests {
522372
None,
523373
);
524374
}
525-
526-
#[test]
527-
fn approval_checking_to_grandpa_rules() {
528-
assert_eq!(
529-
approval_checking_vote_to_grandpa_vote::<(), _>(None, 5),
530-
ParachainVotingRuleTarget::Base,
531-
);
532-
533-
assert_eq!(
534-
approval_checking_vote_to_grandpa_vote(Some(("2", 2)), 3),
535-
ParachainVotingRuleTarget::Explicit(("2", 2)),
536-
);
537-
538-
assert_eq!(
539-
approval_checking_vote_to_grandpa_vote(Some(("2", 2)), 2),
540-
ParachainVotingRuleTarget::Explicit(("2", 2)),
541-
);
542-
543-
assert_eq!(
544-
approval_checking_vote_to_grandpa_vote(Some(("2", 2)), 1),
545-
ParachainVotingRuleTarget::Current,
546-
);
547-
}
548375
}

node/service/src/lib.rs

-17
Original file line numberDiff line numberDiff line change
@@ -907,23 +907,6 @@ pub fn new_full<RuntimeApi, Executor, OverseerGenerator>(
907907
// after the given pause block is finalized and restarting after the
908908
// given delay.
909909
let builder = grandpa::VotingRulesBuilder::default();
910-
// we should enable approval checking voting rule before we deploy parachains on polkadot
911-
let enable_approval_checking_voting_rule = chain_spec.is_kusama()
912-
|| chain_spec.is_westend()
913-
|| chain_spec.is_rococo()
914-
|| chain_spec.is_wococo();
915-
916-
let builder = if let Some(ref overseer) = overseer_handler {
917-
if enable_approval_checking_voting_rule {
918-
builder.add(grandpa_support::ApprovalCheckingVotingRule::new(
919-
overseer.clone(),
920-
))
921-
} else {
922-
builder
923-
}
924-
} else {
925-
builder
926-
};
927910

928911
let voting_rule = match grandpa_pause {
929912
Some((block, delay)) => {

0 commit comments

Comments
 (0)