-
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
Refactor/separate validation from other executions #1837
Refactor/separate validation from other executions #1837
Conversation
…with unimplemented code
_block: Block, | ||
) -> fuel_core_types::services::executor::Result<ExecutionResult> { | ||
let (result, changes) = self.validate_without_commit(_block)?.into(); |
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.
_block: Block, | |
) -> fuel_core_types::services::executor::Result<ExecutionResult> { | |
let (result, changes) = self.validate_without_commit(_block)?.into(); | |
block: Block, | |
) -> fuel_core_types::services::executor::Result<ExecutionResult> { | |
let (result, changes) = self.validate_without_commit(block)?.into(); |
### Changed | ||
|
||
- [#1837](https://github.com/FuelLabs/fuel-core/pull/1837): Refactor the executor and separate validation from the other use cases |
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.
We need to move it into "Unreleased" section
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.
Still not removed=)
@@ -55,6 +58,13 @@ impl ExecutorAdapter { | |||
) -> ExecutorResult<Vec<TransactionExecutionStatus>> { | |||
self.executor.dry_run(block, utxo_validation) | |||
} | |||
|
|||
pub(crate) fn _validate_block( |
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.
You can name the method validate_block_inner
=)
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.
Can we just get rid of these "private" methods? They are all just used in one/two places and think I like the idea of just calling executor.validate
, etc in those places.
let ( | ||
ExecutionResult { | ||
block, | ||
skipped_transactions, | ||
tx_status, | ||
events, | ||
}, | ||
changes, | ||
) = instance.execute_without_commit(block)?.into(); | ||
|
||
Ok(Uncommitted::new( | ||
ExecutionResult { | ||
block, | ||
skipped_transactions, | ||
tx_status, | ||
events, | ||
}, | ||
changes, | ||
)) |
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.
@@ -294,10 +318,6 @@ where | |||
// Compute the block id before execution if there is one. | |||
let pre_exec_block_id = block.id(); |
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.
It seems you can remove this code and related logic=)
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.
I've mostly done that in the next PR:
#1847
I left a note over there to remove the rest.
fn execute_transaction_and_commit( | ||
&self, | ||
block: &mut PartialFuelBlock, | ||
thread_block_transaction: &mut StorageTransaction< |
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.
You can use a generic here, as we do in other places=) Or create an alias if you want to have control over the storage type
Ok(_) => {} | ||
Err(err) => match execution_kind { | ||
ExecutionKind::Production => { | ||
execution_data.skipped_transactions.push((tx_id, err)); | ||
data.skipped_transactions.push((tx_id, err)); | ||
} | ||
ExecutionKind::DryRun | ExecutionKind::Validation => { |
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.
It seems you can remove handling of the ExecutionKind::Validation
here=) Maybe you even can remove this variant from the enum
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.
The goal is to remove this enum entirely. Unfortunately there are some spots that are still using this variant. I have a follow-up PR already in the works and I can probably remove it as part of that:
#1847
Trying to keep these PRs small, so I just stopped this one after I got rid of ExecutionType
.
gas_price: Word, | ||
coinbase_contract_id: ContractId, | ||
execution_kind: ExecutionKind, |
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.
In later PRs we can make these fields as part of the Instance
=) And maybe have ExecutionInstance
, ValidationInstance
, etc.
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.
Nice. That seems like it might be the right approach to get rid of ExecutionKind
.
|
||
// L2 originated transactions should be in the `TxSource`. This will be triggered after | ||
// all relayed transactions are processed. | ||
let mut regular_tx_iter = source.next(block_gas_limit).into_iter().peekable(); |
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.
Hmm, maybe we can also simplify that logic, because you already have pre defined list of transactions.
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.
Done in the next PR:
#1847
)?; | ||
} | ||
|
||
let new_remaining_gas_limit = block_gas_limit.saturating_sub(data.used_gas); |
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.
Hmm, instead of saturating_sub
it should be checked_add
. Because maybe bloc producer included more transactions than was allowed=)
Also, maybe we need to update execute_inner
as well
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.
In the follow-up PR, I don't event have this variable:
#1847
I just expect the execution to fail if it exceeds the limit. There is no source
in that case anyway, so there is no use for this.
@@ -336,7 +311,7 @@ impl ExecutionKind { | |||
match self { | |||
ExecutionKind::DryRun => ExecutionTypes::DryRun(t), | |||
ExecutionKind::Production => ExecutionTypes::Production(t), | |||
ExecutionKind::Validation => ExecutionTypes::Validation(t), | |||
ExecutionKind::Validation => todo!("remove this variant"), |
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.
If this todo!
still supposed to be here? Or is this part of the follow-up PR to remove ExecutionKind
?
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.
Hmm. My IDE didn't find any uses for this method anywhere so I just removed it entirely.
### Changed | ||
|
||
- [#1837](https://github.com/FuelLabs/fuel-core/pull/1837): Refactor the executor and separate validation from the other use cases |
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.
Still not removed=)
// TODO: Refactor this function to reduce the number of arguments. | ||
#[allow(clippy::too_many_arguments)] | ||
fn execute_transaction_and_commit< | ||
W: WriteTransaction + KeyValueInspect<Column = Column> + Modifiable, |
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.
W: WriteTransaction + KeyValueInspect<Column = Column> + Modifiable, | |
W: KeyValueInspect<Column = Column> + Modifiable, |
let block_height = *block.header.height(); | ||
let execution_kind = ExecutionKind::Validation; | ||
|
||
let forced_transactions = if self.relayer.enabled() { |
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 it make sense to move relayer related logic into a separate functions and reuse it in validate_block
and execute_block
=) It can be a part of the follow up
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.
You can fix comments in the follow-up PR=)
## Version v0.26.0 ### Fixed #### Breaking - [#1868](#1868): Include the `event_inbox_root` in the header hash. Changed types of the `transactions_count` to `u16` and `message_receipt_count` to `u32` instead of `u64`. Updated the application hash root calculation to not pad numbers. - [#1866](#1866): Fixed a runtime panic that occurred when restarting a node. The panic happens when the relayer database is already populated, and the relayer attempts an empty commit during start up. This invalid commit is removed in this PR. - [#1871](#1871): Fixed `block` endpoint to return fetch the blocks from both databases after regenesis. - [#1856](#1856): Replaced instances of `Union` with `Enum` for GraphQL definitions of `ConsensusParametersVersion` and related types. This is needed because `Union` does not support multiple `Version`s inside discriminants or empty variants. - [#1870](#1870): Fixed benchmarks for the `0.25.3`. - [#1870](#1870): Improves the performance of getting the size of the contract from the `InMemoryTransaction`. - [#1851](#1851): Provided migration capabilities (enabled addition of new column families) to RocksDB instance. ### Added - [#1853](#1853): Added a test case to verify the database's behavior when new columns are added to the RocksDB database. - [#1860](#1860): Regenesis now preserves `FuelBlockIdsToHeights` off-chain table. ### Changed - [#1847](#1847): Simplify the validation interface to use `Block`. Remove `Validation` variant of `ExecutionKind`. - [#1832](#1832): Snapshot generation can be cancelled. Progress is also reported. - [#1837](#1837): Refactor the executor and separate validation from the other use cases ## What's Changed * Weekly `cargo update` by @github-actions in #1850 * Refactor/separate validation from other executions by @MitchTurner in #1837 * fix: Use `Enum` for `ConsensusParametersVersion` and related types by @bvrooman in #1856 * feat: snapshot generation graceful shutdown by @segfault-magnet in #1832 * regenesis: migrate FuelBlockIdsToHeights by @Dentosal in #1860 * Weekly `cargo update` by @github-actions in #1869 * Refactor/Simplify validation logic by @MitchTurner in #1847 * Fixed `block` endpoint to return fetch the blocks from both databases after regenesis by @xgreenx in #1871 * Add Eq and Partial Eq to tx response and status by @MujkicA in #1872 * test: restart with relayer data by @bvrooman in #1866 * Fix `BlockHeader` hash by @MitchTurner in #1868 * Added a test for the case of adding new columns into the existing RocksDB database by @xgreenx in #1853 * Fixed benchmarks for the `0.25.3` by @xgreenx in #1870 **Full Changelog**: v0.25.3...v0.26.0
Part of: #1751
Executor
is use both for producing a block, executing dry-run txs, and validating blocks. This is done using the same functions and we have internal conditional logic for each use case. This makes the code more complicated than it needs to be and makes it hard to read.This PR removes the
Validation
variant fromExecutionTypes
and creates new methods for just validation. Since there is only a set number of places in our code that uses this variant, it cleans the code up a lot to just have it be separate method, thus removing the need for all the internal conditional logic for each variant.Remaining work to do in subsequent PRs:
DryRun
fromProduction
and removeExecutionType
ExecutionKind
as well. It goes deep so I still need to figure out how to untangle it.Checklist
Before requesting review
After merging, notify other teams
[Add or remove entries as needed]