From 20f8ade84150810e4d052b58eacb72d333e37e36 Mon Sep 17 00:00:00 2001 From: 0xmountaintop <37070449+0xmountaintop@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:10:11 +1100 Subject: [PATCH] fix: account for tx subcircuit confidence factor (#1069) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: account for tx subcircuit confidence factor (#1065) * fix types * fix `TestValidateTxBlockSize` --------- Co-authored-by: Ă–mer Faruk Irmak --- core/block_validator.go | 3 ++- core/txpool/legacypool/legacypool_test.go | 2 +- core/txpool/validation.go | 2 +- miner/scroll_worker.go | 2 +- miner/worker.go | 2 +- params/config.go | 9 +++++++-- rollup/pipeline/pipeline.go | 3 ++- 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/block_validator.go b/core/block_validator.go index 3950b49ac1ee..99dce2177e72 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -21,6 +21,7 @@ import ( "fmt" "time" + "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/consensus" "github.com/scroll-tech/go-ethereum/core/rawdb" "github.com/scroll-tech/go-ethereum/core/state" @@ -77,7 +78,7 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error { return consensus.ErrInvalidTxCount } // Check if block payload size is smaller than the max size - if !v.config.Scroll.IsValidBlockSize(block.PayloadSize()) { + if !v.config.Scroll.IsValidBlockSize(common.StorageSize(block.PayloadSize())) { return ErrInvalidBlockPayloadSize } diff --git a/core/txpool/legacypool/legacypool_test.go b/core/txpool/legacypool/legacypool_test.go index edad39fc4657..c4b6633db95a 100644 --- a/core/txpool/legacypool/legacypool_test.go +++ b/core/txpool/legacypool/legacypool_test.go @@ -2740,7 +2740,7 @@ func TestValidateTxBlockSize(t *testing.T) { account := crypto.PubkeyToAddress(key.PublicKey) testAddBalance(pool, account, big.NewInt(1000000000000000000)) - validTx := pricedDataTransaction(1, 2100000, big.NewInt(1), key, uint64(*pool.chainconfig.Scroll.MaxTxPayloadBytesPerBlock)-128) + validTx := pricedDataTransaction(1, 2100000, big.NewInt(1), key, uint64(float64(*pool.chainconfig.Scroll.MaxTxPayloadBytesPerBlock)*float64(0.9))) oversizedTx := pricedDataTransaction(2, 2100000, big.NewInt(1), key, uint64(*pool.chainconfig.Scroll.MaxTxPayloadBytesPerBlock)) tests := []struct { diff --git a/core/txpool/validation.go b/core/txpool/validation.go index 17a6f39bbcaf..eacc3f9e3c4c 100644 --- a/core/txpool/validation.go +++ b/core/txpool/validation.go @@ -58,7 +58,7 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types return fmt.Errorf("%w: transaction size %v, limit %v", ErrOversizedData, tx.Size(), opts.MaxSize) } // Reject transactions that cannot fit into a block even as a single transaction - if !opts.Config.Scroll.IsValidBlockSize(tx.Size()) { + if !opts.Config.Scroll.IsValidBlockSizeForMining(common.StorageSize(tx.Size())) { return ErrOversizedData } // Ensure only transactions that have been enabled are accepted diff --git a/miner/scroll_worker.go b/miner/scroll_worker.go index a478d95838ae..754ce54ddbe5 100644 --- a/miner/scroll_worker.go +++ b/miner/scroll_worker.go @@ -690,7 +690,7 @@ func (w *worker) processTxn(tx *types.Transaction) (bool, error) { return false, ErrUnexpectedL1MessageIndex } - if !tx.IsL1MessageTx() && !w.chain.Config().Scroll.IsValidBlockSize(uint64(w.current.blockSize)+tx.Size()) { + if !tx.IsL1MessageTx() && !w.chain.Config().Scroll.IsValidBlockSizeForMining(w.current.blockSize+common.StorageSize(tx.Size())) { // can't fit this txn in this block, silently ignore and continue looking for more txns return false, errors.New("tx too big") } diff --git a/miner/worker.go b/miner/worker.go index fa9ec3cd9f51..9f933ed8f8b9 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1083,7 +1083,7 @@ loop: ) break } - if !tx.IsL1MessageTx() && !w.chainConfig.Scroll.IsValidBlockSize(env.blockSize+tx.Size()) { + if !tx.IsL1MessageTx() && !w.chainConfig.Scroll.IsValidBlockSizeForMining(common.StorageSize(env.blockSize+tx.Size())) { log.Trace("Block size limit reached", "have", env.blockSize, "want", w.chainConfig.Scroll.MaxTxPayloadBytesPerBlock, "tx", tx.Size()) txs.Pop() // skip transactions from this account continue diff --git a/params/config.go b/params/config.go index 9e4df420ffb1..6a81fe990a4d 100644 --- a/params/config.go +++ b/params/config.go @@ -581,8 +581,13 @@ func (s ScrollConfig) IsValidTxCount(count int) bool { } // IsValidBlockSize returns whether the given block's transaction payload size is below the limit. -func (s ScrollConfig) IsValidBlockSize(size uint64) bool { - return s.MaxTxPayloadBytesPerBlock == nil || size <= uint64(*s.MaxTxPayloadBytesPerBlock) +func (s ScrollConfig) IsValidBlockSize(size common.StorageSize) bool { + return s.MaxTxPayloadBytesPerBlock == nil || size <= common.StorageSize(*s.MaxTxPayloadBytesPerBlock) +} + +// IsValidBlockSizeForMining is similar to IsValidBlockSize, but it accounts for the confidence factor in Rust CCC +func (s ScrollConfig) IsValidBlockSizeForMining(size common.StorageSize) bool { + return s.IsValidBlockSize(size * (1.0 / 0.95)) } func (s ScrollConfig) String() string { diff --git a/rollup/pipeline/pipeline.go b/rollup/pipeline/pipeline.go index ee28d8e3c32f..aaf364fb46da 100644 --- a/rollup/pipeline/pipeline.go +++ b/rollup/pipeline/pipeline.go @@ -8,6 +8,7 @@ import ( "time" "unsafe" + "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/core" "github.com/scroll-tech/go-ethereum/core/state" "github.com/scroll-tech/go-ethereum/core/txpool" @@ -306,7 +307,7 @@ func (p *Pipeline) traceAndApplyStage(txsIn <-chan *txpool.LazyTransaction) (<-c continue } - if !tx.IsL1MessageTx() && !p.chain.Config().Scroll.IsValidBlockSize(p.blockSize+tx.Size()) { + if !tx.IsL1MessageTx() && !p.chain.Config().Scroll.IsValidBlockSizeForMining(common.StorageSize(p.blockSize+tx.Size())) { // can't fit this txn in this block, silently ignore and continue looking for more txns sendCancellable(resCh, nil, p.ctx.Done()) continue