mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
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
This commit is contained in:
parent
fcc31a562c
commit
dece2fa8af
18 changed files with 75 additions and 76 deletions
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
4
Makefile
4
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."
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package circuitcapacitychecker
|
||||
package ccc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue