-
Notifications
You must be signed in to change notification settings - Fork 62
feat(l1): properly calculate enr
sequence field
#2679
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
Merged
Merged
Changes from 39 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
d97afae
Change struct name
mechanix97 a2c8f49
add store config file
mechanix97 bb26b62
read config file
mechanix97 bc8968b
remove clone
mechanix97 53acf85
chane info msg
mechanix97 2a46284
refactor P2Pcontext
mechanix97 6da35d7
Add mutex node record
mechanix97 2a57cb5
add seq to save
mechanix97 6d1152e
try fix test
mechanix97 bda131d
fix tests
mechanix97 e18bf60
fix clippy
mechanix97 8f7072c
fix clippy now
mechanix97 a130f43
change seq to 1
mechanix97 d0474ce
Fix test
mechanix97 875cc2c
Fix l2 clippy
mechanix97 97423da
Merge branch 'main' into feat/properly-calculate-enr-seq
mechanix97 1f787b9
Merge branch 'main' into feat/properly-calculate-enr-seq
mechanix97 b647c08
Merge branch 'main' into feat/properly-calculate-enr-seq
mechanix97 0893f60
Fix initilizer 0 to 1
mechanix97 29ea80c
Remove arc mutex
mechanix97 c0fe29d
Merge branch 'main' into feat/properly-calculate-enr-seq
mechanix97 bc8275d
fix l2
mechanix97 98a1f77
Merge branch 'feat/properly-calculate-enr-seq' of github.com:lambdacl…
mechanix97 5e0cf28
fix clippy l2
mechanix97 dec4aae
Merge branch 'main' into feat/properly-calculate-enr-seq
mechanix97 fe799c0
Remove arc from RPC
mechanix97 d4d7f46
Merge branch 'main' into feat/properly-calculate-enr-seq
mechanix97 115ad7c
Update node record when opening config file
mechanix97 eb08378
Merge branch 'feat/properly-calculate-enr-seq' of github.com:lambdacl…
mechanix97 a1aaf58
fix lint
mechanix97 f98b056
fix lint l2
mechanix97 f4b0bf1
Update seq properly
mechanix97 987c540
Merge branch 'main' into feat/properly-calculate-enr-seq
mechanix97 736e046
fix clippy
mechanix97 751dff6
Merge branch 'main' into feat/properly-calculate-enr-seq
mechanix97 cc197ab
Merge branch 'main' into feat/properly-calculate-enr-seq
mechanix97 ff25b47
Use timestamp as default seq
mechanix97 c7609bc
Fix l2
mechanix97 6bd37b7
Remove async/await
mechanix97 81d887a
Merge branch 'main' into feat/properly-calculate-enr-seq
mechanix97 5ea5708
Merge branch 'main' into feat/properly-calculate-enr-seq
mechanix97 aced208
Fix typo
mechanix97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,17 @@ use crate::decode; | |
use bytes::Bytes; | ||
use directories::ProjectDirs; | ||
use ethrex_common::types::{Block, Genesis}; | ||
use ethrex_p2p::{kademlia::KademliaTable, sync::SyncMode, types::Node}; | ||
use ethrex_p2p::{ | ||
kademlia::KademliaTable, | ||
sync::SyncMode, | ||
types::{Node, NodeRecord}, | ||
}; | ||
use ethrex_rlp::decode::RLPDecode; | ||
use ethrex_vm::EvmEngine; | ||
use hex::FromHexError; | ||
#[cfg(feature = "l2")] | ||
use secp256k1::SecretKey; | ||
use serde::{Deserialize, Serialize}; | ||
use std::{ | ||
fs::File, | ||
io, | ||
|
@@ -18,6 +23,28 @@ use std::{ | |
use tokio::sync::Mutex; | ||
use tracing::{error, info}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct NodeConfigFile { | ||
pub known_peers: Vec<Node>, | ||
pub node_record: NodeRecord, | ||
} | ||
|
||
impl NodeConfigFile { | ||
pub async fn new(table: Arc<Mutex<KademliaTable>>, node_record: NodeRecord) -> Self { | ||
let mut connected_peers = vec![]; | ||
|
||
for peer in table.lock().await.iter_peers() { | ||
if peer.is_connected { | ||
connected_peers.push(peer.node); | ||
} | ||
} | ||
NodeConfigFile { | ||
known_peers: connected_peers, | ||
node_record, | ||
} | ||
} | ||
} | ||
|
||
pub fn read_jwtsecret_file(jwt_secret_path: &str) -> Bytes { | ||
match File::open(jwt_secret_path) { | ||
Ok(mut file) => decode::jwtsecret_file(&mut file), | ||
|
@@ -93,35 +120,26 @@ pub fn set_datadir(datadir: &str) -> String { | |
.to_owned() | ||
} | ||
|
||
pub async fn store_known_peers(table: Arc<Mutex<KademliaTable>>, file_path: PathBuf) { | ||
let mut connected_peers = vec![]; | ||
|
||
for peer in table.lock().await.iter_peers() { | ||
if peer.is_connected { | ||
connected_peers.push(peer.node.enode_url()); | ||
} | ||
} | ||
|
||
let json = match serde_json::to_string(&connected_peers) { | ||
pub async fn store_node_config_file(config: NodeConfigFile, file_path: PathBuf) { | ||
let json = match serde_json::to_string(&config) { | ||
Ok(json) => json, | ||
Err(e) => { | ||
error!("Could not store peers in file: {:?}", e); | ||
error!("Could not store config in file: {:?}", e); | ||
return; | ||
} | ||
}; | ||
|
||
if let Err(e) = std::fs::write(file_path, json) { | ||
error!("Could not store peers in file: {:?}", e); | ||
error!("Could not store config in file: {:?}", e); | ||
}; | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub fn read_known_peers(file_path: PathBuf) -> Result<Vec<Node>, serde_json::Error> { | ||
let Ok(file) = std::fs::File::open(file_path) else { | ||
return Ok(vec![]); | ||
}; | ||
|
||
serde_json::from_reader(file) | ||
pub fn read_node_config_file(file_path: PathBuf) -> Result<NodeConfigFile, String> { | ||
match std::fs::File::open(file_path) { | ||
Ok(file) => serde_json::from_reader(file).map_err(|e| format!("Invlid config file {}", e)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Invalid |
||
Err(e) => Err(format!("No config file found: {}", e)), | ||
} | ||
} | ||
|
||
#[cfg(feature = "l2")] | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.