Skip to content

Commit babfca4

Browse files
committed
Handle delegations, orders in rollback
1 parent bfc91f1 commit babfca4

File tree

1 file changed

+21
-8
lines changed
  • wallet/src/account/output_cache

1 file changed

+21
-8
lines changed

wallet/src/account/output_cache/mod.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ impl OutputCache {
862862
}
863863

864864
for tx in tx_to_rollback_data {
865-
self.rollback_tx_data(&tx);
865+
self.rollback_tx_data(&tx)?;
866866
}
867867

868868
conflicting_txs_with_descendants.extend(txs_to_rollback.into_iter());
@@ -1276,7 +1276,7 @@ impl OutputCache {
12761276
pub fn remove_confirmed_tx(&mut self, tx_id: &OutPointSourceId) -> WalletResult<()> {
12771277
if let Some(tx) = self.txs.remove(tx_id) {
12781278
matches!(tx.state(), TxState::Confirmed(..));
1279-
self.rollback_tx_data(&tx);
1279+
self.rollback_tx_data(&tx)?;
12801280
}
12811281

12821282
ensure!(
@@ -1495,7 +1495,7 @@ impl OutputCache {
14951495

14961496
// After tx is removed as a result of reorg, abandoning or marking as conflicted
14971497
// its effect on OutputCache's data fields should be rolled back
1498-
fn rollback_tx_data(&mut self, tx: &WalletTx) {
1498+
fn rollback_tx_data(&mut self, tx: &WalletTx) -> WalletResult<()> {
14991499
let tx_id = tx.id();
15001500

15011501
// Iterate in reverse to handle situations where an account is modified twice in the same tx
@@ -1585,18 +1585,31 @@ impl OutputCache {
15851585
}
15861586
}
15871587
}
1588+
TxOutput::CreateDelegationId(_, _) => {
1589+
let input0_outpoint = crate::utils::get_first_utxo_outpoint(tx.inputs())?;
1590+
let delegation_id = make_delegation_id(input0_outpoint);
1591+
self.delegations.remove(&delegation_id);
1592+
}
1593+
TxOutput::IssueFungibleToken(_) => {
1594+
let token_id = make_token_id(tx.inputs()).ok_or(WalletError::NoUtxos)?;
1595+
self.token_issuance.remove(&token_id);
1596+
}
1597+
TxOutput::CreateOrder(_) => {
1598+
let input0_outpoint = crate::utils::get_first_utxo_outpoint(tx.inputs())?;
1599+
let order_id = make_order_id(input0_outpoint);
1600+
self.orders.remove(&order_id);
1601+
}
15881602
TxOutput::Burn(_)
15891603
| TxOutput::Transfer(_, _)
15901604
| TxOutput::IssueNft(_, _, _)
15911605
| TxOutput::DataDeposit(_)
15921606
| TxOutput::DelegateStaking(_, _)
15931607
| TxOutput::LockThenTransfer(_, _, _)
1594-
| TxOutput::CreateDelegationId(_, _)
1595-
| TxOutput::IssueFungibleToken(_)
1596-
| TxOutput::Htlc(_, _)
1597-
| TxOutput::CreateOrder(_) => {}
1608+
| TxOutput::Htlc(_, _) => {}
15981609
}
15991610
}
1611+
1612+
Ok(())
16001613
}
16011614

16021615
/// Mark a transaction and its descendants as abandoned
@@ -1633,7 +1646,7 @@ impl OutputCache {
16331646
}
16341647

16351648
for tx in txs_to_rollback {
1636-
self.rollback_tx_data(&tx);
1649+
self.rollback_tx_data(&tx)?;
16371650
}
16381651

16391652
Ok(all_abandoned)

0 commit comments

Comments
 (0)