serve epoch signals over network and check them
This commit is contained in:
@@ -62,6 +62,7 @@ fn hardcoded_serve_time(kind: Kind) -> u64 {
|
||||
Kind::Storage => 2_000_000,
|
||||
Kind::Code => 1_500_000,
|
||||
Kind::Execution => 250, // per gas.
|
||||
Kind::Signal => 500_000,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -102,9 +102,8 @@ 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;
|
||||
// two packets were previously meant to be reserved for epoch proofs.
|
||||
// these have since been moved to requests.
|
||||
}
|
||||
|
||||
// timeouts for different kinds of requests. all values are in milliseconds.
|
||||
@@ -122,6 +121,7 @@ mod timeout {
|
||||
pub const CONTRACT_CODE: i64 = 100;
|
||||
pub const HEADER_PROOF: i64 = 100;
|
||||
pub const TRANSACTION_PROOF: i64 = 1000; // per gas?
|
||||
pub const EPOCH_SIGNAL: i64 = 200;
|
||||
}
|
||||
|
||||
/// A request id.
|
||||
@@ -582,12 +582,6 @@ 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))
|
||||
}
|
||||
@@ -950,6 +944,7 @@ impl LightProtocol {
|
||||
CompleteRequest::Storage(req) => self.provider.storage_proof(req).map(Response::Storage),
|
||||
CompleteRequest::Code(req) => self.provider.contract_code(req).map(Response::Code),
|
||||
CompleteRequest::Execution(req) => self.provider.transaction_proof(req).map(Response::Execution),
|
||||
CompleteRequest::Signal(req) => self.provider.epoch_signal(req).map(Response::Signal),
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ pub struct CostTable {
|
||||
code: U256,
|
||||
header_proof: U256,
|
||||
transaction_proof: U256, // cost per gas.
|
||||
epoch_signal: U256,
|
||||
}
|
||||
|
||||
impl Default for CostTable {
|
||||
@@ -107,6 +108,7 @@ impl Default for CostTable {
|
||||
code: 20000.into(),
|
||||
header_proof: 15000.into(),
|
||||
transaction_proof: 2.into(),
|
||||
epoch_signal: 10000.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,7 +123,7 @@ impl Encodable for CostTable {
|
||||
s.append(cost);
|
||||
}
|
||||
|
||||
s.begin_list(10).append(&self.base);
|
||||
s.begin_list(11).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);
|
||||
@@ -131,6 +133,7 @@ impl Encodable for CostTable {
|
||||
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);
|
||||
append_cost(s, &self.epoch_signal, request::Kind::Signal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,6 +150,7 @@ impl Decodable for CostTable {
|
||||
let mut code = None;
|
||||
let mut header_proof = None;
|
||||
let mut transaction_proof = None;
|
||||
let mut epoch_signal = None;
|
||||
|
||||
for cost_list in rlp.iter().skip(1) {
|
||||
let cost = cost_list.val_at(1)?;
|
||||
@@ -160,6 +164,7 @@ impl Decodable for CostTable {
|
||||
request::Kind::Code => code = Some(cost),
|
||||
request::Kind::HeaderProof => header_proof = Some(cost),
|
||||
request::Kind::Execution => transaction_proof = Some(cost),
|
||||
request::Kind::Signal => epoch_signal = Some(cost),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,6 +181,7 @@ impl Decodable for CostTable {
|
||||
code: unwrap_cost(code)?,
|
||||
header_proof: unwrap_cost(header_proof)?,
|
||||
transaction_proof: unwrap_cost(transaction_proof)?,
|
||||
epoch_signal: unwrap_cost(epoch_signal)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -238,6 +244,7 @@ impl FlowParams {
|
||||
code: cost_for_kind(Kind::Code),
|
||||
header_proof: cost_for_kind(Kind::HeaderProof),
|
||||
transaction_proof: cost_for_kind(Kind::Execution),
|
||||
epoch_signal: cost_for_kind(Kind::Signal),
|
||||
};
|
||||
|
||||
FlowParams {
|
||||
@@ -263,7 +270,8 @@ impl FlowParams {
|
||||
storage: free_cost.clone(),
|
||||
code: free_cost.clone(),
|
||||
header_proof: free_cost.clone(),
|
||||
transaction_proof: free_cost,
|
||||
transaction_proof: free_cost.clone(),
|
||||
epoch_signal: free_cost,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -293,6 +301,7 @@ impl FlowParams {
|
||||
Request::Storage(_) => self.costs.storage,
|
||||
Request::Code(_) => self.costs.code,
|
||||
Request::Execution(ref req) => self.costs.transaction_proof * req.gas,
|
||||
Request::Signal(_) => self.costs.epoch_signal,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,6 +139,7 @@ fn compute_timeout(reqs: &Requests) -> Duration {
|
||||
Request::Storage(_) => timeout::PROOF,
|
||||
Request::Code(_) => timeout::CONTRACT_CODE,
|
||||
Request::Execution(_) => timeout::TRANSACTION_PROOF,
|
||||
Request::Signal(_) => timeout::EPOCH_SIGNAL,
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -156,6 +156,12 @@ impl Provider for TestProvider {
|
||||
None
|
||||
}
|
||||
|
||||
fn epoch_signal(&self, _req: request::CompleteSignalRequest) -> Option<request::SignalResponse> {
|
||||
Some(request::SignalResponse {
|
||||
signal: vec![1, 2, 3, 4],
|
||||
})
|
||||
}
|
||||
|
||||
fn ready_transactions(&self) -> Vec<PendingTransaction> {
|
||||
self.0.client.ready_transactions()
|
||||
}
|
||||
@@ -521,6 +527,50 @@ fn get_contract_code() {
|
||||
proto.handle_packet(&expected, &1, packet::REQUEST, &request_body);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn epoch_signal() {
|
||||
let capabilities = capabilities();
|
||||
|
||||
let (provider, proto) = setup(capabilities.clone());
|
||||
let flow_params = proto.flow_params.read().clone();
|
||||
|
||||
let cur_status = status(provider.client.chain_info());
|
||||
|
||||
{
|
||||
let packet_body = write_handshake(&cur_status, &capabilities, &proto);
|
||||
proto.on_connect(&1, &Expect::Send(1, packet::STATUS, packet_body.clone()));
|
||||
proto.handle_packet(&Expect::Nothing, &1, packet::STATUS, &packet_body);
|
||||
}
|
||||
|
||||
let req_id = 112;
|
||||
let request = Request::Signal(request::IncompleteSignalRequest {
|
||||
block_hash: H256([1; 32]).into(),
|
||||
});
|
||||
|
||||
let requests = encode_single(request.clone());
|
||||
let request_body = make_packet(req_id, &requests);
|
||||
|
||||
let response = {
|
||||
let response = vec![Response::Signal(SignalResponse {
|
||||
signal: vec![1, 2, 3, 4],
|
||||
})];
|
||||
|
||||
let limit = *flow_params.limit();
|
||||
let cost = flow_params.compute_cost_multi(requests.requests());
|
||||
|
||||
println!("limit = {}, cost = {}", limit, cost);
|
||||
let new_creds = limit - cost;
|
||||
|
||||
let mut response_stream = RlpStream::new_list(3);
|
||||
response_stream.append(&req_id).append(&new_creds).append_list(&response);
|
||||
|
||||
response_stream.out()
|
||||
};
|
||||
|
||||
let expected = Expect::Respond(packet::RESPONSE, response);
|
||||
proto.handle_packet(&expected, &1, packet::REQUEST, &request_body);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn proof_of_execution() {
|
||||
let capabilities = capabilities();
|
||||
|
||||
Reference in New Issue
Block a user