-
Notifications
You must be signed in to change notification settings - Fork 47
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
fix(block_production): dynamic block closing #456
Changes from 2 commits
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 |
---|---|---|
|
@@ -358,20 +358,45 @@ impl<Mempool: MempoolProvider> BlockProductionTask<Mempool> { | |
Ok(()) | ||
} | ||
|
||
fn maybe_add_prev_block_hash(&self, state_diff: &mut StateDiff, block_n: u64) -> Result<(), Error> { | ||
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. The current name 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. does it make more sense now? or any suggestion what can be improved? 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. perfect with documentation 👍 |
||
if block_n >= 10 { | ||
let prev_block_number = block_n - 10; | ||
let prev_block_hash = self | ||
.backend | ||
.get_block_hash(&BlockId::Number(prev_block_number)) | ||
.map_err(|err| { | ||
Error::Unexpected( | ||
format!("Error fetching block hash for block {prev_block_number}: {err:#}").into(), | ||
) | ||
})? | ||
.ok_or_else(|| { | ||
Error::Unexpected(format!("No block hash found for block number {prev_block_number}").into()) | ||
})?; | ||
|
||
state_diff.storage_diffs.push(ContractStorageDiffItem { | ||
address: Felt::ONE, | ||
storage_entries: vec![StorageEntry { key: Felt::from(prev_block_number), value: prev_block_hash }], | ||
}); | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[tracing::instrument(skip(self), fields(module = "BlockProductionTask"))] | ||
pub async fn on_pending_time_tick(&mut self) -> Result<bool, Error> { | ||
let current_pending_tick = self.current_pending_tick; | ||
if current_pending_tick == 0 { | ||
return Ok(false); | ||
} | ||
|
||
// Use full bouncer capacity | ||
let bouncer_cap = self.backend.chain_config().bouncer_config.block_max_capacity; | ||
|
||
let start_time = Instant::now(); | ||
|
||
let ContinueBlockResult { state_diff, visited_segments, bouncer_weights, stats, block_now_full } = | ||
self.continue_block(bouncer_cap)?; | ||
let ContinueBlockResult { | ||
state_diff: mut new_state_diff, | ||
visited_segments, | ||
bouncer_weights, | ||
stats, | ||
block_now_full, | ||
} = self.continue_block(self.backend.chain_config().bouncer_config.block_max_capacity)?; | ||
|
||
if stats.n_added_to_block > 0 { | ||
tracing::info!( | ||
|
@@ -384,16 +409,19 @@ impl<Mempool: MempoolProvider> BlockProductionTask<Mempool> { | |
|
||
// Check if block is full | ||
if block_now_full { | ||
let block_n = self.block_n(); | ||
self.maybe_add_prev_block_hash(&mut new_state_diff, block_n)?; | ||
|
||
tracing::info!("Resource limits reached, closing block early"); | ||
self.close_and_prepare_next_block(state_diff, visited_segments, start_time).await?; | ||
self.close_and_prepare_next_block(new_state_diff, visited_segments, start_time).await?; | ||
Trantorian1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return Ok(true); | ||
} | ||
|
||
// Store pending block | ||
// todo, prefer using the block import pipeline? | ||
self.backend.store_block( | ||
self.block.clone().into(), | ||
state_diff, | ||
new_state_diff, | ||
self.declared_classes.clone(), | ||
Some(visited_segments), | ||
Some(bouncer_weights), | ||
|
@@ -420,27 +448,7 @@ impl<Mempool: MempoolProvider> BlockProductionTask<Mempool> { | |
block_now_full: _block_now_full, | ||
} = self.continue_block(self.backend.chain_config().bouncer_config.block_max_capacity)?; | ||
|
||
// SNOS requirement: For blocks >= 10, the hash of the block 10 blocks prior | ||
// at address 0x1 with the block number as the key | ||
if block_n >= 10 { | ||
let prev_block_number = block_n - 10; | ||
let prev_block_hash = self | ||
.backend | ||
.get_block_hash(&BlockId::Number(prev_block_number)) | ||
.map_err(|err| { | ||
Error::Unexpected( | ||
format!("Error fetching block hash for block {prev_block_number}: {err:#}").into(), | ||
) | ||
})? | ||
.ok_or_else(|| { | ||
Error::Unexpected(format!("No block hash found for block number {prev_block_number}").into()) | ||
})?; | ||
|
||
new_state_diff.storage_diffs.push(ContractStorageDiffItem { | ||
address: Felt::ONE, | ||
storage_entries: vec![StorageEntry { key: Felt::from(prev_block_number), value: prev_block_hash }], | ||
}); | ||
} | ||
self.maybe_add_prev_block_hash(&mut new_state_diff, block_n)?; | ||
|
||
self.close_and_prepare_next_block(new_state_diff, visited_segments, start_time).await | ||
} | ||
|
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.
Maybe add a doc comment to this function explaining why this is needed and what it does.
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.
added