pub struct PartialChainState(/* private fields */);Expand description
A partial chain is a chain that only contains a subset of the blocks in the full chain. We use multiple partial chains to sync up with the full chain, and then merge them together to get the full chain. This allows us to conduct the sync in parallel. To build one, we need to know the initial height, the final height, and the block headers in between.
We need to modify our current state as-we-go, but we also need to use the main traits that define a chainstate. Most cruccially, both crates don’t take a mutable reference in any method, so we need some form of interior mutability. We could just use a mutex, but this is not required and very wateful. Partial chains differ from the normal chain because they only have one owner, the worker responsible for driving this chain to it’s completion. Because of that, we can simply use a UnsafeCell and forbid shared access between threads by not implementing Clone.
Implementations§
Source§impl PartialChainState
impl PartialChainState
Sourcepub fn list_blocks(&self) -> &[BlockHeader]
pub fn list_blocks(&self) -> &[BlockHeader]
Returns all blocks in this partial chain
Sourcepub fn list_valid_blocks(&self) -> Vec<&BlockHeader>
pub fn list_valid_blocks(&self) -> Vec<&BlockHeader>
Returns all block we have validated so far in this chain
Sourcepub fn has_invalid_blocks(&self) -> bool
pub fn has_invalid_blocks(&self) -> bool
Returns whether any block inside this interval is invalid
Trait Implementations§
Source§impl BlockchainInterface for PartialChainState
impl BlockchainInterface for PartialChainState
type Error = BlockchainError
fn get_params(&self) -> Params
fn acc(&self) -> Stump
Source§fn get_block_hash(&self, height: u32) -> Result<BlockHash, BlockchainError>
fn get_block_hash(&self, height: u32) -> Result<BlockHash, BlockchainError>
Source§fn get_best_block(&self) -> Result<(u32, BlockHash), Self::Error>
fn get_best_block(&self) -> Result<(u32, BlockHash), Self::Error>
Source§fn is_coinbase_mature(
&self,
height: u32,
_block: BlockHash,
) -> Result<bool, Self::Error>
fn is_coinbase_mature( &self, height: u32, _block: BlockHash, ) -> Result<bool, Self::Error>
Source§fn get_validation_index(&self) -> Result<u32, Self::Error>
fn get_validation_index(&self) -> Result<u32, Self::Error>
Source§fn get_block_header(
&self,
_height: &BlockHash,
) -> Result<BlockHeader, Self::Error>
fn get_block_header( &self, _height: &BlockHash, ) -> Result<BlockHeader, Self::Error>
hashfn get_chain_tips(&self) -> Result<Vec<BlockHash>, Self::Error>
fn validate_block( &self, _block: &Block, _proof: Proof, _inputs: HashMap<OutPoint, UtxoData>, _del_hashes: Vec<Hash>, _acc: Stump, ) -> Result<(), Self::Error>
fn get_fork_point(&self, _block: BlockHash) -> Result<BlockHash, Self::Error>
fn update_acc( &self, _acc: Stump, _block: UtreexoBlock, _height: u32, _proof: Proof, _del_hashes: Vec<Hash>, ) -> Result<Stump, Self::Error>
Source§fn get_block_locator_for_tip(
&self,
_tip: BlockHash,
) -> Result<Vec<BlockHash>, BlockchainError>
fn get_block_locator_for_tip( &self, _tip: BlockHash, ) -> Result<Vec<BlockHash>, BlockchainError>
Source§fn get_block(&self, _hash: &BlockHash) -> Result<Block, Self::Error>
fn get_block(&self, _hash: &BlockHash) -> Result<Block, Self::Error>
hash if any.Source§fn get_tx(&self, _txid: &Txid) -> Result<Option<Transaction>, Self::Error>
fn get_tx(&self, _txid: &Txid) -> Result<Option<Transaction>, Self::Error>
Source§fn broadcast(&self, _tx: &Transaction) -> Result<(), Self::Error>
fn broadcast(&self, _tx: &Transaction) -> Result<(), Self::Error>
Source§fn subscribe(&self, _tx: Arc<dyn BlockConsumer>)
fn subscribe(&self, _tx: Arc<dyn BlockConsumer>)
Source§fn estimate_fee(&self, _target: usize) -> Result<f64, Self::Error>
fn estimate_fee(&self, _target: usize) -> Result<f64, Self::Error>
target blocks.Source§fn get_block_height(
&self,
_hash: &BlockHash,
) -> Result<Option<u32>, Self::Error>
fn get_block_height( &self, _hash: &BlockHash, ) -> Result<Option<u32>, Self::Error>
Source§fn get_unbroadcasted(&self) -> Vec<Transaction>
fn get_unbroadcasted(&self) -> Vec<Transaction>
Source§impl UpdatableChainstate for PartialChainState
impl UpdatableChainstate for PartialChainState
Source§fn connect_block(
&self,
block: &Block,
proof: Proof,
inputs: HashMap<OutPoint, UtxoData>,
del_hashes: Vec<Hash>,
) -> Result<u32, BlockchainError>
fn connect_block( &self, block: &Block, proof: Proof, inputs: HashMap<OutPoint, UtxoData>, del_hashes: Vec<Hash>, ) -> Result<u32, BlockchainError>
Source§fn get_root_hashes(&self) -> Vec<BitcoinNodeHash>
fn get_root_hashes(&self) -> Vec<BitcoinNodeHash>
Source§fn flush(&self) -> Result<(), BlockchainError>
fn flush(&self) -> Result<(), BlockchainError>
Source§fn toggle_ibd(&self, _is_ibd: bool)
fn toggle_ibd(&self, _is_ibd: bool)
Source§fn accept_header(&self, _header: BlockHeader) -> Result<(), BlockchainError>
fn accept_header(&self, _header: BlockHeader) -> Result<(), BlockchainError>
fn switch_chain(&self, _new_tip: BlockHash) -> Result<(), BlockchainError>
Source§fn get_partial_chain(
&self,
_initial_height: u32,
_final_height: u32,
_acc: Stump,
) -> Result<PartialChainState, BlockchainError>
fn get_partial_chain( &self, _initial_height: u32, _final_height: u32, _acc: Stump, ) -> Result<PartialChainState, BlockchainError>
Source§fn invalidate_block(&self, _block: BlockHash) -> Result<(), BlockchainError>
fn invalidate_block(&self, _block: BlockHash) -> Result<(), BlockchainError>
Source§fn handle_transaction(&self) -> Result<(), BlockchainError>
fn handle_transaction(&self) -> Result<(), BlockchainError>
Source§fn mark_chain_as_assumed(
&self,
_acc: Stump,
_tip: BlockHash,
) -> Result<bool, BlockchainError>
fn mark_chain_as_assumed( &self, _acc: Stump, _tip: BlockHash, ) -> Result<bool, BlockchainError>
Source§fn mark_block_as_valid(&self, _block: BlockHash) -> Result<(), BlockchainError>
fn mark_block_as_valid(&self, _block: BlockHash) -> Result<(), BlockchainError>
impl Send for PartialChainState
We need to send PartialChainState between threads/tasks, because the worker thread, once it finishes, needs to notify the main task and pass the final partial chain.
§Safety
All items inside the UnsafeCell are Send, most importantly, there are no references or smart pointers inside it, so sending shouldn’t be a problem.
impl Sync for PartialChainState
Auto Trait Implementations§
impl !Freeze for PartialChainState
impl !RefUnwindSafe for PartialChainState
impl Unpin for PartialChainState
impl UnwindSafe for PartialChainState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more