Skip to content

feat: implement and integrate counter-based CCC #982

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

Merged
merged 31 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e844a5b
feat: add counter based CCC logger (#970)
omerfirmak Aug 13, 2024
299832d
feat: integrate one-pass-ccc to miner
omerfirmak Aug 12, 2024
d731d9c
feat: trigger reorgs on CCC failures
omerfirmak Aug 12, 2024
5f48411
fix: protect against stack underflows and out-of-bounds memory accesses
omerfirmak Aug 23, 2024
378048c
move skipped tx log
omerfirmak Aug 24, 2024
30ebf0d
feat(tx-pool): fast reject known skipped txs (#1001)
colinlyguo Aug 26, 2024
d82d719
Merge branch 'develop' into omerfirmak/reorging-worker
colinlyguo Aug 26, 2024
c1c32e7
Merge branch 'develop' into omerfirmak/reorging-worker
colinlyguo Aug 26, 2024
cfcf112
fix(async-ccc): handle empty transaction block (#1006)
colinlyguo Aug 27, 2024
d12914d
fix(worker): index out of range panic (#1008)
colinlyguo Aug 27, 2024
23f5e49
chore(libzkp): upgrade to speedup rust-ccc(poseidon) by 30% (#1009)
lispc Aug 27, 2024
003d711
Merge branch 'develop' into omerfirmak/reorging-worker
colinlyguo Aug 27, 2024
8d1422e
fix: unintentional reuse of old forkCtx
omerfirmak Aug 30, 2024
858c4cc
prioritize reorgs
omerfirmak Aug 30, 2024
90489b7
add continue
omerfirmak Aug 30, 2024
268814c
feat(counter-based ccc): add keccak (#1015)
zimpha Aug 30, 2024
cebf525
Merge branch 'develop' into omerfirmak/reorging-worker
colinlyguo Aug 30, 2024
057b2c1
feat: add an initial CCC check to block close to HEAD (#1017)
omerfirmak Aug 30, 2024
4736632
better CCC error logging
omerfirmak Sep 2, 2024
e8b4e10
fix double counting reorged gas
omerfirmak Sep 2, 2024
6abc581
make onBlockFailing callback synchronous
omerfirmak Sep 2, 2024
07f3faf
decouple Check() blocking behaviour from stream.Go()'s
omerfirmak Sep 2, 2024
3ea2c59
make double-reorgs impossible
omerfirmak Sep 3, 2024
5063695
set currentEnv to nil in snapshot
omerfirmak Sep 3, 2024
843f5fa
handle GetMemoryCopyPadded error
omerfirmak Sep 3, 2024
024a49c
remove unused return value
omerfirmak Sep 3, 2024
bec2ffe
fix wrong err check
omerfirmak Sep 3, 2024
aebc426
lower reorgCh cap
omerfirmak Sep 3, 2024
12a7d55
add a buffer to bytecode usage
omerfirmak Sep 4, 2024
21a3575
catch worker panic
omerfirmak Sep 4, 2024
98bb35d
chore: auto version bump [bot]
omerfirmak Sep 4, 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
1 change: 1 addition & 0 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
func (m callMsg) Data() []byte { return m.CallMsg.Data }
func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList }
func (m callMsg) IsL1MessageTx() bool { return false }
func (m callMsg) TxSize() common.StorageSize { return 0 }

// filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account.
Expand Down
5 changes: 5 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,11 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
if ctx.GlobalIsSet(LegacyMinerGasTargetFlag.Name) {
log.Warn("The generic --miner.gastarget flag is deprecated and will be removed in the future!")
}

cfg.CCCMaxWorkers = runtime.GOMAXPROCS(0)
if ctx.GlobalIsSet(CircuitCapacityCheckWorkersFlag.Name) {
cfg.CCCMaxWorkers = int(ctx.GlobalUint(CircuitCapacityCheckWorkersFlag.Name))
}
}

func setWhitelist(ctx *cli.Context, cfg *ethconfig.Config) {
Expand Down
8 changes: 5 additions & 3 deletions core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, chainConfig *p
// NewEVMTxContext creates a new transaction context for a single transaction.
func NewEVMTxContext(msg Message) vm.TxContext {
return vm.TxContext{
Origin: msg.From(),
To: msg.To(),
GasPrice: new(big.Int).Set(msg.GasPrice()),
Origin: msg.From(),
To: msg.To(),
GasPrice: new(big.Int).Set(msg.GasPrice()),
IsL1MessageTx: msg.IsL1MessageTx(),
TxSize: msg.TxSize(),
}
}

Expand Down
5 changes: 5 additions & 0 deletions core/rawdb/accessors_row_consumption.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ func ReadBlockRowConsumptionRLP(db ethdb.Reader, l2BlockHash common.Hash) rlp.Ra
}
return data
}

// DeleteBlockRowConsumption deletes a RowConsumption of the block from the database
func DeleteBlockRowConsumption(db ethdb.KeyValueWriter, l2BlockHash common.Hash) error {
return db.Delete(rowConsumptionKey(l2BlockHash))
}
6 changes: 6 additions & 0 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package core

import (
"errors"
"fmt"
"math/big"
"time"
Expand Down Expand Up @@ -132,6 +133,11 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon
// Apply the transaction to the current state (included in the env).
applyMessageStartTime := time.Now()
result, err := ApplyMessage(evm, msg, gp, l1DataFee)
if evm.Config.Debug {
if erroringTracer, ok := evm.Config.Tracer.(interface{ Error() error }); ok {
err = errors.Join(err, erroringTracer.Error())
}
}
applyMessageTimer.Update(time.Since(applyMessageStartTime))
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type Message interface {
Data() []byte
AccessList() types.AccessList
IsL1MessageTx() bool
TxSize() common.StorageSize
}

// ExecutionResult includes all output after executing given evm
Expand Down
27 changes: 15 additions & 12 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ type Message struct {
accessList AccessList
isFake bool
isL1MessageTx bool
txSize common.StorageSize
}

func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice, gasFeeCap, gasTipCap *big.Int, data []byte, accessList AccessList, isFake bool) Message {
Expand Down Expand Up @@ -785,6 +786,7 @@ func (tx *Transaction) AsMessage(s Signer, baseFee *big.Int) (Message, error) {
accessList: tx.AccessList(),
isFake: false,
isL1MessageTx: tx.IsL1MessageTx(),
txSize: tx.Size(),
}
// If baseFee provided, set gasPrice to effectiveGasPrice.
if baseFee != nil {
Expand All @@ -795,18 +797,19 @@ func (tx *Transaction) AsMessage(s Signer, baseFee *big.Int) (Message, error) {
return msg, err
}

func (m Message) From() common.Address { return m.from }
func (m Message) To() *common.Address { return m.to }
func (m Message) GasPrice() *big.Int { return m.gasPrice }
func (m Message) GasFeeCap() *big.Int { return m.gasFeeCap }
func (m Message) GasTipCap() *big.Int { return m.gasTipCap }
func (m Message) Value() *big.Int { return m.amount }
func (m Message) Gas() uint64 { return m.gasLimit }
func (m Message) Nonce() uint64 { return m.nonce }
func (m Message) Data() []byte { return m.data }
func (m Message) AccessList() AccessList { return m.accessList }
func (m Message) IsFake() bool { return m.isFake }
func (m Message) IsL1MessageTx() bool { return m.isL1MessageTx }
func (m Message) From() common.Address { return m.from }
func (m Message) To() *common.Address { return m.to }
func (m Message) GasPrice() *big.Int { return m.gasPrice }
func (m Message) GasFeeCap() *big.Int { return m.gasFeeCap }
func (m Message) GasTipCap() *big.Int { return m.gasTipCap }
func (m Message) Value() *big.Int { return m.amount }
func (m Message) Gas() uint64 { return m.gasLimit }
func (m Message) Nonce() uint64 { return m.nonce }
func (m Message) Data() []byte { return m.data }
func (m Message) AccessList() AccessList { return m.accessList }
func (m Message) IsFake() bool { return m.isFake }
func (m Message) IsL1MessageTx() bool { return m.isL1MessageTx }
func (m Message) TxSize() common.StorageSize { return m.txSize }

// copyAddressPtr copies an address.
func copyAddressPtr(a *common.Address) *common.Address {
Expand Down
8 changes: 5 additions & 3 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ type BlockContext struct {
// All fields can change between transactions.
type TxContext struct {
// Message information
Origin common.Address // Provides information for ORIGIN
To *common.Address // Provides information for trace
GasPrice *big.Int // Provides information for GASPRICE
Origin common.Address // Provides information for ORIGIN
To *common.Address // Provides information for trace
IsL1MessageTx bool // Provides information for trace
TxSize common.StorageSize // Provides information for trace
GasPrice *big.Int // Provides information for GASPRICE
}

// EVM is the Ethereum Virtual Machine base object and provides
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func New(stack *node.Node, config *ethconfig.Config, l1Client sync_service.EthCl
return nil, err
}
if config.CheckCircuitCapacity {
eth.asyncChecker = ccc.NewAsyncChecker(eth.blockchain, config.CCCMaxWorkers, true)
eth.asyncChecker = ccc.NewAsyncChecker(eth.blockchain, config.CCCMaxWorkers, false)
eth.asyncChecker.WithOnFailingBlock(func(b *types.Block, err error) {
log.Warn("block failed CCC check, it will be reorged by the sequencer", "hash", b.Hash(), "err", err)
})
Expand Down
1 change: 1 addition & 0 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Config struct {

StoreSkippedTxTraces bool // Whether store the wrapped traces when storing a skipped tx
MaxAccountsNum int // Maximum number of accounts that miner will fetch the pending transactions of when building a new block
CCCMaxWorkers int // Maximum number of workers to use for async CCC tasks
}

// Miner creates blocks and searches for proof-of-work values.
Expand Down
1 change: 1 addition & 0 deletions miner/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func createMiner(t *testing.T) (*Miner, *event.TypeMux) {
config := Config{
Etherbase: common.HexToAddress("123456789"),
MaxAccountsNum: math.MaxInt,
CCCMaxWorkers: 2,
}
// Create chainConfig
memdb := memorydb.New()
Expand Down
Loading
Loading