Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into na-remove-subxt-sub…
Browse files Browse the repository at this point in the history
…strate-compat-feature
  • Loading branch information
niklasad1 committed Feb 20, 2025
2 parents b9fe96f + 42e9de7 commit 754c5ff
Show file tree
Hide file tree
Showing 15 changed files with 1,004 additions and 494 deletions.
1,260 changes: 848 additions & 412 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ hyper-rustls = { version = "0.27.3", default-features = false, features = ["http
hyper-util = { version = "0.1.5", default-features = false }
impl-serde = { version = "0.5.0", default-features = false }
impl-trait-for-tuples = { version = "0.2.2" }
indexmap = { version = "2.0.0" }
indexmap = { version = "2.7.1" }
indicatif = { version = "0.17.7" }
integer-sqrt = { version = "0.1.2" }
ip_network = { version = "0.4.1" }
Expand Down Expand Up @@ -856,7 +856,7 @@ linked-hash-map = { version = "0.5.4" }
linked_hash_set = { version = "0.1.4" }
linregress = { version = "0.5.1" }
lite-json = { version = "0.2.0", default-features = false }
litep2p = { version = "0.9.0", features = ["websocket"] }
litep2p = { version = "0.9.1", features = ["websocket"] }
log = { version = "0.4.22", default-features = false }
macro_magic = { version = "0.5.1" }
maplit = { version = "1.0.2" }
Expand Down Expand Up @@ -1374,7 +1374,7 @@ tt-call = { version = "1.0.8" }
tuplex = { version = "0.1", default-features = false }
twox-hash = { version = "1.6.3", default-features = false }
unsigned-varint = { version = "0.7.2" }
url = { version = "2.4.0" }
url = { version = "2.5.4" }
void = { version = "1.0.2" }
w3f-bls = { version = "0.1.3", default-features = false }
wait-timeout = { version = "0.2" }
Expand Down
14 changes: 9 additions & 5 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2372,11 +2372,15 @@ impl_runtime_apis! {
{
use pallet_revive::tracing::trace;
let mut tracer = config.build(Revive::evm_gas_from_weight);
trace(&mut tracer, || {
Self::eth_transact(tx)
})?;

Ok(tracer.collect_traces().pop().expect("eth_transact succeeded, trace must exist, qed"))
let result = trace(&mut tracer, || Self::eth_transact(tx));

if let Some(trace) = tracer.collect_traces().pop() {
Ok(trace)
} else if let Err(err) = result {
Err(err)
} else {
Ok(Default::default())
}
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions prdoc/pr_7614.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
title: '[pallet-revive] tracing improvements'
doc:
- audience: Runtime Dev
description: |-
Various pallet-revive improvements

- add check for precompiles addresses,
So we can easily identified which one are being called and not supported yet

- fixes debug_call for revert call
If a call revert we still want to get the traces for that call, that matches geth behaviors, diff tests will be added to the test suite for this

- fixes traces for staticcall
The call type was not always being reported properly.
crates:
- name: asset-hub-westend-runtime
bump: minor
- name: pallet-revive-eth-rpc
bump: minor
- name: pallet-revive
bump: minor
25 changes: 25 additions & 0 deletions prdoc/pr_7640.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
title: Bring the latest compatibility fixes via litep2p v0.9.1

doc:
- audience: [Node Dev, Node Operator]
description: |
This release enhances compatibility between litep2p and libp2p by using the latest Yamux upstream version.
Additionally, it includes various improvements and fixes to boost the stability and performance of the WebSocket stream and the multistream-select protocol.

crates:
- name: sc-network
bump: minor
- name: cumulus-client-cli
bump: minor
- name: sc-network-types
bump: minor
- name: sc-transaction-pool-api
bump: minor
- name: sc-transaction-pool
bump: minor
- name: polkadot-statement-distribution
bump: minor
- name: polkadot-dispute-distribution
bump: minor
- name: cumulus-relay-chain-rpc-interface
bump: minor
14 changes: 9 additions & 5 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3745,11 +3745,15 @@ impl_runtime_apis! {
{
use pallet_revive::tracing::trace;
let mut tracer = config.build(Revive::evm_gas_from_weight);
trace(&mut tracer, || {
Self::eth_transact(tx)
})?;

Ok(tracer.collect_traces().pop().expect("eth_transact succeeded, trace must exist, qed"))
let result = trace(&mut tracer, || Self::eth_transact(tx));

if let Some(trace) = tracer.collect_traces().pop() {
Ok(trace)
} else if let Err(err) = result {
Err(err)
} else {
Ok(Default::default())
}
}
}

Expand Down
52 changes: 2 additions & 50 deletions substrate/client/network/src/litep2p/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use crate::{
},
},
peer_store::PeerStoreProvider,
protocol,
service::{
metrics::{register_without_sources, MetricSources, Metrics, NotificationMetrics},
out_events,
Expand Down Expand Up @@ -277,53 +276,6 @@ impl Litep2pNetworkBackend {
};
let config_builder = ConfigBuilder::new();

// The yamux buffer size limit is configured to be equal to the maximum frame size
// of all protocols. 10 bytes are added to each limit for the length prefix that
// is not included in the upper layer protocols limit but is still present in the
// yamux buffer. These 10 bytes correspond to the maximum size required to encode
// a variable-length-encoding 64bits number. In other words, we make the
// assumption that no notification larger than 2^64 will ever be sent.
let yamux_maximum_buffer_size = {
let requests_max = config
.request_response_protocols
.iter()
.map(|cfg| usize::try_from(cfg.max_request_size).unwrap_or(usize::MAX));
let responses_max = config
.request_response_protocols
.iter()
.map(|cfg| usize::try_from(cfg.max_response_size).unwrap_or(usize::MAX));
let notifs_max = config
.notification_protocols
.iter()
.map(|cfg| usize::try_from(cfg.max_notification_size()).unwrap_or(usize::MAX));

// A "default" max is added to cover all the other protocols: ping, identify,
// kademlia, block announces, and transactions.
let default_max = cmp::max(
1024 * 1024,
usize::try_from(protocol::BLOCK_ANNOUNCES_TRANSACTIONS_SUBSTREAM_SIZE)
.unwrap_or(usize::MAX),
);

iter::once(default_max)
.chain(requests_max)
.chain(responses_max)
.chain(notifs_max)
.max()
.expect("iterator known to always yield at least one element; qed")
.saturating_add(10)
};

let yamux_config = {
let mut yamux_config = litep2p::yamux::Config::default();
// Enable proper flow-control: window updates are only sent when
// buffered data has been consumed.
yamux_config.set_window_update_mode(litep2p::yamux::WindowUpdateMode::OnRead);
yamux_config.set_max_buffer_size(yamux_maximum_buffer_size);

yamux_config
};

let (tcp, websocket): (Vec<Option<_>>, Vec<Option<_>>) = config
.network_config
.listen_addresses
Expand Down Expand Up @@ -372,13 +324,13 @@ impl Litep2pNetworkBackend {
config_builder
.with_websocket(WebSocketTransportConfig {
listen_addresses: websocket.into_iter().flatten().map(Into::into).collect(),
yamux_config: yamux_config.clone(),
yamux_config: litep2p::yamux::Config::default(),
nodelay: true,
..Default::default()
})
.with_tcp(TcpTransportConfig {
listen_addresses: tcp.into_iter().flatten().map(Into::into).collect(),
yamux_config,
yamux_config: litep2p::yamux::Config::default(),
nodelay: true,
..Default::default()
})
Expand Down
5 changes: 0 additions & 5 deletions substrate/client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::{
protocol_controller::{self, SetId},
service::{metrics::NotificationMetrics, traits::Direction},
types::ProtocolName,
MAX_RESPONSE_SIZE,
};

use codec::Encode;
Expand Down Expand Up @@ -56,10 +55,6 @@ pub mod message;
// Log target for this file.
const LOG_TARGET: &str = "sub-libp2p";

/// Maximum size used for notifications in the block announce and transaction protocols.
// Must be equal to `max(MAX_BLOCK_ANNOUNCE_SIZE, MAX_TRANSACTIONS_SIZE)`.
pub(crate) const BLOCK_ANNOUNCES_TRANSACTIONS_SUBSTREAM_SIZE: u64 = MAX_RESPONSE_SIZE;

/// Identifier of the peerset for the block announces protocol.
const HARDCODED_PEERSETS_SYNC: SetId = SetId::from(0);

Expand Down
Binary file modified substrate/frame/revive/rpc/revive_chain.metadata
Binary file not shown.
3 changes: 2 additions & 1 deletion substrate/frame/revive/src/evm/api/debug_rpc_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ pub struct CallTrace<Gas = U256> {
#[serde(skip_serializing_if = "Vec::is_empty")]
pub logs: Vec<CallLog>,
/// Amount of value transferred.
pub value: U256,
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<U256>,
/// Type of call.
#[serde(rename = "type")]
pub call_type: CallType,
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/evm/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<Gas: Default, GasMapper: Fn(Weight) -> Gas> Tracer for CallTracer<Gas, GasM
self.traces.push(CallTrace {
from,
to,
value,
value: if is_read_only { None } else { Some(value) },
call_type,
input: input.to_vec().into(),
gas: (self.gas_mapper)(gas_left),
Expand Down
40 changes: 31 additions & 9 deletions substrate/frame/revive/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,13 @@ where
}
}

/// Determine if the given address is a precompile.
/// For now, we consider that all addresses between 0x1 and 0xff are reserved for precompiles.
fn is_precompile(address: &H160) -> bool {
let bytes = address.as_bytes();
bytes.starts_with(&[0u8; 19]) && bytes[19] != 0
}

impl<'a, T, E> Ext for Stack<'a, T, E>
where
T: Config,
Expand Down Expand Up @@ -1403,6 +1410,11 @@ where
*self.last_frame_output_mut() = Default::default();

let try_call = || {
if is_precompile(dest_addr) {
log::debug!(target: crate::LOG_TARGET, "Unsupported precompile address {dest_addr:?}");
return Err(Error::<T>::UnsupportedPrecompileAddress.into());
}

let dest = T::AddressMapper::to_account_id(dest_addr);
if !self.allows_reentry(&dest) {
return Err(<Error<T>>::ReentranceDenied.into());
Expand All @@ -1420,28 +1432,38 @@ where
CachedContract::Cached(contract) => Some(contract.clone()),
_ => None,
});

// Enable read-only access if requested; cannot disable it if already set.
let is_read_only = read_only || self.is_read_only();

if let Some(executable) = self.push_frame(
FrameArgs::Call { dest: dest.clone(), cached_info, delegated_call: None },
value,
gas_limit,
deposit_limit.saturated_into::<BalanceOf<T>>(),
// Enable read-only access if requested; cannot disable it if already set.
read_only || self.is_read_only(),
is_read_only,
)? {
self.run(executable, input_data)
} else {
let result = Self::transfer_from_origin(
&self.origin,
&Origin::from_account_id(self.account_id().clone()),
&dest,
value,
);
let result = if is_read_only && value.is_zero() {
Ok(Default::default())
} else if is_read_only {
Err(Error::<T>::StateChangeDenied.into())
} else {
Self::transfer_from_origin(
&self.origin,
&Origin::from_account_id(self.account_id().clone()),
&dest,
value,
)
};

if_tracing(|t| {
t.enter_child_span(
T::AddressMapper::to_address(self.account_id()),
T::AddressMapper::to_address(&dest),
false,
false,
is_read_only,
value,
&input_data,
Weight::zero(),
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@ pub mod pallet {
InvalidGenericTransaction,
/// The refcount of a code either over or underflowed.
RefcountOverOrUnderflow,
/// Unsupported precompile address
UnsupportedPrecompileAddress,
}

/// A reason for the pallet contracts placing a hold on funds.
Expand Down
5 changes: 4 additions & 1 deletion substrate/frame/revive/src/test_utils/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ builder!(

/// Build the instantiate call and unwrap the account id.
pub fn build_and_unwrap_contract(self) -> Contract<T> {
let addr = self.build().result.unwrap().addr;
let result = self.build().result.unwrap();
assert!(!result.result.did_revert(), "instantiation did revert");

let addr = result.addr;
let account_id = T::AddressMapper::to_account_id(&addr);
Contract{ account_id, addr }
}
Expand Down
Loading

0 comments on commit 754c5ff

Please sign in to comment.