mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-30 18:27:36 +00:00
## Why this should be merged Coreth and Subnet-EVM require access to the current tx hash in the Warp precompile (for selecting the correct predicate results). This can not be exposed as a wrapper through the `OverrideEVMResetArgs` because `SetTxContext` is called _prior_ to resetting the EVM instance. Therefore, the `SetTxContext` function on any DB wrapper would never be called. ## How this works Exposes the existing `txHash` through a `TxHash()` function. ## How this was tested Added a trivial unit test.
59 lines
2.1 KiB
Go
59 lines
2.1 KiB
Go
// Copyright 2024 the libevm authors.
|
|
//
|
|
// The libevm additions to go-ethereum are free software: you can redistribute
|
|
// them and/or modify them under the terms of the GNU Lesser General Public License
|
|
// as published by the Free Software Foundation, either version 3 of the License,
|
|
// or (at your option) any later version.
|
|
//
|
|
// The libevm additions are distributed in the hope that they will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
|
|
// General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
package state
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
"github.com/ava-labs/libevm/common"
|
|
"github.com/ava-labs/libevm/core/state/snapshot"
|
|
"github.com/ava-labs/libevm/libevm/stateconf"
|
|
)
|
|
|
|
// TxHash returns the current transaction hash set by [StateDB.SetTxContext].
|
|
func (s *StateDB) TxHash() common.Hash {
|
|
return s.thash
|
|
}
|
|
|
|
// SnapshotTree mirrors the functionality of a [snapshot.Tree], allowing for
|
|
// drop-in replacements. This is intended as a temporary feature as a workaround
|
|
// until a standard Tree can be used.
|
|
type SnapshotTree interface {
|
|
Cap(common.Hash, int) error
|
|
Snapshot(common.Hash) snapshot.Snapshot
|
|
StorageIterator(root, account, seek common.Hash) (snapshot.StorageIterator, error)
|
|
Update(
|
|
blockRoot common.Hash,
|
|
parentRoot common.Hash,
|
|
destructs map[common.Hash]struct{},
|
|
accounts map[common.Hash][]byte,
|
|
storage map[common.Hash]map[common.Hash][]byte,
|
|
opts ...stateconf.SnapshotUpdateOption,
|
|
) error
|
|
}
|
|
|
|
var _ SnapshotTree = (*snapshot.Tree)(nil)
|
|
|
|
// clearTypedNilPointer returns nil if `snaps == nil` or if it holds a nil
|
|
// pointer. The default geth behaviour expected a [snapshot.Tree] pointer
|
|
// instead of a SnapshotTree interface, which could result in typed-nil bugs.
|
|
func clearTypedNilPointer(snaps SnapshotTree) SnapshotTree {
|
|
if v := reflect.ValueOf(snaps); v.Kind() == reflect.Pointer && v.IsNil() {
|
|
return nil
|
|
}
|
|
return snaps
|
|
}
|