From 06cac4849fb4fc17e9ef173407548bd04f9d8aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Thu, 13 Jun 2024 18:32:56 +0300 Subject: [PATCH 01/18] feat(clique): allow shadowforking a clique network --- consensus/clique/clique.go | 13 +++++ consensus/clique/clique_test.go | 86 +++++++++++++++++++++++++++++++++ params/config.go | 8 +-- 3 files changed, 104 insertions(+), 3 deletions(-) diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index bd92b525b980..8bcfd1c2b5c3 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -195,6 +195,11 @@ func New(config *params.CliqueConfig, db ethdb.Database) *Clique { if conf.Epoch == 0 { conf.Epoch = epochLength } + + if conf.ShadowForkHeight > 0 && conf.ShadowForkHeight%conf.Epoch != 0 { + panic("ShadowForkHeight must be a multiple of Epoch") + } + // Allocate the snapshot caches and create the engine recents, _ := lru.NewARC(inmemorySnapshots) signatures, _ := lru.NewARC(inmemorySignatures) @@ -375,6 +380,14 @@ func (c *Clique) snapshot(chain consensus.ChainHeaderReader, number uint64, hash snap *Snapshot ) for snap == nil { + if c.config.ShadowForkHeight > 0 && number == c.config.ShadowForkHeight { + c.signatures.Purge() + c.recents.Purge() + c.proposals = make(map[common.Address]bool) + snap = newSnapshot(c.config, c.signatures, number, hash, []common.Address{c.config.ShadowForkSigner}) + break + } + // If an in-memory snapshot was found, use that if s, ok := c.recents.Get(hash); ok { snap = s.(*Snapshot) diff --git a/consensus/clique/clique_test.go b/consensus/clique/clique_test.go index 4faa93650175..1fde431d39cb 100644 --- a/consensus/clique/clique_test.go +++ b/consensus/clique/clique_test.go @@ -17,7 +17,9 @@ package clique import ( + "bytes" "math/big" + "strings" "testing" "github.com/scroll-tech/go-ethereum/common" @@ -125,3 +127,87 @@ func TestSealHash(t *testing.T) { t.Errorf("have %x, want %x", have, want) } } + +func TestShadowFork(t *testing.T) { + engineConf := *params.AllCliqueProtocolChanges.Clique + engineConf.Epoch = 2 + forkedEngineConf := engineConf + forkedEngineConf.ShadowForkHeight = 4 + shadowForkKey, _ := crypto.HexToECDSA(strings.Repeat("11", 32)) + shadowForkAddr := crypto.PubkeyToAddress(shadowForkKey.PublicKey) + forkedEngineConf.ShadowForkSigner = shadowForkAddr + + // Initialize a Clique chain with a single signer + var ( + db = rawdb.NewMemoryDatabase() + key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") + addr = crypto.PubkeyToAddress(key.PublicKey) + engine = New(&engineConf, db) + signer = new(types.HomesteadSigner) + forkedEngine = New(&forkedEngineConf, db) + ) + genspec := &core.Genesis{ + ExtraData: make([]byte, extraVanity+common.AddressLength+extraSeal), + Alloc: map[common.Address]core.GenesisAccount{ + addr: {Balance: big.NewInt(10000000000000000)}, + }, + BaseFee: big.NewInt(params.InitialBaseFee), + } + copy(genspec.ExtraData[extraVanity:], addr[:]) + genesis := genspec.MustCommit(db) + + // Generate a batch of blocks, each properly signed + chain, _ := core.NewBlockChain(db, nil, params.AllCliqueProtocolChanges, engine, vm.Config{}, nil, nil) + defer chain.Stop() + + forkedChain, _ := core.NewBlockChain(db, nil, params.AllCliqueProtocolChanges, forkedEngine, vm.Config{}, nil, nil) + defer forkedChain.Stop() + + blocks, _ := core.GenerateChain(params.AllCliqueProtocolChanges, genesis, engine, db, 16, func(i int, block *core.BlockGen) { + // The chain maker doesn't have access to a chain, so the difficulty will be + // lets unset (nil). Set it here to the correct value. + block.SetDifficulty(diffInTurn) + + tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr), common.Address{0x00}, new(big.Int), params.TxGas, block.BaseFee(), nil), signer, key) + if err != nil { + panic(err) + } + block.AddTxWithChain(chain, tx) + }) + for i, block := range blocks { + header := block.Header() + if i > 0 { + header.ParentHash = blocks[i-1].Hash() + } + + signingAddr, signingKey := addr, key + if header.Number.Uint64() > forkedEngineConf.ShadowForkHeight { + // start signing with shadow fork authority key + signingAddr, signingKey = shadowForkAddr, shadowForkKey + } + + header.Extra = make([]byte, extraVanity) + if header.Number.Uint64()%engineConf.Epoch == 0 { + header.Extra = append(header.Extra, signingAddr.Bytes()...) + } + header.Extra = append(header.Extra, bytes.Repeat([]byte{0}, extraSeal)...) + header.Difficulty = diffInTurn + + sig, _ := crypto.Sign(SealHash(header).Bytes(), signingKey) + copy(header.Extra[len(header.Extra)-extraSeal:], sig) + blocks[i] = block.WithSeal(header) + } + + if _, err := chain.InsertChain(blocks); err == nil { + t.Fatalf("should've failed to insert some blocks to canonical chain") + } + if chain.CurrentHeader().Number.Uint64() != forkedEngineConf.ShadowForkHeight { + t.Fatalf("unexpected canonical chain height") + } + if _, err := forkedChain.InsertChain(blocks); err != nil { + t.Fatalf("failed to insert blocks to forked chain: %v %d", err, forkedChain.CurrentHeader().Number) + } + if forkedChain.CurrentHeader().Number.Uint64() != uint64(len(blocks)) { + t.Fatalf("unexpected forked chain height") + } +} diff --git a/params/config.go b/params/config.go index a9ce6a2e33b7..1fcd4c748f80 100644 --- a/params/config.go +++ b/params/config.go @@ -718,9 +718,11 @@ func (c *EthashConfig) String() string { // CliqueConfig is the consensus engine configs for proof-of-authority based sealing. type CliqueConfig struct { - Period uint64 `json:"period"` // Number of seconds between blocks to enforce - Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint - RelaxedPeriod bool `json:"relaxed_period"` // Relaxes the period to be just an upper bound + Period uint64 `json:"period"` // Number of seconds between blocks to enforce + Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint + RelaxedPeriod bool `json:"relaxed_period"` // Relaxes the period to be just an upper bound + ShadowForkHeight uint64 `json:"shadow_fork_height"` // Allows shadow forking consensus layer at given height + ShadowForkSigner common.Address `json:"shadow_fork_signer"` // Sets the address to be the authorized signer after the shadow fork } // String implements the stringer interface, returning the consensus engine details. From 5f15b83b861c7e945cb22c3904a448fe20078a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Fri, 21 Jun 2024 10:48:57 +0300 Subject: [PATCH 02/18] feat: allow limiting outgoing gossip to shadow fork peers --- eth/handler.go | 58 +++++++++++++++++++++----------- eth/handler_test.go | 82 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 20 deletions(-) diff --git a/eth/handler.go b/eth/handler.go index 91adb2a62b5b..2cba7d3f07de 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -20,6 +20,7 @@ import ( "errors" "math" "math/big" + "slices" "sync" "sync/atomic" "time" @@ -76,15 +77,16 @@ type txPool interface { // handlerConfig is the collection of initialization parameters to create a full // node network handler. type handlerConfig struct { - Database ethdb.Database // Database for direct sync insertions - Chain *core.BlockChain // Blockchain to serve data from - TxPool txPool // Transaction pool to propagate from - Network uint64 // Network identifier to adfvertise - Sync downloader.SyncMode // Whether to fast or full sync - BloomCache uint64 // Megabytes to alloc for fast sync bloom - EventMux *event.TypeMux // Legacy event mux, deprecate for `feed` - Checkpoint *params.TrustedCheckpoint // Hard coded checkpoint for sync challenges - Whitelist map[uint64]common.Hash // Hard coded whitelist for sync challenged + Database ethdb.Database // Database for direct sync insertions + Chain *core.BlockChain // Blockchain to serve data from + TxPool txPool // Transaction pool to propagate from + Network uint64 // Network identifier to adfvertise + Sync downloader.SyncMode // Whether to fast or full sync + BloomCache uint64 // Megabytes to alloc for fast sync bloom + EventMux *event.TypeMux // Legacy event mux, deprecate for `feed` + Checkpoint *params.TrustedCheckpoint // Hard coded checkpoint for sync challenges + Whitelist map[uint64]common.Hash // Hard coded whitelist for sync challenged + ShadowForkPeerIDs []string // List of peer ids that take part in the shadow-fork } type handler struct { @@ -122,6 +124,8 @@ type handler struct { chainSync *chainSyncer wg sync.WaitGroup peerWG sync.WaitGroup + + shadowForkPeerIDs []string } // newHandler returns a handler for all Ethereum chain management protocol. @@ -131,15 +135,16 @@ func newHandler(config *handlerConfig) (*handler, error) { config.EventMux = new(event.TypeMux) // Nicety initialization for tests } h := &handler{ - networkID: config.Network, - forkFilter: forkid.NewFilter(config.Chain), - eventMux: config.EventMux, - database: config.Database, - txpool: config.TxPool, - chain: config.Chain, - peers: newPeerSet(), - whitelist: config.Whitelist, - quitSync: make(chan struct{}), + networkID: config.Network, + forkFilter: forkid.NewFilter(config.Chain), + eventMux: config.EventMux, + database: config.Database, + txpool: config.TxPool, + chain: config.Chain, + peers: newPeerSet(), + whitelist: config.Whitelist, + quitSync: make(chan struct{}), + shadowForkPeerIDs: config.ShadowForkPeerIDs, } if config.Sync == downloader.FullSync { // The database seems empty as the current block is the genesis. Yet the fast @@ -433,7 +438,7 @@ func (h *handler) Stop() { // will only announce its availability (depending what's requested). func (h *handler) BroadcastBlock(block *types.Block, propagate bool) { hash := block.Hash() - peers := h.peers.peersWithoutBlock(hash) + peers := onlyShadowForkPeers(h.shadowForkPeerIDs, h.peers.peersWithoutBlock(hash)) // If propagation is requested, send to a subset of the peer if propagate { @@ -483,7 +488,7 @@ func (h *handler) BroadcastTransactions(txs types.Transactions) { if tx.IsL1MessageTx() { continue } - peers := h.peers.peersWithoutTransaction(tx.Hash()) + peers := onlyShadowForkPeers(h.shadowForkPeerIDs, h.peers.peersWithoutTransaction(tx.Hash())) // Send the tx unconditionally to a subset of our peers numDirect := int(math.Sqrt(float64(len(peers)))) for _, peer := range peers[:numDirect] { @@ -533,3 +538,16 @@ func (h *handler) txBroadcastLoop() { } } } + +// onlyShadowForkPeers filters out peers that are not part of the shadow fork +func onlyShadowForkPeers[peerT interface { + ID() string +}](shadowForkPeerIDs []string, peers []peerT) []peerT { + if shadowForkPeerIDs == nil { + return peers + } + + return slices.DeleteFunc(peers, func(peer peerT) bool { + return !slices.Contains(shadowForkPeerIDs, peer.ID()) + }) +} diff --git a/eth/handler_test.go b/eth/handler_test.go index b9931a4b38e9..54118133aeda 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -20,6 +20,9 @@ import ( "math/big" "sort" "sync" + "testing" + + "github.com/stretchr/testify/require" "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/consensus/ethash" @@ -168,3 +171,82 @@ func (b *testHandler) close() { b.handler.Stop() b.chain.Stop() } + +type testPeer struct { + id string +} + +func (p testPeer) ID() string { + return p.id +} + +func TestOnlyShadowForkPeers(t *testing.T) { + + tests := map[string]struct { + shadowForkPeerIDs []string + peers []testPeer + expectedPeerIDs []string + }{ + "nil peers": { + shadowForkPeerIDs: nil, + peers: nil, + expectedPeerIDs: []string{}, + }, + "empty peers": { + shadowForkPeerIDs: nil, + peers: []testPeer{}, + expectedPeerIDs: []string{}, + }, + "no fork": { + shadowForkPeerIDs: nil, + peers: []testPeer{ + { + id: "peer1", + }, + { + id: "peer2", + }, + }, + expectedPeerIDs: []string{ + "peer1", + "peer2", + }, + }, + "some shadow fork peers": { + shadowForkPeerIDs: []string{"peer2"}, + peers: []testPeer{ + { + id: "peer1", + }, + { + id: "peer2", + }, + }, + expectedPeerIDs: []string{ + "peer2", + }, + }, + "no shadow fork peers": { + shadowForkPeerIDs: []string{"peer2"}, + peers: []testPeer{ + { + id: "peer1", + }, + { + id: "peer3", + }, + }, + expectedPeerIDs: []string{}, + }, + } + + for desc, test := range tests { + t.Run(desc, func(t *testing.T) { + gotIds := []string{} + for _, peer := range onlyShadowForkPeers(test.shadowForkPeerIDs, test.peers) { + gotIds = append(gotIds, peer.ID()) + } + require.Equal(t, gotIds, test.expectedPeerIDs) + }) + } +} From 3e972223b12ddf6e6948b07939815ba20323c6d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Mon, 24 Jun 2024 12:10:07 +0300 Subject: [PATCH 03/18] feat: do not drop peers if we are shadowforking --- eth/handler.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/eth/handler.go b/eth/handler.go index 2cba7d3f07de..9717f050ff7d 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -187,7 +187,14 @@ func newHandler(config *handlerConfig) (*handler, error) { if atomic.LoadUint32(&h.fastSync) == 1 && atomic.LoadUint32(&h.snapSync) == 0 { h.stateBloom = trie.NewSyncBloom(config.BloomCache, config.Database) } - h.downloader = downloader.New(h.checkpointNumber, config.Database, h.stateBloom, h.eventMux, h.chain, nil, h.removePeer) + + dropPeerFunc := h.removePeer + // If we are shadowforking, don't drop peers. + if config.ShadowForkPeerIDs != nil { + dropPeerFunc = func(id string) {} + } + + h.downloader = downloader.New(h.checkpointNumber, config.Database, h.stateBloom, h.eventMux, h.chain, nil, dropPeerFunc) // Construct the fetcher (short sync) validator := func(header *types.Header) error { @@ -222,7 +229,7 @@ func newHandler(config *handlerConfig) (*handler, error) { } return n, err } - h.blockFetcher = fetcher.NewBlockFetcher(false, nil, h.chain.GetBlockByHash, validator, h.BroadcastBlock, heighter, nil, inserter, h.removePeer) + h.blockFetcher = fetcher.NewBlockFetcher(false, nil, h.chain.GetBlockByHash, validator, h.BroadcastBlock, heighter, nil, inserter, dropPeerFunc) fetchTx := func(peer string, hashes []common.Hash) error { p := h.peers.peer(peer) From 00afb29a611fccfa67423a2e0b60efda213a3325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Tue, 25 Jun 2024 10:53:10 +0300 Subject: [PATCH 04/18] feat: add shadowfork flag for convenience --- cmd/geth/main.go | 1 + cmd/geth/usage.go | 1 + cmd/utils/flags.go | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 8ba46d38fe84..6e00463fa016 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -169,6 +169,7 @@ var ( utils.L1DeploymentBlockFlag, utils.CircuitCapacityCheckEnabledFlag, utils.RollupVerifyEnabledFlag, + utils.ShadowforkFlag, } rpcFlags = []cli.Flag{ diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 1fa00a384e2b..84be7d19f2a8 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -237,6 +237,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{ utils.BloomFilterSizeFlag, cli.HelpFlag, utils.CatalystFlag, + utils.ShadowforkFlag, }, }, } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index b547fe25204e..29c5504926fc 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -858,6 +858,12 @@ var ( Name: "rpc.getlogs.maxrange", Usage: "Limit max fetched block range for `eth_getLogs` method", } + + // Clique shadowfork + ShadowforkFlag = cli.StringFlag{ + Name: "clique.shadowfork", + Usage: "Schedule a shadow fork for a given signer to takeover at a given height", + } ) // MakeDataDir retrieves the currently requested data directory, terminating @@ -1888,6 +1894,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { log.Warn("Using legacy db prefix for L1 messages") rawdb.SetL1MessageLegacyPrefix() } + setShadowFork(ctx, cfg.Genesis.Config.Clique) } // SetDNSDiscoveryDefaults configures DNS discovery with the given URL if @@ -2088,6 +2095,20 @@ func MakeGenesis(ctx *cli.Context) *core.Genesis { return genesis } +func setShadowFork(ctx *cli.Context, cfg *params.CliqueConfig) { + if ctx.GlobalIsSet(ShadowforkFlag.Name) { + config := ctx.GlobalString(ShadowforkFlag.Name) + args := strings.Split(config, ",") + var err error + cfg.ShadowForkHeight, err = strconv.ParseUint(args[0], 10, 64) + if err != nil { + Fatalf("cannot parse shadowfork height", "err", err) + } + cfg.ShadowForkSigner = common.HexToAddress(args[1]) + log.Info("Shadow fork enabled", "height", cfg.ShadowForkHeight, "signer", cfg.ShadowForkSigner) + } +} + // MakeChain creates a chain manager from set command line flags. func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chainDb ethdb.Database) { var err error From 949cee7450ea0349b84b78c475f6bf973732ce41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Tue, 25 Jun 2024 12:52:48 +0300 Subject: [PATCH 05/18] relaxed shadow fork height constraint --- consensus/clique/clique.go | 4 ---- consensus/clique/clique_test.go | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 8bcfd1c2b5c3..a40073acebe2 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -196,10 +196,6 @@ func New(config *params.CliqueConfig, db ethdb.Database) *Clique { conf.Epoch = epochLength } - if conf.ShadowForkHeight > 0 && conf.ShadowForkHeight%conf.Epoch != 0 { - panic("ShadowForkHeight must be a multiple of Epoch") - } - // Allocate the snapshot caches and create the engine recents, _ := lru.NewARC(inmemorySnapshots) signatures, _ := lru.NewARC(inmemorySignatures) diff --git a/consensus/clique/clique_test.go b/consensus/clique/clique_test.go index 1fde431d39cb..f7190ff174ed 100644 --- a/consensus/clique/clique_test.go +++ b/consensus/clique/clique_test.go @@ -132,7 +132,7 @@ func TestShadowFork(t *testing.T) { engineConf := *params.AllCliqueProtocolChanges.Clique engineConf.Epoch = 2 forkedEngineConf := engineConf - forkedEngineConf.ShadowForkHeight = 4 + forkedEngineConf.ShadowForkHeight = 3 shadowForkKey, _ := crypto.HexToECDSA(strings.Repeat("11", 32)) shadowForkAddr := crypto.PubkeyToAddress(shadowForkKey.PublicKey) forkedEngineConf.ShadowForkSigner = shadowForkAddr From 6a2c52856b8de8714438fe89ce0449b8047e20f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Tue, 25 Jun 2024 13:54:31 +0300 Subject: [PATCH 06/18] inflate shadow fork difficulty --- consensus/clique/clique.go | 26 +++++++++++++++----------- consensus/clique/clique_test.go | 9 ++++++--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index a40073acebe2..4aaed107ad36 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -22,6 +22,7 @@ import ( "errors" "fmt" "io" + "math" "math/big" "math/rand" "sync" @@ -66,8 +67,9 @@ var ( uncleHash = types.CalcUncleHash(nil) // Always Keccak256(RLP([])) as uncles are meaningless outside of PoW. - diffInTurn = big.NewInt(2) // Block difficulty for in-turn signatures - diffNoTurn = big.NewInt(1) // Block difficulty for out-of-turn signatures + diffInTurn = big.NewInt(2) // Block difficulty for in-turn signatures + diffNoTurn = big.NewInt(1) // Block difficulty for out-of-turn signatures + diffShadowFork = big.NewInt(math.MaxInt64) ) // Various error messages to mark blocks invalid. These should be private to @@ -292,7 +294,7 @@ func (c *Clique) verifyHeader(chain consensus.ChainHeaderReader, header *types.H } // Ensure that the block's difficulty is meaningful (may not be correct at this point) if number > 0 { - if header.Difficulty == nil || (header.Difficulty.Cmp(diffInTurn) != 0 && header.Difficulty.Cmp(diffNoTurn) != 0) { + if header.Difficulty == nil || (header.Difficulty.Cmp(diffInTurn) != 0 && header.Difficulty.Cmp(diffNoTurn) != 0 && header.Difficulty.Cmp(diffShadowFork) != 0) { return errInvalidDifficulty } } @@ -494,11 +496,8 @@ func (c *Clique) verifySeal(snap *Snapshot, header *types.Header, parents []*typ } // Ensure that the difficulty corresponds to the turn-ness of the signer if !c.fakeDiff { - inturn := snap.inturn(header.Number.Uint64(), signer) - if inturn && header.Difficulty.Cmp(diffInTurn) != 0 { - return errWrongDifficulty - } - if !inturn && header.Difficulty.Cmp(diffNoTurn) != 0 { + expected := c.calcDifficulty(snap, signer) + if header.Difficulty.Cmp(expected) != 0 { return errWrongDifficulty } } @@ -543,7 +542,7 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header c.lock.RUnlock() // Set the correct difficulty - header.Difficulty = calcDifficulty(snap, signer) + header.Difficulty = c.calcDifficulty(snap, signer) // Ensure the extra data has all its components if len(header.Extra) < extraVanity { @@ -687,10 +686,15 @@ func (c *Clique) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, c.lock.RLock() signer := c.signer c.lock.RUnlock() - return calcDifficulty(snap, signer) + return c.calcDifficulty(snap, signer) } -func calcDifficulty(snap *Snapshot, signer common.Address) *big.Int { +func (c *Clique) calcDifficulty(snap *Snapshot, signer common.Address) *big.Int { + if c.config.ShadowForkHeight > 0 && snap.Number >= c.config.ShadowForkHeight { + // if we are past shadow fork point, set a high difficulty so that forked nodes don't switch to main chain + // unexpectedly. + return new(big.Int).Set(diffShadowFork) + } if snap.inturn(snap.Number+1, signer) { return new(big.Int).Set(diffInTurn) } diff --git a/consensus/clique/clique_test.go b/consensus/clique/clique_test.go index f7190ff174ed..67e0e8c620f7 100644 --- a/consensus/clique/clique_test.go +++ b/consensus/clique/clique_test.go @@ -163,10 +163,14 @@ func TestShadowFork(t *testing.T) { forkedChain, _ := core.NewBlockChain(db, nil, params.AllCliqueProtocolChanges, forkedEngine, vm.Config{}, nil, nil) defer forkedChain.Stop() - blocks, _ := core.GenerateChain(params.AllCliqueProtocolChanges, genesis, engine, db, 16, func(i int, block *core.BlockGen) { + blocks, _ := core.GenerateChain(params.AllCliqueProtocolChanges, genesis, forkedEngine, db, 16, func(i int, block *core.BlockGen) { // The chain maker doesn't have access to a chain, so the difficulty will be // lets unset (nil). Set it here to the correct value. - block.SetDifficulty(diffInTurn) + if block.Number().Uint64() > forkedEngineConf.ShadowForkHeight { + block.SetDifficulty(diffShadowFork) + } else { + block.SetDifficulty(diffInTurn) + } tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr), common.Address{0x00}, new(big.Int), params.TxGas, block.BaseFee(), nil), signer, key) if err != nil { @@ -191,7 +195,6 @@ func TestShadowFork(t *testing.T) { header.Extra = append(header.Extra, signingAddr.Bytes()...) } header.Extra = append(header.Extra, bytes.Repeat([]byte{0}, extraSeal)...) - header.Difficulty = diffInTurn sig, _ := crypto.Sign(SealHash(header).Bytes(), signingKey) copy(header.Extra[len(header.Extra)-extraSeal:], sig) From f2bc93060c7deec5c113d02a56155426109c6c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Tue, 25 Jun 2024 14:04:20 +0300 Subject: [PATCH 07/18] add shadow fork peers flag --- cmd/geth/main.go | 1 + cmd/geth/usage.go | 1 + cmd/utils/flags.go | 10 ++++++++++ eth/backend.go | 19 ++++++++++--------- eth/ethconfig/config.go | 3 +++ 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 6e00463fa016..671f60d05bad 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -170,6 +170,7 @@ var ( utils.CircuitCapacityCheckEnabledFlag, utils.RollupVerifyEnabledFlag, utils.ShadowforkFlag, + utils.ShadowforkPeersFlag, } rpcFlags = []cli.Flag{ diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 84be7d19f2a8..497a4db21572 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -238,6 +238,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{ cli.HelpFlag, utils.CatalystFlag, utils.ShadowforkFlag, + utils.ShadowforkPeersFlag, }, }, } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 29c5504926fc..47dea56f82b5 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -864,6 +864,12 @@ var ( Name: "clique.shadowfork", Usage: "Schedule a shadow fork for a given signer to takeover at a given height", } + + // Shadowfork peers + ShadowforkPeersFlag = cli.StringSliceFlag{ + Name: "net.shadowforkpeer", + Usage: "peer id of a shadow fork peer", + } ) // MakeDataDir retrieves the currently requested data directory, terminating @@ -1657,6 +1663,10 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { setCircuitCapacityCheck(ctx, cfg) setEnableRollupVerify(ctx, cfg) setMaxBlockRange(ctx, cfg) + if ctx.GlobalIsSet(ShadowforkPeersFlag.Name) { + cfg.ShadowForkPeerIDs = ctx.GlobalStringSlice(ShadowforkPeersFlag.Name) + log.Info("Shadow fork peers", "ids", cfg.ShadowForkPeerIDs) + } // Cap the cache allowance and tune the garbage collector mem, err := gopsutil.VirtualMemory() diff --git a/eth/backend.go b/eth/backend.go index 280e956b619e..26e24293535f 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -239,15 +239,16 @@ func New(stack *node.Node, config *ethconfig.Config, l1Client sync_service.EthCl checkpoint = params.TrustedCheckpoints[genesisHash] } if eth.handler, err = newHandler(&handlerConfig{ - Database: chainDb, - Chain: eth.blockchain, - TxPool: eth.txPool, - Network: config.NetworkId, - Sync: config.SyncMode, - BloomCache: uint64(cacheLimit), - EventMux: eth.eventMux, - Checkpoint: checkpoint, - Whitelist: config.Whitelist, + Database: chainDb, + Chain: eth.blockchain, + TxPool: eth.txPool, + Network: config.NetworkId, + Sync: config.SyncMode, + BloomCache: uint64(cacheLimit), + EventMux: eth.eventMux, + Checkpoint: checkpoint, + Whitelist: config.Whitelist, + ShadowForkPeerIDs: config.ShadowForkPeerIDs, }); err != nil { return nil, err } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 4205c040873e..70871c7b9ff6 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -214,6 +214,9 @@ type Config struct { // Max block range for eth_getLogs api method MaxBlockRange int64 + + // + ShadowForkPeerIDs []string } // CreateConsensusEngine creates a consensus engine for the given chain configuration. From 060656ea2ca91fae949b0c3d1922bd5c0b197e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Tue, 2 Jul 2024 12:39:37 +0300 Subject: [PATCH 08/18] set lower difficulty instead of higher --- consensus/clique/clique.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 4aaed107ad36..448cf75efab0 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -22,7 +22,6 @@ import ( "errors" "fmt" "io" - "math" "math/big" "math/rand" "sync" @@ -69,7 +68,7 @@ var ( diffInTurn = big.NewInt(2) // Block difficulty for in-turn signatures diffNoTurn = big.NewInt(1) // Block difficulty for out-of-turn signatures - diffShadowFork = big.NewInt(math.MaxInt64) + diffShadowFork = diffNoTurn ) // Various error messages to mark blocks invalid. These should be private to @@ -691,8 +690,7 @@ func (c *Clique) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, func (c *Clique) calcDifficulty(snap *Snapshot, signer common.Address) *big.Int { if c.config.ShadowForkHeight > 0 && snap.Number >= c.config.ShadowForkHeight { - // if we are past shadow fork point, set a high difficulty so that forked nodes don't switch to main chain - // unexpectedly. + // if we are past shadow fork point, set a low difficulty so that mainnet nodes don't try to switch to forked chain return new(big.Int).Set(diffShadowFork) } if snap.inturn(snap.Number+1, signer) { From 335f3cd2642df1a79db7eb1e29a9c14edcdc7809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Wed, 3 Jul 2024 09:52:31 +0300 Subject: [PATCH 09/18] send existing txns to shadow fork peers only --- eth/handler.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eth/handler.go b/eth/handler.go index 9717f050ff7d..9a154c417d7a 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -318,7 +318,9 @@ func (h *handler) runEthPeer(peer *eth.Peer, handler eth.Handler) error { // Propagate existing transactions. new transactions appearing // after this will be sent via broadcasts. - h.syncTransactions(peer) + if h.shadowForkPeerIDs == nil || slices.Contains(h.shadowForkPeerIDs, peer.ID()) { + h.syncTransactions(peer) + } // If we have a trusted CHT, reject all peers below that (avoid fast sync eclipse) if h.checkpointHash != (common.Hash{}) { From 38af54d3bb0c6454d6e50ac4134a8ab58ee69c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Wed, 3 Jul 2024 15:24:36 +0300 Subject: [PATCH 10/18] Revert "feat: add shadowfork flag for conveience" This reverts commit 4a43466e2db6b0ad1e0d05702037d3da54803a98. --- cmd/geth/main.go | 1 - cmd/geth/usage.go | 1 - cmd/utils/flags.go | 21 --------------------- 3 files changed, 23 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 671f60d05bad..50f6ceda49b1 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -169,7 +169,6 @@ var ( utils.L1DeploymentBlockFlag, utils.CircuitCapacityCheckEnabledFlag, utils.RollupVerifyEnabledFlag, - utils.ShadowforkFlag, utils.ShadowforkPeersFlag, } diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 497a4db21572..26818ddfd14d 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -237,7 +237,6 @@ var AppHelpFlagGroups = []flags.FlagGroup{ utils.BloomFilterSizeFlag, cli.HelpFlag, utils.CatalystFlag, - utils.ShadowforkFlag, utils.ShadowforkPeersFlag, }, }, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 47dea56f82b5..3bfc44ac190c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -859,12 +859,6 @@ var ( Usage: "Limit max fetched block range for `eth_getLogs` method", } - // Clique shadowfork - ShadowforkFlag = cli.StringFlag{ - Name: "clique.shadowfork", - Usage: "Schedule a shadow fork for a given signer to takeover at a given height", - } - // Shadowfork peers ShadowforkPeersFlag = cli.StringSliceFlag{ Name: "net.shadowforkpeer", @@ -1904,7 +1898,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { log.Warn("Using legacy db prefix for L1 messages") rawdb.SetL1MessageLegacyPrefix() } - setShadowFork(ctx, cfg.Genesis.Config.Clique) } // SetDNSDiscoveryDefaults configures DNS discovery with the given URL if @@ -2105,20 +2098,6 @@ func MakeGenesis(ctx *cli.Context) *core.Genesis { return genesis } -func setShadowFork(ctx *cli.Context, cfg *params.CliqueConfig) { - if ctx.GlobalIsSet(ShadowforkFlag.Name) { - config := ctx.GlobalString(ShadowforkFlag.Name) - args := strings.Split(config, ",") - var err error - cfg.ShadowForkHeight, err = strconv.ParseUint(args[0], 10, 64) - if err != nil { - Fatalf("cannot parse shadowfork height", "err", err) - } - cfg.ShadowForkSigner = common.HexToAddress(args[1]) - log.Info("Shadow fork enabled", "height", cfg.ShadowForkHeight, "signer", cfg.ShadowForkSigner) - } -} - // MakeChain creates a chain manager from set command line flags. func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chainDb ethdb.Database) { var err error From bce3861e1096d02a91b5fbf5a68cd5098450276d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Mon, 8 Jul 2024 11:44:00 +0300 Subject: [PATCH 11/18] force a low basefee on shadow network --- consensus/misc/eip1559.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/consensus/misc/eip1559.go b/consensus/misc/eip1559.go index 1e6b54389f86..700b9f47546b 100644 --- a/consensus/misc/eip1559.go +++ b/consensus/misc/eip1559.go @@ -51,8 +51,11 @@ func VerifyEip1559Header(config *params.ChainConfig, parent, header *types.Heade // CalcBaseFee calculates the basefee of the header. func CalcBaseFee(config *params.ChainConfig, parent *types.Header, parentL1BaseFee *big.Int) *big.Int { - l2SequencerFee := big.NewInt(1000000) // 0.001 Gwei - provingFee := big.NewInt(47700000) // 0.0477 Gwei + if config.Clique != nil && config.Clique.ShadowForkHeight != 0 && parent.Number.Uint64() >= config.Clique.ShadowForkHeight { + return big.NewInt(10000000) // 0.01 Gwei + } + l2SequencerFee := big.NewInt(10000000) // 0.01 Gwei + provingFee := big.NewInt(140000000) // 0.14 Gwei // L1_base_fee * 0.0046 verificationFee := parentL1BaseFee From 8706dc2cc797ba3b9fe1b30a62d79b521076a074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Mon, 8 Jul 2024 14:44:04 +0300 Subject: [PATCH 12/18] unregister peer from downloader if requested to be dropeed --- eth/handler.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/eth/handler.go b/eth/handler.go index 9a154c417d7a..09e6b3d17e27 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -188,13 +188,16 @@ func newHandler(config *handlerConfig) (*handler, error) { h.stateBloom = trie.NewSyncBloom(config.BloomCache, config.Database) } - dropPeerFunc := h.removePeer + fetcherDropPeerFunc := h.removePeer + downloaderDropPeerFunc := h.removePeer // If we are shadowforking, don't drop peers. if config.ShadowForkPeerIDs != nil { - dropPeerFunc = func(id string) {} + downloaderDropPeerFunc = func(id string) { + h.downloader.UnregisterPeer(id) + } + fetcherDropPeerFunc = func(id string) {} } - - h.downloader = downloader.New(h.checkpointNumber, config.Database, h.stateBloom, h.eventMux, h.chain, nil, dropPeerFunc) + h.downloader = downloader.New(h.checkpointNumber, config.Database, h.stateBloom, h.eventMux, h.chain, nil, downloaderDropPeerFunc) // Construct the fetcher (short sync) validator := func(header *types.Header) error { @@ -229,7 +232,7 @@ func newHandler(config *handlerConfig) (*handler, error) { } return n, err } - h.blockFetcher = fetcher.NewBlockFetcher(false, nil, h.chain.GetBlockByHash, validator, h.BroadcastBlock, heighter, nil, inserter, dropPeerFunc) + h.blockFetcher = fetcher.NewBlockFetcher(false, nil, h.chain.GetBlockByHash, validator, h.BroadcastBlock, heighter, nil, inserter, fetcherDropPeerFunc) fetchTx := func(peer string, hashes []common.Hash) error { p := h.peers.peer(peer) From a33f4c2ebe61dbbd73aa24421a98f0e25e7a9e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Mon, 8 Jul 2024 16:38:58 +0300 Subject: [PATCH 13/18] unregister peer failing in downlaoder --- eth/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/handler.go b/eth/handler.go index 09e6b3d17e27..6e0a65298b24 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -193,7 +193,7 @@ func newHandler(config *handlerConfig) (*handler, error) { // If we are shadowforking, don't drop peers. if config.ShadowForkPeerIDs != nil { downloaderDropPeerFunc = func(id string) { - h.downloader.UnregisterPeer(id) + h.peers.unregisterPeer(id) } fetcherDropPeerFunc = func(id string) {} } From 0d7cf68d2a9fc00ab881757ffd685bd09444045b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Mon, 8 Jul 2024 18:01:25 +0300 Subject: [PATCH 14/18] after shadowfork boundry do not attempt to sync from main chain peers --- eth/handler.go | 17 +++++++---------- eth/peerset.go | 6 +++++- eth/sync.go | 12 +++++++++++- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/eth/handler.go b/eth/handler.go index 6e0a65298b24..6939a4d6823b 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -188,16 +188,7 @@ func newHandler(config *handlerConfig) (*handler, error) { h.stateBloom = trie.NewSyncBloom(config.BloomCache, config.Database) } - fetcherDropPeerFunc := h.removePeer - downloaderDropPeerFunc := h.removePeer - // If we are shadowforking, don't drop peers. - if config.ShadowForkPeerIDs != nil { - downloaderDropPeerFunc = func(id string) { - h.peers.unregisterPeer(id) - } - fetcherDropPeerFunc = func(id string) {} - } - h.downloader = downloader.New(h.checkpointNumber, config.Database, h.stateBloom, h.eventMux, h.chain, nil, downloaderDropPeerFunc) + h.downloader = downloader.New(h.checkpointNumber, config.Database, h.stateBloom, h.eventMux, h.chain, nil, h.removePeer) // Construct the fetcher (short sync) validator := func(header *types.Header) error { @@ -232,6 +223,12 @@ func newHandler(config *handlerConfig) (*handler, error) { } return n, err } + + fetcherDropPeerFunc := h.removePeer + // If we are shadowforking, don't drop peers. + if config.ShadowForkPeerIDs != nil { + fetcherDropPeerFunc = func(id string) {} + } h.blockFetcher = fetcher.NewBlockFetcher(false, nil, h.chain.GetBlockByHash, validator, h.BroadcastBlock, heighter, nil, inserter, fetcherDropPeerFunc) fetchTx := func(peer string, hashes []common.Hash) error { diff --git a/eth/peerset.go b/eth/peerset.go index fae769c3afda..77ef958336db 100644 --- a/eth/peerset.go +++ b/eth/peerset.go @@ -19,6 +19,7 @@ package eth import ( "errors" "math/big" + "slices" "sync" "github.com/scroll-tech/go-ethereum/common" @@ -231,7 +232,7 @@ func (ps *peerSet) snapLen() int { // peerWithHighestTD retrieves the known peer with the currently highest total // difficulty. -func (ps *peerSet) peerWithHighestTD() *eth.Peer { +func (ps *peerSet) peerWithHighestTD(allowList []string) *eth.Peer { ps.lock.RLock() defer ps.lock.RUnlock() @@ -240,6 +241,9 @@ func (ps *peerSet) peerWithHighestTD() *eth.Peer { bestTd *big.Int ) for _, p := range ps.peers { + if allowList != nil && !slices.Contains(allowList, p.ID()) { + continue + } if _, td := p.Head(); bestPeer == nil || td.Cmp(bestTd) > 0 { bestPeer, bestTd = p.Peer, td } diff --git a/eth/sync.go b/eth/sync.go index 5d5f0327d77d..c7328537c59d 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -156,8 +156,18 @@ func (cs *chainSyncer) nextSyncOp() *chainSyncOp { if cs.handler.peers.len() < minPeers { return nil } + + var syncAllowList []string + chainConfig := cs.handler.chain.Config() + currentHeight := cs.handler.chain.CurrentHeader().Number.Uint64() + if chainConfig.Clique != nil { + shadowForkHeight := chainConfig.Clique.ShadowForkHeight + if shadowForkHeight != 0 && currentHeight >= shadowForkHeight { + syncAllowList = cs.handler.shadowForkPeerIDs + } + } // We have enough peers, check TD - peer := cs.handler.peers.peerWithHighestTD() + peer := cs.handler.peers.peerWithHighestTD(syncAllowList) if peer == nil { return nil } From ec32d3914a24c33113ab8f24ab2f71a157701c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Wed, 31 Jul 2024 13:09:04 +0300 Subject: [PATCH 15/18] address review comments --- cmd/utils/flags.go | 4 ++-- eth/ethconfig/config.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 3bfc44ac190c..07605e42a839 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -861,8 +861,8 @@ var ( // Shadowfork peers ShadowforkPeersFlag = cli.StringSliceFlag{ - Name: "net.shadowforkpeer", - Usage: "peer id of a shadow fork peer", + Name: "net.shadowforkpeers", + Usage: "peer ids of shadow fork peers", } ) diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 70871c7b9ff6..ff46a725a443 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -215,7 +215,7 @@ type Config struct { // Max block range for eth_getLogs api method MaxBlockRange int64 - // + // List of peer ids that take part in the shadow-fork ShadowForkPeerIDs []string } From cd36433da26762603193cc16bbdb8b684ec12475 Mon Sep 17 00:00:00 2001 From: omerfirmak Date: Wed, 31 Jul 2024 10:10:52 +0000 Subject: [PATCH 16/18] =?UTF-8?q?chore:=20auto=20version=20bump=E2=80=89[b?= =?UTF-8?q?ot]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- params/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/version.go b/params/version.go index 8779b0e64665..fe87555ffb66 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 = 5 // Minor version component of the current release - VersionPatch = 18 // Patch version component of the current release + VersionPatch = 19 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string ) From 131820e9355febe8226565a46b11258eb0f60a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Wed, 31 Jul 2024 15:18:23 +0300 Subject: [PATCH 17/18] Update consensus/misc/eip1559.go Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> --- consensus/misc/eip1559.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/consensus/misc/eip1559.go b/consensus/misc/eip1559.go index 700b9f47546b..3d6458547a8f 100644 --- a/consensus/misc/eip1559.go +++ b/consensus/misc/eip1559.go @@ -54,8 +54,8 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header, parentL1BaseF if config.Clique != nil && config.Clique.ShadowForkHeight != 0 && parent.Number.Uint64() >= config.Clique.ShadowForkHeight { return big.NewInt(10000000) // 0.01 Gwei } - l2SequencerFee := big.NewInt(10000000) // 0.01 Gwei - provingFee := big.NewInt(140000000) // 0.14 Gwei + l2SequencerFee := big.NewInt(1000000) // 0.001 Gwei + provingFee := big.NewInt(47700000) // 0.0477 Gwei // L1_base_fee * 0.0046 verificationFee := parentL1BaseFee From a845dc97c63e214653119fbae627bff87caf1cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Wed, 31 Jul 2024 19:58:03 +0300 Subject: [PATCH 18/18] rename allowlist to whitelist --- eth/peerset.go | 4 ++-- eth/sync.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eth/peerset.go b/eth/peerset.go index 77ef958336db..14ee4df43607 100644 --- a/eth/peerset.go +++ b/eth/peerset.go @@ -232,7 +232,7 @@ func (ps *peerSet) snapLen() int { // peerWithHighestTD retrieves the known peer with the currently highest total // difficulty. -func (ps *peerSet) peerWithHighestTD(allowList []string) *eth.Peer { +func (ps *peerSet) peerWithHighestTD(whileList []string) *eth.Peer { ps.lock.RLock() defer ps.lock.RUnlock() @@ -241,7 +241,7 @@ func (ps *peerSet) peerWithHighestTD(allowList []string) *eth.Peer { bestTd *big.Int ) for _, p := range ps.peers { - if allowList != nil && !slices.Contains(allowList, p.ID()) { + if whileList != nil && !slices.Contains(whileList, p.ID()) { continue } if _, td := p.Head(); bestPeer == nil || td.Cmp(bestTd) > 0 { diff --git a/eth/sync.go b/eth/sync.go index c7328537c59d..06584696411f 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -157,17 +157,17 @@ func (cs *chainSyncer) nextSyncOp() *chainSyncOp { return nil } - var syncAllowList []string + var syncWhiteList []string chainConfig := cs.handler.chain.Config() currentHeight := cs.handler.chain.CurrentHeader().Number.Uint64() if chainConfig.Clique != nil { shadowForkHeight := chainConfig.Clique.ShadowForkHeight if shadowForkHeight != 0 && currentHeight >= shadowForkHeight { - syncAllowList = cs.handler.shadowForkPeerIDs + syncWhiteList = cs.handler.shadowForkPeerIDs } } // We have enough peers, check TD - peer := cs.handler.peers.peerWithHighestTD(syncAllowList) + peer := cs.handler.peers.peerWithHighestTD(syncWhiteList) if peer == nil { return nil }