-
Notifications
You must be signed in to change notification settings - Fork 5
refactor!: temporary extras require proof of global lock #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly questions
// | ||
// WithTemporaryExtrasLock MUST NOT be used on a live chain. It is solely | ||
// intended for off-chain consumers that require access to extras. | ||
func WithTemporaryExtrasLock(fn func(lock ExtrasLock) error) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can omit taking the lock in the fn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? The fn
doesn't take it; it waits for it to be taken before being called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v := extrasHandle.Load() | ||
return fn(ExtrasLock{&v}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to pass the lock here and defer the lock verification to the fn
? Can't we verify that here? Are we expecting fn
to be called with different locks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1- This pattern could be difficult for a consumer. I wonder if we can move the complexity either to libevm or to coreth/subnet-evm so that the consumer can use something like this
evm.WithTempRegisteredLibEVMExtras(func() error {
t.Run("payloads", func(t *testing.T) {
for pkg, fn := range payloadTests {
t.Run(pkg, fn)
}
})
return nil
})
TLDR; IMO locks should be abstracted away.
// An ExtrasLock is a handle that proves a current call to | ||
// [WithTemporaryExtrasLock]. | ||
type ExtrasLock struct { | ||
handle *uint64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we have this handle as a uint64
? Or why do we need the handle
? Aren't this implying if the lock is held or not?
v := extrasHandle.Load() | ||
return fn(ExtrasLock{&v}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1- This pattern could be difficult for a consumer. I wonder if we can move the complexity either to libevm or to coreth/subnet-evm so that the consumer can use something like this
evm.WithTempRegisteredLibEVMExtras(func() error {
t.Run("payloads", func(t *testing.T) {
for pkg, fn := range payloadTests {
t.Run(pkg, fn)
}
})
return nil
})
TLDR; IMO locks should be abstracted away.
// | ||
// WithTemporaryExtrasLock MUST NOT be used on a live chain. It is solely | ||
// intended for off-chain consumers that require access to extras. | ||
func WithTemporaryExtrasLock(fn func(lock ExtrasLock) error) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// | ||
// WithTemporaryExtrasLock MUST NOT be used on a live chain. It is solely | ||
// intended for off-chain consumers that require access to extras. | ||
func WithTemporaryExtrasLock(fn func(lock ExtrasLock) error) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if taking multiple fns
(i.e WithTemporaryExtrasLock(fns ...func(lock ExtrasLock) error)` would help cleaning this nested calls.
Why this should be merged
The
temporary.WithTempRegisteredExtras()
global lock introduced in #234 wasn't fit for purpose when used incoreth
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 respectivecoreth
functions.See ava-labs/coreth#1328 for intended usage in
coreth
andsubnet-evm
. A consumer of both of these can then safely do the following:How this was tested
Unit test of the new function plus existing integration tests of all modified code.