Skip to content

Commit

Permalink
Feat: Migrate to helios 0.2.0 (eigerco#194)
Browse files Browse the repository at this point in the history
* migrate to helios 0.2.0

* changes based on review
  • Loading branch information
danilowhk committed Feb 6, 2023
1 parent 9d9b69f commit 56354ae
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 355 deletions.
578 changes: 236 additions & 342 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions beerus_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ async fn main() -> Result<()> {
let ethereum_lightclient = HeliosLightClient::new(config.clone()).await?;
// Create a new StarkNet light client.
let starknet_lightclient = StarkNetLightClientImpl::new(&config)?;

// Create a new Beerus light client.
let mut beerus = BeerusLightClient::new(
config,
Box::new(ethereum_lightclient),
Box::new(starknet_lightclient),
);

// Start the Beerus light client.
beerus.start().await?;

// Run the CLI command.
let command_response = runner::run(beerus, cli).await?;
// Print the command response.
Expand Down
2 changes: 2 additions & 0 deletions beerus_cli/tests/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(test)]
mod test {
use std::path::PathBuf;
use std::str::FromStr;

use beerus_cli::{
Expand Down Expand Up @@ -3263,6 +3264,7 @@ mod test {
ethereum_consensus_rpc: "http://localhost:8545".to_string(),
ethereum_execution_rpc: "http://localhost:8545".to_string(),
starknet_rpc: "http://localhost:8545".to_string(),
data_dir: Some(PathBuf::from("/tmp")),
starknet_core_contract_address: Address::from_str(
"0x0000000000000000000000000000000000000000",
)
Expand Down
9 changes: 8 additions & 1 deletion beerus_core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use std::str::FromStr;
use ethers::types::Address;
use eyre::{eyre, Result};
use helios::config::{checkpoints, networks::Network};
use std::path::PathBuf;

pub const DEFAULT_ETHEREUM_NETWORK: &str = "goerli";
// By default, we use the Ethereum Mainnet value.
//const DEFAULT_STARKNET_CORE_CONTRACT_ADDRESS: &str = "0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4";
// For testing purpose use Goerli address until we make it configurable
pub const DEFAULT_STARKNET_CORE_CONTRACT_ADDRESS: &str =
"0xde29d060D45901Fb19ED6C6e959EB22d8626708e";

pub const DEFAULT_DATA_DIR: &str = "/tmp";
/// Global configuration.
#[derive(Clone, PartialEq)]
pub struct Config {
Expand All @@ -24,6 +25,8 @@ pub struct Config {
pub starknet_rpc: String,
// StarkNet core contract address.
pub starknet_core_contract_address: Address,
// Path to storage directory
pub data_dir: Option<PathBuf>,
}

impl Config {
Expand All @@ -42,13 +45,17 @@ impl Config {
let starknet_core_contract_address = std::env::var("STARKNET_CORE_CONTRACT_ADDRESS")
.unwrap_or_else(|_| DEFAULT_STARKNET_CORE_CONTRACT_ADDRESS.to_string());
let starknet_core_contract_address = Address::from_str(&starknet_core_contract_address)?;
let data_dir_str =
std::env::var("DATA_DIR").unwrap_or_else(|_| DEFAULT_DATA_DIR.to_string());
let data_dir = PathBuf::from(data_dir_str);

Ok(Self {
ethereum_network,
ethereum_consensus_rpc,
ethereum_execution_rpc,
starknet_rpc,
starknet_core_contract_address,
data_dir: Some(data_dir),
})
}

Expand Down
1 change: 1 addition & 0 deletions beerus_core/src/lightclient/beerus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl BeerusLightClient {
self.starknet_lightclient.start().await?;
self.sync_status = SyncStatus::Synced;
}

Ok(())
}

Expand Down
8 changes: 3 additions & 5 deletions beerus_core/src/lightclient/ethereum/helios_lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,13 @@ impl EthereumLightClient for HeliosLightClient {
impl HeliosLightClient {
/// Create a new HeliosLightClient.
pub async fn new(config: Config) -> eyre::Result<Self> {
// Fetch the current checkpoint.
let checkpoint_value = config.get_checkpoint().await.unwrap();

// Build the Helios wrapped light client.
let helios_light_client = ClientBuilder::new()
let helios_light_client: Client<FileDB> = ClientBuilder::new()
.network(config.ethereum_network()?)
.consensus_rpc(config.ethereum_consensus_rpc.as_str())
.execution_rpc(config.ethereum_execution_rpc.as_str())
.checkpoint(&checkpoint_value)
.load_external_fallback()
.data_dir(config.data_dir.unwrap())
.build()?;

Ok(Self {
Expand Down
4 changes: 4 additions & 0 deletions beerus_core/tests/beerus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ mod tests {
StateDiff, StateUpdate, SyncStatusType, Transaction as StarknetTransaction,
},
};
use std::path::PathBuf;
use std::str::FromStr;

#[test]
fn when_call_new_then_should_return_beerus_lightclient() {
// Given
Expand Down Expand Up @@ -1674,6 +1676,7 @@ mod tests {
ethereum_consensus_rpc: "http://localhost:8545".to_string(),
ethereum_execution_rpc: "http://localhost:8545".to_string(),
starknet_rpc: "mainnet".to_string(),
data_dir: Some(PathBuf::from("/tmp")),
starknet_core_contract_address: Address::from_str(
"0x0000000000000000000000000000000000000000",
)
Expand Down Expand Up @@ -3362,6 +3365,7 @@ mod tests {
ethereum_consensus_rpc: "http://localhost:8545".to_string(),
ethereum_execution_rpc: "http://localhost:8545".to_string(),
starknet_rpc: "http://localhost:8545".to_string(),
data_dir: Some(PathBuf::from("/tmp")),
starknet_core_contract_address: Address::from_str(
"0x0000000000000000000000000000000000000000",
)
Expand Down
13 changes: 8 additions & 5 deletions beerus_core/tests/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#[cfg(test)]
mod tests {
use std::str::FromStr;

use beerus_core::config::{Config, DEFAULT_STARKNET_CORE_CONTRACT_ADDRESS};
use ethers::types::Address;
use helios::config::networks::Network;
use std::path::PathBuf;
use std::str::FromStr;

/// Test `new_from_env` function.
#[test]
Expand Down Expand Up @@ -209,8 +209,9 @@ mod tests {
ethereum_consensus_rpc: "http://localhost:8545".to_string(),
ethereum_execution_rpc: "http://localhost:8545".to_string(),
starknet_rpc: "http://localhost:8545".to_string(),
data_dir: Some(PathBuf::from("/tmp")),
starknet_core_contract_address: Address::from_str(
"0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4",
"0x0000000000000000000000000000000000000000",
)
.unwrap(),
};
Expand All @@ -229,8 +230,9 @@ mod tests {
ethereum_consensus_rpc: "http://localhost:8545".to_string(),
ethereum_execution_rpc: "http://localhost:8545".to_string(),
starknet_rpc: "http://localhost:8545".to_string(),
data_dir: Some(PathBuf::from("/tmp")),
starknet_core_contract_address: Address::from_str(
"0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4",
"0x0000000000000000000000000000000000000000",
)
.unwrap(),
};
Expand All @@ -249,8 +251,9 @@ mod tests {
ethereum_consensus_rpc: "http://localhost:8545".to_string(),
ethereum_execution_rpc: "http://localhost:8545".to_string(),
starknet_rpc: "http://localhost:8545".to_string(),
data_dir: Some(PathBuf::from("/tmp")),
starknet_core_contract_address: Address::from_str(
"0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4",
"0x0000000000000000000000000000000000000000",
)
.unwrap(),
};
Expand Down
2 changes: 2 additions & 0 deletions beerus_core/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod test {
use serde_json::json;
use starknet::{core::types::FieldElement, providers::jsonrpc::models::BlockId};
use std::fs;
use std::path::PathBuf;
use std::str::FromStr;

#[tokio::test]
Expand Down Expand Up @@ -244,6 +245,7 @@ mod test {
ethereum_network: "mainnet".to_string(),
ethereum_consensus_rpc: server.base_url(),
ethereum_execution_rpc: server.base_url(),
data_dir: Some(PathBuf::from("/tmp")),
starknet_rpc: server.base_url(),
starknet_core_contract_address: Address::from_str(
"0x0000000000000000000000000000000000000000",
Expand Down
5 changes: 3 additions & 2 deletions beerus_rest_api/tests/api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#[cfg(test)]
mod test {
use std::str::FromStr;

use beerus_core::{
config::Config,
lightclient::{
Expand All @@ -25,6 +23,8 @@ mod test {
StateDiff, StateUpdate, Transaction as StarknetTransaction,
},
};
use std::path::PathBuf;
use std::str::FromStr;

/// Test the `send_raw_transaction` endpoint.
/// `/ethereum/send_raw_transaction/<bytes>`
Expand Down Expand Up @@ -2361,6 +2361,7 @@ mod test {
ethereum_consensus_rpc: "http://localhost:8545".to_string(),
ethereum_execution_rpc: "http://localhost:8545".to_string(),
starknet_rpc: "http://localhost:8545".to_string(),
data_dir: Some(PathBuf::from("/tmp")),
starknet_core_contract_address: Address::from_str(
"0x0000000000000000000000000000000000000000",
)
Expand Down

0 comments on commit 56354ae

Please sign in to comment.