Module Evm_node_lib_dev.Durable_storage

Typed access layer for the EVM node durable storage.

All durable storage access MUST go through this module. The path GADT ensures type-safe read/write/delete operations. Raw_path is provided as an escape hatch for paths not yet modeled in the GADT. New code should add typed constructors instead of using Raw_path.

module EVM_account_info : sig ... end

Decoded form of the /evm/world_state/accounts/<addr>/info record: balance, nonce, and code hash for an EVM account.

Typed path GADT

A path carries two phantom parameters: the decoded value type 'a and a capability row 'cap made of the polymorphic-variant tags `Read and `Write. The aliases rw (read+write) and ro (read-only) name the two closed rows. Raw_path is the escape hatch that decodes to raw bytes; new code should add typed constructors with the precise capability row instead.

type rw = [
  1. | `Read
  2. | `Write
  3. | `Delete
]

Phantom capability markers for path: rw is read+write+delete, ro is read-only.

type ro = [
  1. | `Read
]
type read_delete = [
  1. | `Read
  2. | `Delete
]
type ('a, 'cap) path =
  1. | Raw_path : string -> (bytes, rw) path
  2. | Chain_id : (Evm_node_lib_dev_encoding.L2_types.chain_id, ro) path
  3. | Michelson_runtime_chain_id : (Evm_node_lib_dev_encoding.L2_types.chain_id, ro) path
  4. | Kernel_version : (string, ro) path
  5. | Kernel_root_hash : (Evm_node_lib_dev_encoding.Ethereum_types.hex, ro) path
  6. | Multichain_flag : (unit, ro) path
  7. | Sequencer_key : (Tezos_base.TzPervasives.Signature.Public_key.t, ro) path
  8. | Chain_config_family : Evm_node_lib_dev_encoding.L2_types.chain_id -> (Evm_node_lib_dev_encoding.L2_types.ex_chain_family, ro) path
  9. | Tezosx_feature_flag : Tezosx.runtime -> (unit, ro) path
  10. | Michelson_runtime_sunrise_level : (Evm_node_lib_dev_encoding.Ethereum_types.quantity, ro) path
  11. | Current_block_number : _ Evm_node_lib_dev_encoding.L2_types.chain_family -> (Evm_node_lib_dev_encoding.Ethereum_types.quantity, ro) path
  12. | Current_block_hash : _ Evm_node_lib_dev_encoding.L2_types.chain_family -> (Evm_node_lib_dev_encoding.Ethereum_types.block_hash, ro) path
  13. | Evm_node_flag : (unit, rw) path
  14. | Blueprint_chunk : {
    1. blueprint_number : Z.t;
    2. chunk_index : int;
    } -> (bytes, rw) path
  15. | Blueprint_nb_chunks : Z.t -> (int, rw) path
  16. | Blueprint_generation : Z.t -> (Evm_node_lib_dev_encoding.Ethereum_types.quantity, rw) path
  17. | Single_tx_input : (Evm_node_lib_dev_encoding.Rlp.item, rw) path
  18. | Assemble_block_input : (Evm_node_lib_dev_encoding.Rlp.item, rw) path
  19. | Current_block : _ Evm_node_lib_dev_encoding.L2_types.chain_family -> (Evm_node_lib_dev_encoding.Ethereum_types.legacy_transaction_object Evm_node_lib_dev_encoding.L2_types.block, ro) path
  20. | Block_by_hash : _ Evm_node_lib_dev_encoding.L2_types.chain_family * Evm_node_lib_dev_encoding.Ethereum_types.block_hash -> (Evm_node_lib_dev_encoding.Ethereum_types.legacy_transaction_object Evm_node_lib_dev_encoding.L2_types.block, read_delete) path
  21. | Block_index : _ Evm_node_lib_dev_encoding.L2_types.chain_family * Durable_storage_path.Block.number -> (unit, [ `Delete ]) path
  22. | Tezosx_tezos_current_block : (Evm_node_lib_dev_encoding.Ethereum_types.legacy_transaction_object Evm_node_lib_dev_encoding.L2_types.block, ro) path
  23. | Current_receipts : (Evm_node_lib_dev_encoding.Transaction_receipt.t, ro) path
  24. | Backlog : (int64, ro) path
  25. | Minimum_base_fee_per_gas : (Z.t, ro) path
  26. | Da_fee_per_byte : (Evm_node_lib_dev_encoding.Ethereum_types.quantity, ro) path
  27. | Maximum_gas_per_transaction : (Evm_node_lib_dev_encoding.Ethereum_types.quantity, ro) path
  28. | Michelson_to_evm_gas_multiplier : (int64, ro) path
  29. | Sequencer_pool_address : (Evm_node_lib_dev_encoding.Ethereum_types.address, ro) path
  30. | Evm_legacy_account_balance : Evm_node_lib_dev_encoding.Ethereum_types.address -> (Evm_node_lib_dev_encoding.Ethereum_types.quantity, rw) path
  31. | Evm_legacy_account_nonce : Evm_node_lib_dev_encoding.Ethereum_types.address -> (Evm_node_lib_dev_encoding.Ethereum_types.quantity, rw) path
  32. | Evm_legacy_account_code : Evm_node_lib_dev_encoding.Ethereum_types.address -> (Evm_node_lib_dev_encoding.Ethereum_types.hex, rw) path
  33. | Evm_legacy_account_code_hash : Evm_node_lib_dev_encoding.Ethereum_types.address -> (Evm_node_lib_dev_encoding.Ethereum_types.hash, ro) path
  34. | Evm_legacy_block_by_hash : Evm_node_lib_dev_encoding.Ethereum_types.block_hash -> (Evm_node_lib_dev_encoding.Ethereum_types.legacy_transaction_object Evm_node_lib_dev_encoding.Ethereum_types.block, ro) path
  35. | Evm_legacy_current_block : (Evm_node_lib_dev_encoding.Ethereum_types.legacy_transaction_object Evm_node_lib_dev_encoding.Ethereum_types.block, ro) path
  36. | Evm_code_by_hash : Evm_node_lib_dev_encoding.Ethereum_types.hash -> (Evm_node_lib_dev_encoding.Ethereum_types.hex, rw) path
  37. | Evm_account_storage : Durable_storage_path.Accounts.fixed_address * Durable_storage_path.Accounts.fixed_index -> (Evm_node_lib_dev_encoding.Ethereum_types.hex, rw) path
  38. | Evm_account_info : Evm_node_lib_dev_encoding.Ethereum_types.address -> (EVM_account_info.t, rw) path
  39. | Tezos_account_info : Tezosx.Tezos_runtime.address -> (Tezosx.Tezos_runtime.account_info, ro) path
  40. | Evm_block_hash_by_number : Durable_storage_path.Block.number -> (Evm_node_lib_dev_encoding.Ethereum_types.block_hash, ro) path
  41. | Evm_transaction_receipt_by_hash : Evm_node_lib_dev_encoding.Ethereum_types.hash * Evm_node_lib_dev_encoding.Ethereum_types.block_hash -> (Evm_node_lib_dev_encoding.Transaction_receipt.t, ro) path
  42. | Evm_transaction_object_by_hash : Evm_node_lib_dev_encoding.Ethereum_types.hash * Evm_node_lib_dev_encoding.Ethereum_types.block_hash option -> (Evm_node_lib_dev_encoding.Ethereum_types.legacy_transaction_object, ro) path
  43. | Evm_current_block_receipts : Evm_node_lib_dev_encoding.Ethereum_types.block_hash -> (Evm_node_lib_dev_encoding.Transaction_receipt.t list, ro) path
  44. | Evm_current_block_transactions_objects : Evm_node_lib_dev_encoding.Ethereum_types.block_hash -> (Evm_node_lib_dev_encoding.Ethereum_types.legacy_transaction_object list, ro) path
  45. | Tezos_contract_storage : Evm_node_lib_dev_tezlink.Tezos_types.Contract.t -> (Evm_node_lib_dev_tezlink.Tezlink_imports.Imported_context.Script.expr, ro) path
  46. | Tezos_contract_code : Evm_node_lib_dev_tezlink.Tezos_types.Contract.t -> (Evm_node_lib_dev_tezlink.Tezlink_imports.Imported_context.Script.expr, ro) path
  47. | Tezos_big_map_value : Evm_node_lib_dev_tezlink.Tezlink_imports.Imported_context.Big_map.Id.t * Evm_node_lib_dev_tezlink.Tezlink_imports.Imported_protocol.Script_expr_hash.t -> (Evm_node_lib_dev_tezlink.Tezlink_imports.Imported_context.Script.expr, ro) path
  48. | Tezos_big_map_key_type : Evm_node_lib_dev_tezlink.Tezlink_imports.Imported_context.Big_map.Id.t -> (Evm_node_lib_dev_tezlink.Tezlink_imports.Imported_context.Script.expr, ro) path
  49. | Tezos_big_map_value_type : Evm_node_lib_dev_tezlink.Tezlink_imports.Imported_context.Big_map.Id.t -> (Evm_node_lib_dev_tezlink.Tezlink_imports.Imported_context.Script.expr, ro) path
  50. | Tezos_big_map_total_bytes : Evm_node_lib_dev_tezlink.Tezlink_imports.Imported_context.Big_map.Id.t -> (Z.t, ro) path
  51. | Blueprint_current_generation : (Evm_node_lib_dev_encoding.Ethereum_types.quantity, ro) path
  52. | Kernel_boot_wasm : (bytes, rw) path
  53. | Kernel_verbosity : (string, rw) path

Typed operations

val storage_version : Pvm.State.t -> int Tezos_base.TzPervasives.tzresult Lwt.t

storage_version state reads the kernel storage-version integer from state, or 0 if no version marker is present.

val read : ('a, [> `Read ]) path -> Pvm.State.t -> 'a Tezos_base.TzPervasives.tzresult Lwt.t

read p state decodes the value at path p from state and fails if no value is present.

val read_opt : ('a, [> `Read ]) path -> Pvm.State.t -> 'a option Tezos_base.TzPervasives.tzresult Lwt.t

read_opt p state is Some v when a value is present at p, and None otherwise.

val read_or_default : default:'a -> ('a, [> `Read ]) path -> Pvm.State.t -> 'a Tezos_base.TzPervasives.tzresult Lwt.t

read_or_default ~default p state is the value at p, or default if none is present. Equivalent to Option.value ~default composed with read_opt.

val write : ('a, rw) path -> 'a -> Pvm.State.t -> Pvm.State.t Tezos_base.TzPervasives.tzresult Lwt.t

write p value state encodes value and stores it at p.

val delete : ('a, [> `Delete ]) path -> Pvm.State.t -> Pvm.State.t Tezos_base.TzPervasives.tzresult Lwt.t

delete p state removes the value stored at p.

val exists : ('a, 'cap) path -> Pvm.State.t -> bool Tezos_base.TzPervasives.tzresult Lwt.t

exists p state is true iff a value is stored at the exact leaf path p. For directory checks, use exists_dir on a dir.

val write_all : (('a, rw) path * 'a) list -> Pvm.State.t -> Pvm.State.t Tezos_base.TzPervasives.tzresult Lwt.t

write_all pairs state writes each (path, value) pair in order. The storage version is read at most once across the whole batch — lazily on the first Versioned path. Equivalent to folding write over the list, but without redundant version reads.

list_runtimes state enumerates the TezosX runtimes whose feature flag is set in state.

type dir =
  1. | Raw_dir of string
  2. | Delayed_inbox
  3. | Delayed_transactions
  4. | Evm_events
  5. | Transaction_receipts
  6. | Transaction_objects
  7. | Michelson_runtime_contracts_index
  8. | Michelson_runtime_ledger
  9. | Evm_account_storage_dir of Durable_storage_path.Accounts.fixed_address

Directory paths in the durable storage. Unlike path, a dir does not carry a decoded value type — directory operations work on the subtree as a whole (existence, listing of subkeys, recursive delete). Raw_dir is the escape hatch for paths not yet modeled; new code should add a typed constructor instead.

delete_dir d state recursively removes the subtree rooted at d.

val exists_dir : dir -> Pvm.State.t -> bool Tezos_base.TzPervasives.tzresult Lwt.t

exists_dir d state is true iff the subtree rooted at d is non-empty (i.e. has at least one descendant).

subkeys d state lists the immediate subkeys directly under d.

exception Block_not_found of string

Raised by the legacy block readers when no block is found at the requested path.