Crate floresta_wire
source ·Expand description
Floresta Wire
This crate provides the core networking logic for a full node using libfloresta,
including the P2P network and the mempool. You can easily integrate it with any
other crate that provides a BlockchainInterface
and UpdatableChainstate
implementation.
A node also gives you a handle
that you can use to send messages to the node,
like requesting blocks, mempool transactions or asking to connect with a given
peer.
Modules
- Address manager is a module that keeps track of known peer addresses and associated metadata. This module is very important in keeping our node protected against targeted attacks, like eclipse attacks.
- A simple mempool that keeps our transactions in memory. It try to rebroadcast our transactions every 1 hour. Once our transaction is included in a block, we remove it from the mempool.
- Main file for this blockchain. A node is the central task that runs and handles important events, such as new blocks, peer connection/disconnection, new addresses, etc. A node should not care about peer-specific messages, peers’ll handle things like pings.
- During the lifetime of a Bitcoin client, we have a couple of phases that are slightly different from each other, having to implement their own state-machines and logic for handing requests. While we could simply put everything in one struct and have a single
impl
block, that would create a massive amount of if’s in the code, taking different paths depending on which state are we in. For that reason, we define the basics of a node, like code shared by all the states into one base struct calledUtreexoNode
, we then further refine this struct using fine-tunnedContexts
, that should implement NodeContext and are passed-in as a generic parameter by the caller.
Structs
- Configuration for the Utreexo node.
Traits
- NodeHooks is a trait that defines the hooks that a node can use to interact with the network and the blockchain. Every time an event happens, the node will call the corresponding hook.