Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ca5f695
Add new task structure and traits
MitchTurner Feb 24, 2025
c76d4b6
Merge branch 'master' into feature/pre-confirmation-task
MitchTurner Feb 24, 2025
b91726e
Add first test for key rotation trigger
MitchTurner Feb 24, 2025
eb315e1
Add test for key being signed
MitchTurner Feb 24, 2025
e5817e8
Add broadcast, compile tests
MitchTurner Feb 24, 2025
e34311a
Merge branch 'master' into feature/pre-confirmation-task
MitchTurner Feb 24, 2025
efff269
Update current key when updating
MitchTurner Feb 25, 2025
fa4f651
Merge branch 'master' into feature/pre-confirmation-task
MitchTurner Feb 25, 2025
a934075
Add broadcast for proconfirmed txs
MitchTurner Feb 25, 2025
aa6310f
Update CHANGELOG
MitchTurner Feb 25, 2025
9f6ba77
Cleanpu
MitchTurner Feb 25, 2025
61e479f
Cleanup
MitchTurner Feb 25, 2025
842b3e6
Impl `shutdown`
MitchTurner Feb 25, 2025
03ec51f
Remove allows
MitchTurner Feb 25, 2025
d940d01
Merge branch 'master' into feature/pre-confirmation-task
MitchTurner Feb 25, 2025
4a02950
Appease Clippy-sama
MitchTurner Feb 25, 2025
b2fbe7f
Remove `#[async_trait::async_trait]`
MitchTurner Feb 25, 2025
ccb97e1
Merge branch 'master' into feature/pre-confirmation-task
MitchTurner Feb 26, 2025
c7e9662
Merge branch 'master' into feature/pre-confirmation-task
MitchTurner Feb 26, 2025
01e81e2
Add docs to traits
MitchTurner Feb 26, 2025
6723485
Rename task and file
MitchTurner Feb 26, 2025
5bfea01
Merge branch 'master' into feature/pre-confirmation-task
MitchTurner Feb 27, 2025
729972f
Remove unused lib, add alias for signatures
MitchTurner Feb 27, 2025
287283e
Merge branch 'master' into feature/pre-confirmation-task
MitchTurner Feb 27, 2025
78dec7c
Add trigger impl
MitchTurner Feb 27, 2025
0440743
Add another test, refactor
MitchTurner Feb 28, 2025
9c156c5
Add parent signature impl
MitchTurner Feb 28, 2025
f9d8a46
Add tx receiver impl
MitchTurner Feb 28, 2025
7ccd113
Refactor
MitchTurner Feb 28, 2025
6638691
Add some dummy implementations
MitchTurner Feb 28, 2025
c7cc9a1
Organize more, add todo
MitchTurner Feb 28, 2025
703da90
Update CHANGELOG
MitchTurner Feb 28, 2025
d235932
Fix compilation errors
MitchTurner Feb 28, 2025
fb7058c
Update TODOs
MitchTurner Feb 28, 2025
393e0d7
Merge branch 'master' into feature/pre-confirmation-task
xgreenx Feb 28, 2025
d0505cb
Merge branch 'feature/pre-confirmation-task' into feature/pre-confirm…
xgreenx Mar 1, 2025
cb4e69a
Fix weird doc requirement
MitchTurner Mar 1, 2025
7b145dd
Ignore typo
MitchTurner Mar 1, 2025
a8a37e3
Merge branch 'master' into feature/pre-confirmation-task
MitchTurner Mar 3, 2025
f5f5c1e
Merge branch 'feature/pre-confirmation-task' into feature/pre-confirm…
MitchTurner Mar 3, 2025
22eaa46
Merge branch 'refs/heads/master' into feature/pre-confirmations/add-i…
xgreenx Mar 3, 2025
29487a9
use tick instead of sleep, fix test
MitchTurner Mar 3, 2025
b393ee9
Use single interval for trigger
MitchTurner Mar 3, 2025
6fa24d6
Remove unused, commeted code
MitchTurner Mar 3, 2025
cb39a1c
Remove `Time` generic because no longer used
MitchTurner Mar 3, 2025
324979b
Appease Clippy-sama
MitchTurner Mar 3, 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/2780.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add implementations for the pre-confirmation signing task
15 changes: 15 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ mockall = { workspace = true }
proptest = { workspace = true }
test-case = { workspace = true }
test-strategy = { workspace = true }
tokio-test = "0.4.4"
tracing-subscriber = { workspace = true }

[features]
default = ["rocksdb"]
Expand Down
3 changes: 3 additions & 0 deletions crates/fuel-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#![deny(unused_crate_dependencies)]
#![deny(warnings)]

#[cfg(test)]
use tracing_subscriber as _;

use crate::service::genesis::NotifyCancel;
use tokio_util::sync::CancellationToken;

Expand Down
35 changes: 19 additions & 16 deletions crates/fuel-core/src/service/adapters.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
use crate::{
database::{
database_description::relayer::Relayer,
Database,
},
fuel_core_graphql_api::ports::GasPriceEstimate,
service::{
sub_services::{
BlockProducerService,
TxPoolSharedState,
},
vm_pool::MemoryPool,
},
};
use std::sync::Arc;

use fuel_core_consensus_module::{
block_verifier::Verifier,
RelayerConsensusConfig,
Expand Down Expand Up @@ -53,7 +41,21 @@ use fuel_core_types::{
};
//#[cfg(not(feature = "parallel-executor"))]
use fuel_core_upgradable_executor::executor::Executor;
use std::sync::Arc;

use crate::{
database::{
database_description::relayer::Relayer,
Database,
},
fuel_core_graphql_api::ports::GasPriceEstimate,
service::{
sub_services::{
BlockProducerService,
TxPoolSharedState,
},
vm_pool::MemoryPool,
},
};

pub mod block_importer;
pub mod chain_state_info_provider;
Expand Down Expand Up @@ -100,9 +102,10 @@ impl StaticGasPrice {
mod universal_gas_price_provider_tests {
#![allow(non_snake_case)]

use super::*;
use proptest::proptest;

use super::*;

fn _worst_case__correctly_calculates_value(
gas_price: u64,
starting_height: u32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ use tokio_stream::{
StreamExt,
};

pub mod pre_confirmation_signature;

impl PoAAdapter {
pub fn new(shared_state: Option<SharedState>) -> Self {
Self { shared_state }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use fuel_core_types::{
fuel_tx::TxId,
services::p2p::PreconfirmationStatus,
};

pub mod broadcast;
pub mod key_generator;
pub mod parent_signature;
pub mod signing_key;
pub mod trigger;
pub mod tx_receiver;

pub type Preconfirmations = Vec<(TxId, PreconfirmationStatus)>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use crate::service::adapters::consensus_module::poa::pre_confirmation_signature::{
parent_signature::FuelParentSignature,
signing_key::DummyKey,
Preconfirmations,
};
use fuel_core_poa::pre_confirmation_signature_service::{
broadcast::Broadcast,
error::Result as PoAResult,
Signed,
};

/// TODO: Implement `Broadcast` properly: <https://github.com/FuelLabs/fuel-core/issues/2783>
pub struct P2PBroadcast;

impl Broadcast for P2PBroadcast {
type PreConfirmations = Preconfirmations;
type ParentSignature = FuelParentSignature<DummyKey>;
type DelegateKey = DummyKey;

async fn broadcast_txs(
&mut self,
_txs: Signed<Self::DelegateKey, Self::PreConfirmations>,
) -> PoAResult<()> {
todo!()
}

async fn broadcast_delegate_key(
&mut self,
_delegate_key: Self::ParentSignature,
) -> PoAResult<()> {
todo!()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use crate::service::adapters::consensus_module::poa::pre_confirmation_signature::{
signing_key::DummyKey,
};
use fuel_core_poa::pre_confirmation_signature_service::{
error::Result as PoAResult,
key_generator::KeyGenerator,
};

pub struct DelegateKeyGenerator;

impl KeyGenerator for DelegateKeyGenerator {
type Key = DummyKey;

async fn generate(&mut self) -> PoAResult<Self::Key> {
todo!()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use fuel_core_poa::pre_confirmation_signature_service::{
error::{
Error as PoaError,
Result as PoAResult,
},
parent_signature::ParentSignature,
};
use fuel_core_types::{
fuel_crypto,
signer::SignMode,
};

pub struct FuelParentSigner<T> {
mode: SignMode,
_phantom: std::marker::PhantomData<T>,
}

pub struct FuelParentSignature<T> {
signature: fuel_core_types::fuel_vm::Signature,
_phantom: std::marker::PhantomData<T>,
}

impl<T> FuelParentSignature<T> {
pub fn signature(&self) -> fuel_core_types::fuel_vm::Signature {
self.signature
}
}

impl<T> From<fuel_core_types::fuel_vm::Signature> for FuelParentSignature<T> {
fn from(signature: fuel_core_types::fuel_vm::Signature) -> Self {
Self {
signature,
_phantom: std::marker::PhantomData,
}
}
}

impl<T> ParentSignature<T> for FuelParentSigner<T>
where
T: Send + Sync,
T: Into<fuel_crypto::Message>,
{
type SignedData = FuelParentSignature<T>;

async fn sign(&self, data: T) -> PoAResult<Self::SignedData> {
let message = data.into();
let signature = self.mode.sign_message(message).await.map_err(|e| {
PoaError::ParentSignature(format!("Failed to sign message: {}", e))
})?;
Ok(signature.into())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use fuel_core_poa::pre_confirmation_signature_service::signing_key::SigningKey;

/// TODO: Decide what key to use for signing
/// <https://github.com/FuelLabs/fuel-core/issues/2782>
#[derive(Clone)]
pub struct DummyKey;

#[derive(Clone)]
pub struct DummyKeySignature<T> {
_phantom: std::marker::PhantomData<T>,
}

impl SigningKey for DummyKey {
type Signature<T: Send + Clone> = DummyKeySignature<T>;

fn sign<T: Send + Clone>(
&self,
_data: T,
) -> fuel_core_poa::pre_confirmation_signature_service::error::Result<
Self::Signature<T>,
> {
todo!()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use fuel_core_poa::pre_confirmation_signature_service::{
error::Result as PoAResult,
trigger::KeyRotationTrigger,
};
use std::time::Duration;

#[allow(dead_code)]
pub struct TimeBasedTrigger {
interval: tokio::time::Interval,
}

impl TimeBasedTrigger {
pub fn new(rotation_interval: Duration) -> Self {
Self {
interval: tokio::time::interval(rotation_interval),
}
}
}

impl KeyRotationTrigger for TimeBasedTrigger {
async fn next_rotation(&mut self) -> PoAResult<()> {
self.interval.tick().await;
Ok(())
}
}
#[cfg(test)]
mod tests {
#![allow(non_snake_case)]
use super::*;

#[tokio::test]
async fn next_rotation__triggers_at_expected_time() {
tokio::time::pause();
// given
let rotation_interval = 10;
let rotation_interval_duration = Duration::from_secs(rotation_interval);

let mut trigger = TimeBasedTrigger::new(rotation_interval_duration);

// when
let mut fut = tokio_test::task::spawn(trigger.next_rotation());
tokio_test::assert_pending!(fut.poll());

// then
let advance_time = Duration::from_secs(rotation_interval + 1);
tokio::time::advance(advance_time).await;
tokio_test::assert_ready!(fut.poll()).expect("should trigger");
}

#[tokio::test]
async fn next_rotation__subsequent_triggers_are_same_interval() {
tokio::time::pause();
// given
let rotation_interval = 10;
let rotation_interval_duration = Duration::from_secs(rotation_interval);

let mut trigger = TimeBasedTrigger::new(rotation_interval_duration);

tokio::time::advance(Duration::from_secs(1)).await;
trigger.next_rotation().await.unwrap();

// when
let mut fut = tokio_test::task::spawn(trigger.next_rotation());
tokio_test::assert_pending!(fut.poll());

// then
let advance_time = Duration::from_secs(rotation_interval);
tokio::time::advance(advance_time).await;
tokio_test::assert_ready!(fut.poll()).expect("should trigger");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use crate::service::adapters::consensus_module::poa::pre_confirmation_signature::Preconfirmations;
use fuel_core_poa::pre_confirmation_signature_service::{
error::{
Error as PoaError,
Result as PoAResult,
},
tx_receiver::TxReceiver,
};
use fuel_core_types::{
fuel_tx::TxId,
services::p2p::PreconfirmationStatus,
};

pub struct MPSCTxReceiver<T> {
receiver: tokio::sync::mpsc::Receiver<T>,
}

impl TxReceiver for MPSCTxReceiver<Vec<(TxId, PreconfirmationStatus)>> {
type Txs = Preconfirmations;

async fn receive(&mut self) -> PoAResult<Self::Txs> {
self.receiver.recv().await.ok_or(PoaError::TxReceiver(
"Failed to receive transaction, channel closed".to_string(),
))
}
}
#[cfg(test)]
mod tests {
#![allow(non_snake_case)]
use super::*;
use fuel_core_types::fuel_types::BlockHeight;

#[tokio::test]
async fn receive__gets_what_is_sent_through_channel() {
// given
let (sender, receiver) = tokio::sync::mpsc::channel(1);
let txs = vec![
(
TxId::default(),
PreconfirmationStatus::SuccessByBlockProducer {
block_height: BlockHeight::from(123),
},
),
(
TxId::default(),
PreconfirmationStatus::SqueezedOutByBlockProducer {
reason: "test".to_string(),
},
),
];

let mut receiver = MPSCTxReceiver { receiver };

// when
sender.send(txs.clone()).await.unwrap();

// then
let received_txs = receiver.receive().await.unwrap();
assert_eq!(txs, received_txs);
}
}
Loading
Loading