Skip to content

Commit

Permalink
Move Taiko chain ID to configuration parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailUshakoff committed Aug 20, 2024
1 parent 9566983 commit 3de0cdd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions Node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async fn main() -> Result<(), Error> {
&config.taiko_proposer_url,
&config.taiko_driver_url,
config.block_proposed_receiver_timeout_sec,
config.taiko_chain_id,
));
let ethereum_l1 = Arc::new(
ethereum_l1::EthereumL1::new(
Expand Down
6 changes: 3 additions & 3 deletions Node/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
EthereumL1,
},
mev_boost::MevBoost,
taiko::{self, l2_tx_lists::RPCReplyL2TxLists, Taiko},
taiko::{l2_tx_lists::RPCReplyL2TxLists, Taiko},
utils::{
block_proposed::BlockProposed, commit::L2TxListsCommit,
preconfirmation_message::PreconfirmationMessage,
Expand Down Expand Up @@ -136,7 +136,7 @@ impl Node {
tracing::debug!("Node received message from p2p: {:?}", msg);
// TODO check valid preconfer
// check hash
match L2TxListsCommit::from_preconf(msg.block_height, msg.tx_list_bytes).hash() {
match L2TxListsCommit::from_preconf(msg.block_height, msg.tx_list_bytes, taiko.chain_id).hash() {
Ok(hash) => {
if hash == msg.proof.commit_hash {
// check signature
Expand Down Expand Up @@ -288,7 +288,7 @@ impl Node {
reply: &RPCReplyL2TxLists,
block_height: u64,
) -> Result<([u8; 32], [u8; 65]), Error> {
let commit = L2TxListsCommit::new(reply, block_height);
let commit = L2TxListsCommit::new(reply, block_height, self.taiko.chain_id);
let hash = commit.hash()?;
let signature = self
.ethereum_l1
Expand Down
5 changes: 4 additions & 1 deletion Node/src/taiko/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ pub struct Taiko {
rpc_proposer: RpcClient,
rpc_driver: RpcClient,
rpc_driver_long_timeout: RpcClient,
pub chain_id: u64,
}

impl Taiko {
pub fn new(proposer_url: &str, driver_url: &str, long_timeout_sec: u64) -> Self {
pub fn new(proposer_url: &str, driver_url: &str, long_timeout_sec: u64, chain_id: u64) -> Self {
Self {
rpc_proposer: RpcClient::new(proposer_url),
rpc_driver: RpcClient::new(driver_url),
rpc_driver_long_timeout: RpcClient::new_with_timeout(
driver_url,
Duration::from_secs(long_timeout_sec),
),
chain_id,
}
}

Expand Down Expand Up @@ -156,6 +158,7 @@ mod test {
&format!("http://127.0.0.1:{}", port),
&format!("http://127.0.0.1:{}", port),
120,
1,
);
(rpc_server, taiko)
}
Expand Down
16 changes: 10 additions & 6 deletions Node/src/utils/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use secp256k1::{ecdsa::Signature, Message, Secp256k1, SecretKey};
use serde::{Deserialize, Serialize};
use tiny_keccak::{Hasher, Keccak};

// TODO add chain id to taiko
const CHAIN_ID: [u8; 32] = [0u8; 32];
//https://github.com/NethermindEth/Taiko-Preconf-AVS/blob/caf9fbbde0dd84947af5a7b26610ffd38525d932/SmartContracts/src/avs/PreconfTaskManager.sol#L175
#[derive(Serialize, Deserialize)]
pub struct L2TxListsCommit {
Expand All @@ -16,24 +14,30 @@ pub struct L2TxListsCommit {
}

impl L2TxListsCommit {
pub fn new(reply: &RPCReplyL2TxLists, block_height: u64) -> Self {
pub fn new(reply: &RPCReplyL2TxLists, block_height: u64, chain_id: u64) -> Self {
let block_height_bytes = block_height.to_le_bytes(); // Convert u64 to a [u8; 8] array
let mut block_height = [0u8; 32];
block_height[24..].copy_from_slice(&block_height_bytes);
let chain_id_bytes = chain_id.to_le_bytes(); // Convert u64 to a [u8; 8] array
let mut chain_id = [0u8; 32];
chain_id[24..].copy_from_slice(&chain_id_bytes);
L2TxListsCommit {
block_height,
chain_id: CHAIN_ID,
chain_id,
tx_list_bytes: reply.tx_list_bytes[0].clone(), // TODO check for other indexes
}
}

pub fn from_preconf(block_height: u64, tx_list_bytes: Vec<u8>) -> Self {
pub fn from_preconf(block_height: u64, tx_list_bytes: Vec<u8>, chain_id: u64) -> Self {
let block_height_bytes = block_height.to_le_bytes(); // Convert u64 to a [u8; 8] array
let mut block_height = [0u8; 32];
block_height[24..].copy_from_slice(&block_height_bytes);
let chain_id_bytes = chain_id.to_le_bytes(); // Convert u64 to a [u8; 8] array
let mut chain_id = [0u8; 32];
chain_id[24..].copy_from_slice(&chain_id_bytes);
L2TxListsCommit {
block_height,
chain_id: CHAIN_ID,
chain_id,
tx_list_bytes,
}
}
Expand Down
4 changes: 4 additions & 0 deletions Node/src/utils/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Config {
pub preconf_registry_expiry_sec: u64,
pub contract_addresses: ContractAddresses,
pub p2p_network_config: P2PNetworkConfig,
pub taiko_chain_id: u64,
}

#[derive(Debug)]
Expand Down Expand Up @@ -195,6 +196,8 @@ impl Config {
boot_nodes,
};

let taiko_chain_id = 1u64;

let config = Self {
taiko_proposer_url: std::env::var("TAIKO_PROPOSER_URL")
.unwrap_or("http://127.0.0.1:1234".to_string()),
Expand All @@ -214,6 +217,7 @@ impl Config {
preconf_registry_expiry_sec,
contract_addresses,
p2p_network_config,
taiko_chain_id,
};

info!(
Expand Down

0 comments on commit 3de0cdd

Please sign in to comment.