diff --git a/bin/fuel-core/src/cli/run/consensus.rs b/bin/fuel-core/src/cli/run/consensus.rs index adfb115e20..1e638051e5 100644 --- a/bin/fuel-core/src/cli/run/consensus.rs +++ b/bin/fuel-core/src/cli/run/consensus.rs @@ -12,8 +12,6 @@ pub struct PoATriggerArgs { #[clap(flatten)] instant: Instant, #[clap(flatten)] - hybrid: Hybrid, - #[clap(flatten)] interval: Interval, } @@ -21,19 +19,6 @@ pub struct PoATriggerArgs { impl From for PoATrigger { fn from(value: PoATriggerArgs) -> Self { match value { - PoATriggerArgs { - hybrid: - Hybrid { - idle_time: Some(idle_time), - min_time: Some(min_time), - max_time: Some(max_time), - }, - .. - } => PoATrigger::Hybrid { - min_block_time: min_time.into(), - max_tx_idle_time: idle_time.into(), - max_block_time: max_time.into(), - }, PoATriggerArgs { interval: Interval { period: Some(p) }, .. @@ -50,7 +35,7 @@ impl From for PoATrigger { #[derive(Debug, Clone, clap::Args)] #[clap( - group = ArgGroup::new("instant-mode").args(&["instant"]).conflicts_with_all(&["interval-mode", "hybrid-mode"]), + group = ArgGroup::new("instant-mode").args(&["instant"]).conflicts_with_all(&["interval-mode"]), )] struct Instant { /// Use instant block production mode. @@ -68,39 +53,7 @@ enum Boolean { #[derive(Debug, Clone, clap::Args)] #[clap( - group = ArgGroup::new("hybrid-mode") - .args(&["min_time", "idle_time", "max_time"]) - .multiple(true) - .conflicts_with_all(&["interval-mode", "instant-mode"]), -)] -struct Hybrid { - /// Hybrid trigger option. - /// Sets a minimum lower bound between blocks. This should be set high enough to ensure - /// peers can sync the blockchain. - /// Cannot be combined with other poa mode options (instant or interval). - #[arg(long = "poa-hybrid-min-time", requires_all = ["idle_time", "max_time"], env)] - min_time: Option, - /// Hybrid trigger option. - /// Sets the max time block production will wait after a period of inactivity before producing - /// a new block. If there are txs available but not enough for a full block, - /// this is how long the trigger will wait for more txs. - /// This ensures that if a burst of transactions are submitted, - /// they will all be included into the next block instead of making a new block immediately and - /// then waiting for the minimum block time to process the rest. - /// Cannot be combined with other poa mode options (instant or interval). - #[arg(long = "poa-hybrid-idle-time", requires_all = ["min_time", "max_time"], env)] - idle_time: Option, - /// Hybrid trigger option. - /// Sets the maximum time block production will wait to produce a block (even if empty). This - /// ensures that there is a regular cadence even under sustained load. - /// Cannot be combined with other poa mode options (instant or interval). - #[arg(long = "poa-hybrid-max-time", requires_all = ["min_time", "idle_time"], env)] - max_time: Option, -} - -#[derive(Debug, Clone, clap::Args)] -#[clap( - group = ArgGroup::new("interval-mode").args(&["period"]).conflicts_with_all(&["instant-mode", "hybrid-mode"]), + group = ArgGroup::new("interval-mode").args(&["period"]).conflicts_with_all(&["instant-mode"]), )] struct Interval { /// Interval trigger option. @@ -124,22 +77,10 @@ mod tests { trigger: PoATriggerArgs, } - pub fn hybrid(min_t: u64, mi_t: u64, max_t: u64) -> Trigger { - Trigger::Hybrid { - min_block_time: StdDuration::from_secs(min_t), - max_tx_idle_time: StdDuration::from_secs(mi_t), - max_block_time: StdDuration::from_secs(max_t), - } - } - #[test_case(&[] => Ok(Trigger::Instant); "defaults to instant trigger")] #[test_case(&["", "--poa-instant=false"] => Ok(Trigger::Never); "never trigger if instant is explicitly disabled")] #[test_case(&["", "--poa-interval-period=1s"] => Ok(Trigger::Interval { block_time: StdDuration::from_secs(1)}); "uses interval mode if set")] - #[test_case(&["", "--poa-hybrid-min-time=1s", "--poa-hybrid-idle-time=2s", "--poa-hybrid-max-time=3s"] => Ok(hybrid(1,2,3)); "uses hybrid mode if set")] - #[test_case(&["", "--poa-interval-period=1s", "--poa-hybrid-min-time=1s", "--poa-hybrid-idle-time=2s", "--poa-hybrid-max-time=3s"] => Err(()); "can't set hybrid and interval at the same time")] - #[test_case(&["", "--poa-instant=true", "--poa-hybrid-min-time=1s", "--poa-hybrid-idle-time=2s", "--poa-hybrid-max-time=3s"] => Err(()); "can't set hybrid and instant at the same time")] #[test_case(&["", "--poa-instant=true", "--poa-interval-period=1s"] => Err(()); "can't set interval and instant at the same time")] - #[test_case(&["", "--poa-hybrid-min-time=1s"] => Err(()); "can't set hybrid min time without idle and max")] fn parse(args: &[&str]) -> Result { Command::try_parse_from(args) .map_err(|_| ()) diff --git a/crates/services/consensus_module/poa/src/config.rs b/crates/services/consensus_module/poa/src/config.rs index e766d9fd9c..5380b3dd75 100644 --- a/crates/services/consensus_module/poa/src/config.rs +++ b/crates/services/consensus_module/poa/src/config.rs @@ -42,20 +42,4 @@ pub enum Trigger { Never, /// A new block is produced periodically. Used to simulate consensus block delay. Interval { block_time: Duration }, - /// A new block will be produced when the timer runs out. - /// Set to `max_block_time` when the txpool is empty, otherwise - /// `min(max_block_time, max_tx_idle_time)`. If it expires, - /// but minimum block time hasn't expired yet, then the deadline - /// is set to `last_block_created + min_block_time`. - /// See https://github.com/FuelLabs/fuel-core/issues/50#issuecomment-1241895887 - /// Requires `min_block_time` <= `max_tx_idle_time` <= `max_block_time`. - Hybrid { - /// Minimum time between two blocks, even if there are more txs available - min_block_time: Duration, - /// If there are txs available, but not enough for a full block, - /// this is how long the block is waiting for more txs - max_tx_idle_time: Duration, - /// Time after which a new block is produced, even if it's empty - max_block_time: Duration, - }, } diff --git a/crates/services/consensus_module/poa/src/service.rs b/crates/services/consensus_module/poa/src/service.rs index e908f01184..edb63777fa 100644 --- a/crates/services/consensus_module/poa/src/service.rs +++ b/crates/services/consensus_module/poa/src/service.rs @@ -228,9 +228,6 @@ where Trigger::Interval { block_time } => { increase_time(self.last_timestamp, block_time) } - Trigger::Hybrid { min_block_time, .. } => { - increase_time(self.last_timestamp, min_block_time) - } }, RequestType::Trigger => { let now = Tai64::now(); @@ -357,36 +354,6 @@ where .set_deadline(last_block_created + block_time, OnConflict::Overwrite) .await; } - ( - Trigger::Hybrid { - max_block_time, - min_block_time, - max_tx_idle_time, - }, - RequestType::Trigger, - ) => { - let consumable_gas = self.txpool.total_consumable_gas(); - - // If txpool still has more than a full block of transactions available, - // produce new block in min_block_time. - if consumable_gas > self.block_gas_limit { - self.timer - .set_timeout(min_block_time, OnConflict::Max) - .await; - } else if self.txpool.pending_number() > 0 { - // If we still have available txs, reduce the timeout to max idle time - self.timer - .set_timeout(max_tx_idle_time, OnConflict::Max) - .await; - } else { - self.timer - .set_timeout(max_block_time, OnConflict::Max) - .await; - } - } - (Trigger::Hybrid { .. }, RequestType::Manual) => { - unreachable!("Trigger types hybrid cannot be used with manual. This is enforced during config validation") - } } Ok(()) @@ -403,28 +370,6 @@ where Ok(()) } Trigger::Never | Trigger::Interval { .. } => Ok(()), - Trigger::Hybrid { - max_tx_idle_time, - min_block_time, - .. - } => { - let consumable_gas = self.txpool.total_consumable_gas(); - - // If we have over one full block of transactions and min_block_time - // has expired, start block production immediately - if consumable_gas > self.block_gas_limit - && self.last_block_created + min_block_time < Instant::now() - { - self.produce_next_block().await?; - } else if self.txpool.pending_number() > 0 { - // We have at least one transaction, so tx_max_idle_time is the limit - self.timer - .set_timeout(max_tx_idle_time, OnConflict::Min) - .await; - } - - Ok(()) - } } } @@ -434,13 +379,7 @@ where unreachable!("Timer is never set in this mode"); } // In the Interval mode the timer expires only when a new block should be created. - // In the Hybrid mode the timer can be either: - // 1. min_block_time expired after it was set when a block - // would have been produced too soon - // 2. max_tx_idle_time expired after a tx has arrived - // 3. max_block_time expired - // => we produce a new block in any case - Trigger::Interval { .. } | Trigger::Hybrid { .. } => { + Trigger::Interval { .. } => { self.produce_next_block().await?; Ok(()) } @@ -477,11 +416,6 @@ where .set_timeout(block_time, OnConflict::Overwrite) .await; } - Trigger::Hybrid { max_block_time, .. } => { - self.timer - .set_timeout(max_block_time, OnConflict::Overwrite) - .await; - } }; Ok(self) diff --git a/crates/services/consensus_module/poa/src/service_test.rs b/crates/services/consensus_module/poa/src/service_test.rs index c6d4b42826..b2626997d2 100644 --- a/crates/services/consensus_module/poa/src/service_test.rs +++ b/crates/services/consensus_module/poa/src/service_test.rs @@ -26,7 +26,6 @@ use fuel_core_types::{ primitives::SecretKeyWrapper, SealedBlock, }, - fuel_asm::*, fuel_crypto::SecretKey, fuel_tx::{ field::GasLimit, @@ -387,69 +386,6 @@ async fn does_not_produce_when_txpool_empty_in_instant_mode() { task.on_txpool_event().await.unwrap(); } -#[tokio::test(start_paused = true)] -async fn hybrid_production_doesnt_produce_empty_blocks_when_txpool_is_empty() { - // verify the PoA service doesn't alter the hybrid block timing when - // receiving txpool events if txpool is actually empty - let mut rng = StdRng::seed_from_u64(2322); - let secret_key = SecretKey::random(&mut rng); - - const TX_IDLE_TIME_MS: u64 = 50u64; - - let mut block_producer = MockBlockProducer::default(); - - block_producer - .expect_produce_and_execute_block() - .returning(|_, _, _| panic!("Block production should not be called")); - - let mut block_importer = MockBlockImporter::default(); - - block_importer - .expect_commit_result() - .returning(|_| panic!("Block importer should not be called")); - - block_importer - .expect_block_stream() - .returning(|| Box::pin(tokio_stream::pending())); - - let mut txpool = MockTransactionPool::no_tx_updates(); - txpool.expect_total_consumable_gas().returning(|| 0); - txpool.expect_pending_number().returning(|| 0); - - let config = Config { - trigger: Trigger::Hybrid { - min_block_time: Duration::from_millis(100), - max_tx_idle_time: Duration::from_millis(TX_IDLE_TIME_MS), - max_block_time: Duration::from_millis(1000), - }, - block_gas_limit: 1000000, - signing_key: Some(Secret::new(secret_key.into())), - metrics: false, - ..Default::default() - }; - - let p2p_port = generate_p2p_port(); - - let task = MainTask::new( - &BlockHeader::new_block(BlockHeight::from(1u32), Tai64::now()), - config, - txpool, - block_producer, - block_importer, - p2p_port, - ); - - let service = Service::new(task); - service.start_and_await().await.unwrap(); - - // wait max_tx_idle_time - causes block production to occur if - // pending txs > 0 is not checked. - time::sleep(Duration::from_millis(TX_IDLE_TIME_MS)).await; - - service.stop_and_await().await.unwrap(); - assert!(service.state().stopped()); -} - fn test_signing_key() -> Secret { let mut rng = StdRng::seed_from_u64(0); let secret_key = SecretKey::random(&mut rng); diff --git a/crates/services/consensus_module/poa/src/service_test/trigger_tests.rs b/crates/services/consensus_module/poa/src/service_test/trigger_tests.rs index 0efdb2d9dd..ed886f1fe6 100644 --- a/crates/services/consensus_module/poa/src/service_test/trigger_tests.rs +++ b/crates/services/consensus_module/poa/src/service_test/trigger_tests.rs @@ -8,11 +8,6 @@ async fn clean_startup_shutdown_each_trigger() -> anyhow::Result<()> { Trigger::Interval { block_time: Duration::new(1, 0), }, - Trigger::Hybrid { - min_block_time: Duration::new(1, 0), - max_tx_idle_time: Duration::new(1, 0), - max_block_time: Duration::new(1, 0), - }, ] { let mut ctx_builder = TestContextBuilder::new(); ctx_builder.with_config(Config { @@ -249,251 +244,3 @@ async fn interval_trigger_doesnt_react_to_full_txpool() -> anyhow::Result<()> { Ok(()) } - -#[tokio::test(start_paused = true)] -async fn hybrid_trigger_produces_blocks_correctly_max_block_time() -> anyhow::Result<()> { - let mut ctx = DefaultContext::new(Config { - trigger: Trigger::Hybrid { - min_block_time: Duration::new(2, 0), - max_tx_idle_time: Duration::new(3, 0), - max_block_time: Duration::new(10, 0), - }, - block_gas_limit: 100_000, - signing_key: Some(test_signing_key()), - metrics: false, - ..Default::default() - }); - - // Make sure no blocks are produced yet - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - - // Make sure no blocks are produced when txpool is empty and max_block_time is not exceeded - time::sleep(Duration::new(9, 0)).await; - - // Make sure the empty block is actually produced - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - - time::sleep(Duration::new(2, 0)).await; - assert!(matches!(ctx.block_import.try_recv(), Ok(_))); - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - - // Stop - ctx.test_ctx.service.stop_and_await().await?; - - Ok(()) -} - -#[tokio::test(start_paused = true)] -async fn hybrid_trigger_produces_blocks_correctly_max_block_time_not_overrides_max_tx_idle_time( -) -> anyhow::Result<()> { - const MIN_BLOCK_TIME: u64 = 6; - const MAX_TX_IDLE_TIME: u64 = 3; - const MAX_BLOCK_TIME: u64 = 10; - let mut ctx = DefaultContext::new(Config { - trigger: Trigger::Hybrid { - min_block_time: Duration::new(MIN_BLOCK_TIME, 0), - max_tx_idle_time: Duration::new(MAX_TX_IDLE_TIME, 0), - max_block_time: Duration::new(MAX_BLOCK_TIME, 0), - }, - // We want to test behaviour when the gas of all transactions < `block_gas_limit` - block_gas_limit: Word::MAX, - signing_key: Some(test_signing_key()), - metrics: false, - ..Default::default() - }); - - // Make sure no blocks are produced when txpool is empty and `MAX_BLOCK_TIME` is not exceeded - time::sleep(Duration::new(9, 0)).await; - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - - // Emulate tx status update to trigger the execution. It should produce the block after - // `MAX_TX_IDLE_TIME`. - ctx.status_sender.send_replace(Some(TxId::zeroed())); - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - - time::sleep(Duration::new(2, 0)).await; - assert!(matches!(ctx.block_import.try_recv(), Ok(_))); - - // Stop - ctx.test_ctx.service.stop_and_await().await?; - - Ok(()) -} - -#[tokio::test(start_paused = true)] -async fn hybrid_trigger_produces_blocks_correctly_max_tx_idle_time() -> anyhow::Result<()> -{ - const MIN_BLOCK_TIME: u64 = 6; - const MAX_TX_IDLE_TIME: u64 = 3; - const MAX_BLOCK_TIME: u64 = 10; - let mut ctx = DefaultContext::new(Config { - trigger: Trigger::Hybrid { - min_block_time: Duration::new(MIN_BLOCK_TIME, 0), - max_tx_idle_time: Duration::new(MAX_TX_IDLE_TIME, 0), - max_block_time: Duration::new(MAX_BLOCK_TIME, 0), - }, - // We want to test behaviour when the gas of all transactions < `block_gas_limit` - block_gas_limit: Word::MAX, - signing_key: Some(test_signing_key()), - metrics: false, - ..Default::default() - }); - - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - - // Emulate tx status update to trigger the execution. - ctx.status_sender.send_replace(Some(TxId::zeroed())); - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - - time::sleep(Duration::new(1, 0)).await; - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - - time::sleep(Duration::new(1, 0)).await; - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - - time::sleep(Duration::new(2, 0)).await; - assert!(matches!(ctx.block_import.try_recv(), Ok(_))); - - // Stop - ctx.test_ctx.service.stop_and_await().await?; - - Ok(()) -} - -#[tokio::test(start_paused = true)] -async fn hybrid_trigger_produces_blocks_correctly_min_block_time_min_block_gas_limit( -) -> anyhow::Result<()> { - const MIN_BLOCK_TIME: u64 = 4; - const MAX_TX_IDLE_TIME: u64 = 9; - const MAX_BLOCK_TIME: u64 = 10; - let mut ctx = DefaultContext::new(Config { - trigger: Trigger::Hybrid { - min_block_time: Duration::new(MIN_BLOCK_TIME, 0), - max_tx_idle_time: Duration::new(MAX_TX_IDLE_TIME, 0), - max_block_time: Duration::new(MAX_BLOCK_TIME, 0), - }, - // We want to test behaviour when the gas of all transactions > `block_gas_limit` - block_gas_limit: Word::MIN, - signing_key: Some(test_signing_key()), - metrics: false, - ..Default::default() - }); - - // Emulate tx status update to trigger the execution. - ctx.status_sender.send_replace(Some(TxId::zeroed())); - - time::sleep(Duration::new(MIN_BLOCK_TIME - 1, 0)).await; - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - - time::sleep(Duration::new(2, 0)).await; - - // Trigger the `produce_block` if `min_block_time` passed and block is full. - ctx.status_sender.send_replace(Some(TxId::zeroed())); - tokio::task::yield_now().await; - assert!(matches!(ctx.block_import.try_recv(), Ok(_))); - - for _ in 0..5 { - time::sleep(Duration::new(MIN_BLOCK_TIME, 0)).await; - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - tokio::task::yield_now().await; - assert!(matches!(ctx.block_import.try_recv(), Ok(_))); - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - } - - // Stop - ctx.test_ctx.service.stop_and_await().await?; - - Ok(()) -} - -// TODO: We found a bug https://github.com/FuelLabs/fuel-core/issues/866 in the hybrid logic, -// we need to fix it=) Don't remove this test. Remove `ignore` when bug is resolved. -#[ignore] -#[tokio::test(start_paused = true)] -async fn hybrid_trigger_produces_blocks_correctly_min_block_time_max_block_gas_limit( -) -> anyhow::Result<()> { - const MIN_BLOCK_TIME: u64 = 6; - const MAX_TX_IDLE_TIME: u64 = 1; - const MAX_BLOCK_TIME: u64 = 10; - let mut ctx = DefaultContext::new(Config { - trigger: Trigger::Hybrid { - min_block_time: Duration::new(MIN_BLOCK_TIME, 0), - max_tx_idle_time: Duration::new(MAX_TX_IDLE_TIME, 0), - max_block_time: Duration::new(MAX_BLOCK_TIME, 0), - }, - // We want to test behaviour when the gas of all transactions < `block_gas_limit` - block_gas_limit: Word::MAX, - signing_key: Some(test_signing_key()), - metrics: false, - ..Default::default() - }); - - // Emulate tx status update to trigger the execution. - ctx.status_sender.send_replace(Some(TxId::zeroed())); - - time::sleep(Duration::new(2, 0)).await; - assert!(matches!(ctx.block_import.try_recv(), Ok(_))); - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - - // Emulate tx status update to trigger the execution. - ctx.status_sender.send_replace(Some(TxId::zeroed())); - - time::sleep(Duration::new(2, 0)).await; - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - - time::sleep(Duration::new(2, 0)).await; - assert!(matches!( - ctx.block_import.try_recv(), - Err(broadcast::error::TryRecvError::Empty) - )); - - time::sleep(Duration::new(3, 0)).await; - assert!(matches!(ctx.block_import.try_recv(), Ok(_))); - - // Stop - ctx.test_ctx.service.stop_and_await().await?; - - Ok(()) -} diff --git a/deployment/charts/templates/fuel-core-deploy.yaml b/deployment/charts/templates/fuel-core-deploy.yaml index d343966d7e..1c03b140cf 100644 --- a/deployment/charts/templates/fuel-core-deploy.yaml +++ b/deployment/charts/templates/fuel-core-deploy.yaml @@ -160,18 +160,6 @@ spec: - "--poa-interval-period" - "{{ .Values.app.poa_interval_period }}" {{- end}} - {{- if .Values.app.poa_hybrid_min_time }} - - "--poa-hybrid-min-time" - - "{{ .Values.app.poa_hybrid_min_time }}" - {{- end}} - {{- if .Values.app.poa_hybrid_idle_time }} - - "--poa-hybrid-idle-time" - - "{{ .Values.app.poa_hybrid_idle_time }}" - {{- end}} - {{- if .Values.app.poa_hybrid_max_time }} - - "--poa-hybrid-max-time" - - "{{ .Values.app.poa_hybrid_max_time }}" - {{- end}} {{- if .Values.app.relayer }} - "--relayer" - "{{ .Values.app.relayer }}" diff --git a/deployment/charts/values.yaml b/deployment/charts/values.yaml index 3324e38e90..e11ab4d586 100644 --- a/deployment/charts/values.yaml +++ b/deployment/charts/values.yaml @@ -17,9 +17,6 @@ app: network_name: ${fuel_core_network_name} poa_instant: "${fuel_core_poa_instant}" poa_interval_period: "${fuel_core_poa_interval_period}" - poa_hybrid_min_time: "${fuel_core_poa_hybrid_min_time}" - poa_hybrid_idle_time: "${fuel_core_poa_hybrid_idle_time}" - poa_hybrid_max_time: "${fuel_core_poa_hybrid_max_time}" max_block_size: "${fuel_core_max_buffer_size}" max_database_cache_size: "${fuel_core_max_database_cache_size}" max_transmit_size: "${fuel_core_max_buffer_size}" diff --git a/deployment/scripts/.env b/deployment/scripts/.env index 7eed159ca2..a7b4e98d5e 100644 --- a/deployment/scripts/.env +++ b/deployment/scripts/.env @@ -41,10 +41,6 @@ fuel_core_consensus_key_secret="dGVzdA==" # fuel_core_poa_instant=true # Or interval, where teh value can be `10s` in seconds, `1m` minutes, or `1h` hours. # fuel_core_poa_interval_period="3s" -# Or hybrid, all 3 fields should be set. -# fuel_core_poa_hybrid_min_time="2s" -# fuel_core_poa_hybrid_idle_time="500ms" -# fuel_core_poa_hybrid_max_time="1h" # allow multiple fuel-core nodes in the same namespace, also used for setting up reserved nodes fuel_core_service_name="fuel-core" diff --git a/tests/tests/trigger_integration/hybrid.rs b/tests/tests/trigger_integration/hybrid.rs deleted file mode 100644 index 4e15fbedcf..0000000000 --- a/tests/tests/trigger_integration/hybrid.rs +++ /dev/null @@ -1,169 +0,0 @@ -use fuel_core::{ - database::Database, - service::{ - Config, - FuelService, - }, -}; -use fuel_core_client::client::{ - pagination::{ - PageDirection, - PaginationRequest, - }, - FuelClient, -}; -use fuel_core_poa::Trigger; -use fuel_core_types::{ - fuel_asm::*, - fuel_crypto::SecretKey, - fuel_tx::TransactionBuilder, - secrecy::Secret, -}; -use rand::{ - rngs::StdRng, - Rng, - SeedableRng, -}; -use std::time::Duration; - -#[tokio::test(start_paused = true)] -async fn poa_hybrid_produces_empty_blocks_at_correct_rate() { - let rounds = 64; - let round_time_seconds = 2; - - let mut rng = StdRng::seed_from_u64(10); - - let db = Database::default(); - let mut config = Config::local_node(); - config.consensus_key = Some(Secret::new(SecretKey::random(&mut rng).into())); - config.block_production = Trigger::Hybrid { - max_block_time: Duration::new(round_time_seconds, 0), - max_tx_idle_time: Duration::new(5, 0), - min_block_time: Duration::new(2, 0), - }; - - let srv = FuelService::from_database(db.clone(), config) - .await - .unwrap(); - - let client = FuelClient::from(srv.bound_address); - - let time_start = tokio::time::Instant::now(); - let count_start = client - .blocks(PaginationRequest { - cursor: None, - results: 1024, - direction: PageDirection::Forward, - }) - .await - .expect("blocks request failed") - .results - .len(); - - loop { - let resp = client - .blocks(PaginationRequest { - cursor: None, - results: 1024, - direction: PageDirection::Forward, - }) - .await - .expect("blocks request failed"); - - // Make sure that we do not depend on scheduler behavior too much - for _ in 0..(rng.gen::() % 8) { - tokio::task::yield_now().await; - } - - let count_now = resp.results.len(); - if count_now > count_start + rounds { - break - } - } - - let time_end = tokio::time::Instant::now(); - - // Require at least minimum time, allow up to one round time of error - let secs_per_round = (time_end - time_start).as_secs() / (rounds as u64); - assert!( - round_time_seconds <= secs_per_round - && secs_per_round - <= round_time_seconds + 2 * (rounds as u64) / round_time_seconds, - "Round time not within treshold" - ); -} - -#[tokio::test(start_paused = true)] -async fn poa_hybrid_produces_nonempty_blocks_at_correct_rate() { - let rounds = 64; - let round_time_seconds = 2; - - let mut rng = StdRng::seed_from_u64(10); - - let db = Database::default(); - let mut config = Config::local_node(); - config.consensus_key = Some(Secret::new(SecretKey::random(&mut rng).into())); - config.block_production = Trigger::Hybrid { - max_block_time: Duration::new(30, 0), - max_tx_idle_time: Duration::new(5, 0), - min_block_time: Duration::new(round_time_seconds, 0), - }; - - let srv = FuelService::from_database(db.clone(), config) - .await - .unwrap(); - - let client = FuelClient::from(srv.bound_address); - - for i in 0..200 { - let tx = - TransactionBuilder::script([op::movi(0x10, i)].into_iter().collect(), vec![]) - .add_random_fee_input() - .finalize_as_transaction(); - let _tx_id = client.submit(&tx).await.unwrap(); - } - - let time_start = tokio::time::Instant::now(); - let count_start = client - .blocks(PaginationRequest { - cursor: None, - results: 1024, - direction: PageDirection::Forward, - }) - .await - .expect("blocks request failed") - .results - .len(); - - loop { - let resp = client - .blocks(PaginationRequest { - cursor: None, - results: 1024, - direction: PageDirection::Forward, - }) - .await - .expect("blocks request failed"); - - // Make sure that we do not depend on scheduler behavior too much - for _ in 0..(rng.gen::() % 8) { - tokio::task::yield_now().await; - } - - let count_now = resp.results.len(); - if dbg!(count_now) > dbg!(count_start + rounds) { - break - } - } - - let time_end = tokio::time::Instant::now(); - - // Require at least minimum time, allow up to one round time of error - let secs_per_round = (time_end - time_start).as_secs() / (rounds as u64); - assert!( - round_time_seconds <= secs_per_round - && secs_per_round - <= round_time_seconds + 2 * (rounds as u64) / round_time_seconds, - "Round time not within treshold" - ); -} diff --git a/tests/tests/trigger_integration/mod.rs b/tests/tests/trigger_integration/mod.rs index 89eec56bc6..7b18b8a68d 100644 --- a/tests/tests/trigger_integration/mod.rs +++ b/tests/tests/trigger_integration/mod.rs @@ -1,4 +1,3 @@ -mod hybrid; mod instant; mod interval; mod never;