Permalink
Browse files

update to latest cardano-deps

  • Loading branch information...
vincenthz committed Feb 11, 2019
1 parent 210e582 commit d915cdecabe1995323e75797602bedf7f9f2e023
Showing with 98 additions and 56 deletions.
  1. +2 −2 Cargo.toml
  2. +1 −1 cardano-deps
  3. +21 −3 src/config.rs
  4. +12 −8 src/handlers/block.rs
  5. +7 −2 src/handlers/epoch.rs
  6. +7 −2 src/handlers/pack.rs
  7. +2 −2 src/handlers/tip.rs
  8. +3 −4 src/handlers/tx.rs
  9. +16 −13 src/handlers/utxos.rs
  10. +19 −12 src/handlers/utxos_delta.rs
  11. +8 −7 src/service.rs
@@ -30,9 +30,9 @@ env_logger = "0.5.9"
iron = "*"
router ="*"
base64 = "0.9"
cbor_event = "1.0"
cbor_event = "^2.1.1"

[dependencies.clap]
version = "2.31"
default-features = false
features = [ "suggestions", "color", "wrap_help" ]
features = [ "suggestions", "color", "wrap_help" ]
Submodule cardano-deps updated 199 files
@@ -4,7 +4,7 @@ use cardano_storage::config::StorageConfig;
use cardano_storage::{self, Storage};
use exe_common::config::net;
use std::collections::HashSet;
use std::{collections::BTreeMap, num::ParseIntError, sync::Arc};
use std::{collections::BTreeMap, num::ParseIntError, sync::Arc, sync::RwLock};
use std::{
env::{self, home_dir, VarError},
io,
@@ -88,7 +88,7 @@ impl Config {
let network = Network {
path: netcfg_dir,
config: self.get_network_config(name)?,
storage: Arc::new(self.get_storage(name)?),
storage: Arc::new(RwLock::new(self.get_storage(name)?)),
};

networks.insert(name.to_owned(), network);
@@ -142,9 +142,27 @@ impl Config {
pub struct Network {
pub path: PathBuf,
pub config: net::Config,
pub storage: Arc<cardano_storage::Storage>,
pub storage: Arc<RwLock<cardano_storage::Storage>>,
}

/*
impl Network {
pub fn read_storage_config<'a>(&'a self) -> &'a StorageConfig {
let r = self.storage.read().unwrap();
let cfg = &r.config;
&cfg
}
pub fn with_ro_storage(&self) -> &Storage {
&self.storage.read().unwrap()
}
pub fn with_rw_storage(&self) -> &mut Storage {
&mut self.storage.write().unwrap()
}
}
*/

pub type Networks = BTreeMap<String, Network>;

/// the environment variable to define where the Hermes files are stores
@@ -1,7 +1,7 @@
use super::super::config::Networks;
use cardano::block;
use cardano::util::{hex, try_from_slice::TryFromSlice};
use cardano_storage::{block_location, block_read_location, tag};
use cardano_storage::tag;
use std::sync::Arc;

use iron;
@@ -56,26 +56,30 @@ impl iron::Handler for Handler {
error!("invalid blockid: {}", blockid);
return Ok(Response::with(status::BadRequest));
}
let hh_bytes = match tag::read(&net.storage, &blockid) {
let hh_bytes = match tag::read(&net.storage.read().unwrap(), &blockid) {
None => hex::decode(&blockid).unwrap(),
Some(t) => t,
};
let hh = block::HeaderHash::try_from_slice(&hh_bytes).expect("blockid invalid");
info!("querying block header: {}", hh);

match block_location(&net.storage, &hh.clone().into()) {
None => {
match &(net.storage)
.read()
.unwrap()
.block_location(&hh.clone().into())
{
Err(_) => {
warn!("block `{}' does not exist", hh);
Ok(Response::with((status::NotFound, "Not Found")))
}
Some(loc) => {
Ok(loc) => {
debug!("blk location: {:?}", loc);
match block_read_location(&net.storage, &loc, &hh.into()) {
None => {
match net.storage.read().unwrap().read_block_at(&loc) {
Err(_) => {
error!("error while reading block at location: {:?}", loc);
Ok(Response::with(status::InternalServerError))
}
Some(rblk) => Ok(Response::with((status::Ok, rblk.as_ref()))),
Ok(rblk) => Ok(Response::with((status::Ok, rblk.as_ref()))),
}
}
}
@@ -32,13 +32,18 @@ impl iron::Handler for Handler {
Some(x) => x,
};

let opackref = epoch::epoch_read_pack(&net.storage.config, epochid);
let opackref = epoch::epoch_read_pack(&net.storage.read().unwrap().config, epochid);
match opackref {
Err(_) => {
return Ok(Response::with(status::NotFound));
}
Ok(packref) => {
let path = net.storage.config.get_pack_filepath(&packref);
let path = net
.storage
.read()
.unwrap()
.config
.get_pack_filepath(&packref);
Ok(Response::with((status::Ok, path)))
}
}
@@ -56,14 +56,19 @@ impl iron::Handler for Handler {
return Ok(Response::with(status::BadRequest));
}
info!("query pack: {}", packid);
let packhash_vec = match tag::read(&net.storage, &packid) {
let packhash_vec = match tag::read(&net.storage.read().unwrap(), &packid) {
None => hex::decode(&packid).unwrap(),
Some(t) => t,
};

let mut packhash = [0; HASH_SIZE];
packhash[..].clone_from_slice(packhash_vec.as_slice());
let path = net.storage.config.get_pack_filepath(&packhash);
let path = net
.storage
.read()
.unwrap()
.config
.get_pack_filepath(&packhash);

Ok(Response::with((status::Ok, path)))
}
@@ -44,15 +44,15 @@ impl iron::Handler for Handler {
Some(net) => net,
};

match net.storage.get_block_from_tag(&tag::HEAD) {
match net.storage.read().unwrap().get_block_from_tag(&tag::HEAD) {
Err(Error::NoSuchTag) => Ok(Response::with((status::NotFound, "No Tip To Serve"))),
Err(err) => {
error!("error while reading block: {:?}", err);
Ok(Response::with(status::InternalServerError))
}
Ok(block) => Ok(Response::with((
status::Ok,
block.get_header().to_raw().as_ref(),
block.header().to_raw().as_ref(),
))),
}
}
@@ -32,9 +32,8 @@ impl iron::Handler for Handler {
let json = serde_json::from_str::<serde_json::Value>(tx_str).ok()?;
let base_64 = json.as_object()?.get("signedTx")?.as_str()?;
let bytes = base64::decode(&base_64).ok()?;
cbor_event::de::RawCbor::from(&bytes)
.deserialize_complete()
.ok()
let mut de = cbor_event::de::Deserializer::from(std::io::Cursor::new(&bytes));
de.deserialize_complete().ok()
}
let mut req_body_str = String::new();
req.body.read_to_string(&mut req_body_str).unwrap();
@@ -54,7 +53,7 @@ impl iron::Handler for Handler {
}
Some(x) => x,
};
let netcfg_file = net.storage.config.get_config_file();
let netcfg_file = net.storage.read().unwrap().config.get_config_file();
let net_cfg = net::Config::from_file(&netcfg_file).expect("no network config present");

if let Err(verify_error) = txaux.verify(net_cfg.protocol_magic) {
@@ -1,4 +1,6 @@
use cardano_storage::utxo;
use cardano_storage::chain_state;
use exe_common::genesis_data;
use exe_common::genesisdata;

use std::sync::Arc;

@@ -19,7 +21,7 @@ impl Handler {
Handler { networks: networks }
}
pub fn route(self, router: &mut Router) -> &mut Router {
router.get(":network/utxos/:epochid", self, "utxos")
router.get(":network/chain-state/:epochid", self, "chain-state")
}
}

@@ -34,17 +36,18 @@ impl iron::Handler for Handler {

let mut res = vec![];

let utxo_state = utxo::get_utxos_for_epoch(&net.storage, epochid).unwrap();

utxo::write_utxos_delta(
&net.storage,
&utxo_state.last_block,
&utxo_state.last_date,
&utxo_state.utxos,
None,
&mut res,
)
.unwrap();
let genesis_str = genesis_data::get_genesis_data(&net.config.genesis_prev).unwrap();
let genesis_data = genesisdata::parse::parse(genesis_str.as_bytes());

let last_hdr =
&chain_state::get_last_block_of_epoch(&net.storage.read().unwrap(), epochid).unwrap();

let chain_state =
chain_state::read_chain_state(&net.storage.read().unwrap(), &genesis_data, last_hdr)
.unwrap();

chain_state::write_chain_state(&net.storage.read().unwrap(), &genesis_data, &chain_state)
.unwrap();

Ok(Response::with((status::Ok, res)))
}
@@ -1,4 +1,6 @@
use cardano_storage::utxo;
use cardano_storage::chain_state;
use exe_common::genesis_data;
use exe_common::genesisdata;

use std::sync::Arc;

@@ -19,7 +21,11 @@ impl Handler {
Handler { networks: networks }
}
pub fn route(self, router: &mut Router) -> &mut Router {
router.get(":network/utxos-delta/:epochid/:to", self, "utxos-delta")
router.get(
":network/chain-state-delta/:epochid/:to",
self,
"chain-state-delta",
)
}
}

@@ -38,17 +44,18 @@ impl iron::Handler for Handler {

let mut res = vec![];

let to_state = utxo::get_utxos_for_epoch(&net.storage, to).unwrap();
let genesis_str = genesis_data::get_genesis_data(&net.config.genesis_prev).unwrap();
let genesis_data = genesisdata::parse::parse(genesis_str.as_bytes());

utxo::write_utxos_delta(
&net.storage,
&to_state.last_block,
&to_state.last_date,
&to_state.utxos,
Some(from),
&mut res,
)
.unwrap();
let last_hdr =
&chain_state::get_last_block_of_epoch(&net.storage.read().unwrap(), from).unwrap();

let chain_state =
chain_state::read_chain_state(&net.storage.read().unwrap(), &genesis_data, last_hdr)
.unwrap();

chain_state::write_chain_state(&net.storage.read().unwrap(), &genesis_data, &chain_state)
.unwrap();

Ok(Response::with((status::Ok, res)))
}
@@ -1,7 +1,8 @@
use super::config::{Config, Network, Networks};
use super::handlers;
use exe_common::config::net;
use exe_common::{genesis_data, parse_genesis_data, sync};
use exe_common::genesisdata;
use exe_common::{genesis_data, sync};
use iron;
use router::Router;
use std::sync::Arc;
@@ -41,10 +42,10 @@ fn start_networks_refreshers(cfg: Config) -> Vec<thread::JoinHandle<()>> {
match cfg.get_networks() {
Err(err) => panic!("Unable to get networks: {:?}", err),
Ok(networks) => {
for (label, net) in networks.into_iter() {
for (label, mut net) in networks.into_iter() {
threads.push(thread::spawn(move || {
loop {
refresh_network(&label, &net);
refresh_network(&label, &mut net);
// In case of an error, wait a while before retrying.
thread::sleep(Duration::from_secs(10));
}
@@ -56,23 +57,23 @@ fn start_networks_refreshers(cfg: Config) -> Vec<thread::JoinHandle<()>> {
}

// XXX: how do we want to report partial failures?
fn refresh_network(label: &str, net: &Network) {
fn refresh_network(label: &str, net: &mut Network) {
info!("Refreshing network {:?}", label);

let netcfg_file = net.storage.config.get_config_file();
let netcfg_file = net.storage.read().unwrap().config.get_config_file();
let net_cfg = net::Config::from_file(&netcfg_file).expect("no network config present");

let genesis_data = {
let genesis_data =
genesis_data::get_genesis_data(&net_cfg.genesis_prev).expect("genesis data not found");
parse_genesis_data::parse_genesis_data(genesis_data)
genesisdata::parse::parse(genesis_data.as_bytes())
};

sync::net_sync(
&mut sync::get_peer(&label, &net_cfg, true),
&net_cfg,
&genesis_data,
&net.storage,
&mut net.storage.write().unwrap(),
false,
)
.unwrap_or_else(|err| warn!("Sync failed: {:?}", err));

0 comments on commit d915cde

Please sign in to comment.