Skip to content

Commit da10033

Browse files
committed
Merge branch 'master' into merge-v1.14.4
2 parents 6b24c8d + be92342 commit da10033

File tree

12 files changed

+158
-60
lines changed

12 files changed

+158
-60
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
@@ -207,6 +207,18 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
207207
return sdb, nil
208208
}
209209

210+
func (s *StateDB) FilterTx() {
211+
s.arbExtraData.arbTxFilter = true
212+
}
213+
214+
func (s *StateDB) ClearTxFilter() {
215+
s.arbExtraData.arbTxFilter = false
216+
}
217+
218+
func (s *StateDB) IsTxFiltered() bool {
219+
return s.arbExtraData.arbTxFilter
220+
}
221+
210222
// SetLogger sets the logger for account update hooks.
211223
func (s *StateDB) SetLogger(l *tracing.Hooks) {
212224
s.logger = l
@@ -717,6 +729,7 @@ func (s *StateDB) Copy() *StateDB {
717729
recentWasms: s.arbExtraData.recentWasms.Copy(),
718730
openWasmPages: s.arbExtraData.openWasmPages,
719731
everWasmPages: s.arbExtraData.everWasmPages,
732+
arbTxFilter: s.arbExtraData.arbTxFilter,
720733
},
721734

722735
db: s.db,
@@ -1167,6 +1180,9 @@ func (s *StateDB) GetTrie() Trie {
11671180
// commit gathers the state mutations accumulated along with the associated
11681181
// trie changes, resetting all internal flags with the new state as the base.
11691182
func (s *StateDB) commit(deleteEmptyObjects bool) (*stateUpdate, error) {
1183+
if s.arbExtraData.arbTxFilter {
1184+
return nil, ErrArbTxFilter
1185+
}
11701186
// Short circuit in case any database failure occurred earlier.
11711187
if s.dbErr != nil {
11721188
return nil, 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/instructions_arbitrum.go

Lines changed: 0 additions & 50 deletions
This file was deleted.

core/vm/interface.go

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

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

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
}

0 commit comments

Comments
 (0)