Skip to content

Commit ac85a19

Browse files
committed
Merge branch 'master' into pebble-extra-options
2 parents 1aaeef7 + da4c975 commit ac85a19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1028
-54
lines changed

arbitrum/recordingdb.go

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ func (db *RecordingKV) Get(key []byte) ([]byte, error) {
5555
// Retrieving code
5656
copy(hash[:], key[len(rawdb.CodePrefix):])
5757
res, err = db.diskDb.Get(key)
58+
} else if ok, _ := rawdb.IsActivatedAsmKey(key); ok {
59+
// Arbitrum: the asm is non-consensus
60+
return db.diskDb.Get(key)
61+
} else if ok, _ := rawdb.IsActivatedModuleKey(key); ok {
62+
// Arbitrum: the module is non-consensus (only its hash is)
63+
return db.diskDb.Get(key)
5864
} else {
5965
err = fmt.Errorf("recording KV attempted to access non-hash key %v", hex.EncodeToString(key))
6066
}
@@ -278,6 +284,7 @@ func (r *RecordingDatabase) PrepareRecording(ctx context.Context, lastBlockHeade
278284
if err != nil {
279285
return nil, nil, nil, fmt.Errorf("failed to create recordingStateDb: %w", err)
280286
}
287+
recordingStateDb.StartRecording()
281288
var recordingChainContext *RecordingChainContext
282289
if lastBlockHeader != nil {
283290
if !lastBlockHeader.Number.IsUint64() {

cmd/evm/internal/t8ntool/tracewriter.go

+2
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,5 @@ func (t *traceWriter) CaptureArbitrumTransfer(env *vm.EVM, from, to *common.Addr
8484

8585
func (t *traceWriter) CaptureArbitrumStorageGet(key common.Hash, depth int, before bool) {}
8686
func (t *traceWriter) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {}
87+
88+
func (t *traceWriter) CaptureStylusHostio(name string, args, outs []byte, startInk, endInk uint64) {}

cmd/geth/logging_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ func censor(input string, start, end int) string {
5959
}
6060

6161
func TestLogging(t *testing.T) {
62+
t.Skip("Skipping cmd logging test due to color stripping")
63+
6264
t.Parallel()
6365
testConsoleLogging(t, "terminal", 6, 24)
6466
testConsoleLogging(t, "logfmt", 2, 26)

common/lru/basiclru_arbitrum.go

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2022 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
// Package lru implements generically-typed LRU caches.
18+
package lru
19+
20+
func (c *BasicLRU[K, V]) Capacity() int {
21+
return c.cap
22+
}

common/types_arbitrum.go

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2015 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package common
18+
19+
type Signed interface {
20+
~int | ~int8 | ~int16 | ~int32 | ~int64
21+
}
22+
23+
type Unsigned interface {
24+
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
25+
}
26+
27+
type Integer interface {
28+
Signed | Unsigned
29+
}
30+
31+
type Float interface {
32+
~float32 | ~float64
33+
}
34+
35+
// Ordered is anything that implements comparison operators such as `<` and `>`.
36+
// Unfortunately, that doesn't include big ints.
37+
type Ordered interface {
38+
Integer | Float
39+
}
40+
41+
// MinInt the minimum of two ints
42+
func MinInt[T Ordered](value, ceiling T) T {
43+
if value > ceiling {
44+
return ceiling
45+
}
46+
return value
47+
}
48+
49+
// MaxInt the maximum of two ints
50+
func MaxInt[T Ordered](value, floor T) T {
51+
if value < floor {
52+
return floor
53+
}
54+
return value
55+
}
56+
57+
// SaturatingUAdd add two integers without overflow
58+
func SaturatingUAdd[T Unsigned](a, b T) T {
59+
sum := a + b
60+
if sum < a || sum < b {
61+
sum = ^T(0)
62+
}
63+
return sum
64+
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2020 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package rawdb
18+
19+
import (
20+
"github.com/ethereum/go-ethereum/common"
21+
"github.com/ethereum/go-ethereum/ethdb"
22+
"github.com/ethereum/go-ethereum/log"
23+
)
24+
25+
// Stores the activated asm and module for a given codeHash
26+
func WriteActivation(db ethdb.KeyValueWriter, moduleHash common.Hash, asm, module []byte) {
27+
key := ActivatedAsmKey(moduleHash)
28+
if err := db.Put(key[:], asm); err != nil {
29+
log.Crit("Failed to store activated wasm asm", "err", err)
30+
}
31+
32+
key = ActivatedModuleKey(moduleHash)
33+
if err := db.Put(key[:], module); err != nil {
34+
log.Crit("Failed to store activated wasm module", "err", err)
35+
}
36+
}

core/rawdb/fileutil.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
// You should have received a copy of the GNU Lesser General Public License
1515
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
1616

17-
//go:build !js
18-
// +build !js
17+
//go:build !wasm
18+
// +build !wasm
1919

2020
package rawdb
2121

core/rawdb/fileutil_mock.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
// You should have received a copy of the GNU Lesser General Public License
1515
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
1616

17-
//go:build js
18-
// +build js
17+
//go:build wasm
18+
// +build wasm
1919

2020
package rawdb
2121

core/rawdb/schema_arbitrum.go

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2018 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
// Package rawdb contains a collection of low level database accessors.
18+
19+
package rawdb
20+
21+
import (
22+
"bytes"
23+
24+
"github.com/ethereum/go-ethereum/common"
25+
)
26+
27+
var (
28+
activatedAsmPrefix = []byte{0x00, 'w', 'a'} // (prefix, moduleHash) -> stylus asm
29+
activatedModulePrefix = []byte{0x00, 'w', 'm'} // (prefix, moduleHash) -> stylus module
30+
)
31+
32+
// WasmKeyLen = CompiledWasmCodePrefix + moduleHash
33+
const WasmKeyLen = 3 + 32
34+
35+
type WasmKey = [WasmKeyLen]byte
36+
37+
func ActivatedAsmKey(moduleHash common.Hash) WasmKey {
38+
return newWasmKey(activatedAsmPrefix, moduleHash)
39+
}
40+
41+
func ActivatedModuleKey(moduleHash common.Hash) WasmKey {
42+
return newWasmKey(activatedModulePrefix, moduleHash)
43+
}
44+
45+
// key = prefix + moduleHash
46+
func newWasmKey(prefix []byte, moduleHash common.Hash) WasmKey {
47+
var key WasmKey
48+
copy(key[:3], prefix)
49+
copy(key[3:], moduleHash[:])
50+
return key
51+
}
52+
53+
func IsActivatedAsmKey(key []byte) (bool, common.Hash) {
54+
return extractWasmKey(activatedAsmPrefix, key)
55+
}
56+
57+
func IsActivatedModuleKey(key []byte) (bool, common.Hash) {
58+
return extractWasmKey(activatedModulePrefix, key)
59+
}
60+
61+
func extractWasmKey(prefix, key []byte) (bool, common.Hash) {
62+
if !bytes.HasPrefix(key, prefix) || len(key) != WasmKeyLen {
63+
return false, common.Hash{}
64+
}
65+
return true, common.BytesToHash(key[len(prefix):])
66+
}

core/state/database.go

+19
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import (
3333
)
3434

3535
const (
36+
// Arbitrum: Cache size granted for caching clean compiled wasm code.
37+
activatedWasmCacheSize = 64 * 1024 * 1024
38+
3639
// Number of codehash->size associations to keep.
3740
codeSizeCacheSize = 100000
3841

@@ -48,6 +51,10 @@ const (
4851

4952
// Database wraps access to tries and contract code.
5053
type Database interface {
54+
// Arbitrum: Read activated Stylus contracts
55+
ActivatedAsm(moduleHash common.Hash) (asm []byte, err error)
56+
ActivatedModule(moduleHash common.Hash) (module []byte, err error)
57+
5158
// OpenTrie opens the main account trie.
5259
OpenTrie(root common.Hash) (Trie, error)
5360

@@ -152,6 +159,10 @@ func NewDatabase(db ethdb.Database) Database {
152159
// large memory cache.
153160
func NewDatabaseWithConfig(db ethdb.Database, config *trie.Config) Database {
154161
cdb := &cachingDB{
162+
// Arbitrum only
163+
activatedAsmCache: lru.NewSizeConstrainedCache[common.Hash, []byte](activatedWasmCacheSize),
164+
activatedModuleCache: lru.NewSizeConstrainedCache[common.Hash, []byte](activatedWasmCacheSize),
165+
155166
disk: db,
156167
codeSizeCache: lru.NewCache[common.Hash, int](codeSizeCacheSize),
157168
codeCache: lru.NewSizeConstrainedCache[common.Hash, []byte](codeCacheSize),
@@ -163,6 +174,10 @@ func NewDatabaseWithConfig(db ethdb.Database, config *trie.Config) Database {
163174
// NewDatabaseWithNodeDB creates a state database with an already initialized node database.
164175
func NewDatabaseWithNodeDB(db ethdb.Database, triedb *trie.Database) Database {
165176
cdb := &cachingDB{
177+
// Arbitrum only
178+
activatedAsmCache: lru.NewSizeConstrainedCache[common.Hash, []byte](activatedWasmCacheSize),
179+
activatedModuleCache: lru.NewSizeConstrainedCache[common.Hash, []byte](activatedWasmCacheSize),
180+
166181
disk: db,
167182
codeSizeCache: lru.NewCache[common.Hash, int](codeSizeCacheSize),
168183
codeCache: lru.NewSizeConstrainedCache[common.Hash, []byte](codeCacheSize),
@@ -172,6 +187,10 @@ func NewDatabaseWithNodeDB(db ethdb.Database, triedb *trie.Database) Database {
172187
}
173188

174189
type cachingDB struct {
190+
// Arbitrum
191+
activatedAsmCache *lru.SizeConstrainedCache[common.Hash, []byte]
192+
activatedModuleCache *lru.SizeConstrainedCache[common.Hash, []byte]
193+
175194
disk ethdb.KeyValueStore
176195
codeSizeCache *lru.Cache[common.Hash, int]
177196
codeCache *lru.SizeConstrainedCache[common.Hash, []byte]

core/state/database_arbitrum.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package state
2+
3+
import (
4+
"errors"
5+
6+
"github.com/ethereum/go-ethereum/common"
7+
"github.com/ethereum/go-ethereum/core/rawdb"
8+
)
9+
10+
func (db *cachingDB) ActivatedAsm(moduleHash common.Hash) ([]byte, error) {
11+
if asm, _ := db.activatedAsmCache.Get(moduleHash); len(asm) > 0 {
12+
return asm, nil
13+
}
14+
wasmKey := rawdb.ActivatedAsmKey(moduleHash)
15+
asm, err := db.disk.Get(wasmKey[:])
16+
if err != nil {
17+
return nil, err
18+
}
19+
if len(asm) > 0 {
20+
db.activatedAsmCache.Add(moduleHash, asm)
21+
return asm, nil
22+
}
23+
return nil, errors.New("not found")
24+
}
25+
26+
func (db *cachingDB) ActivatedModule(moduleHash common.Hash) ([]byte, error) {
27+
if module, _ := db.activatedModuleCache.Get(moduleHash); len(module) > 0 {
28+
return module, nil
29+
}
30+
wasmKey := rawdb.ActivatedModuleKey(moduleHash)
31+
module, err := db.disk.Get(wasmKey[:])
32+
if err != nil {
33+
return nil, err
34+
}
35+
if len(module) > 0 {
36+
db.activatedModuleCache.Add(moduleHash, module)
37+
return module, nil
38+
}
39+
return nil, errors.New("not found")
40+
}

core/state/journal_arbitrum.go

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package state
2+
3+
import (
4+
"github.com/ethereum/go-ethereum/common"
5+
)
6+
7+
type wasmActivation struct {
8+
moduleHash common.Hash
9+
}
10+
11+
func (ch wasmActivation) revert(s *StateDB) {
12+
delete(s.arbExtraData.activatedWasms, ch.moduleHash)
13+
}
14+
15+
func (ch wasmActivation) dirtied() *common.Address {
16+
return nil
17+
}
18+
19+
// Updates the Rust-side recent program cache
20+
var CacheWasmRust func(asm []byte, moduleHash common.Hash, version uint16, debug bool) = func([]byte, common.Hash, uint16, bool) {}
21+
var EvictWasmRust func(moduleHash common.Hash, version uint16, debug bool) = func(common.Hash, uint16, bool) {}
22+
23+
type CacheWasm struct {
24+
ModuleHash common.Hash
25+
Version uint16
26+
Debug bool
27+
}
28+
29+
func (ch CacheWasm) revert(s *StateDB) {
30+
EvictWasmRust(ch.ModuleHash, ch.Version, ch.Debug)
31+
}
32+
33+
func (ch CacheWasm) dirtied() *common.Address {
34+
return nil
35+
}
36+
37+
type EvictWasm struct {
38+
ModuleHash common.Hash
39+
Version uint16
40+
Debug bool
41+
}
42+
43+
func (ch EvictWasm) revert(s *StateDB) {
44+
asm := s.GetActivatedAsm(ch.ModuleHash) // only happens in native mode
45+
CacheWasmRust(asm, ch.ModuleHash, ch.Version, ch.Debug)
46+
}
47+
48+
func (ch EvictWasm) dirtied() *common.Address {
49+
return nil
50+
}

0 commit comments

Comments
 (0)