-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Modify block producer to take into account the total gas used by the L1 transactions #1785
Changes from 19 commits
2112149
e71e858
46939ae
4d11df6
a3890f8
9175f7b
5cb72c4
2f283a4
c1a025f
fbb85fe
3402243
9997cb6
37edfc0
069738f
73dd733
3415fa8
6c53316
0492ff0
fe75066
f271235
8ddec16
eda5023
ce832df
ec80451
7f4cbc7
321a39e
7c0ef76
4577a3a
650549a
dabc8d8
e7dbb65
8b59aea
e08ba99
1021022
c628f99
4980eba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ use fuel_core_types::{ | |
ConsensusParametersVersion, | ||
StateTransitionBytecodeVersion, | ||
}, | ||
primitives, | ||
primitives::DaBlockHeight, | ||
}, | ||
fuel_tx, | ||
fuel_tx::Transaction, | ||
|
@@ -123,31 +123,53 @@ impl fuel_core_producer::ports::DryRunner for ExecutorAdapter { | |
|
||
#[async_trait::async_trait] | ||
impl fuel_core_producer::ports::Relayer for MaybeRelayerAdapter { | ||
async fn wait_for_at_least( | ||
async fn get_latest_da_blocks_with_costs( | ||
&self, | ||
height: &primitives::DaBlockHeight, | ||
) -> anyhow::Result<primitives::DaBlockHeight> { | ||
starting_from: &DaBlockHeight, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice, maybe, to move this logic to block producer. In this case, the block producer will have control over the number of iterations. Because we had a long delay/finalization and we have 100 blocks with a maxed gas limit, you will do 100 iterations while you need only one. We could use something like: #[async_trait::async_trait]
pub trait Relayer: Send + Sync {
/// Wait for the relayer to reach at least this height and return the
/// latest height (which is guaranteed to be >= height).
async fn wait_for_at_least(
&self,
height: &DaBlockHeight,
) -> anyhow::Result<DaBlockHeight>;
/// Returns the gas cost of events at the given height.
async fn gas_cost_at_height(
&self,
height: &DaBlockHeight,
) -> anyhow::Result<Word>;
} |
||
) -> anyhow::Result<Vec<(DaBlockHeight, u64)>> { | ||
#[cfg(feature = "relayer")] | ||
{ | ||
if let Some(sync) = self.relayer_synced.as_ref() { | ||
sync.await_at_least_synced(height).await?; | ||
sync.get_finalized_da_height() | ||
sync.await_at_least_synced(starting_from).await?; | ||
let highest = sync.get_finalized_da_height()?; | ||
(starting_from.0..=highest.0) | ||
.map(|height| get_gas_cost_for_height(height, sync)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm afraid that the current usage of the Genesis da block height will lead to iterations from 0..5M. It may not be a huge problem in the long term, but it may slow down the start of the |
||
.collect() | ||
} else { | ||
Ok(0u64.into()) | ||
Ok(Vec::new()) | ||
} | ||
} | ||
#[cfg(not(feature = "relayer"))] | ||
{ | ||
anyhow::ensure!( | ||
**height == 0, | ||
**starting_from == 0, | ||
"Cannot have a da height above zero without a relayer" | ||
); | ||
// If the relayer is not enabled, then all blocks are zero. | ||
Ok(0u64.into()) | ||
Ok(Vec::new()) | ||
} | ||
} | ||
} | ||
|
||
#[cfg(feature = "relayer")] | ||
fn get_gas_cost_for_height( | ||
height: u64, | ||
sync: &fuel_core_relayer::SharedState< | ||
Database<crate::database::database_description::relayer::Relayer>, | ||
>, | ||
) -> anyhow::Result<(DaBlockHeight, u64)> { | ||
let da_height = DaBlockHeight(height); | ||
let cost = sync | ||
.database() | ||
.storage::<fuel_core_relayer::storage::EventsHistory>() | ||
.get(&da_height)? | ||
.map(|cow| cow.into_owned()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to call |
||
.unwrap_or_default() | ||
.iter() | ||
.fold(0u64, |acc, event| acc.saturating_add(event.cost())); | ||
Ok((da_height, cost)) | ||
} | ||
|
||
impl fuel_core_producer::ports::BlockProducerDatabase for Database { | ||
fn get_block(&self, height: &BlockHeight) -> StorageResult<Cow<CompressedBlock>> { | ||
self.storage::<FuelBlocks>() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you revert back indent changes in this file, please?=)