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

network/src/legacy/gossip: Wrap GossipEngine in Arc Mutex & lock it on use #890

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,051 changes: 1,025 additions & 1,026 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions availability-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ futures = "0.3.4"
tokio = { version = "0.2.10", features = ["rt-core"] }
exit-future = "0.2.0"
codec = { package = "parity-scale-codec", version = "1.1.0", features = ["derive"] }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
consensus_common = { package = "sp-consensus", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
client = { package = "sc-client-api", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-client = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
keystore = { package = "sc-keystore", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-network = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
consensus_common = { package = "sp-consensus", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
client = { package = "sc-client-api", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sc-client = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-runtime = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-blockchain = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-api = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
keystore = { package = "sc-keystore", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-core = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
kvdb = "0.4.0"
kvdb-memorydb = "0.4.0"

Expand Down
18 changes: 9 additions & 9 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ crate-type = ["cdylib", "rlib"]
log = "0.4.8"
futures = { version = "0.3.4", features = ["compat"] }
structopt = "0.3.8"
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-client = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-client-db = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-cli = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", optional = true }
sp-api = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-core = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-runtime = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sc-client = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sc-client-api = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sc-client-db = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sc-executor = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
service = { package = "polkadot-service", path = "../service", default-features = false }

tokio = { version = "0.2.10", features = ["rt-threaded"], optional = true }

wasm-bindgen = { version = "0.2.57", optional = true }
wasm-bindgen-futures = { version = "0.4.7", optional = true }
browser-utils = { package = "substrate-browser-utils", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true }
browser-utils = { package = "substrate-browser-utils", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", optional = true }

[features]
default = [ "wasmtime", "rocksdb", "cli" ]
Expand Down
20 changes: 10 additions & 10 deletions collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ edition = "2018"

[dependencies]
futures = "0.3.4"
sc-client = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
consensus_common = { package = "sp-consensus", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-client = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sc-cli = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sc-client-api = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sc-network = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-blockchain = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-api = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-core = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-runtime = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
consensus_common = { package = "sp-consensus", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
polkadot-primitives = { path = "../primitives" }
polkadot-cli = { path = "../cli" }
polkadot-network = { path = "../network" }
Expand All @@ -27,4 +27,4 @@ futures-timer = "2.0"
codec = { package = "parity-scale-codec", version = "1.1.0" }

[dev-dependencies]
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
keyring = { package = "sp-keyring", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
4 changes: 2 additions & 2 deletions erasure-coding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ edition = "2018"
primitives = { package = "polkadot-primitives", path = "../primitives" }
reed_solomon = { package = "reed-solomon-erasure", git = "https://github.com/paritytech/reed-solomon-erasure" }
codec = { package = "parity-scale-codec", version = "1.1.0", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
trie = { package = "sp-trie", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-core = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
trie = { package = "sp-trie", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
derive_more = "0.15.0"
18 changes: 9 additions & 9 deletions network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ polkadot-validation = { path = "../validation" }
polkadot-primitives = { path = "../primitives" }
polkadot-erasure-coding = { path = "../erasure-coding" }
codec = { package = "parity-scale-codec", version = "1.1.0", default-features = false, features = ["derive"] }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-network-gossip = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-network = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sc-network-gossip = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-core = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-runtime = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
futures = "0.3.4"
log = "0.4.8"
exit-future = "0.2.0"
futures-timer = "2.0"
sc-client = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-client = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-blockchain = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-api = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
wasm-timer = "0.2.4"

[dev-dependencies]
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-keyring = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
sp-state-machine = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
30 changes: 19 additions & 11 deletions network/src/legacy/gossip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ use std::sync::Arc;

use arrayvec::ArrayVec;
use futures::prelude::*;
use parking_lot::RwLock;
use parking_lot::{Mutex, RwLock};

use crate::legacy::{GossipMessageStream, GossipService};

Expand Down Expand Up @@ -289,20 +289,28 @@ pub fn register_validator<C: ChainContext + 'static>(
});

let gossip_side = validator.clone();
let gossip_engine = sc_network_gossip::GossipEngine::new(
let gossip_engine = Arc::new(Mutex::new(sc_network_gossip::GossipEngine::new(
service.clone(),
POLKADOT_ENGINE_ID,
POLKADOT_PROTOCOL_NAME,
gossip_side,
);
)));

// Spawn gossip engine.
//
// Ideally this would not be spawned as an orphaned task, but polled by
// `RegisteredMessageValidator` which in turn would be polled by a `ValidationNetwork`.
let spawn_res = executor.spawn_obj(futures::task::FutureObj::from(Box::new(gossip_engine.clone())));
{
let gossip_engine = gossip_engine.clone();
let fut = futures::future::poll_fn(move |cx| {
gossip_engine.lock().poll_unpin(cx)
});
let spawn_res = executor.spawn_obj(futures::task::FutureObj::from(Box::new(fut)));

// Note: we consider the chances of an error to spawn a background task almost null.
if spawn_res.is_err() {
log::error!(target: "polkadot-gossip", "Failed to spawn background task");
// Note: we consider the chances of an error to spawn a background task almost null.
if spawn_res.is_err() {
log::error!(target: "polkadot-gossip", "Failed to spawn background task");
}
}

RegisteredMessageValidator {
Expand Down Expand Up @@ -350,7 +358,7 @@ pub struct RegisteredMessageValidator {
// Note: this is always `Some` in real code and `None` in tests.
service: Option<Arc<NetworkService<Block, Hash>>>,
// Note: this is always `Some` in real code and `None` in tests.
gossip_engine: Option<sc_network_gossip::GossipEngine<Block>>,
gossip_engine: Option<Arc<Mutex<sc_network_gossip::GossipEngine<Block>>>>,
}

impl RegisteredMessageValidator {
Expand Down Expand Up @@ -398,7 +406,7 @@ impl RegisteredMessageValidator {

pub(crate) fn gossip_messages_for(&self, topic: Hash) -> GossipMessageStream {
let topic_stream = if let Some(gossip_engine) = self.gossip_engine.as_ref() {
gossip_engine.messages_for(topic)
gossip_engine.lock().messages_for(topic)
} else {
log::error!("Called gossip_messages_for on a test engine");
futures::channel::mpsc::unbounded().1
Expand All @@ -409,7 +417,7 @@ impl RegisteredMessageValidator {

pub(crate) fn gossip_message(&self, topic: Hash, message: GossipMessage) {
if let Some(gossip_engine) = self.gossip_engine.as_ref() {
gossip_engine.gossip_message(
gossip_engine.lock().gossip_message(
topic,
message.encode(),
false,
Expand All @@ -421,7 +429,7 @@ impl RegisteredMessageValidator {

pub(crate) fn send_message(&self, who: PeerId, message: GossipMessage) {
if let Some(gossip_engine) = self.gossip_engine.as_ref() {
gossip_engine.send_message(vec![who], message.encode());
gossip_engine.lock().send_message(vec![who], message.encode());
} else {
log::error!("Called send_message on a test engine");
}
Expand Down
14 changes: 7 additions & 7 deletions parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ edition = "2018"
codec = { package = "parity-scale-codec", version = "1.1.0", default-features = false, features = [ "derive" ] }
derive_more = { version = "0.99.2", optional = true }
serde = { version = "1.0.102", default-features = false, features = [ "derive" ], optional = true }
rstd = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-wasm-interface = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-externalities = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true }
rstd = { package = "sp-std", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", default-features = false }
sp-core = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", default-features = false }
sp-runtime-interface = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", default-features = false }
sp-wasm-interface = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", default-features = false }
sp-externalities = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", optional = true }
sc-executor = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", optional = true }
sp-io = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", optional = true }
lazy_static = { version = "1.4.0", optional = true }
parking_lot = { version = "0.10.0", optional = true }
log = { version = "0.4.8", optional = true }
Expand Down
20 changes: 10 additions & 10 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ edition = "2018"
[dependencies]
serde = { version = "1.0.102", optional = true, features = ["derive"] }
parity-scale-codec = { version = "1.1.0", default-features = false, features = ["bit-vec", "derive"] }
primitives = { package = "sp-core", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
inherents = { package = "sp-inherents", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
application-crypto = { package = "sp-application-crypto", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
rstd = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
runtime_primitives = { package = "sp-runtime", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
primitives = { package = "sp-core", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", default-features = false }
inherents = { package = "sp-inherents", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", default-features = false }
application-crypto = { package = "sp-application-crypto", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", default-features = false }
sp-api = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", default-features = false }
sp-version = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", default-features = false }
rstd = { package = "sp-std", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", default-features = false }
runtime_primitives = { package = "sp-runtime", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", default-features = false }
polkadot-parachain = { path = "../parachain", default-features = false }
trie = { package = "sp-trie", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
trie = { package = "sp-trie", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", default-features = false }
bitvec = { version = "0.15.2", default-features = false, features = ["alloc"] }
babe = { package = "pallet-babe", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
babe = { package = "pallet-babe", git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master", default-features = false }

[dev-dependencies]
sp-serializer = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-serializer = { git = "https://github.com/mxinden/substrate", branch = "merge-gossip-engine-polkadot-master" }
pretty_assertions = "0.5.1"

[features]
Expand Down
Loading