2025-01-09 01:26:25 -05:00
|
|
|
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
|
|
|
|
#![doc = include_str!("../README.md")]
|
|
|
|
|
#![deny(missing_docs)]
|
|
|
|
|
|
2025-01-08 17:01:37 -05:00
|
|
|
use core::future::Future;
|
2025-01-03 13:04:27 -05:00
|
|
|
|
2025-01-08 17:01:37 -05:00
|
|
|
use borsh::{BorshSerialize, BorshDeserialize};
|
2025-01-07 18:09:25 -05:00
|
|
|
|
2025-01-08 17:01:37 -05:00
|
|
|
use serai_client::{primitives::NetworkId, validator_sets::primitives::ValidatorSet};
|
2025-01-07 15:36:06 -05:00
|
|
|
|
2025-01-08 19:39:09 -05:00
|
|
|
use tokio::sync::oneshot;
|
|
|
|
|
|
|
|
|
|
use serai_cosign::SignedCosign;
|
|
|
|
|
|
2025-01-04 22:21:23 -05:00
|
|
|
/// The heartbeat task, effecting sync of Tributaries
|
2025-01-09 01:26:25 -05:00
|
|
|
pub mod heartbeat;
|
2025-01-03 13:04:27 -05:00
|
|
|
|
2025-01-08 17:01:37 -05:00
|
|
|
/// A tributary block and its commit.
|
|
|
|
|
#[derive(Clone, BorshSerialize, BorshDeserialize)]
|
2025-01-09 01:26:25 -05:00
|
|
|
pub struct TributaryBlockWithCommit {
|
|
|
|
|
/// The serialized block.
|
|
|
|
|
pub block: Vec<u8>,
|
|
|
|
|
/// The serialized commit.
|
|
|
|
|
pub commit: Vec<u8>,
|
2025-01-03 13:04:27 -05:00
|
|
|
}
|
2025-01-04 22:21:23 -05:00
|
|
|
|
2025-01-09 01:26:25 -05:00
|
|
|
/// A representation of a peer.
|
|
|
|
|
pub trait Peer<'a>: Send {
|
|
|
|
|
/// Send a heartbeat to this peer.
|
2025-01-08 17:01:37 -05:00
|
|
|
fn send_heartbeat(
|
|
|
|
|
&self,
|
|
|
|
|
set: ValidatorSet,
|
|
|
|
|
latest_block_hash: [u8; 32],
|
2025-01-08 17:40:08 -05:00
|
|
|
) -> impl Send + Future<Output = Option<Vec<TributaryBlockWithCommit>>>;
|
2025-01-04 22:21:23 -05:00
|
|
|
}
|
2025-01-04 23:28:29 -05:00
|
|
|
|
2025-01-09 01:26:25 -05:00
|
|
|
/// The representation of the P2P network.
|
|
|
|
|
pub trait P2p: Send + Sync + Clone + tributary::P2p + serai_cosign::RequestNotableCosigns {
|
|
|
|
|
/// The representation of a peer.
|
2025-01-08 17:40:08 -05:00
|
|
|
type Peer<'a>: Peer<'a>;
|
2025-01-08 19:39:09 -05:00
|
|
|
|
|
|
|
|
/// Fetch the peers for this network.
|
2025-01-08 17:40:08 -05:00
|
|
|
fn peers(&self, network: NetworkId) -> impl Send + Future<Output = Vec<Self::Peer<'_>>>;
|
2025-01-08 19:39:09 -05:00
|
|
|
|
|
|
|
|
/// A cancel-safe future for the next heartbeat received over the P2P network.
|
|
|
|
|
///
|
|
|
|
|
/// Yields the validator set its for, the latest block hash observed, and a channel to return the
|
|
|
|
|
/// descending blocks.
|
|
|
|
|
fn heartbeat(
|
|
|
|
|
&self,
|
|
|
|
|
) -> impl Send
|
|
|
|
|
+ Future<Output = (ValidatorSet, [u8; 32], oneshot::Sender<Vec<TributaryBlockWithCommit>>)>;
|
|
|
|
|
|
|
|
|
|
/// A cancel-safe future for the next request for the notable cosigns of a gloabl session.
|
|
|
|
|
///
|
|
|
|
|
/// Yields the global session the request is for and a channel to return the notable cosigns.
|
|
|
|
|
fn notable_cosigns_request(
|
|
|
|
|
&self,
|
|
|
|
|
) -> impl Send + Future<Output = ([u8; 32], oneshot::Sender<Vec<SignedCosign>>)>;
|
|
|
|
|
|
|
|
|
|
/// A cancel-safe future for the next message regarding a Tributary.
|
|
|
|
|
///
|
|
|
|
|
/// Yields the message's Tributary's genesis block hash and the message.
|
|
|
|
|
fn tributary_message(&self) -> impl Send + Future<Output = ([u8; 32], Vec<u8>)>;
|
|
|
|
|
|
|
|
|
|
/// A cancel-safe future for the next cosign received.
|
|
|
|
|
fn cosign(&self) -> impl Send + Future<Output = SignedCosign>;
|
2025-01-04 23:28:29 -05:00
|
|
|
}
|