Skip to content

Commit

Permalink
A0-4295: Base protocol config creation (#1711)
Browse files Browse the repository at this point in the history
# Description

Config creation for the base protocol, mostly dummy values, but this is
what we want in our case. Not yet used, will have to be used in tandem
with the network building.

## Type of change

- New feature (non-breaking change which adds functionality)

# Checklist:

- I have created new documentation
  • Loading branch information
timorleph authored May 7, 2024
1 parent 3b32220 commit 1236343
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ aleph-bft-mock = { version = "0.14" }
aleph-bft-rmc = { version = "0.13" }
aleph-bft-types = { version = "0.13" }
async-trait = { version = "0.1" }
array-bytes = { version = "6" }
bytes = { version = "1.6" }
derive_more = { version = "0.99" }
env_logger = { version = "0.10" }
Expand Down
1 change: 1 addition & 0 deletions finality-aleph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ current-aleph-aggregator = { path = "../aggregator", package = "aggregator" }
rate-limiter = { package = "rate-limiter", path = "../rate-limiter" }

async-trait = { workspace = true }
array-bytes = { workspace = true }
bytes = { workspace = true }
derive_more = { workspace = true }
env_logger = { workspace = true }
Expand Down
54 changes: 54 additions & 0 deletions finality-aleph/src/base_protocol/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::iter;

use array_bytes::bytes2hex;
use sc_network::{
config::{NonDefaultSetConfig, NonReservedPeerMode, NotificationHandshake, Role, SetConfig},
NotificationService,
};
use sc_network_common::sync::message::BlockAnnouncesHandshake;
use sp_core::H256;
use sp_runtime::traits::{Block, Header};

use crate::{BlockHash, BlockNumber};

// NOTE: `set_config` will be ignored by `protocol.rs` as the base
// protocol is still hardcoded into the peerset.
const DUMMY_SET_CONFIG: SetConfig = SetConfig {
in_peers: 0,
out_peers: 0,
reserved_nodes: Vec::new(),
non_reserved_mode: NonReservedPeerMode::Deny,
};

/// Generate a config for the base protocol and the notification service that should be passed to its service.
pub fn setup<B>(genesis_hash: B::Hash) -> (NonDefaultSetConfig, Box<dyn NotificationService>)
where
B: Block<Hash = BlockHash>,
B::Header: Header<Number = BlockNumber>,
{
// used for backwards compatibility with older nodes, should be safe to remove after update 14
let legacy_block_announces_protocol =
format!("/{}/block-announces/1", bytes2hex("", genesis_hash));
let base_protocol_name = format!("/{}/base-protocol/1", bytes2hex("", genesis_hash));

NonDefaultSetConfig::new(
base_protocol_name.into(),
iter::once(legacy_block_announces_protocol.into()).collect(),
// This is the maximum message size. We don't need messages at all,
// but we want to avoid tripping some magic value,
// which 0 might suddenly become, so 1.
1,
Some(NotificationHandshake::new(
BlockAnnouncesHandshake::<B>::build(
// All nodes are full nodes.
(&Role::Full).into(),
// The best block number, always send a dummy value of 0.
0,
// The best block hash, always an obviously dummy value.
H256([0; 32]),
genesis_hash,
),
)),
DUMMY_SET_CONFIG,
)
}
2 changes: 2 additions & 0 deletions finality-aleph/src/base_protocol/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//TODO(A0-3750): This code should be used.
#![allow(dead_code)]
mod config;
mod handler;
mod service;

pub use config::setup;
pub use service::Service;

const LOG_TARGET: &str = "aleph-base-protocol";

0 comments on commit 1236343

Please sign in to comment.