Add flag for web3 server

This commit is contained in:
Paul Hauner
2019-09-03 16:40:53 +10:00
parent 29584ca087
commit d80d9dba4c
7 changed files with 85 additions and 57 deletions

View File

@@ -23,6 +23,7 @@ pub struct Config {
/// files. It can only be configured via the CLI.
#[serde(skip)]
pub beacon_chain_start_method: BeaconChainStartMethod,
pub eth1_backend_method: Eth1BackendMethod,
pub network: network::NetworkConfig,
pub rpc: rpc::RPCConfig,
pub rest_api: rest_api::ApiConfig,
@@ -69,6 +70,22 @@ impl Default for BeaconChainStartMethod {
}
}
/// Defines which Eth1 backend the client should use.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum Eth1BackendMethod {
/// Use the mocked eth1 backend used in interop testing
Interop,
/// Use a web3 connection to a running Eth1 node.
Web3 { server: String },
}
impl Default for Eth1BackendMethod {
fn default() -> Self {
Eth1BackendMethod::Interop
}
}
impl Default for Config {
fn default() -> Self {
Self {
@@ -81,6 +98,7 @@ impl Default for Config {
rest_api: <_>::default(),
spec_constants: TESTNET_SPEC_CONSTANTS.into(),
beacon_chain_start_method: <_>::default(),
eth1_backend_method: <_>::default(),
}
}
}

View File

@@ -21,14 +21,14 @@ use tokio::runtime::TaskExecutor;
use tokio::timer::Interval;
use types::EthSpec;
pub use beacon_chain::BeaconChainTypes;
pub use config::{BeaconChainStartMethod, Config as ClientConfig};
pub use beacon_chain::{BeaconChainTypes, Eth1ChainBackend, InteropEth1ChainBackend};
pub use config::{BeaconChainStartMethod, Config as ClientConfig, Eth1BackendMethod};
pub use eth2_config::Eth2Config;
#[derive(Clone)]
pub struct ClientType<S: Store, E: EthSpec> {
_phantom_t: PhantomData<S>,
_phantom_u: PhantomData<E>,
_phantom_s: PhantomData<S>,
_phantom_e: PhantomData<E>,
}
impl<S, E> BeaconChainTypes for ClientType<S, E>
@@ -39,6 +39,7 @@ where
type Store = S;
type SlotClock = SystemTimeSlotClock;
type LmdGhost = ThreadSafeReducedTree<S, E>;
type Eth1Chain = InteropEth1ChainBackend<E>;
type EthSpec = E;
}
@@ -168,9 +169,11 @@ where
}
};
let eth1_backend = T::Eth1Chain::new(String::new()).map_err(|e| format!("{:?}", e))?;
let beacon_chain: Arc<BeaconChain<T>> = Arc::new(
beacon_chain_builder
.build(store)
.build(store, eth1_backend)
.map_err(error::Error::from)?,
);