Skip to content

Commit

Permalink
Merge branch 'polkadot-v0.9.24-1' into update-carthage-to-v0.9.24-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaamani committed Sep 5, 2022
2 parents 31f4f76 + 3e7e33d commit d29a53b
Show file tree
Hide file tree
Showing 35 changed files with 502 additions and 270 deletions.
357 changes: 229 additions & 128 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/authority-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features =
futures = "0.3.21"
futures-timer = "3.0.1"
ip_network = "0.4.1"
libp2p = { version = "0.44.0", default-features = false, features = ["kad"] }
libp2p = { version = "0.45.1", default-features = false, features = ["kad"] }
log = "0.4.17"
prost = "0.10"
rand = "0.7.2"
Expand Down
2 changes: 1 addition & 1 deletion client/chain-spec/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ proc-macro = true
proc-macro-crate = "1.1.3"
proc-macro2 = "1.0.37"
quote = "1.0.10"
syn = "1.0.82"
syn = "1.0.98"
2 changes: 1 addition & 1 deletion client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ clap = { version = "3.1.18", features = ["derive"] }
fdlimit = "0.2.1"
futures = "0.3.21"
hex = "0.4.2"
libp2p = "0.44.0"
libp2p = "0.45.1"
log = "0.4.17"
names = { version = "0.13.0", default-features = false }
parity-scale-codec = "3.0.0"
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
async-trait = "0.1.42"
futures = { version = "0.3.21", features = ["thread-pool"] }
futures-timer = "3.0.1"
libp2p = { version = "0.44.0", default-features = false }
libp2p = { version = "0.45.1", default-features = false }
log = "0.4.17"
parking_lot = "0.12.0"
serde = { version = "1.0", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion client/network-gossip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"]
ahash = "0.7.6"
futures = "0.3.21"
futures-timer = "3.0.1"
libp2p = { version = "0.44.0", default-features = false }
libp2p = { version = "0.45.1", default-features = false }
log = "0.4.17"
lru = "0.7.5"
tracing = "0.1.29"
Expand Down
2 changes: 1 addition & 1 deletion client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ futures = "0.3.21"
futures-timer = "3.0.2"
hex = "0.4.0"
ip_network = "0.4.1"
libp2p = "0.44.0"
libp2p = "0.45.1"
linked_hash_set = "0.1.3"
linked-hash-map = "0.5.4"
log = "0.4.17"
Expand Down
2 changes: 1 addition & 1 deletion client/network/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ codec = { package = "parity-scale-codec", version = "3.0.0", features = [
"derive",
] }
futures = "0.3.21"
libp2p = "0.44.0"
libp2p = "0.45.1"
smallvec = "1.8.0"
sc-peerset = { version = "4.0.0-dev", path = "../../peerset" }
2 changes: 1 addition & 1 deletion client/network/light/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ codec = { package = "parity-scale-codec", version = "3.0.0", features = [
"derive",
] }
futures = "0.3.21"
libp2p = "0.44.0"
libp2p = "0.45.1"
log = "0.4.16"
prost = "0.10"
sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" }
Expand Down
9 changes: 6 additions & 3 deletions client/network/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ pub fn build_transport(
// Build the base layer of the transport.
let transport = if !memory_only {
let desktop_trans = tcp::TcpConfig::new().nodelay(true);
let desktop_trans =
websocket::WsConfig::new(desktop_trans.clone()).or_transport(desktop_trans);
let dns_init = futures::executor::block_on(dns::DnsConfig::system(desktop_trans.clone()));
let desktop_trans = websocket::WsConfig::new(desktop_trans)
.or_transport(tcp::TcpConfig::new().nodelay(true));
let dns_init = futures::executor::block_on(dns::DnsConfig::system(desktop_trans));
EitherTransport::Left(if let Ok(dns) = dns_init {
EitherTransport::Left(dns)
} else {
let desktop_trans = tcp::TcpConfig::new().nodelay(true);
let desktop_trans = websocket::WsConfig::new(desktop_trans)
.or_transport(tcp::TcpConfig::new().nodelay(true));
EitherTransport::Right(desktop_trans.map_err(dns::DnsErr::Transport))
})
} else {
Expand Down
2 changes: 1 addition & 1 deletion client/network/sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ codec = { package = "parity-scale-codec", version = "3.0.0", features = [
] }
either = "1.5.3"
futures = "0.3.21"
libp2p = "0.44.0"
libp2p = "0.45.1"
log = "0.4.17"
lru = "0.7.5"
prost = "0.10"
Expand Down
2 changes: 1 addition & 1 deletion client/network/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async-std = "1.11.0"
async-trait = "0.1.50"
futures = "0.3.21"
futures-timer = "3.0.1"
libp2p = { version = "0.44.0", default-features = false }
libp2p = { version = "0.45.1", default-features = false }
log = "0.4.17"
parking_lot = "0.12.0"
rand = "0.7.2"
Expand Down
2 changes: 1 addition & 1 deletion client/peerset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
futures = "0.3.21"
libp2p = { version = "0.44.0", default-features = false }
libp2p = { version = "0.45.1", default-features = false }
log = "0.4.17"
serde_json = "1.0.79"
wasm-timer = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion client/telemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
chrono = "0.4.19"
futures = "0.3.21"
libp2p = { version = "0.44.0", default-features = false, features = ["dns-async-std", "tcp-async-io", "wasm-ext", "websocket"] }
libp2p = { version = "0.45.1", default-features = false, features = ["dns-async-std", "tcp-async-io", "wasm-ext", "websocket"] }
log = "0.4.17"
parking_lot = "0.12.0"
pin-project = "1.0.10"
Expand Down
32 changes: 23 additions & 9 deletions client/telemetry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ use log::{error, warn};
use parking_lot::Mutex;
use serde::Serialize;
use std::{
collections::HashMap,
collections::{
hash_map::Entry::{Occupied, Vacant},
HashMap,
},
sync::{atomic, Arc},
};

Expand Down Expand Up @@ -147,15 +150,14 @@ pub struct TelemetryWorker {
register_receiver: mpsc::UnboundedReceiver<Register>,
register_sender: mpsc::UnboundedSender<Register>,
id_counter: Arc<atomic::AtomicU64>,
transport: WsTrans,
}

impl TelemetryWorker {
/// Instantiate a new [`TelemetryWorker`] which can run in background.
///
/// Only one is needed per process.
pub fn new(buffer_size: usize) -> Result<Self> {
let transport = initialize_transport()?;
let _transport = initialize_transport()?;
let (message_sender, message_receiver) = mpsc::channel(buffer_size);
let (register_sender, register_receiver) = mpsc::unbounded();

Expand All @@ -165,7 +167,6 @@ impl TelemetryWorker {
register_receiver,
register_sender,
id_counter: Arc::new(atomic::AtomicU64::new(1)),
transport,
})
}

Expand Down Expand Up @@ -200,7 +201,6 @@ impl TelemetryWorker {
&mut node_pool,
&mut node_map,
&mut pending_connection_notifications,
self.transport.clone(),
).await,
}
}
Expand All @@ -211,7 +211,6 @@ impl TelemetryWorker {
node_pool: &mut HashMap<Multiaddr, Node<WsTrans>>,
node_map: &mut HashMap<Id, Vec<(VerbosityLevel, Multiaddr)>>,
pending_connection_notifications: &mut Vec<(Multiaddr, ConnectionNotifierSender)>,
transport: WsTrans,
) {
let input = input.expect("the stream is never closed; qed");

Expand Down Expand Up @@ -248,9 +247,24 @@ impl TelemetryWorker {
);
node_map.entry(id).or_default().push((verbosity, addr.clone()));

let node = node_pool.entry(addr.clone()).or_insert_with(|| {
Node::new(transport.clone(), addr.clone(), Vec::new(), Vec::new())
});
let node = match node_pool.entry(addr.clone()) {
Occupied(entry) => entry.into_mut(),
Vacant(entry) => {
let transport = initialize_transport();
let transport = match transport {
Ok(t) => t,
Err(err) => {
log::error!(
target: "telemetry",
"Could not initialise transport: {}",
err,
);
continue
},
};
entry.insert(Node::new(transport, addr.clone(), Vec::new(), Vec::new()))
},
};

node.connection_messages.extend(connection_message.clone());

Expand Down
24 changes: 13 additions & 11 deletions client/telemetry/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ impl<TTrans: Transport> Node<TTrans> {

impl<TTrans: Transport, TSinkErr> Node<TTrans>
where
TTrans: Clone + Unpin,
TTrans::Dial: Unpin,
TTrans::Output:
Sink<Vec<u8>, Error = TSinkErr> + Stream<Item = Result<Vec<u8>, TSinkErr>> + Unpin,
Expand All @@ -137,7 +136,7 @@ pub(crate) enum Infallible {}

impl<TTrans: Transport, TSinkErr> Sink<TelemetryPayload> for Node<TTrans>
where
TTrans: Clone + Unpin,
TTrans: Unpin,
TTrans::Dial: Unpin,
TTrans::Output:
Sink<Vec<u8>, Error = TSinkErr> + Stream<Item = Result<Vec<u8>, TSinkErr>> + Unpin,
Expand Down Expand Up @@ -228,15 +227,18 @@ where
socket = NodeSocket::wait_reconnect();
},
},
NodeSocket::ReconnectNow => match self.transport.clone().dial(self.addr.clone()) {
Ok(d) => {
log::trace!(target: "telemetry", "Re-dialing {}", self.addr);
socket = NodeSocket::Dialing(d);
},
Err(err) => {
log::warn!(target: "telemetry", "❌ Error while re-dialing {}: {:?}", self.addr, err);
socket = NodeSocket::wait_reconnect();
},
NodeSocket::ReconnectNow => {
let addr = self.addr.clone();
match self.transport.dial(addr) {
Ok(d) => {
log::trace!(target: "telemetry", "Re-dialing {}", self.addr);
socket = NodeSocket::Dialing(d);
},
Err(err) => {
log::warn!(target: "telemetry", "❌ Error while re-dialing {}: {:?}", self.addr, err);
socket = NodeSocket::wait_reconnect();
},
}
},
NodeSocket::WaitingReconnect(mut s) => {
if Future::poll(Pin::new(&mut s), cx).is_ready() {
Expand Down
2 changes: 1 addition & 1 deletion client/tracing/proc-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ proc-macro = true
proc-macro-crate = "1.1.3"
proc-macro2 = "1.0.37"
quote = { version = "1.0.10", features = ["proc-macro"] }
syn = { version = "1.0.82", features = ["proc-macro", "full", "extra-traits", "parsing"] }
syn = { version = "1.0.98", features = ["proc-macro", "full", "extra-traits", "parsing"] }
2 changes: 1 addition & 1 deletion frame/contracts/proc-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ proc-macro = true
[dependencies]
proc-macro2 = "1"
quote = "1"
syn = "1"
syn = "1.0.98"

[dev-dependencies]

Expand Down
86 changes: 84 additions & 2 deletions frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ where
)?;
}

// Every call or instantiate also optionally transferres balance.
// Every non delegate call or instantiate also optionally transfers the balance.
self.initial_transfer()?;

// Call into the wasm blob.
Expand Down Expand Up @@ -905,8 +905,14 @@ where
// The transfer as performed by a call or instantiate.
fn initial_transfer(&self) -> DispatchResult {
let frame = self.top_frame();
let value = frame.value_transferred;

// If it is a delegate call, then we've already transferred tokens in the
// last non-delegate frame.
if frame.delegate_caller.is_some() {
return Ok(())
}

let value = frame.value_transferred;
Self::transfer(ExistenceRequirement::KeepAlive, self.caller(), &frame.account_id, value)
}

Expand Down Expand Up @@ -1482,6 +1488,82 @@ mod tests {
});
}

#[test]
fn correct_transfer_on_call() {
let origin = ALICE;
let dest = BOB;
let value = 55;

let success_ch = MockLoader::insert(Call, move |ctx, _| {
assert_eq!(ctx.ext.value_transferred(), value);
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(Vec::new()) })
});

ExtBuilder::default().build().execute_with(|| {
let schedule = <Test as Config>::Schedule::get();
place_contract(&dest, success_ch);
set_balance(&origin, 100);
let balance = get_balance(&dest);
let mut storage_meter = storage::meter::Meter::new(&origin, Some(0), 55).unwrap();

let _ = MockStack::run_call(
origin.clone(),
dest.clone(),
&mut GasMeter::<Test>::new(GAS_LIMIT),
&mut storage_meter,
&schedule,
value,
vec![],
None,
)
.unwrap();

assert_eq!(get_balance(&origin), 100 - value);
assert_eq!(get_balance(&dest), balance + value);
});
}

#[test]
fn correct_transfer_on_delegate_call() {
let origin = ALICE;
let dest = BOB;
let value = 35;

let success_ch = MockLoader::insert(Call, move |ctx, _| {
assert_eq!(ctx.ext.value_transferred(), value);
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(Vec::new()) })
});

let delegate_ch = MockLoader::insert(Call, move |ctx, _| {
assert_eq!(ctx.ext.value_transferred(), value);
let _ = ctx.ext.delegate_call(success_ch, Vec::new())?;
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(Vec::new()) })
});

ExtBuilder::default().build().execute_with(|| {
let schedule = <Test as Config>::Schedule::get();
place_contract(&dest, delegate_ch);
set_balance(&origin, 100);
let balance = get_balance(&dest);
let mut storage_meter = storage::meter::Meter::new(&origin, Some(0), 55).unwrap();

let _ = MockStack::run_call(
origin.clone(),
dest.clone(),
&mut GasMeter::<Test>::new(GAS_LIMIT),
&mut storage_meter,
&schedule,
value,
vec![],
None,
)
.unwrap();

assert_eq!(get_balance(&origin), 100 - value);
assert_eq!(get_balance(&dest), balance + value);
});
}

#[test]
fn changes_are_reverted_on_failing_call() {
// This test verifies that changes are reverted on a call which fails (or equally, returns
Expand Down
2 changes: 1 addition & 1 deletion frame/election-provider-support/solution-type/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
proc-macro = true

[dependencies]
syn = { version = "1.0.82", features = ["full", "visit"] }
syn = { version = "1.0.98", features = ["full", "visit"] }
quote = "1.0"
proc-macro2 = "1.0.37"
proc-macro-crate = "1.1.3"
Expand Down
2 changes: 1 addition & 1 deletion frame/staking/reward-curve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ proc-macro = true
proc-macro-crate = "1.1.3"
proc-macro2 = "1.0.37"
quote = "1.0.10"
syn = { version = "1.0.82", features = ["full", "visit"] }
syn = { version = "1.0.98", features = ["full", "visit"] }

[dev-dependencies]
sp-runtime = { version = "6.0.0", path = "../../../primitives/runtime" }
2 changes: 1 addition & 1 deletion frame/support/procedural/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ proc-macro = true
Inflector = "0.11.4"
proc-macro2 = "1.0.37"
quote = "1.0.10"
syn = { version = "1.0.82", features = ["full"] }
syn = { version = "1.0.98", features = ["full"] }
frame-support-procedural-tools = { version = "4.0.0-dev", path = "./tools" }

[features]
Expand Down
Loading

0 comments on commit d29a53b

Please sign in to comment.