Skip to content

Commit 05e9984

Browse files
committed
Merge branch 'main' into arr4n/parallel
2 parents e737446 + 1bccf4f commit 05e9984

31 files changed

+959
-92
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ jobs:
4343
# commit of a pull request, and we want to avoid reporting invalid goheader errors.
4444
uses: golangci/golangci-lint-action@v6
4545
with:
46-
version: v1.60
46+
version: v1.64.8
4747
only-new-issues: true
4848
args: --enable-only goheader
4949
- name: golangci-lint
5050
uses: golangci/golangci-lint-action@v6
5151
with:
52-
version: v1.60
52+
version: v1.64.8
5353

5454
yamllint:
5555
runs-on: ubuntu-latest

accounts/abi/unpack_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ func TestOOMMaliciousInput(t *testing.T) {
947947
}
948948
encb, err := hex.DecodeString(test.enc)
949949
if err != nil {
950-
t.Fatalf("invalid hex: %s" + test.enc)
950+
t.Fatalf("invalid hex: %s", test.enc)
951951
}
952952
_, err = abi.Methods["method"].Outputs.UnpackValues(encb)
953953
if err == nil {

cmd/evm/t8n_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func TestT9n(t *testing.T) {
412412
ok, err := cmpJson(have, want)
413413
switch {
414414
case err != nil:
415-
t.Logf(string(have))
415+
t.Log(string(have))
416416
t.Fatalf("test %d, json parsing failed: %v", i, err)
417417
case !ok:
418418
t.Fatalf("test %d: output wrong, have \n%v\nwant\n%v\n", i, string(have), string(want))
@@ -547,7 +547,7 @@ func TestB11r(t *testing.T) {
547547
ok, err := cmpJson(have, want)
548548
switch {
549549
case err != nil:
550-
t.Logf(string(have))
550+
t.Log(string(have))
551551
t.Fatalf("test %d, json parsing failed: %v", i, err)
552552
case !ok:
553553
t.Fatalf("test %d: output wrong, have \n%v\nwant\n%v\n", i, string(have), string(want))

cmd/rlpdump/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func dump(in *inStream, s *rlp.Stream, depth int, out io.Writer) error {
142142
s.List()
143143
defer s.ListEnd()
144144
if size == 0 {
145-
fmt.Fprintf(out, ws(depth)+"[]")
145+
fmt.Fprint(out, ws(depth)+"[]")
146146
} else {
147147
fmt.Fprintln(out, ws(depth)+"[")
148148
for i := 0; ; i++ {

core/asm/tokentype_string.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/rawdb/accessors_chain_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func TestBlockReceiptStorage(t *testing.T) {
391391
t.Fatalf("no receipts returned")
392392
} else {
393393
if err := checkReceiptsRLP(rs, receipts); err != nil {
394-
t.Fatalf(err.Error())
394+
t.Fatal(err.Error())
395395
}
396396
}
397397
// Delete the body and ensure that the receipts are no longer returned (metadata can't be recomputed)
@@ -401,7 +401,7 @@ func TestBlockReceiptStorage(t *testing.T) {
401401
}
402402
// Ensure that receipts without metadata can be returned without the block body too
403403
if err := checkReceiptsRLP(ReadRawReceipts(db, hash, 0), receipts); err != nil {
404-
t.Fatalf(err.Error())
404+
t.Fatal(err.Error())
405405
}
406406
// Sanity check that body alone without the receipt is a full purge
407407
WriteBody(db, hash, 0, body)

core/state/statedb.libevm.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/ava-labs/libevm/common"
2323
"github.com/ava-labs/libevm/core/state/snapshot"
24+
"github.com/ava-labs/libevm/libevm"
2425
"github.com/ava-labs/libevm/libevm/register"
2526
"github.com/ava-labs/libevm/libevm/stateconf"
2627
)
@@ -82,6 +83,22 @@ func RegisterExtras(s StateDBHooks) {
8283
registeredExtras.MustRegister(s)
8384
}
8485

86+
// WithTempRegisteredExtras temporarily registers `s` as if calling
87+
// [RegisterExtras] the same type parameter. After `fn` returns, the
88+
// registration is returned to its former state, be that none or the types
89+
// originally passed to [RegisterExtras].
90+
//
91+
// This MUST NOT be used on a live chain. It is solely intended for off-chain
92+
// consumers that require access to extras. Said consumers SHOULD NOT, however
93+
// call this function directly. Use the libevm/temporary.WithRegisteredExtras()
94+
// function instead as it atomically overrides all possible packages.
95+
func WithTempRegisteredExtras(lock libevm.ExtrasLock, s StateDBHooks, fn func() error) error {
96+
if err := lock.Verify(); err != nil {
97+
return err
98+
}
99+
return registeredExtras.TempOverride(s, fn)
100+
}
101+
85102
// TestOnlyClearRegisteredExtras clears the arguments previously passed to
86103
// [RegisterExtras]. It panics if called from a non-testing call stack.
87104
//

core/state/statedb.libevm_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/ava-labs/libevm/core/state/snapshot"
2828
"github.com/ava-labs/libevm/core/types"
2929
"github.com/ava-labs/libevm/ethdb"
30+
"github.com/ava-labs/libevm/libevm"
3031
"github.com/ava-labs/libevm/libevm/stateconf"
3132
"github.com/ava-labs/libevm/trie"
3233
"github.com/ava-labs/libevm/trie/trienode"
@@ -150,6 +151,12 @@ func (highByteFlipper) TransformStateKey(_ common.Address, key common.Hash) comm
150151
return flipHighByte(key)
151152
}
152153

154+
type noopHooks struct{}
155+
156+
func (noopHooks) TransformStateKey(_ common.Address, key common.Hash) common.Hash {
157+
return key
158+
}
159+
153160
func TestTransformStateKey(t *testing.T) {
154161
rawdb := rawdb.NewMemoryDatabase()
155162
trie := triedb.NewDatabase(rawdb, nil)
@@ -209,6 +216,20 @@ func TestTransformStateKey(t *testing.T) {
209216
assertCommittedEq(t, flippedKey, regularVal)
210217
assertCommittedEq(t, flippedKey, flippedVal, noTransform)
211218

219+
t.Run("WithTempRegisteredExtras", func(t *testing.T) {
220+
err := libevm.WithTemporaryExtrasLock(func(lock libevm.ExtrasLock) error {
221+
return WithTempRegisteredExtras(lock, noopHooks{}, func() error {
222+
// No-op hooks are equivalent to using the `noTransform` option.
223+
// NOTE this is NOT the intended usage of [WithTempRegisteredExtras]
224+
// and is simply an easy way to test the temporary registration.
225+
assertEq(t, regularKey, regularVal)
226+
assertEq(t, flippedKey, flippedVal)
227+
return nil
228+
})
229+
})
230+
require.NoError(t, err)
231+
})
232+
212233
updatedVal := common.Hash{'u', 'p', 'd', 'a', 't', 'e', 'd'}
213234
sdb.SetState(addr, regularKey, updatedVal)
214235
assertEq(t, regularKey, updatedVal)

core/types/block.libevm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ type BlockBodyHooks interface {
130130
// to no type having been registered.
131131
type NOOPBlockBodyHooks struct{}
132132

133-
var _ BlockBodyPayload[*NOOPBlockBodyHooks] = NOOPBlockBodyHooks{}
133+
var _ BlockBodyPayload[*NOOPBlockBodyHooks] = (*NOOPBlockBodyHooks)(nil)
134134

135135
func (NOOPBlockBodyHooks) Copy() *NOOPBlockBodyHooks { return &NOOPBlockBodyHooks{} }
136136

core/types/rlp_payload.libevm.go

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"io"
2222

2323
"github.com/ava-labs/libevm/common"
24+
"github.com/ava-labs/libevm/libevm"
2425
"github.com/ava-labs/libevm/libevm/pseudo"
2526
"github.com/ava-labs/libevm/libevm/register"
2627
"github.com/ava-labs/libevm/libevm/testonly"
@@ -44,17 +45,27 @@ import (
4445
// [Header] or [Block] / [Body] is a non-nil `HPtr` or `BPtr` respectively. The
4546
// latter guarantee ensures that hooks won't be called on nil-pointer receivers.
4647
func RegisterExtras[
47-
H any, HPtr interface {
48-
HeaderHooks
49-
*H
50-
},
51-
B any, BPtr interface {
52-
BlockBodyPayload[BPtr]
53-
*B
54-
},
48+
H any, HPtr HeaderHooksPointer[H],
49+
B any, BPtr BlockBodyHooksPointer[B, BPtr],
5550
SA any,
5651
]() ExtraPayloads[HPtr, BPtr, SA] {
57-
extra := ExtraPayloads[HPtr, BPtr, SA]{
52+
payloads, ctors := payloadsAndConstructors[H, HPtr, B, BPtr, SA]()
53+
registeredExtras.MustRegister(ctors)
54+
log.Info(
55+
"Registered core/types extras",
56+
"Header", log.TypeOf(pseudo.Zero[HPtr]().Value.Get()),
57+
"Block/Body", log.TypeOf(pseudo.Zero[BPtr]().Value.Get()),
58+
"StateAccount", log.TypeOf(pseudo.Zero[SA]().Value.Get()),
59+
)
60+
return payloads
61+
}
62+
63+
func payloadsAndConstructors[
64+
H any, HPtr HeaderHooksPointer[H],
65+
B any, BPtr BlockBodyHooksPointer[B, BPtr],
66+
SA any,
67+
]() (ExtraPayloads[HPtr, BPtr, SA], *extraConstructors) {
68+
payloads := ExtraPayloads[HPtr, BPtr, SA]{
5869
Header: pseudo.NewAccessor[*Header, HPtr](
5970
(*Header).extraPayload,
6071
func(h *Header, t *pseudo.Type) { h.extra = t },
@@ -72,7 +83,7 @@ func RegisterExtras[
7283
func(a StateOrSlimAccount, t *pseudo.Type) { a.extra().t = t },
7384
),
7485
}
75-
registeredExtras.MustRegister(&extraConstructors{
86+
ctors := &extraConstructors{
7687
stateAccountType: func() string {
7788
var x SA
7889
return fmt.Sprintf("%T", x)
@@ -84,23 +95,54 @@ func RegisterExtras[
8495
newHeader: pseudo.NewConstructor[H]().NewPointer, // i.e. non-nil HPtr
8596
newBlockOrBody: pseudo.NewConstructor[B]().NewPointer, // i.e. non-nil BPtr
8697
newStateAccount: pseudo.NewConstructor[SA]().Zero,
87-
hooks: extra,
88-
})
89-
log.Info(
90-
"Registered core/types extras",
91-
"Header", log.TypeOf(pseudo.Zero[HPtr]().Value.Get()),
92-
"Block/Body", log.TypeOf(pseudo.Zero[BPtr]().Value.Get()),
93-
"StateAccount", log.TypeOf(pseudo.Zero[SA]().Value.Get()),
94-
)
95-
return extra
98+
hooks: payloads,
99+
}
100+
return payloads, ctors
101+
}
102+
103+
// WithTempRegisteredExtras temporarily registers `HPtr`, `BPtr`, and `SA` as if
104+
// calling [RegisterExtras] the same type parameters. The [ExtraPayloads] are
105+
// passed to `fn` instead of being returned; the argument MUST NOT be persisted
106+
// beyond the life of `fn`. After `fn` returns, the registration is returned to
107+
// its former state, be that none or the types originally passed to
108+
// [RegisterExtras].
109+
//
110+
// This MUST NOT be used on a live chain. It is solely intended for off-chain
111+
// consumers that require access to extras. Said consumers SHOULD NOT, however
112+
// call this function directly. Use the libevm/temporary.WithRegisteredExtras()
113+
// function instead as it atomically overrides all possible packages.
114+
func WithTempRegisteredExtras[
115+
H, B, SA any,
116+
HPtr HeaderHooksPointer[H],
117+
BPtr BlockBodyHooksPointer[B, BPtr],
118+
](lock libevm.ExtrasLock, fn func(ExtraPayloads[HPtr, BPtr, SA]) error) error {
119+
if err := lock.Verify(); err != nil {
120+
return err
121+
}
122+
payloads, ctors := payloadsAndConstructors[H, HPtr, B, BPtr, SA]()
123+
return registeredExtras.TempOverride(ctors, func() error { return fn(payloads) })
124+
}
125+
126+
// A HeaderHooksPointer is a type constraint for an implementation of
127+
// [HeaderHooks] with a pointer receiver.
128+
type HeaderHooksPointer[H any] interface {
129+
HeaderHooks
130+
*H
131+
}
132+
133+
// A BlockBodyHooksPointer is a type constraint for an implementation of
134+
// [BlockBodyPayload] with a pointer receiver.
135+
type BlockBodyHooksPointer[B any, Self any] interface {
136+
BlockBodyPayload[Self]
137+
*B
96138
}
97139

98140
// A BlockBodyPayload is an implementation of [BlockBodyHooks] that is also able
99141
// to clone itself. Both [Block.Body] and [Block.WithBody] require this
100142
// functionality to copy the payload between the types.
101-
type BlockBodyPayload[BPtr any] interface {
143+
type BlockBodyPayload[Self any] interface {
102144
BlockBodyHooks
103-
Copy() BPtr
145+
Copy() Self
104146
}
105147

106148
// TestOnlyClearRegisteredExtras clears the [Extras] previously passed to

0 commit comments

Comments
 (0)