Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7876706
WIP
MitchTurner Mar 10, 2025
1e27960
Add basic trait for adding delegate key
MitchTurner Mar 11, 2025
8b3eb35
Add tests for verifying incoming preconfirmation signatures
MitchTurner Mar 11, 2025
136ff89
Include test for tracking preconfirmations that return too early for …
MitchTurner Mar 12, 2025
37579b6
Cleanup
MitchTurner Mar 12, 2025
af74f22
Update CHANGELOG
MitchTurner Mar 12, 2025
fdd2dc6
Merge branch 'master' into feature/pre-confirmations/implement-signat…
MitchTurner Mar 12, 2025
a0b531f
Add basic impl
MitchTurner Mar 12, 2025
c056e36
Fix trait method signature
MitchTurner Mar 12, 2025
6683c41
Merge branch 'master' into feature/pre-confirmations/implement-signat…
xgreenx Mar 12, 2025
b26bbd3
Update crates/services/tx_status_manager/src/service.rs
MitchTurner Mar 13, 2025
8769da7
Merge branch 'master' into feature/pre-confirmations/implement-signat…
AurelienFT Mar 13, 2025
329f7dd
remove trait and replace with concrete impl (#2869)
MitchTurner Mar 14, 2025
bdbc5fc
Merge branch 'master' into feature/pre-confirmations/implement-signat…
MitchTurner Mar 14, 2025
85b5afe
Merge branch 'master' into feature/pre-confirmations/implement-signat…
MitchTurner Mar 14, 2025
f60f793
Use `ConsensusConfig` to get `PublicKey` (`Address` actually)
MitchTurner Mar 14, 2025
7d44a66
Avoid DoS vector by removing `early_preconfirmations` concept and test
MitchTurner Mar 14, 2025
4f40fc0
Apply suggestions from code review
xgreenx Mar 15, 2025
b012cdb
Fix compilation
xgreenx Mar 15, 2025
0402595
Merge branch 'master' into feature/pre-confirmations/implement-signat…
xgreenx Mar 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changes/added/2856.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add generic logic for managing the signatures and delegate keys for pre-confirmations signatures
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.

43 changes: 27 additions & 16 deletions crates/chain-config/src/config/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ pub struct PoAV2 {

impl PoAV2 {
pub fn new(
genesis_signing_key: Address,
signing_key_overrides: BTreeMap<BlockHeight, Address>,
genesis_signing_key_address: Address,
signing_key_address_overrides: BTreeMap<BlockHeight, Address>,
) -> Self {
PoAV2 {
genesis_signing_key,
signing_key_overrides,
genesis_signing_key: genesis_signing_key_address,
signing_key_overrides: signing_key_address_overrides,
}
}

/// Returns the signing key for the given block height.
pub fn signing_key_at(&self, height: BlockHeight) -> Address {
/// Returns the address for the signing key at block height.
pub fn address_for_height(&self, height: BlockHeight) -> Address {
if self.signing_key_overrides.is_empty() {
self.genesis_signing_key
} else {
Expand All @@ -60,6 +60,15 @@ impl PoAV2 {
}
}

/// Returns the address of the latest signing key for the given block height.
pub fn latest_address(&self) -> Address {
self.signing_key_overrides
.last_key_value()
.map(|(_, key)| key)
.cloned()
.unwrap_or(self.genesis_signing_key)
}

/// Returns overrides for all the signing keys.
pub fn get_all_overrides(&self) -> &BTreeMap<BlockHeight, Address> {
&self.signing_key_overrides
Expand All @@ -73,10 +82,12 @@ impl PoAV2 {

#[cfg(test)]
mod tests {
#![allow(non_snake_case)]

use super::*;

#[test]
fn signing_key_at_works() {
fn address_at_height__returns_expected_values() {
// Given
let genesis_signing_key = Address::from([1; 32]);
let signing_key_after_10 = Address::from([2; 32]);
Expand All @@ -95,16 +106,16 @@ mod tests {
};

// When/Then
assert_eq!(poa.signing_key_at(0u32.into()), genesis_signing_key);
assert_eq!(poa.signing_key_at(9u32.into()), genesis_signing_key);
assert_eq!(poa.signing_key_at(10u32.into()), signing_key_after_10);
assert_eq!(poa.signing_key_at(19u32.into()), signing_key_after_10);
assert_eq!(poa.signing_key_at(20u32.into()), signing_key_after_20);
assert_eq!(poa.signing_key_at(29u32.into()), signing_key_after_20);
assert_eq!(poa.signing_key_at(30u32.into()), signing_key_after_30);
assert_eq!(poa.signing_key_at(40u32.into()), signing_key_after_30);
assert_eq!(poa.address_for_height(0u32.into()), genesis_signing_key);
assert_eq!(poa.address_for_height(9u32.into()), genesis_signing_key);
assert_eq!(poa.address_for_height(10u32.into()), signing_key_after_10);
assert_eq!(poa.address_for_height(19u32.into()), signing_key_after_10);
assert_eq!(poa.address_for_height(20u32.into()), signing_key_after_20);
assert_eq!(poa.address_for_height(29u32.into()), signing_key_after_20);
assert_eq!(poa.address_for_height(30u32.into()), signing_key_after_30);
assert_eq!(poa.address_for_height(40u32.into()), signing_key_after_30);
assert_eq!(
poa.signing_key_at(4_000_000u32.into()),
poa.address_for_height(4_000_000u32.into()),
signing_key_after_30
);
}
Expand Down
29 changes: 26 additions & 3 deletions crates/fuel-core/src/service/adapters/tx_status_manager.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use fuel_core_services::stream::BoxStream;
use fuel_core_tx_status_manager::ports::P2PPreConfirmationGossipData;

use super::P2PAdapter;
use fuel_core_chain_config::ConsensusConfig;
use fuel_core_services::stream::BoxStream;
use fuel_core_tx_status_manager::{
ports::P2PPreConfirmationGossipData,
service::ProtocolPublicKey,
};
use fuel_core_types::fuel_tx::Address;

#[cfg(feature = "p2p")]
impl fuel_core_tx_status_manager::ports::P2PSubscriptions for P2PAdapter {
Expand Down Expand Up @@ -32,3 +36,22 @@ impl fuel_core_tx_status_manager::ports::P2PSubscriptions for P2PAdapter {
Box::pin(fuel_core_services::stream::pending())
}
}

pub struct ConsensusConfigProtocolPublicKey {
inner: ConsensusConfig,
}

impl ConsensusConfigProtocolPublicKey {
pub fn new(inner: ConsensusConfig) -> Self {
Self { inner }
}
}

impl ProtocolPublicKey for ConsensusConfigProtocolPublicKey {
fn latest_address(&self) -> Address {
match &self.inner {
ConsensusConfig::PoA { signing_key } => *signing_key,
ConsensusConfig::PoAV2(poa_v2) => poa_v2.latest_address(),
}
}
}
24 changes: 14 additions & 10 deletions crates/fuel-core/src/service/sub_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ use crate::service::adapters::consensus_module::poa::pre_confirmation_signature:
tx_receiver::PreconfirmationsReceiver,
};

use super::{
adapters::{
FuelBlockSigner,
P2PAdapter,
TxStatusManagerAdapter,
},
genesis::create_genesis_block,
DbType,
};
use crate::{
combined_database::CombinedDatabase,
database::Database,
Expand All @@ -58,6 +67,7 @@ use crate::{
graphql_api::GraphQLBlockImporter,
import_result_provider::ImportResultProvider,
ready_signal::ReadySignal,
tx_status_manager::ConsensusConfigProtocolPublicKey,
BlockImporterAdapter,
BlockProducerAdapter,
ChainStateInfoProvider,
Expand All @@ -76,16 +86,6 @@ use crate::{
},
};

use super::{
adapters::{
FuelBlockSigner,
P2PAdapter,
TxStatusManagerAdapter,
},
genesis::create_genesis_block,
DbType,
};

pub type PoAService = fuel_core_poa::Service<
TxPoolAdapter,
BlockProducerAdapter,
Expand Down Expand Up @@ -257,9 +257,13 @@ pub fn init_sub_services(
universal_gas_price_provider.clone(),
);

let protocol_pubkey =
ConsensusConfigProtocolPublicKey::new(chain_config.consensus.clone());

let tx_status_manager = fuel_core_tx_status_manager::new_service(
p2p_adapter.clone(),
config.tx_status_manager.clone(),
protocol_pubkey,
);
let tx_status_manager_adapter =
TxStatusManagerAdapter::new(tx_status_manager.shared.clone());
Expand Down
2 changes: 1 addition & 1 deletion crates/services/consensus_module/poa/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn verify_consensus(
ConsensusConfig::PoAV2(poa) => {
let id = header.id();
let m = id.as_message();
let signing_key = poa.signing_key_at(*header.height());
let signing_key = poa.address_for_height(*header.height());
consensus
.signature
.recover(m)
Expand Down
3 changes: 2 additions & 1 deletion crates/services/tx_status_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ async-trait = { workspace = true }
derive_more = { workspace = true }
fuel-core-metrics = { workspace = true }
fuel-core-services = { workspace = true }
fuel-core-types = { workspace = true, features = ["std"] }
fuel-core-types = { workspace = true, features = ["std", "serde"] }
futures = { workspace = true }
parking_lot = { workspace = true }
postcard = { workspace = true }
tokio = { workspace = true }
tokio-stream = { workspace = true }
tracing = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/services/tx_status_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod config;
mod error;
mod manager;
pub mod ports;
mod service;
pub mod service;
mod subscriptions;
mod tx_status_stream;
mod update_sender;
Expand Down
Loading
Loading