Skip to content

store: TrieAccountingCache is pretty iffy part of our codebase #13008

Open
@nagisa

Description

@nagisa

TrieAccountingCache (hereon TAC) is pretty iffy part of our codebase.

First, it is currently mostly unused for the purpose of caching, but rather is chiefly a tool for discriminating first and subsequent store accesses from contracts for the purposes of charging different amounts of gas. Since the accesses now always go to the memtrie, it is up for debate if these fees have any reason to be any different at all, since all accesses now cost the same. But at the same time we can't exactly get rid of TAC as it is necessary for support of older protocol versions (replayability.)

There is point to be made to replace TAC with just a mechanism that tracks whether access to a key happens for the first time or not, and just maintain the access type counters. In making this change the cache would stop storing the values and only store the keys that have been accessed.

Second, the current enable_switch mechanism that's part of TAC (and relatedly the Trie::charge_gas_for_trie_node_access field) is super iffy especially as we look towards sharing this type across multiple threads. #12981 made the switch somewhat more palatable by making the switch track state on a thread-local basis, but ideally each access should be passing an argument to describe whether an access should increment the TAC counters (mostly enabled just from the context in which contract execution occurs,) whether an access should incur a side effect of recording it to state witness (subsuming get_no_side_effect), etc. Passing an argument describing the effects makes the whole store concept much more friendly to it being used in a multi-threaded context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions