mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
refactor: rename CCC package for less repetition (#967)
This commit is contained in:
parent
3f5fb275ef
commit
2411ae063e
18 changed files with 63 additions and 1717 deletions
2
.github/workflows/l2geth_ci.yml
vendored
2
.github/workflows/l2geth_ci.yml
vendored
|
|
@ -45,7 +45,7 @@ jobs:
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
make libzkp
|
make libzkp
|
||||||
sudo cp ./rollup/circuitcapacitychecker/libzkp/libzkp.so /usr/local/lib/
|
sudo cp ./rollup/ccc/libzkp/libzkp.so /usr/local/lib/
|
||||||
make geth
|
make geth
|
||||||
check:
|
check:
|
||||||
if: github.event.pull_request.draft == false
|
if: github.event.pull_request.draft == false
|
||||||
|
|
|
||||||
|
|
@ -9,15 +9,15 @@ FROM scrolltech/go-rust-builder:go-1.21-rust-nightly-2023-12-03 as chef
|
||||||
WORKDIR app
|
WORKDIR app
|
||||||
|
|
||||||
FROM chef as planner
|
FROM chef as planner
|
||||||
COPY ./rollup/circuitcapacitychecker/libzkp/ .
|
COPY ./rollup/ccc/libzkp/ .
|
||||||
RUN cargo chef prepare --recipe-path recipe.json
|
RUN cargo chef prepare --recipe-path recipe.json
|
||||||
|
|
||||||
FROM chef as zkp-builder
|
FROM chef as zkp-builder
|
||||||
COPY ./rollup/circuitcapacitychecker/libzkp/rust-toolchain ./
|
COPY ./rollup/ccc/libzkp/rust-toolchain ./
|
||||||
COPY --from=planner /app/recipe.json recipe.json
|
COPY --from=planner /app/recipe.json recipe.json
|
||||||
RUN cargo chef cook --release --recipe-path recipe.json
|
RUN cargo chef cook --release --recipe-path recipe.json
|
||||||
|
|
||||||
COPY ./rollup/circuitcapacitychecker/libzkp .
|
COPY ./rollup/ccc/libzkp .
|
||||||
RUN cargo clean
|
RUN cargo clean
|
||||||
RUN cargo build --release
|
RUN cargo build --release
|
||||||
|
|
||||||
|
|
|
||||||
2
Makefile
2
Makefile
|
|
@ -9,7 +9,7 @@ GO ?= latest
|
||||||
GORUN = env GO111MODULE=on go run
|
GORUN = env GO111MODULE=on go run
|
||||||
|
|
||||||
libzkp:
|
libzkp:
|
||||||
cd $(PWD)/rollup/circuitcapacitychecker/libzkp && make libzkp
|
cd $(PWD)/rollup/ccc/libzkp && make libzkp
|
||||||
|
|
||||||
nccc_geth: ## geth without circuit capacity checker
|
nccc_geth: ## geth without circuit capacity checker
|
||||||
$(GORUN) build/ci.go install ./cmd/geth
|
$(GORUN) build/ci.go install ./cmd/geth
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import (
|
||||||
"github.com/scroll-tech/go-ethereum/log"
|
"github.com/scroll-tech/go-ethereum/log"
|
||||||
"github.com/scroll-tech/go-ethereum/metrics"
|
"github.com/scroll-tech/go-ethereum/metrics"
|
||||||
"github.com/scroll-tech/go-ethereum/params"
|
"github.com/scroll-tech/go-ethereum/params"
|
||||||
"github.com/scroll-tech/go-ethereum/rollup/circuitcapacitychecker"
|
"github.com/scroll-tech/go-ethereum/rollup/ccc"
|
||||||
"github.com/scroll-tech/go-ethereum/trie"
|
"github.com/scroll-tech/go-ethereum/trie"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -55,7 +55,7 @@ type BlockValidator struct {
|
||||||
checkCircuitCapacity bool // whether enable circuit capacity check
|
checkCircuitCapacity bool // whether enable circuit capacity check
|
||||||
cMu sync.Mutex // mutex for circuit capacity checker
|
cMu sync.Mutex // mutex for circuit capacity checker
|
||||||
tracer tracerWrapper // scroll tracer wrapper
|
tracer tracerWrapper // scroll tracer wrapper
|
||||||
circuitCapacityChecker *circuitcapacitychecker.CircuitCapacityChecker // circuit capacity checker instance
|
circuitCapacityChecker *ccc.Checker // circuit capacity checker instance
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBlockValidator returns a new block validator which is safe for re-use
|
// NewBlockValidator returns a new block validator which is safe for re-use
|
||||||
|
|
@ -75,7 +75,7 @@ type tracerWrapper interface {
|
||||||
func (v *BlockValidator) SetupTracerAndCircuitCapacityChecker(tracer tracerWrapper) {
|
func (v *BlockValidator) SetupTracerAndCircuitCapacityChecker(tracer tracerWrapper) {
|
||||||
v.checkCircuitCapacity = true
|
v.checkCircuitCapacity = true
|
||||||
v.tracer = tracer
|
v.tracer = tracer
|
||||||
v.circuitCapacityChecker = circuitcapacitychecker.NewCircuitCapacityChecker(true)
|
v.circuitCapacityChecker = ccc.NewChecker(true)
|
||||||
log.Info("new CircuitCapacityChecker in BlockValidator", "ID", v.circuitCapacityChecker.ID)
|
log.Info("new CircuitCapacityChecker in BlockValidator", "ID", v.circuitCapacityChecker.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ import (
|
||||||
"github.com/scroll-tech/go-ethereum/log"
|
"github.com/scroll-tech/go-ethereum/log"
|
||||||
"github.com/scroll-tech/go-ethereum/metrics"
|
"github.com/scroll-tech/go-ethereum/metrics"
|
||||||
"github.com/scroll-tech/go-ethereum/params"
|
"github.com/scroll-tech/go-ethereum/params"
|
||||||
"github.com/scroll-tech/go-ethereum/rollup/circuitcapacitychecker"
|
"github.com/scroll-tech/go-ethereum/rollup/ccc"
|
||||||
"github.com/scroll-tech/go-ethereum/rollup/fees"
|
"github.com/scroll-tech/go-ethereum/rollup/fees"
|
||||||
"github.com/scroll-tech/go-ethereum/rollup/pipeline"
|
"github.com/scroll-tech/go-ethereum/rollup/pipeline"
|
||||||
"github.com/scroll-tech/go-ethereum/trie"
|
"github.com/scroll-tech/go-ethereum/trie"
|
||||||
|
|
@ -128,7 +128,7 @@ type worker struct {
|
||||||
// External functions
|
// External functions
|
||||||
isLocalBlock func(block *types.Block) bool // Function used to determine whether the specified block is mined by local miner.
|
isLocalBlock func(block *types.Block) bool // Function used to determine whether the specified block is mined by local miner.
|
||||||
|
|
||||||
circuitCapacityChecker *circuitcapacitychecker.CircuitCapacityChecker
|
circuitCapacityChecker *ccc.Checker
|
||||||
prioritizedTx *prioritizedTransaction
|
prioritizedTx *prioritizedTransaction
|
||||||
|
|
||||||
// Test hooks
|
// Test hooks
|
||||||
|
|
@ -148,7 +148,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
|
||||||
chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
|
chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
|
||||||
exitCh: make(chan struct{}),
|
exitCh: make(chan struct{}),
|
||||||
startCh: make(chan struct{}, 1),
|
startCh: make(chan struct{}, 1),
|
||||||
circuitCapacityChecker: circuitcapacitychecker.NewCircuitCapacityChecker(true),
|
circuitCapacityChecker: ccc.NewChecker(true),
|
||||||
}
|
}
|
||||||
log.Info("created new worker", "CircuitCapacityChecker ID", worker.circuitCapacityChecker.ID)
|
log.Info("created new worker", "CircuitCapacityChecker ID", worker.circuitCapacityChecker.ID)
|
||||||
|
|
||||||
|
|
@ -176,7 +176,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
|
||||||
|
|
||||||
// getCCC returns a pointer to this worker's CCC instance.
|
// getCCC returns a pointer to this worker's CCC instance.
|
||||||
// Only used in tests.
|
// Only used in tests.
|
||||||
func (w *worker) getCCC() *circuitcapacitychecker.CircuitCapacityChecker {
|
func (w *worker) getCCC() *ccc.Checker {
|
||||||
return w.circuitCapacityChecker
|
return w.circuitCapacityChecker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -586,16 +586,16 @@ func (w *worker) handlePipelineResult(res *pipeline.Result) error {
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case res.OverflowingTx.IsL1MessageTx() &&
|
case res.OverflowingTx.IsL1MessageTx() &&
|
||||||
errors.Is(res.CCCErr, circuitcapacitychecker.ErrBlockRowConsumptionOverflow):
|
errors.Is(res.CCCErr, ccc.ErrBlockRowConsumptionOverflow):
|
||||||
l1TxRowConsumptionOverflowCounter.Inc(1)
|
l1TxRowConsumptionOverflowCounter.Inc(1)
|
||||||
case !res.OverflowingTx.IsL1MessageTx() &&
|
case !res.OverflowingTx.IsL1MessageTx() &&
|
||||||
errors.Is(res.CCCErr, circuitcapacitychecker.ErrBlockRowConsumptionOverflow):
|
errors.Is(res.CCCErr, ccc.ErrBlockRowConsumptionOverflow):
|
||||||
l2TxRowConsumptionOverflowCounter.Inc(1)
|
l2TxRowConsumptionOverflowCounter.Inc(1)
|
||||||
case res.OverflowingTx.IsL1MessageTx() &&
|
case res.OverflowingTx.IsL1MessageTx() &&
|
||||||
errors.Is(res.CCCErr, circuitcapacitychecker.ErrUnknown):
|
errors.Is(res.CCCErr, ccc.ErrUnknown):
|
||||||
l1TxCccUnknownErrCounter.Inc(1)
|
l1TxCccUnknownErrCounter.Inc(1)
|
||||||
case !res.OverflowingTx.IsL1MessageTx() &&
|
case !res.OverflowingTx.IsL1MessageTx() &&
|
||||||
errors.Is(res.CCCErr, circuitcapacitychecker.ErrUnknown):
|
errors.Is(res.CCCErr, ccc.ErrUnknown):
|
||||||
l2TxCccUnknownErrCounter.Inc(1)
|
l2TxCccUnknownErrCounter.Inc(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ import (
|
||||||
"github.com/scroll-tech/go-ethereum/ethdb"
|
"github.com/scroll-tech/go-ethereum/ethdb"
|
||||||
"github.com/scroll-tech/go-ethereum/event"
|
"github.com/scroll-tech/go-ethereum/event"
|
||||||
"github.com/scroll-tech/go-ethereum/params"
|
"github.com/scroll-tech/go-ethereum/params"
|
||||||
"github.com/scroll-tech/go-ethereum/rollup/circuitcapacitychecker"
|
"github.com/scroll-tech/go-ethereum/rollup/ccc"
|
||||||
"github.com/scroll-tech/go-ethereum/rollup/sync_service"
|
"github.com/scroll-tech/go-ethereum/rollup/sync_service"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -788,7 +788,7 @@ func TestOversizedTxThenNormal(t *testing.T) {
|
||||||
switch blockNum {
|
switch blockNum {
|
||||||
case 0:
|
case 0:
|
||||||
// schedule to skip 2nd call to ccc
|
// schedule to skip 2nd call to ccc
|
||||||
w.getCCC().ScheduleError(2, circuitcapacitychecker.ErrBlockRowConsumptionOverflow)
|
w.getCCC().ScheduleError(2, ccc.ErrBlockRowConsumptionOverflow)
|
||||||
return false
|
return false
|
||||||
case 1:
|
case 1:
|
||||||
// include #0, fail on #1, then seal the block
|
// include #0, fail on #1, then seal the block
|
||||||
|
|
@ -803,7 +803,7 @@ func TestOversizedTxThenNormal(t *testing.T) {
|
||||||
assert.Equal(uint64(1), *queueIndex)
|
assert.Equal(uint64(1), *queueIndex)
|
||||||
|
|
||||||
// schedule to skip next call to ccc
|
// schedule to skip next call to ccc
|
||||||
w.getCCC().ScheduleError(1, circuitcapacitychecker.ErrBlockRowConsumptionOverflow)
|
w.getCCC().ScheduleError(1, ccc.ErrBlockRowConsumptionOverflow)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
case 2:
|
case 2:
|
||||||
|
|
@ -869,7 +869,7 @@ func TestPrioritizeOverflowTx(t *testing.T) {
|
||||||
|
|
||||||
// Process 2 transactions with gas order: tx0 > tx1, tx1 will overflow.
|
// Process 2 transactions with gas order: tx0 > tx1, tx1 will overflow.
|
||||||
b.txPool.AddRemotesSync([]*types.Transaction{tx0, tx1})
|
b.txPool.AddRemotesSync([]*types.Transaction{tx0, tx1})
|
||||||
w.getCCC().ScheduleError(2, circuitcapacitychecker.ErrBlockRowConsumptionOverflow)
|
w.getCCC().ScheduleError(2, ccc.ErrBlockRowConsumptionOverflow)
|
||||||
w.start()
|
w.start()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
|
@ -903,7 +903,7 @@ func TestPrioritizeOverflowTx(t *testing.T) {
|
||||||
t.Fatalf("timeout")
|
t.Fatalf("timeout")
|
||||||
}
|
}
|
||||||
|
|
||||||
w.getCCC().Skip(tx4.Hash(), circuitcapacitychecker.ErrBlockRowConsumptionOverflow)
|
w.getCCC().Skip(tx4.Hash(), ccc.ErrBlockRowConsumptionOverflow)
|
||||||
assert.Equal([]error{nil, nil, nil}, b.txPool.AddRemotesSync([]*types.Transaction{tx3, tx4, tx5}))
|
assert.Equal([]error{nil, nil, nil}, b.txPool.AddRemotesSync([]*types.Transaction{tx3, tx4, tx5}))
|
||||||
|
|
||||||
w.start()
|
w.start()
|
||||||
|
|
|
||||||
1654
miner/worker.go
1654
miner/worker.go
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
||||||
//go:build circuit_capacity_checker
|
//go:build circuit_capacity_checker
|
||||||
|
|
||||||
package circuitcapacitychecker
|
package ccc
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo LDFLAGS: -lm -ldl -lzkp
|
#cgo LDFLAGS: -lm -ldl -lzkp
|
||||||
|
|
@ -22,7 +22,7 @@ import (
|
||||||
"github.com/scroll-tech/go-ethereum/metrics"
|
"github.com/scroll-tech/go-ethereum/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
// mutex for concurrent CircuitCapacityChecker creations
|
// mutex for concurrent Checker creations
|
||||||
var (
|
var (
|
||||||
creationMu sync.Mutex
|
creationMu sync.Mutex
|
||||||
encodeTimer = metrics.NewRegisteredTimer("ccc/encode", nil)
|
encodeTimer = metrics.NewRegisteredTimer("ccc/encode", nil)
|
||||||
|
|
@ -32,26 +32,26 @@ func init() {
|
||||||
C.init()
|
C.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
type CircuitCapacityChecker struct {
|
type Checker struct {
|
||||||
// mutex for each CircuitCapacityChecker itself
|
// mutex for each Checker itself
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
ID uint64
|
ID uint64
|
||||||
jsonBuffer bytes.Buffer
|
jsonBuffer bytes.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCircuitCapacityChecker creates a new CircuitCapacityChecker
|
// NewChecker creates a new Checker
|
||||||
func NewCircuitCapacityChecker(lightMode bool) *CircuitCapacityChecker {
|
func NewChecker(lightMode bool) *Checker {
|
||||||
creationMu.Lock()
|
creationMu.Lock()
|
||||||
defer creationMu.Unlock()
|
defer creationMu.Unlock()
|
||||||
|
|
||||||
id := C.new_circuit_capacity_checker()
|
id := C.new_circuit_capacity_checker()
|
||||||
ccc := &CircuitCapacityChecker{ID: uint64(id)}
|
ccc := &Checker{ID: uint64(id)}
|
||||||
ccc.SetLightMode(lightMode)
|
ccc.SetLightMode(lightMode)
|
||||||
return ccc
|
return ccc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset resets a CircuitCapacityChecker
|
// Reset resets a CircuitCapacityChecker
|
||||||
func (ccc *CircuitCapacityChecker) Reset() {
|
func (ccc *Checker) Reset() {
|
||||||
ccc.Lock()
|
ccc.Lock()
|
||||||
defer ccc.Unlock()
|
defer ccc.Unlock()
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ func (ccc *CircuitCapacityChecker) Reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyTransaction appends a tx's wrapped BlockTrace into the ccc, and return the accumulated RowConsumption
|
// ApplyTransaction appends a tx's wrapped BlockTrace into the ccc, and return the accumulated RowConsumption
|
||||||
func (ccc *CircuitCapacityChecker) ApplyTransaction(traces *types.BlockTrace) (*types.RowConsumption, error) {
|
func (ccc *Checker) ApplyTransaction(traces *types.BlockTrace) (*types.RowConsumption, error) {
|
||||||
ccc.Lock()
|
ccc.Lock()
|
||||||
defer ccc.Unlock()
|
defer ccc.Unlock()
|
||||||
|
|
||||||
|
|
@ -84,13 +84,13 @@ func (ccc *CircuitCapacityChecker) ApplyTransaction(traces *types.BlockTrace) (*
|
||||||
return ccc.applyTransactionRustTrace(rustTrace)
|
return ccc.applyTransactionRustTrace(rustTrace)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ccc *CircuitCapacityChecker) ApplyTransactionRustTrace(rustTrace unsafe.Pointer) (*types.RowConsumption, error) {
|
func (ccc *Checker) ApplyTransactionRustTrace(rustTrace unsafe.Pointer) (*types.RowConsumption, error) {
|
||||||
ccc.Lock()
|
ccc.Lock()
|
||||||
defer ccc.Unlock()
|
defer ccc.Unlock()
|
||||||
return ccc.applyTransactionRustTrace(rustTrace)
|
return ccc.applyTransactionRustTrace(rustTrace)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ccc *CircuitCapacityChecker) applyTransactionRustTrace(rustTrace unsafe.Pointer) (*types.RowConsumption, error) {
|
func (ccc *Checker) applyTransactionRustTrace(rustTrace unsafe.Pointer) (*types.RowConsumption, error) {
|
||||||
rawResult := C.apply_tx(C.uint64_t(ccc.ID), rustTrace)
|
rawResult := C.apply_tx(C.uint64_t(ccc.ID), rustTrace)
|
||||||
defer func() {
|
defer func() {
|
||||||
C.free_c_chars(rawResult)
|
C.free_c_chars(rawResult)
|
||||||
|
|
@ -103,11 +103,11 @@ func (ccc *CircuitCapacityChecker) applyTransactionRustTrace(rustTrace unsafe.Po
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.Error != "" {
|
if result.Error != "" {
|
||||||
log.Error("fail to apply_tx in CircuitCapacityChecker", "id", ccc.ID, "err", result.Error)
|
log.Error("fail to apply_tx in Checker", "id", ccc.ID, "err", result.Error)
|
||||||
return nil, ErrUnknown
|
return nil, ErrUnknown
|
||||||
}
|
}
|
||||||
if result.AccRowUsage == nil {
|
if result.AccRowUsage == nil {
|
||||||
log.Error("fail to apply_tx in CircuitCapacityChecker",
|
log.Error("fail to apply_tx in Checker",
|
||||||
"id", ccc.ID, "result.AccRowUsage == nil", result.AccRowUsage == nil,
|
"id", ccc.ID, "result.AccRowUsage == nil", result.AccRowUsage == nil,
|
||||||
"err", "AccRowUsage is empty unexpectedly")
|
"err", "AccRowUsage is empty unexpectedly")
|
||||||
return nil, ErrUnknown
|
return nil, ErrUnknown
|
||||||
|
|
@ -119,7 +119,7 @@ func (ccc *CircuitCapacityChecker) applyTransactionRustTrace(rustTrace unsafe.Po
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyBlock gets a block's RowConsumption
|
// ApplyBlock gets a block's RowConsumption
|
||||||
func (ccc *CircuitCapacityChecker) ApplyBlock(traces *types.BlockTrace) (*types.RowConsumption, error) {
|
func (ccc *Checker) ApplyBlock(traces *types.BlockTrace) (*types.RowConsumption, error) {
|
||||||
ccc.Lock()
|
ccc.Lock()
|
||||||
defer ccc.Unlock()
|
defer ccc.Unlock()
|
||||||
|
|
||||||
|
|
@ -145,11 +145,11 @@ func (ccc *CircuitCapacityChecker) ApplyBlock(traces *types.BlockTrace) (*types.
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.Error != "" {
|
if result.Error != "" {
|
||||||
log.Error("fail to apply_block in CircuitCapacityChecker", "id", ccc.ID, "blockNumber", traces.Header.Number, "blockHash", traces.Header.Hash(), "err", result.Error)
|
log.Error("fail to apply_block in Checker", "id", ccc.ID, "blockNumber", traces.Header.Number, "blockHash", traces.Header.Hash(), "err", result.Error)
|
||||||
return nil, ErrUnknown
|
return nil, ErrUnknown
|
||||||
}
|
}
|
||||||
if result.AccRowUsage == nil {
|
if result.AccRowUsage == nil {
|
||||||
log.Error("fail to apply_block in CircuitCapacityChecker", "id", ccc.ID, "blockNumber", traces.Header.Number, "blockHash", traces.Header.Hash(), "err", "AccRowUsage is empty unexpectedly")
|
log.Error("fail to apply_block in Checker", "id", ccc.ID, "blockNumber", traces.Header.Number, "blockHash", traces.Header.Hash(), "err", "AccRowUsage is empty unexpectedly")
|
||||||
return nil, ErrUnknown
|
return nil, ErrUnknown
|
||||||
}
|
}
|
||||||
if !result.AccRowUsage.IsOk {
|
if !result.AccRowUsage.IsOk {
|
||||||
|
|
@ -159,7 +159,7 @@ func (ccc *CircuitCapacityChecker) ApplyBlock(traces *types.BlockTrace) (*types.
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckTxNum compares whether the tx_count in ccc match the expected
|
// CheckTxNum compares whether the tx_count in ccc match the expected
|
||||||
func (ccc *CircuitCapacityChecker) CheckTxNum(expected int) (bool, uint64, error) {
|
func (ccc *Checker) CheckTxNum(expected int) (bool, uint64, error) {
|
||||||
ccc.Lock()
|
ccc.Lock()
|
||||||
defer ccc.Unlock()
|
defer ccc.Unlock()
|
||||||
|
|
||||||
|
|
@ -182,7 +182,7 @@ func (ccc *CircuitCapacityChecker) CheckTxNum(expected int) (bool, uint64, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLightMode sets to ccc light mode
|
// SetLightMode sets to ccc light mode
|
||||||
func (ccc *CircuitCapacityChecker) SetLightMode(lightMode bool) error {
|
func (ccc *Checker) SetLightMode(lightMode bool) error {
|
||||||
ccc.Lock()
|
ccc.Lock()
|
||||||
defer ccc.Unlock()
|
defer ccc.Unlock()
|
||||||
|
|
||||||
|
|
@ -198,7 +198,7 @@ func (ccc *CircuitCapacityChecker) SetLightMode(lightMode bool) error {
|
||||||
return fmt.Errorf("fail to json unmarshal set_light_mode result, id: %d, err: %w", ccc.ID, err)
|
return fmt.Errorf("fail to json unmarshal set_light_mode result, id: %d, err: %w", ccc.ID, err)
|
||||||
}
|
}
|
||||||
if result.Error != "" {
|
if result.Error != "" {
|
||||||
return fmt.Errorf("fail to set_light_mode in CircuitCapacityChecker, id: %d, err: %w", ccc.ID, result.Error)
|
return fmt.Errorf("fail to set_light_mode in Checker, id: %d, err: %w", ccc.ID, result.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
//go:build !circuit_capacity_checker
|
//go:build !circuit_capacity_checker
|
||||||
|
|
||||||
package circuitcapacitychecker
|
package ccc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/scroll-tech/go-ethereum/core/types"
|
"github.com/scroll-tech/go-ethereum/core/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CircuitCapacityChecker struct {
|
type Checker struct {
|
||||||
ID uint64
|
ID uint64
|
||||||
countdown int
|
countdown int
|
||||||
nextError *error
|
nextError *error
|
||||||
|
|
@ -20,20 +20,20 @@ type CircuitCapacityChecker struct {
|
||||||
skipError error
|
skipError error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCircuitCapacityChecker creates a new CircuitCapacityChecker
|
// NewChecker creates a new Checker
|
||||||
func NewCircuitCapacityChecker(lightMode bool) *CircuitCapacityChecker {
|
func NewChecker(lightMode bool) *Checker {
|
||||||
ccc := &CircuitCapacityChecker{ID: rand.Uint64()}
|
ccc := &Checker{ID: rand.Uint64()}
|
||||||
ccc.SetLightMode(lightMode)
|
ccc.SetLightMode(lightMode)
|
||||||
return ccc
|
return ccc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset resets a ccc, but need to do nothing in mock_ccc.
|
// Reset resets a ccc, but need to do nothing in mock_ccc.
|
||||||
func (ccc *CircuitCapacityChecker) Reset() {
|
func (ccc *Checker) Reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyTransaction appends a tx's wrapped BlockTrace into the ccc, and return the accumulated RowConsumption.
|
// ApplyTransaction appends a tx's wrapped BlockTrace into the ccc, and return the accumulated RowConsumption.
|
||||||
// Will only return a dummy value in mock_ccc.
|
// Will only return a dummy value in mock_ccc.
|
||||||
func (ccc *CircuitCapacityChecker) ApplyTransaction(traces *types.BlockTrace) (*types.RowConsumption, error) {
|
func (ccc *Checker) ApplyTransaction(traces *types.BlockTrace) (*types.RowConsumption, error) {
|
||||||
if ccc.nextError != nil {
|
if ccc.nextError != nil {
|
||||||
ccc.countdown--
|
ccc.countdown--
|
||||||
if ccc.countdown == 0 {
|
if ccc.countdown == 0 {
|
||||||
|
|
@ -53,13 +53,13 @@ func (ccc *CircuitCapacityChecker) ApplyTransaction(traces *types.BlockTrace) (*
|
||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ccc *CircuitCapacityChecker) ApplyTransactionRustTrace(rustTrace unsafe.Pointer) (*types.RowConsumption, error) {
|
func (ccc *Checker) ApplyTransactionRustTrace(rustTrace unsafe.Pointer) (*types.RowConsumption, error) {
|
||||||
return ccc.ApplyTransaction(goTraces[rustTrace])
|
return ccc.ApplyTransaction(goTraces[rustTrace])
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyBlock gets a block's RowConsumption.
|
// ApplyBlock gets a block's RowConsumption.
|
||||||
// Will only return a dummy value in mock_ccc.
|
// Will only return a dummy value in mock_ccc.
|
||||||
func (ccc *CircuitCapacityChecker) ApplyBlock(traces *types.BlockTrace) (*types.RowConsumption, error) {
|
func (ccc *Checker) ApplyBlock(traces *types.BlockTrace) (*types.RowConsumption, error) {
|
||||||
return &types.RowConsumption{types.SubCircuitRowUsage{
|
return &types.RowConsumption{types.SubCircuitRowUsage{
|
||||||
Name: "mock",
|
Name: "mock",
|
||||||
RowNumber: 2,
|
RowNumber: 2,
|
||||||
|
|
@ -68,23 +68,23 @@ func (ccc *CircuitCapacityChecker) ApplyBlock(traces *types.BlockTrace) (*types.
|
||||||
|
|
||||||
// CheckTxNum compares whether the tx_count in ccc match the expected.
|
// CheckTxNum compares whether the tx_count in ccc match the expected.
|
||||||
// Will alway return true in mock_ccc.
|
// Will alway return true in mock_ccc.
|
||||||
func (ccc *CircuitCapacityChecker) CheckTxNum(expected int) (bool, uint64, error) {
|
func (ccc *Checker) CheckTxNum(expected int) (bool, uint64, error) {
|
||||||
return true, uint64(expected), nil
|
return true, uint64(expected), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLightMode sets to ccc light mode
|
// SetLightMode sets to ccc light mode
|
||||||
func (ccc *CircuitCapacityChecker) SetLightMode(lightMode bool) error {
|
func (ccc *Checker) SetLightMode(lightMode bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScheduleError schedules an error for a tx (see `ApplyTransaction`), only used in tests.
|
// ScheduleError schedules an error for a tx (see `ApplyTransaction`), only used in tests.
|
||||||
func (ccc *CircuitCapacityChecker) ScheduleError(cnt int, err error) {
|
func (ccc *Checker) ScheduleError(cnt int, err error) {
|
||||||
ccc.countdown = cnt
|
ccc.countdown = cnt
|
||||||
ccc.nextError = &err
|
ccc.nextError = &err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip forced CCC to return always an error for a given txn
|
// Skip forced CCC to return always an error for a given txn
|
||||||
func (ccc *CircuitCapacityChecker) Skip(txnHash common.Hash, err error) {
|
func (ccc *Checker) Skip(txnHash common.Hash, err error) {
|
||||||
ccc.skipHash = txnHash.String()
|
ccc.skipHash = txnHash.String()
|
||||||
ccc.skipError = err
|
ccc.skipError = err
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package circuitcapacitychecker
|
package ccc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
@ -16,7 +16,7 @@ import (
|
||||||
"github.com/scroll-tech/go-ethereum/log"
|
"github.com/scroll-tech/go-ethereum/log"
|
||||||
"github.com/scroll-tech/go-ethereum/metrics"
|
"github.com/scroll-tech/go-ethereum/metrics"
|
||||||
"github.com/scroll-tech/go-ethereum/params"
|
"github.com/scroll-tech/go-ethereum/params"
|
||||||
"github.com/scroll-tech/go-ethereum/rollup/circuitcapacitychecker"
|
"github.com/scroll-tech/go-ethereum/rollup/ccc"
|
||||||
"github.com/scroll-tech/go-ethereum/rollup/tracing"
|
"github.com/scroll-tech/go-ethereum/rollup/tracing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -62,7 +62,7 @@ type Pipeline struct {
|
||||||
cancelCtx context.CancelFunc
|
cancelCtx context.CancelFunc
|
||||||
|
|
||||||
// accumulators
|
// accumulators
|
||||||
ccc *circuitcapacitychecker.CircuitCapacityChecker
|
ccc *ccc.Checker
|
||||||
Header types.Header
|
Header types.Header
|
||||||
state *state.StateDB
|
state *state.StateDB
|
||||||
nextL1MsgIndex uint64
|
nextL1MsgIndex uint64
|
||||||
|
|
@ -88,7 +88,7 @@ func NewPipeline(
|
||||||
|
|
||||||
header *types.Header,
|
header *types.Header,
|
||||||
nextL1MsgIndex uint64,
|
nextL1MsgIndex uint64,
|
||||||
ccc *circuitcapacitychecker.CircuitCapacityChecker,
|
ccc *ccc.Checker,
|
||||||
) *Pipeline {
|
) *Pipeline {
|
||||||
// make sure we are not sharing a tracer with the caller and not in debug mode
|
// make sure we are not sharing a tracer with the caller and not in debug mode
|
||||||
vmConfig.Tracer = nil
|
vmConfig.Tracer = nil
|
||||||
|
|
@ -359,7 +359,7 @@ func (p *Pipeline) encodeStage(traces <-chan *BlockCandidate) <-chan *BlockCandi
|
||||||
|
|
||||||
encodeStart := time.Now()
|
encodeStart := time.Now()
|
||||||
if p.ccc != nil {
|
if p.ccc != nil {
|
||||||
trace.RustTrace = circuitcapacitychecker.MakeRustTrace(trace.LastTrace, buffer)
|
trace.RustTrace = ccc.MakeRustTrace(trace.LastTrace, buffer)
|
||||||
if trace.RustTrace == nil {
|
if trace.RustTrace == nil {
|
||||||
log.Error("making rust trace", "txHash", trace.LastTrace.Transactions[0].TxHash)
|
log.Error("making rust trace", "txHash", trace.LastTrace.Transactions[0].TxHash)
|
||||||
// ignore the error here, CCC stage will catch it and treat it as a CCC error
|
// ignore the error here, CCC stage will catch it and treat it as a CCC error
|
||||||
|
|
@ -370,7 +370,7 @@ func (p *Pipeline) encodeStage(traces <-chan *BlockCandidate) <-chan *BlockCandi
|
||||||
stallStart := time.Now()
|
stallStart := time.Now()
|
||||||
if sendCancellable(downstreamCh, trace, p.ctx.Done()) && trace.RustTrace != nil {
|
if sendCancellable(downstreamCh, trace, p.ctx.Done()) && trace.RustTrace != nil {
|
||||||
// failed to send the trace downstream, free it here.
|
// failed to send the trace downstream, free it here.
|
||||||
circuitcapacitychecker.FreeRustTrace(trace.RustTrace)
|
ccc.FreeRustTrace(trace.RustTrace)
|
||||||
}
|
}
|
||||||
encodeStallTimer.UpdateSince(stallStart)
|
encodeStallTimer.UpdateSince(stallStart)
|
||||||
case <-p.ctx.Done():
|
case <-p.ctx.Done():
|
||||||
|
|
@ -404,7 +404,7 @@ func (p *Pipeline) cccStage(candidates <-chan *BlockCandidate, deadline time.Tim
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if candidate.RustTrace != nil {
|
if candidate.RustTrace != nil {
|
||||||
circuitcapacitychecker.FreeRustTrace(candidate.RustTrace)
|
ccc.FreeRustTrace(candidate.RustTrace)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.wg.Done()
|
p.wg.Done()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue