Implement skeleton for transaction index and epoch transition proof PIP messages (#5908)

* add transaction index message without implementing

* add epoch proof fetch and response messages
This commit is contained in:
Robert Habermeier
2017-07-03 12:25:10 +02:00
committed by Arkadiy Paronyan
parent f22745eb0a
commit 826a4ca0a2
5 changed files with 183 additions and 7 deletions

View File

@@ -55,6 +55,7 @@ fn hardcoded_serve_time(kind: Kind) -> u64 {
match kind {
Kind::Headers => 500_000,
Kind::HeaderProof => 500_000,
Kind::TransactionIndex => 500_000,
Kind::Receipts => 1_000_000,
Kind::Body => 1_000_000,
Kind::Account => 1_500_000,

View File

@@ -80,7 +80,7 @@ pub const PROTOCOL_VERSIONS: &'static [u8] = &[1];
pub const MAX_PROTOCOL_VERSION: u8 = 1;
/// Packet count for PIP.
pub const PACKET_COUNT: u8 = 5;
pub const PACKET_COUNT: u8 = 9;
// packet ID definitions.
mod packet {
@@ -100,6 +100,10 @@ mod packet {
// relay transactions to peers.
pub const SEND_TRANSACTIONS: u8 = 0x06;
// request and respond with epoch transition proof
pub const REQUEST_EPOCH_PROOF: u8 = 0x07;
pub const EPOCH_PROOF: u8 = 0x08;
}
// timeouts for different kinds of requests. all values are in milliseconds.
@@ -110,6 +114,7 @@ mod timeout {
// timeouts per request within packet.
pub const HEADERS: i64 = 250; // per header?
pub const TRANSACTION_INDEX: i64 = 100;
pub const BODY: i64 = 50;
pub const RECEIPT: i64 = 50;
pub const PROOF: i64 = 100; // state proof
@@ -523,6 +528,12 @@ impl LightProtocol {
packet::SEND_TRANSACTIONS => self.relay_transactions(peer, io, rlp),
packet::REQUEST_EPOCH_PROOF | packet::EPOCH_PROOF => {
// ignore these for now, but leave them specified.
debug!(target: "pip", "Ignoring request/response for epoch proof");
Ok(())
}
other => {
Err(Error::UnrecognizedPacket(other))
}
@@ -867,6 +878,7 @@ impl LightProtocol {
match complete_req {
CompleteRequest::Headers(req) => self.provider.block_headers(req).map(Response::Headers),
CompleteRequest::HeaderProof(req) => self.provider.header_proof(req).map(Response::HeaderProof),
CompleteRequest::TransactionIndex(_) => None, // don't answer these yet, but leave them in protocol.
CompleteRequest::Body(req) => self.provider.block_body(req).map(Response::Body),
CompleteRequest::Receipts(req) => self.provider.block_receipts(req).map(Response::Receipts),
CompleteRequest::Account(req) => self.provider.account_proof(req).map(Response::Account),

View File

@@ -83,6 +83,7 @@ impl Credits {
pub struct CostTable {
base: U256, // cost per packet.
headers: U256, // cost per header
transaction_index: U256,
body: U256,
receipts: U256,
account: U256,
@@ -98,6 +99,7 @@ impl Default for CostTable {
CostTable {
base: 100000.into(),
headers: 10000.into(),
transaction_index: 10000.into(),
body: 15000.into(),
receipts: 5000.into(),
account: 25000.into(),
@@ -119,8 +121,9 @@ impl Encodable for CostTable {
s.append(cost);
}
s.begin_list(9).append(&self.base);
s.begin_list(10).append(&self.base);
append_cost(s, &self.headers, request::Kind::Headers);
append_cost(s, &self.transaction_index, request::Kind::TransactionIndex);
append_cost(s, &self.body, request::Kind::Body);
append_cost(s, &self.receipts, request::Kind::Receipts);
append_cost(s, &self.account, request::Kind::Account);
@@ -136,6 +139,7 @@ impl Decodable for CostTable {
let base = rlp.val_at(0)?;
let mut headers = None;
let mut transaction_index = None;
let mut body = None;
let mut receipts = None;
let mut account = None;
@@ -148,6 +152,7 @@ impl Decodable for CostTable {
let cost = cost_list.val_at(1)?;
match cost_list.val_at(0)? {
request::Kind::Headers => headers = Some(cost),
request::Kind::TransactionIndex => transaction_index = Some(cost),
request::Kind::Body => body = Some(cost),
request::Kind::Receipts => receipts = Some(cost),
request::Kind::Account => account = Some(cost),
@@ -163,6 +168,7 @@ impl Decodable for CostTable {
Ok(CostTable {
base: base,
headers: unwrap_cost(headers)?,
transaction_index: unwrap_cost(transaction_index)?,
body: unwrap_cost(body)?,
receipts: unwrap_cost(receipts)?,
account: unwrap_cost(account)?,
@@ -224,6 +230,7 @@ impl FlowParams {
let costs = CostTable {
base: 0.into(),
headers: cost_for_kind(Kind::Headers),
transaction_index: cost_for_kind(Kind::TransactionIndex),
body: cost_for_kind(Kind::Body),
receipts: cost_for_kind(Kind::Receipts),
account: cost_for_kind(Kind::Account),
@@ -249,6 +256,7 @@ impl FlowParams {
costs: CostTable {
base: free_cost.clone(),
headers: free_cost.clone(),
transaction_index: free_cost.clone(),
body: free_cost.clone(),
receipts: free_cost.clone(),
account: free_cost.clone(),
@@ -278,6 +286,7 @@ impl FlowParams {
match *request {
Request::Headers(ref req) => self.costs.headers * req.max.into(),
Request::HeaderProof(_) => self.costs.header_proof,
Request::TransactionIndex(_) => self.costs.transaction_index,
Request::Body(_) => self.costs.body,
Request::Receipts(_) => self.costs.receipts,
Request::Account(_) => self.costs.account,

View File

@@ -132,6 +132,7 @@ fn compute_timeout(reqs: &Requests) -> Duration {
tm + match *req {
Request::Headers(_) => timeout::HEADERS,
Request::HeaderProof(_) => timeout::HEADER_PROOF,
Request::TransactionIndex(_) => timeout::TRANSACTION_INDEX,
Request::Receipts(_) => timeout::RECEIPT,
Request::Body(_) => timeout::BODY,
Request::Account(_) => timeout::PROOF,