Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions crates/fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ axum = { workspace = true }
clap = { workspace = true, features = ["derive"] }
cosmrs = { version = "0.21", optional = true }
derive_more = { version = "0.99" }
ed25519 = { version = "2.2.3", features = ["serde"] }
ed25519-dalek = { version = "2.1.1", features = ["serde"] }
enum-iterator = { workspace = true }
fuel-core-chain-config = { workspace = true, features = ["std"] }
fuel-core-compression = { workspace = true }
Expand Down Expand Up @@ -49,7 +51,7 @@ mockall = { workspace = true, optional = true }
num_cpus = { version = "1.16.0", optional = true }
parking_lot = { workspace = true }
paste = { workspace = true }
postcard = { workspace = true, optional = true }
postcard = { workspace = true }
rand = { workspace = true }
rocksdb = { version = "0.21", default-features = false, features = [
"lz4",
Expand Down Expand Up @@ -102,7 +104,7 @@ smt = [
p2p = ["dep:fuel-core-p2p", "dep:fuel-core-sync"]
relayer = ["dep:fuel-core-relayer"]
shared-sequencer = ["dep:fuel-core-shared-sequencer", "dep:cosmrs"]
rocksdb = ["dep:rocksdb", "dep:tempfile", "dep:num_cpus", "dep:postcard"]
rocksdb = ["dep:rocksdb", "dep:tempfile", "dep:num_cpus"]
backup = ["rocksdb", "fuel-core-database/backup"]
test-helpers = [
"fuel-core-database/test-helpers",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
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
@@ -1,32 +1,41 @@
use crate::service::adapters::consensus_module::poa::pre_confirmation_signature::{
parent_signature::FuelParentSignature,
signing_key::DummyKey,
Preconfirmations,
key_generator::Ed25519Key,
parent_signature::FuelParentSigner,
};
use fuel_core_poa::pre_confirmation_signature_service::{
broadcast::Broadcast,
broadcast::{
Broadcast,
PublicKey,
Signature,
},
error::Result as PoAResult,
Signed,
parent_signature::ParentSignature,
};
use fuel_core_types::services::p2p::{
DelegatePreConfirmationKey,
Preconfirmation,
};

/// 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;
type DelegateKey = Ed25519Key;
type ParentKey = FuelParentSigner;
type Preconfirmations = Vec<Preconfirmation>;

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

async fn broadcast_delegate_key(
&mut self,
_delegate_key: Self::ParentSignature,
_: DelegatePreConfirmationKey<PublicKey<Self>>,
_: <Self::ParentKey as ParentSignature>::Signature,
) -> PoAResult<()> {
todo!()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,56 @@
use crate::service::adapters::consensus_module::poa::pre_confirmation_signature::{
signing_key::DummyKey,
};
use ed25519::signature::Signer;
use ed25519_dalek::SigningKey as DalekSigningKey;
use fuel_core_poa::pre_confirmation_signature_service::{
error::Result as PoAResult,
error::{
Error as PoAError,
Result as PoAResult,
},
key_generator::KeyGenerator,
signing_key::SigningKey,
};
use fuel_core_types::fuel_crypto::SecretKey;
use rand::{
prelude::StdRng,
SeedableRng,
};
use serde::Serialize;
use std::ops::Deref;

pub struct DelegateKeyGenerator;
pub struct Ed25519KeyGenerator;

impl KeyGenerator for DelegateKeyGenerator {
type Key = DummyKey;
impl KeyGenerator for Ed25519KeyGenerator {
type Key = Ed25519Key;

async fn generate(&mut self) -> PoAResult<Self::Key> {
todo!()
let mut rng = StdRng::from_entropy();
let secret = SecretKey::random(&mut rng);

Ok(Ed25519Key {
signer: DalekSigningKey::from_bytes(secret.deref()),
})
}
}

#[derive(Clone)]
pub struct Ed25519Key {
signer: DalekSigningKey,
}

impl SigningKey for Ed25519Key {
type Signature = ed25519::Signature;
type PublicKey = ed25519_dalek::VerifyingKey;

fn public_key(&self) -> Self::PublicKey {
self.signer.verifying_key()
}

fn sign<T>(&self, data: &T) -> PoAResult<Self::Signature>
where
T: Serialize,
{
let bytes = postcard::to_allocvec(data)
.map_err(|e| PoAError::Signature(format!("{e:?}")))?;
let signature = self.signer.sign(&bytes);
Ok(signature)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,28 @@ use fuel_core_poa::pre_confirmation_signature_service::{
};
use fuel_core_types::{
fuel_crypto,
fuel_vm::Signature,
signer::SignMode,
};
use serde::Serialize;

pub struct FuelParentSigner<T> {
pub struct FuelParentSigner {
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>;
impl ParentSignature for FuelParentSigner {
type Signature = Signature;

async fn sign(&self, data: T) -> PoAResult<Self::SignedData> {
let message = data.into();
async fn sign<T>(&self, data: &T) -> PoAResult<Self::Signature>
where
T: Serialize + Send + Sync,
{
let bytes = postcard::to_allocvec(data)
.map_err(|e| PoaError::ParentSignature(format!("{e:?}")))?;
let message = fuel_crypto::Message::new(bytes);
let signature = self.mode.sign_message(message).await.map_err(|e| {
PoaError::ParentSignature(format!("Failed to sign message: {}", e))
})?;
Ok(signature.into())
Ok(signature)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,58 +1,84 @@
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,
};
use fuel_core_types::services::p2p::Preconfirmation;
use tokio::sync::mpsc;

pub struct PreconfirmationsReceiver {
capacity: usize,
receiver: mpsc::Receiver<Vec<Preconfirmation>>,
}

impl Default for PreconfirmationsReceiver {
fn default() -> Self {
let (_, receiver) = mpsc::channel(1);
Self::new(receiver)
}
}

// TODO(#2739): Remove when integrated
// link: https://github.com/FuelLabs/fuel-core/issues/2739
#[allow(dead_code)]
pub struct MPSCTxReceiver<T> {
receiver: tokio::sync::mpsc::Receiver<T>,
impl PreconfirmationsReceiver {
pub fn new(receiver: mpsc::Receiver<Vec<Preconfirmation>>) -> Self {
let capacity = receiver.capacity();
PreconfirmationsReceiver { capacity, receiver }
}
}

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

async fn receive(&mut self) -> PoAResult<Self::Txs> {
self.receiver.recv().await.ok_or(PoaError::TxReceiver(
"Failed to receive transaction, channel closed".to_string(),
))
let mut buffer = Vec::new();
let received = self.receiver.recv_many(&mut buffer, self.capacity).await;

if received == 0 {
return Err(PoaError::TxReceiver(
"Failed to receive transaction, channel closed".to_string(),
));
}

Ok(buffer.into_iter().flatten().collect::<Vec<_>>())
}
}

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

use super::*;
use fuel_core_types::fuel_types::BlockHeight;
use fuel_core_types::{
fuel_tx::TxId,
fuel_types::BlockHeight,
services::p2p::PreconfirmationStatus,
};

#[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 {
Preconfirmation {
tx_id: TxId::default(),
status: PreconfirmationStatus::SuccessByBlockProducer {
block_height: BlockHeight::from(123),
},
),
(
TxId::default(),
PreconfirmationStatus::SqueezedOutByBlockProducer {
},
Preconfirmation {
tx_id: TxId::default(),
status: PreconfirmationStatus::SqueezedOutByBlockProducer {
reason: "test".to_string(),
},
),
},
];

let mut receiver = MPSCTxReceiver { receiver };
let (sender, receiver) = mpsc::channel(1);

let mut receiver = PreconfirmationsReceiver::new(receiver);

// when
sender.send(txs.clone()).await.unwrap();
Expand Down
5 changes: 4 additions & 1 deletion crates/fuel-core/src/service/adapters/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use fuel_core_storage::transactional::{
use fuel_core_types::blockchain::primitives::DaBlockHeight;

impl Transactional for Database<Relayer> {
type Transaction<'a> = StorageTransaction<&'a mut Self> where Self: 'a;
type Transaction<'a>
= StorageTransaction<&'a mut Self>
where
Self: 'a;

fn transaction(&mut self) -> Self::Transaction<'_> {
self.into_transaction()
Expand Down
Loading
Loading