Skip to content

Commit bf86c5c

Browse files
MitchTurnerxgreenx
andauthored
add implementations for pre conf task (#2780)
## Linked Issues/PRs <!-- List of related issues/PRs --> part of #2739 ## Description <!-- List of detailed changes --> Introduced some working and some dummy implementations. We still need to implement the P2P broadcast trait and the delegate key generator stuff. We don't know what kind of keys we are going to use, so that needs to be decided on. ## Checklist - [x] New behavior is reflected in tests ### Before requesting review - [x] I have reviewed the code myself - [x] I have created follow-up issues caused by this PR and linked them here #2782 #2783 --------- Co-authored-by: Green Baneling <[email protected]>
1 parent 0eb69c4 commit bf86c5c

File tree

20 files changed

+361
-66
lines changed

20 files changed

+361
-66
lines changed

.changes/added/2780.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add implementations for the pre-confirmation signing task

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/fuel-core/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ mockall = { workspace = true }
8989
proptest = { workspace = true }
9090
test-case = { workspace = true }
9191
test-strategy = { workspace = true }
92+
tokio-test = "0.4.4"
93+
tracing-subscriber = { workspace = true }
9294

9395
[features]
9496
default = ["rocksdb"]

crates/fuel-core/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#![deny(unused_crate_dependencies)]
44
#![deny(warnings)]
55

6+
#[cfg(test)]
7+
use tracing_subscriber as _;
8+
69
use crate::service::genesis::NotifyCancel;
710
use tokio_util::sync::CancellationToken;
811

crates/fuel-core/src/service/adapters.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
use crate::{
2-
database::{
3-
database_description::relayer::Relayer,
4-
Database,
5-
},
6-
fuel_core_graphql_api::ports::GasPriceEstimate,
7-
service::{
8-
sub_services::{
9-
BlockProducerService,
10-
TxPoolSharedState,
11-
},
12-
vm_pool::MemoryPool,
13-
},
14-
};
1+
use std::sync::Arc;
2+
153
use fuel_core_consensus_module::{
164
block_verifier::Verifier,
175
RelayerConsensusConfig,
@@ -53,7 +41,21 @@ use fuel_core_types::{
5341
};
5442
//#[cfg(not(feature = "parallel-executor"))]
5543
use fuel_core_upgradable_executor::executor::Executor;
56-
use std::sync::Arc;
44+
45+
use crate::{
46+
database::{
47+
database_description::relayer::Relayer,
48+
Database,
49+
},
50+
fuel_core_graphql_api::ports::GasPriceEstimate,
51+
service::{
52+
sub_services::{
53+
BlockProducerService,
54+
TxPoolSharedState,
55+
},
56+
vm_pool::MemoryPool,
57+
},
58+
};
5759

5860
pub mod block_importer;
5961
pub mod chain_state_info_provider;
@@ -100,9 +102,10 @@ impl StaticGasPrice {
100102
mod universal_gas_price_provider_tests {
101103
#![allow(non_snake_case)]
102104

103-
use super::*;
104105
use proptest::proptest;
105106

107+
use super::*;
108+
106109
fn _worst_case__correctly_calculates_value(
107110
gas_price: u64,
108111
starting_height: u32,

crates/fuel-core/src/service/adapters/consensus_module/poa.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ use tokio_stream::{
4747
StreamExt,
4848
};
4949

50+
pub mod pre_confirmation_signature;
51+
5052
impl PoAAdapter {
5153
pub fn new(shared_state: Option<SharedState>) -> Self {
5254
Self { shared_state }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use fuel_core_types::{
2+
fuel_tx::TxId,
3+
services::p2p::PreconfirmationStatus,
4+
};
5+
6+
pub mod broadcast;
7+
pub mod key_generator;
8+
pub mod parent_signature;
9+
pub mod signing_key;
10+
pub mod trigger;
11+
pub mod tx_receiver;
12+
13+
pub type Preconfirmations = Vec<(TxId, PreconfirmationStatus)>;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use crate::service::adapters::consensus_module::poa::pre_confirmation_signature::{
2+
parent_signature::FuelParentSignature,
3+
signing_key::DummyKey,
4+
Preconfirmations,
5+
};
6+
use fuel_core_poa::pre_confirmation_signature_service::{
7+
broadcast::Broadcast,
8+
error::Result as PoAResult,
9+
Signed,
10+
};
11+
12+
/// TODO: Implement `Broadcast` properly: <https://github.com/FuelLabs/fuel-core/issues/2783>
13+
pub struct P2PBroadcast;
14+
15+
impl Broadcast for P2PBroadcast {
16+
type PreConfirmations = Preconfirmations;
17+
type ParentSignature = FuelParentSignature<DummyKey>;
18+
type DelegateKey = DummyKey;
19+
20+
async fn broadcast_txs(
21+
&mut self,
22+
_txs: Signed<Self::DelegateKey, Self::PreConfirmations>,
23+
) -> PoAResult<()> {
24+
todo!()
25+
}
26+
27+
async fn broadcast_delegate_key(
28+
&mut self,
29+
_delegate_key: Self::ParentSignature,
30+
) -> PoAResult<()> {
31+
todo!()
32+
}
33+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use crate::service::adapters::consensus_module::poa::pre_confirmation_signature::{
2+
signing_key::DummyKey,
3+
};
4+
use fuel_core_poa::pre_confirmation_signature_service::{
5+
error::Result as PoAResult,
6+
key_generator::KeyGenerator,
7+
};
8+
9+
pub struct DelegateKeyGenerator;
10+
11+
impl KeyGenerator for DelegateKeyGenerator {
12+
type Key = DummyKey;
13+
14+
async fn generate(&mut self) -> PoAResult<Self::Key> {
15+
todo!()
16+
}
17+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use fuel_core_poa::pre_confirmation_signature_service::{
2+
error::{
3+
Error as PoaError,
4+
Result as PoAResult,
5+
},
6+
parent_signature::ParentSignature,
7+
};
8+
use fuel_core_types::{
9+
fuel_crypto,
10+
signer::SignMode,
11+
};
12+
13+
pub struct FuelParentSigner<T> {
14+
mode: SignMode,
15+
_phantom: std::marker::PhantomData<T>,
16+
}
17+
18+
pub struct FuelParentSignature<T> {
19+
signature: fuel_core_types::fuel_vm::Signature,
20+
_phantom: std::marker::PhantomData<T>,
21+
}
22+
23+
impl<T> FuelParentSignature<T> {
24+
pub fn signature(&self) -> fuel_core_types::fuel_vm::Signature {
25+
self.signature
26+
}
27+
}
28+
29+
impl<T> From<fuel_core_types::fuel_vm::Signature> for FuelParentSignature<T> {
30+
fn from(signature: fuel_core_types::fuel_vm::Signature) -> Self {
31+
Self {
32+
signature,
33+
_phantom: std::marker::PhantomData,
34+
}
35+
}
36+
}
37+
38+
impl<T> ParentSignature<T> for FuelParentSigner<T>
39+
where
40+
T: Send + Sync,
41+
T: Into<fuel_crypto::Message>,
42+
{
43+
type SignedData = FuelParentSignature<T>;
44+
45+
async fn sign(&self, data: T) -> PoAResult<Self::SignedData> {
46+
let message = data.into();
47+
let signature = self.mode.sign_message(message).await.map_err(|e| {
48+
PoaError::ParentSignature(format!("Failed to sign message: {}", e))
49+
})?;
50+
Ok(signature.into())
51+
}
52+
}

0 commit comments

Comments
 (0)