pub struct UtreexoNode<Chain: ChainBackend, Context = RunningNode> { /* private fields */ }Expand description
The main node that operates while florestad is up.
UtreexoNode aims to be modular where Chain can be any implementation
of a ChainBackend.
Context refers to which state the UtreexoNode is on, being
RunningNode, SyncNode, and ChainSelector. Defaults to
RunningNode which automatically transitions between contexts.
Implementations§
Source§impl<Chain> UtreexoNode<Chain, ChainSelector>where
Chain: ChainBackend + 'static,
WireError: From<Chain::Error>,
Chain::Error: From<UtreexoLeafError>,
impl<Chain> UtreexoNode<Chain, ChainSelector>where
Chain: ChainBackend + 'static,
WireError: From<Chain::Error>,
Chain::Error: From<UtreexoLeafError>,
Source§impl<T, Chain> UtreexoNode<Chain, T>where
T: 'static + Default + NodeContext,
Chain: ChainBackend + 'static,
WireError: From<Chain::Error>,
impl<T, Chain> UtreexoNode<Chain, T>where
T: 'static + Default + NodeContext,
Chain: ChainBackend + 'static,
WireError: From<Chain::Error>,
pub fn new( config: UtreexoNodeConfig, chain: Chain, mempool: Arc<Mutex<Mempool>>, block_filters: Option<Arc<NetworkFilters<FlatFiltersStore>>>, kill_signal: Arc<RwLock<bool>>, address_man: AddressMan, ) -> Result<Self, WireError>
Sourcepub fn get_handle(&self) -> NodeInterface
pub fn get_handle(&self) -> NodeInterface
Returns a handle to the node interface that we can use to request data from our node. This struct is thread safe, so we can use it from multiple threads and have multiple handles. It also doesn’t require a mutable reference to the node, or any synchronization mechanism.
Sourcepub async fn handle_addnode_add_peer(
&mut self,
addr: IpAddr,
port: u16,
v2_transport: bool,
) -> Result<(), WireError>
pub async fn handle_addnode_add_peer( &mut self, addr: IpAddr, port: u16, v2_transport: bool, ) -> Result<(), WireError>
Handles addnode-RPC Add requests, adding a new peer to the added_peers list. This means
the peer is marked as a “manually added peer”. We then try to connect to it, or retry later.
Sourcepub fn handle_addnode_remove_peer(
&mut self,
addr: IpAddr,
port: u16,
) -> Result<(), WireError>
pub fn handle_addnode_remove_peer( &mut self, addr: IpAddr, port: u16, ) -> Result<(), WireError>
Handles remove node requests, removing a peer from the node.
Removes a node from the [added_peers] list but does not
disconnect the node if it was already connected. It only ensures
that the node is no longer treated as a manually added node
(i.e., it won’t be reconnected if disconnected).
If someone wants to remove a peer, it should be done using the
disconnectnode.
Sourcepub async fn handle_addnode_onetry_peer(
&mut self,
addr: IpAddr,
port: u16,
v2_transport: bool,
) -> Result<(), WireError>
pub async fn handle_addnode_onetry_peer( &mut self, addr: IpAddr, port: u16, v2_transport: bool, ) -> Result<(), WireError>
Handles addnode onetry requests, connecting to the node and this will try to connect to the given address and port. If it’s successful, it will add the node to the peers list, but not to the added_peers list (e.g., it won’t be reconnected if disconnected).
Source§impl<Chain> UtreexoNode<Chain, RunningNode>where
Chain: ThreadSafeChain + Clone,
WireError: From<Chain::Error>,
Chain::Error: From<UtreexoLeafError>,
impl<Chain> UtreexoNode<Chain, RunningNode>where
Chain: ThreadSafeChain + Clone,
WireError: From<Chain::Error>,
Chain::Error: From<UtreexoLeafError>,
Sourcepub async fn catch_up(self) -> Result<Self, WireError>
pub async fn catch_up(self) -> Result<Self, WireError>
Every time we restart the node, we’ll be a few blocks behind the tip. This function will start a sync node that will request, download and validate all blocks from the last validation index to the tip. This function will block until the sync node is finished.
On the first startup, if we use either assumeutreexo or pow fraud proofs, this function will only download the blocks that are after the one that got assumed. So, for PoW fraud proofs, this means the last 100 blocks, and for assumeutreexo, this means however many blocks from the hard-coded value in the config file.
Sourcepub fn backfill(&self, done_flag: Sender<()>) -> Result<bool, WireError>
pub fn backfill(&self, done_flag: Sender<()>) -> Result<bool, WireError>
If either PoW fraud proofs or assumeutreexo are enabled, we will “skip” IBD for all historical blocks. This allow us to start the node faster, making it usable in a few minutes. If you still want to validate all blocks, you can enable the backfill option.
This function will spawn a background task that will download and validate all blocks that got assumed. After completion, the task will shutdown and the node will continue running normally. If we ever assume an invalid chain, the node will halt and catch fire.
pub async fn run(self, stop_signal: Sender<()>)
Source§impl<Chain> UtreexoNode<Chain, SyncNode>
Node methods for a UtreexoNode where its Context is a SyncNode.
See node for more information.
impl<Chain> UtreexoNode<Chain, SyncNode>
Node methods for a UtreexoNode where its Context is a SyncNode.
See node for more information.
Sourcepub async fn run(self, done_cb: impl FnOnce(&Chain)) -> Self
pub async fn run(self, done_cb: impl FnOnce(&Chain)) -> Self
Starts the sync node by updating the last block requested and starting the main loop. This loop to the following tasks, in order: - Receives messages from our peers through the node_tx channel. - Handles the message received. - Checks if the kill signal is set, if so, breaks the loop. - Checks if the chain is in IBD and disables it if it’s not (e.g. if the chain is synced). - Checks if our tip is obsolete and requests a new one, creating a new connection. - Handles timeouts for inflight requests. - If were low on inflights, requests new blocks to validate.
Trait Implementations§
Source§impl<Chain: ChainBackend, T> Deref for UtreexoNode<Chain, T>
impl<Chain: ChainBackend, T> Deref for UtreexoNode<Chain, T>
Source§impl<T, Chain: ChainBackend> DerefMut for UtreexoNode<Chain, T>
impl<T, Chain: ChainBackend> DerefMut for UtreexoNode<Chain, T>
Auto Trait Implementations§
impl<Chain, Context> Freeze for UtreexoNode<Chain, Context>
impl<Chain, Context = RunningNode> !RefUnwindSafe for UtreexoNode<Chain, Context>
impl<Chain, Context> Send for UtreexoNode<Chain, Context>
impl<Chain, Context> Sync for UtreexoNode<Chain, Context>
impl<Chain, Context> Unpin for UtreexoNode<Chain, Context>
impl<Chain, Context = RunningNode> !UnwindSafe for UtreexoNode<Chain, Context>
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