Skip to content

Commit

Permalink
feat: change config to allow env vars for deployment file data
Browse files Browse the repository at this point in the history
  • Loading branch information
renan061 committed Nov 9, 2023
1 parent ae72878 commit 7f5b61d
Show file tree
Hide file tree
Showing 14 changed files with 313 additions and 297 deletions.
3 changes: 3 additions & 0 deletions offchain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 20 additions & 37 deletions offchain/authority-claimer/src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@ use log::{LogConfig, LogEnvCliConfig};
use rollups_events::{BrokerCLIConfig, BrokerConfig};
use rusoto_core::Region;
use snafu::ResultExt;
use std::{fs, path::PathBuf, str::FromStr};
use std::{fs, str::FromStr};
use types::blockchain_config::BlockchainCLIConfig;

use crate::auth::{AuthConfig, AuthEnvCLIConfig};
use crate::config::{
error::{
AuthSnafu, AuthorityClaimerConfigError, InvalidRegionSnafu,
MnemonicFileSnafu, TxManagerSnafu, TxSigningConfigError,
TxSigningSnafu,
AuthSnafu, AuthorityClaimerConfigError, BlockchainSnafu,
InvalidRegionSnafu, MnemonicFileSnafu, TxManagerSnafu,
TxSigningConfigError, TxSigningSnafu,
},
json::{
read_json_file, DappDeployment, RollupsDeployment,
RollupsDeploymentJson,
},
AuthorityClaimerConfig, TxSigningConfig,
AuthorityClaimerConfig, BlockchainConfig, TxSigningConfig,
};

// ------------------------------------------------------------------------------------------------
Expand All @@ -35,27 +32,22 @@ use crate::config::{
#[command(about = "Configuration for authority-claimer")]
pub(crate) struct AuthorityClaimerCLI {
#[command(flatten)]
tx_manager_config: TxManagerCLIConfig,
pub tx_manager_config: TxManagerCLIConfig,

#[command(flatten)]
tx_signing_config: TxSigningCLIConfig,
pub tx_signing_config: TxSigningCLIConfig,

#[command(flatten)]
broker_config: BrokerCLIConfig,
pub broker_config: BrokerCLIConfig,

#[command(flatten)]
pub log_config: LogEnvCliConfig,

#[command(flatten)]
pub auth_config: AuthEnvCLIConfig,

/// Path to a file with the deployment json of the dapp
#[arg(long, env, default_value = "./dapp_deployment.json")]
dapp_deployment_file: PathBuf,

/// Path to file with deployment json of rollups
#[arg(long, env, default_value = "./rollups_deployment.json")]
pub rollups_deployment_file: PathBuf,
#[command(flatten)]
pub blockchain_config: BlockchainCLIConfig,
}

impl TryFrom<AuthorityClaimerCLI> for AuthorityClaimerConfig {
Expand All @@ -72,38 +64,29 @@ impl TryFrom<AuthorityClaimerCLI> for AuthorityClaimerConfig {

let broker_config = BrokerConfig::from(cli_config.broker_config);

let log_config = LogConfig::initialize(cli_config.log_config);

let auth_config = AuthConfig::initialize(cli_config.auth_config)
.context(AuthSnafu)?;

let dapp_deployment =
read_json_file::<DappDeployment>(cli_config.dapp_deployment_file)?;
let dapp_address = dapp_deployment.dapp_address;
let dapp_deploy_block_hash = dapp_deployment.dapp_deploy_block_hash;

let log_config = LogConfig::initialize(cli_config.log_config);
let rollups_deployment = read_json_file::<RollupsDeploymentJson>(
cli_config.rollups_deployment_file,
)
.map(RollupsDeployment::from)?;

let authority_address = rollups_deployment.authority_address.address;
let blockchain_config =
BlockchainConfig::try_from(cli_config.blockchain_config)
.context(BlockchainSnafu)?;

Ok(AuthorityClaimerConfig {
tx_manager_config,
tx_signing_config,
tx_manager_priority: Priority::Normal,
auth_config,
broker_config,
log_config,
authority_address,
dapp_address,
dapp_deploy_block_hash,
auth_config,
blockchain_config,
})
}
}

// ------------------------------------------------------------------------------------------------
// TxSigningConfig
// TxSigningCLIConfig
// ------------------------------------------------------------------------------------------------

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -152,7 +135,7 @@ impl TryFrom<TxSigningCLIConfig> for TxSigningConfig {
} else {
match (cli.tx_signing_aws_kms_key_id, cli.tx_signing_aws_kms_region)
{
(None, _) => Err(TxSigningConfigError::MissingConfiguration),
(None, _) => Err(TxSigningConfigError::AuthConfigMissing),
(Some(_), None) => Err(TxSigningConfigError::MissingRegion),
(Some(key_id), Some(region)) => {
let region = Region::from_str(&region)
Expand Down
19 changes: 5 additions & 14 deletions offchain/authority-claimer/src/config/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use eth_tx_manager::config::Error as TxManagerConfigError;
use rusoto_core::region::ParseRegionError;
use snafu::Snafu;
use std::path::PathBuf;
use types::blockchain_config::BlockchainConfigError;

use crate::auth::AuthError;

Expand All @@ -17,27 +17,18 @@ pub enum AuthorityClaimerConfigError {
#[snafu(display("TxSigning configuration error"))]
TxSigningError { source: TxSigningConfigError },

#[snafu(display("Auth configuration error: {}", source))]
#[snafu(display("Auth configuration error"))]
AuthError { source: AuthError },

#[snafu(display("Read file error ({})", path.display()))]
ReadFileError {
path: PathBuf,
source: std::io::Error,
},

#[snafu(display("Json parse error ({})", path.display()))]
JsonParseError {
path: PathBuf,
source: serde_json::Error,
},
#[snafu(display("Blockchain configuration error"))]
BlockchainError { source: BlockchainConfigError },
}

#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
pub enum TxSigningConfigError {
#[snafu(display("Missing auth configuration"))]
MissingConfiguration,
AuthConfigMissing,

#[snafu(display("Could not read mnemonic file at path `{}`", path,))]
MnemonicFileError {
Expand Down
62 changes: 0 additions & 62 deletions offchain/authority-claimer/src/config/json.rs

This file was deleted.

8 changes: 3 additions & 5 deletions offchain/authority-claimer/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

mod cli;
mod error;
mod json;

pub use error::{AuthorityClaimerConfigError, TxSigningConfigError};

use cli::AuthorityClaimerCLI;
use eth_tx_manager::{config::TxManagerConfig, Priority};
use http_server::HttpServerConfig;
use log::LogConfig;
use rollups_events::{Address, BrokerConfig, Hash};
use rollups_events::BrokerConfig;
use rusoto_core::Region;
use types::blockchain_config::BlockchainConfig;

use crate::auth::AuthConfig;

Expand All @@ -30,9 +30,7 @@ pub struct AuthorityClaimerConfig {
pub auth_config: AuthConfig,
pub broker_config: BrokerConfig,
pub log_config: LogConfig,
pub authority_address: Address,
pub dapp_address: Address,
pub dapp_deploy_block_hash: Hash,
pub blockchain_config: BlockchainConfig,
}

#[derive(Debug, Clone)]
Expand Down
6 changes: 3 additions & 3 deletions offchain/authority-claimer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub async fn run(config: Config) -> Result<(), Box<dyn Error>> {
let config = config.authority_claimer_config;
let dapp_metadata = DAppMetadata {
chain_id: config.tx_manager_config.chain_id,
dapp_address: config.dapp_address.clone(),
dapp_address: config.blockchain_config.dapp_address.clone(),
};

// Creating the broker listener.
Expand All @@ -50,7 +50,7 @@ pub async fn run(config: Config) -> Result<(), Box<dyn Error>> {
trace!("Creating the duplicate checker");
let duplicate_checker = DefaultDuplicateChecker::new(
config.tx_manager_config.provider_http_endpoint.clone(),
config.authority_address.clone(),
config.blockchain_config.authority_address.clone(),
)?;

// Creating the transaction sender.
Expand All @@ -61,7 +61,7 @@ pub async fn run(config: Config) -> Result<(), Box<dyn Error>> {

// Creating the claimer loop.
let claimer = DefaultClaimer::new(
config.dapp_address.clone(),
config.blockchain_config.dapp_address.clone(),
broker_listener,
duplicate_checker,
transaction_sender,
Expand Down
10 changes: 6 additions & 4 deletions offchain/authority-claimer/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,12 @@ impl DefaultTransactionSender {
let authority = {
let (provider, _mock) = Provider::mocked();
let provider = Arc::new(provider);
Authority::new(
H160(config.authority_address.inner().to_owned()),
provider,
)
let address: H160 = config
.blockchain_config
.authority_address
.into_inner()
.into();
Authority::new(address, provider)
};

Ok(Self {
Expand Down
Loading

0 comments on commit 7f5b61d

Please sign in to comment.