Skip to content

Commit

Permalink
fix: burned reorg (#4697)
Browse files Browse the repository at this point in the history
Description
---
Fixes rewind to height for burned outputs

Motivation and Context
---
When rewinding the blockchain, the rewind tries to delete the "unspent" utxo. But burned outputs never have spent utxos created for them. This causes rewinds to break. 


How Has This Been Tested?
---
Added a new cucumber test

Fixes: #4662
  • Loading branch information
SWvheerden committed Sep 20, 2022
1 parent 2b5afcf commit 08773f4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,10 @@ impl LMDBDatabase {
if inputs.iter().any(|r| r.input.output_hash() == output_hash) {
continue;
}
// if an output was burned, it was never created as an unspent utxo
if output.is_burned() {
continue;
}
lmdb_delete(
txn,
&*self.utxo_commitment_index,
Expand Down
29 changes: 29 additions & 0 deletions integration_tests/features/Reorgs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,35 @@ Feature: Reorgs
And node B is at height 10
And node C is at height 10


@critical
Scenario: Simple reorg with burned output
# Chain 1
# Note: Use more than 1 base node to speed up the test
Given I have a seed node SEED_B
And I have a base node B connected to seed SEED_B
And I have wallet WB connected to base node B
And I have mining node BM connected to base node B and wallet WB
And mining node BM mines 10 blocks with min difficulty 1 and max difficulty 1

When I wait for wallet WB to have at least 55000000000 uT
When I create a burn transaction of 1000000 uT from WB at fee 100
And mining node BM mines 5 blocks with min difficulty 1 and max difficulty 1
# Chain 2
# Note: Use more than 1 base node to speed up the test
Given I have a seed node SEED_C
And I have a base node C connected to seed SEED_C
And I have wallet WC connected to base node C
And I have mining node CM connected to base node C and wallet WC
And mining node CM mines 17 blocks with min difficulty 1 and max difficulty 1
# Connect chain 1 and 2
Then node B is at height 15
And node C is at height 17
Given I have a base node SA connected to nodes B,C
Then node SA is at height 17
And node B is at height 17
And node C is at height 17

@critical
Scenario: Node rolls back reorg on invalid block
Given I have a seed node SA
Expand Down

0 comments on commit 08773f4

Please sign in to comment.