github.com/ethereum/go-ethereum@v1.16.1/triedb/states.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 triedb 18 19 import ( 20 "github.com/ethereum/go-ethereum/common" 21 "github.com/ethereum/go-ethereum/triedb/pathdb" 22 ) 23 24 // StateSet represents a collection of mutated states during a state transition. 25 type StateSet struct { 26 Accounts map[common.Hash][]byte // Mutated accounts in 'slim RLP' encoding 27 AccountsOrigin map[common.Address][]byte // Original values of mutated accounts in 'slim RLP' encoding 28 Storages map[common.Hash]map[common.Hash][]byte // Mutated storage slots in 'prefix-zero-trimmed' RLP format 29 StoragesOrigin map[common.Address]map[common.Hash][]byte // Original values of mutated storage slots in 'prefix-zero-trimmed' RLP format 30 RawStorageKey bool // Flag whether the storage set uses the raw slot key or the hash 31 } 32 33 // NewStateSet initializes an empty state set. 34 func NewStateSet() *StateSet { 35 return &StateSet{ 36 Accounts: make(map[common.Hash][]byte), 37 AccountsOrigin: make(map[common.Address][]byte), 38 Storages: make(map[common.Hash]map[common.Hash][]byte), 39 StoragesOrigin: make(map[common.Address]map[common.Hash][]byte), 40 } 41 } 42 43 // internal returns a state set for path database internal usage. 44 func (set *StateSet) internal() *pathdb.StateSetWithOrigin { 45 // the nil state set is possible in tests. 46 if set == nil { 47 return nil 48 } 49 return pathdb.NewStateSetWithOrigin(set.Accounts, set.Storages, set.AccountsOrigin, set.StoragesOrigin, set.RawStorageKey) 50 }