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

Split explorer storage in stable and unstable #3205

Closed

Conversation

ecioppettini
Copy link
Contributor

@ecioppettini ecioppettini commented Apr 10, 2021

Motivation

Intermediate step to introduce use a non-volatile database for the explorer. It doesn't change any behavior by itself, so it could be merged individually, it's mostly to prepare things.

About

This PR

  • Adds a simple in-memory representation of what the explorer would need to persist the indices. Each time the chain_length of the tip increases by one, a new block passes the epoch stability depth threshold and gets inserted there.
  • Adds a wrapper type to make queries first looking in the multiverse and then looking in the stable storage.
  • Undo the apply_block operation from blocks moved to the stable storage, in any incoming multiverse State.
  • (WIP) Improves the explorer sanity test a bit, to account for the fact that blocks will be removed from 'memory'.

The last point requires some explanation. Currently the explorer has a multiverse of State, which is entirely a persistent data structure. This means we have an immutable version of the indexes for each block that we have, and there is no way to simply forget things in there, but if we don't remove things that we move to the stable storage, then there will be no point in doing it.

Because of this, I took the approach of applying delayed deletes. Each time we add a State, we also unapply a block from the past (the one epoch_stability_depth blocks behind), before inserting.

See the following graph of the multiverse for a graphical illustration.

For the notation:

  • B{id} represents a block.
  • S{id} means the State in the multiverse, which in this case represents a snapshot of the explorer index. This is what's used to answer queries by providing a branch id through the api.
  • + means applying a block to the index.
  • - means un-applying a block from the index. (which was previously applied)
    image

Important: this is just partial, although it can be merged as it is, this is still missing the undo operations for the vote tally indices (mostly because I don't quite understand that one entirely).

Note: I wrote something about this in #2759, but is better to read this first, because I still need to update that one with more up-to-date thoughts.

the important part here is that we only need to remove from the
beginning, because this is a blockchain, and we are going to be undoing
blocks from the back.
doing it in set_tip doesn't work, because we do that *after* applying
the block, and then we won't have the stable_block in the tip's branch
also, prevents some concurrency issues
mostly to account for the fact that at some point data won't be entirely
in memory, so we need to take epoch_stability_depth and utxo inputs into
account
@ecioppettini ecioppettini added the A-explorer Area: Explorer API and backend label Apr 10, 2021
@ecioppettini ecioppettini self-assigned this Apr 10, 2021
Base automatically changed from dev to master April 10, 2021 16:15
@ecioppettini ecioppettini deleted the split-explorer-storage-in-stable-and-unstable branch July 22, 2021 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-explorer Area: Explorer API and backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant