From ef67ff8bbba40b4448f6704dce505f731c01ca35 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Date: Thu, 3 Aug 2023 19:09:59 +0800 Subject: [PATCH] fix(miner): fix `acc_rows` for empty block (#431) * Revert "fix(worker): set row consumption for genesis and empty blocks (#428)" This reverts commit b51736fd3c5a233d7d8fd2113306270a11f9af50. * fix: fix accRows for empty block * bump version * remove log * fix * set default accRows as nil explicitly * fix genesis block * fix --- core/blockchain.go | 4 ---- core/genesis.go | 1 - core/trace.go | 6 +++++- miner/worker.go | 18 +++++++++++++++--- params/version.go | 2 +- .../circuitcapacitychecker/libzkp/src/lib.rs | 14 -------------- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index faa212e513..f6e1070788 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -280,9 +280,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par // initialize L1 message index for genesis block rawdb.WriteFirstQueueIndexNotInL2Block(db, bc.genesisBlock.Hash(), 0) - // initialize row consumption for genesis block - rawdb.WriteBlockRowConsumption(db, bc.genesisBlock.Hash(), &types.RowConsumption{}) - var nilBlock *types.Block bc.currentBlock.Store(nilBlock) bc.currentFastBlock.Store(nilBlock) @@ -702,7 +699,6 @@ func (bc *BlockChain) ResetWithGenesisBlock(genesis *types.Block) error { rawdb.WriteTd(batch, genesis.Hash(), genesis.NumberU64(), genesis.Difficulty()) rawdb.WriteBlock(batch, genesis) rawdb.WriteFirstQueueIndexNotInL2Block(batch, genesis.Hash(), 0) - rawdb.WriteBlockRowConsumption(batch, genesis.Hash(), &types.RowConsumption{}) if err := batch.Write(); err != nil { log.Crit("Failed to write genesis block", "err", err) } diff --git a/core/genesis.go b/core/genesis.go index 592978969d..96d11c72dc 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -353,7 +353,6 @@ func (g *Genesis) Commit(db ethdb.Database) (*types.Block, error) { rawdb.WriteHeadHeaderHash(db, block.Hash()) rawdb.WriteChainConfig(db, block.Hash(), config) rawdb.WriteFirstQueueIndexNotInL2Block(db, block.Hash(), 0) - rawdb.WriteBlockRowConsumption(db, block.Hash(), &types.RowConsumption{}) return block, nil } diff --git a/core/trace.go b/core/trace.go index 50a460a4ec..9c3fd85a42 100644 --- a/core/trace.go +++ b/core/trace.go @@ -447,8 +447,12 @@ func (env *TraceEnv) fillBlockTrace(block *types.Block) (*types.BlockTrace, erro } } + var chainID uint64 + if env.chainConfig.ChainID != nil { + chainID = env.chainConfig.ChainID.Uint64() + } blockTrace := &types.BlockTrace{ - ChainID: env.chainConfig.ChainID.Uint64(), + ChainID: chainID, Version: params.ArchiveVersion(params.CommitHash), Coinbase: &types.AccountWrapper{ Address: env.coinbase, diff --git a/miner/worker.go b/miner/worker.go index 1f8f24b434..44cea4be98 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -753,6 +753,7 @@ func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error { uncles: mapset.NewSet(), header: header, traceEnv: traceEnv, + accRows: nil, } // when 08 is processed ancestors contain 07 (quick block) for _, ancestor := range w.chain.GetBlocksFromHash(parent.Hash(), 7) { @@ -768,9 +769,6 @@ func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error { env.l1TxCount = 0 env.maxL1Index = 0 - // make sure accRows is not nil, even for empty blocks - env.accRows = &types.RowConsumption{} - // Swap out the old work with the new one, terminating any leftover prefetcher // processes in the mean time and starting a new one. if w.current != nil && w.current.state != nil { @@ -1226,6 +1224,20 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64) // commit runs any post-transaction state modifications, assembles the final block // and commits new work if consensus engine is running. func (w *worker) commit(uncles []*types.Header, interval func(), update bool, start time.Time) error { + // set w.current.accRows for empty-but-not-genesis block + if (w.current.header.Number.Uint64() != 0) && + (w.current.accRows == nil || len(*w.current.accRows) == 0) { + traces, err := w.current.traceEnv.GetBlockTrace(types.NewBlockWithHeader(w.current.header)) + if err != nil { + return err + } + accRows, err := w.circuitCapacityChecker.ApplyBlock(traces) + if err != nil { + return err + } + w.current.accRows = accRows + } + // Deep copy receipts here to avoid interaction between different tasks. receipts := copyReceipts(w.current.receipts) s := w.current.state.Copy() diff --git a/params/version.go b/params/version.go index e0f65cdcd5..422814de0c 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 4 // Major version component of the current release VersionMinor = 3 // Minor version component of the current release - VersionPatch = 11 // Patch version component of the current release + VersionPatch = 12 // Patch version component of the current release VersionMeta = "sepolia" // Version metadata to append to the version string ) diff --git a/rollup/circuitcapacitychecker/libzkp/src/lib.rs b/rollup/circuitcapacitychecker/libzkp/src/lib.rs index b0dfe26dfb..4ce5943c16 100644 --- a/rollup/circuitcapacitychecker/libzkp/src/lib.rs +++ b/rollup/circuitcapacitychecker/libzkp/src/lib.rs @@ -60,13 +60,6 @@ pub mod checker { pub unsafe extern "C" fn apply_tx(id: u64, tx_traces: *const c_char) -> *const c_char { let result = panic::catch_unwind(|| { let tx_traces_vec = c_char_to_vec(tx_traces); - - log::debug!( - "ccc apply_tx raw input, id: {:?}, tx_traces: {:?}", - id, - String::from(tx_traces_vec) - ); - let traces = serde_json::from_slice::(&tx_traces_vec) .unwrap_or_else(|_| panic!("id: {id:?}, fail to deserialize tx_traces")); if traces.transactions.len() != 1 { @@ -121,13 +114,6 @@ pub mod checker { pub unsafe extern "C" fn apply_block(id: u64, block_trace: *const c_char) -> *const c_char { let result = panic::catch_unwind(|| { let block_trace = c_char_to_vec(block_trace); - - log::debug!( - "ccc apply_block raw input, id: {:?}, block_trace: {:?}", - id, - String::from(block_trace) - ); - let traces = serde_json::from_slice::(&block_trace) .unwrap_or_else(|_| panic!("id: {id:?}, fail to deserialize block_trace")); CHECKERS