Skip to content

Commit

Permalink
chore: relayers again (#1420)
Browse files Browse the repository at this point in the history
* fix bin for relayers

* fmt

* refix the relayers
  • Loading branch information
greged93 authored Sep 30, 2024
1 parent 890c7e9 commit ec4ea91
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 140 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ katana-primitives = { git = 'https://github.com/dojoengine/dojo', rev = "7ff6593
"serde",
], optional = true }
mockall = { version = "0.13.0", default-features = false, optional = true }
clap = { version = "4.5.17" }
clap = { version = "4.5.17", optional = true }


starknet_api = { version = "0.13.0-rc.0", optional = true }
Expand Down Expand Up @@ -209,6 +209,7 @@ testing = [
"revm-primitives",
"starknet-crypto",
]
binaries = ["clap"]
hive = []
arbitrary = ["rand", "dep:arbitrary"]

Expand All @@ -218,8 +219,8 @@ required-features = ["testing"]

[[bin]]
name = "hive_genesis"
required-features = ["testing"]
required-features = ["testing", "binaries"]

[[bin]]
name = "hive_chain"
required-features = ["testing"]
required-features = ["testing", "binaries"]
1 change: 1 addition & 0 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ services:
- MAX_LOGS=10000
- WHITE_LISTED_EIP_155_TRANSACTION_HASHES=0xeddf9e61fb9d8f5111840daef55e5fde0041f5702856532cdbb5a02998033d26,0xb6274b80bc7cda162df89894c7748a5cb7ba2eaa6004183c41a1837c3b072f1e,0x07471adfe8f4ec553c1199f495be97fc8be8e0626ae307281c22534460184ed1,0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3
- RELAYER_PRIVATE_KEY=0x1234
- RELAYERS_ADDRESSES=0x12,0x34
restart: on-failure
volumes:
# Mount the indexer code
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ services:
- MAX_LOGS=10000
- WHITE_LISTED_EIP_155_TRANSACTION_HASHES=0xeddf9e61fb9d8f5111840daef55e5fde0041f5702856532cdbb5a02998033d26,0xb6274b80bc7cda162df89894c7748a5cb7ba2eaa6004183c41a1837c3b072f1e,0x07471adfe8f4ec553c1199f495be97fc8be8e0626ae307281c22534460184ed1,0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3
- RELAYER_PRIVATE_KEY=0x1234
- RELAYERS_ADDRESSES:>
0x6f644133991e779509cb319fd4c9416f949950f07a8bc3cb10916966ec1dca,0xc6d61dd26ec6175554977f61198b28f58a7c5f46228b7fb7b44f6f619d800,
0x6faca0d5ce2437933257a91d95536c7cf3bfa12808f314741efd104e9a0c2d9,0x2cced3d1628b867e1b69216df87d869e7f5c8dd066a9114d44e2d1af3fbf2c4,
0x30ee97c478d8a845d0d6ec0c447650ee6161817199f3d5c2a84f8a033b960b2,0x13b09830d3bef686db99c570df79ddfd813502cfa1d7c640ed871a0de6637ba,
0x1e8f2ef3d53eb800432031fc3000b69b5132a2c4c0df821c20173ac8a91de6d,0x2523ffb01dad3d8803a4bae7e2990d74d92b201f5425f921cec2ccb92ee6f18,
0xf6413b17b8ae645ce13e635df7dcb573086ff9558d8d9d7d2e343a250e4885,0x765e5f1ae2f6d796f359ea7c47c88387046d371aef1f02337921fe326fbacc2,
0x21466caac9f9e2605100c76a0ab15e2cbc72942b876f4665fa490dd83f7a00f,0x28d165b48e0b523044bd790bae4cc7096d8747565b1d58691683662e12b6402,
0x7297a3b129e3d3101bb9956338c9c64b7055556146c7ff2497caad4a831c11d,0x8d9da3628af39d3bb9a2155b4eb63af7791da1fd3864f93bb57130fa2b59d2,
0x4dc2ebca0fa6de9e7f67e821e425a0f9a53cb300cc44cbd93d69c307ac536eb,0x6ea69b53281261da1cfde205a5e8c02db26bfa51df77419fef71014c53e03f1,
0x3709159b0a92aefacba33401098c5b3c09240b67dd5c1d5ee9a778e6205028b,0x3ea725fcff7ddaffbdc1134be5ae164bcbf8155135de1d8663c5efb106c9b08,
0x3135b4bb94b1b7c0d7a7074291d0f1d92ab57d1f61bddd0b7195f70207752ae,0x1eb1e028ffa31652cecb7d18311aac1a281610a535f20e7a3a82c13db226b0c,
0x4f57bf04228bf2d2db2e0a8573c6594558a5f0b487c1229b5fe7723473afa58,0x2f24013ebb0911d5f27a2a2c3d07b8c73b2f36239d8325187ed25db1ce794b5,
0x10e3a8574c22d19951d8e8715cc98a26b9ed9fe39f8e002cc82f49c189ea56c,0x6f823719688a9c3e54f7528d4e2a464773170365c2e8b97d699aa2cc519875e,
0x669774f839f462c3267b1d28e9c31264e1436a48033ee0f71e77bef153cfb81,0x6ad46e2c0b5f52412560bb12ad77e2958d53e5f30fc5bc995101dd700e22597,
0xe07332a9bf6f9d3ced6f3f1cb60607d01fba1f6be9da1b3650c58c8d683e06,0x3c320f3726b90a8e21d200eeb956f863c59c9d3744e5f5d9280c648225c7775,
0xdc68dd15efb6b43a02a8679e4a21a9b8195cd44e6134d5034131520c55dbfa,0x594aa6e8d8d5ea9ea4a86681222f65975ed38c4e0f20e8493c0ad9887b3c3f4
restart: on-failure
volumes:
# Mount the indexer code
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ services:
- WHITE_LISTED_EIP_155_TRANSACTION_HASHES=0xeddf9e61fb9d8f5111840daef55e5fde0041f5702856532cdbb5a02998033d26,0xb6274b80bc7cda162df89894c7748a5cb7ba2eaa6004183c41a1837c3b072f1e,0x07471adfe8f4ec553c1199f495be97fc8be8e0626ae307281c22534460184ed1,0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel:4317
- RELAYER_PRIVATE_KEY=0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a
- RELAYERS_ADDRESSES=0xb3ff441a68610b30fd5e2abbf3a1548eb6ba6f3559f2862bf2dc757e5828ca
volumes:
# Mount the volume on workdir and use .env stored in root of the volume
- deployments:/usr/src/app
Expand Down
4 changes: 2 additions & 2 deletions docker/hive/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ COPY --from=compiler /usr/src/compiler/.kakarot/artifacts /usr/src/rpc/.kakarot/
RUN cargo build \
--features hive --release --target-dir /usr/src/rpc/target && \
cargo build \
--bin hive_genesis --release --features "testing" --target-dir /usr/src/rpc/target && \
--bin hive_genesis --release --features "testing,binaries" --target-dir /usr/src/rpc/target && \
cargo build \
--bin hive_chain --release --features "testing" --target-dir /usr/src/rpc/target
--bin hive_chain --release --features "testing,binaries" --target-dir /usr/src/rpc/target

FROM ubuntu:24.10 as base
# Install any necessary dependencies
Expand Down
4 changes: 2 additions & 2 deletions docker/rpc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ HEALTHCHECK --interval=3s --timeout=5s --start-period=1s --retries=5 \
--data '{"jsonrpc": "2.0", "method": "eth_chainId", "id": 1}' http://${KAKAROT_RPC_URL} || exit 1

RUN apt-get update && \
apt-get -y upgrade && \
apt-get install --no-install-recommends -y libssl-dev ca-certificates tini curl && \
apt-get -y upgrade && \
apt-get install --no-install-recommends -y libssl-dev ca-certificates tini curl && \
rm -rf /var/lib/apt/lists/*

# Copy the indexer code into the RPC
Expand Down
16 changes: 6 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use clap::Parser;
use dotenvy::dotenv;
use eyre::Result;
use kakarot_rpc::{
Expand All @@ -12,15 +11,10 @@ use mongodb::options::{DatabaseOptions, ReadConcern, WriteConcern};
use opentelemetry_sdk::runtime::Tokio;
use reth_transaction_pool::PoolConfig;
use starknet::providers::{jsonrpc::HttpTransport, JsonRpcClient};
use std::{env::var, path::PathBuf, sync::Arc};
use std::{env::var, sync::Arc};
use tracing_opentelemetry::MetricsLayer;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer};

#[derive(Parser)]
struct Cli {
accounts_path: PathBuf,
}

#[tokio::main]
async fn main() -> Result<()> {
// Environment variables are safe to use after this
Expand Down Expand Up @@ -83,15 +77,17 @@ async fn main() -> Result<()> {
}
#[cfg(not(feature = "hive"))]
{
let args = Cli::parse();
AccountManager::new(args.accounts_path, Arc::clone(&eth_client)).await?
use starknet::core::types::Felt;
use std::str::FromStr;
let addresses =
var("RELAYERS_ADDRESSES")?.split(',').filter_map(|addr| Felt::from_str(addr).ok()).collect::<Vec<_>>();
AccountManager::from_addresses(addresses, Arc::clone(&eth_client)).await?
}
};
account_manager.start();

// Start the maintenance of the mempool
maintain_transaction_pool(Arc::clone(&eth_client));

// Setup the RPC module
let kakarot_rpc_module = KakarotRpcModuleBuilder::new(eth_client).rpc_module()?;

Expand Down
95 changes: 2 additions & 93 deletions src/pool/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ use reth_transaction_pool::{
blobstore::NoopBlobStore, BlockInfo, CanonicalStateUpdate, CoinbaseTipOrdering, EthPooledTransaction, Pool,
TransactionOrigin, TransactionPool, TransactionPoolExt,
};
use serde_json::Value;
use starknet::{
core::types::{BlockTag, Felt},
providers::{jsonrpc::HttpTransport, JsonRpcClient},
};
use std::{collections::HashMap, fs::File, io::Read, path::PathBuf, str::FromStr, sync::Arc, time::Duration};
use std::{collections::HashMap, sync::Arc, time::Duration};
use tokio::sync::Mutex;

/// A type alias for the Kakarot Transaction Validator.
Expand All @@ -49,47 +48,7 @@ pub struct AccountManager<SP: starknet::providers::Provider + Send + Sync + Clon
}

impl<SP: starknet::providers::Provider + Send + Sync + Clone + 'static> AccountManager<SP> {
/// Creates a new [`AccountManager`] instance by initializing account data from a JSON file.
pub async fn new(path: PathBuf, eth_client: Arc<EthClient<SP>>) -> eyre::Result<Self> {
let mut accounts = HashMap::new();

// Open the file specified by `path`
let mut file = File::open(path)?;

let mut contents = String::new();
file.read_to_string(&mut contents)?;

// Parse the file contents as JSON
let json: Value = serde_json::from_str(&contents)?;

// Extract the account addresses from the JSON array of objects
if let Some(array) = json.as_array() {
for item in array {
if let Some(address_value) = item.get("address") {
if let Some(account_address) = address_value.as_str() {
let felt_address = Felt::from_str(account_address)
.map_err(|e| eyre::eyre!("Error converting account address to Felt: {:?}", e))?;

// Query the initial account_nonce for the account from the provider
let nonce = eth_client
.starknet_provider()
.get_nonce(starknet::core::types::BlockId::Tag(BlockTag::Pending), felt_address)
.await
.unwrap_or_default();
accounts.insert(felt_address, Arc::new(Mutex::new(nonce)));
}
}
}
}

if accounts.is_empty() {
return Err(eyre::eyre!("No accounts found in file"));
}

Ok(Self { accounts, eth_client })
}

/// Initialize the account manager with a set of passed accounts
/// Initialize the account manager with a set of passed accounts.
pub async fn from_addresses(addresses: Vec<Felt>, eth_client: Arc<EthClient<SP>>) -> eyre::Result<Self> {
let mut accounts = HashMap::new();

Expand Down Expand Up @@ -343,53 +302,3 @@ where
}
});
}

#[cfg(test)]
mod tests {
use super::*;
use crate::test_utils::{fixtures::katana, katana::Katana};
use rstest::rstest;
use serde_json::json;
use std::io::Write;
use tempfile::NamedTempFile;

#[rstest]
#[awt]
#[tokio::test(flavor = "multi_thread")]
async fn test_account_manager_setup(#[future] katana: Katana) {
let eth_client = katana.eth_client();

// Create a temporary file to simulate the account JSON file
let mut temp_file = NamedTempFile::new().unwrap();
let json_data = json!([
{"address": "2883640181176136234335915321173609316686035330597712783682502353343947167672"},
{"address": "163189206500119404227396165700254790683726361202744501915894563246389642629"}
]);
write!(temp_file, "{json_data}").unwrap();

// Create an AccountManager instance with the temporary file
let account_manager = AccountManager::new(temp_file.path().to_path_buf(), Arc::new(eth_client)).await.unwrap();

// Verify that the accounts are loaded correctly
let accounts = account_manager.accounts;
assert_eq!(accounts.len(), 2, "Expected 2 accounts in the manager");

// Expected account addresses.
//
// These are the addresses from the temporary JSON file converted to hex.
//
// We want to test a different init method from hex to be sure that the account manager handle the initialization of Felts correctly.
let expected_addresses = [
Felt::from_hex("0x660151ef6c0c8a4eda708478c8b909a8f784fd5b25c6d0f08fa9ea9957b57b8").unwrap(),
Felt::from_hex("0x5c5ca015b2dbfa8a25113a9e89fe996211f25a32887d43b5e9afefa3b8c585").unwrap(),
];

// Validate if the accounts are initialized with the correct nonce values
for (account, nonce) in &accounts {
// Assert that the account address is in the expected list
assert!(expected_addresses.contains(account), "Account address should be in the expected list");
// Assert that the account nonce is initialized to 0
assert_eq!(*(nonce.lock().await), Felt::ZERO, "Account nonce should be initialized to 0");
}
}
}
60 changes: 30 additions & 30 deletions src/pool/staging_accounts.json
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
[
{
"address": "196811956655529464938870506963356417265254982755656721182220531581703691722"
"address": "0x6f644133991e779509cb319fd4c9416f949950f07a8bc3cb10916966ec1dca"
},
{
"address": "21957093533996098199893735879676383136588679748311520227589168706310756352"
"address": "0xc6d61dd26ec6175554977f61198b28f58a7c5f46228b7fb7b44f6f619d800"
},
{
"address": "3156983370717363046107439255471720141779327817437045655686255812427584160473"
"address": "0x6faca0d5ce2437933257a91d95536c7cf3bfa12808f314741efd104e9a0c2d9"
},
{
"address": "1266699859155881030745853831582690989288270820499403211360777706785321251524"
"address": "0x2cced3d1628b867e1b69216df87d869e7f5c8dd066a9114d44e2d1af3fbf2c4"
},
{
"address": "1383285862124284806198255017695143972155822358618284496274717006854914400434"
"address": "0x30ee97c478d8a845d0d6ec0c447650ee6161817199f3d5c2a84f8a033b960b2"
},
{
"address": "556622474269041273239978518722272168991994308790614400316179417436866885562"
"address": "0x13b09830d3bef686db99c570df79ddfd813502cfa1d7c640ed871a0de6637ba"
},
{
"address": "863898040113600763634815654889111716414611996024493703975326561137637580397"
"address": "0x1e8f2ef3d53eb800432031fc3000b69b5132a2c4c0df821c20173ac8a91de6d"
},
{
"address": "1049948733640154265069686452829912746649894206825640979196164127637122215704"
"address": "0x2523ffb01dad3d8803a4bae7e2990d74d92b201f5425f921cec2ccb92ee6f18"
},
{
"address": "435094584583033448832295201512088425433478133620062714947210506762034497669"
"address": "0xf6413b17b8ae645ce13e635df7dcb573086ff9558d8d9d7d2e343a250e4885"
},
{
"address": "3346228509229892705693151942978582777745110237359153985339946277086349208770"
"address": "0x765e5f1ae2f6d796f359ea7c47c88387046d371aef1f02337921fe326fbacc2"
},
{
"address": "940672080678076973284220857522811867751109665531403734530877519116610543631"
"address": "0x21466caac9f9e2605100c76a0ab15e2cbc72942b876f4665fa490dd83f7a00f"
},
{
"address": "1153905432749985401265458683733499773022608046916287656285521728480507290626"
"address": "0x28d165b48e0b523044bd790bae4cc7096d8747565b1d58691683662e12b6402"
},
{
"address": "3239474275390657297685389416379959181890460903604840916970761026219042521373"
"address": "0x7297a3b129e3d3101bb9956338c9c64b7055556146c7ff2497caad4a831c11d"
},
{
"address": "250213415159271018200527943072110142874471999830693008856604231562179598802"
"address": "0x8d9da3628af39d3bb9a2155b4eb63af7791da1fd3864f93bb57130fa2b59d2"
},
{
"address": "2198280314339223222557092281776828065489416638847497213783499893084441097963"
"address": "0x4dc2ebca0fa6de9e7f67e821e425a0f9a53cb300cc44cbd93d69c307ac536eb"
},
{
"address": "3128048873093243381876638739685352454173062731516385990432861353508777886705"
"address": "0x6ea69b53281261da1cfde205a5e8c02db26bfa51df77419fef71014c53e03f1"
},
{
"address": "1555828588265071115262743178862761512333590937219830474927477936652084904587"
"address": "0x3709159b0a92aefacba33401098c5b3c09240b67dd5c1d5ee9a778e6205028b"
},
{
"address": "1771170141088019121607099543715528103387743149193776509961998409196567829256"
"address": "0x3ea725fcff7ddaffbdc1134be5ae164bcbf8155135de1d8663c5efb106c9b08"
},
{
"address": "1391138740407817780135845053928430177089762593084057844256920673963627467438"
"address": "0x3135b4bb94b1b7c0d7a7074291d0f1d92ab57d1f61bddd0b7195f70207752ae"
},
{
"address": "867729030279064875529548689518070988175185922650816101519059977121980115724"
"address": "0x1eb1e028ffa31652cecb7d18311aac1a281610a535f20e7a3a82c13db226b0c"
},
{
"address": "2242984317358998574195157522220615218790909801911372191666690443003473623640"
"address": "0x4f57bf04228bf2d2db2e0a8573c6594558a5f0b487c1229b5fe7723473afa58"
},
{
"address": "1332644935669106989468987587551966650897687168489438413314411798711369176245"
"address": "0x2f24013ebb0911d5f27a2a2c3d07b8c73b2f36239d8325187ed25db1ce794b5"
},
{
"address": "477452606747289630100801764512823550290143451527521169897857094721176773996"
"address": "0x10e3a8574c22d19951d8e8715cc98a26b9ed9fe39f8e002cc82f49c189ea56c"
},
{
"address": "3152299787013812409150951128071649069809927970379603418783350452667249428318"
"address": "0x6f823719688a9c3e54f7528d4e2a464773170365c2e8b97d699aa2cc519875e"
},
{
"address": "2900219484813815244663452001325825033560729068581832394454919729462799825793"
"address": "0x669774f839f462c3267b1d28e9c31264e1436a48033ee0f71e77bef153cfb81"
},
{
"address": "3020030869193293942595440056191719689367143055447934973977689404209268663703"
"address": "0x6ad46e2c0b5f52412560bb12ad77e2958d53e5f30fc5bc995101dd700e22597"
},
{
"address": "396568809214101853914278146231211325536717896034045776470162047322020134406"
"address": "0xe07332a9bf6f9d3ced6f3f1cb60607d01fba1f6be9da1b3650c58c8d683e06"
},
{
"address": "1701701142581572481335003412606291319941240723790422258957246134847335593845"
"address": "0x3c320f3726b90a8e21d200eeb956f863c59c9d3744e5f5d9280c648225c7775"
},
{
"address": "389430096329694827798034205258091031637534110544741892019394563550374910970"
"address": "0xdc68dd15efb6b43a02a8679e4a21a9b8195cd44e6134d5034131520c55dbfa"
},
{
"address": "2524233885883809884722481000086760329502676546916492443119822698758295241716"
"address": "0x594aa6e8d8d5ea9ea4a86681222f65975ed38c4e0f20e8493c0ad9887b3c3f4"
}
]

0 comments on commit ec4ea91

Please sign in to comment.