Skip to content

Commit 53ea58b

Browse files
authored
feat: limit rollup fee in tx pool (#316)
* feat: limit rollup fee in tx pool Signed-off-by: Gregory Edison <[email protected]> * fix: check rollup fee Signed-off-by: Gregory Edison <[email protected]> * feat: limit pool tx size (#317) * feat: add maxTxPayloadBytesPerBlock to ScrollChainConfig Signed-off-by: Gregory Edison <[email protected]> * feat: limit pool max tx input bytes Signed-off-by: Gregory Edison <[email protected]> * test: set max_tx_payload_bytes_per_block Signed-off-by: Gregory Edison <[email protected]> * feat: make MockEthProvider more generic Signed-off-by: Gregory Edison <[email protected]> * test: add pool limit tests Signed-off-by: Gregory Edison <[email protected]> * fix: lints Signed-off-by: Gregory Edison <[email protected]> --------- Signed-off-by: Gregory Edison <[email protected]> * test: update Signed-off-by: Gregory Edison <[email protected]> --------- Signed-off-by: Gregory Edison <[email protected]>
1 parent 85a5d1d commit 53ea58b

File tree

11 files changed

+394
-121
lines changed

11 files changed

+394
-121
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/scroll/chainspec/src/constants.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use alloy_primitives::{address, b256, Address, B256};
55
/// The transaction fee recipient on the L2.
66
pub const SCROLL_FEE_VAULT_ADDRESS: Address = address!("5300000000000000000000000000000000000005");
77

8+
/// The maximum size in bytes of the payload for a block.
9+
pub const MAX_TX_PAYLOAD_BYTES_PER_BLOCK: usize = 120 * 1024;
10+
811
/// The system contract on L2 mainnet.
912
pub const SCROLL_MAINNET_L2_SYSTEM_CONFIG_CONTRACT_ADDRESS: Address =
1013
address!("331A873a2a85219863d80d248F9e2978fE88D0Ea");

crates/scroll/chainspec/src/genesis.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
//! Scroll types for genesis data.
22
33
use crate::{
4-
constants::{SCROLL_FEE_VAULT_ADDRESS, SCROLL_MAINNET_L1_CONFIG, SCROLL_SEPOLIA_L1_CONFIG},
4+
constants::{
5+
MAX_TX_PAYLOAD_BYTES_PER_BLOCK, SCROLL_FEE_VAULT_ADDRESS, SCROLL_MAINNET_L1_CONFIG,
6+
SCROLL_SEPOLIA_L1_CONFIG,
7+
},
58
SCROLL_DEV_L1_CONFIG,
69
};
10+
711
use alloy_primitives::Address;
812
use alloy_serde::OtherFields;
913
use serde::de::Error;
@@ -113,6 +117,8 @@ pub struct ScrollChainConfig {
113117
/// This is an optional field that, when set, specifies where L2 transaction fees
114118
/// will be sent or stored.
115119
pub fee_vault_address: Option<Address>,
120+
/// The maximum tx payload size of blocks that we produce.
121+
pub max_tx_payload_bytes_per_block: usize,
116122
/// The L1 configuration.
117123
/// This field encapsulates specific settings and parameters required for L1
118124
pub l1_config: L1Config,
@@ -129,6 +135,7 @@ impl ScrollChainConfig {
129135
pub const fn mainnet() -> Self {
130136
Self {
131137
fee_vault_address: Some(SCROLL_FEE_VAULT_ADDRESS),
138+
max_tx_payload_bytes_per_block: MAX_TX_PAYLOAD_BYTES_PER_BLOCK,
132139
l1_config: SCROLL_MAINNET_L1_CONFIG,
133140
}
134141
}
@@ -137,13 +144,18 @@ impl ScrollChainConfig {
137144
pub const fn sepolia() -> Self {
138145
Self {
139146
fee_vault_address: Some(SCROLL_FEE_VAULT_ADDRESS),
147+
max_tx_payload_bytes_per_block: MAX_TX_PAYLOAD_BYTES_PER_BLOCK,
140148
l1_config: SCROLL_SEPOLIA_L1_CONFIG,
141149
}
142150
}
143151

144152
/// Returns the [`ScrollChainConfig`] for Scroll dev.
145153
pub const fn dev() -> Self {
146-
Self { fee_vault_address: Some(SCROLL_FEE_VAULT_ADDRESS), l1_config: SCROLL_DEV_L1_CONFIG }
154+
Self {
155+
fee_vault_address: Some(SCROLL_FEE_VAULT_ADDRESS),
156+
max_tx_payload_bytes_per_block: MAX_TX_PAYLOAD_BYTES_PER_BLOCK,
157+
l1_config: SCROLL_DEV_L1_CONFIG,
158+
}
147159
}
148160
}
149161

@@ -209,6 +221,7 @@ mod tests {
209221
"feynmanTime": 100,
210222
"scroll": {
211223
"feeVaultAddress": "0x5300000000000000000000000000000000000005",
224+
"maxTxPayloadBytesPerBlock": 122880,
212225
"l1Config": {
213226
"l1ChainId": 1,
214227
"l1MessageQueueAddress": "0x0d7E906BD9cAFa154b048cFa766Cc1E54E39AF9B",
@@ -237,6 +250,7 @@ mod tests {
237250
}),
238251
scroll_chain_config: ScrollChainConfig {
239252
fee_vault_address: Some(address!("5300000000000000000000000000000000000005")),
253+
max_tx_payload_bytes_per_block: MAX_TX_PAYLOAD_BYTES_PER_BLOCK,
240254
l1_config: L1Config {
241255
l1_chain_id: 1,
242256
l1_message_queue_address: address!("0d7E906BD9cAFa154b048cFa766Cc1E54E39AF9B"),

crates/scroll/chainspec/src/lib.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ extern crate alloc;
3535

3636
mod constants;
3737
pub use constants::{
38-
SCROLL_BASE_FEE_PARAMS_FEYNMAN, SCROLL_DEV_L1_CONFIG, SCROLL_DEV_L1_MESSAGE_QUEUE_ADDRESS,
39-
SCROLL_DEV_L1_MESSAGE_QUEUE_V2_ADDRESS, SCROLL_DEV_L1_PROXY_ADDRESS,
40-
SCROLL_DEV_L2_SYSTEM_CONFIG_CONTRACT_ADDRESS, SCROLL_DEV_MAX_L1_MESSAGES,
41-
SCROLL_EIP1559_BASE_FEE_MAX_CHANGE_DENOMINATOR_FEYNMAN,
38+
MAX_TX_PAYLOAD_BYTES_PER_BLOCK, SCROLL_BASE_FEE_PARAMS_FEYNMAN, SCROLL_DEV_L1_CONFIG,
39+
SCROLL_DEV_L1_MESSAGE_QUEUE_ADDRESS, SCROLL_DEV_L1_MESSAGE_QUEUE_V2_ADDRESS,
40+
SCROLL_DEV_L1_PROXY_ADDRESS, SCROLL_DEV_L2_SYSTEM_CONFIG_CONTRACT_ADDRESS,
41+
SCROLL_DEV_MAX_L1_MESSAGES, SCROLL_EIP1559_BASE_FEE_MAX_CHANGE_DENOMINATOR_FEYNMAN,
4242
SCROLL_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER_FEYNMAN, SCROLL_FEE_VAULT_ADDRESS,
4343
SCROLL_MAINNET_GENESIS_HASH, SCROLL_MAINNET_L1_CONFIG, SCROLL_MAINNET_L1_MESSAGE_QUEUE_ADDRESS,
4444
SCROLL_MAINNET_L1_MESSAGE_QUEUE_V2_ADDRESS, SCROLL_MAINNET_L1_PROXY_ADDRESS,
@@ -653,26 +653,26 @@ mod tests {
653653
#[test]
654654
fn parse_scroll_hardforks() {
655655
let geth_genesis = r#"
656-
{
657-
"config": {
658-
"bernoulliBlock": 10,
659-
"curieBlock": 20,
660-
"darwinTime": 30,
661-
"darwinV2Time": 31,
662-
"scroll": {
663-
"feeVaultAddress": "0x5300000000000000000000000000000000000005",
664-
"l1Config": {
665-
"l1ChainId": 1,
666-
"l1MessageQueueAddress": "0x0d7E906BD9cAFa154b048cFa766Cc1E54E39AF9B",
667-
"l1MessageQueueV2Address": "0x56971da63A3C0205184FEF096E9ddFc7A8C2D18a",
668-
"l2SystemConfigAddress": "0x331A873a2a85219863d80d248F9e2978fE88D0Ea",
669-
"scrollChainAddress": "0xa13BAF47339d63B743e7Da8741db5456DAc1E556",
670-
"numL1MessagesPerBlock": 10
656+
{
657+
"config": {
658+
"bernoulliBlock": 10,
659+
"curieBlock": 20,
660+
"darwinTime": 30,
661+
"darwinV2Time": 31,
662+
"scroll": {
663+
"feeVaultAddress": "0x5300000000000000000000000000000000000005",
664+
"maxTxPayloadBytesPerBlock": 122880,
665+
"l1Config": {
666+
"l1ChainId": 1,
667+
"l1MessageQueueAddress": "0x0d7E906BD9cAFa154b048cFa766Cc1E54E39AF9B",
668+
"l1MessageQueueV2Address": "0x56971da63A3C0205184FEF096E9ddFc7A8C2D18a",
669+
"l2SystemConfigAddress": "0x331A873a2a85219863d80d248F9e2978fE88D0Ea",
670+
"scrollChainAddress": "0xa13BAF47339d63B743e7Da8741db5456DAc1E556",
671+
"numL1MessagesPerBlock": 10
672+
}
673+
}
671674
}
672-
}
673-
}
674-
}
675-
"#;
675+
}"#;
676676
let genesis: Genesis = serde_json::from_str(geth_genesis).unwrap();
677677

678678
let actual_bernoulli_block = genesis.config.extra_fields.get("bernoulliBlock");
@@ -688,6 +688,7 @@ mod tests {
688688
scroll_object,
689689
&serde_json::json!({
690690
"feeVaultAddress": "0x5300000000000000000000000000000000000005",
691+
"maxTxPayloadBytesPerBlock": 122880,
691692
"l1Config": {
692693
"l1ChainId": 1,
693694
"l1MessageQueueAddress": "0x0d7E906BD9cAFa154b048cFa766Cc1E54E39AF9B",
@@ -741,6 +742,7 @@ mod tests {
741742
String::from("scroll"),
742743
serde_json::json!({
743744
"feeVaultAddress": "0x5300000000000000000000000000000000000005",
745+
"maxTxPayloadBytesPerBlock": 122880,
744746
"l1Config": {
745747
"l1ChainId": 1,
746748
"l1MessageQueueAddress": "0x0d7E906BD9cAFa154b048cFa766Cc1E54E39AF9B",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
use alloy_primitives::U256;
2+
3+
/// The maximum value Rollup fee.
4+
pub const MAX_ROLLUP_FEE: U256 = U256::from_limbs([u64::MAX, 0, 0, 0]);

crates/scroll/consensus/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
33
extern crate alloc;
44

5+
mod constants;
6+
pub use constants::MAX_ROLLUP_FEE;
7+
58
mod error;
69
pub use error::ScrollConsensusError;
710

811
mod validation;
9-
1012
pub use validation::ScrollBeaconConsensus;

0 commit comments

Comments
 (0)