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

Commit 0eeebc9

Browse files
committed
Merge branch 'master' into avoid_stack_protected
2 parents 27cbd6a + d5d6304 commit 0eeebc9

File tree

21 files changed

+246
-101
lines changed

21 files changed

+246
-101
lines changed

.gitlab-ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ cargo-audit:
158158
cargo-deny:
159159
stage: test
160160
<<: *docker-env
161+
only:
162+
- schedules
163+
- tags
164+
- web
161165
script:
162166
- cargo deny check --hide-inclusion-graph -c .maintain/deny.toml
163167
after_script:
@@ -259,7 +263,7 @@ test-wasmtime:
259263
variables:
260264
<<: *default-vars
261265
# Enable debug assertions since we are running optimized builds for testing
262-
# but still want to have debug assertions.
266+
# but still want to have debug assertions.
263267
RUSTFLAGS: -Cdebug-assertions=y
264268
RUST_BACKTRACE: 1
265269
except:
@@ -285,7 +289,7 @@ test-runtime-benchmarks:
285289
- $DEPLOY_TAG
286290
script:
287291
- cd bin/node/cli
288-
- WASM_BUILD_NO_COLOR=1 time cargo test --release --verbose --features runtime-benchmarks
292+
- WASM_BUILD_NO_COLOR=1 time cargo test --workspace --release --verbose --features runtime-benchmarks
289293
- sccache -s
290294

291295
test-linux-stable-int:

.maintain/monitoring/alerting-rules/alerting-rule-tests.yaml

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ tests:
1818
pod="polkadot-abcdef01234-abcdef",
1919
instance="polkadot-abcdef01234-abcdef",
2020
}'
21-
values: '10+1x30' # 10 11 12 13 .. 40
21+
values: '11+1x10 22+2x30 10043x5'
2222

2323
- series: 'polkadot_sub_txpool_validations_finished{
2424
job="polkadot",
2525
pod="polkadot-abcdef01234-abcdef",
2626
instance="polkadot-abcdef01234-abcdef",
2727
}'
28-
values: '0x30' # 0 0 0 0 .. 0
28+
values: '0+1x42 42x5'
2929

3030
- series: 'polkadot_block_height{
3131
status="best", job="polkadot",
@@ -161,43 +161,66 @@ tests:
161161
# Transaction queue
162162
######################################################################
163163

164-
- eval_time: 10m
165-
alertname: TransactionQueueSize
166-
exp_alerts:
167164
- eval_time: 11m
168-
alertname: TransactionQueueSize
165+
alertname: TransactionQueueSizeIncreasing
166+
# Number of validations scheduled and finished both grow at a rate
167+
# of 1 in the first 10 minutes, thereby the queue is not increasing
168+
# in size, thus don't expect an alert.
169+
exp_alerts:
170+
- eval_time: 22m
171+
alertname: TransactionQueueSizeIncreasing
172+
# Number of validations scheduled is growing twice as fast as the
173+
# number of validations finished after minute 10. Thus expect
174+
# warning alert after 20 minutes.
169175
exp_alerts:
170176
- exp_labels:
171177
severity: warning
172178
pod: polkadot-abcdef01234-abcdef
173179
instance: polkadot-abcdef01234-abcdef
174180
job: polkadot
175181
exp_annotations:
176-
message: "The node polkadot-abcdef01234-abcdef has more
177-
than 10 transactions in the queue for more than 10
178-
minutes"
179-
180-
- eval_time: 31m
181-
alertname: TransactionQueueSize
182+
message: "The transaction pool size on node
183+
polkadot-abcdef01234-abcdef has been monotonically
184+
increasing for the last 10 minutes."
185+
- eval_time: 43m
186+
alertname: TransactionQueueSizeIncreasing
187+
# Number of validations scheduled is growing twice as fast as the
188+
# number of validations finished after minute 10. Thus expect
189+
# both warning and critical alert after 40 minutes.
182190
exp_alerts:
183191
- exp_labels:
184192
severity: warning
185193
pod: polkadot-abcdef01234-abcdef
186194
instance: polkadot-abcdef01234-abcdef
187195
job: polkadot
188196
exp_annotations:
189-
message: "The node polkadot-abcdef01234-abcdef has more
190-
than 10 transactions in the queue for more than 10
191-
minutes"
197+
message: "The transaction pool size on node
198+
polkadot-abcdef01234-abcdef has been monotonically
199+
increasing for the last 10 minutes."
200+
- exp_labels:
201+
severity: critical
202+
pod: polkadot-abcdef01234-abcdef
203+
instance: polkadot-abcdef01234-abcdef
204+
job: polkadot
205+
exp_annotations:
206+
message: "The transaction pool size on node
207+
polkadot-abcdef01234-abcdef has been monotonically
208+
increasing for the last 30 minutes."
209+
- eval_time: 49m
210+
alertname: TransactionQueueSizeHigh
211+
# After minute 43 the number of validations scheduled jumps up
212+
# drastically while the number of validations finished stays the
213+
# same. Thus expect an alert.
214+
exp_alerts:
192215
- exp_labels:
193216
severity: critical
194217
pod: polkadot-abcdef01234-abcdef
195218
instance: polkadot-abcdef01234-abcdef
196219
job: polkadot
197220
exp_annotations:
198-
message: "The node polkadot-abcdef01234-abcdef has more
199-
than 10 transactions in the queue for more than 30
200-
minutes"
221+
message: "The transaction pool size on node
222+
polkadot-abcdef01234-abcdef has been above 10_000 for the
223+
last 5 minutes."
201224

202225
######################################################################
203226
# Networking

.maintain/monitoring/alerting-rules/alerting-rules.yaml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,33 @@ groups:
7373
# Transaction queue
7474
##############################################################################
7575

76-
- alert: TransactionQueueSize
77-
expr: 'polkadot_sub_txpool_validations_scheduled -
78-
polkadot_sub_txpool_validations_finished > 10'
76+
- alert: TransactionQueueSizeIncreasing
77+
expr: 'increase(polkadot_sub_txpool_validations_scheduled[5m]) -
78+
increase(polkadot_sub_txpool_validations_finished[5m]) > 0'
7979
for: 10m
8080
labels:
8181
severity: warning
8282
annotations:
83-
message: 'The node {{ $labels.instance }} has more than 10 transactions in
84-
the queue for more than 10 minutes'
85-
- alert: TransactionQueueSize
86-
expr: 'polkadot_sub_txpool_validations_scheduled -
87-
polkadot_sub_txpool_validations_finished > 10'
83+
message: 'The transaction pool size on node {{ $labels.instance }} has
84+
been monotonically increasing for the last 10 minutes.'
85+
- alert: TransactionQueueSizeIncreasing
86+
expr: 'increase(polkadot_sub_txpool_validations_scheduled[5m]) -
87+
increase(polkadot_sub_txpool_validations_finished[5m]) > 0'
8888
for: 30m
8989
labels:
9090
severity: critical
9191
annotations:
92-
message: 'The node {{ $labels.instance }} has more than 10 transactions in
93-
the queue for more than 30 minutes'
92+
message: 'The transaction pool size on node {{ $labels.instance }} has
93+
been monotonically increasing for the last 30 minutes.'
94+
- alert: TransactionQueueSizeHigh
95+
expr: 'polkadot_sub_txpool_validations_scheduled -
96+
polkadot_sub_txpool_validations_finished > 10000'
97+
for: 5m
98+
labels:
99+
severity: critical
100+
annotations:
101+
message: 'The transaction pool size on node {{ $labels.instance }} has
102+
been above 10_000 for the last 5 minutes.'
94103

95104
##############################################################################
96105
# Networking

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/executor/src/integration_tests/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,7 @@ fn offchain_http_should_work(wasm_method: WasmExecutionMethod) {
497497
let mut ext = TestExternalities::default();
498498
let (offchain, state) = testing::TestOffchainExt::new();
499499
ext.register_extension(OffchainExt::new(offchain));
500-
state.write().expect_request(
501-
0,
502-
testing::PendingRequest {
500+
state.write().expect_request(testing::PendingRequest {
503501
method: "POST".into(),
504502
uri: "http://localhost:12345".into(),
505503
body: vec![1, 2, 3, 4],

client/finality-grandpa/src/communication/gossip.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,11 @@ impl<Block: BlockT> Inner<Block> {
750750
Round(1),
751751
)),
752752
Some(ref mut v) => if v.set_id == set_id {
753-
if self.authorities != authorities {
753+
let diff_authorities =
754+
self.authorities.iter().collect::<HashSet<_>>() !=
755+
authorities.iter().collect();
756+
757+
if diff_authorities {
754758
debug!(target: "afg",
755759
"Gossip validator noted set {:?} twice with different authorities. \
756760
Was the authority set hard forked?",
@@ -829,7 +833,7 @@ impl<Block: BlockT> Inner<Block> {
829833
return Action::Discard(cost::UNKNOWN_VOTER);
830834
}
831835

832-
if let Err(()) = sp_finality_grandpa::check_message_signature(
836+
if !sp_finality_grandpa::check_message_signature(
833837
&full.message.message,
834838
&full.message.id,
835839
&full.message.signature,
@@ -2620,12 +2624,12 @@ mod tests {
26202624
fn allow_noting_different_authorities_for_same_set() {
26212625
let (val, _) = GossipValidator::<Block>::new(config(), voter_set_state(), None);
26222626

2623-
let a1 = vec![AuthorityId::default()];
2627+
let a1 = vec![AuthorityId::from_slice(&[0; 32])];
26242628
val.note_set(SetId(1), a1.clone(), |_, _| {});
26252629

26262630
assert_eq!(val.inner().read().authorities, a1);
26272631

2628-
let a2 = vec![AuthorityId::default(), AuthorityId::default()];
2632+
let a2 = vec![AuthorityId::from_slice(&[1; 32]), AuthorityId::from_slice(&[2; 32])];
26292633
val.note_set(SetId(1), a2.clone(), |_, _| {});
26302634

26312635
assert_eq!(val.inner().read().authorities, a2);

client/finality-grandpa/src/communication/mod.rs

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,34 @@ mod benefit {
105105
pub(super) const PER_EQUIVOCATION: i32 = 10;
106106
}
107107

108+
/// A type that ties together our local authority id and a keystore where it is
109+
/// available for signing.
110+
pub struct LocalIdKeystore((AuthorityId, BareCryptoStorePtr));
111+
112+
impl LocalIdKeystore {
113+
/// Returns a reference to our local authority id.
114+
fn local_id(&self) -> &AuthorityId {
115+
&(self.0).0
116+
}
117+
118+
/// Returns a reference to the keystore.
119+
fn keystore(&self) -> &BareCryptoStorePtr {
120+
&(self.0).1
121+
}
122+
}
123+
124+
impl AsRef<BareCryptoStorePtr> for LocalIdKeystore {
125+
fn as_ref(&self) -> &BareCryptoStorePtr {
126+
self.keystore()
127+
}
128+
}
129+
130+
impl From<(AuthorityId, BareCryptoStorePtr)> for LocalIdKeystore {
131+
fn from(inner: (AuthorityId, BareCryptoStorePtr)) -> LocalIdKeystore {
132+
LocalIdKeystore(inner)
133+
}
134+
}
135+
108136
/// If the voter set is larger than this value some telemetry events are not
109137
/// sent to avoid increasing usage resource on the node and flooding the
110138
/// telemetry server (e.g. received votes, received commits.)
@@ -272,11 +300,10 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
272300
/// network all within the current set.
273301
pub(crate) fn round_communication(
274302
&self,
275-
keystore: Option<BareCryptoStorePtr>,
303+
keystore: Option<LocalIdKeystore>,
276304
round: Round,
277305
set_id: SetId,
278306
voters: Arc<VoterSet<AuthorityId>>,
279-
local_key: Option<AuthorityId>,
280307
has_voted: HasVoted<B>,
281308
) -> (
282309
impl Stream<Item = SignedMessage<B>> + Unpin,
@@ -288,9 +315,10 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
288315
&*voters,
289316
);
290317

291-
let local_id = local_key.and_then(|id| {
292-
if voters.contains(&id) {
293-
Some(id)
318+
let keystore = keystore.and_then(|ks| {
319+
let id = ks.local_id();
320+
if voters.contains(id) {
321+
Some(ks)
294322
} else {
295323
None
296324
}
@@ -350,11 +378,10 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
350378

351379
let (tx, out_rx) = mpsc::channel(0);
352380
let outgoing = OutgoingMessages::<B> {
353-
keystore: keystore.clone(),
381+
keystore,
354382
round: round.0,
355383
set_id: set_id.0,
356384
network: self.gossip_engine.clone(),
357-
local_id,
358385
sender: tx,
359386
has_voted,
360387
};
@@ -629,11 +656,10 @@ pub struct SetId(pub SetIdNumber);
629656
pub(crate) struct OutgoingMessages<Block: BlockT> {
630657
round: RoundNumber,
631658
set_id: SetIdNumber,
632-
local_id: Option<AuthorityId>,
659+
keystore: Option<LocalIdKeystore>,
633660
sender: mpsc::Sender<SignedMessage<Block>>,
634661
network: Arc<Mutex<GossipEngine<Block>>>,
635662
has_voted: HasVoted<Block>,
636-
keystore: Option<BareCryptoStorePtr>,
637663
}
638664

639665
impl<B: BlockT> Unpin for OutgoingMessages<B> {}
@@ -667,19 +693,12 @@ impl<Block: BlockT> Sink<Message<Block>> for OutgoingMessages<Block>
667693
}
668694

669695
// when locals exist, sign messages on import
670-
if let Some(ref public) = self.local_id {
671-
let keystore = match &self.keystore {
672-
Some(keystore) => keystore.clone(),
673-
None => {
674-
return Err(Error::Signing("Cannot sign without a keystore".to_string()))
675-
}
676-
};
677-
696+
if let Some(ref keystore) = self.keystore {
678697
let target_hash = *(msg.target().0);
679698
let signed = sp_finality_grandpa::sign_message(
680-
keystore,
699+
keystore.as_ref(),
681700
msg,
682-
public.clone(),
701+
keystore.local_id().clone(),
683702
self.round,
684703
self.set_id,
685704
).ok_or(
@@ -774,7 +793,7 @@ fn check_compact_commit<Block: BlockT>(
774793
use crate::communication::gossip::Misbehavior;
775794
use finality_grandpa::Message as GrandpaMessage;
776795

777-
if let Err(()) = sp_finality_grandpa::check_message_signature_with_buffer(
796+
if !sp_finality_grandpa::check_message_signature_with_buffer(
778797
&GrandpaMessage::Precommit(precommit.clone()),
779798
id,
780799
sig,
@@ -862,7 +881,7 @@ fn check_catch_up<Block: BlockT>(
862881
for (msg, id, sig) in messages {
863882
signatures_checked += 1;
864883

865-
if let Err(()) = sp_finality_grandpa::check_message_signature_with_buffer(
884+
if !sp_finality_grandpa::check_message_signature_with_buffer(
866885
&msg,
867886
id,
868887
sig,

client/finality-grandpa/src/environment.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,12 +716,18 @@ where
716716
HasVoted::No => HasVoted::No,
717717
};
718718

719+
// we can only sign when we have a local key in the authority set
720+
// and we have a reference to the keystore.
721+
let keystore = match (local_key.as_ref(), self.config.keystore.as_ref()) {
722+
(Some(id), Some(keystore)) => Some((id.clone(), keystore.clone()).into()),
723+
_ => None,
724+
};
725+
719726
let (incoming, outgoing) = self.network.round_communication(
720-
self.config.keystore.clone(),
727+
keystore,
721728
crate::communication::Round(round),
722729
crate::communication::SetId(self.set_id),
723730
self.voters.clone(),
724-
local_key.clone(),
725731
has_voted,
726732
);
727733

client/finality-grandpa/src/justification.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ impl<Block: BlockT> GrandpaJustification<Block> {
133133
let mut buf = Vec::new();
134134
let mut visited_hashes = HashSet::new();
135135
for signed in self.commit.precommits.iter() {
136-
if sp_finality_grandpa::check_message_signature_with_buffer(
136+
if !sp_finality_grandpa::check_message_signature_with_buffer(
137137
&finality_grandpa::Message::Precommit(signed.precommit.clone()),
138138
&signed.id,
139139
&signed.signature,
140140
self.round,
141141
set_id,
142142
&mut buf,
143-
).is_err() {
143+
) {
144144
return Err(ClientError::BadJustification(
145145
"invalid signature for precommit in grandpa justification".to_string()));
146146
}

0 commit comments

Comments
 (0)