Documentation
¶
Index ¶
- Variables
- type AccountTrie
- func (a *AccountTrie) Commit(bool) (common.Hash, *trienode.NodeSet, error)
- func (a *AccountTrie) Copy() *AccountTrie
- func (a *AccountTrie) DeleteAccount(addr common.Address) error
- func (a *AccountTrie) DeleteStorage(addr common.Address, key []byte) error
- func (a *AccountTrie) GetAccount(addr common.Address) (*types.StateAccount, error)
- func (*AccountTrie) GetKey([]byte) []byte
- func (a *AccountTrie) GetStorage(addr common.Address, key []byte) ([]byte, error)
- func (a *AccountTrie) Hash() common.Hash
- func (*AccountTrie) NodeIterator([]byte) (trie.NodeIterator, error)
- func (*AccountTrie) Prove([]byte, ethdb.KeyValueWriter) error
- func (a *AccountTrie) UpdateAccount(addr common.Address, account *types.StateAccount) error
- func (*AccountTrie) UpdateContractCode(_ common.Address, _ common.Hash, _ []byte) error
- func (a *AccountTrie) UpdateStorage(addr common.Address, key []byte, value []byte) error
- type Config
- type Database
- func (*Database) Cap(common.StorageSize) error
- func (db *Database) Close() error
- func (db *Database) Commit(root common.Hash, report bool) (err error)
- func (*Database) Dereference(common.Hash)
- func (db *Database) Initialized(common.Hash) bool
- func (db *Database) Reader(root common.Hash) (database.Reader, error)
- func (*Database) Reference(common.Hash, common.Hash)
- func (*Database) Scheme() string
- func (*Database) Size() (common.StorageSize, common.StorageSize)
- func (db *Database) Update(root common.Hash, parentRoot common.Hash, block uint64, ...) error
- type ProposalContext
- type StorageTrie
Constants ¶
This section is empty.
Variables ¶
var Defaults = Config{ CleanCacheSize: 1024 * 1024, FreeListCacheEntries: 40_000, Revisions: 100, ReadCacheStrategy: ffi.CacheAllReads, }
Note that `FilePath` is not specified, and must always be set by the user.
Functions ¶
This section is empty.
Types ¶
type AccountTrie ¶
type AccountTrie struct {
// contains filtered or unexported fields
}
AccountTrie implements state.Trie for managing account states. There are a couple caveats to the current implementation:
- `Commit` is not used as expected in the state package. The `StorageTrie` doesn't return values, and we thus rely on the `AccountTrie`.
- The `Hash` method actually creates the proposal, since Firewood cannot calculate the hash of the trie without committing it. It is immediately dropped, and this can likely be optimized.
Note this is not concurrent safe.
func NewAccountTrie ¶
func NewAccountTrie(root common.Hash, db *Database) (*AccountTrie, error)
func (*AccountTrie) Commit ¶
Commit returns the new root hash of the trie and a NodeSet containing all modified accounts and storage slots. The format of the NodeSet is different than in go-ethereum's trie implementation due to Firewood's design. This boolean is ignored, as it is a relic of the StateTrie implementation.
func (*AccountTrie) Copy ¶
func (a *AccountTrie) Copy() *AccountTrie
func (*AccountTrie) DeleteAccount ¶
func (a *AccountTrie) DeleteAccount(addr common.Address) error
DeleteAccount removes the state account associated with an address.
func (*AccountTrie) DeleteStorage ¶
func (a *AccountTrie) DeleteStorage(addr common.Address, key []byte) error
DeleteStorage removes the value associated with a storage key for a given account address.
func (*AccountTrie) GetAccount ¶
func (a *AccountTrie) GetAccount(addr common.Address) (*types.StateAccount, error)
GetAccount returns the state account associated with an address. - If the account has been updated, the new value is returned. - If the account has been deleted, (nil, nil) is returned. - If the account does not exist, (nil, nil) is returned.
func (*AccountTrie) GetKey ¶
func (*AccountTrie) GetKey([]byte) []byte
GetKey implements state.Trie. This should not be used, since any user should not be accessing by raw key.
func (*AccountTrie) GetStorage ¶
GetStorage returns the value associated with a storage key for a given account address. - If the storage slot has been updated, the new value is returned. - If the storage slot has been deleted, (nil, nil) is returned. - If the storage slot does not exist, (nil, nil) is returned.
func (*AccountTrie) Hash ¶
func (a *AccountTrie) Hash() common.Hash
Hash returns the current hash of the state trie. This will create a proposal and drop it, so it is not efficient to call for each transaction. If there are no changes since the last call, the cached root is returned.
func (*AccountTrie) NodeIterator ¶
func (*AccountTrie) NodeIterator([]byte) (trie.NodeIterator, error)
NodeIterator implements state.Trie. Firewood does not support iterating over internal nodes.
func (*AccountTrie) Prove ¶
func (*AccountTrie) Prove([]byte, ethdb.KeyValueWriter) error
Prove implements state.Trie. Firewood does not yet support providing key proofs.
func (*AccountTrie) UpdateAccount ¶
func (a *AccountTrie) UpdateAccount(addr common.Address, account *types.StateAccount) error
UpdateAccount replaces or creates the state account associated with an address. This new value will be returned for subsequent `GetAccount` calls.
func (*AccountTrie) UpdateContractCode ¶
UpdateContractCode implements state.Trie. Contract code is controlled by rawdb, so we don't need to do anything here.
func (*AccountTrie) UpdateStorage ¶
UpdateStorage replaces or creates the value associated with a storage key for a given account address. This new value will be returned for subsequent `GetStorage` calls.
type Config ¶
type Config struct {
FilePath string
CleanCacheSize int // Size of the clean cache in bytes
FreeListCacheEntries uint // Number of free list entries to cache
Revisions uint
ReadCacheStrategy ffi.CacheStrategy
}
func (Config) BackendConstructor ¶
func (c Config) BackendConstructor(ethdb.Database) triedb.DBOverride
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
func New ¶
New creates a new Firewood database with the given disk database and configuration. Any error during creation will cause the program to exit.
func (*Database) Cap ¶
func (*Database) Cap(common.StorageSize) error
Firewood does not support this.
func (*Database) Commit ¶
Commit persists a proposal as a revision to the database.
Any time this is called, we expect either:
- The root is the same as the current root of the database (empty block during bootstrapping)
- We have created a valid propsal with that root, and it is of height +1 above the proposal tree root. Additionally, this should be unique.
Afterward, we know that no other proposal at this height can be committed, so we can dereference all children in the the other branches of the proposal tree.
func (*Database) Dereference ¶
Dereference drops a proposal from the database. This function is no-op because unused proposals are dereferenced when no longer valid. We cannot dereference at this call. Consider the following case: Chain 1 has root A and root C Chain 2 has root B and root C We commit root A, and immediately dereference root B and its child. Root C is Rejected, (which is intended to be 2C) but there's now only one record of root C in the proposal map. Thus, we recognize the single root C as the only proposal, and dereference it.
func (*Database) Initialized ¶
Initialized checks whether a non-empty genesis block has been written.
func (*Database) Reader ¶
Reader retrieves a node reader belonging to the given state root. An error will be returned if the requested state is not available.
func (*Database) Scheme ¶
Scheme returns the scheme of the database. This is only used in some API calls and in StateDB to avoid iterating through deleted storage tries. WARNING: If cherry-picking anything from upstream that uses this, it must be overwritten to use something like: `_, ok := db.(*Database); if !ok { return "" }` to recognize the Firewood database.
func (*Database) Size ¶
func (*Database) Size() (common.StorageSize, common.StorageSize)
Size returns the storage size of diff layer nodes above the persistent disk layer and the dirty nodes buffered within the disk layer Only used for metrics and Commit intervals in APIs. This will be implemented in the firewood database eventually. Currently, Firewood stores all revisions in disk and proposals in memory.
func (*Database) Update ¶
func (db *Database) Update(root common.Hash, parentRoot common.Hash, block uint64, nodes *trienode.MergedNodeSet, _ *triestate.Set, opts ...stateconf.TrieDBUpdateOption) error
Update takes a root and a set of keys-values and creates a new proposal. It will not be committed until the Commit method is called. This function should be called even if there are no changes to the state to ensure proper tracking of block hashes.
type ProposalContext ¶
type ProposalContext struct {
Proposal *ffi.Proposal
Hashes map[common.Hash]struct{} // All corresponding block hashes
Root common.Hash
Block uint64
Parent *ProposalContext
Children []*ProposalContext
}
ProposalContext represents a proposal in the Firewood database. This tracks all outstanding proposals to allow dereferencing upon commit.
type StorageTrie ¶
type StorageTrie struct {
*AccountTrie
}
func NewStorageTrie ¶
func NewStorageTrie(accountTrie *AccountTrie) (*StorageTrie, error)
`NewStorageTrie` returns a wrapper around an `AccountTrie` since Firewood does not require a separate storage trie. All changes are managed by the account trie.
func (*StorageTrie) Commit ¶
Actual commit is handled by the account trie. Return the old storage root as if there was no change since Firewood will manage the hash calculations without it. All changes are managed by the account trie.
func (*StorageTrie) Copy ¶
func (*StorageTrie) Copy() *StorageTrie
Copy should never be called on a storage trie, as it is just a wrapper around the account trie. Each storage trie should be re-opened with the account trie separately.
func (*StorageTrie) Hash ¶
func (*StorageTrie) Hash() common.Hash
Firewood doesn't require tracking storage roots inside of an account. They will be updated in place when hashing of the proposal takes place.