Skip to content

Commit 80ec023

Browse files
authored
Merge branch 'master' into rm_blockhashop
2 parents 15fccba + 57663a5 commit 80ec023

File tree

11 files changed

+158
-10
lines changed

11 files changed

+158
-10
lines changed

common/lru/blob_lru.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,21 @@ func (c *SizeConstrainedCache[K, V]) Get(key K) (V, bool) {
8282

8383
return c.lru.Get(key)
8484
}
85+
86+
func (c *SizeConstrainedCache[K, V]) Remove(key K) {
87+
c.lock.Lock()
88+
defer c.lock.Unlock()
89+
90+
if v, ok := c.lru.Peek(key); ok {
91+
c.size -= uint64(len(v))
92+
c.lru.Remove(key)
93+
}
94+
}
95+
96+
func (c *SizeConstrainedCache[K, V]) Clear() {
97+
c.lock.Lock()
98+
defer c.lock.Unlock()
99+
100+
c.lru.Purge()
101+
c.size = 0
102+
}

core/state/statedb.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
219219
return sdb, nil
220220
}
221221

222+
func (s *StateDB) FilterTx() {
223+
s.arbExtraData.arbTxFilter = true
224+
}
225+
226+
func (s *StateDB) ClearTxFilter() {
227+
s.arbExtraData.arbTxFilter = false
228+
}
229+
230+
func (s *StateDB) IsTxFiltered() bool {
231+
return s.arbExtraData.arbTxFilter
232+
}
233+
222234
// SetLogger sets the logger for account update hooks.
223235
func (s *StateDB) SetLogger(l *tracing.Hooks) {
224236
s.logger = l
@@ -736,6 +748,7 @@ func (s *StateDB) Copy() *StateDB {
736748
recentWasms: s.arbExtraData.recentWasms.Copy(),
737749
openWasmPages: s.arbExtraData.openWasmPages,
738750
everWasmPages: s.arbExtraData.everWasmPages,
751+
arbTxFilter: s.arbExtraData.arbTxFilter,
739752
},
740753

741754
db: s.db,
@@ -1220,6 +1233,9 @@ func (s *StateDB) GetTrie() Trie {
12201233
// The associated block number of the state transition is also provided
12211234
// for more chain context.
12221235
func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, error) {
1236+
if s.arbExtraData.arbTxFilter {
1237+
return common.Hash{}, ErrArbTxFilter
1238+
}
12231239
// Short circuit in case any database failure occurred earlier.
12241240
if s.dbErr != nil {
12251241
return common.Hash{}, fmt.Errorf("commit aborted due to earlier error: %v", s.dbErr)

core/state/statedb_arbitrum.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,16 @@ func (s *StateDB) Deterministic() bool {
164164
return s.deterministic
165165
}
166166

167+
var ErrArbTxFilter error = errors.New("internal error")
168+
167169
type ArbitrumExtraData struct {
168170
unexpectedBalanceDelta *big.Int // total balance change across all accounts
169171
userWasms UserWasms // user wasms encountered during execution
170172
openWasmPages uint16 // number of pages currently open
171173
everWasmPages uint16 // largest number of pages ever allocated during this tx's execution
172174
activatedWasms map[common.Hash]ActivatedWasm // newly activated WASMs
173175
recentWasms RecentWasms
176+
arbTxFilter bool
174177
}
175178

176179
func (s *StateDB) SetArbFinalizer(f func(*ArbitrumExtraData)) {

core/types/transaction.go

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,54 @@ type Transaction struct {
6464
inner TxData // Consensus contents of a transaction
6565
time time.Time // Time first seen locally (spam avoidance)
6666

67-
// Arbitrum cache: must be atomically accessed
68-
CalldataUnits uint64
67+
// Arbitrum cache of the calldata units at a brotli compression level.
68+
// The top 8 bits are the brotli compression level last used to compute this,
69+
// and the remaining 56 bits are the calldata units at that compression level.
70+
calldataUnitsForBrotliCompressionLevel atomic.Uint64
6971

7072
// caches
7173
hash atomic.Pointer[common.Hash]
7274
size atomic.Uint64
7375
from atomic.Pointer[sigCache]
7476
}
7577

78+
// GetRawCachedCalldataUnits returns the cached brotli compression level and corresponding calldata units,
79+
// or (0, 0) if the cache is empty.
80+
func (tx *Transaction) GetRawCachedCalldataUnits() (uint64, uint64) {
81+
repr := tx.calldataUnitsForBrotliCompressionLevel.Load()
82+
cachedCompressionLevel := repr >> 56
83+
calldataUnits := repr & ((1 << 56) - 1)
84+
return cachedCompressionLevel, calldataUnits
85+
}
86+
87+
// GetCachedCalldataUnits returns the cached calldata units for a given brotli compression level,
88+
// returning nil if no cache is present or the cache is for a different compression level.
89+
func (tx *Transaction) GetCachedCalldataUnits(requestedCompressionLevel uint64) *uint64 {
90+
cachedCompressionLevel, cachedUnits := tx.GetRawCachedCalldataUnits()
91+
if cachedUnits == 0 {
92+
// empty cache
93+
return nil
94+
}
95+
if cachedCompressionLevel != requestedCompressionLevel {
96+
// wrong compression level
97+
return nil
98+
}
99+
return &cachedUnits
100+
}
101+
102+
// SetCachedCalldataUnits sets the cached brotli compression level and corresponding calldata units,
103+
// or clears the cache if the values are too large to fit (at least 2**8 and 2**56 respectively).
104+
// Note that a zero calldataUnits is also treated as an empty cache.
105+
func (tx *Transaction) SetCachedCalldataUnits(compressionLevel uint64, calldataUnits uint64) {
106+
var repr uint64
107+
// Ensure the compressionLevel and calldataUnits will fit.
108+
// Otherwise, just clear the cache.
109+
if compressionLevel < 1<<8 && calldataUnits < 1<<56 {
110+
repr = compressionLevel<<56 | calldataUnits
111+
}
112+
tx.calldataUnitsForBrotliCompressionLevel.Store(repr)
113+
}
114+
76115
// NewTx creates a new transaction.
77116
func NewTx(inner TxData) *Transaction {
78117
tx := new(Transaction)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2014 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 types
18+
19+
import "testing"
20+
21+
func TestTxCalldataUnitsCache(t *testing.T) {
22+
tx := &Transaction{}
23+
units := tx.GetCachedCalldataUnits(0)
24+
if units != nil {
25+
t.Errorf("unexpected initial cache present %v for compression 0", units)
26+
}
27+
units = tx.GetCachedCalldataUnits(1)
28+
if units != nil {
29+
t.Errorf("unexpected initial cache present %v for compression 1", units)
30+
}
31+
tx.SetCachedCalldataUnits(200, 1000)
32+
units = tx.GetCachedCalldataUnits(100)
33+
if units != nil {
34+
t.Errorf("unexpected cached units %v present for incorrect compression 100", units)
35+
}
36+
units = tx.GetCachedCalldataUnits(0)
37+
if units != nil {
38+
t.Errorf("unexpected cached units %v present for incorrect compression 0", units)
39+
}
40+
units = tx.GetCachedCalldataUnits(200)
41+
if units == nil || *units != 1000 {
42+
t.Errorf("unexpected cached units %v for correct compression 200", units)
43+
}
44+
tx.SetCachedCalldataUnits(1, 1<<60)
45+
units = tx.GetCachedCalldataUnits(1)
46+
if units != nil {
47+
t.Errorf("unexpected cache value %v present after reset", units)
48+
}
49+
}

core/vm/interface.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ type StateDB interface {
4848
// Arbitrum: preserve old empty account behavior
4949
CreateZombieIfDeleted(common.Address)
5050

51+
// Arbitrum
52+
FilterTx()
53+
ClearTxFilter()
54+
IsTxFiltered() bool
55+
5156
Deterministic() bool
5257
Database() state.Database
5358

ethdb/pebble/extraoptions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package pebble
33
import "time"
44

55
type ExtraOptions struct {
6+
SyncMode bool
67
BytesPerSync int
78
L0CompactionFileThreshold int
89
L0CompactionThreshold int

ethdb/pebble/pebble.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func New(file string, cache int, handles int, namespace string, readonly bool, e
238238
fn: file,
239239
log: logger,
240240
quitChan: make(chan chan error),
241-
writeOptions: &pebble.WriteOptions{Sync: !ephemeral},
241+
writeOptions: &pebble.WriteOptions{Sync: !ephemeral && extraOptions.SyncMode},
242242
}
243243
opt := &pebble.Options{
244244
// Pebble has a single combined cache area and the write

params/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,15 +574,15 @@ func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *bi
574574
// IsShanghai returns whether time is either equal to the Shanghai fork time or greater.
575575
func (c *ChainConfig) IsShanghai(num *big.Int, time uint64, currentArbosVersion uint64) bool {
576576
if c.IsArbitrum() {
577-
return currentArbosVersion >= 11
577+
return currentArbosVersion >= ArbosVersion_11
578578
}
579579
return c.IsLondon(num) && isTimestampForked(c.ShanghaiTime, time)
580580
}
581581

582582
// IsCancun returns whether num is either equal to the Cancun fork time or greater.
583583
func (c *ChainConfig) IsCancun(num *big.Int, time uint64, currentArbosVersion uint64) bool {
584584
if c.IsArbitrum() {
585-
return currentArbosVersion >= 20
585+
return currentArbosVersion >= ArbosVersion_20
586586
}
587587
return c.IsLondon(num) && isTimestampForked(c.CancunTime, time)
588588
}

params/config_arbitrum.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,27 @@ import (
2222
"github.com/ethereum/go-ethereum/common"
2323
)
2424

25-
const ArbosVersion_FixRedeemGas = uint64(11)
26-
const ArbosVersion_Stylus = uint64(30)
27-
const ArbosVersion_StylusFixes = uint64(31)
28-
const ArbosVersion_StylusChargingFixes = uint64(32)
25+
const ArbosVersion_2 = uint64(2)
26+
const ArbosVersion_3 = uint64(3)
27+
const ArbosVersion_4 = uint64(4)
28+
const ArbosVersion_5 = uint64(5)
29+
const ArbosVersion_6 = uint64(6)
30+
const ArbosVersion_7 = uint64(7)
31+
const ArbosVersion_8 = uint64(8)
32+
const ArbosVersion_9 = uint64(9)
33+
const ArbosVersion_10 = uint64(10)
34+
const ArbosVersion_11 = uint64(11)
35+
const ArbosVersion_20 = uint64(20)
36+
const ArbosVersion_30 = uint64(30)
37+
const ArbosVersion_31 = uint64(31)
38+
const ArbosVersion_32 = uint64(32)
39+
40+
const ArbosVersion_FixRedeemGas = ArbosVersion_11
41+
const ArbosVersion_Stylus = ArbosVersion_30
42+
const ArbosVersion_StylusFixes = ArbosVersion_31
43+
const ArbosVersion_StylusChargingFixes = ArbosVersion_32
44+
const MaxArbosVersionSupported = ArbosVersion_32
45+
const MaxDebugArbosVersionSupported = ArbosVersion_32
2946

3047
type ArbitrumChainParams struct {
3148
EnableArbOS bool

params/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestConfigRules(t *testing.T) {
131131
t.Errorf("expected %v to not be shanghai", currentArbosVersion)
132132
}
133133
stamp = 500
134-
currentArbosVersion = 11
134+
currentArbosVersion = ArbosVersion_11
135135
if r := c.Rules(big.NewInt(0), true, stamp, currentArbosVersion); !r.IsShanghai {
136136
t.Errorf("expected %v to be shanghai", currentArbosVersion)
137137
}

0 commit comments

Comments
 (0)