Skip to content

Commit

Permalink
Add another messy test, fix bug in activity code
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchTurner committed Dec 11, 2024
1 parent 6f46343 commit 3496adc
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 51 deletions.
62 changes: 33 additions & 29 deletions crates/fuel-core/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use self::adapters::BlockImporterAdapter;
use crate::{
combined_database::{
CombinedDatabase,
ShutdownListener,
},
database::Database,
service::{
adapters::{
ExecutorAdapter,
PoAAdapter,
},
sub_services::TxPoolSharedState,
},
use std::{
net::SocketAddr,
sync::Arc,
};

pub use config::{
Config,
DbType,
RelayerConsensusConfig,
VMConfig,
};
use fuel_core_chain_config::{
ConsensusConfig,
Expand All @@ -21,6 +17,7 @@ use fuel_core_poa::{
ports::BlockImporter,
verifier::verify_consensus,
};
pub use fuel_core_services::Service as ServiceTrait;
use fuel_core_services::{
RunnableService,
RunnableTask,
Expand All @@ -40,18 +37,23 @@ use fuel_core_storage::{
StorageAsMut,
};
use fuel_core_types::blockchain::consensus::Consensus;
use std::{
net::SocketAddr,
sync::Arc,
};

pub use config::{
Config,
DbType,
RelayerConsensusConfig,
VMConfig,
use crate::{
combined_database::{
CombinedDatabase,
ShutdownListener,
},
database::Database,
service::{
adapters::{
ExecutorAdapter,
PoAAdapter,
},
sub_services::TxPoolSharedState,
},
};
pub use fuel_core_services::Service as ServiceTrait;

use self::adapters::BlockImporterAdapter;

pub mod adapters;
pub mod config;
Expand Down Expand Up @@ -465,18 +467,20 @@ impl RunnableTask for Task {
#[allow(non_snake_case)]
#[cfg(test)]
mod tests {
use std::{
thread::sleep,
time::Duration,
};

use fuel_core_services::State;

use crate::{
service::{
Config,
FuelService,
},
ShutdownListener,
};
use fuel_core_services::State;
use std::{
thread::sleep,
time::Duration,
};

#[tokio::test]
async fn stop_sub_service_shutdown_all_services() {
Expand Down
19 changes: 15 additions & 4 deletions crates/fuel-gas-price-algorithm/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,25 @@ impl L2ActivityTracker {
}

pub fn safety_mode(&self) -> DAGasPriceSafetyMode {
if self.chain_activity > self.capped_activity_threshold {
if self.chain_activity >= self.capped_activity_threshold {
DAGasPriceSafetyMode::Normal
} else if self.chain_activity > self.decrease_activity_threshold {
} else if self.chain_activity >= self.decrease_activity_threshold {
DAGasPriceSafetyMode::Capped
} else {
DAGasPriceSafetyMode::AlwaysDecrease
}
}

pub fn update(&mut self, block_usage: ClampedPercentage) {
tracing::info!("Block usage: {:?}", block_usage);
tracing::info!("Chain activity: {}", self.chain_activity);
tracing::info!("threshold: {:?}", self.block_activity_threshold);
if block_usage < self.block_activity_threshold {
tracing::info!(
"Decreasing activity {:?} < {:?}",
block_usage,
self.block_activity_threshold
);
self.chain_activity = self.chain_activity.saturating_sub(1);
} else {
self.chain_activity =
Expand Down Expand Up @@ -414,7 +422,9 @@ impl AlgorithmUpdaterV1 {
}

fn update_da_rewards(&mut self, fee_wei: u128) {
tracing::info!("Fee: {}", fee_wei);
let block_da_reward = self.da_portion_of_fee(fee_wei);
tracing::info!("DA reward: {}", block_da_reward);
self.total_da_rewards_excess =
self.total_da_rewards_excess.saturating_add(block_da_reward);
}
Expand Down Expand Up @@ -498,8 +508,8 @@ impl AlgorithmUpdaterV1 {
0u64
}
});
tracing::debug!("Profit: {}", self.last_profit);
tracing::debug!(
tracing::info!("Profit: {}", self.last_profit);
tracing::info!(
"DA gas price change: p: {}, d: {}, change: {}, new: {}",
p,
d,
Expand All @@ -518,6 +528,7 @@ impl AlgorithmUpdaterV1 {
DAGasPriceSafetyMode::Normal => maybe_da_change,
DAGasPriceSafetyMode::Capped => 0,
DAGasPriceSafetyMode::AlwaysDecrease => {
tracing::info!("Activity is low, decreasing DA gas price");
self.max_change().saturating_mul(-1)
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/services/executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,9 @@ where
.iter()
.map(|input| input.predicate_gas_used())
.collect();
tracing::info!("Executing transaction: {:?}", tx_id);
let ready_tx = checked_tx.into_ready(gas_price, gas_costs, fee_params)?;
tracing::info!("Transaction ready: {:?}", tx_id);

let mut vm = Interpreter::with_storage(
memory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ impl UpdaterMetadata {
UpdaterMetadata::V1(v1) => v1.l2_block_height.into(),
}
}

pub fn v1(&self) -> Option<&V1Metadata> {
match self {
UpdaterMetadata::V1(v1) => Some(v1),
_ => None,
}
}
}

impl From<AlgorithmUpdaterV0> for UpdaterMetadata {
Expand Down
6 changes: 4 additions & 2 deletions crates/services/gas_price_service/src/v1/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ where
let capacity = Self::validate_block_gas_capacity(block_gas_capacity)?;
let mut storage_tx = self.storage_tx_provider.begin_transaction()?;

for da_block_costs in self.da_block_costs_buffer.drain(..) {
tracing::debug!("Updating DA block costs: {:?}", da_block_costs);
let drained = self.da_block_costs_buffer.drain(..);
tracing::info!("Drained DA block costs: {:?}", drained);
for da_block_costs in drained {
tracing::info!("Updating DA block costs: {:?}", da_block_costs);
self.algorithm_updater.update_da_record_data(
&da_block_costs.l2_blocks,
da_block_costs.blob_size_bytes,
Expand Down
7 changes: 5 additions & 2 deletions crates/services/producer/src/block_producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,13 @@ where
}

async fn calculate_gas_price(&self) -> anyhow::Result<u64> {
self.gas_price_provider
let price = self
.gas_price_provider
.next_gas_price()
.await
.map_err(|e| anyhow!("No gas price found: {e:?}"))
.map_err(|e| anyhow!("No gas price found: {e:?}"));
tracing::info!("Gas price: {:?}", price);
price
}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/proptest-regressions/gas_price.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 76d053f5828c12ddd3090b4b076bb287e1b4dde50e69f7edd5b3a5b64ae3c743 # shrinks to block_delay = 103, blob_size = 70
Loading

0 comments on commit 3496adc

Please sign in to comment.