go-ethereum/core/state
Arran Schlosberg 1bccf4f2dd
refactor!: temporary extras require proof of global lock (#238)
## Why this should be merged

The `temporary.WithTempRegisteredExtras()` global lock introduced in
#234 wasn't fit for purpose when used in `coreth` as it required central
coordination of registration, types, and usage of the payload accessor.

## How this works

Instead of a central registration point, the new
`libevm.WithTemporaryExtrasLock()` function takes out a global lock and
provides the caller with a handle that proves the lock is held. All of
the override functions, e.g. `params.WithTempRegisteredExtras()` now
require a current lock, which will be propagated by the respective
`coreth` functions.

See https://github.com/ava-labs/coreth/pull/1328 for intended usage in
`coreth` and `subnet-evm`. A consumer of both of these can then safely
do the following:

```go
import (
    "github.com/ava-labs/libevm/libevm"

    coreth "github.com/ava-labs/coreth/plugin/evm"
    subnet "github.com/ava-labs/subnet-evm/plugin/evm"
)

// asCChain calls `fn` while emulating `coreth`. It is safe for concurrent usage with [asSubnetEVM].
func asCChain(fn func() error) error {
    return libevm.WithTemporaryExtrasLock(func(l libevm.ExtrasLock) error {
        return coreth.WithTempRegisteredLibEVMExtras(l, fn)
    })
}

// asSubnetEVM calls `fn` while emulating `subnet-evm`. It is safe for concurrent usage with [asCChain].
func asSubnetEVM(fn func() error) error {
    return libevm.WithTemporaryExtrasLock(func(l libevm.ExtrasLock) error {
        return subnet.WithTempRegisteredLibEVMExtras(l, fn)
    })
}
```

## How this was tested

Unit test of the new function plus existing integration tests of all
modified code.
2025-10-16 14:27:15 +00:00
..
pruner [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
snapshot core/state/snapshot: add a missing lock (#30001) 2025-06-10 15:08:40 +01:00
access_list.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
database.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
dump.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
iterator.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
iterator_test.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
journal.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
metrics.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
state.libevm.go feat: types.HeaderHooks for RLP overrides (#89) 2024-12-17 13:54:58 +00:00
state.libevm_test.go chore: placate goheader (#195) 2025-06-23 15:25:18 +00:00
state_object.go fix: state.stateObject.empty() with extra payload (#62) 2024-10-28 11:34:19 -07:00
state_object.libevm_test.go chore: placate goheader (#195) 2025-06-23 15:25:18 +00:00
state_object_test.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
state_test.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
statedb.go feat: state-key transformation w/ override (#205) 2025-07-22 13:08:53 -04:00
statedb.libevm.go refactor!: temporary extras require proof of global lock (#238) 2025-10-16 14:27:15 +00:00
statedb.libevm_test.go refactor!: temporary extras require proof of global lock (#238) 2025-10-16 14:27:15 +00:00
statedb_fuzz_test.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
statedb_test.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
sync.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
sync_test.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
transient_storage.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
trie_prefetcher.go feat(core/state): async trie prefetching (#76) 2024-11-26 08:01:47 -08:00
trie_prefetcher.libevm.go feat(core/state): async trie prefetching (#76) 2024-11-26 08:01:47 -08:00
trie_prefetcher.libevm_test.go feat(core/state): async trie prefetching (#76) 2024-11-26 08:01:47 -08:00
trie_prefetcher_test.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00