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: initial setup for RIP-7560 #1

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 0 additions & 34 deletions .github/workflows/rip7560test.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ tests/spec-tests/
/alexfdata/prysmctl
/alexfdata/validator
/alexfdata/genesis.ssz

/db
2 changes: 1 addition & 1 deletion circleciconfig.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Eth]
Rip7560MaxBundleSize = 0
Rip7560MaxBundleGas = 0
Rip7560PullUrls = ["http://localhost:3001/rpc"]
Rip7560PullUrls = ["http://localhost:7560/rpc"]
Rip7560AcceptPush = false
1 change: 1 addition & 0 deletions config/test-jwt-secret.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
688f5d737bad920bdfb2fc2f488d6b6209eebda1dae949a8de91398d932c517a
12 changes: 9 additions & 3 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 @@ -852,7 +858,7 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
// so there's no need to explicitly wait for the prefetchers to finish.
var (
start = time.Now()
workers errgroup.Group
workers = newWorkerGroup(s.singlethreaded)
)
if s.db.TrieDB().IsVerkle() {
// Whilst MPT storage tries are independent, Verkle has one single trie
Expand Down Expand Up @@ -1227,7 +1233,7 @@ func (s *StateDB) commit(deleteEmptyObjects bool) (*stateUpdate, error) {
var (
start = time.Now()
root common.Hash
workers errgroup.Group
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: 1 addition & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
if tx.Type() == types.Rip7560Type {
// HandleRip7560Transactions accepts a transaction array and in the future bundle handling will need this
tmpTxs := [1]*types.Transaction{tx}
_, validatedTxsReceipts, _, validateTxsLogs, err := HandleRip7560Transactions(tmpTxs[:], 0, statedb, &context.Coinbase, header, gp, p.config, p.bc, cfg, false, usedGas)
_, validatedTxsReceipts, _, validateTxsLogs, err := HandleRip7560Transactions(tmpTxs[:], 0, statedb, &context.Coinbase, header, gp, p.config, p.chain, cfg, false, usedGas)
receipts = append(receipts, validatedTxsReceipts...)
allLogs = append(allLogs, validateTxsLogs...)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions core/state_processor_rip7560.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func ApplyRip7560ValidationPhases(
return nil, wrapError(err)
}

blockContext := NewEVMBlockContext(header, bc, coinbase)
blockContext := NewEVMBlockContext(header, bc, coinbase, chainConfig, statedb)
sender := aatx.Sender
txContext := vm.TxContext{
Origin: *aatx.Sender,
Expand Down Expand Up @@ -635,7 +635,7 @@ func ApplyRip7560ExecutionPhase(
usedGas *uint64,
) (*types.Receipt, error) {

blockContext := NewEVMBlockContext(header, bc, author)
blockContext := NewEVMBlockContext(header, bc, author, config, statedb)
aatx := vpr.Tx.Rip7560TransactionData()
sender := aatx.Sender
txContext := vm.TxContext{
Expand Down
2 changes: 2 additions & 0 deletions core/types/tx_rip7560.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type Rip7560AccountAbstractionTx struct {
NonceKey *big.Int
}

func (tx *Rip7560AccountAbstractionTx) isSystemTx() bool { return false }

// copy creates a deep copy of the transaction data and initializes all fields.
func (tx *Rip7560AccountAbstractionTx) copy() TxData {
cpy := &Rip7560AccountAbstractionTx{
Expand Down
15 changes: 7 additions & 8 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,20 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
}
legacyPool := legacypool.New(config.TxPool, eth.blockchain)

txPools := []txpool.SubPool{legacyPool}
if !eth.BlockChain().Config().IsOptimism() {
blobPool := blobpool.New(config.BlobPool, eth.blockchain)
txPools = append(txPools, blobPool)
}
eth.txPool, err = txpool.New(config.TxPool.PriceLimit, eth.blockchain, txPools)

rip7560PoolConfig := rip7560pool.Config{
MaxBundleGas: config.Rip7560MaxBundleGas,
MaxBundleSize: config.Rip7560MaxBundleSize,
PullUrls: config.Rip7560PullUrls,
}
rip7560 := rip7560pool.New(rip7560PoolConfig, eth.blockchain, config.Miner.Etherbase)

eth.txPool, err = txpool.New(config.TxPool.PriceLimit, eth.blockchain, []txpool.SubPool{legacyPool, blobPool, rip7560})
txPools := []txpool.SubPool{legacyPool, rip7560}
if !eth.BlockChain().Config().IsOptimism() {
blobPool := blobpool.New(config.BlobPool, eth.blockchain)
txPools = append(txPools, blobPool)
}
eth.txPool, err = txpool.New(config.TxPool.PriceLimit, eth.blockchain, txPools)

if err != nil {
return nil, err
}
Expand Down
98 changes: 8 additions & 90 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion eth/tracers/api_tracing_rip7560.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (api *Rip7560API) TraceRip7560Validation(
}
defer release()

vmctx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
vmctx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil, api.backend.ChainConfig(), statedb)
if err := args.CallDefaults(api.backend.RPCGasCap(), vmctx.BaseFee, api.backend.ChainConfig().ChainID); err != nil {
return nil, err
}
Expand Down
11 changes: 11 additions & 0 deletions prepare-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
VERBOSITY=${GETH_VERBOSITY:-3}

echo "
--dev
--dev.gaslimit=30000000
--http
--http.api=eth,net,web3,personal,debug
--http.port=8545
--rpc.allow-unprotected-txs
--config=circleciconfig.toml
" | pbcopy
49 changes: 49 additions & 0 deletions prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
VERBOSITY=${GETH_VERBOSITY:-3}
GETH_DATA_DIR=./db
GETH_CHAINDATA_DIR="$GETH_DATA_DIR/geth/chaindata"
GENESIS_FILE_PATH="${GENESIS_FILE_PATH:-../.devnet/genesis-l2.json}"
CHAIN_ID=$(cat "$GENESIS_FILE_PATH" | jq -r .config.chainId)
RPC_PORT="${RPC_PORT:-38545}"
WS_PORT="${WS_PORT:-38546}"

if [ ! -d "$GETH_CHAINDATA_DIR" ]; then
echo "$GETH_CHAINDATA_DIR missing, running init"
echo "Initializing genesis."
./build/bin/geth --verbosity="$VERBOSITY" init \
--state.scheme=hash \
--datadir="$GETH_DATA_DIR" \
"$GENESIS_FILE_PATH"
else
echo "$GETH_CHAINDATA_DIR exists."
fi

echo "
--datadir=$GETH_DATA_DIR
--verbosity=$VERBOSITY
--http
--http.corsdomain=*
--http.vhosts=*
--http.addr=0.0.0.0
--http.port=$RPC_PORT
--http.api=web3,debug,eth,txpool,net,engine
--ws
--ws.addr=0.0.0.0
--ws.port=$WS_PORT
--ws.origins=*
--ws.api=debug,eth,txpool,net,engine
--syncmode=full
--nodiscover
--maxpeers=0
--networkid=$CHAIN_ID
--rpc.allow-unprotected-txs
--authrpc.addr=0.0.0.0
--authrpc.port=38551
--authrpc.vhosts=*
--authrpc.jwtsecret=./config/test-jwt-secret.txt
--gcmode=archive
--metrics
--metrics.addr=0.0.0.0
--metrics.port=36060
--miner.recommit=1s
--config=circleciconfig.toml
" | pbcopy