nimbus-eth1/nimbus/db
Jordan Hrycaj 0f430c70fd
Aristo avoid storage trie update race conditions (#2251)
* Update TDD suite logger output format choices

why:
  New format is not practical for TDD as it just dumps data across a wide
  range (considerably larder than 80 columns.)

  So the new format can be turned on by function argument.

* Update unit tests samples configuration

why:
  Slightly changed the way to find the `era1` directory

* Remove compiler warnings (fix deprecated expressions and phrases)

* Update `Aristo` debugging tools

* Always update the `storageID` field of account leaf vertices

why:
  Storage tries are weekly linked to an account leaf object in that
  the `storageID` field is updated by the application.

  Previously, `Aristo` verified that leaf objects make sense when passed
  to the database. As a consequence
  * the database was inconsistent for a short while
  * the burden for correctness was all on the application which led
    to delayed error handling which is hard to debug.

  So `Aristo` will internally update the account leaf objects so that
  there are no race conditions due to the storage trie handling

* Aristo: Let `stow()`/`persist()` bail out unless there is a `VertexID(1)`

why:
  The journal and filter logic depends on the hash of the `VertexID(1)`
  which is commonly known as the state root. This implies that all
  changes to the database are somehow related to that.

* Make sure that a `Ledger` account does not overwrite the storage trie reference

why:
  Due to the abstraction of a sub-trie (now referred to as column with a
  hash describing its state) there was a weakness in the `Aristo` handler
  where an account leaf could be overwritten though changing the validity
  of the database. This has been changed and the database will now reject
  such changes.

  This patch fixes the behaviour on the application layer. In particular,
  the column handle returned by the `CoreDb` needs to be updated by
  the `Aristo` database state. This mitigates the problem that a storage
  trie might have vanished or re-apperaed with a different vertex ID.

* Fix sub-trie deletion test

why:
  Was originally hinged on `VertexID(1)` which cannot be wholesale
  deleted anymore after the last Aristo update. Also, running with
  `VertexID(2)` needs an artificial `VertexID(1)` for making `stow()`
  or `persist()` work.

* Cosmetics

* Activate `test_generalstate_json`

* Temporarily `deactivate test_tracer_json`

* Fix copyright header

---------

Co-authored-by: jordan <jordan@dry.pudding>
Co-authored-by: Jacek Sieka <jacek@status.im>
2024-05-30 17:48:38 +00:00
..
aristo Aristo avoid storage trie update race conditions (#2251) 2024-05-30 17:48:38 +00:00
core_db Aristo avoid storage trie update race conditions (#2251) 2024-05-30 17:48:38 +00:00
era1_db fix import path; force refc memory management even with Nim 2.0+ (#2241) 2024-05-29 20:47:06 +02:00
kvt fix warnings around unused imports of std/algorithm; proc -> func (#2220) 2024-05-25 21:01:28 +02:00
ledger Aristo avoid storage trie update race conditions (#2251) 2024-05-30 17:48:38 +00:00
state_db Culling legacy DB and accounts cache (#2197) 2024-05-20 10:17:51 +00:00
.gitignore Database architecture diagram & module overview (#2065) 2024-03-08 18:42:46 +00:00
README.md Aristo resume off line syncing on pre loaded database (#2203) 2024-05-22 13:41:14 +00:00
access_list.nim Implement RPC method eth_getAccessList (#2091) 2024-03-21 18:24:32 +07:00
aristo.nim Coredb use stackable api for aristo backend (#2060) 2024-02-29 21:10:24 +00:00
core_db.nim Cleanup unused raises in evm/state and other obsolete informations (#2243) 2024-05-30 09:03:54 +00:00
distinct_tries.nim Culling legacy DB and accounts cache (#2197) 2024-05-20 10:17:51 +00:00
era1_db.nim era: simplify, instant startup (#2218) 2024-05-26 08:24:13 +02:00
kvstore_rocksdb.nim results: use canonical import (#2248) 2024-05-30 14:54:03 +02:00
kvt.nim Coredb use stackable api for aristo backend (#2060) 2024-02-29 21:10:24 +00:00
ledger.nim Simplify AccountsLedgerRef complexity (#2239) 2024-05-29 13:06:49 +02:00
state_db.nim Rename hasCodeOrNonce to contractCollision 2024-04-16 09:31:10 +07:00
storage_types.nim rm clique/mining remnants; rm unused code (#2232) 2024-05-28 07:10:10 +02:00
transient_storage.nim implement EIP-1153: Transient storage 2023-06-23 14:04:36 +07:00
trie_get_branch.nim Implementation of Nimbus eth_getProof RPC Endpoint. (#1960) 2024-01-09 10:05:52 +08:00
values_from_bytes.nim Add check copyright year linter to CI 2023-11-01 10:41:20 +07:00

README.md

Nimbus-eth1 -- Ethereum execution layer database architecture

Last update: 2024-03-08

The following diagram gives a simplified view how components relate with regards to the data storage management.

An arrow between components a and b (as in a->b) is meant to be read as a relies directly on b, or a is served by b. For classifying the functional type of a component in the below diagram, the abstraction type is enclosed in brackets after the name of a component.

  • (application)
    This is a group of software modules at the top level of the hierarchy. In the diagram below, the EVM is used as an example. Another application might be the RPC service.

  • (API)
    The API classification is used for a thin software layer hiding a set of different drivers where only one driver is active for the same API instance. It servers as sort of a logical switch.

  • (concentrator)
    The concentrator merges several sub-module instances and provides their collected services as a single unified instance. There is not much additional logic implemented besides what the sub-modules provide.

  • (driver)
    The driver instances are sort of the lower layer workhorses. The implement logic for solving a particular problem, providing a typically well defined service, etc.

  • (engine)
    This is a bottom level driver in the below diagram.

                           +-------------------+
                           | EVM (application) |
                           +-------------------+
                                   |     |
                                   v     |
       +-----------------------------+   |
       |   State DB (concentrator)   |   |
       +-----------------------------+   |
           |                       |     |
           v                       |     |
       +------------------------+  |     |
       |      Ledger (API)      |  |     |
       +------------------------+  |     |
           |              |        |     |
           v              |        |     |
       +--------------+   |        |     |
       | ledger cache |   |        |     |
       |   (driver)   |   |        |     |
       +--------------+   |        |     |
           |              v        |     |
           |   +----------------+  |     |
           |   |   Common       |  |     |
           |   | (concentrator) |  |     |
           |   +----------------+  |     |
           |             |         |     |
           v             v         v     v
       +---------------------------------------+
       |               Core DB (API)           |
       +---------------------------------------+
                         |
                         v
       +---------------------------------------+
       |    Aristo DB (driver,concentrator)    |
       +---------------------------------------+
                 |             |
                 v             v
       +--------------+  +---------------------+
       | Kvt (driver) |  | Aristo MPT (driver) |
       +--------------+  +---------------------+
                 |             |
                 v             v
       +---------------------------------------+
       |         Rocks DB (engine)             |
       +---------------------------------------+
    

Here is a list of path references for the components with some explanation. The sources for the components are not always complete but indicate the main locations where to start looking at.

  • Aristo DB (driver)

    • Sources:
      ./nimbus/db/core_db/backend/aristo_*

    • Synopsis:
      Combines both, the Kvt and the Aristo driver sub-modules providing an interface similar to the legacy DB (concentrator) module.

  • Aristo MPT (driver)

    • Sources:
      ./nimbus/db/aristo*

    • Synopsis:
      Revamped implementation of a hexary Merkle Patricia Tree.

  • Common (concentrator)

    • Sources:
      ./nimbus/common*

    • Synopsis:
      Collected information for running block chain execution layer applications.

  • Core DB (API)

    • Sources:
      ./nimbus/db/core_db*

    • Synopsis:
      Database abstraction layer. Unless for legacy applications, there should be no need to reach out to the layers below.

  • EVM (application)

    • Sources:
      ./nimbus/core/executor/* ./nimbus/evm/*

    • Synopsis:
      An implementation of the Ethereum Virtual Machine.

  • Hexary DB (driver)

  • Key-value table (driver)

    • Sources:
      ./vendor/nim-eth/eth/trie/db.nim

    • Synopsis:
      Key value table interface to be used directly for key-value storage or by the Hexary DB (driver) module for storage. Some magic is applied in order to treat hexary data accordingly (based on key length.)

  • Kvt (driver)

  • Ledger (API)

  • ledger cache (driver)

    • Sources:
      ./nimbus/db/ledger/accounts_ledger.nim
      ./nimbus/db/ledger/backend/accounts_ledger*
      ./nimbus/db/ledger/distinct_ledgers.nim

    • Synopsis:
      Management of accounts and storage data. This is a re-write of the legacy DB (driver) which is supposed to work with all Core DB (API) backends.

  • legacy DB (concentrator)

  • Rocks DB (engine)

    • Sources:
      ./vendor/nim-rocksdb/*

    • Synopsis:
      Persistent storage engine.

  • State DB (concentrator)

    • Sources:
      ./nimbus/evm/state.nim
      ./nimbus/evm/types.nim

    • Synopsis:
      Integrated collection of modules and methods relevant for the EVM.