Skip to content

Commit

Permalink
A0-3390: Proposals with headers (#1491)
Browse files Browse the repository at this point in the history
# Description

Proposals now include headers.

## Type of change

- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)

# Checklist:

- I have made corresponding changes to the existing documentation
  • Loading branch information
timorleph authored Nov 17, 2023
1 parent bd9be28 commit 67d4512
Show file tree
Hide file tree
Showing 26 changed files with 657 additions and 355 deletions.
25 changes: 17 additions & 8 deletions finality-aleph/src/abft/current/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{
common::{unit_creation_delay_fn, MAX_ROUNDS, SESSION_LEN_LOWER_BOUND_MS},
NetworkWrapper,
},
block::{Header as BlockHeader, HeaderVerifier, UnverifiedHeader},
crypto::Signature,
data_io::{AlephData, OrderedDataInterpreter, SubstrateChainInfoProvider},
network::data::Network,
Expand All @@ -28,23 +29,31 @@ use crate::{
CurrentNetworkData, Hasher, Keychain, NodeIndex, SessionId, SignatureSet, UnitCreationDelay,
};

pub fn run_member<B, C, ADN>(
type WrappedNetwork<H, ADN> = NetworkWrapper<
current_aleph_bft::NetworkData<Hasher, AlephData<H>, Signature, SignatureSet<Signature>>,
ADN,
>;

pub fn run_member<B, C, ADN, V>(
subtask_common: TaskCommon,
multikeychain: Keychain,
config: Config,
network: NetworkWrapper<
current_aleph_bft::NetworkData<Hasher, AlephData, Signature, SignatureSet<Signature>>,
ADN,
network: WrappedNetwork<B::Header, ADN>,
data_provider: impl current_aleph_bft::DataProvider<AlephData<B::Header>> + Send + 'static,
ordered_data_interpreter: OrderedDataInterpreter<
SubstrateChainInfoProvider<B, C>,
B::Header,
V,
>,
data_provider: impl current_aleph_bft::DataProvider<AlephData> + Send + 'static,
ordered_data_interpreter: OrderedDataInterpreter<SubstrateChainInfoProvider<B, C>>,
backup: ABFTBackup,
) -> Task
where
B: Block<Hash = BlockHash>,
B::Header: Header<Number = BlockNumber>,
B::Header:
Header<Number = BlockNumber> + UnverifiedHeader + BlockHeader<Unverified = B::Header>,
C: HeaderBackend<B> + Send + 'static,
ADN: Network<CurrentNetworkData> + 'static,
ADN: Network<CurrentNetworkData<B::Header>> + 'static,
V: HeaderVerifier<B::Header>,
{
let TaskCommon {
spawn_handle,
Expand Down
9 changes: 5 additions & 4 deletions finality-aleph/src/abft/current/network.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use crate::{
abft::SignatureSet,
block::UnverifiedHeader,
crypto::Signature,
data_io::{AlephData, AlephNetworkMessage},
Hasher,
};

pub type NetworkData =
current_aleph_bft::NetworkData<Hasher, AlephData, Signature, SignatureSet<Signature>>;
pub type NetworkData<UH> =
current_aleph_bft::NetworkData<Hasher, AlephData<UH>, Signature, SignatureSet<Signature>>;

impl AlephNetworkMessage for NetworkData {
fn included_data(&self) -> Vec<AlephData> {
impl<UH: UnverifiedHeader> AlephNetworkMessage<UH> for NetworkData<UH> {
fn included_data(&self) -> Vec<AlephData<UH>> {
self.included_data()
}
}
20 changes: 15 additions & 5 deletions finality-aleph/src/abft/current/traits.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
//! Implementations and definitions of traits used in current abft
use crate::data_io::{AlephData, ChainInfoProvider, DataProvider, OrderedDataInterpreter};
use crate::{
block::{Header, HeaderVerifier, UnverifiedHeader},
data_io::{AlephData, ChainInfoProvider, DataProvider, OrderedDataInterpreter},
};

#[async_trait::async_trait]
impl current_aleph_bft::DataProvider<AlephData> for DataProvider {
async fn get_data(&mut self) -> Option<AlephData> {
impl<UH: UnverifiedHeader> current_aleph_bft::DataProvider<AlephData<UH>> for DataProvider<UH> {
async fn get_data(&mut self) -> Option<AlephData<UH>> {
DataProvider::get_data(self).await
}
}

impl<CIP> current_aleph_bft::FinalizationHandler<AlephData> for OrderedDataInterpreter<CIP>
impl<CIP, H, V> current_aleph_bft::FinalizationHandler<AlephData<H::Unverified>>
for OrderedDataInterpreter<CIP, H, V>
where
CIP: ChainInfoProvider,
H: Header,
V: HeaderVerifier<H>,
{
fn data_finalized(&mut self, data: AlephData, _creator: current_aleph_bft::NodeIndex) {
fn data_finalized(
&mut self,
data: AlephData<H::Unverified>,
_creator: current_aleph_bft::NodeIndex,
) {
OrderedDataInterpreter::data_finalized(self, data)
}
}
12 changes: 8 additions & 4 deletions finality-aleph/src/block/mock/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
mock::{MockBlock, MockHeader, MockJustification, MockNotification},
Block, BlockImport, BlockStatus, ChainStatus, ChainStatusNotifier,
EquivocationProof as EquivocationProofT, FinalizationStatus, Finalizer, Header,
Justification as JustificationT, VerifiedHeader, Verifier,
HeaderVerifier, Justification as JustificationT, JustificationVerifier, VerifiedHeader,
},
nodes::VERIFIER_CACHE_SIZE,
session::{SessionBoundaryInfo, SessionId},
Expand Down Expand Up @@ -414,8 +414,7 @@ impl Display for VerifierError {
}
}

impl Verifier<MockJustification> for Backend {
type EquivocationProof = EquivocationProof;
impl JustificationVerifier<MockJustification> for Backend {
type Error = VerifierError;

fn verify_justification(
Expand Down Expand Up @@ -445,12 +444,17 @@ impl Verifier<MockJustification> for Backend {
false => Err(Self::Error::Justification),
}
}
}

impl HeaderVerifier<MockHeader> for Backend {
type EquivocationProof = EquivocationProof;
type Error = VerifierError;

fn verify_header(
&mut self,
header: MockHeader,
_just_created: bool,
) -> Result<VerifiedHeader<MockJustification, Self::EquivocationProof>, Self::Error> {
) -> Result<VerifiedHeader<MockHeader, Self::EquivocationProof>, Self::Error> {
match (header.valid(), header.equivocated()) {
(true, false) => Ok(VerifiedHeader {
header,
Expand Down
29 changes: 17 additions & 12 deletions finality-aleph/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Display for BlockId {
}

/// The unverified header of a block, containing information about the parent relation.
pub trait UnverifiedHeader: Clone + Codec + Debug + Send + Sync + 'static {
pub trait UnverifiedHeader: Clone + Codec + Debug + Send + Sync + Eq + 'static {
/// The identifier of this block.
fn id(&self) -> BlockId;
}
Expand Down Expand Up @@ -82,36 +82,41 @@ pub trait Justification: Clone + Send + Sync + Debug + 'static {
fn into_unverified(self) -> Self::Unverified;
}

/// A verifier of justifications.
pub trait JustificationVerifier<J: Justification> {
type Error: Display + Debug;

/// Verifies the raw justification and returns a full justification if successful, otherwise an
/// error.
fn verify_justification(&mut self, justification: J::Unverified) -> Result<J, Self::Error>;
}

pub type UnverifiedHeaderFor<J> = <<J as Justification>::Header as Header>::Unverified;

pub trait EquivocationProof: Display {
/// Returns if we are the offender.
fn are_we_equivocating(&self) -> bool;
}

pub struct VerifiedHeader<J: Justification, P: EquivocationProof> {
pub header: J::Header,
pub struct VerifiedHeader<H: Header, P: EquivocationProof> {
pub header: H,
pub maybe_equivocation_proof: Option<P>,
}

/// A verifier of justifications and headers.
pub trait Verifier<J: Justification> {
/// A verifier of headers.
pub trait HeaderVerifier<H: Header>: Clone + Send + Sync + 'static {
type EquivocationProof: EquivocationProof;
type Error: Display;

/// Verifies the raw justification and returns a full justification if successful, otherwise an
/// error.
fn verify_justification(&mut self, justification: J::Unverified) -> Result<J, Self::Error>;
type Error: Display + Debug;

/// Verifies the raw header and returns a struct containing a full header and possibly
/// an equivocation proof if successful, otherwise an error.
/// In case the header comes from a block that we've just authored,
/// the `just_created` flag must be set to `true`.
fn verify_header(
&mut self,
header: UnverifiedHeaderFor<J>,
header: H::Unverified,
just_created: bool,
) -> Result<VerifiedHeader<J, Self::EquivocationProof>, Self::Error>;
) -> Result<VerifiedHeader<H, Self::EquivocationProof>, Self::Error>;
}

/// The block, including a header.
Expand Down
Loading

0 comments on commit 67d4512

Please sign in to comment.