Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freesig/sync e2e testing #934

Merged
merged 29 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bc14a76
add trace logging to fuel core
freesig Jan 25, 2023
9a1e882
toml
freesig Jan 25, 2023
282d472
tracing on fuel sync
freesig Jan 25, 2023
6304761
add tracing to next event p2p
freesig Jan 25, 2023
79181c3
add more e2e tests for sync
freesig Jan 25, 2023
15201f0
Merge branch 'master' of github.com:FuelLabs/fuel-core into freesig/s…
freesig Jan 25, 2023
0e40e0c
Merge branch 'master' of github.com:FuelLabs/fuel-core into freesig/s…
freesig Jan 26, 2023
6c3d2a1
add tracing of tx pool
freesig Jan 26, 2023
7edca4c
move state change to info
freesig Jan 26, 2023
5146da1
Merge branch 'master' of github.com:FuelLabs/fuel-core into freesig/s…
freesig Jan 26, 2023
f111d14
Merge branch 'freesig/sync-tracing' of github.com:FuelLabs/fuel-core …
freesig Jan 26, 2023
7dfed30
add more tracing and p2p sync tests
freesig Jan 26, 2023
1c8a9a0
fix toml
freesig Jan 26, 2023
f14271d
Merge branch 'master' into freesig/sync-tracing
freesig Jan 26, 2023
df18fa7
Merge branch 'freesig/sync-tracing' into freesig/sync-e2e-testing
freesig Jan 26, 2023
c3897c0
change test names
freesig Jan 26, 2023
f3698ee
Merge branch 'master' into freesig/sync-e2e-testing
Voxelot Jan 26, 2023
c539df1
Calculate genesis hash correctly including all fields
xgreenx Jan 26, 2023
1c5d8e0
Fix the `test_multiple_producers_different_keys` test.
xgreenx Jan 26, 2023
f2a31ed
Push my changes
xgreenx Jan 26, 2023
4ab83e3
Merge branch 'master' into freesig/sync-e2e-testing
Voxelot Jan 27, 2023
e44d983
Merge branch 'master' into freesig/sync-e2e-testing
Voxelot Jan 27, 2023
8fbd609
more merging
Voxelot Jan 27, 2023
49b4853
Replaced mdns with bootstrap nodes. All validators have access to boo…
xgreenx Jan 27, 2023
4cfc997
Merge branch 'master' into freesig/sync-e2e-testing
freesig Jan 27, 2023
0f93c46
cleanup
freesig Jan 27, 2023
7777046
Merge branch 'master' into freesig/sync-e2e-testing
freesig Jan 27, 2023
d311e17
Fixed all tests.
xgreenx Jan 27, 2023
ed3da6b
Don't enable `fuel-core-sync` if block production enabled.
xgreenx Jan 27, 2023
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
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.

1 change: 1 addition & 0 deletions bin/fuel-core/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ impl Command {
#[cfg(feature = "p2p")]
sync: sync_args.into(),
consensus_key,
name: String::default(),
})
}
}
Expand Down
43 changes: 39 additions & 4 deletions crates/chain-config/src/config/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,26 @@ impl FromStr for ChainConfig {

impl GenesisCommitment for ChainConfig {
fn root(&self) -> anyhow::Result<MerkleRoot> {
// TODO: Hash settlement configuration, consensus block production
// # Dev-note: If `ChainConfig` got a new field, maybe we need to hash it too.
// Avoid using the `..` in the code below. Use `_` instead if you don't need to hash
// the field. Explicit fields help to prevent a bug of missing fields in the hash.
let ChainConfig {
chain_name,
block_gas_limit,
// Skip the `initial_state` bec
initial_state: _,
transaction_parameters,
gas_costs,
consensus,
} = self;

// TODO: Hash settlement configuration when it will be available.
let config_hash = *Hasher::default()
.chain(self.block_gas_limit.to_be_bytes())
.chain(self.transaction_parameters.root()?)
.chain(self.chain_name.as_bytes())
.chain(chain_name.as_bytes())
.chain(block_gas_limit.to_be_bytes())
.chain(transaction_parameters.root()?)
.chain(gas_costs.root()?)
.chain(consensus.root()?)
.finalize();

Ok(config_hash)
Expand All @@ -188,3 +203,23 @@ impl GenesisCommitment for ConsensusParameters {
Ok(params_hash.into())
}
}

impl GenesisCommitment for GasCosts {
fn root(&self) -> anyhow::Result<MerkleRoot> {
// TODO: Define hash algorithm for `GasCosts`
let bytes = postcard::to_stdvec(&self)?;
let hash = Hasher::default().chain(bytes).finalize();

Ok(hash.into())
}
}

impl GenesisCommitment for ConsensusConfig {
fn root(&self) -> anyhow::Result<MerkleRoot> {
// TODO: Define hash algorithm for `ConsensusConfig`
let bytes = postcard::to_stdvec(&self)?;
let hash = Hasher::default().chain(bytes).finalize();

Ok(hash.into())
}
}
1 change: 1 addition & 0 deletions crates/fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ metrics = ["dep:fuel-core-metrics"]
p2p = ["dep:fuel-core-p2p", "dep:fuel-core-sync"]
relayer = ["dep:fuel-core-relayer"]
rocksdb = ["dep:rocksdb", "dep:tempfile"]
test-helpers = []
# features to enable in production, but increase build times
rocksdb-production = ["rocksdb?/jemalloc"]
12 changes: 8 additions & 4 deletions crates/fuel-core/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use self::adapters::BlockImporterAdapter;

pub mod adapters;
pub mod config;
pub(crate) mod genesis;
pub mod genesis;
pub mod metrics;
pub mod sub_services;

Expand All @@ -44,6 +44,9 @@ pub struct SharedState {
pub graph_ql: crate::fuel_core_graphql_api::service::SharedState,
/// Subscribe to new block production.
pub block_importer: BlockImporterAdapter,
#[cfg(feature = "test-helpers")]
/// The config of the service.
pub config: Config,
}

pub struct FuelService {
Expand All @@ -61,7 +64,7 @@ pub struct FuelService {

impl FuelService {
/// Creates a `FuelService` instance from service config
#[tracing::instrument(skip_all)]
#[tracing::instrument(skip_all, fields(name = %config.name))]
pub fn new(database: Database, mut config: Config) -> anyhow::Result<Self> {
Self::make_config_consistent(&mut config);
let task = Task::new(database, config)?;
Expand Down Expand Up @@ -212,6 +215,7 @@ impl RunnableService for Task {

#[async_trait::async_trait]
impl RunnableTask for Task {
#[tracing::instrument(skip_all)]
async fn run(&mut self, watcher: &mut StateWatcher) -> anyhow::Result<bool> {
let mut stop_signals = vec![];
for service in &self.services {
Expand Down Expand Up @@ -326,8 +330,8 @@ mod tests {
// }
#[cfg(feature = "p2p")]
{
// p2p + sync
expected_services += 2;
// p2p
expected_services += 1;
}

// # Dev-note: Update the `expected_services` when we add/remove a new/old service.
Expand Down
11 changes: 11 additions & 0 deletions crates/fuel-core/src/service/adapters/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ impl PeerToPeerPort for P2PAdapter {

#[async_trait::async_trait]
impl BlockImporterPort for BlockImporterAdapter {
fn committed_height_stream(&self) -> BoxStream<BlockHeight> {
use futures::StreamExt;
fuel_core_services::stream::IntoBoxStream::into_boxed(
tokio_stream::wrappers::BroadcastStream::new(self.block_importer.subscribe())
.filter_map(|r| {
futures::future::ready(
r.ok().map(|r| *r.sealed_block.entity.header().height()),
)
}),
)
}
async fn execute_and_commit(&self, block: SealedBlock) -> anyhow::Result<()> {
self.execute_and_commit(block).await
}
Expand Down
2 changes: 2 additions & 0 deletions crates/fuel-core/src/service/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct Config {
#[cfg(feature = "p2p")]
pub sync: fuel_core_sync::Config,
pub consensus_key: Option<Secret<SecretKeyWrapper>>,
pub name: String,
}

impl Config {
Expand Down Expand Up @@ -84,6 +85,7 @@ impl Config {
max_get_txns_requests: 10,
},
consensus_key: Some(Secret::new(default_consensus_dev_key().into())),
name: String::default(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/fuel-core/src/service/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use fuel_core_types::{
use itertools::Itertools;

/// Loads state from the chain config into database
pub(crate) fn maybe_initialize_state(
pub fn maybe_initialize_state(
config: &Config,
database: &Database,
) -> anyhow::Result<()> {
Expand Down
17 changes: 14 additions & 3 deletions crates/fuel-core/src/service/sub_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
SubServices,
},
};
use fuel_core_poa::Trigger;
use std::sync::Arc;
use tokio::sync::{
Mutex,
Expand Down Expand Up @@ -112,9 +113,12 @@ pub fn init_sub_services(
};
let producer_adapter = BlockProducerAdapter::new(block_producer);

let poa_config: fuel_core_poa::Config = config.try_into()?;
let production_enabled =
!matches!(poa_config.trigger, Trigger::Never) || config.manual_blocks_enabled;
let poa = fuel_core_poa::new_service(
last_height,
config.try_into()?,
poa_config,
tx_pool_adapter,
producer_adapter.clone(),
importer_adapter.clone(),
Expand Down Expand Up @@ -166,17 +170,22 @@ pub fn init_sub_services(
relayer: relayer_service.as_ref().map(|r| r.shared.clone()),
graph_ql: graph_ql.shared.clone(),
block_importer: importer_adapter,
#[cfg(feature = "test-helpers")]
config: config.clone(),
};

#[allow(unused_mut)]
// `FuelService` starts and shutdowns all sub-services in the `services` order
let mut services: SubServices = vec![
// GraphQL should be shutdown first, so let's start it first.
Box::new(graph_ql),
Box::new(poa),
Box::new(txpool),
];

if production_enabled {
services.push(Box::new(poa));
}

#[cfg(feature = "relayer")]
if let Some(relayer) = relayer_service {
services.push(Box::new(relayer));
Expand All @@ -185,7 +194,9 @@ pub fn init_sub_services(
#[cfg(feature = "p2p")]
{
services.push(Box::new(network));
services.push(Box::new(sync));
if !production_enabled {
services.push(Box::new(sync));
}
}

Ok((services, shared))
Expand Down
10 changes: 10 additions & 0 deletions crates/services/importer/src/importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ where
self._commit_result(result)
}

#[tracing::instrument(
skip_all,
fields(
block_id = %result.result().sealed_block.entity.id(),
height = **result.result().sealed_block.entity.header().height(),
tx_status = ?result.result().tx_status,
),
err
)]
fn _commit_result<ExecutorDatabase>(
&self,
result: UncommittedResult<StorageTransaction<ExecutorDatabase>>,
Expand Down Expand Up @@ -221,6 +230,7 @@ where

db_tx.commit()?;

tracing::info!("Committed block");
let _ = self.broadcast.send(Arc::new(result));
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/services/p2p/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl Config<NotInitialized> {
max_peers_connected: 50,
max_connections_per_peer: 3,
allow_private_addresses: true,
random_walk: Some(Duration::from_secs(5)),
random_walk: Some(Duration::from_millis(500)),
connection_idle_timeout: Some(Duration::from_secs(120)),
reserved_nodes: vec![],
reserved_nodes_only_mode: false,
Expand Down
4 changes: 0 additions & 4 deletions crates/services/p2p/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ impl NetworkBehaviour for DiscoveryBehaviour {
}
}

if let Some(next_event) = self.pending_events.pop_front() {
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(next_event))
}

Poll::Pending
}

Expand Down
6 changes: 6 additions & 0 deletions crates/services/p2p/src/heartbeat/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ impl HeartbeatConfig {
}
}

impl Default for HeartbeatConfig {
fn default() -> Self {
Self::new()
}
}

#[derive(Debug)]
pub enum HeartbeatFailure {
Timeout,
Expand Down
8 changes: 7 additions & 1 deletion crates/services/p2p/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod behavior;
mod codecs;
pub mod codecs;
pub mod config;
mod discovery;
mod gossipsub;
Expand All @@ -13,9 +13,15 @@ pub mod service;
pub use gossipsub::config as gossipsub_config;

pub use libp2p::{
multiaddr::Protocol,
Multiaddr,
PeerId,
};

#[cfg(feature = "test-helpers")]
pub mod network_service {
pub use crate::p2p_service::*;
}

#[cfg(test)]
fuel_core_trace::enable_tracing!();
5 changes: 5 additions & 0 deletions crates/services/p2p/src/p2p_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ impl<Codec: NetworkCodec> FuelP2PService<Codec> {
Ok(())
}

#[cfg(feature = "test-helpers")]
pub fn listeners(&self) -> impl Iterator<Item = &Multiaddr> {
self.swarm.listeners()
}

pub fn get_peers_ids(&self) -> impl Iterator<Item = &PeerId> {
self.swarm.behaviour().get_peers_ids()
}
Expand Down
Loading