pub(crate) struct BlockSyncClient<N: Network> {
config: BlockSyncClientConfiguration,
receiver: BlockSyncClientStub,
sender: SenderHandle<N>,
validator_set_update_handle: ValidatorSetUpdateHandle<N>,
block_sync_client_state: BlockSyncClientState,
event_publisher: Option<Sender<Event>>,
}
Fields§
§config: BlockSyncClientConfiguration
§receiver: BlockSyncClientStub
§sender: SenderHandle<N>
§validator_set_update_handle: ValidatorSetUpdateHandle<N>
§block_sync_client_state: BlockSyncClientState
§event_publisher: Option<Sender<Event>>
Implementations§
source§impl<N: Network> BlockSyncClient<N>
impl<N: Network> BlockSyncClient<N>
sourcepub(crate) fn new(
config: BlockSyncClientConfiguration,
receiver: BlockSyncClientStub,
sender: SenderHandle<N>,
validator_set_update_handle: ValidatorSetUpdateHandle<N>,
event_publisher: Option<Sender<Event>>,
) -> Self
pub(crate) fn new( config: BlockSyncClientConfiguration, receiver: BlockSyncClientStub, sender: SenderHandle<N>, validator_set_update_handle: ValidatorSetUpdateHandle<N>, event_publisher: Option<Sender<Event>>, ) -> Self
Create a new instance of the BlockSyncClient.
sourcepub(crate) fn on_receive_msg<K: KVStore>(
&mut self,
msg: BlockSyncAdvertiseMessage,
origin: &VerifyingKey,
block_tree: &mut BlockTreeSingleton<K>,
app: &mut impl App<K>,
) -> Result<(), BlockSyncClientError>
pub(crate) fn on_receive_msg<K: KVStore>( &mut self, msg: BlockSyncAdvertiseMessage, origin: &VerifyingKey, block_tree: &mut BlockTreeSingleton<K>, app: &mut impl App<K>, ) -> Result<(), BlockSyncClientError>
Process a received BlockSyncAdvertiseMessage
.
sourcepub(crate) fn tick<K: KVStore>(
&mut self,
block_tree: &mut BlockTreeSingleton<K>,
app: &mut impl App<K>,
) -> Result<(), BlockSyncClientError>
pub(crate) fn tick<K: KVStore>( &mut self, block_tree: &mut BlockTreeSingleton<K>, app: &mut impl App<K>, ) -> Result<(), BlockSyncClientError>
Update the BlockSyncClient
’s internal state, and possibly trigger sync on reaching sync trigger
timeout.
sourcefn on_receive_advertise_block<K: KVStore>(
&mut self,
advertise_block: AdvertiseBlock,
origin: &VerifyingKey,
block_tree: &BlockTreeSingleton<K>,
) -> Result<(), BlockSyncClientError>
fn on_receive_advertise_block<K: KVStore>( &mut self, advertise_block: AdvertiseBlock, origin: &VerifyingKey, block_tree: &BlockTreeSingleton<K>, ) -> Result<(), BlockSyncClientError>
Process an AdvertiseBlock
message. This can lead to registering the sender as an available sync
server and storing information on the server’s claimed highest committed block height.
sourcefn on_receive_advertise_pc<K: KVStore>(
&mut self,
advertise_pc: AdvertisePC,
origin: &VerifyingKey,
block_tree: &mut BlockTreeSingleton<K>,
app: &mut impl App<K>,
) -> Result<(), BlockSyncClientError>
fn on_receive_advertise_pc<K: KVStore>( &mut self, advertise_pc: AdvertisePC, origin: &VerifyingKey, block_tree: &mut BlockTreeSingleton<K>, app: &mut impl App<K>, ) -> Result<(), BlockSyncClientError>
Process an AdvertisePC
message. This can lead to triggering sync if the criteria for event-based
sync trigger are met.
sourcefn sync<K: KVStore>(
&mut self,
block_tree: &mut BlockTreeSingleton<K>,
app: &mut impl App<K>,
) -> Result<(), BlockSyncClientError>
fn sync<K: KVStore>( &mut self, block_tree: &mut BlockTreeSingleton<K>, app: &mut impl App<K>, ) -> Result<(), BlockSyncClientError>
Sync with a randomly selected peer.
sourcefn sync_with<K: KVStore>(
&mut self,
peer: &VerifyingKey,
block_tree: &mut BlockTreeSingleton<K>,
app: &mut impl App<K>,
) -> Result<(), BlockSyncClientError>
fn sync_with<K: KVStore>( &mut self, peer: &VerifyingKey, block_tree: &mut BlockTreeSingleton<K>, app: &mut impl App<K>, ) -> Result<(), BlockSyncClientError>
Sync with a given peer. This involves possibly multiple iterations of:
- Sending a sync request to the peer for a given number of blocks,
- Waiting for a response from the peer,
- Processing the response: validating blocks, inserting into the block tree, performing related block tree and app state updates.
As part of this process, a sync peer can be blacklisted if:
- It sends an incorrect or unsafe block,
- It sends a block that is not validated by the App,
- It fails to provide the minimum number of blocks it committed to providing through AdvertiseBlock.
Auto Trait Implementations§
impl<N> Freeze for BlockSyncClient<N>where
N: Freeze,
impl<N> RefUnwindSafe for BlockSyncClient<N>where
N: RefUnwindSafe,
impl<N> Send for BlockSyncClient<N>
impl<N> !Sync for BlockSyncClient<N>
impl<N> Unpin for BlockSyncClient<N>where
N: Unpin,
impl<N> UnwindSafe for BlockSyncClient<N>where
N: UnwindSafe,
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
Mutably borrows from an owned value. Read more