-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add expiration check on pending pool and refactor extracted outputs cache #2855
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b67b2e1
Add expiration check on pending pool and fix error on saved_outputs
AurelienFT 7b8a21c
Changelog
AurelienFT 5fc6db4
Fix test fakyness
AurelienFT 683d89e
Fix test
AurelienFT b779d2d
Merge branch 'master' into add_timer_based_expiration_pending_pool
AurelienFT b071c93
Refactor extracted outputs cache
AurelienFT 1c7e283
Update extract outputs to work with TxId useful for skipped transactions
AurelienFT 9949937
update changelog
AurelienFT 29ae565
Fix clippy
AurelienFT 2cf1efb
fmt
AurelienFT e90de63
Remove expiration out of timer
AurelienFT 080b73b
change coins_created management in extracted outputs
AurelienFT be8c150
Use double index map for contracts
AurelienFT 43c8506
Merge branch 'master' into add_timer_based_expiration_pending_pool
xgreenx 02595bb
Merge branch 'master' into add_timer_based_expiration_pending_pool
AurelienFT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add an expiration interval check for pending pool and refactor extracted_outputs to not rely on block creation/process sequence. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| //! Temporary module to extract outputs until we know that they have been settled in database or skipped. | ||
|
|
||
| use std::collections::HashMap; | ||
|
|
||
| use fuel_core_types::{ | ||
| fuel_tx::{ | ||
| input::coin::{ | ||
| CoinPredicate, | ||
| CoinSigned, | ||
| }, | ||
| Address, | ||
| AssetId, | ||
| ContractId, | ||
| Input, | ||
| Output, | ||
| TxId, | ||
| UtxoId, | ||
| }, | ||
| services::txpool::ArcPoolTx, | ||
| }; | ||
|
|
||
| pub struct ExtractedOutputs { | ||
| contract_created: HashMap<ContractId, TxId>, | ||
| contract_created_by_tx: HashMap<TxId, Vec<ContractId>>, | ||
| coins_created: HashMap<TxId, HashMap<u16, (Address, u64, AssetId)>>, | ||
| } | ||
|
|
||
| impl ExtractedOutputs { | ||
| pub fn new() -> Self { | ||
| Self { | ||
| contract_created: HashMap::new(), | ||
| contract_created_by_tx: HashMap::new(), | ||
| coins_created: HashMap::new(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Default for ExtractedOutputs { | ||
| fn default() -> Self { | ||
| Self::new() | ||
| } | ||
| } | ||
|
|
||
| impl ExtractedOutputs { | ||
| pub fn new_extracted_transaction(&mut self, tx: &ArcPoolTx) { | ||
| let tx_id = tx.id(); | ||
| for (idx, output) in tx.outputs().iter().enumerate() { | ||
| match output { | ||
| Output::ContractCreated { contract_id, .. } => { | ||
| self.contract_created.insert(*contract_id, tx_id); | ||
| self.contract_created_by_tx | ||
| .entry(tx_id) | ||
| .or_default() | ||
| .push(*contract_id); | ||
| } | ||
| Output::Coin { | ||
| to, | ||
| amount, | ||
| asset_id, | ||
| } => { | ||
| self.coins_created.entry(tx_id).or_default().insert( | ||
| u16::try_from(idx).expect("Outputs count is less than u16::MAX"), | ||
| (*to, *amount, *asset_id), | ||
| ); | ||
| } | ||
| Output::Contract { .. } | ||
| | Output::Change { .. } | ||
| | Output::Variable { .. } => { | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
| for input in tx.inputs() { | ||
| match input { | ||
| Input::CoinSigned(CoinSigned { utxo_id, .. }) | ||
| | Input::CoinPredicate(CoinPredicate { utxo_id, .. }) => { | ||
| self.coins_created | ||
| .entry(*utxo_id.tx_id()) | ||
| .and_modify(|coins| { | ||
| coins.remove(&utxo_id.output_index()); | ||
| }); | ||
| } | ||
| Input::Contract(_) | ||
| | Input::MessageCoinPredicate(_) | ||
| | Input::MessageCoinSigned(_) | ||
| | Input::MessageDataPredicate(_) | ||
| | Input::MessageDataSigned(_) => { | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub fn new_skipped_transaction(&mut self, tx_id: &TxId) { | ||
| self.new_executed_transaction(tx_id); | ||
| } | ||
AurelienFT marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+94
to
+96
Contributor
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.
At first glance this code is similar to something like this 😄 |
||
|
|
||
| pub fn new_executed_transaction(&mut self, tx_id: &TxId) { | ||
| let contract_ids = self.contract_created_by_tx.remove(tx_id); | ||
| if let Some(contract_ids) = contract_ids { | ||
| for contract_id in contract_ids { | ||
| self.contract_created.remove(&contract_id); | ||
| } | ||
| } | ||
| self.coins_created.remove(tx_id); | ||
| } | ||
|
|
||
| pub fn contract_exists(&self, contract_id: &ContractId) -> bool { | ||
| self.contract_created.contains_key(contract_id) | ||
| } | ||
|
|
||
| pub fn coin_exists( | ||
| &self, | ||
| utxo_id: &UtxoId, | ||
| address: &Address, | ||
| amount: &u64, | ||
| asset_id: &AssetId, | ||
| ) -> bool { | ||
| self.coins_created | ||
| .get(utxo_id.tx_id()) | ||
| .map_or(false, |coins| { | ||
| coins | ||
| .get(&utxo_id.output_index()) | ||
| .map_or(false, |(a, am, asid)| { | ||
| a == address && am == amount && asid == asset_id | ||
| }) | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
A nit:
For clarity,
HashMap<TxId, HashMap<u16, (Address, u64, AssetId)>>maybe deserves a dedicated type to be introduced.It'll also allow to make code like this more lean:
a == address && am == amount && asid == asset_id