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

[DB] Introduce EVO database #2271

Merged
merged 20 commits into from
Apr 13, 2021
Merged

Conversation

random-zebra
Copy link

@random-zebra random-zebra commented Mar 25, 2021

Extracted from #2267.
This introduces the new database, used for all DMN-related things, and updates the dbWrapper.

Builds on top of:

random-zebra and others added 17 commits April 11, 2021 10:20
>>> backports dash@4531f6b896119b2b8f33c03a50cb4d4ee62a6acb

Allows easier commit/rollback handling, especially useful when
AcceptBlock fails and things need to be reverted.
>>> backports dash@c9a72e8880fe88f07b64aecfc059f08ec14440fc

Also add transaction handling to ConnectTip and DisconnectTip and a few
other places where blocks are processed.
>>> adapted from dash@378dadd0f7c73285ab5a13d1f6fb96314822170b
>>> Backports dash@a1cca1b9a11975b8a57d916d1325dc8d855217b7

the boolean value will lose its meaning in the next commit
>>> from dash@521d4ae08fe0e35c30bf05ffe8b9d611e86c3bfd

CDBTransaction is changed to allow CDBBatch, CDBWrapper and other
CDBTransactions as parent instead of just CDBWrapper. This in turn
allows to implement multi-staged commits in CEvoDB.

We now have the "current transaction" which is started and ended (commit
or rollback) for each call to Connect-/DisconnectBlock. When the current
transaction is committed, it moves its contents into the "root
transaction" instead of directly writing to CDBWrapper.
CommitRootTransaction() then handles the final commitment to CDBWrapper.
It is called at the same time when the chainstate is flushed to disk,
which guarantees consistency between chainstate and CEvoDB.
>>> backports dash@5b4fe43c2577f3f39fd174c84a8c23c99646903d

This has the wanted side effect of proper locking of "cs" inside
CommitCurTransaction and RollbackCurTransaction, which was not easily
possible to implement in the generic version. This fixes some rare
crashes.
This allow to pre-serialize keys in advance and pass the serialized form
into these classes.
...instead of comparing by using the keys < operator.
There are 2 reasons for this:
1. This better mimics the behavior of CDBWrapper. Otherwise there is
   a chance of discrepancy when it comes to key equality.
2. Next commit will introduce CDBTransactionIterator, which relies on
   CDBTransaction and CDBWrapper being compatible in the way keys are
   compared.
This iterator allows merged iteration of the key/values from the parent
and the not-yet-committed key/values from the transaction. This also
works for nested transactions (as used in CEvoDB).

It's interface mimics CDBIterator.
>>> backports dash@1b3d0d9a347f1e40e9efa246ff3691c8e995383f
>>> backports dash@849bf3c76e62a980e89f2be2877ea2cc3728017c
it will be locked from outside when iterating mined commitments (ref.
dash@c68b5f68aa41881c3bf36d8881b60b6855868605)
@random-zebra
Copy link
Author

Rebased on master. Next in line for #2267

Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

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

Code ACK c27bbed

@@ -1466,13 +1476,23 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
LogPrintf("%s: hashPrev=%s view=%s\n", __func__, hashPrevBlock.GetHex(), view.GetBestBlock().GetHex());
assert(hashPrevBlock == view.GetBestBlock());

if (pindex->pprev) {
bool fDIP3Active = Params().GetConsensus().NetworkUpgradeActive(pindex->nHeight, Consensus::UPGRADE_V6_0);
bool fHasBestBlock = evoDb->VerifyBestBlock(hashPrevBlock);
Copy link

Choose a reason for hiding this comment

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

future: would be good to maintain the best block hash cached inside a manager (manager that should be created, and the evoDb should be encapsulated there), preventing the disk access on every new connected block (slow operation).

src/dbwrapper.h Show resolved Hide resolved
Copy link

@furszy furszy left a comment

Choose a reason for hiding this comment

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

Code ACK c27bbed.

Have to add that spent some time thinking about this and will return to this area after finishing with #2267, so we can talk and brainstorm more about it after reviewing the complete set of changes.

@furszy furszy merged commit 75ed795 into PIVX-Project:master Apr 13, 2021
furszy added a commit that referenced this pull request Apr 27, 2021
6dbdf37 [Consensus] Serialize also shield inputs for ProReg inputshash (random-zebra)
e0ff60f [Consensus] Serialize the whole scriptPayout for ProReg sign string (random-zebra)
e659d7e [Trivial] Fix styling/logging nits (random-zebra)
170ab92 [Tests] Check for protx inputs hash in evo_specialtx_tests (random-zebra)
a1cb227 [BUG] Add proper virtual dtor for CActiveDeterministicMasternodeManager (random-zebra)
0520ea9 [Init] Add -mnoperatorprivatekey to flag the active mn as deterministic (random-zebra)
dcb5df9 [Refactoring] CADMM: GetLocalAddress static (random-zebra)
6cd5b0c [Refactoring] encapsulate activeMNINfo inside activeMNManager (random-zebra)
ca9d10c Implement CActiveDeterministicMasternodeManager (Alexander Block)
66302c3 [Tests] Check deterministic masternodes unique properties (random-zebra)
ddad010 [Validation] Check duplicate unique-properties for masternodes (random-zebra)
41869ec [Refactoring] Add IsDIP3Enforced/LegacyMNObsolete funcs to DMNManager (random-zebra)
c013bf1 [Refactoring] Add evo Notification Interface (random-zebra)
180a311 [Validation] Connect deterministic manager to block processing (random-zebra)
7f2d2b5 [MOVE-ONLY] move special_tx_validation_test inside evo_* test file (random-zebra)
9ac0f37 [Tests] Introduce evo_deterministicmns_tests.cpp (random-zebra)
48c66dc Conflict handling for ProRegTx in mempool (Alexander Block)
ae33972 [Core] Deterministic Masternode List implementation (random-zebra)
50c277b Implement std::unordered_map/set compatible hasher classes for salted hashes (Alexander Block)
0c064f8 [Tests] Add tests for SetTxPayload/GetTxPayload and CheckStringSig (random-zebra)
693772a [Core] Introduce ProRegTx payload (random-zebra)
6fb2496 Define hash function for uint256 to be used in STL-like containers (random-zebra)
3f74c88 [Build] CMake: add immer headers (random-zebra)
e067443 [Build] Add "immer" functional/immutable containers library (random-zebra)
b92de4d [Consensus] Reject special txes before V6 enforcement (random-zebra)

Pull request description:

  Extracted from #2267.
  This is the first fundamental PR.
  Here we introduce the `PROREG` transaction type, the DMN manager (and active-masternode manager), and all the required classes (`CDeterministicMN`, `CDeterministicMNState`, `CDeterministicMNStateDiff`, `CDeterministicMNList` and `CDeterministicMNListDiff`).

  This contains also the headers-only immer library for persistent immutable data structures. Reasons for the inclusion are explained in #2267 (under "code architecture").
  The headers are copied over, at the same commit used by Dash (`0a718d2d76bab6ebdcf43de943bd6c7d2dbfe2f9`). Later on, we might want to properly include this as a git subtree.

  Built on top of:
  - [x] #2271

ACKs for top commit:
  furszy:
    Code review ACK 6dbdf37.
  Fuzzbawls:
    Code ACK 6dbdf37

Tree-SHA512: 3b175eef5cd03c73ee4d125063a4a5f5a5eff6064fb6ff3f54c01b6f2d48562c6181cbfa2687025a2fc9a65a80b17d799581cba1f2937333dfee4c3212b5cfac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants