Skip to content
Merged
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
12 changes: 12 additions & 0 deletions prdoc/pr_10047.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
title: 'pallet_revive: Increase event sizes'
doc:
- audience: Runtime User
description: |-
Fixes https://github.com/paritytech/contract-issues/issues/140

This increases the maximum event payload size from 416 bytes to 64k. Since https://github.com/paritytech/polkadot-sdk/pull/9418 we charge some additional weight per byte of event payload. This makes it possible to raise the limit while staying within our memory envelope. This artificial weight will add 18us of weight to a maximum sized event.
crates:
- name: pallet-revive-fixtures
bump: patch
- name: pallet-revive
bump: patch
2 changes: 1 addition & 1 deletion substrate/frame/revive/fixtures/contracts/event_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include!("../panic_handler.rs");

use uapi::{input, HostFn, HostFnImpl as api};

static BUFFER: [u8; 16 * 1024 + 1] = [0u8; 16 * 1024 + 1];
static BUFFER: [u8; 64 * 1024 + 1] = [0u8; 64 * 1024 + 1];

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down
48 changes: 24 additions & 24 deletions substrate/frame/revive/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ mod benchmarks {
#[benchmark(skip_meta, pov_mode = Measured)]
fn on_initialize_per_trie_key(k: Linear<0, 1024>) -> Result<(), BenchmarkError> {
let instance =
Contract::<T>::with_storage(VmBinaryModule::dummy(), k, limits::PAYLOAD_BYTES)?;
Contract::<T>::with_storage(VmBinaryModule::dummy(), k, limits::STORAGE_BYTES)?;
instance.info()?.queue_trie_for_deletion();

#[block]
Expand Down Expand Up @@ -1233,7 +1233,7 @@ mod benchmarks {
#[benchmark(pov_mode = Measured)]
fn seal_deposit_event(
t: Linear<0, { limits::NUM_EVENT_TOPICS as u32 }>,
n: Linear<0, { limits::PAYLOAD_BYTES }>,
n: Linear<0, { limits::EVENT_BYTES }>,
) {
let num_topic = t as u32;
let topics = (0..t).map(|i| H256::repeat_byte(i as u8)).collect::<Vec<_>>();
Expand Down Expand Up @@ -1268,7 +1268,7 @@ mod benchmarks {
fn get_storage_empty() -> Result<(), BenchmarkError> {
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = vec![0u8; max_key_len as usize];
let max_value_len = limits::PAYLOAD_BYTES as usize;
let max_value_len = limits::STORAGE_BYTES as usize;
let value = vec![1u8; max_value_len];

let instance = Contract::<T>::new(VmBinaryModule::dummy(), vec![])?;
Expand All @@ -1291,7 +1291,7 @@ mod benchmarks {
fn get_storage_full() -> Result<(), BenchmarkError> {
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = vec![0u8; max_key_len as usize];
let max_value_len = limits::PAYLOAD_BYTES;
let max_value_len = limits::STORAGE_BYTES;
let value = vec![1u8; max_value_len as usize];

let instance = Contract::<T>::with_unbalanced_storage_trie(VmBinaryModule::dummy(), &key)?;
Expand All @@ -1314,7 +1314,7 @@ mod benchmarks {
fn set_storage_empty() -> Result<(), BenchmarkError> {
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = vec![0u8; max_key_len as usize];
let max_value_len = limits::PAYLOAD_BYTES as usize;
let max_value_len = limits::STORAGE_BYTES as usize;
let value = vec![1u8; max_value_len];

let instance = Contract::<T>::new(VmBinaryModule::dummy(), vec![])?;
Expand All @@ -1339,7 +1339,7 @@ mod benchmarks {
fn set_storage_full() -> Result<(), BenchmarkError> {
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = vec![0u8; max_key_len as usize];
let max_value_len = limits::PAYLOAD_BYTES;
let max_value_len = limits::STORAGE_BYTES;
let value = vec![1u8; max_value_len as usize];

let instance = Contract::<T>::with_unbalanced_storage_trie(VmBinaryModule::dummy(), &key)?;
Expand All @@ -1364,8 +1364,8 @@ mod benchmarks {
// o: old byte size
#[benchmark(skip_meta, pov_mode = Measured)]
fn seal_set_storage(
n: Linear<0, { limits::PAYLOAD_BYTES }>,
o: Linear<0, { limits::PAYLOAD_BYTES }>,
n: Linear<0, { limits::STORAGE_BYTES }>,
o: Linear<0, { limits::STORAGE_BYTES }>,
) -> Result<(), BenchmarkError> {
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![0u8; max_key_len as usize])
Expand Down Expand Up @@ -1397,7 +1397,7 @@ mod benchmarks {
}

#[benchmark(skip_meta, pov_mode = Measured)]
fn clear_storage(n: Linear<0, { limits::PAYLOAD_BYTES }>) -> Result<(), BenchmarkError> {
fn clear_storage(n: Linear<0, { limits::STORAGE_BYTES }>) -> Result<(), BenchmarkError> {
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![0u8; max_key_len as usize])
.map_err(|_| "Key has wrong length")?;
Expand Down Expand Up @@ -1430,7 +1430,7 @@ mod benchmarks {
}

#[benchmark(skip_meta, pov_mode = Measured)]
fn seal_get_storage(n: Linear<0, { limits::PAYLOAD_BYTES }>) -> Result<(), BenchmarkError> {
fn seal_get_storage(n: Linear<0, { limits::STORAGE_BYTES }>) -> Result<(), BenchmarkError> {
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![0u8; max_key_len as usize])
.map_err(|_| "Key has wrong length")?;
Expand Down Expand Up @@ -1460,7 +1460,7 @@ mod benchmarks {
}

#[benchmark(skip_meta, pov_mode = Measured)]
fn contains_storage(n: Linear<0, { limits::PAYLOAD_BYTES }>) -> Result<(), BenchmarkError> {
fn contains_storage(n: Linear<0, { limits::STORAGE_BYTES }>) -> Result<(), BenchmarkError> {
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![0u8; max_key_len as usize])
.map_err(|_| "Key has wrong length")?;
Expand Down Expand Up @@ -1492,7 +1492,7 @@ mod benchmarks {
}

#[benchmark(skip_meta, pov_mode = Measured)]
fn take_storage(n: Linear<0, { limits::PAYLOAD_BYTES }>) -> Result<(), BenchmarkError> {
fn take_storage(n: Linear<0, { limits::STORAGE_BYTES }>) -> Result<(), BenchmarkError> {
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![3u8; max_key_len as usize])
.map_err(|_| "Key has wrong length")?;
Expand Down Expand Up @@ -1530,7 +1530,7 @@ mod benchmarks {
// complexity can introduce approximation errors.
#[benchmark(pov_mode = Ignored)]
fn set_transient_storage_empty() -> Result<(), BenchmarkError> {
let max_value_len = limits::PAYLOAD_BYTES;
let max_value_len = limits::STORAGE_BYTES;
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![0u8; max_key_len as usize])
.map_err(|_| "Key has wrong length")?;
Expand All @@ -1552,7 +1552,7 @@ mod benchmarks {

#[benchmark(pov_mode = Ignored)]
fn set_transient_storage_full() -> Result<(), BenchmarkError> {
let max_value_len = limits::PAYLOAD_BYTES;
let max_value_len = limits::STORAGE_BYTES;
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![0u8; max_key_len as usize])
.map_err(|_| "Key has wrong length")?;
Expand All @@ -1575,7 +1575,7 @@ mod benchmarks {

#[benchmark(pov_mode = Ignored)]
fn get_transient_storage_empty() -> Result<(), BenchmarkError> {
let max_value_len = limits::PAYLOAD_BYTES;
let max_value_len = limits::STORAGE_BYTES;
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![0u8; max_key_len as usize])
.map_err(|_| "Key has wrong length")?;
Expand All @@ -1600,7 +1600,7 @@ mod benchmarks {

#[benchmark(pov_mode = Ignored)]
fn get_transient_storage_full() -> Result<(), BenchmarkError> {
let max_value_len = limits::PAYLOAD_BYTES;
let max_value_len = limits::STORAGE_BYTES;
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![0u8; max_key_len as usize])
.map_err(|_| "Key has wrong length")?;
Expand All @@ -1627,7 +1627,7 @@ mod benchmarks {
// The weight of journal rollbacks should be taken into account when setting storage.
#[benchmark(pov_mode = Ignored)]
fn rollback_transient_storage() -> Result<(), BenchmarkError> {
let max_value_len = limits::PAYLOAD_BYTES;
let max_value_len = limits::STORAGE_BYTES;
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![0u8; max_key_len as usize])
.map_err(|_| "Key has wrong length")?;
Expand Down Expand Up @@ -1655,8 +1655,8 @@ mod benchmarks {
// o: old byte size
#[benchmark(pov_mode = Measured)]
fn seal_set_transient_storage(
n: Linear<0, { limits::PAYLOAD_BYTES }>,
o: Linear<0, { limits::PAYLOAD_BYTES }>,
n: Linear<0, { limits::STORAGE_BYTES }>,
o: Linear<0, { limits::STORAGE_BYTES }>,
) -> Result<(), BenchmarkError> {
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![0u8; max_key_len as usize])
Expand Down Expand Up @@ -1689,7 +1689,7 @@ mod benchmarks {

#[benchmark(pov_mode = Measured)]
fn seal_clear_transient_storage(
n: Linear<0, { limits::PAYLOAD_BYTES }>,
n: Linear<0, { limits::STORAGE_BYTES }>,
) -> Result<(), BenchmarkError> {
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![0u8; max_key_len as usize])
Expand Down Expand Up @@ -1723,7 +1723,7 @@ mod benchmarks {

#[benchmark(pov_mode = Measured)]
fn seal_get_transient_storage(
n: Linear<0, { limits::PAYLOAD_BYTES }>,
n: Linear<0, { limits::STORAGE_BYTES }>,
) -> Result<(), BenchmarkError> {
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![0u8; max_key_len as usize])
Expand Down Expand Up @@ -1759,7 +1759,7 @@ mod benchmarks {

#[benchmark(pov_mode = Measured)]
fn seal_contains_transient_storage(
n: Linear<0, { limits::PAYLOAD_BYTES }>,
n: Linear<0, { limits::STORAGE_BYTES }>,
) -> Result<(), BenchmarkError> {
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![0u8; max_key_len as usize])
Expand Down Expand Up @@ -1794,9 +1794,9 @@ mod benchmarks {

#[benchmark(pov_mode = Measured)]
fn seal_take_transient_storage(
n: Linear<0, { limits::PAYLOAD_BYTES }>,
n: Linear<0, { limits::STORAGE_BYTES }>,
) -> Result<(), BenchmarkError> {
let n = limits::PAYLOAD_BYTES;
let n = limits::STORAGE_BYTES;
let value = vec![42u8; n as usize];
let max_key_len = limits::STORAGE_KEY_BYTES;
let key = Key::try_from_var(vec![0u8; max_key_len as usize])
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/call_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ where
return Err("Key size too small to create the specified trie");
}

let value = vec![16u8; limits::PAYLOAD_BYTES as usize];
let value = vec![16u8; limits::STORAGE_BYTES as usize];
let contract = Contract::<T>::new(code, vec![])?;
let info = contract.info()?;
let child_trie_info = info.child_trie_info();
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/evm/block_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub fn process_transaction<T: Config>(
// `EthereumBlockBuilder = 3 * (max size of transactions + max size of receipts)`
// The maximum size of a transaction is limited by
// `limits::MAX_TRANSACTION_PAYLOAD_SIZE`, while the maximum size of a receipt is
// limited by `limits::PAYLOAD_BYTES`.
// limited by `limits::EVENT_BYTES`.
//
// Similarly, this is the amount of pallet storage consumed by the
// `EthereumBlockBuilderIR` object, plus a marginal book-keeping overhead.
Expand Down
7 changes: 0 additions & 7 deletions substrate/frame/revive/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,6 @@ pub trait PrecompileExt: sealing::Sealed {
/// Returns the chain id.
fn chain_id(&self) -> u64;

/// Returns the maximum allowed size of a storage item.
fn max_value_size(&self) -> u32;

/// Get an immutable reference to the nested gas meter.
fn gas_meter(&self) -> &GasMeter<Self::T>;

Expand Down Expand Up @@ -2130,10 +2127,6 @@ where
<T as Config>::ChainId::get()
}

fn max_value_size(&self) -> u32 {
limits::PAYLOAD_BYTES
}

fn gas_meter(&self) -> &GasMeter<Self::T> {
&self.top_frame().nested_gas
}
Expand Down
4 changes: 0 additions & 4 deletions substrate/frame/revive/src/exec/mock_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ impl<T: Config> PrecompileExt for MockExt<T> {
panic!("MockExt::chain_id")
}

fn max_value_size(&self) -> u32 {
panic!("MockExt::max_value_size")
}

fn gas_meter(&self) -> &GasMeter<Self::T> {
&self.gas_meter
}
Expand Down
Loading
Loading