Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(l1): move mempool from Store to Blockchain #2089

Merged
merged 26 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
878d920
add hex-literal to blockchain only for a test could be removed
LeanSerra Feb 25, 2025
7b5fbc8
move mempool functions from Store to new struct Mempool
LeanSerra Feb 25, 2025
c4fa7db
Merge branch 'main' into l1/move_mempool_from_store
LeanSerra Feb 25, 2025
08a4a49
fix missing argument for l2
LeanSerra Feb 26, 2025
c05fc05
remove arc from mempool
LeanSerra Feb 26, 2025
52271d6
pass blockchain as argument when using both store and mempool
LeanSerra Feb 26, 2025
906f68d
move basic mempool operations to blockchain struct, remove duplicate …
LeanSerra Feb 26, 2025
3df7183
Merge branch 'main' into l1/move_mempool_from_store
LeanSerra Feb 26, 2025
065e90f
remove hex-literal dependecy, change test to use hex::decode
LeanSerra Feb 26, 2025
99f43c4
move filter transaction functions to mempool struct
LeanSerra Feb 26, 2025
f02ad2d
add comment indicating that blockchain add_tx functions perform valid…
LeanSerra Feb 26, 2025
e375c39
move get_nonce function to mempool
LeanSerra Feb 26, 2025
d240452
fix using wrong filter function when broadcasting NewPooledTransactio…
LeanSerra Feb 26, 2025
35db6fe
pass both blockchain and store when needed for l2 stuff
LeanSerra Feb 27, 2025
fea985e
pass both blockchain and store when needed for connection.rs
LeanSerra Feb 27, 2025
8e61405
pass both blockchain and store when needed
LeanSerra Feb 27, 2025
43d02f1
add missing parameter for ethrex_p2p::start_network in dev mode
LeanSerra Feb 27, 2025
539af5c
change .blockchain.storage to .storage
LeanSerra Feb 27, 2025
7377508
change .blockchain.storage to .storage
LeanSerra Feb 27, 2025
308fab7
change .blockchain.storage to .storage
LeanSerra Feb 27, 2025
c3e7bdf
change .blockchain.storage to .storage
LeanSerra Feb 27, 2025
482e796
Merge branch 'main' into l1/move_mempool_from_store
LeanSerra Feb 27, 2025
f6c0715
pass blockchain as argument instead of mempool
LeanSerra Feb 27, 2025
36fa3aa
fix function call arguments
LeanSerra Feb 27, 2025
6fd0f21
Merge branch 'main' into l1/move_mempool_from_store
LeanSerra Feb 27, 2025
a19887a
change blockchain.storage to storage for tests
LeanSerra Feb 27, 2025
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions cmd/ethrex/ethrex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ async fn main() {
peer_table.clone(),
sync_mode,
cancel_token.clone(),
blockchain,
blockchain.clone(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we pass a blockchain reference instead of cloning? I would disable clone for a blockchain, since it's a singleton.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would mean adding an Arc and then cloning that Arc right? What we are doing right now is technically the same as the only field we are really cloning is the EVM both the store and mempool are internally arcs so when we clone them we are only cloning the references. I will still change it to Arc if thats what makes more sense.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, leave it as is then.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be tackled in a separate PR, moving blockchain to an Arc

);

// TODO: Check every module starts properly.
Expand Down Expand Up @@ -312,7 +312,7 @@ async fn main() {
let rpc_api = ethrex_rpc::start_api(
http_socket_addr,
authrpc_socket_addr,
store.clone(),
blockchain.clone(),
jwt_secret_clone,
local_p2p_node,
local_node_record,
Expand Down Expand Up @@ -348,7 +348,7 @@ async fn main() {
error!("Cannot run with DEV_MODE if the `l2` feature is enabled.");
panic!("Run without the --dev argument.");
}
let l2_proposer = ethrex_l2::start_proposer(store).into_future();
let l2_proposer = ethrex_l2::start_proposer(blockchain.clone()).into_future();
tracker.spawn(l2_proposer);
} else if #[cfg(feature = "dev")] {
use ethrex_dev;
Expand Down Expand Up @@ -385,7 +385,7 @@ async fn main() {
bootnodes,
signer,
peer_table.clone(),
store,
blockchain,
)
.await.expect("Network starts");
tracker.spawn(ethrex_p2p::periodically_show_peer_stats(peer_table.clone()));
Expand Down
1 change: 1 addition & 0 deletions crates/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ethrex-metrics = { path = "./metrics", default-features = false }
[dev-dependencies]
serde_json.workspace = true
hex = "0.4.3"
hex-literal.workspace = true

[lib]
path = "./blockchain.rs"
Expand Down
4 changes: 4 additions & 0 deletions crates/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use ethrex_common::types::{
BlockHeader, BlockNumber, ChainConfig, EIP4844Transaction, Receipt, Transaction,
};
use ethrex_common::H256;
use mempool::Mempool;
use std::{ops::Div, time::Instant};

use ethrex_storage::error::StoreError;
Expand All @@ -31,20 +32,23 @@ use tracing::{error, info, warn};
pub struct Blockchain {
pub vm: EVM,
pub storage: Store,
pub mempool: Mempool,
}

impl Blockchain {
pub fn new(evm: EVM, store: Store) -> Self {
Self {
vm: evm,
storage: store,
mempool: Mempool::new(),
}
}

pub fn default_with_store(store: Store) -> Self {
Self {
vm: Default::default(),
storage: store,
mempool: Mempool::new(),
}
}

Expand Down
Loading
Loading