Skip to content

Commit

Permalink
Remove extra traits
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchTurner committed May 9, 2024
1 parent 4af3946 commit 398884e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 74 deletions.
41 changes: 10 additions & 31 deletions crates/fuel-core/src/service/adapters/fuel_gas_price_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ use fuel_core_producer::block_producer::gas_price::{
};
use fuel_core_types::fuel_types::BlockHeight;
use ports::{
BlockFullnessHistory,
BlockHistory,
DARecordingCostHistory,
FuelBlockProductionRewardHistory,
GasPriceHistory,
FuelBlockHistory,
};

pub mod ports;
Expand All @@ -17,44 +14,29 @@ pub mod ports;
mod tests;

/// Gives the gas price for a given block height, and calculates the gas price if not yet committed.
pub struct FuelGasPriceProvider<B, GP, BF, BP, DA> {
_block_history: B,
gas_price_history: GP,
_block_fullness_history: BF,
_block_production_reward: BP,
pub struct FuelGasPriceProvider<FB, DA> {
_block_history: FB,
_da_recording_cost_history: DA,
}

impl<B, GP, BF, BP, DA> FuelGasPriceProvider<B, GP, BF, BP, DA> {
pub fn new(
block_history: B,
gas_price_history: GP,
block_fullness_history: BF,
block_production_reward: BP,
da_recording_cost_history: DA,
) -> Self {
impl<FB, DA> FuelGasPriceProvider<FB, DA> {
pub fn new(block_history: FB, da_recording_cost_history: DA) -> Self {
Self {
_block_history: block_history,
gas_price_history,
_block_fullness_history: block_fullness_history,
_block_production_reward: block_production_reward,
_da_recording_cost_history: da_recording_cost_history,
}
}
}

impl<B, GP, BF, BP, DA> FuelGasPriceProvider<B, GP, BF, BP, DA>
impl<FB, DA> FuelGasPriceProvider<FB, DA>
where
B: BlockHistory,
GP: GasPriceHistory,
BF: BlockFullnessHistory,
BP: FuelBlockProductionRewardHistory,
FB: FuelBlockHistory,
DA: DARecordingCostHistory,
{
fn inner_gas_price(&self, block_height: BlockHeight) -> Option<u64> {
let latest_block = self._block_history.latest_height();
if latest_block > block_height {
self.gas_price_history.gas_price(block_height)
self._block_history.gas_price(block_height)
} else if *latest_block + 1 == *block_height {
let arbitrary_cost = 237894;
Some(arbitrary_cost)
Expand All @@ -65,12 +47,9 @@ where
}
}

impl<B, GP, BF, BP, DA> GasPriceProvider for FuelGasPriceProvider<B, GP, BF, BP, DA>
impl<FB, DA> GasPriceProvider for FuelGasPriceProvider<FB, DA>
where
B: BlockHistory,
GP: GasPriceHistory,
BF: BlockFullnessHistory,
BP: FuelBlockProductionRewardHistory,
FB: FuelBlockHistory,
DA: DARecordingCostHistory,
{
fn gas_price(&self, params: GasPriceParams) -> Option<u64> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@ impl PartialEq<DARecordingCost> for BlockProductionReward {
}
}

pub trait BlockHistory {
pub trait FuelBlockHistory {
fn latest_height(&self) -> BlockHeight;
}

pub trait GasPriceHistory {
fn gas_price(&self, height: BlockHeight) -> Option<u64>;
}

pub trait BlockFullnessHistory {
fn block_fullness(&self, height: BlockHeight) -> BlockFullness;
}

pub trait FuelBlockProductionRewardHistory {
fn block_production_reward(&self, height: BlockHeight) -> BlockProductionReward;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,19 @@ mod producer_gas_price_tests;

struct FakeBlockHistory {
latest_height: BlockHeight,
history: HashMap<BlockHeight, u64>,
}

impl BlockHistory for FakeBlockHistory {
impl FuelBlockHistory for FakeBlockHistory {
fn latest_height(&self) -> BlockHeight {
self.latest_height
}
}

struct FakeGasPriceHistory {
history: HashMap<BlockHeight, u64>,
}

impl GasPriceHistory for FakeGasPriceHistory {
fn gas_price(&self, height: BlockHeight) -> Option<u64> {
self.history.get(&height).copied()
}
}

struct FakeBlockFullnessHistory;

impl BlockFullnessHistory for FakeBlockFullnessHistory {
fn block_fullness(&self, _height: BlockHeight) -> BlockFullness {
todo!();
}
}

struct FakeBlockProductionRewardHistory;

impl FuelBlockProductionRewardHistory for FakeBlockProductionRewardHistory {
fn block_production_reward(&self, _height: BlockHeight) -> BlockProductionReward {
todo!();
}
Expand Down Expand Up @@ -85,31 +69,17 @@ impl ProviderBuilder {
self
}

fn build(
self,
) -> FuelGasPriceProvider<
FakeBlockHistory,
FakeGasPriceHistory,
FakeBlockFullnessHistory,
FakeBlockProductionRewardHistory,
FakeDARecordingCostHistory,
> {
fn build(self) -> FuelGasPriceProvider<FakeBlockHistory, FakeDARecordingCostHistory> {
let Self {
latest_height,
historical_gas_price,
} = self;

let fake_block_history = FakeBlockHistory { latest_height };
let gas_price_history = FakeGasPriceHistory {
let fake_block_history = FakeBlockHistory {
latest_height,
history: historical_gas_price,
};
FuelGasPriceProvider::new(
fake_block_history,
gas_price_history,
FakeBlockFullnessHistory,
FakeBlockProductionRewardHistory,
FakeDARecordingCostHistory,
)
FuelGasPriceProvider::new(fake_block_history, FakeDARecordingCostHistory)
}
}

Expand Down

0 comments on commit 398884e

Please sign in to comment.