@@ -48,6 +48,7 @@ use ethrex_metrics::metrics_blocks::METRICS_BLOCKS;
48
48
use ethrex_common:: types:: BlobsBundle ;
49
49
50
50
const MAX_PAYLOADS : usize = 10 ;
51
+ const MAX_MEMPOOL_SIZE_DEFAULT : usize = 10_000 ;
51
52
52
53
//TODO: Implement a struct Chain or BlockChain to encapsulate
53
54
//functionality and canonical chain state and config
@@ -67,14 +68,30 @@ pub struct Blockchain {
67
68
/// This will be set to true once the initial sync has taken place and wont be set to false after
68
69
/// This does not reflect whether there is an ongoing sync process
69
70
is_synced : AtomicBool ,
70
- /// Whether performance logs should be emitted
71
- pub perf_logs_enabled : bool ,
72
- pub r#type : BlockchainType ,
71
+ pub options : BlockchainOptions ,
73
72
/// Mapping from a payload id to either a complete payload or a payload build task
74
73
/// We need to keep completed payloads around in case consensus requests them twice
75
74
pub payloads : Arc < TokioMutex < Vec < ( u64 , PayloadOrTask ) > > > ,
76
75
}
77
76
77
+ #[ derive( Debug , Clone ) ]
78
+ pub struct BlockchainOptions {
79
+ pub max_mempool_size : usize ,
80
+ /// Whether performance logs should be emitted
81
+ pub perf_logs_enabled : bool ,
82
+ pub r#type : BlockchainType ,
83
+ }
84
+
85
+ impl Default for BlockchainOptions {
86
+ fn default ( ) -> Self {
87
+ Self {
88
+ max_mempool_size : MAX_MEMPOOL_SIZE_DEFAULT ,
89
+ perf_logs_enabled : false ,
90
+ r#type : BlockchainType :: default ( ) ,
91
+ }
92
+ }
93
+ }
94
+
78
95
#[ derive( Debug , Clone ) ]
79
96
pub struct BatchBlockProcessingFailure {
80
97
pub last_valid_hash : H256 ,
@@ -94,25 +111,23 @@ fn log_batch_progress(batch_size: u32, current_block: u32) {
94
111
}
95
112
96
113
impl Blockchain {
97
- pub fn new ( store : Store , blockchain_type : BlockchainType , perf_logs_enabled : bool ) -> Self {
114
+ pub fn new ( store : Store , blockchain_opts : BlockchainOptions ) -> Self {
98
115
Self {
99
116
storage : store,
100
- mempool : Mempool :: new ( ) ,
117
+ mempool : Mempool :: new ( blockchain_opts . max_mempool_size ) ,
101
118
is_synced : AtomicBool :: new ( false ) ,
102
- r#type : blockchain_type,
103
119
payloads : Arc :: new ( TokioMutex :: new ( Vec :: new ( ) ) ) ,
104
- perf_logs_enabled ,
120
+ options : blockchain_opts ,
105
121
}
106
122
}
107
123
108
124
pub fn default_with_store ( store : Store ) -> Self {
109
125
Self {
110
126
storage : store,
111
- mempool : Mempool :: new ( ) ,
127
+ mempool : Mempool :: new ( MAX_MEMPOOL_SIZE_DEFAULT ) ,
112
128
is_synced : AtomicBool :: new ( false ) ,
113
- r#type : BlockchainType :: default ( ) ,
114
129
payloads : Arc :: new ( TokioMutex :: new ( Vec :: new ( ) ) ) ,
115
- perf_logs_enabled : false ,
130
+ options : BlockchainOptions :: default ( ) ,
116
131
}
117
132
}
118
133
@@ -204,7 +219,7 @@ impl Blockchain {
204
219
let vm_db: DynVmDatabase =
205
220
Box :: new ( StoreVmDatabase :: new ( self . storage . clone ( ) , parent_hash) ) ;
206
221
let logger = Arc :: new ( DatabaseLogger :: new ( Arc :: new ( Mutex :: new ( Box :: new ( vm_db) ) ) ) ) ;
207
- let mut vm = match self . r#type {
222
+ let mut vm = match self . options . r#type {
208
223
BlockchainType :: L1 => Evm :: new_from_db_for_l1 ( logger. clone ( ) ) ,
209
224
BlockchainType :: L2 => Evm :: new_from_db_for_l2 ( logger. clone ( ) ) ,
210
225
} ;
@@ -422,7 +437,7 @@ impl Blockchain {
422
437
let result = self . store_block ( block, account_updates_list, res) . await ;
423
438
let stored = Instant :: now ( ) ;
424
439
425
- if self . perf_logs_enabled {
440
+ if self . options . perf_logs_enabled {
426
441
Self :: print_add_block_logs ( block, since, executed, merkleized, stored) ;
427
442
}
428
443
result
@@ -613,7 +628,7 @@ impl Blockchain {
613
628
METRICS_BLOCKS . set_latest_gigagas( throughput) ;
614
629
) ;
615
630
616
- if self . perf_logs_enabled {
631
+ if self . options . perf_logs_enabled {
617
632
info ! (
618
633
"[METRICS] Executed and stored: Range: {}, Last block num: {}, Last block gas limit: {}, Total transactions: {}, Total Gas: {}, Throughput: {} Gigagas/s" ,
619
634
blocks_len,
@@ -883,7 +898,7 @@ impl Blockchain {
883
898
}
884
899
885
900
pub fn new_evm ( & self , vm_db : StoreVmDatabase ) -> Result < Evm , EvmError > {
886
- let evm = match self . r#type {
901
+ let evm = match self . options . r#type {
887
902
BlockchainType :: L1 => Evm :: new_for_l1 ( vm_db) ,
888
903
BlockchainType :: L2 => Evm :: new_for_l2 ( vm_db) ?,
889
904
} ;
0 commit comments