Skip to content

Conversation

@ARR4N
Copy link
Collaborator

@ARR4N ARR4N commented Oct 7, 2025

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 ava-labs/coreth#1328 for intended usage in coreth and subnet-evm. A consumer of both of these can then safely do the following:

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.

@ARR4N ARR4N marked this pull request as ready for review October 7, 2025 15:43
@ARR4N ARR4N requested review from a team and ceyonur October 7, 2025 15:43
@ARR4N ARR4N self-assigned this Oct 8, 2025
Copy link

@ceyonur ceyonur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly questions

Copy link

@ceyonur ceyonur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ARR4N ARR4N enabled auto-merge (squash) October 16, 2025 14:26
@ARR4N ARR4N merged commit 1bccf4f into main Oct 16, 2025
12 checks passed
@ARR4N ARR4N deleted the arr4n/extras-lock-handle branch October 16, 2025 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants