Skip to content

Commit

Permalink
A0-4574: Update ABFT after release 14 (#1873)
Browse files Browse the repository at this point in the history
# Description

Updates ABFT to 0.39. Starts using the extended finalization handler,
but in a trivial way, the actual scoring will happen in a separate PR.

Note that this shouldn't break the pipelines that connect to
test/mainnet (like #1842 did), even though it technically makes `main`
incompatible, since the incompatibility is limited to validation.
However I might be wrong, so keep that in mind.

## Type of change

- 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
- I have created new documentation
  • Loading branch information
timorleph authored Dec 3, 2024
1 parent 9c2036b commit 98f0499
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 226 deletions.
250 changes: 133 additions & 117 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ repository = "https://github.com/Cardinal-Cryptography/aleph-node"

[workspace.dependencies]
aleph-bft-crypto = { version = "0.9" }
aleph-bft-mock = { version = "0.14" }
aleph-bft-rmc = { version = "0.13" }
aleph-bft-types = { version = "0.13" }
aleph-bft-mock = { version = "0.15" }
aleph-bft-rmc = { version = "0.14" }
aleph-bft-types = { version = "0.14" }
async-trait = { version = "0.1" }
array-bytes = { version = "6" }
bytes = { version = "1.8" }
Expand Down
11 changes: 6 additions & 5 deletions finality-aleph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ repository.workspace = true
# fixed version to 'freeze' some types used in abft, mainly `SignatureSet` used in justification and signature aggregation
aleph-bft-crypto = { workspace = true }

current-aleph-bft = { package = "aleph-bft", version = "0.36" }
current-aleph-bft-rmc = { package = "aleph-bft-rmc", version = "0.13" }
legacy-aleph-bft = { package = "aleph-bft", version = "0.33" }
legacy-aleph-bft-rmc = { package = "aleph-bft-rmc", version = "0.11" }
current-aleph-bft = { package = "aleph-bft", version = "0.39" }
current-aleph-bft-rmc = { package = "aleph-bft-rmc", version = "0.14" }
legacy-aleph-bft = { package = "aleph-bft", version = "0.36" }
legacy-aleph-bft-rmc = { package = "aleph-bft-rmc", version = "0.13" }

network-clique = { workspace = true }
primitives = { workspace = true }
legacy-aleph-aggregator = { package = "aggregator", git = "https://github.com/Cardinal-Cryptography/aleph-node.git", tag = "r-13.3" }
# TODO: update this to the appropriate release tag once it exists
legacy-aleph-aggregator = { package = "aggregator", git = "https://github.com/Cardinal-Cryptography/aleph-node.git", tag = "r-14.0-rc1" }
current-aleph-aggregator = { path = "../aggregator", package = "aggregator" }
rate-limiter = { package = "rate-limiter", path = "../rate-limiter" }
fake-runtime-api = { workspace = true, features = ["std"] }
Expand Down
49 changes: 3 additions & 46 deletions finality-aleph/src/abft/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,14 @@ impl Keychain {
}
}

impl current_aleph_bft::Index for Keychain {
fn index(&self) -> current_aleph_bft::NodeIndex {
Keychain::index(self).into()
}
}

// Currently the traits for legacy and current match, so only one implementation needed.
impl legacy_aleph_bft::Index for Keychain {
fn index(&self) -> legacy_aleph_bft::NodeIndex {
Keychain::index(self).into()
}
}

impl current_aleph_bft::Keychain for Keychain {
type Signature = Signature;

fn node_count(&self) -> current_aleph_bft::NodeCount {
Keychain::node_count(self).into()
}

fn sign(&self, msg: &[u8]) -> Signature {
Keychain::sign(self, msg)
}

fn verify(&self, msg: &[u8], sgn: &Signature, index: current_aleph_bft::NodeIndex) -> bool {
Keychain::verify(self, msg, sgn, index)
}
}

// Currently the traits for legacy and current match, so only one implementation needed.
impl legacy_aleph_bft::Keychain for Keychain {
type Signature = Signature;

Expand All @@ -92,30 +72,7 @@ impl legacy_aleph_bft::Keychain for Keychain {
}
}

impl current_aleph_bft::MultiKeychain for Keychain {
// Using `SignatureSet` is slow, but Substrate has not yet implemented aggregation.
// We probably should do this for them at some point.
type PartialMultisignature = SignatureSet<Signature>;

fn bootstrap_multi(
&self,
signature: &Signature,
index: current_aleph_bft::NodeIndex,
) -> Self::PartialMultisignature {
current_aleph_bft::PartialMultisignature::add_signature(
SignatureSet(aleph_bft_crypto::SignatureSet::with_size(
aleph_bft_crypto::Keychain::node_count(self),
)),
signature,
index,
)
}

fn is_complete(&self, msg: &[u8], partial: &Self::PartialMultisignature) -> bool {
Keychain::is_complete(self, msg, partial)
}
}

// Currently the traits for legacy and current match, so only one implementation needed.
impl legacy_aleph_bft::MultiKeychain for Keychain {
// Using `SignatureSet` is slow, but Substrate has not yet implemented aggregation.
// We probably should do this for them at some point.
Expand Down
9 changes: 7 additions & 2 deletions finality-aleph/src/abft/current/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn run_member<H, C, ADN, V>(
multikeychain: Keychain,
config: Config,
network: WrappedNetwork<H::Unverified, ADN>,
data_provider: impl current_aleph_bft::DataProvider<AlephData<H::Unverified>> + 'static,
data_provider: impl current_aleph_bft::DataProvider<Output = AlephData<H::Unverified>> + 'static,
ordered_data_interpreter: OrderedDataInterpreter<SubstrateChainInfoProvider<H, C>, H, V>,
backup: ABFTBackup,
) -> Task
Expand All @@ -53,7 +53,12 @@ where
} = subtask_common;
let (stop, exit) = oneshot::channel();
let member_terminator = Terminator::create_root(exit, "member");
let local_io = LocalIO::new(data_provider, ordered_data_interpreter, backup.0, backup.1);
let local_io = LocalIO::new_with_unit_finalization_handler(
data_provider,
ordered_data_interpreter,
backup.0,
backup.1,
);

let task = {
let spawn_handle = spawn_handle.clone();
Expand Down
23 changes: 18 additions & 5 deletions finality-aleph/src/abft/current/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,36 @@
use crate::{
block::{Header, HeaderVerifier, UnverifiedHeader},
data_io::{AlephData, ChainInfoProvider, DataProvider, OrderedDataInterpreter},
Hasher,
};

#[async_trait::async_trait]
impl<UH: UnverifiedHeader> current_aleph_bft::DataProvider<AlephData<UH>> for DataProvider<UH> {
impl<UH: UnverifiedHeader> current_aleph_bft::DataProvider for DataProvider<UH> {
type Output = AlephData<UH>;

async fn get_data(&mut self) -> Option<AlephData<UH>> {
DataProvider::get_data(self).await
}
}

impl<CIP, H, V> current_aleph_bft::FinalizationHandler<AlephData<H::Unverified>>
for OrderedDataInterpreter<CIP, H, V>
impl<CIP, H, V> current_aleph_bft::UnitFinalizationHandler for OrderedDataInterpreter<CIP, H, V>
where
CIP: ChainInfoProvider,
H: Header,
V: HeaderVerifier<H>,
{
fn data_finalized(&mut self, data: AlephData<H::Unverified>) {
OrderedDataInterpreter::data_finalized(self, data)
type Data = AlephData<H::Unverified>;
type Hasher = Hasher;

fn batch_finalized(
&mut self,
batch: Vec<current_aleph_bft::OrderedUnit<Self::Data, Self::Hasher>>,
) {
// TODO(A0-4575): compute performance scores.
for unit in batch {
if let Some(data) = unit.data {
self.data_finalized(data)
}
}
}
}
9 changes: 2 additions & 7 deletions finality-aleph/src/abft/legacy/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{pin::Pin, time::Duration};
use std::time::Duration;

use legacy_aleph_bft::{create_config, default_delay_config, Config, LocalIO, Terminator};
use log::debug;
Expand Down Expand Up @@ -52,12 +52,7 @@ where
} = subtask_common;
let (stop, exit) = oneshot::channel();
let member_terminator = Terminator::create_root(exit, "member");
let local_io = LocalIO::new(
data_provider,
ordered_data_interpreter,
Pin::into_inner(backup.0),
Pin::into_inner(backup.1),
);
let local_io = LocalIO::new(data_provider, ordered_data_interpreter, backup.0, backup.1);

let task = {
let spawn_handle = spawn_handle.clone();
Expand Down
6 changes: 1 addition & 5 deletions finality-aleph/src/abft/legacy/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ where
H: Header,
V: HeaderVerifier<H>,
{
fn data_finalized(
&mut self,
data: AlephData<H::Unverified>,
_creator: legacy_aleph_bft::NodeIndex,
) {
fn data_finalized(&mut self, data: AlephData<H::Unverified>) {
OrderedDataInterpreter::data_finalized(self, data)
}
}
13 changes: 1 addition & 12 deletions finality-aleph/src/abft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl<S: 'static> IntoIterator for SignatureSet<S> {
}
}

// Currently the traits for legacy and current match, so only one implementation needed.
impl<S: Signature> legacy_aleph_bft::PartialMultisignature for SignatureSet<S> {
type Signature = S;

Expand All @@ -83,15 +84,3 @@ impl<S: Signature> legacy_aleph_bft::PartialMultisignature for SignatureSet<S> {
SignatureSet::add_signature(self, signature, index.into())
}
}

impl<S: Signature> current_aleph_bft::PartialMultisignature for SignatureSet<S> {
type Signature = S;

fn add_signature(
self,
signature: &Self::Signature,
index: current_aleph_bft::NodeIndex,
) -> Self {
SignatureSet::add_signature(self, signature, index.into())
}
}
2 changes: 1 addition & 1 deletion finality-aleph/src/abft/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<D: Data, DN: Network<D>> NetworkWrapper<D, DN> {
}

#[async_trait::async_trait]
impl<D: Data, DN: Network<D>> current_aleph_bft::Network<D> for NetworkWrapper<D, DN> {
impl<D: Data, DN: Network<D> + 'static> current_aleph_bft::Network<D> for NetworkWrapper<D, DN> {
fn send(&self, data: D, recipient: current_aleph_bft::Recipient) {
NetworkWrapper::send(self, data, recipient)
}
Expand Down
27 changes: 4 additions & 23 deletions finality-aleph/src/abft/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,53 +49,34 @@ impl From<current_aleph_bft::Recipient> for Recipient {
}
}

impl From<NodeCount> for current_aleph_bft::NodeCount {
fn from(count: NodeCount) -> Self {
current_aleph_bft::NodeCount(count.0)
}
}
// Currently the traits for legacy and current match, so only one implementation needed.
impl From<NodeCount> for legacy_aleph_bft::NodeCount {
fn from(count: NodeCount) -> Self {
legacy_aleph_bft::NodeCount(count.0)
}
}

// Currently the traits for legacy and current match, so only one implementation needed.
impl From<legacy_aleph_bft::NodeCount> for NodeCount {
fn from(count: legacy_aleph_bft::NodeCount) -> Self {
Self(count.0)
}
}

impl From<current_aleph_bft::NodeCount> for NodeCount {
fn from(count: current_aleph_bft::NodeCount) -> Self {
Self(count.0)
}
}

impl From<NodeIndex> for current_aleph_bft::NodeIndex {
fn from(idx: NodeIndex) -> Self {
current_aleph_bft::NodeIndex(idx.0)
}
}

// Currently the traits for legacy and current match, so only one implementation needed.
impl From<NodeIndex> for legacy_aleph_bft::NodeIndex {
fn from(idx: NodeIndex) -> Self {
legacy_aleph_bft::NodeIndex(idx.0)
}
}

// Currently the traits for legacy and current match, so only one implementation needed.
impl From<legacy_aleph_bft::NodeIndex> for NodeIndex {
fn from(idx: legacy_aleph_bft::NodeIndex) -> Self {
Self(idx.0)
}
}

impl From<current_aleph_bft::NodeIndex> for NodeIndex {
fn from(idx: current_aleph_bft::NodeIndex) -> Self {
Self(idx.0)
}
}

impl From<Recipient> for current_aleph_bft::Recipient {
fn from(recipient: Recipient) -> Self {
match recipient {
Expand Down

0 comments on commit 98f0499

Please sign in to comment.