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

Commit 7c4f847

Browse files
committed
Merge branch 'master' into wasm-builder-offline-mode
2 parents 4de5bad + 90d08f7 commit 7c4f847

File tree

53 files changed

+540
-259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+540
-259
lines changed

Cargo.lock

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

client/authority-discovery/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ readme = "README.md"
1414
targets = ["x86_64-unknown-linux-gnu"]
1515

1616
[build-dependencies]
17-
prost-build = "0.9"
17+
prost-build = "0.10"
1818

1919
[dependencies]
2020
async-trait = "0.1"
2121
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
2222
futures = "0.3.21"
2323
futures-timer = "3.0.1"
2424
ip_network = "0.4.1"
25-
libp2p = { version = "0.44.0", default-features = false, features = ["kad"] }
25+
libp2p = { version = "0.45.1", default-features = false, features = ["kad"] }
2626
log = "0.4.17"
2727
prost = "0.10"
2828
rand = "0.7.2"

client/authority-discovery/src/worker/schema/dht-v2.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ message SignedAuthorityRecord {
1818
bytes record = 1;
1919
bytes auth_signature = 2;
2020
// Even if there are multiple `record.addresses`, all of them have the same peer id.
21-
// Old versions are missing this field, so `optional` will provide compatibility both ways.
22-
optional PeerSignature peer_signature = 3;
21+
// Old versions are missing this field. It is optional in order to provide compatibility both ways.
22+
PeerSignature peer_signature = 3;
2323
}

client/basic-authorship/src/basic_authorship.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
2121
// FIXME #1021 move this into sp-consensus
2222

23-
use codec::{Decode, Encode};
23+
use codec::Encode;
2424
use futures::{
2525
channel::oneshot,
2626
future,
@@ -536,10 +536,6 @@ where
536536
"hash" => ?<Block as BlockT>::Hash::from(block.header().hash()),
537537
);
538538

539-
if Decode::decode(&mut block.encode().as_slice()).as_ref() != Ok(&block) {
540-
error!("Failed to verify block encoding/decoding");
541-
}
542-
543539
if let Err(err) =
544540
evaluation::evaluate_initial(&block, &self.parent_hash, self.parent_number)
545541
{

client/beefy/src/worker.rs

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ use std::{
2525
};
2626

2727
use codec::{Codec, Decode, Encode};
28-
use futures::{future, FutureExt, StreamExt};
28+
use futures::StreamExt;
2929
use log::{debug, error, info, log_enabled, trace, warn};
30-
use parking_lot::Mutex;
3130

32-
use sc_client_api::{Backend, FinalityNotification, FinalityNotifications};
31+
use sc_client_api::{Backend, FinalityNotification};
3332
use sc_network_gossip::GossipEngine;
3433

3534
use sp_api::{BlockId, ProvideRuntimeApi};
@@ -80,15 +79,14 @@ pub(crate) struct BeefyWorker<B: Block, BE, C, R, SO> {
8079
runtime: Arc<R>,
8180
key_store: BeefyKeystore,
8281
signed_commitment_sender: BeefySignedCommitmentSender<B>,
83-
gossip_engine: Arc<Mutex<GossipEngine<B>>>,
82+
gossip_engine: GossipEngine<B>,
8483
gossip_validator: Arc<GossipValidator<B>>,
8584
/// Min delta in block numbers between two blocks, BEEFY should vote on
8685
min_block_delta: u32,
8786
metrics: Option<Metrics>,
8887
rounds: Option<Rounds<Payload, B>>,
8988
/// Buffer holding votes for blocks that the client hasn't seen finality for.
9089
pending_votes: BTreeMap<NumberFor<B>, Vec<VoteMessage<NumberFor<B>, AuthorityId, Signature>>>,
91-
finality_notifications: FinalityNotifications<B>,
9290
/// Best block we received a GRANDPA notification for
9391
best_grandpa_block_header: <B as Block>::Header,
9492
/// Best block a BEEFY voting round has been concluded for
@@ -143,14 +141,13 @@ where
143141
runtime,
144142
key_store,
145143
signed_commitment_sender,
146-
gossip_engine: Arc::new(Mutex::new(gossip_engine)),
144+
gossip_engine,
147145
gossip_validator,
148146
// always target at least one block better than current best beefy
149147
min_block_delta: min_block_delta.max(1),
150148
metrics,
151149
rounds: None,
152150
pending_votes: BTreeMap::new(),
153-
finality_notifications: client.finality_notification_stream(),
154151
best_grandpa_block_header: last_finalized_header,
155152
best_beefy_block: None,
156153
last_signed_id: 0,
@@ -471,15 +468,21 @@ where
471468
true,
472469
);
473470

474-
self.gossip_engine.lock().gossip_message(topic::<B>(), encoded_message, false);
471+
self.gossip_engine.gossip_message(topic::<B>(), encoded_message, false);
475472
}
476473

477474
/// Wait for BEEFY runtime pallet to be available.
478475
async fn wait_for_runtime_pallet(&mut self) {
479-
self.client
480-
.finality_notification_stream()
481-
.take_while(|notif| {
482-
let at = BlockId::hash(notif.header.hash());
476+
let mut gossip_engine = &mut self.gossip_engine;
477+
let mut finality_stream = self.client.finality_notification_stream().fuse();
478+
loop {
479+
futures::select! {
480+
notif = finality_stream.next() => {
481+
let notif = match notif {
482+
Some(notif) => notif,
483+
None => break
484+
};
485+
let at = BlockId::hash(notif.header.hash());
483486
if let Some(active) = self.runtime.runtime_api().validator_set(&at).ok().flatten() {
484487
if active.id() == GENESIS_AUTHORITY_SET_ID {
485488
// When starting from genesis, there is no session boundary digest.
@@ -490,18 +493,18 @@ where
490493
// worker won't vote until it witnesses a session change.
491494
// Once we'll implement 'initial sync' (catch-up), the worker will be able to
492495
// start voting right away.
493-
self.handle_finality_notification(notif);
494-
future::ready(false)
496+
self.handle_finality_notification(&notif);
497+
break
495498
} else {
496499
trace!(target: "beefy", "🥩 Finality notification: {:?}", notif);
497500
debug!(target: "beefy", "🥩 Waiting for BEEFY pallet to become available...");
498-
future::ready(true)
499501
}
500-
})
501-
.for_each(|_| future::ready(()))
502-
.await;
503-
// get a new stream that provides _new_ notifications (from here on out)
504-
self.finality_notifications = self.client.finality_notification_stream();
502+
},
503+
_ = gossip_engine => {
504+
break
505+
}
506+
}
507+
}
505508
}
506509

507510
/// Main loop for BEEFY worker.
@@ -512,35 +515,37 @@ where
512515
info!(target: "beefy", "🥩 run BEEFY worker, best grandpa: #{:?}.", self.best_grandpa_block_header.number());
513516
self.wait_for_runtime_pallet().await;
514517

515-
let mut votes = Box::pin(self.gossip_engine.lock().messages_for(topic::<B>()).filter_map(
516-
|notification| async move {
517-
trace!(target: "beefy", "🥩 Got vote message: {:?}", notification);
518-
519-
VoteMessage::<NumberFor<B>, AuthorityId, Signature>::decode(
520-
&mut &notification.message[..],
521-
)
522-
.ok()
523-
},
524-
));
518+
let mut finality_notifications = self.client.finality_notification_stream().fuse();
519+
let mut votes = Box::pin(
520+
self.gossip_engine
521+
.messages_for(topic::<B>())
522+
.filter_map(|notification| async move {
523+
trace!(target: "beefy", "🥩 Got vote message: {:?}", notification);
524+
525+
VoteMessage::<NumberFor<B>, AuthorityId, Signature>::decode(
526+
&mut &notification.message[..],
527+
)
528+
.ok()
529+
})
530+
.fuse(),
531+
);
525532

526533
loop {
527534
while self.sync_oracle.is_major_syncing() {
528535
debug!(target: "beefy", "Waiting for major sync to complete...");
529536
futures_timer::Delay::new(Duration::from_secs(5)).await;
530537
}
531538

532-
let engine = self.gossip_engine.clone();
533-
let gossip_engine = future::poll_fn(|cx| engine.lock().poll_unpin(cx));
534-
539+
let mut gossip_engine = &mut self.gossip_engine;
535540
futures::select! {
536-
notification = self.finality_notifications.next().fuse() => {
541+
notification = finality_notifications.next() => {
537542
if let Some(notification) = notification {
538543
self.handle_finality_notification(&notification);
539544
} else {
540545
return;
541546
}
542547
},
543-
vote = votes.next().fuse() => {
548+
vote = votes.next() => {
544549
if let Some(vote) = vote {
545550
let block_num = vote.commitment.block_number;
546551
if block_num > *self.best_grandpa_block_header.number() {
@@ -563,7 +568,7 @@ where
563568
return;
564569
}
565570
},
566-
_ = gossip_engine.fuse() => {
571+
_ = gossip_engine => {
567572
error!(target: "beefy", "🥩 Gossip engine has terminated.");
568573
return;
569574
}

client/chain-spec/derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ proc-macro = true
1818
proc-macro-crate = "1.1.3"
1919
proc-macro2 = "1.0.37"
2020
quote = "1.0.10"
21-
syn = "1.0.82"
21+
syn = "1.0.98"

client/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ clap = { version = "3.1.18", features = ["derive"] }
1818
fdlimit = "0.2.1"
1919
futures = "0.3.21"
2020
hex = "0.4.2"
21-
libp2p = "0.44.0"
21+
libp2p = "0.45.1"
2222
log = "0.4.17"
2323
names = { version = "0.13.0", default-features = false }
2424
parity-scale-codec = "3.0.0"

client/consensus/babe/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,11 @@ where
18731873
{
18741874
let best_number = client.info().best_number;
18751875
let finalized = client.info().finalized_number;
1876+
18761877
let revertible = blocks.min(best_number - finalized);
1878+
if revertible == Zero::zero() {
1879+
return Ok(())
1880+
}
18771881

18781882
let revert_up_to_number = best_number - revertible;
18791883
let revert_up_to_hash = client.hash(revert_up_to_number)?.ok_or(ClientError::Backend(

client/consensus/common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
1616
async-trait = "0.1.42"
1717
futures = { version = "0.3.21", features = ["thread-pool"] }
1818
futures-timer = "3.0.1"
19-
libp2p = { version = "0.44.0", default-features = false }
19+
libp2p = { version = "0.45.1", default-features = false }
2020
log = "0.4.17"
2121
parking_lot = "0.12.0"
2222
serde = { version = "1.0", features = ["derive"] }

client/executor/wasmtime/src/host.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,7 @@ impl<'a> sp_wasm_interface::FunctionContext for HostContext<'a> {
145145
}
146146

147147
fn register_panic_error_message(&mut self, message: &str) {
148-
self.caller
149-
.data_mut()
150-
.host_state_mut()
151-
.expect("host state is not empty when calling a function in wasm; qed")
152-
.panic_message = Some(message.to_owned());
148+
self.host_state_mut().panic_message = Some(message.to_owned());
153149
}
154150
}
155151

0 commit comments

Comments
 (0)