MCPcopy Index your code
hub / github.com/Zacholme7/NodeDB

github.com/Zacholme7/NodeDB @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
52 symbols 113 edges 9 files 11 documented · 21%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

NodeDB

NodeDB is a revm DB implementation that hooks directly into the reth database and operates on the latest canonical state. The advantages of this are very obvious. Fetching from the db is very fast and should be used instead of RPC/IPC when possible.

Current baked in revm DB implementations cache state without fetching from provider (CacheDB), fetch state from provider but dont dont allow you to insert accounts/storage (AlloyDB), or fetch state and cache it which results in old state (CacheDB(AlloyDB)).

Note

If you are running reth 1.2, you must enable immediate block flushing via --engine.persistence-threshold 0 and --engine.memory-block-buffer-target 0

Usage

use node_db::NodeDB;

let nodedb = NodeDB::new("path/to/your/data")?;

//...use as you would any other db

Use Case/Inspiration

I have a custom quoter contract for my arbitrage bot which I use for simulations. I needed a DB that would allow me to insert the contract code and other state information while also being able to operate on the most up to date chain state for proper quotes. NodeDB allows me to insert and execute against arbitraty contract code while also being able to insert storage data for things such as token balances, approvals, etc.

Problems

We have no way to know before hand if an account/storage has been updated. The only way is to fetch the account when it is needed and then compare it to the cached value. If we are fetching, we might as well just insert it anyways. On the other hand, we know that custom contracts/accounts that we have inserted will only be modifed within the evm instance as it has no chain state.

You could implement functionality to pass in list of updated accounts that can be marked as out of date, or you could modify the update_provider function to process blocks and determine touched state.

This is not the prettiest implementation and im sure there are uncaught edge cases, but it works for what I need to accomplish. Please fork/submit pull req if you you make any positive upgrades!

Extension points exported contracts — how you extend this code

NodeDBBackendSync (Interface)
Synchronous backend trait [1 implementers]
src/lib.rs
NodeDBBackendAsync (Interface)
(no doc) [1 implementers]
src/lib.rs
NodeDBStorageSync (Interface)
(no doc) [1 implementers]
src/lib.rs
NodeDBStorageAsync (Interface)
(no doc) [1 implementers]
src/lib.rs

Core symbols most depended-on inside this repo

update_provider
called by 8
src/lib.rs
block_on
called by 8
src/lib.rs
insert_account_info
called by 5
src/lib.rs
insert_account_storage
called by 5
src/lib.rs
basic_account
called by 4
src/lib.rs
account_code
called by 4
src/lib.rs
storage
called by 3
src/lib.rs
block_hash
called by 2
src/lib.rs

Shape

Method 31
Function 9
Class 6
Interface 4
Enum 2

Languages

Rust100%

Modules by API surface

src/lib.rs43 symbols
example/get_balance_slot.rs2 symbols
example/swap_async.rs1 symbols
example/swap.rs1 symbols
example/quote.rs1 symbols
example/custom_slot.rs1 symbols
example/custom_account.rs1 symbols
example/approval_async.rs1 symbols
example/approval.rs1 symbols

For agents

$ claude mcp add NodeDB \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact