re-do cost table
This commit is contained in:
parent
bb39f104f4
commit
9692616958
@ -31,7 +31,7 @@ use ethcore::service::ClientIoMessage;
|
||||
use ethcore::encoded;
|
||||
use io::IoChannel;
|
||||
|
||||
use util::{Bytes, DBValue, H256, Mutex, RwLock};
|
||||
use util::{H256, Mutex, RwLock};
|
||||
|
||||
use self::header_chain::{AncestryIter, HeaderChain};
|
||||
|
||||
|
@ -20,7 +20,6 @@ use network::{NetworkContext, PeerId, NodeId};
|
||||
|
||||
use super::{Announcement, LightProtocol, ReqId};
|
||||
use super::error::Error;
|
||||
use request::{self, Request};
|
||||
use request_builder::Requests;
|
||||
|
||||
/// An I/O context which allows sending and receiving packets as well as
|
||||
|
@ -18,14 +18,13 @@
|
||||
//!
|
||||
//! This uses a "Provider" to answer requests.
|
||||
|
||||
use ethcore::transaction::{Action, UnverifiedTransaction};
|
||||
use ethcore::receipt::Receipt;
|
||||
use ethcore::transaction::UnverifiedTransaction;
|
||||
|
||||
use io::TimerToken;
|
||||
use network::{NetworkProtocolHandler, NetworkContext, PeerId};
|
||||
use rlp::{RlpStream, Stream, UntrustedRlp, View};
|
||||
use util::hash::H256;
|
||||
use util::{Bytes, DBValue, Mutex, RwLock, U256};
|
||||
use util::{DBValue, Mutex, RwLock, U256};
|
||||
use time::{Duration, SteadyTime};
|
||||
|
||||
use std::collections::HashMap;
|
||||
@ -34,7 +33,7 @@ use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use provider::Provider;
|
||||
use request::{self, HashOrNumber, Request, Response};
|
||||
use request::{Request, Response};
|
||||
use request_builder::Requests;
|
||||
|
||||
use self::request_credits::{Credits, FlowParams};
|
||||
@ -48,8 +47,8 @@ mod error;
|
||||
mod status;
|
||||
mod request_set;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
// #[cfg(test)]
|
||||
// mod tests;
|
||||
|
||||
pub mod request_credits;
|
||||
|
||||
|
@ -27,7 +27,6 @@
|
||||
//! on any empirical timings or mathematical models.
|
||||
|
||||
use request::{self, Request};
|
||||
use super::packet;
|
||||
use super::error::Error;
|
||||
|
||||
use rlp::*;
|
||||
@ -107,13 +106,63 @@ impl Default for CostTable {
|
||||
|
||||
impl RlpEncodable for CostTable {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
unimplemented!()
|
||||
fn append_cost(s: &mut RlpStream, cost: &U256, kind: request::Kind) {
|
||||
s.begin_list(2).append(&kind).append(cost);
|
||||
}
|
||||
|
||||
s.begin_list(9).append(&self.base);
|
||||
append_cost(s, &self.headers, request::Kind::Headers);
|
||||
append_cost(s, &self.body, request::Kind::Body);
|
||||
append_cost(s, &self.receipts, request::Kind::Receipts);
|
||||
append_cost(s, &self.account, request::Kind::Account);
|
||||
append_cost(s, &self.storage, request::Kind::Storage);
|
||||
append_cost(s, &self.code, request::Kind::Code);
|
||||
append_cost(s, &self.header_proof, request::Kind::HeaderProof);
|
||||
append_cost(s, &self.transaction_proof, request::Kind::Execution);
|
||||
}
|
||||
}
|
||||
|
||||
impl RlpDecodable for CostTable {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
unimplemented!()
|
||||
let rlp = decoder.as_rlp();
|
||||
let base = rlp.val_at(0)?;
|
||||
|
||||
let mut headers = None;
|
||||
let mut body = None;
|
||||
let mut receipts = None;
|
||||
let mut account = None;
|
||||
let mut storage = None;
|
||||
let mut code = None;
|
||||
let mut header_proof = None;
|
||||
let mut transaction_proof = None;
|
||||
|
||||
for cost_list in rlp.iter().skip(1) {
|
||||
let cost = cost_list.val_at(1)?;
|
||||
match cost_list.val_at(0)? {
|
||||
request::Kind::Headers => headers = Some(cost),
|
||||
request::Kind::Body => body = Some(cost),
|
||||
request::Kind::Receipts => receipts = Some(cost),
|
||||
request::Kind::Account => account = Some(cost),
|
||||
request::Kind::Storage => storage = Some(cost),
|
||||
request::Kind::Code => code = Some(cost),
|
||||
request::Kind::HeaderProof => header_proof = Some(cost),
|
||||
request::Kind::Execution => transaction_proof = Some(cost),
|
||||
}
|
||||
}
|
||||
|
||||
let unwrap_cost = |cost: Option<U256>| cost.ok_or(DecoderError::Custom("Not all costs specified in cost table."));
|
||||
|
||||
Ok(CostTable {
|
||||
base: base,
|
||||
headers: unwrap_cost(headers)?,
|
||||
body: unwrap_cost(body)?,
|
||||
receipts: unwrap_cost(receipts)?,
|
||||
account: unwrap_cost(account)?,
|
||||
storage: unwrap_cost(storage)?,
|
||||
code: unwrap_cost(code)?,
|
||||
header_proof: unwrap_cost(header_proof)?,
|
||||
transaction_proof: unwrap_cost(transaction_proof)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::iter::FromIterator;
|
||||
|
||||
use request::{self, Request};
|
||||
use request::Request;
|
||||
use request_builder::Requests;
|
||||
use net::{timeout, ReqId};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user