-
Notifications
You must be signed in to change notification settings - Fork 522
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
Document Mina daemon's databases #15767
Comments
This document is needed to analyze usage of RocksDB in block production/processing. Major focus should be on frontier and ledger-related DBs. |
AFAIU all DBs we have are key-value storages. And we probably have more than one key-value space within some of these DBs, let's have one "key-value space" per row in a resuting table. To start with the task I suggest one launching a Mina node that connects to mainnet. And then checking what you have in .mina-config. What I see on a mainnet's node:
|
|
let snarked_ledger root = Filename.concat root "snarked_ledger" |
This path is given to
Ledger.Db
where Ledger
is Mina_ledger.Ledger
.So the
snarked_ledger
Db type gets defined here:mina/src/lib/mina_ledger/ledger.ml
Lines 108 to 120 in 4495af5
module Db : | |
Merkle_ledger.Intf.Ledger.DATABASE | |
with module Location = Location_at_depth | |
with module Addr = Location_at_depth.Addr | |
with type root_hash := Ledger_hash.t | |
and type hash := Ledger_hash.t | |
and type key := Public_key.Compressed.t | |
and type token_id := Token_id.t | |
and type token_id_set := Token_id.Set.t | |
and type account := Account.t | |
and type account_id_set := Account_id.Set.t | |
and type account_id := Account_id.t = | |
Database.Make (Inputs) |
which calls this functor:
module Make (Inputs : Intf.Inputs.DATABASE) = struct |
On this module:
mina/src/lib/mina_ledger/ledger.ml
Lines 89 to 106 in 4495af5
module Inputs = struct | |
module Key = Public_key.Compressed | |
module Token_id = Token_id | |
module Account_id = Account_id | |
module Balance = struct | |
include Currency.Balance | |
let to_int = to_nanomina_int | |
end | |
module Account = Account.Stable.Latest | |
module Hash = Hash.Stable.Latest | |
module Kvdb = Kvdb | |
module Location = Location_at_depth | |
module Location_binable = Location_binable | |
module Storage_locations = Storage_locations | |
end |
The Kvbd.t
type it takes seems to be a generic database type with Bigstring.t
for both key and value.
But from calls to Kvdb
like this:
mina/src/lib/merkle_ledger/database.ml
Lines 101 to 102 in 4495af5
let get_raw { kvdb; depth; _ } location = | |
Kvdb.get kvdb ~key:(Location.serialize ~ledger_depth:depth location) |
It looks like the keys represent serialized
Location.t
s which I think is this enum:mina/src/lib/merkle_ledger/location.ml
Lines 54 to 55 in 4495af5
type t = Generic of Bigstring.t | Account of Addr.t | Hash of Addr.t | |
[@@deriving hash, sexp, compare] |
and the value appears to be the Toeken_id.Set.t
type from the inputs.
I'm not sure where Token_id
comes from, there are a few opens at the top of the file.
The root/root
location is defined here and seems to store a hash of the genesis state.
|
module Peer_id = struct | |
type t = int [@@deriving sexp, yojson] | |
let ip t = Unix.Inet_addr.of_string (sprintf "127.0.0.%d" t) | |
end |
and the value Record.t
which I beleive reffers to this
mina/src/lib/trust_system/record.ml
Lines 5 to 12 in 10a0bf9
module V1 = struct | |
type t = | |
{ trust : float | |
; trust_last_updated : Core.Time.Stable.V1.t | |
; banned_until_opt : Core.Time.Stable.V1.t option | |
} | |
let to_latest = Fn.id |
|
module Rocks = Rocksdb.Serializable.GADT.Make (Schema) |
calls this functor:
mina/src/lib/rocksdb/serializable.ml
Line 53 in 4495af5
module Make (Key : Intf.Key.S) : Intf.Database.S with type 'a g := 'a Key.t = |
With this argument:
module Schema = struct |
I think that results in the key type being this private Enum:
mina/src/lib/transition_frontier/persistent_frontier/database.ml
Lines 49 to 56 in 4495af5
type _ t = | |
| Db_version : int t | |
| Transition : State_hash.Stable.V1.t -> Mina_block.Stable.V2.t t | |
| Arcs : State_hash.Stable.V1.t -> State_hash.Stable.V1.t list t | |
| Root : Root_data.Minimal.Stable.V2.t t | |
| Best_tip : State_hash.Stable.V1.t t | |
| Protocol_states_for_root_scan_state | |
: Mina_state.Protocol_state.Value.Stable.V2.t list t |
Here Root_data.Minimal.Stable.V2
refers to this type:
type t = { hash : State_hash.Stable.V1.t; common : Common.Stable.V2.t } |
and I think this defines a type family like thing for what the value types is depending on the key:
mina/src/lib/transition_frontier/persistent_frontier/database.ml
Lines 74 to 86 in 4495af5
let binable_data_type (type a) : a t -> a Bin_prot.Type_class.t = function | |
| Db_version -> | |
[%bin_type_class: int] | |
| Transition _ -> | |
[%bin_type_class: Mina_block.Stable.Latest.t] | |
| Arcs _ -> | |
[%bin_type_class: State_hash.Stable.Latest.t list] | |
| Root -> | |
[%bin_type_class: Root_data.Minimal.Stable.Latest.t] | |
| Best_tip -> | |
[%bin_type_class: State_hash.Stable.Latest.t] | |
| Protocol_states_for_root_scan_state -> | |
[%bin_type_class: Mina_state.Protocol_state.Value.Stable.Latest.t list] |
Produce a document describing what are databases that Daemon uses.
Result of this task is expected to be a table of databases and descriptions.
Table's rows, I imagine, would be:
Relates to #13971
The text was updated successfully, but these errors were encountered: