From ff23c5272aeefd2aa822557f8f28361984b9b1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Mon, 26 Aug 2024 16:15:56 +0200 Subject: [PATCH 1/2] feat: schedule DarwinV2 (#1002) * refactor: add darwinV2 to tests, improve log format * feat: schedule DarwinV2 --- core/blockchain_test.go | 1 + core/state_processor_test.go | 1 + core/vm/runtime/runtime.go | 1 + eth/gasprice/gasprice_test.go | 1 + params/config.go | 20 ++++++++++++++++++-- params/version.go | 4 ++-- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 87fa6d18a610..13b75622b169 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -3723,6 +3723,7 @@ func TestCurieTransition(t *testing.T) { json.Unmarshal(b, &config) config.CurieBlock = big.NewInt(2) config.DarwinTime = nil + config.DarwinV2Time = nil var ( db = rawdb.NewMemoryDatabase() diff --git a/core/state_processor_test.go b/core/state_processor_test.go index f2d82ac8c569..e9d6e426e11b 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -59,6 +59,7 @@ func TestStateProcessorErrors(t *testing.T) { BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), + DarwinV2Time: new(uint64), Ethash: new(params.EthashConfig), } signer = types.LatestSigner(config) diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index ebd09e797ff2..3808d0b4d329 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -73,6 +73,7 @@ func setDefaults(cfg *Config) { BernoulliBlock: new(big.Int), CurieBlock: new(big.Int), DarwinTime: new(uint64), + DarwinV2Time: new(uint64), } } diff --git a/eth/gasprice/gasprice_test.go b/eth/gasprice/gasprice_test.go index 16a64a2eabf4..560b6a69aada 100644 --- a/eth/gasprice/gasprice_test.go +++ b/eth/gasprice/gasprice_test.go @@ -123,6 +123,7 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool, pendingTxC config.BernoulliBlock = londonBlock config.CurieBlock = londonBlock config.DarwinTime = nil + config.DarwinV2Time = nil engine := ethash.NewFaker() db := rawdb.NewMemoryDatabase() genesis, err := gspec.Commit(db) diff --git a/params/config.go b/params/config.go index 44c1292cb006..11b8ff9390c9 100644 --- a/params/config.go +++ b/params/config.go @@ -284,6 +284,7 @@ var ( BernoulliBlock: nil, CurieBlock: nil, DarwinTime: nil, + DarwinV2Time: nil, Clique: &CliqueConfig{ Period: 3, Epoch: 30000, @@ -323,6 +324,7 @@ var ( BernoulliBlock: big.NewInt(3747132), CurieBlock: big.NewInt(4740239), DarwinTime: newUint64(1723622400), + DarwinV2Time: newUint64(1724832000), Clique: &CliqueConfig{ Period: 3, Epoch: 30000, @@ -362,6 +364,7 @@ var ( BernoulliBlock: big.NewInt(5220340), CurieBlock: big.NewInt(7096836), DarwinTime: newUint64(1724227200), + DarwinV2Time: newUint64(1725264000), Clique: &CliqueConfig{ Period: 3, Epoch: 30000, @@ -407,6 +410,7 @@ var ( BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), + DarwinV2Time: new(uint64), TerminalTotalDifficulty: nil, Ethash: new(EthashConfig), Clique: nil, @@ -450,6 +454,7 @@ var ( BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), + DarwinV2Time: new(uint64), TerminalTotalDifficulty: nil, Ethash: nil, Clique: &CliqueConfig{Period: 0, Epoch: 30000}, @@ -488,6 +493,7 @@ var ( BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), + DarwinV2Time: new(uint64), TerminalTotalDifficulty: nil, Ethash: new(EthashConfig), Clique: nil, @@ -527,6 +533,7 @@ var ( BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), + DarwinV2Time: new(uint64), TerminalTotalDifficulty: nil, Ethash: new(EthashConfig), Clique: nil, @@ -744,7 +751,15 @@ func (c *ChainConfig) String() string { default: engine = "unknown" } - return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Berlin: %v, London: %v, Arrow Glacier: %v, Archimedes: %v, Shanghai: %v, Bernoulli: %v, Curie: %v, Darwin: %v, Engine: %v, Scroll config: %v}", + darwinTime := "" + if c.DarwinTime != nil { + darwinTime = fmt.Sprintf("@%v", *c.DarwinTime) + } + darwinV2Time := "" + if c.DarwinV2Time != nil { + darwinV2Time = fmt.Sprintf("@%v", *c.DarwinV2Time) + } + return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Berlin: %v, London: %v, Arrow Glacier: %v, Archimedes: %v, Shanghai: %v, Bernoulli: %v, Curie: %v, Darwin: %v, DarwinV2: %v, Engine: %v, Scroll config: %v}", c.ChainID, c.HomesteadBlock, c.DAOForkBlock, @@ -764,7 +779,8 @@ func (c *ChainConfig) String() string { c.ShanghaiBlock, c.BernoulliBlock, c.CurieBlock, - c.DarwinTime, + darwinTime, + darwinV2Time, engine, c.Scroll, ) diff --git a/params/version.go b/params/version.go index fedc375ed9dd..01721495ad18 100644 --- a/params/version.go +++ b/params/version.go @@ -23,8 +23,8 @@ import ( const ( VersionMajor = 5 // Major version component of the current release - VersionMinor = 6 // Minor version component of the current release - VersionPatch = 5 // Patch version component of the current release + VersionMinor = 7 // Minor version component of the current release + VersionPatch = 0 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string ) From c252ee1ee01c79b30a1a06c41c63952371b3ba77 Mon Sep 17 00:00:00 2001 From: colin <102356659+colinlyguo@users.noreply.github.com> Date: Mon, 26 Aug 2024 22:48:44 +0800 Subject: [PATCH 2/2] feat(tx-pool): fast reject known skipped txs (#1004) * feat(tx-pool): fast reject known skipped txs (#1001) * feat(tx-pool): fast reject known skipped txs * fix make lint * add miner flag to tx pool * bump version --- cmd/geth/main.go | 1 + core/rawdb/accessors_skipped_txs.go | 10 +++++++++ core/tx_pool.go | 35 ++++++++++++++++++++++++----- core/tx_pool_test.go | 5 +++++ miner/miner_test.go | 4 ++++ params/version.go | 2 +- 6 files changed, 51 insertions(+), 6 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index f137e8df82ec..24760af5e080 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -441,6 +441,7 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend) { // Set the gas price to the limits from the CLI and start mining gasprice := utils.GlobalBig(ctx, utils.MinerGasPriceFlag.Name) ethBackend.TxPool().SetGasPrice(gasprice) + ethBackend.TxPool().SetIsMiner(true) // start mining threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name) if err := ethBackend.StartMining(threads); err != nil { diff --git a/core/rawdb/accessors_skipped_txs.go b/core/rawdb/accessors_skipped_txs.go index 3481a955c8b3..5378c28c2bbb 100644 --- a/core/rawdb/accessors_skipped_txs.go +++ b/core/rawdb/accessors_skipped_txs.go @@ -158,6 +158,16 @@ func ReadSkippedTransaction(db ethdb.Reader, txHash common.Hash) *SkippedTransac return &stxV2 } +// IsSkippedTransaction checks if a transaction exists as a skipped transaction in the database. +func IsSkippedTransaction(db ethdb.Reader, txHash common.Hash) bool { + exists, err := db.Has(SkippedTransactionKey(txHash)) + if err != nil { + log.Error("Failed to check skipped transaction", "hash", txHash.String(), "err", err) + return false + } + return exists +} + // writeSkippedTransactionHash writes the hash of a skipped transaction to the database. func writeSkippedTransactionHash(db ethdb.KeyValueWriter, index uint64, txHash common.Hash) { if err := db.Put(SkippedTransactionHashKey(index), txHash[:]); err != nil { diff --git a/core/tx_pool.go b/core/tx_pool.go index 14124e7633b7..533547dc26e9 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -29,8 +29,10 @@ import ( "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/common/prque" "github.com/scroll-tech/go-ethereum/consensus/misc" + "github.com/scroll-tech/go-ethereum/core/rawdb" "github.com/scroll-tech/go-ethereum/core/state" "github.com/scroll-tech/go-ethereum/core/types" + "github.com/scroll-tech/go-ethereum/ethdb" "github.com/scroll-tech/go-ethereum/event" "github.com/scroll-tech/go-ethereum/log" "github.com/scroll-tech/go-ethereum/metrics" @@ -109,11 +111,12 @@ var ( queuedEvictionMeter = metrics.NewRegisteredMeter("txpool/queued/eviction", nil) // Dropped due to lifetime // General tx metrics - knownTxMeter = metrics.NewRegisteredMeter("txpool/known", nil) - validTxMeter = metrics.NewRegisteredMeter("txpool/valid", nil) - invalidTxMeter = metrics.NewRegisteredMeter("txpool/invalid", nil) - underpricedTxMeter = metrics.NewRegisteredMeter("txpool/underpriced", nil) - overflowedTxMeter = metrics.NewRegisteredMeter("txpool/overflowed", nil) + knownTxMeter = metrics.NewRegisteredMeter("txpool/known", nil) + knownSkippedTxMeter = metrics.NewRegisteredMeter("txpool/known/skipped", nil) + validTxMeter = metrics.NewRegisteredMeter("txpool/valid", nil) + invalidTxMeter = metrics.NewRegisteredMeter("txpool/invalid", nil) + underpricedTxMeter = metrics.NewRegisteredMeter("txpool/underpriced", nil) + overflowedTxMeter = metrics.NewRegisteredMeter("txpool/overflowed", nil) // throttleTxMeter counts how many transactions are rejected due to too-many-changes between // txpool reorgs. throttleTxMeter = metrics.NewRegisteredMeter("txpool/throttle", nil) @@ -154,6 +157,8 @@ type blockChain interface { StateAt(root common.Hash) (*state.StateDB, error) SubscribeChainHeadEvent(ch chan<- ChainHeadEvent) event.Subscription + + Database() ethdb.Database } // TxPoolConfig are the configuration parameters of the transaction pool. @@ -279,6 +284,8 @@ type TxPool struct { initDoneCh chan struct{} // is closed once the pool is initialized (for tests) changesSinceReorg int // A counter for how many drops we've performed in-between reorg. + + isMiner atomic.Bool } type txpoolResetRequest struct { @@ -492,6 +499,17 @@ func (pool *TxPool) SetGasPrice(price *big.Int) { log.Info("Transaction pool price threshold updated", "price", price) } +// SetIsMiner updates the miner status of the node. +func (pool *TxPool) SetIsMiner(isMiner bool) { + pool.isMiner.Store(isMiner) + log.Info("Transaction pool miner status updated", "isMiner", isMiner) +} + +// IsMiner returns the current miner status of the node. +func (pool *TxPool) IsMiner() bool { + return pool.isMiner.Load() +} + // Nonce returns the next nonce of an account, with all transactions executable // by the pool already applied on top. func (pool *TxPool) Nonce(addr common.Address) uint64 { @@ -767,6 +785,13 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e knownTxMeter.Mark(1) return false, ErrAlreadyKnown } + + if pool.IsMiner() && rawdb.IsSkippedTransaction(pool.chain.Database(), hash) { + log.Trace("Discarding already known skipped transaction", "hash", hash) + knownSkippedTxMeter.Mark(1) + return false, ErrAlreadyKnown + } + // Make the local flag. If it's from local source or it's from the network but // the sender is marked as local previously, treat it as the local transaction. isLocal := local || pool.locals.containsTx(tx) diff --git a/core/tx_pool_test.go b/core/tx_pool_test.go index ca99bf1a7895..22e498718fc6 100644 --- a/core/tx_pool_test.go +++ b/core/tx_pool_test.go @@ -35,6 +35,7 @@ import ( "github.com/scroll-tech/go-ethereum/core/state" "github.com/scroll-tech/go-ethereum/core/types" "github.com/scroll-tech/go-ethereum/crypto" + "github.com/scroll-tech/go-ethereum/ethdb" "github.com/scroll-tech/go-ethereum/event" "github.com/scroll-tech/go-ethereum/params" "github.com/scroll-tech/go-ethereum/trie" @@ -97,6 +98,10 @@ func (bc *testBlockChain) SubscribeChainHeadEvent(ch chan<- ChainHeadEvent) even return bc.chainHeadFeed.Subscribe(ch) } +func (bc *testBlockChain) Database() ethdb.Database { + return nil +} + func transaction(nonce uint64, gaslimit uint64, key *ecdsa.PrivateKey) *types.Transaction { return pricedTransaction(nonce, gaslimit, big.NewInt(1), key) } diff --git a/miner/miner_test.go b/miner/miner_test.go index 56f6c1f2da88..820961711160 100644 --- a/miner/miner_test.go +++ b/miner/miner_test.go @@ -91,6 +91,10 @@ func (bc *testBlockChain) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) return bc.chainHeadFeed.Subscribe(ch) } +func (bc *testBlockChain) Database() ethdb.Database { + return nil +} + func TestMiner(t *testing.T) { miner, mux := createMiner(t) miner.Start(common.HexToAddress("0x12345")) diff --git a/params/version.go b/params/version.go index 01721495ad18..44aa95662f6d 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 7 // Minor version component of the current release - VersionPatch = 0 // Patch version component of the current release + VersionPatch = 1 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string )