Skip to content
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

fix: accumulated block data bitmap now contains current stxo indexes #3109

Merged

Conversation

sdbondi
Copy link
Member

@sdbondi sdbondi commented Jul 20, 2021

Description

Greatly reduces the amount of data stored per block by only storing the
spent indexes at a specific height instead of the entire spent bitmap.

The block chain database now stores a single full deleted bitmap at the
tip.

Breaking changes:

  • Blockchain Database (database must be reynced)
  • Blockchain Consensus (hard/soft fork)
  • P2P Network (some protocols are no longer compatible)
  • GRPC (GRPC clients need to be updated)

Motivation and Context

Bytes of storage per block reduced. At height 8033, the savings are
130mb on the new database. As the STXO set increases, the size of
the deleted bitmap typically increases (depends on compressibility of the data
in the bitmap), previously resulting in many megabytes of data per block.
This is no longer the case.

As a result of only having the tip bitmap, we can only calculate the output_mr for the next block
from the tip. In practice this is all that is needed, however some unit tests needed to be updated.

How Has This Been Tested?

Checklist:

  • I'm merging against the development branch.
  • I have squashed my commits into a single commit.

BREAKING CHANGE: Blockchain Database (database must be resynced)

@sdbondi sdbondi force-pushed the core-minimal-spent-bitmap branch 3 times, most recently from 93601b1 to 1a040a4 Compare July 20, 2021 06:32
@sdbondi sdbondi changed the title Fix: Accumulated block data bitmap only contains current spent indexes Fix: Accumulated block data bitmap now contains current spent indexes, db size reduction Jul 20, 2021
@sdbondi sdbondi changed the title Fix: Accumulated block data bitmap now contains current spent indexes, db size reduction fix: accumulated block data bitmap now contains current spent indexes, db size reduction Jul 20, 2021
@sdbondi sdbondi force-pushed the core-minimal-spent-bitmap branch from 1a040a4 to ff6ee27 Compare July 20, 2021 07:37
@sdbondi sdbondi changed the title fix: accumulated block data bitmap now contains current spent indexes, db size reduction fix: accumulated block data bitmap now contains current stxo indexes Jul 20, 2021
@@ -264,6 +264,9 @@ impl LMDBDatabase {
UpdateDeletedBlockAccumulatedDataWithDiff { header_hash, deleted } => {
self.update_deleted_block_accumulated_data_with_diff(&write_txn, header_hash, deleted)?;
},
UpdateDeletedBitmap { deleted } => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like exposing this operation on its own. The deleted bitmap should only ever be updated as part of another operation, so that the database is alway consistent. Where is this operation called on it's own?

Copy link
Member Author

@sdbondi sdbondi Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with that, but trying to avoid refactoring existing code too much. It's used in pruned mode where there are a number of operations that must be atomic to not break the database and could potentially be brought together into one operation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment there to discourage it's use

@sdbondi sdbondi force-pushed the core-minimal-spent-bitmap branch 5 times, most recently from 6f5dd66 to ef69b32 Compare July 20, 2021 10:40
Greatly reduces the amount of data stored per block by only storing the
spent indexes at a specific height instead of the entire spent bitmap.

The block chain database now stores a single full deleted bitmap at the
tip.

BREAKING CHANGE: Blockchain database format is not backward-compatible
@sdbondi sdbondi force-pushed the core-minimal-spent-bitmap branch from ef69b32 to d844043 Compare July 20, 2021 10:42
@aviator-app
Copy link
Contributor

aviator-app bot commented Jul 21, 2021

PR queued successfully. Your position in queue is: 2

@aviator-app
Copy link
Contributor

aviator-app bot commented Jul 21, 2021

PR is on top of the queue now

@aviator-app aviator-app bot merged commit 77b1789 into tari-project:development Jul 21, 2021
@sdbondi sdbondi deleted the core-minimal-spent-bitmap branch July 23, 2021 15:17
sdbondi added a commit to sdbondi/tari that referenced this pull request Jul 26, 2021
Prevent double spends from being added to the mempool. This bug
was introduced by the blockchain deleted bitmap storage changes
in tari-project#3109. A new block template contained already spent transactions
which would then fail a double spend check in `calculate_mmr_roots`.
sdbondi added a commit to sdbondi/tari that referenced this pull request Jul 26, 2021
Prevent double spends from being added to the mempool. This bug
was introduced by the blockchain deleted bitmap storage changes
in tari-project#3109. A new block template contained already spent transactions
which would then fail a double spend check in `calculate_mmr_roots`.
sdbondi added a commit to sdbondi/tari that referenced this pull request Jul 26, 2021
Prevent double spends from being added to the mempool. This bug
was introduced by the blockchain deleted bitmap storage changes
in tari-project#3109. A new block template contained already spent transactions
which would then fail a double spend check in `calculate_mmr_roots`.
sdbondi added a commit to sdbondi/tari that referenced this pull request Jul 27, 2021
Prevent double spends from being added to the mempool. This bug
was introduced by the blockchain deleted bitmap storage changes
in tari-project#3109. A new block template contained already spent transactions
which would then fail a double spend check in `calculate_mmr_roots`.
sdbondi added a commit to sdbondi/tari that referenced this pull request Jul 27, 2021
Prevent double spends from being added to the mempool. This bug
was introduced by the blockchain deleted bitmap storage changes
in tari-project#3109. A new block template contained already spent transactions
which would then fail a double spend check in `calculate_mmr_roots`.
sdbondi added a commit to sdbondi/tari that referenced this pull request Jul 27, 2021
Prevent double spends from being added to the mempool. This bug
was introduced by the blockchain deleted bitmap storage changes
in tari-project#3109. A new block template contained already spent transactions
which would then fail a double spend check in `calculate_mmr_roots`.
sdbondi added a commit to sdbondi/tari that referenced this pull request Jul 27, 2021
Prevent double spends from being added to the mempool. This bug
was introduced by the blockchain deleted bitmap storage changes
in tari-project#3109. A new block template contained already spent transactions
which would then fail a double spend check in `calculate_mmr_roots`.
sdbondi added a commit to sdbondi/tari that referenced this pull request Jul 27, 2021
Prevent double spends from being added to the mempool. This bug
was introduced by the blockchain deleted bitmap storage changes
in tari-project#3109. A new block template contained already spent transactions
which would then fail a double spend check in `calculate_mmr_roots`.
aviator-app bot added a commit that referenced this pull request Jul 28, 2021
…3141)

<!--- Provide a general summary of your changes in the Title above -->

## Description
<!--- Describe your changes in detail -->
The main change here is to check the tip height after retrieving the
block template but before MMR roots are calculated. When mining quickly
in cucumber tests, this race condition occurs. Previously, this would be
ok, the miner would simply mine 1 behind the current tip height. But
because we can no longer calculate MMRs prior to the tip, this MMR call
(`get_new_block`) now returns an error, which fails cucumber.

`get_new_block` now returns a `FailedPrecondition` GRPC error status in the event
that the block template submitted is not for the current chain tip. This allows
clients to more easily identify this case, typically by asking for a new template. 

This refactor was performed because the protocol was gaining too much
complexity to exist in a single function.

Some extra changes to get all cucumbers to pass:
- Replace `--daemon` flags with `--non-interactive` 
- Used more 'tolerant' step for `As a user I want to change base node for a wallet` scenario

## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
The `Verify all coinbases in hybrid mining are accounted for` cucumber test is flakey
due to change in semantics for get_new_block since #3109. The possibility of this occurring 
with normal difficulties is usually tiny, but may be a symptom of a slow get_coinbase request. 

## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->
Merge mined on local machine
`Verify all coinbases in hybrid mining are accounted for` passes
Suggest that we run tests with monero pool and nodejs pool

## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
* [x] I'm merging against the `development` branch.
* [x] I have squashed my commits into a single commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants