Create BeaconChainTypes, thread through runtime

This commit is contained in:
Paul Hauner
2019-05-25 20:51:15 +10:00
parent 45e3a1759c
commit ee8d13573f
24 changed files with 254 additions and 452 deletions

View File

@@ -1,6 +1,6 @@
mod prometheus_handler;
use beacon_chain::BeaconChain;
use beacon_chain::{BeaconChain, BeaconChainTypes};
use futures::Future;
use iron::prelude::*;
use iron::{status::Status, Handler, IronResult, Request, Response};
@@ -10,7 +10,6 @@ use router::Router;
use slog::{info, o, warn};
use std::sync::Arc;
use tokio::runtime::TaskExecutor;
use types::EthSpec;
#[derive(PartialEq, Clone, Debug)]
pub struct HttpServerConfig {
@@ -45,15 +44,9 @@ impl Handler for IndexHandler {
}
}
pub fn create_iron_http_server<T, U, F, E>(
beacon_chain: Arc<BeaconChain<T, U, F, E>>,
) -> Iron<Router>
where
T: store::Store + 'static,
U: slot_clock::SlotClock + 'static,
F: fork_choice::ForkChoice + 'static,
E: EthSpec + 'static,
{
pub fn create_iron_http_server<T: BeaconChainTypes + 'static>(
beacon_chain: Arc<BeaconChain<T>>,
) -> Iron<Router> {
let index_handler = IndexHandler {
message: "Hello world".to_string(),
};
@@ -67,19 +60,13 @@ where
Iron::new(router)
}
pub fn start_service<T, U, F, E>(
pub fn start_service<T: BeaconChainTypes + 'static>(
config: &HttpServerConfig,
executor: &TaskExecutor,
_network_chan: crossbeam_channel::Sender<NetworkMessage>,
beacon_chain: Arc<BeaconChain<T, U, F, E>>,
beacon_chain: Arc<BeaconChain<T>>,
log: &slog::Logger,
) -> exit_future::Signal
where
T: store::Store + 'static,
U: slot_clock::SlotClock + 'static,
F: fork_choice::ForkChoice + 'static,
E: EthSpec + 'static,
{
) -> exit_future::Signal {
let log = log.new(o!("Service"=>"HTTP"));
// Create:

View File

@@ -1,22 +1,17 @@
use beacon_chain::BeaconChain;
use beacon_chain::{BeaconChain, BeaconChainTypes};
use iron::{status::Status, Handler, IronResult, Request, Response};
use prometheus::{Encoder, IntCounter, Opts, Registry, TextEncoder};
use slot_clock::SlotClock;
use std::sync::Arc;
use types::{EthSpec, Slot};
use types::Slot;
pub struct PrometheusHandler<T, U, F, E: EthSpec> {
pub beacon_chain: Arc<BeaconChain<T, U, F, E>>,
pub struct PrometheusHandler<T: BeaconChainTypes> {
pub beacon_chain: Arc<BeaconChain<T>>,
}
impl<T, U, F, E> PrometheusHandler<T, U, F, E> where E: EthSpec {}
impl<T: BeaconChainTypes> PrometheusHandler<T> {}
impl<T, U, F, E> Handler for PrometheusHandler<T, U, F, E>
where
E: EthSpec + 'static,
U: slot_clock::SlotClock + Send + Sync + 'static,
T: Send + Sync + 'static,
F: Send + Sync + 'static,
{
impl<T: BeaconChainTypes + 'static> Handler for PrometheusHandler<T> {
fn handle(&self, _: &mut Request) -> IronResult<Response> {
let r = Registry::new();