Skip to content
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

Feat: Add Gasback precompile #378

Draft
wants to merge 44 commits into
base: optimism
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
54d2023
update dependency on superchain registry
geoknee Aug 26, 2024
365b1de
remove defunct overrides
geoknee Aug 26, 2024
e46a484
go mod tidy
geoknee Aug 26, 2024
3365bc9
update dependency
geoknee Aug 26, 2024
bb15bcd
Support purely single threaded execution (#370)
ajsutton Aug 27, 2024
110c433
Expose method to force statedb to use singlethreaded mode even when m…
ajsutton Aug 27, 2024
8c45e10
make lint
geoknee Aug 27, 2024
dbaa55d
Remove Optimism config overrides (these will be pushed down into the …
geoknee Aug 27, 2024
f8f2252
add debug line
geoknee Aug 27, 2024
ae570ee
set Optimism config inside LoadOPStackChainConfig
geoknee Aug 27, 2024
f7ef5f4
update scr
geoknee Aug 27, 2024
24bff41
remove more defunct chain info
geoknee Aug 27, 2024
2d89785
refactor Genesis Config loading and remove override for OPM Optimism …
geoknee Aug 27, 2024
2be1da8
load Optimism config from registry chain config
geoknee Aug 27, 2024
f4e77e1
update scr
geoknee Aug 27, 2024
1071ac1
update import from scr
geoknee Aug 27, 2024
2998edb
update scr
geoknee Aug 27, 2024
f4fa09a
undo unintended change
geoknee Aug 27, 2024
988ce03
remove debug lines
geoknee Aug 27, 2024
52c4993
copy pointers when loading
geoknee Aug 27, 2024
f9dfe44
update scr to mainline commit
geoknee Aug 28, 2024
673a11f
Merge branch 'optimism' into gk/elastic
geoknee Aug 28, 2024
6003812
Merge pull request #371 from ethereum-optimism/gk/elastic
geoknee Aug 28, 2024
1a060c9
Add gasback precompile
Vectorized Sep 9, 2024
53ba04d
T
Vectorized Sep 9, 2024
caae1d7
T
Vectorized Sep 9, 2024
44d60ad
T
Vectorized Sep 9, 2024
156f9fd
T
Vectorized Sep 9, 2024
fb678f4
T
Vectorized Sep 9, 2024
dd24efd
Refactor to pass caller via args instead of via evm struct
Vectorized Sep 9, 2024
1e1f849
fmt
Vectorized Sep 9, 2024
9102ec6
fmt
Vectorized Sep 9, 2024
0776315
Edit comment
Vectorized Sep 9, 2024
585f11b
Tidy
Vectorized Sep 9, 2024
51d5c1d
Refactor
Vectorized Sep 13, 2024
a8176bb
Tidy
Vectorized Sep 13, 2024
fe7ef30
Tidy
Vectorized Sep 13, 2024
ec710c3
Tidy
Vectorized Sep 13, 2024
c104cf6
Tidy
Vectorized Sep 13, 2024
8364899
Add missing nil check
Vectorized Sep 13, 2024
01ebf8e
Make gasback required gas uint64 max if input is wrong
Vectorized Sep 13, 2024
7f1d4f0
Tidy
Vectorized Sep 13, 2024
ddbd9e5
Tidy
Vectorized Sep 13, 2024
8889b69
Tidy
Vectorized Sep 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,6 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g
}
}
}

if config.IsOptimism() && config.ChainID != nil && config.ChainID.Cmp(big.NewInt(params.OPGoerliChainID)) == 0 {
// Apply Optimism Goerli regolith time
config.RegolithTime = &params.OptimismGoerliRegolithTime
}
if config.IsOptimism() && config.ChainID != nil && config.ChainID.Cmp(big.NewInt(params.BaseGoerliChainID)) == 0 {
// Apply Base Goerli regolith time
config.RegolithTime = &params.BaseGoerliRegolithTime
}
if overrides != nil && overrides.OverrideCancun != nil {
config.CancunTime = overrides.OverrideCancun
}
Expand Down
18 changes: 12 additions & 6 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
"github.com/ethereum/go-ethereum/trie/triestate"
"github.com/ethereum/go-ethereum/trie/utils"
"github.com/holiman/uint256"
"golang.org/x/sync/errgroup"
)

// TriesInMemory represents the number of layers that are kept in RAM.
Expand Down Expand Up @@ -167,6 +166,9 @@ type StateDB struct {
StorageUpdated atomic.Int64
AccountDeleted int
StorageDeleted atomic.Int64

// singlethreaded avoids creation of additional threads when set to true for compatibility with cannon.
singlethreaded bool
}

// New creates a new state from a given trie.
Expand Down Expand Up @@ -196,6 +198,10 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
return sdb, nil
}

func (s *StateDB) MakeSinglethreaded() {
s.singlethreaded = true
}

// SetLogger sets the logger for account update hooks.
func (s *StateDB) SetLogger(l *tracing.Hooks) {
s.logger = l
Expand Down Expand Up @@ -851,9 +857,9 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
// method will internally call a blocking trie fetch from the prefetcher,
// so there's no need to explicitly wait for the prefetchers to finish.
var (
start = time.Now()
workers errgroup.Group
start = time.Now()
)
workers := newWorkerGroup(s.singlethreaded)
if s.db.TrieDB().IsVerkle() {
// Whilst MPT storage tries are independent, Verkle has one single trie
// for all the accounts and all the storage slots merged together. The
Expand Down Expand Up @@ -1225,10 +1231,10 @@ func (s *StateDB) commit(deleteEmptyObjects bool) (*stateUpdate, error) {
// off some milliseconds from the commit operation. Also accumulate the code
// writes to run in parallel with the computations.
var (
start = time.Now()
root common.Hash
workers errgroup.Group
start = time.Now()
root common.Hash
)
workers := newWorkerGroup(s.singlethreaded)
// Schedule the account trie first since that will be the biggest, so give
// it the most time to crunch.
//
Expand Down
37 changes: 37 additions & 0 deletions core/state/workers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package state

import (
"errors"

"golang.org/x/sync/errgroup"
)

type workerGroup interface {
Go(func() error)
SetLimit(int)
Wait() error
}

func newWorkerGroup(singlethreaded bool) workerGroup {
if singlethreaded {
return &inlineWorkerGroup{}
} else {
var grp errgroup.Group
return &grp
}
}

type inlineWorkerGroup struct {
err error
}

func (i *inlineWorkerGroup) Go(action func() error) {
i.err = errors.Join(i.err, action())
}

func (i *inlineWorkerGroup) SetLimit(_ int) {
}

func (i *inlineWorkerGroup) Wait() error {
return i.err
}
2 changes: 0 additions & 2 deletions core/superchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ func LoadOPStackGenesis(chainID uint64) (*Genesis, error) {
switch chainID {
case params.OPMainnetChainID:
expectedHash = common.HexToHash("0x7ca38a1916c42007829c55e69d3e9a73265554b586a499015373241b8a3fa48b")
case params.OPGoerliChainID:
expectedHash = common.HexToHash("0xc1fc15cd51159b1f1e5cbc4b82e85c1447ddfa33c52cf1d98d14fba0d6354be1")
default:
return nil, fmt.Errorf("unknown stateless genesis definition for chain %d", chainID)
}
Expand Down
3 changes: 3 additions & 0 deletions core/superchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func TestRegistryChainConfigOverride(t *testing.T) {
rawdb.WriteCanonicalHash(db, bl.Hash(), 0)
rawdb.WriteBlock(db, bl)

if genesis.Config.Optimism == nil {
t.Fatal("expected non nil Optimism config")
}
genesis.Config.Optimism.EIP1559DenominatorCanyon = tt.setDenominator
// create chain config, even with incomplete genesis input: the chain config should be corrected
chainConfig, _, err := SetupGenesisBlockWithOverride(db, tdb, genesis, tt.overrides)
Expand Down
Loading