Increase network limits (#2796)

Fix max packet sizes

Fix max_payload_size function

Add merge block test

Fix max size calculation; fix up test

Clear comments

Add a payload_size_function

Use safe arith for payload calculation

Return an error if block too big in block production

Separate test to check if block is over limit
This commit is contained in:
pawan
2021-11-09 10:42:02 -06:00
committed by Paul Hauner
parent afe59afacd
commit 44a7b37ce3
14 changed files with 268 additions and 46 deletions

View File

@@ -210,6 +210,11 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq +
Self::MaxTransactionsPerPayload::to_usize()
}
/// Returns the `MAX_EXTRA_DATA_BYTES` constant for this specification.
fn max_extra_data_bytes() -> usize {
Self::MaxExtraDataBytes::to_usize()
}
/// Returns the `BYTES_PER_LOGS_BLOOM` constant for this specification.
fn bytes_per_logs_bloom() -> usize {
Self::BytesPerLogsBloom::to_usize()

View File

@@ -1,5 +1,7 @@
use crate::{test_utils::TestRandom, *};
use safe_arith::{ArithError, SafeArith};
use serde_derive::{Deserialize, Serialize};
use ssz::Encode;
use ssz_derive::{Decode, Encode};
use test_random_derive::TestRandom;
use tree_hash_derive::TreeHash;
@@ -57,4 +59,51 @@ impl<T: EthSpec> ExecutionPayload<T> {
transactions: VariableList::empty(),
}
}
/// Returns the ssz size of `self`.
pub fn payload_size(&self) -> Result<usize, ArithError> {
let mut tx_size = ssz::BYTES_PER_LENGTH_OFFSET.safe_mul(self.transactions.len())?;
for tx in self.transactions.iter() {
tx_size.safe_add_assign(tx.len())?;
}
Self::empty()
.as_ssz_bytes()
.len()
.safe_add(<u8 as Encode>::ssz_fixed_len().safe_mul(self.extra_data.len())?)?
.safe_add(tx_size)
}
#[allow(clippy::integer_arithmetic)]
/// Returns the maximum size of an execution payload.
pub fn max_execution_payload_size() -> usize {
// Fixed part
Self::empty().as_ssz_bytes().len()
// Max size of variable length `extra_data` field
+ (T::max_extra_data_bytes() * <u8 as Encode>::ssz_fixed_len())
// Max size of variable length `transactions` field
+ (T::max_transactions_per_payload() * (ssz::BYTES_PER_LENGTH_OFFSET + T::max_bytes_per_transaction()))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_payload_size() {
let mut payload = ExecutionPayload::<crate::MainnetEthSpec>::empty();
assert_eq!(
payload.as_ssz_bytes().len(),
payload.payload_size().unwrap()
);
payload.extra_data = VariableList::from(vec![42; 16]);
payload.transactions = VariableList::from(vec![VariableList::from(vec![42; 42])]);
assert_eq!(
payload.as_ssz_bytes().len(),
payload.payload_size().unwrap()
);
}
}