Skip to content

Commit

Permalink
fix: use get_full_block
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Sep 20, 2024
1 parent 44378c6 commit abbf480
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
32 changes: 6 additions & 26 deletions crates/fuel-core/src/service/adapters/gas_price_adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ use fuel_core_gas_price_service::{
},
ports::L2Data,
};
use fuel_core_storage::{
not_found,
tables::{
FuelBlocks,
Transactions,
},
Result as StorageResult,
StorageAsRef,
};
use fuel_core_storage::Result as StorageResult;
use fuel_core_types::{
blockchain::{
block::Block,
Expand All @@ -39,23 +31,11 @@ impl L2Data for OnChainIterableKeyValueView {
self.latest_height()
}

fn get_block(&self, height: &BlockHeight) -> StorageResult<Block<Transaction>> {
let block = self
.storage::<FuelBlocks>()
.get(height)
.map(|block| block.map(|block| block.as_ref().clone()))?
.ok_or(not_found!("FuelBlock"))?;

let mut transactions = vec![];
for tx_id in block.transactions() {
let tx = self
.storage::<Transactions>()
.get(tx_id)
.map(|tx| tx.map(|tx| tx.as_ref().clone()))?
.ok_or(not_found!("Transaction"))?;
transactions.push(tx);
}
Ok(block.uncompress(transactions))
fn get_block(
&self,
height: &BlockHeight,
) -> StorageResult<Option<Block<Transaction>>> {
self.get_full_block(height)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use fuel_core_services::{
StateWatcher,
};
use fuel_core_storage::{
not_found,
structured_storage::StructuredStorage,
transactional::{
AtomicView,
Expand Down Expand Up @@ -317,7 +318,9 @@ where
let first = metadata_height.saturating_add(1);
let view = on_chain_db.latest_view()?;
for height in first..=latest_block_height {
let block = view.get_block(&height.into())?;
let block = view
.get_block(&height.into())?
.ok_or(not_found!("FullBlock"))?;
let param_version = block.header().consensus_parameters_version;

let GasPriceSettings {
Expand Down
5 changes: 4 additions & 1 deletion crates/services/gas_price_service/src/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ use fuel_core_types::{

pub trait L2Data: Send + Sync {
fn latest_height(&self) -> StorageResult<BlockHeight>;
fn get_block(&self, height: &BlockHeight) -> StorageResult<Block<Transaction>>;
fn get_block(
&self,
height: &BlockHeight,
) -> StorageResult<Option<Block<Transaction>>>;
}

0 comments on commit abbf480

Please sign in to comment.