Allow sync to to request block bodies.

This commit is contained in:
Paul Hauner
2019-03-23 13:23:44 +11:00
parent 96ba1c8f77
commit 4b5b5851a6
7 changed files with 305 additions and 33 deletions

View File

@@ -8,7 +8,9 @@ use beacon_chain::{
CheckPoint,
};
use eth2_libp2p::HelloMessage;
use types::{BeaconStateError, Epoch, Hash256, Slot};
use types::{BeaconBlock, BeaconStateError, Epoch, Hash256, Slot};
pub use beacon_chain::BeaconChainError;
/// The network's API to the beacon chain.
pub trait BeaconChain: Send + Sync {
@@ -20,6 +22,8 @@ pub trait BeaconChain: Send + Sync {
fn head(&self) -> RwLockReadGuard<CheckPoint>;
fn get_block(&self, block_root: &Hash256) -> Result<Option<BeaconBlock>, BeaconChainError>;
fn best_slot(&self) -> Slot;
fn best_block_root(&self) -> Hash256;
@@ -35,6 +39,8 @@ pub trait BeaconChain: Send + Sync {
start_slot: Slot,
count: Slot,
) -> Result<Vec<Hash256>, BeaconStateError>;
fn is_new_block_root(&self, beacon_block_root: &Hash256) -> Result<bool, BeaconChainError>;
}
impl<T, U, F> BeaconChain for RawBeaconChain<T, U, F>
@@ -59,6 +65,10 @@ where
self.head()
}
fn get_block(&self, block_root: &Hash256) -> Result<Option<BeaconBlock>, BeaconChainError> {
self.get_block(block_root)
}
fn finalized_epoch(&self) -> Epoch {
self.get_state().finalized_epoch
}
@@ -95,4 +105,8 @@ where
) -> Result<Vec<Hash256>, BeaconStateError> {
self.get_block_roots(start_slot, count)
}
fn is_new_block_root(&self, beacon_block_root: &Hash256) -> Result<bool, BeaconChainError> {
self.is_new_block_root(beacon_block_root)
}
}