Skip to content

Commit

Permalink
fix node_id with address of node account
Browse files Browse the repository at this point in the history
  • Loading branch information
kafeikui committed May 7, 2024
1 parent da198c7 commit 9160ab9
Show file tree
Hide file tree
Showing 25 changed files with 84 additions and 102 deletions.
4 changes: 1 addition & 3 deletions crates/arpa-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,12 @@ Configuration items in [`conf/config.yml`](conf/config.yml) are listed here:

```
logger:
node_id: running
context_logging: false
log_file_path: log/running/
rolling_file_size: 10 gb
```
- node_id: Set a node id for logging.
- context_logging: Set whether to log context of current node info and group info. Since it will increase log size, it is recommended to set it to false in production.
- context_logging: Set whether to log context of current node info and group info. Since the log size will get a significant boost with this setting enabled, it is recommended to set it to false in production.
- log_file_path: Set log file path. The `node-client` will create a `node.log` as well as a `node_err.log` under `log_file_path`, then log to them with info level and error level respectively.
- rolling_file_size: Log file will be deleted when it reaches this size limit. The following units are supported (case insensitive):
"b", "kb", "kib", "mb", "mib", "gb", "gib", "tb", "tib". The unit defaults to bytes if not specified.
Expand Down
1 change: 0 additions & 1 deletion crates/arpa-node/conf/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ arpa_address: "0xa4F59C4Caf15641F32f5756E37d93912E7F96203"
data_path: "./data0.sqlite"

logger:
node_id: 0
context_logging: false
log_file_path: log/0/
rolling_file_size: 10 gb
Expand Down
11 changes: 6 additions & 5 deletions crates/arpa-node/src/node_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use arpa_contract_client::controller::ControllerClientBuilder;
use arpa_contract_client::controller::ControllerViews;
use arpa_contract_client::node_registry::{NodeRegistryClientBuilder, NodeRegistryTransactions};
use arpa_core::address_to_string;
use arpa_core::build_wallet_from_config;
use arpa_core::log::encoder::JsonEncoder;
use arpa_core::Config;
Expand Down Expand Up @@ -164,10 +165,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let config = Config::load(opt.config_path);

let wallet = build_wallet_from_config(config.get_account())?;

let id_address = wallet.address();

let logger_descriptor = config.get_logger_descriptor();

init_logger(
logger_descriptor.get_node_id(),
&address_to_string(id_address),
logger_descriptor.get_context_logging(),
logger_descriptor.get_log_file_path(),
logger_descriptor.get_rolling_file_size(),
Expand All @@ -177,10 +182,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let data_path = PathBuf::from(config.get_data_path());

let wallet = build_wallet_from_config(config.get_account())?;

let id_address = wallet.address();

let is_new_run = !data_path.exists();

let is_eigenlayer = config.is_eigenlayer();
Expand Down
31 changes: 2 additions & 29 deletions crates/arpa-node/src/node_config_checker.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use arpa_core::address_to_string;
use arpa_core::build_wallet_from_config;
use arpa_core::Config;
use ethers::signers::Signer;
use ethers::types::Address;
use ethers::utils::keccak256;
use std::path::PathBuf;
use structopt::StructOpt;

Expand All @@ -27,33 +26,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let wallet = build_wallet_from_config(config.get_account())?;

println!("{:?}", to_checksum(&wallet.address(), None));
println!("{:?}", address_to_string(wallet.address()));

Ok(())
}

/// Converts an Ethereum address to the checksum encoding
/// Ref: <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md>
pub fn to_checksum(addr: &Address, chain_id: Option<u8>) -> String {
let prefixed_addr = match chain_id {
Some(chain_id) => format!("{}0x{:x}", chain_id, addr),
None => format!("{:x}", addr),
};
let hash = hex::encode(keccak256(&prefixed_addr));
let hash = hash.as_bytes();

let addr_hex = hex::encode(addr.as_bytes());
let addr_hex = addr_hex.as_bytes();

addr_hex
.iter()
.zip(hash)
.fold("0x".to_owned(), |mut encoded, (addr, hash)| {
encoded.push(if *hash >= 56 {
addr.to_ascii_uppercase() as char
} else {
addr.to_ascii_lowercase() as char
});
encoded
})
}
1 change: 0 additions & 1 deletion crates/arpa-node/test/conf/config_test_1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ adapter_address: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
data_path: "./data1.sqlite"

logger:
node_id: 1
context_logging: false
log_file_path: log/1/
rolling_file_size: 10 gb
Expand Down
1 change: 0 additions & 1 deletion crates/arpa-node/test/conf/config_test_10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ adapter_address: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
data_path: "./data10.sqlite"

logger:
node_id: 10
context_logging: false
log_file_path: log/10/
rolling_file_size: 10 gb
Expand Down
1 change: 0 additions & 1 deletion crates/arpa-node/test/conf/config_test_2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ adapter_address: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
data_path: "./data2.sqlite"

logger:
node_id: 2
context_logging: false
log_file_path: log/2/
rolling_file_size: 10 gb
Expand Down
1 change: 0 additions & 1 deletion crates/arpa-node/test/conf/config_test_3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ adapter_address: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
data_path: "./data3.sqlite"

logger:
node_id: 3
context_logging: false
log_file_path: log/3/
rolling_file_size: 10 gb
Expand Down
1 change: 0 additions & 1 deletion crates/arpa-node/test/conf/config_test_4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ adapter_address: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
data_path: "./data4.sqlite"

logger:
node_id: 4
context_logging: false
log_file_path: log/4/
rolling_file_size: 10 gb
Expand Down
1 change: 0 additions & 1 deletion crates/arpa-node/test/conf/config_test_5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ adapter_address: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
data_path: "./data5.sqlite"

logger:
node_id: 5
context_logging: false
log_file_path: log/5/
rolling_file_size: 10 gb
Expand Down
1 change: 0 additions & 1 deletion crates/arpa-node/test/conf/config_test_6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ adapter_address: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
data_path: "./data6.sqlite"

logger:
node_id: 6
context_logging: false
log_file_path: log/6/
rolling_file_size: 10 gb
Expand Down
1 change: 0 additions & 1 deletion crates/arpa-node/test/conf/config_test_7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ adapter_address: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
data_path: "./data7.sqlite"

logger:
node_id: 7
context_logging: false
log_file_path: log/7/
rolling_file_size: 10 gb
Expand Down
1 change: 0 additions & 1 deletion crates/arpa-node/test/conf/config_test_8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ adapter_address: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
data_path: "./data8.sqlite"

logger:
node_id: 8
context_logging: false
log_file_path: log/8/
rolling_file_size: 10 gb
Expand Down
1 change: 0 additions & 1 deletion crates/arpa-node/test/conf/config_test_9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ adapter_address: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
data_path: "./data9.sqlite"

logger:
node_id: 9
context_logging: false
log_file_path: log/9/
rolling_file_size: 10 gb
Expand Down
6 changes: 0 additions & 6 deletions crates/core/src/types/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ impl Default for ConfigHolder {

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LoggerDescriptor {
node_id: String,
context_logging: bool,
log_file_path: String,
#[serde(deserialize_with = "deserialize_limit")]
Expand All @@ -122,7 +121,6 @@ pub struct LoggerDescriptor {
impl Default for LoggerDescriptor {
fn default() -> Self {
Self {
node_id: "running".to_string(),
context_logging: false,
log_file_path: "log/running".to_string(),
rolling_file_size: DEFAULT_ROLLING_LOG_FILE_SIZE,
Expand All @@ -131,10 +129,6 @@ impl Default for LoggerDescriptor {
}

impl LoggerDescriptor {
pub fn get_node_id(&self) -> &str {
&self.node_id
}

pub fn get_context_logging(&self) -> bool {
self.context_logging
}
Expand Down
33 changes: 31 additions & 2 deletions crates/core/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use chrono::Local;
use ethers_core::types::{Address, I256, U256};
use ethers_core::{
types::{Address, I256, U256},
utils::{hex, keccak256},
};
use log::info;

/// The threshold max change/difference (in %) at which we will ignore the fee history values
Expand Down Expand Up @@ -27,7 +30,7 @@ pub fn format_now_date() -> String {
}

pub fn address_to_string(address: Address) -> String {
format!("{:?}", address)
to_checksum(&address, None)
}

pub fn u256_to_vec(x: &U256) -> Vec<u8> {
Expand All @@ -50,6 +53,32 @@ pub fn pad_to_bytes32(s: &[u8]) -> Option<[u8; 32]> {
Some(result)
}

/// Converts an Ethereum address to the checksum encoding
/// Ref: <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md>
pub fn to_checksum(addr: &Address, chain_id: Option<u8>) -> String {
let prefixed_addr = match chain_id {
Some(chain_id) => format!("{}0x{:x}", chain_id, addr),
None => format!("{:x}", addr),
};
let hash = hex::encode(keccak256(&prefixed_addr));
let hash = hash.as_bytes();

let addr_hex = hex::encode(addr.as_bytes());
let addr_hex = addr_hex.as_bytes();

addr_hex
.iter()
.zip(hash)
.fold("0x".to_owned(), |mut encoded, (addr, hash)| {
encoded.push(if *hash >= 56 {
addr.to_ascii_uppercase() as char
} else {
addr.to_ascii_lowercase() as char
});
encoded
})
}

/// The EIP-1559 fee estimator which is based on the work by [ethers-rs](https://github.com/gakonst/ethers-rs/blob/e0e79df7e9032e882fce4f47bcc25d87bceaec68/ethers-core/src/utils/mod.rs#L500) and [MyCrypto](https://github.com/MyCryptoHQ/MyCrypto/blob/master/src/services/ApiService/Gas/eip1559.ts)
pub fn eip1559_gas_price_estimator(base: U256, tips: Vec<Vec<U256>>) -> (U256, U256) {
info!("base: {:?}", base);
Expand Down
2 changes: 0 additions & 2 deletions docker/deployments/internet-test/arpa-node/config_1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,3 @@ time_limits:
use_jitter: false

context_logging: false

node_id: 1
2 changes: 0 additions & 2 deletions docker/deployments/internet-test/arpa-node/config_2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,3 @@ time_limits:
use_jitter: false

context_logging: false

node_id: 2
2 changes: 0 additions & 2 deletions docker/deployments/internet-test/arpa-node/config_3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,3 @@ time_limits:
use_jitter: false

context_logging: false

node_id: 3
2 changes: 0 additions & 2 deletions docker/deployments/localnet-test/arpa-node/config_1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,3 @@ time_limits:
use_jitter: false

context_logging: false

node_id: 1
2 changes: 0 additions & 2 deletions docker/deployments/localnet-test/arpa-node/config_2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,3 @@ time_limits:
use_jitter: false

context_logging: false

node_id: 2
2 changes: 0 additions & 2 deletions docker/deployments/localnet-test/arpa-node/config_3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,3 @@ time_limits:
use_jitter: false

context_logging: false

node_id: 3
1 change: 0 additions & 1 deletion docker/node-client/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ adapter_address: "0xf6f449C580A668073c1742b8Bd07796D20129f7A"
data_path: "./db/data1.sqlite"

logger:
node_id: 1
context_logging: false
log_file_path: log/1/
rolling_file_size: 10 gb
Expand Down
1 change: 0 additions & 1 deletion scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,6 @@ def deploy_nodes(): # ! Deploy Nodes

# set node_id, data_path, and log_file_path
data["data_path"] = f"./db/data{i+1}.sqlite"
data["logger"]["node_id"] = i + 1
data["logger"]["log_file_path"] = f"log/{i+1}/"
# L1
data["adapter_address"] = l1_addresses["Adapter"]
Expand Down
Loading

0 comments on commit 9160ab9

Please sign in to comment.