Skip to content
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
69 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
502eb74
WIP integrate pre confirmations into the greater PoA service
MitchTurner Feb 28, 2025
cad5445
Introduce sender
MitchTurner Mar 1, 2025
12f853f
Get compiling with unimplemented section
MitchTurner Mar 1, 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
648cb0e
Merge branch 'feature/pre-confirmations/add-implementations-for-pre-c…
MitchTurner Mar 1, 2025
7b145dd
Ignore typo
MitchTurner Mar 1, 2025
91a5ac0
Merge branch 'feature/pre-confirmations/add-implementations-for-pre-c…
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
a381b9a
Merge branch 'feature/pre-confirmations/add-implementations-for-pre-c…
MitchTurner Mar 3, 2025
6f196ad
Update CHANGELOG
MitchTurner Mar 3, 2025
cfed22f
Remove over-constraints
MitchTurner Mar 3, 2025
22eaa46
Merge branch 'refs/heads/master' into feature/pre-confirmations/add-i…
xgreenx Mar 3, 2025
d57971d
Merge branch 'feature/pre-confirmations/add-implementations-for-pre-c…
MitchTurner Mar 3, 2025
29487a9
use tick instead of sleep, fix test
MitchTurner Mar 3, 2025
4f04933
Merge branch 'feature/pre-confirmations/add-implementations-for-pre-c…
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
ca53bf5
Merge branch 'feature/pre-confirmations/add-implementations-for-pre-c…
MitchTurner Mar 3, 2025
cef8b12
Merge branch 'refs/heads/master' into feature/pre-confirmations/integ…
xgreenx Mar 3, 2025
e84a385
Fix compilation errors
MitchTurner Mar 3, 2025
291d458
Add new ed25519 delegate signature (#2792)
MitchTurner Mar 3, 2025
eab31c4
Applied changes to run pre confirmation service as a standalone servi…
xgreenx Mar 4, 2025
5bd14eb
Merge branch 'master' into feature/pre-confirmations/integrate-task-i…
xgreenx Mar 4, 2025
5ad9c1a
Make CI happy
xgreenx Mar 4, 2025
18590a9
Merge remote-tracking branch 'origin/feature/pre-confirmations/integr…
xgreenx Mar 4, 2025
5a4fc12
Implement key generation
xgreenx Mar 4, 2025
5eaaef8
Merge branch 'master' into feature/pre-confirmations/integrate-task-i…
MitchTurner Mar 4, 2025
da350d8
Merge branch 'master' into feature/pre-confirmations/integrate-task-i…
AurelienFT Mar 4, 2025
40a927d
Merge branch 'master' into feature/pre-confirmations/integrate-task-i…
xgreenx Mar 4, 2025
4969d67
Merge branch 'master' into feature/pre-confirmations/integrate-task-i…
xgreenx Mar 4, 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/2784.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Integrate the pre conf signature task into the main consensus task
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use fuel_core_poa::pre_confirmation_signature_service::{
parent_signature::ParentSignature,
};
use fuel_core_types::{
fuel_crypto,
signer::SignMode,
};
use crate::service::adapters::consensus_module::poa::pre_confirmation_signature::signing_key::DummyKey;

pub struct FuelParentSigner<T> {
mode: SignMode,
Expand All @@ -35,14 +35,10 @@ impl<T> From<fuel_core_types::fuel_vm::Signature> for FuelParentSignature<T> {
}
}

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

async fn sign(&self, data: T) -> PoAResult<Self::SignedData> {
async fn sign(&self, data: DummyKey) -> 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))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use fuel_core_poa::pre_confirmation_signature_service::signing_key::SigningKey;
use fuel_core_types::fuel_crypto;

/// TODO: Decide what key to use for signing
/// <https://github.com/FuelLabs/fuel-core/issues/2782>
Expand All @@ -22,3 +23,9 @@ impl SigningKey for DummyKey {
todo!()
}
}

impl From<DummyKey> for fuel_crypto::Message {
fn from(_value: DummyKey) -> Self {
todo!()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,67 @@ use fuel_core_poa::pre_confirmation_signature_service::{
Error as PoaError,
Result as PoAResult,
},
tx_receiver::TxReceiver,
tx_receiver::{
TxReceiver,
TxSender,
},
};
use fuel_core_types::{
fuel_tx::TxId,
services::p2p::PreconfirmationStatus,
};

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

impl Default for MPSCTxReceiver<Vec<(TxId, PreconfirmationStatus)>> {
fn default() -> Self {
Self::new()
}
}

impl<T> MPSCTxReceiver<T> {
pub fn new() -> Self {
let (sender, receiver) = tokio::sync::mpsc::channel(1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the size of the buffer is 1? In the case of parallel executor we will have many thread who potentially can send executed transactions. I think it can be limited to a big number like 1024.

And in the receive function you can call recv_many and join all received statuses together and sign over them

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed that to be controlled outside from the sub_services perspective

MPSCTxReceiver { sender, receiver }
}
}

#[derive(Clone)]
pub struct MPSCTxSender<T> {
sender: tokio::sync::mpsc::Sender<T>,
}

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

async fn receive(&mut self) -> PoAResult<Self::Txs> {
self.receiver.recv().await.ok_or(PoaError::TxReceiver(
"Failed to receive transaction, channel closed".to_string(),
))
}

fn get_sender(&self) -> Self::Sender {
MPSCTxSender {
sender: self.sender.clone(),
}
}
}

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

async fn send(&mut self, txs: Self::Txs) -> PoAResult<()> {
self.sender
.send(txs)
.await
.map_err(|e| PoaError::TxReceiver(format!("{}", e)))
}
}

#[cfg(test)]
mod tests {
#![allow(non_snake_case)]
Expand All @@ -33,7 +74,6 @@ mod tests {
#[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(),
Expand All @@ -49,7 +89,8 @@ mod tests {
),
];

let mut receiver = MPSCTxReceiver { receiver };
let mut receiver = MPSCTxReceiver::new();
let mut sender = receiver.get_sender();

// when
sender.send(txs.clone()).await.unwrap();
Expand Down
47 changes: 45 additions & 2 deletions crates/fuel-core/src/service/sub_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ use crate::{
service::{
adapters::{
chain_state_info_provider,
consensus_module::poa::InDirectoryPredefinedBlocks,
consensus_module::poa::{
pre_confirmation_signature::{
broadcast::P2PBroadcast,
key_generator::DelegateKeyGenerator,
parent_signature::{
FuelParentSignature,
FuelParentSigner,
},
signing_key::DummyKey,
trigger::TimeBasedTrigger,
tx_receiver::MPSCTxReceiver,
Preconfirmations,
},
InDirectoryPredefinedBlocks,
},
fuel_gas_price_provider::FuelGasPriceProvider,
graphql_api::GraphQLBlockImporter,
import_result_provider::ImportResultProvider,
Expand Down Expand Up @@ -52,7 +66,11 @@ use fuel_core_gas_price_service::v1::{
metadata::V1AlgorithmConfig,
uninitialized_task::new_gas_price_service_v1,
};
use fuel_core_poa::Trigger;
use fuel_core_poa::{
pre_confirmation_signature_service::PreConfirmationSignatureTask,
Trigger,
};
use fuel_core_services::ServiceRunner;
use fuel_core_storage::{
self,
transactional::AtomicView,
Expand All @@ -70,6 +88,12 @@ pub type PoAService = fuel_core_poa::Service<
SignMode,
InDirectoryPredefinedBlocks,
SystemTime,
MPSCTxReceiver<Preconfirmations>,
P2PBroadcast,
FuelParentSignature<DummyKey>,
DelegateKeyGenerator,
DummyKey,
TimeBasedTrigger<SystemTime>,
>;
#[cfg(feature = "p2p")]
pub type P2PService = fuel_core_p2p::service::Service<Database, TxPoolAdapter>;
Expand All @@ -87,6 +111,9 @@ pub type GraphQL = fuel_core_graphql_api::api_service::Service;
// TODO: Add to consensus params https://github.com/FuelLabs/fuel-vm/issues/888
pub const DEFAULT_GAS_PRICE_CHANGE_PERCENT: u16 = 10;

#[allow(unreachable_code)]
#[allow(unused_variables)]
#[allow(clippy::diverging_sub_expression)]
pub fn init_sub_services(
config: &Config,
database: CombinedDatabase,
Expand Down Expand Up @@ -246,6 +273,7 @@ pub fn init_sub_services(
let tx_pool_adapter = TxPoolAdapter::new(txpool.shared.clone());

#[cfg(feature = "p2p")]
#[allow(unused_mut)]
let mut network = config.p2p.clone().zip(p2p_externals).map(
|(p2p_config, (shared_state, request_receiver))| {
fuel_core_p2p::service::new_service(
Expand Down Expand Up @@ -276,6 +304,7 @@ pub fn init_sub_services(
let poa_config: fuel_core_poa::Config = config.into();
let mut production_enabled = !matches!(poa_config.trigger, Trigger::Never);

#[allow(unused_assignments)]
if !production_enabled && config.debug {
production_enabled = true;
tracing::info!("Enabled manual block production because of `debug` flag");
Expand All @@ -296,6 +325,19 @@ pub fn init_sub_services(

let predefined_blocks =
InDirectoryPredefinedBlocks::new(config.predefined_blocks_path.clone());

#[allow(clippy::type_complexity)]
let pre_confirmation_service: ServiceRunner<
PreConfirmationSignatureTask<
MPSCTxReceiver<Preconfirmations>,
P2PBroadcast,
FuelParentSigner<DummyKey>,
DelegateKeyGenerator,
DummyKey,
TimeBasedTrigger<SystemTime>,
>,
> = todo!();

let poa = production_enabled.then(|| {
fuel_core_poa::new_service(
&last_block_header,
Expand All @@ -307,6 +349,7 @@ pub fn init_sub_services(
signer,
predefined_blocks,
SystemTime,
pre_confirmation_service,
)
});
let poa_adapter = PoAAdapter::new(poa.as_ref().map(|service| service.shared.clone()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use error::Result;
use fuel_core_services::{
RunnableService,
RunnableTask,
StateWatcher,
TaskNextAction,
Expand Down Expand Up @@ -43,6 +44,40 @@ pub struct PreConfirmationSignatureTask<
key_rotation_trigger: KeyRotationTrigger,
}

#[async_trait::async_trait]
impl<TxRcv, Brdcst, Parent, Gen, DelegateKey, Trigger> RunnableService
for PreConfirmationSignatureTask<TxRcv, Brdcst, Parent, Gen, DelegateKey, Trigger>
where
TxRcv: TxReceiver,
<TxRcv as TxReceiver>::Sender: Clone,
Brdcst: Broadcast<
DelegateKey = DelegateKey,
ParentSignature = Parent::SignedData,
PreConfirmations: From<TxRcv::Txs>,
>,
Parent: ParentSignature<DelegateKey>,
Gen: KeyGenerator<Key = DelegateKey>,
DelegateKey: SigningKey,
Trigger: KeyRotationTrigger,
{
const NAME: &'static str = "PreConfirmationSignatureTask";
type SharedData = TxRcv::Sender;
type Task = Self;
type TaskParams = ();

fn shared_data(&self) -> Self::SharedData {
self.tx_receiver.get_sender()
}

async fn into_task(
self,
_state_watcher: &StateWatcher,
_params: Self::TaskParams,
) -> anyhow::Result<Self::Task> {
todo!()
}
}

impl<TxRcv, Brdcst, Parent, Gen, DelegateKey, Trigger>
PreConfirmationSignatureTask<TxRcv, Brdcst, Parent, Gen, DelegateKey, Trigger>
where
Expand Down
Loading
Loading