| 
 | 1 | +// Copyright 2024 the libevm authors.  | 
 | 2 | +//  | 
 | 3 | +// The libevm additions to go-ethereum are free software: you can redistribute  | 
 | 4 | +// them and/or modify them under the terms of the GNU Lesser General Public License  | 
 | 5 | +// as published by the Free Software Foundation, either version 3 of the License,  | 
 | 6 | +// or (at your option) any later version.  | 
 | 7 | +//  | 
 | 8 | +// The libevm additions are distributed in the hope that they will be useful,  | 
 | 9 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
 | 10 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser  | 
 | 11 | +// General Public License for more details.  | 
 | 12 | +//  | 
 | 13 | +// You should have received a copy of the GNU Lesser General Public License  | 
 | 14 | +// along with the go-ethereum library. If not, see  | 
 | 15 | +// <http://www.gnu.org/licenses/>.  | 
 | 16 | + | 
 | 17 | +package state  | 
 | 18 | + | 
 | 19 | +import (  | 
 | 20 | +	"reflect"  | 
 | 21 | + | 
 | 22 | +	"github.com/ava-labs/libevm/common"  | 
 | 23 | +	"github.com/ava-labs/libevm/core/state/snapshot"  | 
 | 24 | +)  | 
 | 25 | + | 
 | 26 | +// SnapshotTree mirrors the functionality of a [snapshot.Tree], allowing for  | 
 | 27 | +// drop-in replacements.  | 
 | 28 | +type SnapshotTree interface {  | 
 | 29 | +	Cap(common.Hash, int) error  | 
 | 30 | +	Snapshot(common.Hash) snapshot.Snapshot  | 
 | 31 | +	StorageIterator(root, account, seek common.Hash) (snapshot.StorageIterator, error)  | 
 | 32 | +	Update(  | 
 | 33 | +		blockRoot common.Hash,  | 
 | 34 | +		parentRoot common.Hash,  | 
 | 35 | +		destructs map[common.Hash]struct{},  | 
 | 36 | +		accounts map[common.Hash][]byte,  | 
 | 37 | +		storage map[common.Hash]map[common.Hash][]byte,  | 
 | 38 | +	) error  | 
 | 39 | +}  | 
 | 40 | + | 
 | 41 | +var _ SnapshotTree = (*snapshot.Tree)(nil)  | 
 | 42 | + | 
 | 43 | +// clearTypedNilPointer returns nil if `snaps == nil` or if it holds a nil  | 
 | 44 | +// pointer. The default geth behaviour expected a [snapshot.Tree] pointer  | 
 | 45 | +// instead of a SnapshotTree interface, which could result in typed-nil bugs.  | 
 | 46 | +func clearTypedNilPointer(snaps SnapshotTree) SnapshotTree {  | 
 | 47 | +	if v := reflect.ValueOf(snaps); v.Kind() == reflect.Pointer && v.IsNil() {  | 
 | 48 | +		return nil  | 
 | 49 | +	}  | 
 | 50 | +	return snaps  | 
 | 51 | +}  | 
0 commit comments