-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Rollback unsuccessful preconfs in the mempool #3264
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
Changes from 4 commits
30b5869
a970140
42f111e
01410e0
84b0c4a
f989aab
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Rollback stale preconfirmations in the mempool when the canonical block at that height omits the preconfirmed transactions, restoring spent inputs and removing dependent transactions. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ use fuel_core_types::{ | |
| CoinPredicate, | ||
| CoinSigned, | ||
| }, | ||
| contract::Contract as ContractInput, | ||
| message::{ | ||
| MessageCoinPredicate, | ||
| MessageCoinSigned, | ||
|
|
@@ -57,6 +58,9 @@ pub struct BasicCollisionManager<StorageIndex> { | |
| coins_spenders: BTreeMap<UtxoId, StorageIndex>, | ||
| /// Contract -> Transaction that currently create the contract | ||
| contracts_creators: HashMap<ContractId, StorageIndex>, | ||
| /// Contract -> Transactions (by TxId) that currently use the contract as an input. | ||
| /// Symmetric to `contracts_creators`; used to evict dependents during rollback. | ||
| contract_users: HashMap<ContractId, Vec<TxId>>, | ||
| /// Blob -> Transaction that currently create the blob | ||
| blobs_users: HashMap<BlobId, StorageIndex>, | ||
| } | ||
|
|
@@ -67,6 +71,7 @@ impl<StorageIndex> BasicCollisionManager<StorageIndex> { | |
| messages_spenders: HashMap::new(), | ||
| coins_spenders: BTreeMap::new(), | ||
| contracts_creators: HashMap::new(), | ||
| contract_users: HashMap::new(), | ||
| blobs_users: HashMap::new(), | ||
| } | ||
| } | ||
|
|
@@ -174,6 +179,17 @@ where | |
| .collect() | ||
| } | ||
|
|
||
| fn get_contract_users(&self, contract_id: &ContractId) -> Vec<TxId> { | ||
| self.contract_users | ||
| .get(contract_id) | ||
| .cloned() | ||
| .unwrap_or_default() | ||
| } | ||
|
|
||
| fn contract_created_in_pool(&self, contract_id: &ContractId) -> bool { | ||
| self.contracts_creators.contains_key(contract_id) | ||
| } | ||
|
|
||
| fn find_collisions( | ||
| &self, | ||
| transaction: &PoolTransaction, | ||
|
|
@@ -248,6 +264,7 @@ where | |
| let blob_id = checked_tx.transaction().blob_id(); | ||
| self.blobs_users.insert(*blob_id, storage_id); | ||
| } | ||
| let tx_id = store_entry.transaction.id(); | ||
| for input in store_entry.transaction.inputs() { | ||
| match input { | ||
| Input::CoinSigned(CoinSigned { utxo_id, .. }) | ||
|
|
@@ -262,7 +279,12 @@ where | |
| // insert message | ||
| self.messages_spenders.insert(*nonce, storage_id); | ||
| } | ||
| _ => {} | ||
| Input::Contract(ContractInput { contract_id, .. }) => { | ||
| self.contract_users | ||
| .entry(*contract_id) | ||
| .or_default() | ||
| .push(tx_id); | ||
| } | ||
| } | ||
| } | ||
| for output in store_entry.transaction.outputs().iter() { | ||
|
|
@@ -284,6 +306,7 @@ where | |
| let blob_id = checked_tx.transaction().blob_id(); | ||
| self.blobs_users.remove(blob_id); | ||
| } | ||
| let tx_id = transaction.id(); | ||
| for input in transaction.inputs() { | ||
| match input { | ||
| Input::CoinSigned(CoinSigned { utxo_id, .. }) | ||
|
|
@@ -298,7 +321,14 @@ where | |
| // remove message | ||
| self.messages_spenders.remove(nonce); | ||
| } | ||
| _ => {} | ||
| Input::Contract(ContractInput { contract_id, .. }) => { | ||
| if let Some(users) = self.contract_users.get_mut(contract_id) { | ||
| users.retain(|id| id != &tx_id); | ||
| if users.is_empty() { | ||
| self.contract_users.remove(contract_id); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+351
to
+358
Collaborator
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 think removing transaction IDs here, you will not have access to them during
Member
Author
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. Follow-up: #3268 |
||
| } | ||
| } | ||
| for output in transaction.outputs().iter() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.