github.com/ethereum/go-ethereum@v1.16.1/triedb/database/database.go (about) 1 // Copyright 2024 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package database 18 19 import ( 20 "github.com/ethereum/go-ethereum/common" 21 "github.com/ethereum/go-ethereum/core/types" 22 ) 23 24 // NodeReader wraps the Node method of a backing trie reader. 25 type NodeReader interface { 26 // Node retrieves the trie node blob with the provided trie identifier, 27 // node path and the corresponding node hash. No error will be returned 28 // if the node is not found. 29 // 30 // The returned node content won't be changed after the call. 31 // 32 // Don't modify the returned byte slice since it's not deep-copied and 33 // still be referenced by database. 34 Node(owner common.Hash, path []byte, hash common.Hash) ([]byte, error) 35 } 36 37 // NodeDatabase wraps the methods of a backing trie store. 38 type NodeDatabase interface { 39 // NodeReader returns a node reader associated with the specific state. 40 // An error will be returned if the specified state is not available. 41 NodeReader(stateRoot common.Hash) (NodeReader, error) 42 } 43 44 // StateReader wraps the Account and Storage method of a backing state reader. 45 type StateReader interface { 46 // Account directly retrieves the account associated with a particular hash in 47 // the slim data format. An error will be returned if the read operation exits 48 // abnormally. Specifically, if the layer is already stale. 49 // 50 // Note: 51 // - the returned account object is safe to modify 52 // - no error will be returned if the requested account is not found in database 53 Account(hash common.Hash) (*types.SlimAccount, error) 54 55 // Storage directly retrieves the storage data associated with a particular hash, 56 // within a particular account. An error will be returned if the read operation 57 // exits abnormally. 58 // 59 // Note: 60 // - the returned storage data is not a copy, please don't modify it 61 // - no error will be returned if the requested slot is not found in database 62 Storage(accountHash, storageHash common.Hash) ([]byte, error) 63 } 64 65 // StateDatabase wraps the methods of a backing state store. 66 type StateDatabase interface { 67 // StateReader returns a state reader associated with the specific state. 68 // An error will be returned if the specified state is not available. 69 StateReader(stateRoot common.Hash) (StateReader, error) 70 }