Struct snarkos_node::Prover

source ·
pub struct Prover<N: Network, C: ConsensusStorage<N>> { /* private fields */ }
Expand description

A prover is a full node, capable of producing proofs for consensus.

Implementations§

source§

impl<N: Network, C: ConsensusStorage<N>> Prover<N, C>

source

pub async fn new( node_ip: SocketAddr, account: Account<N>, trusted_peers: &[SocketAddr], genesis: Block<N>, dev: Option<u16> ) -> Result<Self>

Initializes a new prover node.

Trait Implementations§

source§

impl<N: Clone + Network, C: Clone + ConsensusStorage<N>> Clone for Prover<N, C>

source§

fn clone(&self) -> Prover<N, C>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<N: Network, C: ConsensusStorage<N>> Disconnect for Prover<N, C>

source§

fn handle_disconnect<'life0, 'async_trait>( &'life0 self, peer_addr: SocketAddr ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Any extra operations to be performed during a disconnect.

source§

fn enable_disconnect<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + 'async_trait,

Attaches the behavior specified in Disconnect::handle_disconnect to every occurrence of the node disconnecting from a peer.
source§

impl<N: Network, C: ConsensusStorage<N>> Handshake for Prover<N, C>

source§

fn perform_handshake<'life0, 'async_trait>( &'life0 self, connection: Connection ) -> Pin<Box<dyn Future<Output = Result<Connection>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Performs the handshake protocol.

source§

const TIMEOUT_MS: u64 = 3_000u64

The maximum time allowed for a connection to perform a handshake before it is rejected. Read more
source§

fn enable_handshake<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + 'async_trait,

Prepares the node to perform specified network handshakes.
source§

fn borrow_stream<'a>(&self, conn: &'a mut Connection) -> &'a mut TcpStream

Borrows the full connection stream to be used in the implementation of Handshake::perform_handshake.
source§

fn take_stream(&self, conn: &mut Connection) -> TcpStream

Assumes full control of a connection’s stream in the implementation of Handshake::perform_handshake, by the end of which it must be followed by Handshake::return_stream.
source§

fn return_stream<T>(&self, conn: &mut Connection, stream: T)where T: AsyncRead + AsyncWrite + Send + Sync + 'static,

This method only needs to be called if Handshake::take_stream had been called before; it is used to return a (potentially modified) stream back to the applicable connection.
source§

impl<N: Network, C: ConsensusStorage<N>> Heartbeat<N> for Prover<N, C>

source§

const HEARTBEAT_IN_SECS: u64 = 15u64

The duration in seconds to sleep in between heartbeat executions.
source§

const MINIMUM_NUMBER_OF_PEERS: usize = 3usize

The minimum number of peers required to maintain connections with.
source§

const MEDIAN_NUMBER_OF_PEERS: usize = max(Self::MAXIMUM_NUMBER_OF_PEERS / 2, Self::MINIMUM_NUMBER_OF_PEERS)

The median number of peers to maintain connections with.
source§

const MAXIMUM_NUMBER_OF_PEERS: usize = 21usize

The maximum number of peers permitted to maintain connections with.
source§

fn heartbeat(&self)

Handles the heartbeat request.
source§

fn safety_check_minimum_number_of_peers(&self)

TODO (howardwu): Consider checking minimum number of beacons and validators, to exclude clients and provers. This function performs safety checks on the setting for the minimum number of peers.
source§

fn log_connected_peers(&self)

This function logs the connected peers.
source§

fn remove_stale_connected_peers(&self)

This function removes any connected peers that have not communicated within the predefined time.
source§

fn remove_oldest_connected_peer(&self)

This function removes the oldest connected peer, to keep the connections fresh. This function only triggers if the router is above the minimum number of connected peers.
source§

fn handle_connected_peers(&self)

TODO (howardwu): If the node is a beacon, keep the beacons, and keep 0 clients and provers. If the node is a validator, keep REDUNDANCY_FACTOR beacons. If the node is a client or prover, prioritize validators, and keep 0 beacons. This function keeps the number of connected peers within the allowed range.
source§

fn handle_bootstrap_peers(&self)

This function keeps the number of bootstrap peers within the allowed range.
source§

fn handle_trusted_peers(&self)

This function attempts to connect to any disconnected trusted peers.
source§

fn handle_puzzle_request(&self)

This function updates the coinbase puzzle if network has updated.
source§

impl<N: Network, C: ConsensusStorage<N>> Inbound<N> for Prover<N, C>

source§

fn block_request(&self, peer_ip: SocketAddr, _message: BlockRequest) -> bool

Handles a BlockRequest message.

source§

fn block_response(&self, peer_ip: SocketAddr, _blocks: Vec<Block<N>>) -> bool

Handles a BlockResponse message.

source§

fn pong(&self, peer_ip: SocketAddr, _message: Pong) -> bool

Sleeps for a period and then sends a Ping message to the peer.

source§

fn puzzle_request(&self, peer_ip: SocketAddr) -> bool

Disconnects on receipt of a PuzzleRequest message.

source§

fn puzzle_response( &self, peer_ip: SocketAddr, epoch_challenge: EpochChallenge<N>, header: Header<N> ) -> bool

Saves the latest epoch challenge and latest block header in the node.

source§

fn unconfirmed_solution<'life0, 'async_trait>( &'life0 self, peer_ip: SocketAddr, serialized: UnconfirmedSolution<N>, solution: ProverSolution<N> ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Propagates the unconfirmed solution to all connected validators.

source§

fn unconfirmed_transaction( &self, _peer_ip: SocketAddr, _serialized: UnconfirmedTransaction<N>, _transaction: Transaction<N> ) -> bool

Handles an UnconfirmedTransaction message.

source§

const MAXIMUM_PUZZLE_REQUESTS_PER_INTERVAL: usize = 5usize

The maximum number of puzzle requests per interval.
source§

const PING_SLEEP_IN_SECS: u64 = 9u64

The duration in seconds to sleep in between ping requests with a connected peer.
source§

fn inbound<'life0, 'async_trait>( &'life0 self, peer_addr: SocketAddr, message: Message<N> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + 'async_trait,

Handles the inbound message from the peer.
source§

fn beacon_propose( &self, _peer_ip: SocketAddr, _serialized: BeaconPropose<N>, _block: Block<N> ) -> bool

Handles a BeaconPropose message.
source§

fn peer_request(&self, peer_ip: SocketAddr) -> bool

Handles a PeerRequest message.
source§

fn peer_response(&self, _peer_ip: SocketAddr, peers: &[SocketAddr]) -> bool

Handles a PeerResponse message.
source§

fn ping(&self, peer_ip: SocketAddr, message: Ping<N>) -> bool

source§

impl<N: Network, C: ConsensusStorage<N>> NodeInterface<N> for Prover<N, C>

source§

fn shut_down<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Shuts down the node.

source§

fn node_type(&self) -> NodeType

Returns the node type.
source§

fn private_key(&self) -> &PrivateKey<N>

Returns the account private key of the node.
source§

fn view_key(&self) -> &ViewKey<N>

Returns the account view key of the node.
source§

fn address(&self) -> Address<N>

Returns the account address of the node.
source§

fn is_dev(&self) -> bool

Returns true if the node is in development mode.
source§

fn handle_signals(&self)

Handles OS signals for the node to intercept and perform a clean shutdown. Note: Only Ctrl-C is supported; it should work on both Unix-family systems and Windows.
source§

impl<N: Network, C: ConsensusStorage<N>> OnConnect for Prover<N, C>where Self: Outbound<N>,

source§

fn on_connect<'life0, 'async_trait>( &'life0 self, peer_addr: SocketAddr ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Any initial actions to be executed after the handshake is concluded; in order to be able to communicate with the peer in the usual manner (i.e. via [Writing]), only its SocketAddr (as opposed to the related [Connection] object) is provided as an argument.
source§

fn enable_on_connect<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + 'async_trait,

Attaches the behavior specified in OnConnect::on_connect right after every successful handshake.
source§

impl<N: Network, C: ConsensusStorage<N>> Outbound<N> for Prover<N, C>

source§

fn router(&self) -> &Router<N>

Returns a reference to the router.

source§

fn send_ping( &self, peer_ip: SocketAddr, block_locators: Option<BlockLocators<N>> )

Sends a “Ping” message to the given peer.
source§

fn send( &self, peer_ip: SocketAddr, message: Message<N> ) -> Option<Receiver<Result<(), Error>>>

Sends the given message to specified peer. Read more
source§

fn propagate(&self, message: Message<N>, excluded_peers: &[SocketAddr])

Sends the given message to every connected peer, excluding the sender and any specified peer IPs.
source§

fn propagate_to_beacons( &self, message: Message<N>, excluded_peers: &[SocketAddr] )

Sends the given message to every connected beacon, excluding the sender and any specified IPs.
source§

fn propagate_to_validators( &self, message: Message<N>, excluded_peers: &[SocketAddr] )

Sends the given message to every connected validator, excluding the sender and any specified IPs.
source§

fn can_send(&self, peer_ip: SocketAddr, message: &Message<N>) -> bool

Returns true if the message can be sent.
source§

impl<N: Network, C: ConsensusStorage<N>> P2P for Prover<N, C>

source§

fn tcp(&self) -> &Tcp

Returns a reference to the TCP instance.

source§

impl<N: Network, C: ConsensusStorage<N>> Reading for Prover<N, C>

source§

fn codec(&self, _peer_addr: SocketAddr, _side: ConnectionSide) -> Self::Codec

Creates a [Decoder] used to interpret messages from the network. The side param indicates the connection side from the node’s perspective.

source§

fn process_message<'life0, 'async_trait>( &'life0 self, peer_addr: SocketAddr, message: Self::Message ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Processes a message received from the network.

§

type Codec = MessageCodec<N>

The user-supplied Decoder used to interpret inbound messages.
§

type Message = Message<N>

The final (deserialized) type of inbound messages.
source§

const MESSAGE_QUEUE_DEPTH: usize = 1_024usize

The depth of per-connection queues used to process inbound messages; the greater it is, the more inbound messages the node can enqueue, but setting it to a large value can make the node more susceptible to DoS attacks. Read more
source§

const INITIAL_BUFFER_SIZE: usize = 1_048_576usize

The initial size of a per-connection buffer for reading inbound messages. Can be set to the maximum expected size of the inbound message in order to only allocate it once. Read more
source§

fn enable_reading<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + 'async_trait,

Prepares the node to receive messages.
source§

impl<N: Network, C: ConsensusStorage<N>> Routing<N> for Prover<N, C>

source§

fn initialize_routing<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + 'async_trait,

Initialize the routing.
source§

fn enable_listener<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + 'async_trait,

source§

fn initialize_heartbeat(&self)

Initialize a new instance of the heartbeat.
source§

fn initialize_report(&self)

Initialize a new instance of the report.
source§

impl<N: Network, C: ConsensusStorage<N>> Writing for Prover<N, C>

source§

fn codec(&self, _addr: SocketAddr, _side: ConnectionSide) -> Self::Codec

Creates an [Encoder] used to write the outbound messages to the target stream. The side parameter indicates the connection side from the node’s perspective.

§

type Codec = MessageCodec<N>

The user-supplied Encoder used to write outbound messages to the target stream.
§

type Message = Message<N>

The type of the outbound messages; unless their serialization is expensive and the message is broadcasted (in which case it would get serialized multiple times), serialization should be done in the implementation of Self::Codec.
source§

const MESSAGE_QUEUE_DEPTH: usize = 1_024usize

The depth of per-connection queues used to send outbound messages; the greater it is, the more outbound messages the node can enqueue. Setting it to a large value is not recommended, as doing it might obscure potential issues with your implementation (like slow serialization) or network. Read more
source§

fn enable_writing<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + 'async_trait,

Prepares the node to send messages.
source§

fn unicast( &self, addr: SocketAddr, message: Self::Message ) -> Result<Receiver<Result<(), Error>>, Error>

Sends the provided message to the specified SocketAddr. Returns as soon as the message is queued to be sent, without waiting for the actual delivery; instead, the caller is provided with a oneshot::Receiver which can be used to determine when and whether the message has been delivered. Read more

Auto Trait Implementations§

§

impl<N, C> !RefUnwindSafe for Prover<N, C>

§

impl<N, C> Send for Prover<N, C>

§

impl<N, C> Sync for Prover<N, C>

§

impl<N, C> Unpin for Prover<N, C>where C: Unpin, N: Unpin, <N as Network>::BlockHash: Unpin, <N as Environment>::Field: Unpin, <<N as Environment>::PairingCurve as PairingEngine>::G1Affine: Unpin, <N as Environment>::Projective: Unpin, <N as Environment>::Scalar: Unpin, <N as Network>::StateRoot: Unpin, <N as Network>::TransactionID: Unpin, <N as Network>::TransitionID: Unpin,

§

impl<N, C> !UnwindSafe for Prover<N, C>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for Twhere T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more