From dece2fa8af7e640e348c6f49b95ae4f45f0c5da6 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Date: Sat, 10 Aug 2024 17:41:22 +0800 Subject: [PATCH] refactor: rename CCC package for less repetition (#976) * rename `circuitcapacitychecker` to `ccc` * rename `CircuitCapacityChecker` to `Checker` * rename `NewCircuitCapacityChecker` to `NewChecker` * fix * raname `circuits_capacity_checker` to `ccc` * clean up libzktrie --- .github/workflows/ci.yml | 3 +- Dockerfile | 8 ++-- Makefile | 4 +- core/block_validator.go | 14 +++--- core/types.go | 2 +- miner/scroll_worker.go | 18 ++++---- miner/worker.go | 16 +++---- .../{circuitcapacitychecker => ccc}/impl.go | 44 +++++++++---------- .../libzkp/.gitignore | 0 .../libzkp/Cargo.lock | 0 .../libzkp/Cargo.toml | 0 .../libzkp/Makefile | 0 .../libzkp/libzkp.h | 0 .../libzkp/rust-toolchain | 0 .../libzkp/src/lib.rs | 0 .../{circuitcapacitychecker => ccc}/mock.go | 28 ++++++------ .../{circuitcapacitychecker => ccc}/types.go | 2 +- rollup/pipeline/pipeline.go | 12 ++--- 18 files changed, 75 insertions(+), 76 deletions(-) rename rollup/{circuitcapacitychecker => ccc}/impl.go (75%) rename rollup/{circuitcapacitychecker => ccc}/libzkp/.gitignore (100%) rename rollup/{circuitcapacitychecker => ccc}/libzkp/Cargo.lock (100%) rename rollup/{circuitcapacitychecker => ccc}/libzkp/Cargo.toml (100%) rename rollup/{circuitcapacitychecker => ccc}/libzkp/Makefile (100%) rename rollup/{circuitcapacitychecker => ccc}/libzkp/libzkp.h (100%) rename rollup/{circuitcapacitychecker => ccc}/libzkp/rust-toolchain (100%) rename rollup/{circuitcapacitychecker => ccc}/libzkp/src/lib.rs (100%) rename rollup/{circuitcapacitychecker => ccc}/mock.go (65%) rename rollup/{circuitcapacitychecker => ccc}/types.go (94%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e150254462..5bcb4e8daf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,8 +46,7 @@ jobs: - name: Build run: | make libzkp - sudo cp ./rollup/circuitcapacitychecker/libzkp/libzkp.so /usr/local/lib/ - sudo cp ./rollup/circuitcapacitychecker/libzkp/libzktrie.so /usr/local/lib/ + sudo cp ./rollup/ccc/libzkp/libzkp.so /usr/local/lib/ make geth # check: # if: github.event.pull_request.draft == false diff --git a/Dockerfile b/Dockerfile index 4398975c16..fac744875c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,15 +8,15 @@ FROM scrolltech/go-rust-builder:go-1.21-rust-nightly-2023-12-03 as chef WORKDIR app FROM chef as planner -COPY ./rollup/circuitcapacitychecker/libzkp/ . +COPY ./rollup/ccc/libzkp/ . RUN cargo chef prepare --recipe-path recipe.json 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 RUN cargo chef cook --release --recipe-path recipe.json -COPY ./rollup/circuitcapacitychecker/libzkp . +COPY ./rollup/ccc/libzkp . RUN cargo clean RUN cargo build --release @@ -31,7 +31,7 @@ RUN cd /go-ethereum && go mod download ADD . /go-ethereum COPY --from=zkp-builder /app/target/release/libzkp.so /usr/local/lib/ ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/ -RUN cd /go-ethereum && go run build/ci.go install -tags circuit_capacity_checker ./cmd/geth +RUN cd /go-ethereum && go run build/ci.go install -tags ccc ./cmd/geth # Pull Geth into a second stage deploy container FROM ubuntu:20.04 diff --git a/Makefile b/Makefile index f893408554..f8da14ffc5 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ GO ?= latest GORUN = go run libzkp: - cd $(PWD)/rollup/circuitcapacitychecker/libzkp && make libzkp + cd $(PWD)/rollup/ccc/libzkp && make libzkp nccc_geth: ## geth without circuit capacity checker $(GORUN) build/ci.go install ./cmd/geth @@ -17,7 +17,7 @@ nccc_geth: ## geth without circuit capacity checker @echo "Run \"$(GOBIN)/geth\" to launch geth." geth: libzkp ## geth with circuit capacity checker - $(GORUN) build/ci.go install -tags circuit_capacity_checker ./cmd/geth + $(GORUN) build/ci.go install -tags ccc ./cmd/geth @echo "Done building." @echo "Run \"$(GOBIN)/geth\" to launch geth." diff --git a/core/block_validator.go b/core/block_validator.go index 3f6ee5c7b3..a4ce1b201f 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -30,7 +30,7 @@ import ( "github.com/scroll-tech/go-ethereum/log" "github.com/scroll-tech/go-ethereum/metrics" "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" ) @@ -52,10 +52,10 @@ type BlockValidator struct { engine consensus.Engine // Consensus engine used for validating // circuit capacity checker related fields - checkCircuitCapacity bool // whether enable circuit capacity check - cMu sync.Mutex // mutex for circuit capacity checker - tracer tracerWrapper // scroll tracer wrapper - circuitCapacityChecker *circuitcapacitychecker.CircuitCapacityChecker // circuit capacity checker instance + checkCircuitCapacity bool // whether enable circuit capacity check + cMu sync.Mutex // mutex for circuit capacity checker + tracer tracerWrapper // scroll tracer wrapper + circuitCapacityChecker *ccc.Checker // circuit capacity checker instance } // NewBlockValidator returns a new block validator which is safe for re-use @@ -75,8 +75,8 @@ type tracerWrapper interface { func (v *BlockValidator) SetupTracerAndCircuitCapacityChecker(tracer tracerWrapper) { v.checkCircuitCapacity = true v.tracer = tracer - v.circuitCapacityChecker = circuitcapacitychecker.NewCircuitCapacityChecker(true) - log.Info("new CircuitCapacityChecker in BlockValidator", "ID", v.circuitCapacityChecker.ID) + v.circuitCapacityChecker = ccc.NewChecker(true) + log.Info("new Checker in BlockValidator", "ID", v.circuitCapacityChecker.ID) } // ValidateBody validates the given block's uncles and verifies the block diff --git a/core/types.go b/core/types.go index 3424903799..546de267a6 100644 --- a/core/types.go +++ b/core/types.go @@ -35,7 +35,7 @@ type Validator interface { // gas used. ValidateState(block *types.Block, state *state.StateDB, receipts types.Receipts, usedGas uint64) error - // SetupTracerAndCircuitCapacityChecker sets up ScrollTracerWrapper and CircuitCapacityChecker for validator, + // SetupTracerAndCircuitCapacityChecker sets up ScrollTracerWrapper and Checker for validator, // to get scroll-related traces and to validate the circuit row consumption SetupTracerAndCircuitCapacityChecker(tracer tracerWrapper) } diff --git a/miner/scroll_worker.go b/miner/scroll_worker.go index 9eac3a0167..e5688bc24a 100644 --- a/miner/scroll_worker.go +++ b/miner/scroll_worker.go @@ -38,7 +38,7 @@ import ( "github.com/scroll-tech/go-ethereum/log" "github.com/scroll-tech/go-ethereum/metrics" "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/pipeline" "github.com/scroll-tech/go-ethereum/trie" @@ -131,7 +131,7 @@ type worker struct { // External functions isLocalBlock func(block *types.Header) bool // Function used to determine whether the specified block is mined by local miner. - circuitCapacityChecker *circuitcapacitychecker.CircuitCapacityChecker + circuitCapacityChecker *ccc.Checker prioritizedTx *prioritizedTransaction // Test hooks @@ -153,9 +153,9 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize), exitCh: make(chan struct{}), 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", "Checker ID", worker.circuitCapacityChecker.ID) // Subscribe NewTxsEvent for tx pool worker.txsSub = eth.TxPool().SubscribeTransactions(worker.txsCh, true) @@ -181,7 +181,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus // getCCC returns a pointer to this worker's CCC instance. // Only used in tests. -func (w *worker) getCCC() *circuitcapacitychecker.CircuitCapacityChecker { +func (w *worker) getCCC() *ccc.Checker { return w.circuitCapacityChecker } @@ -533,16 +533,16 @@ func (w *worker) handlePipelineResult(res *pipeline.Result) error { switch { case res.OverflowingTx.IsL1MessageTx() && - errors.Is(res.CCCErr, circuitcapacitychecker.ErrBlockRowConsumptionOverflow): + errors.Is(res.CCCErr, ccc.ErrBlockRowConsumptionOverflow): l1TxRowConsumptionOverflowCounter.Inc(1) case !res.OverflowingTx.IsL1MessageTx() && - errors.Is(res.CCCErr, circuitcapacitychecker.ErrBlockRowConsumptionOverflow): + errors.Is(res.CCCErr, ccc.ErrBlockRowConsumptionOverflow): l2TxRowConsumptionOverflowCounter.Inc(1) case res.OverflowingTx.IsL1MessageTx() && - errors.Is(res.CCCErr, circuitcapacitychecker.ErrUnknown): + errors.Is(res.CCCErr, ccc.ErrUnknown): l1TxCccUnknownErrCounter.Inc(1) case !res.OverflowingTx.IsL1MessageTx() && - errors.Is(res.CCCErr, circuitcapacitychecker.ErrUnknown): + errors.Is(res.CCCErr, ccc.ErrUnknown): l2TxCccUnknownErrCounter.Inc(1) } } diff --git a/miner/worker.go b/miner/worker.go index 019317514e..fa9ec3cd9f 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -279,7 +279,7 @@ type worker struct { // External functions isLocalBlock func(header *types.Header) bool // Function used to determine whether the specified block is mined by local miner. - circuitCapacityChecker *circuitcapacitychecker.CircuitCapacityChecker + circuitCapacityChecker *ccc.Checker prioritizedTx *prioritizedTransaction // Test hooks @@ -314,9 +314,9 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus resubmitAdjustCh: make(chan *intervalAdjust, resubmitAdjustChanSize), l1MsgsCh: make(chan core.NewL1MsgsEvent, txChanSize), - circuitCapacityChecker: circuitcapacitychecker.NewCircuitCapacityChecker(true), + circuitCapacityChecker: ccc.NewChecker(true), } - log.Info("created new worker", "CircuitCapacityChecker ID", worker.circuitCapacityChecker.ID) + log.Info("created new worker", "Checker ID", worker.circuitCapacityChecker.ID) // Subscribe for transaction insertion events (whether from network or resurrects) worker.txsSub = eth.TxPool().SubscribeTransactions(worker.txsCh, true) @@ -374,7 +374,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus // getCCC returns a pointer to this worker's CCC instance. // Only used in tests. -func (w *worker) getCCC() *circuitcapacitychecker.CircuitCapacityChecker { +func (w *worker) getCCC() *ccc.Checker { return w.circuitCapacityChecker } @@ -994,7 +994,7 @@ func (w *worker) applyTransaction(env *environment, tx *types.Transaction) (*typ if accRows != nil { // At this point, we have called CCC but the transaction failed in `ApplyTransaction`. // If we skip this tx and continue to pack more, the next tx will likely fail with - // `circuitcapacitychecker.ErrUnknown`. However, at this point we cannot decide whether + // `ccc.ErrUnknown`. However, at this point we cannot decide whether // we should seal the block or skip the tx and continue, so we simply return the error. log.Error( "GetBlockTrace passed but ApplyTransaction failed, ccc is left in inconsistent state", @@ -1144,7 +1144,7 @@ loop: l1TxGasLimitExceededCounter.Inc(1) // Circuit capacity check - case errors.Is(err, circuitcapacitychecker.ErrBlockRowConsumptionOverflow): + case errors.Is(err, ccc.ErrBlockRowConsumptionOverflow): if env.tcount >= 1 { // 1. Circuit capacity limit reached in a block, and it's not the first tx: // don't pop or shift, just quit the loop immediately; @@ -1199,7 +1199,7 @@ loop: } } - case (errors.Is(err, circuitcapacitychecker.ErrUnknown) && tx.IsL1MessageTx()): + case (errors.Is(err, ccc.ErrUnknown) && tx.IsL1MessageTx()): // Circuit capacity check: unknown circuit capacity checker error for L1MessageTx, // shift to the next from the account because we shouldn't skip the entire txs from the same account queueIndex := tx.AsL1MessageTx().QueueIndex @@ -1221,7 +1221,7 @@ loop: w.checkCurrentTxNumWithCCC(env.tcount) break loop - case (errors.Is(err, circuitcapacitychecker.ErrUnknown) && !tx.IsL1MessageTx()): + case (errors.Is(err, ccc.ErrUnknown) && !tx.IsL1MessageTx()): // Circuit capacity check: unknown circuit capacity checker error for L2MessageTx, skip the account log.Trace("Unknown circuit capacity checker error for L2MessageTx", "tx", tx.Hash().String()) log.Info("Skipping L2 message", "tx", tx.Hash().String(), "block", env.header.Number, "reason", "unknown row consumption error") diff --git a/rollup/circuitcapacitychecker/impl.go b/rollup/ccc/impl.go similarity index 75% rename from rollup/circuitcapacitychecker/impl.go rename to rollup/ccc/impl.go index 19bf3d1a65..d8132ee28c 100644 --- a/rollup/circuitcapacitychecker/impl.go +++ b/rollup/ccc/impl.go @@ -1,6 +1,6 @@ -//go:build circuit_capacity_checker +//go:build ccc -package circuitcapacitychecker +package ccc /* #cgo LDFLAGS: -lm -ldl -lzkp @@ -22,7 +22,7 @@ import ( "github.com/scroll-tech/go-ethereum/metrics" ) -// mutex for concurrent CircuitCapacityChecker creations +// mutex for concurrent Checker creations var ( creationMu sync.Mutex encodeTimer = metrics.NewRegisteredTimer("ccc/encode", nil) @@ -32,26 +32,26 @@ func init() { C.init() } -type CircuitCapacityChecker struct { - // mutex for each CircuitCapacityChecker itself +type Checker struct { + // mutex for each Checker itself sync.Mutex ID uint64 jsonBuffer bytes.Buffer } -// NewCircuitCapacityChecker creates a new CircuitCapacityChecker -func NewCircuitCapacityChecker(lightMode bool) *CircuitCapacityChecker { +// NewChecker creates a new Checker +func NewChecker(lightMode bool) *Checker { creationMu.Lock() defer creationMu.Unlock() id := C.new_circuit_capacity_checker() - ccc := &CircuitCapacityChecker{ID: uint64(id)} + ccc := &Checker{ID: uint64(id)} ccc.SetLightMode(lightMode) return ccc } -// Reset resets a CircuitCapacityChecker -func (ccc *CircuitCapacityChecker) Reset() { +// Reset resets a Checker +func (ccc *Checker) Reset() { ccc.Lock() 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 -func (ccc *CircuitCapacityChecker) ApplyTransaction(traces *types.BlockTrace) (*types.RowConsumption, error) { +func (ccc *Checker) ApplyTransaction(traces *types.BlockTrace) (*types.RowConsumption, error) { ccc.Lock() defer ccc.Unlock() @@ -84,13 +84,13 @@ func (ccc *CircuitCapacityChecker) ApplyTransaction(traces *types.BlockTrace) (* 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() defer ccc.Unlock() 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) defer func() { C.free_c_chars(rawResult) @@ -103,11 +103,11 @@ func (ccc *CircuitCapacityChecker) applyTransactionRustTrace(rustTrace unsafe.Po } 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 } 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, "err", "AccRowUsage is empty unexpectedly") return nil, ErrUnknown @@ -119,7 +119,7 @@ func (ccc *CircuitCapacityChecker) applyTransactionRustTrace(rustTrace unsafe.Po } // 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() defer ccc.Unlock() @@ -145,11 +145,11 @@ func (ccc *CircuitCapacityChecker) ApplyBlock(traces *types.BlockTrace) (*types. } 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 } 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 } 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 -func (ccc *CircuitCapacityChecker) CheckTxNum(expected int) (bool, uint64, error) { +func (ccc *Checker) CheckTxNum(expected int) (bool, uint64, error) { ccc.Lock() defer ccc.Unlock() @@ -175,14 +175,14 @@ func (ccc *CircuitCapacityChecker) CheckTxNum(expected int) (bool, uint64, error return false, 0, fmt.Errorf("fail to json unmarshal get_tx_num result, id: %d, err: %w", ccc.ID, err) } if result.Error != "" { - return false, 0, fmt.Errorf("fail to get_tx_num in CircuitCapacityChecker, id: %d, err: %w", ccc.ID, result.Error) + return false, 0, fmt.Errorf("fail to get_tx_num in Checker, id: %d, err: %w", ccc.ID, result.Error) } return result.TxNum == uint64(expected), result.TxNum, nil } // SetLightMode sets to ccc light mode -func (ccc *CircuitCapacityChecker) SetLightMode(lightMode bool) error { +func (ccc *Checker) SetLightMode(lightMode bool) error { ccc.Lock() 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) } 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 diff --git a/rollup/circuitcapacitychecker/libzkp/.gitignore b/rollup/ccc/libzkp/.gitignore similarity index 100% rename from rollup/circuitcapacitychecker/libzkp/.gitignore rename to rollup/ccc/libzkp/.gitignore diff --git a/rollup/circuitcapacitychecker/libzkp/Cargo.lock b/rollup/ccc/libzkp/Cargo.lock similarity index 100% rename from rollup/circuitcapacitychecker/libzkp/Cargo.lock rename to rollup/ccc/libzkp/Cargo.lock diff --git a/rollup/circuitcapacitychecker/libzkp/Cargo.toml b/rollup/ccc/libzkp/Cargo.toml similarity index 100% rename from rollup/circuitcapacitychecker/libzkp/Cargo.toml rename to rollup/ccc/libzkp/Cargo.toml diff --git a/rollup/circuitcapacitychecker/libzkp/Makefile b/rollup/ccc/libzkp/Makefile similarity index 100% rename from rollup/circuitcapacitychecker/libzkp/Makefile rename to rollup/ccc/libzkp/Makefile diff --git a/rollup/circuitcapacitychecker/libzkp/libzkp.h b/rollup/ccc/libzkp/libzkp.h similarity index 100% rename from rollup/circuitcapacitychecker/libzkp/libzkp.h rename to rollup/ccc/libzkp/libzkp.h diff --git a/rollup/circuitcapacitychecker/libzkp/rust-toolchain b/rollup/ccc/libzkp/rust-toolchain similarity index 100% rename from rollup/circuitcapacitychecker/libzkp/rust-toolchain rename to rollup/ccc/libzkp/rust-toolchain diff --git a/rollup/circuitcapacitychecker/libzkp/src/lib.rs b/rollup/ccc/libzkp/src/lib.rs similarity index 100% rename from rollup/circuitcapacitychecker/libzkp/src/lib.rs rename to rollup/ccc/libzkp/src/lib.rs diff --git a/rollup/circuitcapacitychecker/mock.go b/rollup/ccc/mock.go similarity index 65% rename from rollup/circuitcapacitychecker/mock.go rename to rollup/ccc/mock.go index dc603bfb35..8b09d86f0b 100644 --- a/rollup/circuitcapacitychecker/mock.go +++ b/rollup/ccc/mock.go @@ -1,6 +1,6 @@ -//go:build !circuit_capacity_checker +//go:build !ccc -package circuitcapacitychecker +package ccc import ( "bytes" @@ -11,7 +11,7 @@ import ( "github.com/scroll-tech/go-ethereum/core/types" ) -type CircuitCapacityChecker struct { +type Checker struct { ID uint64 countdown int nextError *error @@ -20,20 +20,20 @@ type CircuitCapacityChecker struct { skipError error } -// NewCircuitCapacityChecker creates a new CircuitCapacityChecker -func NewCircuitCapacityChecker(lightMode bool) *CircuitCapacityChecker { - ccc := &CircuitCapacityChecker{ID: rand.Uint64()} +// NewChecker creates a new Checker +func NewChecker(lightMode bool) *Checker { + ccc := &Checker{ID: rand.Uint64()} ccc.SetLightMode(lightMode) return 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. // 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 { ccc.countdown-- if ccc.countdown == 0 { @@ -53,13 +53,13 @@ func (ccc *CircuitCapacityChecker) ApplyTransaction(traces *types.BlockTrace) (* }}, 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]) } // ApplyBlock gets a block's RowConsumption. // 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{ Name: "mock", 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. // 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 } // SetLightMode sets to ccc light mode -func (ccc *CircuitCapacityChecker) SetLightMode(lightMode bool) error { +func (ccc *Checker) SetLightMode(lightMode bool) error { return nil } // 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.nextError = &err } // 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.skipError = err } diff --git a/rollup/circuitcapacitychecker/types.go b/rollup/ccc/types.go similarity index 94% rename from rollup/circuitcapacitychecker/types.go rename to rollup/ccc/types.go index 13a9385d56..18ccf4127e 100644 --- a/rollup/circuitcapacitychecker/types.go +++ b/rollup/ccc/types.go @@ -1,4 +1,4 @@ -package circuitcapacitychecker +package ccc import ( "errors" diff --git a/rollup/pipeline/pipeline.go b/rollup/pipeline/pipeline.go index e3d0cbafaa..ee28d8e3c3 100644 --- a/rollup/pipeline/pipeline.go +++ b/rollup/pipeline/pipeline.go @@ -16,7 +16,7 @@ import ( "github.com/scroll-tech/go-ethereum/log" "github.com/scroll-tech/go-ethereum/metrics" "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" ) @@ -62,7 +62,7 @@ type Pipeline struct { cancelCtx context.CancelFunc // accumulators - ccc *circuitcapacitychecker.CircuitCapacityChecker + ccc *ccc.Checker Header types.Header state *state.StateDB nextL1MsgIndex uint64 @@ -88,7 +88,7 @@ func NewPipeline( header *types.Header, nextL1MsgIndex uint64, - ccc *circuitcapacitychecker.CircuitCapacityChecker, + ccc *ccc.Checker, ) *Pipeline { // make sure we are not sharing a tracer with the caller and not in debug mode vmConfig.Tracer = nil @@ -393,7 +393,7 @@ func (p *Pipeline) encodeStage(traces <-chan *BlockCandidate) <-chan *BlockCandi encodeStart := time.Now() if p.ccc != nil { - trace.RustTrace = circuitcapacitychecker.MakeRustTrace(trace.LastTrace, buffer) + trace.RustTrace = ccc.MakeRustTrace(trace.LastTrace, buffer) if trace.RustTrace == nil { 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 @@ -404,7 +404,7 @@ func (p *Pipeline) encodeStage(traces <-chan *BlockCandidate) <-chan *BlockCandi stallStart := time.Now() if sendCancellable(downstreamCh, trace, p.ctx.Done()) && trace.RustTrace != nil { // failed to send the trace downstream, free it here. - circuitcapacitychecker.FreeRustTrace(trace.RustTrace) + ccc.FreeRustTrace(trace.RustTrace) } encodeStallTimer.UpdateSince(stallStart) case <-p.ctx.Done(): @@ -438,7 +438,7 @@ func (p *Pipeline) cccStage(candidates <-chan *BlockCandidate, deadline time.Tim break } if candidate.RustTrace != nil { - circuitcapacitychecker.FreeRustTrace(candidate.RustTrace) + ccc.FreeRustTrace(candidate.RustTrace) } } p.wg.Done()