Availability/Extrinsic store (#465)

This commit is contained in:
Robert Habermeier
2018-08-06 11:55:55 +02:00
committed by Benjamin Kampmann
parent 13585cc9cc
commit 21346f34f8
25 changed files with 717 additions and 55 deletions
+17
View File
@@ -65,6 +65,12 @@ pub trait ChainHead<Block: BlockT> {
fn best_block_header(&self) -> Result<<Block as BlockT>::Header, error::Error>;
}
/// Fetch block body by ID.
pub trait BlockBody<Block: BlockT> {
/// Get block body by ID. Returns `None` if the body is not stored.
fn block_body(&self, id: &BlockId<Block>) -> error::Result<Option<Vec<<Block as BlockT>::Extrinsic>>>;
}
/// Client info
// TODO: split queue info from chain info and amalgamate into single struct.
#[derive(Debug)]
@@ -560,6 +566,17 @@ impl<B, E, Block> ChainHead<Block> for Client<B, E, Block>
}
}
impl<B, E, Block> BlockBody<Block> for Client<B, E, Block>
where
B: backend::Backend<Block>,
E: CallExecutor<Block>,
Block: BlockT,
{
fn block_body(&self, id: &BlockId<Block>) -> error::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
self.body(id)
}
}
#[cfg(test)]
mod tests {
use super::*;
+1 -1
View File
@@ -57,7 +57,7 @@ pub use blockchain::Info as ChainInfo;
pub use call_executor::{CallResult, CallExecutor, LocalCallExecutor};
pub use client::{
new_in_mem,
BlockStatus, BlockOrigin, BlockchainEventStream, BlockchainEvents,
BlockBody, BlockStatus, BlockOrigin, BlockchainEventStream, BlockchainEvents,
Client, ClientInfo, ChainHead,
ImportResult, JustifiedHeader,
};
+24
View File
@@ -294,6 +294,20 @@ impl Encode for () {
}
}
impl<'a, T: 'a + Encode + ?Sized> Encode for &'a T {
fn encode_to<D: Output>(&self, dest: &mut D) {
(&**self).encode_to(dest)
}
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
(&**self).using_encoded(f)
}
fn encode(&self) -> Vec<u8> {
(&**self).encode()
}
}
impl Decode for () {
fn decode<I: Input>(_: &mut I) -> Option<()> {
Some(())
@@ -477,4 +491,14 @@ mod tests {
assert_eq!(slice, &b"\x0b\0\0\0Hello world")
);
}
#[test]
fn encode_borrowed_tuple() {
let x = vec![1u8, 2, 3, 4];
let y = 128i64;
let encoded = (&x, &y).encode();
assert_eq!((x, y), Decode::decode(&mut &encoded[..]).unwrap());
}
}
+7
View File
@@ -86,6 +86,7 @@ pub struct Service<Components: components::Components> {
network: Arc<components::NetworkService<Components::Factory>>,
extrinsic_pool: Arc<Components::ExtrinsicPool>,
keystore: Keystore,
exit: ::exit_future::Exit,
signal: Option<Signal>,
_rpc_http: Option<rpc::HttpServer>,
_rpc_ws: Option<rpc::WsServer>,
@@ -246,6 +247,7 @@ impl<Components> Service<Components>
extrinsic_pool: extrinsic_pool,
signal: Some(signal),
keystore: keystore,
exit,
_rpc_http: rpc_http,
_rpc_ws: rpc_ws,
_telemetry: telemetry,
@@ -271,6 +273,11 @@ impl<Components> Service<Components>
pub fn keystore(&self) -> &Keystore {
&self.keystore
}
/// Get a handle to a future that will resolve on exit.
pub fn on_exit(&self) -> ::exit_future::Exit {
self.exit.clone()
}
}
impl<Components> Drop for Service<Components> where Components: components::Components {