From 407bab38a777a8f774dec90045c3af558366e67d Mon Sep 17 00:00:00 2001 From: niuxiaojie81 <85773309@qq.com> Date: Mon, 17 Jul 2023 18:30:02 +0800 Subject: [PATCH 01/42] snapshot disabled by default --- cmd/utils/cmd.go | 4 ++-- cmd/utils/flags.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 073fd8039e..4f5c75dc21 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -109,11 +109,11 @@ func monitorFreeDiskSpace(sigc chan os.Signal, path string, freeDiskSpaceCritica break } if freeSpace < freeDiskSpaceCritical { - log.Error("Low disk space. Gracefully shutting down Geth to prevent database corruption.", "available", common.StorageSize(freeSpace)) + log.Error("Low disk space. Gracefully shutting down PlatON to prevent database corruption.", "available", common.StorageSize(freeSpace)) sigc <- syscall.SIGTERM break } else if freeSpace < 2*freeDiskSpaceCritical { - log.Warn("Disk space is running low. Geth will shutdown if disk space runs below critical level.", "available", common.StorageSize(freeSpace), "critical_level", common.StorageSize(freeDiskSpaceCritical)) + log.Warn("Disk space is running low. PlatON will shutdown if disk space runs below critical level.", "available", common.StorageSize(freeSpace), "critical_level", common.StorageSize(freeDiskSpaceCritical)) } time.Sleep(60 * time.Second) } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 41e8c21a1e..0ef9e96fa4 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -260,9 +260,9 @@ var ( Usage: "Time interval to regenerate the trie cache journal", Value: ethconfig.Defaults.TrieCleanCacheRejournal, } - SnapshotFlag = cli.BoolTFlag{ + SnapshotFlag = cli.BoolFlag{ Name: "snapshot", - Usage: `Enables snapshot-database mode (default = enable)`, + Usage: `Enables snapshot-database mode`, } BloomFilterSizeFlag = cli.Uint64Flag{ Name: "bloomfilter.size", From 1cd6841a3f99af313534b6d6f03d5453d095ba08 Mon Sep 17 00:00:00 2001 From: niuxiaojie81 <85773309@qq.com> Date: Fri, 8 Sep 2023 17:27:12 +0800 Subject: [PATCH 02/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=93=8D=E5=BA=94GetPr?= =?UTF-8?q?epareBlock=E6=B6=88=E6=81=AF=E7=9A=84bug=EF=BC=88wal.SendPrepar?= =?UTF-8?q?eVote=E6=81=A2=E5=A4=8DprepareBlock=E6=97=B6=E7=BC=BA=E5=B0=91?= =?UTF-8?q?=E7=AD=BE=E5=90=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consensus/cbft/cbft.go | 2 +- consensus/cbft/sync_process.go | 2 +- consensus/cbft/types/crypto.go | 7 ++++++- consensus/cbft/types/crypto_test.go | 10 +++++++++- core/parallel_executor.go | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/consensus/cbft/cbft.go b/consensus/cbft/cbft.go index cda997d89b..9042801742 100644 --- a/consensus/cbft/cbft.go +++ b/consensus/cbft/cbft.go @@ -325,7 +325,7 @@ func (cbft *Cbft) ReceiveMessage(msg *ctypes.MsgInfo) error { cMsg := msg.Msg.(ctypes.ConsensusMsg) if invalidMsg(cMsg.EpochNum(), cMsg.ViewNum()) { - cbft.log.Debug("Invalid msg", "peer", msg.PeerID, "type", reflect.TypeOf(msg.Msg), "msg", msg.Msg.String()) + cbft.log.Trace("Invalid msg", "peer", msg.PeerID, "type", reflect.TypeOf(msg.Msg), "msg", msg.Msg.String()) return nil } diff --git a/consensus/cbft/sync_process.go b/consensus/cbft/sync_process.go index 06bdd6ebcf..0ec3bfc23a 100644 --- a/consensus/cbft/sync_process.go +++ b/consensus/cbft/sync_process.go @@ -248,7 +248,7 @@ func (cbft *Cbft) prepareVoteFetchRules(id string, vote *protocols.PrepareVote) func (cbft *Cbft) OnGetPrepareBlock(id string, msg *protocols.GetPrepareBlock) error { if msg.Epoch == cbft.state.Epoch() && msg.ViewNumber == cbft.state.ViewNumber() { prepareBlock := cbft.state.PrepareBlockByIndex(msg.BlockIndex) - if prepareBlock != nil { + if prepareBlock != nil && prepareBlock.Signature.NotEmpty() { cbft.log.Debug("Send PrepareBlock", "peer", id, "prepareBlock", prepareBlock.String()) cbft.network.Send(id, prepareBlock) } diff --git a/consensus/cbft/types/crypto.go b/consensus/cbft/types/crypto.go index f655033043..56f54facb3 100644 --- a/consensus/cbft/types/crypto.go +++ b/consensus/cbft/types/crypto.go @@ -14,10 +14,10 @@ // You should have received a copy of the GNU Lesser General Public License // along with the PlatON-Go library. If not, see . - package types import ( + "bytes" "fmt" "reflect" @@ -48,6 +48,11 @@ func (sig *Signature) Bytes() []byte { return target } +func (sig *Signature) NotEmpty() bool { + var a Signature + return bytes.Compare(sig.Bytes(), a.Bytes()) != 0 +} + // MarshalText returns the hex representation of a. func (sig Signature) MarshalText() ([]byte, error) { return hexutil.Bytes(sig[:]).MarshalText() diff --git a/consensus/cbft/types/crypto_test.go b/consensus/cbft/types/crypto_test.go index 55a7e57ae4..19c124279d 100644 --- a/consensus/cbft/types/crypto_test.go +++ b/consensus/cbft/types/crypto_test.go @@ -14,7 +14,6 @@ // You should have received a copy of the GNU Lesser General Public License // along with the PlatON-Go library. If not, see . - package types import ( @@ -106,3 +105,12 @@ func Test_ViewChangeQC_MaxBlock(t *testing.T) { epoch, viewNumber, blockEpoch, blockViewNumber, blockHash, blockNumber = viewChangeQC.MaxBlock() assert.Equal(t, uint64(0), epoch) } + +func Test_Signature_NotEmpty(t *testing.T) { + var sig Signature + assert.False(t, sig.NotEmpty()) + sig = Signature{byte(0), byte(0), byte(0)} + assert.False(t, sig.NotEmpty()) + sig = Signature{byte(0), byte(0), byte(1)} + assert.True(t, sig.NotEmpty()) +} diff --git a/core/parallel_executor.go b/core/parallel_executor.go index 7d68c58574..640634098f 100644 --- a/core/parallel_executor.go +++ b/core/parallel_executor.go @@ -263,7 +263,7 @@ func (exe *Executor) executeContractTransaction(ctx *ParallelContext, idx int) { ctx.AddPackedTx(tx) ctx.GetState().IncreaseTxIdx() ctx.AddReceipt(receipt) - log.Debug("Execute contract transaction success", "blockNumber", ctx.GetHeader().Number.Uint64(), "txHash", tx.Hash().Hex(), "gasPool", ctx.gp.Gas(), "txGasLimit", tx.Gas(), "gasUsed", receipt.GasUsed) + log.Trace("Execute contract transaction success", "blockNumber", ctx.GetHeader().Number.Uint64(), "txHash", tx.Hash().Hex(), "gasPool", ctx.gp.Gas(), "txGasLimit", tx.Gas(), "gasUsed", receipt.GasUsed) } func (exe *Executor) isContract(tx *types.Transaction, state *state.StateDB, ctx *ParallelContext) bool { From f72a6dc2d2c49abf6150a1dc03d850acab809f21 Mon Sep 17 00:00:00 2001 From: niuxiaojie81 <85773309@qq.com> Date: Fri, 8 Sep 2023 17:31:35 +0800 Subject: [PATCH 03/42] fix bug --- eth/handler_eth.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/eth/handler_eth.go b/eth/handler_eth.go index 0061928c1b..d12666a3c0 100644 --- a/eth/handler_eth.go +++ b/eth/handler_eth.go @@ -193,7 +193,7 @@ func (h *ethHandler) handleBlockAnnounces(peer *eth.Peer, hashes []common.Hash, unknownNumbers = make([]uint64, 0, len(numbers)) ) for i := 0; i < len(hashes); i++ { - if !h.chain.HasBlock(hashes[i], numbers[i]) { + if !h.chain.HasBlock(hashes[i], numbers[i]) && !h.engine.HasBlock(hashes[i], numbers[i]) { unknownHashes = append(unknownHashes, hashes[i]) unknownNumbers = append(unknownNumbers, numbers[i]) } @@ -207,6 +207,10 @@ func (h *ethHandler) handleBlockAnnounces(peer *eth.Peer, hashes []common.Hash, // handleBlockBroadcast is invoked from a peer's message handler when it transmits a // block broadcast for the local node to process. func (h *ethHandler) handleBlockBroadcast(peer *eth.Peer, block *types.Block) error { + if h.engine.HasBlock(block.Hash(), block.NumberU64()) { + return nil + } + // Schedule the block for import h.blockFetcher.Enqueue(peer.ID(), block) From 7a93b1b218c8524b9c53dad65f186df485e80f92 Mon Sep 17 00:00:00 2001 From: benbaley Date: Wed, 13 Sep 2023 15:02:34 +0800 Subject: [PATCH 04/42] fix downloader heighter mistake --- eth/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/handler.go b/eth/handler.go index 714adb211e..2732333dec 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -194,7 +194,7 @@ func newHandler(config *handlerConfig) (*handler, error) { return h.chain.Engine().VerifyHeader(h.chain, header, true) } heighter := func() uint64 { - return h.chain.CurrentBlock().NumberU64() + return h.chain.Engine().CurrentBlock().NumberU64() + 1 } inserter := func(blocks types.Blocks) (int, error) { // If fast sync is running, deny importing weird blocks. This is a problematic From 3d3447a02b45f00c627217e435dbd66eea452c99 Mon Sep 17 00:00:00 2001 From: benbaley Date: Wed, 13 Sep 2023 17:07:04 +0800 Subject: [PATCH 05/42] =?UTF-8?q?=E5=9B=9E=E9=80=80trueBN=E7=AE=97?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eth/handler_eth.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eth/handler_eth.go b/eth/handler_eth.go index 2da8b2024f..41c8bb7c6c 100644 --- a/eth/handler_eth.go +++ b/eth/handler_eth.go @@ -19,6 +19,7 @@ package eth import ( "errors" "fmt" + "math/big" "sync/atomic" "time" @@ -219,7 +220,7 @@ func (h *ethHandler) handleBlockBroadcast(peer *eth.Peer, block *types.Block) er // calculate the head hash and TD that the peer truly must have. var ( trueHead = block.ParentHash() - trueBN = block.Number() + trueBN = new(big.Int).Sub(block.Number(), big.NewInt(1)) ) // Update the peer's total difficulty if better than the previous if _, bn := peer.Head(); trueBN.Cmp(bn) > 0 { From d70277c2d8ef11890e3ff55a9ab95f596a8292c2 Mon Sep 17 00:00:00 2001 From: niuxiaojie81 <85773309@qq.com> Date: Mon, 18 Sep 2023 11:26:44 +0800 Subject: [PATCH 06/42] =?UTF-8?q?1=E3=80=81=E8=8A=82=E7=82=B9=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E4=B8=8D=E6=94=AF=E6=8C=81=E5=8C=BA=E5=9D=97?= =?UTF-8?q?=E5=9B=9E=E6=BB=9A=202=E3=80=81insertChain=E8=BF=87=E7=A8=8B?= =?UTF-8?q?=E4=B8=AD=EF=BC=8CCurrentBlock=E5=8F=AF=E8=83=BD=E8=A2=ABwoker?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E4=BF=AE=E6=94=B9=EF=BC=8C=E6=89=80=E4=BB=A5?= =?UTF-8?q?=E5=85=81=E8=AE=B8ErrKnownBlock=E9=94=99=E8=AF=AF=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E6=8A=9B=E5=87=BA=E9=98=B2=E6=AD=A2=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E8=A2=AB=E6=96=AD=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/utils/flags.go | 2 +- core/blockchain.go | 59 ++++++++++++++++++++++------------------ core/blockchain_cache.go | 2 +- miner/worker.go | 2 +- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index bcbc0e688e..d8a81ba536 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1353,7 +1353,7 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) ethapi.Backend } else { backend, err := eth.New(stack, cfg) if err != nil { - Fatalf("Failed to register the Ethereum service: %v", err) + Fatalf("Failed to register the PlatON service: %v", err) } stack.RegisterAPIs(tracers.APIs(backend.APIBackend)) return backend.APIBackend diff --git a/core/blockchain.go b/core/blockchain.go index 0d9f736b1b..10d5d78c1f 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -325,30 +325,34 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par // Make sure the state associated with the block is available head := bc.CurrentBlock() if _, err := state.New(head.Root(), bc.stateCache, bc.snaps); err != nil { - // Head state is missing, before the state recovery, find out the - // disk layer point of snapshot(if it's enabled). Make sure the - // rewound point is lower than disk layer. - var diskRoot common.Hash - if bc.cacheConfig.SnapshotLimit > 0 { - diskRoot = rawdb.ReadSnapshotRoot(bc.db) - } - if diskRoot != (common.Hash{}) { - log.Warn("Head state missing, repairing", "number", head.Number(), "hash", head.Hash(), "snaproot", diskRoot) - - snapDisk, err := bc.setHeadBeyondRoot(head.NumberU64(), diskRoot, true) - if err != nil { - return nil, err + log.Warn("Head state missing, repair not supported", "number", head.NumberU64(), "hash", head.Hash().String()) + return nil, fmt.Errorf("head state missing, repair not supported, number:%d, hash:%s", head.NumberU64(), head.Hash().String()) + /* + // Head state is missing, before the state recovery, find out the + // disk layer point of snapshot(if it's enabled). Make sure the + // rewound point is lower than disk layer. + var diskRoot common.Hash + if bc.cacheConfig.SnapshotLimit > 0 { + diskRoot = rawdb.ReadSnapshotRoot(bc.db) } - // Chain rewound, persist old snapshot number to indicate recovery procedure - if snapDisk != 0 { - rawdb.WriteSnapshotRecoveryNumber(bc.db, snapDisk) - } - } else { - log.Warn("Head state missing, repairing", "number", head.Number(), "hash", head.Hash()) - if _, err := bc.setHeadBeyondRoot(head.NumberU64(), common.Hash{}, true); err != nil { - return nil, err + if diskRoot != (common.Hash{}) { + log.Warn("Head state missing, repairing", "number", head.Number(), "hash", head.Hash(), "snaproot", diskRoot) + + snapDisk, err := bc.setHeadBeyondRoot(head.NumberU64(), diskRoot, true) + if err != nil { + return nil, err + } + // Chain rewound, persist old snapshot number to indicate recovery procedure + if snapDisk != 0 { + rawdb.WriteSnapshotRecoveryNumber(bc.db, snapDisk) + } + } else { + log.Warn("Head state missing, repairing", "number", head.Number(), "hash", head.Hash()) + if _, err := bc.setHeadBeyondRoot(head.NumberU64(), common.Hash{}, true); err != nil { + return nil, err + } } - } + */ } // Ensure that a previous crash in SetHead doesn't leave extra ancients @@ -399,10 +403,11 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par var recover bool head := bc.CurrentBlock() - if layer := rawdb.ReadSnapshotRecoveryNumber(bc.db); layer != nil && *layer > head.NumberU64() { - log.Warn("Enabling snapshot recovery", "chainhead", head.NumberU64(), "diskbase", *layer) - recover = true - } + // Repair not supported + //if layer := rawdb.ReadSnapshotRecoveryNumber(bc.db); layer != nil && *layer > head.NumberU64() { + // log.Warn("Enabling snapshot recovery", "chainhead", head.NumberU64(), "diskbase", *layer) + // recover = true + //} bc.snaps, _ = snapshot.New(bc.db, bc.stateCache.TrieDB(), bc.cacheConfig.SnapshotLimit, head.Root(), !bc.cacheConfig.SnapshotWait, true, recover) } @@ -1561,7 +1566,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er return it.index, err } // No validation errors for the first block (or chain prefix skipped) - for ; block != nil && err == nil; block, err = it.next() { + for ; block != nil && (err == nil || errors.Is(err, ErrKnownBlock)); block, err = it.next() { // If the chain is terminating, stop processing blocks if bc.insertStopped() { log.Debug("Abort during block processing") diff --git a/core/blockchain_cache.go b/core/blockchain_cache.go index a419df91cc..ae79a8ea50 100644 --- a/core/blockchain_cache.go +++ b/core/blockchain_cache.go @@ -328,7 +328,7 @@ func (bcc *BlockChainCache) executeBlock(block *types.Block, parent *types.Block t := time.Now() //to execute receipts, err := bcc.ProcessDirectly(block, state, parent) - log.Debug("Execute block", "number", block.Number(), "hash", block.Hash(), + log.Debug("Execute block", "number", block.Number(), "hash", block.Hash(), "stateRoot", block.Root().String(), "parentNumber", parent.Number(), "parentHash", parent.Hash(), "duration", time.Since(t), "makeState", elapse, "err", err) if err == nil { //save the receipts and state to consensusCache diff --git a/miner/worker.go b/miner/worker.go index 0b3ab72de1..bc4888f2bf 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -695,7 +695,7 @@ func (w *worker) taskLoop() { w.blockChainCache.WriteReceipts(sealHash, task.receipts, task.block.NumberU64()) w.blockChainCache.AddSealBlock(sealHash, task.block.NumberU64()) task.state.UpdateSnaps() - log.Debug("Add seal block to blockchain cache", "sealHash", sealHash, "number", task.block.NumberU64()) + log.Debug("Add seal block to blockchain cache", "sealHash", sealHash, "number", task.block.NumberU64(), "stateRoot", task.block.Root().String()) if err := cbftEngine.Seal(w.chain, task.block, w.prepareResultCh, stopCh, w.prepareCompleteCh); err != nil { log.Warn("Block sealing failed on bft engine", "err", err) w.commitWorkEnv.setCommitStatusIdle() From cee7ecf96d19ee140ff5af8d287a2843032bbd98 Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Wed, 20 Sep 2023 11:09:12 +0800 Subject: [PATCH 07/42] fix sha3Uncles --- core/types/block.go | 4 +++- internal/ethapi/api.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/types/block.go b/core/types/block.go index 9d5df87f52..4662e174fd 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -41,7 +41,9 @@ import ( ) var ( - EmptyRootHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") + EmptyRootHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") + EmptyUncleHash = rlpHash([]*Header(nil)) + // Extra field in the block header, maximum length ExtraMaxSize = 97 HttpEthCompatible = false diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 9d38bdc100..2ab6e45a3c 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1159,7 +1159,7 @@ func RPCMarshalHeader(head *types.Header, ethCompatible bool) map[string]interfa result["mixHash"] = common.ZeroHash result["nonce"] = hexutil.Bytes(head.Nonce[0:8]) result["timestamp"] = hexutil.Uint64(head.Time / 1000) - result["sha3Uncles"] = common.ZeroHash + result["sha3Uncles"] = types.EmptyUncleHash result["difficulty"] = (*hexutil.Big)(head.Number) } From 848b19808c074487d4ebf3ca15e3ddf59269d3d7 Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Wed, 20 Sep 2023 18:02:00 +0800 Subject: [PATCH 08/42] fix wal not write when stop block chain --- accounts/abi/bind/backends/simulated.go | 2 +- core/blockchain.go | 5 ++++- core/blockchain_cache.go | 2 +- core/chain_makers.go | 6 +++--- miner/worker.go | 3 +-- miner/worker_test.go | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index d15432936f..d928bff23b 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -117,7 +117,7 @@ func (b *SimulatedBackend) Commit() { panic(err) // This cannot happen unless the simulator is wrong, fail in that case } stateDB, _ := b.blockchain.State() - b.blockchain.WriteBlockWithState(b.pendingBlock, b.pendingReceipts, nil, stateDB, true) + b.blockchain.WriteBlockWithState(b.pendingBlock, b.pendingReceipts, nil, stateDB, true, nil) b.rollback() } diff --git a/core/blockchain.go b/core/blockchain.go index 0d9f736b1b..e572c5be0a 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1247,11 +1247,14 @@ func (bc *BlockChain) WriteBlockWithoutState(block *types.Block) (err error) { } // WriteBlockWithState writes the block and all associated state to the database. -func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) { +func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool, cbftBridgeUpdateChainState func()) (status WriteStatus, err error) { if !bc.chainmu.TryLock() { return NonStatTy, errInsertionInterrupted } defer bc.chainmu.Unlock() + if cbftBridgeUpdateChainState != nil { + cbftBridgeUpdateChainState() + } return bc.writeBlockWithState(block, receipts, logs, state, emitHeadEvent) } diff --git a/core/blockchain_cache.go b/core/blockchain_cache.go index a419df91cc..44f587827c 100644 --- a/core/blockchain_cache.go +++ b/core/blockchain_cache.go @@ -370,7 +370,7 @@ func (bcc *BlockChainCache) WriteBlock(block *types.Block) error { // Commit block and state to database. //block.SetExtraData(extraData) log.Debug("Write extra data", "txs", len(block.Transactions()), "extra", len(block.ExtraData())) - _, err := bcc.WriteBlockWithState(block, _receipts, nil, state, true) + _, err := bcc.WriteBlockWithState(block, _receipts, nil, state, true, nil) if err != nil { log.Error("Failed writing block to chain", "hash", block.Hash(), "number", block.NumberU64(), "err", err) return fmt.Errorf("failed writing block to chain, number:%d, hash:%s, err:%s", block.NumberU64(), block.Hash().String(), err.Error()) diff --git a/core/chain_makers.go b/core/chain_makers.go index 50aa1abab8..af0840d923 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -263,7 +263,7 @@ func GenerateBlockChain2(config *params.ChainConfig, parent *types.Block, engine // Finalize and seal the block block, _ := b.engine.Finalize(chainreader, b.header, statedb, b.txs, b.receipts) - _, err := blockchain.WriteBlockWithState(block, b.receipts, nil, statedb, false) + _, err := blockchain.WriteBlockWithState(block, b.receipts, nil, statedb, false, nil) if err != nil { panic(err) } @@ -305,7 +305,7 @@ func GenerateBlockChain3(config *params.ChainConfig, parent *types.Block, engine // Finalize and seal the block block, _ := b.engine.Finalize(chainreader, b.header, statedb, b.txs, b.receipts) - _, err := chain.WriteBlockWithState(block, b.receipts, nil, statedb, false) + _, err := chain.WriteBlockWithState(block, b.receipts, nil, statedb, false, nil) if err != nil { panic(err) } @@ -360,7 +360,7 @@ func GenerateBlockChain(config *params.ChainConfig, parent *types.Block, engine // Finalize and seal the block block, _ := b.engine.Finalize(chainreader, b.header, statedb, b.txs, b.receipts) - _, err := blockchain.WriteBlockWithState(block, b.receipts, nil, statedb, false) + _, err := blockchain.WriteBlockWithState(block, b.receipts, nil, statedb, false, nil) if err != nil { panic(err) } diff --git a/miner/worker.go b/miner/worker.go index 0b3ab72de1..622c21a166 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -809,8 +809,7 @@ func (w *worker) resultLoop() { block.SetExtraData(cbftResult.ExtraData) log.Debug("Write extra data", "txs", len(block.Transactions()), "extra", len(block.ExtraData())) // update 3-chain state - cbftResult.ChainStateUpdateCB() - _, err := w.chain.WriteBlockWithState(block, receipts, logs, _state, true) + _, err := w.chain.WriteBlockWithState(block, receipts, logs, _state, true, cbftResult.ChainStateUpdateCB) if err != nil { if cbftResult.SyncState != nil { cbftResult.SyncState <- err diff --git a/miner/worker_test.go b/miner/worker_test.go index 907e3df3df..659680b496 100644 --- a/miner/worker_test.go +++ b/miner/worker_test.go @@ -196,7 +196,7 @@ func newTestWorker(t *testing.T, chainConfig *params.ChainConfig, miningConfig * } // block write to real chain - _, err = w.chain.WriteBlockWithState(cbftResult.Block, nil, nil, stateDB, false) + _, err = w.chain.WriteBlockWithState(cbftResult.Block, nil, nil, stateDB, false, nil) if nil != err { panic(err) } From 1f76f912414456fae9c0a6609e537d6292ef9a51 Mon Sep 17 00:00:00 2001 From: benbaley Date: Fri, 22 Sep 2023 09:51:55 +0800 Subject: [PATCH 09/42] BlockFetcher modifies minQueueDist restriction --- eth/fetcher/block_fetcher.go | 8 ++++---- eth/fetcher/block_fetcher_test.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/eth/fetcher/block_fetcher.go b/eth/fetcher/block_fetcher.go index b8a234d256..18a4fcfb78 100644 --- a/eth/fetcher/block_fetcher.go +++ b/eth/fetcher/block_fetcher.go @@ -38,7 +38,7 @@ const ( ) const ( - maxUncleDist = 7 // Maximum allowed backward distance from the chain head + minQueueDist = 0 // minimum allowed distance from the chain head to queue maxQueueDist = 32 // Maximum allowed distance from the chain head to queue hashLimit = 256 // Maximum number of unique blocks a peer may have announced blockLimit = 64 // Maximum number of unique blocks a peer may have delivered @@ -342,7 +342,7 @@ func (f *BlockFetcher) loop() { break } // Otherwise if fresh and still unknown, try and import - if number+maxUncleDist < height || f.getBlock(hash) != nil { + if number+minQueueDist <= height || f.getBlock(hash) != nil { f.forgetBlock(hash) continue } @@ -366,7 +366,7 @@ func (f *BlockFetcher) loop() { } // If we have a valid block number, check that it's potentially useful if notification.number > 0 { - if dist := int64(notification.number) - int64(f.chainHeight()); dist < -maxUncleDist || dist > maxQueueDist { + if dist := int64(notification.number) - int64(f.chainHeight()); dist <= minQueueDist || dist > maxQueueDist { log.Debug("Peer discarded announcement", "peer", notification.origin, "number", notification.number, "hash", notification.hash, "distance", dist) blockAnnounceDropMeter.Mark(1) break @@ -661,7 +661,7 @@ func (f *BlockFetcher) enqueue(peer string, block *types.Block) { return } // Discard any past or too distant blocks - if dist := int64(block.NumberU64()) - int64(f.chainHeight()); dist < -maxUncleDist || dist > maxQueueDist { + if dist := int64(block.NumberU64()) - int64(f.chainHeight()); dist <= minQueueDist || dist > maxQueueDist { log.Debug("Discarded propagated block, too far away", "peer", peer, "number", block.Number(), "hash", hash, "distance", dist) blockBroadcastDropMeter.Mark(1) f.forgetHash(hash) diff --git a/eth/fetcher/block_fetcher_test.go b/eth/fetcher/block_fetcher_test.go index bcfc35193e..ea60411f01 100644 --- a/eth/fetcher/block_fetcher_test.go +++ b/eth/fetcher/block_fetcher_test.go @@ -536,7 +536,7 @@ func TestDistantPropagationDiscarding(t *testing.T) { hashes, blocks := makeChain(3*maxQueueDist, 0, genesis) head := hashes[len(hashes)/2] - low, high := len(hashes)/2+maxUncleDist+1, len(hashes)/2-maxQueueDist-1 + low, high := len(hashes)/2+minQueueDist+1, len(hashes)/2-maxQueueDist-1 // Create a tester and simulate a head block being the middle of the above chain tester := newTester() @@ -572,7 +572,7 @@ func testDistantAnnouncementDiscarding(t *testing.T, protocol int) { hashes, blocks := makeChain(3*maxQueueDist, 0, genesis) head := hashes[len(hashes)/2] - low, high := len(hashes)/2+maxUncleDist+1, len(hashes)/2-maxQueueDist-1 + low, high := len(hashes)/2+minQueueDist+1, len(hashes)/2-maxQueueDist-1 // Create a tester and simulate a head block being the middle of the above chain tester := newTester() From 12ec047bfa9caffeee7a9d26bae966cf6a10f69b Mon Sep 17 00:00:00 2001 From: benbaley Date: Fri, 22 Sep 2023 09:53:38 +0800 Subject: [PATCH 10/42] fix sync --- core/snapshotdb/snapshotdb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/snapshotdb/snapshotdb.go b/core/snapshotdb/snapshotdb.go index 8b3b78bacb..f501499643 100644 --- a/core/snapshotdb/snapshotdb.go +++ b/core/snapshotdb/snapshotdb.go @@ -588,7 +588,7 @@ func (s *snapshotDB) findToWrite() int { var length = commitNum for i := 0; i < length; i++ { - if s.committed[i].Number.Cmp(minimumHeight) > 0 { + if s.committed[i].Number.Cmp(minimumHeight) >= 0 { commitNum-- } } From da2931f77f623c2c1098019ece82e99cdd46fedb Mon Sep 17 00:00:00 2001 From: benbaley Date: Fri, 22 Sep 2023 09:59:58 +0800 Subject: [PATCH 11/42] fix downloader heighter mistake --- consensus/cbft/cbft.go | 2 +- consensus/cbft/sync_process.go | 2 +- consensus/cbft/types/crypto.go | 7 ++++++- consensus/cbft/types/crypto_test.go | 10 +++++++++- core/parallel_executor.go | 2 +- eth/handler.go | 2 +- eth/handler_eth.go | 9 +++++++-- 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/consensus/cbft/cbft.go b/consensus/cbft/cbft.go index e0345cc796..d76ff846a5 100644 --- a/consensus/cbft/cbft.go +++ b/consensus/cbft/cbft.go @@ -324,7 +324,7 @@ func (cbft *Cbft) ReceiveMessage(msg *ctypes.MsgInfo) error { cMsg := msg.Msg.(ctypes.ConsensusMsg) if invalidMsg(cMsg.EpochNum(), cMsg.ViewNum()) { - cbft.log.Debug("Invalid msg", "peer", msg.PeerID, "type", reflect.TypeOf(msg.Msg), "msg", msg.Msg.String()) + cbft.log.Trace("Invalid msg", "peer", msg.PeerID, "type", reflect.TypeOf(msg.Msg), "msg", msg.Msg.String()) return nil } diff --git a/consensus/cbft/sync_process.go b/consensus/cbft/sync_process.go index ce7beec441..67ec4ee439 100644 --- a/consensus/cbft/sync_process.go +++ b/consensus/cbft/sync_process.go @@ -248,7 +248,7 @@ func (cbft *Cbft) prepareVoteFetchRules(id string, vote *protocols.PrepareVote) func (cbft *Cbft) OnGetPrepareBlock(id string, msg *protocols.GetPrepareBlock) error { if msg.Epoch == cbft.state.Epoch() && msg.ViewNumber == cbft.state.ViewNumber() { prepareBlock := cbft.state.PrepareBlockByIndex(msg.BlockIndex) - if prepareBlock != nil { + if prepareBlock != nil && prepareBlock.Signature.NotEmpty() { cbft.log.Debug("Send PrepareBlock", "peer", id, "prepareBlock", prepareBlock.String()) cbft.network.Send(id, prepareBlock) } diff --git a/consensus/cbft/types/crypto.go b/consensus/cbft/types/crypto.go index f655033043..56f54facb3 100644 --- a/consensus/cbft/types/crypto.go +++ b/consensus/cbft/types/crypto.go @@ -14,10 +14,10 @@ // You should have received a copy of the GNU Lesser General Public License // along with the PlatON-Go library. If not, see . - package types import ( + "bytes" "fmt" "reflect" @@ -48,6 +48,11 @@ func (sig *Signature) Bytes() []byte { return target } +func (sig *Signature) NotEmpty() bool { + var a Signature + return bytes.Compare(sig.Bytes(), a.Bytes()) != 0 +} + // MarshalText returns the hex representation of a. func (sig Signature) MarshalText() ([]byte, error) { return hexutil.Bytes(sig[:]).MarshalText() diff --git a/consensus/cbft/types/crypto_test.go b/consensus/cbft/types/crypto_test.go index 55a7e57ae4..19c124279d 100644 --- a/consensus/cbft/types/crypto_test.go +++ b/consensus/cbft/types/crypto_test.go @@ -14,7 +14,6 @@ // You should have received a copy of the GNU Lesser General Public License // along with the PlatON-Go library. If not, see . - package types import ( @@ -106,3 +105,12 @@ func Test_ViewChangeQC_MaxBlock(t *testing.T) { epoch, viewNumber, blockEpoch, blockViewNumber, blockHash, blockNumber = viewChangeQC.MaxBlock() assert.Equal(t, uint64(0), epoch) } + +func Test_Signature_NotEmpty(t *testing.T) { + var sig Signature + assert.False(t, sig.NotEmpty()) + sig = Signature{byte(0), byte(0), byte(0)} + assert.False(t, sig.NotEmpty()) + sig = Signature{byte(0), byte(0), byte(1)} + assert.True(t, sig.NotEmpty()) +} diff --git a/core/parallel_executor.go b/core/parallel_executor.go index e461c8a905..e22220054b 100644 --- a/core/parallel_executor.go +++ b/core/parallel_executor.go @@ -225,7 +225,7 @@ func (exe *Executor) executeContractTransaction(ctx *ParallelContext, idx int) { ctx.AddPackedTx(tx) ctx.GetState().IncreaseTxIdx() ctx.AddReceipt(receipt) - log.Debug("Execute contract transaction success", "blockNumber", ctx.GetHeader().Number.Uint64(), "txHash", tx.Hash().Hex(), "gasPool", ctx.gp.Gas(), "txGasLimit", tx.Gas(), "gasUsed", receipt.GasUsed) + log.Trace("Execute contract transaction success", "blockNumber", ctx.GetHeader().Number.Uint64(), "txHash", tx.Hash().Hex(), "gasPool", ctx.gp.Gas(), "txGasLimit", tx.Gas(), "gasUsed", receipt.GasUsed) } func (exe *Executor) isContract(tx *types.Transaction, state *state.StateDB, ctx *ParallelContext) bool { diff --git a/eth/handler.go b/eth/handler.go index f73a31b189..ad848f1935 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -203,7 +203,7 @@ func newHandler(config *handlerConfig) (*handler, error) { return h.chain.Engine().VerifyHeader(h.chain, header, true) } heighter := func() uint64 { - return h.chain.CurrentBlock().NumberU64() + return h.chain.Engine().CurrentBlock().NumberU64() + 1 } inserter := func(blocks types.Blocks) (int, error) { // If fast sync is running, deny importing weird blocks. This is a problematic diff --git a/eth/handler_eth.go b/eth/handler_eth.go index 0ba3343563..a40e83fa73 100644 --- a/eth/handler_eth.go +++ b/eth/handler_eth.go @@ -19,6 +19,7 @@ package eth import ( "errors" "fmt" + "math/big" "sync/atomic" "time" @@ -195,7 +196,7 @@ func (h *ethHandler) handleBlockAnnounces(peer *eth.Peer, hashes []common.Hash, unknownNumbers = make([]uint64, 0, len(numbers)) ) for i := 0; i < len(hashes); i++ { - if !h.chain.HasBlock(hashes[i], numbers[i]) { + if !h.chain.HasBlock(hashes[i], numbers[i]) && !h.engine.HasBlock(hashes[i], numbers[i]) { unknownHashes = append(unknownHashes, hashes[i]) unknownNumbers = append(unknownNumbers, numbers[i]) } @@ -209,6 +210,10 @@ func (h *ethHandler) handleBlockAnnounces(peer *eth.Peer, hashes []common.Hash, // handleBlockBroadcast is invoked from a peer's message handler when it transmits a // block broadcast for the local node to process. func (h *ethHandler) handleBlockBroadcast(peer *eth.Peer, block *types.Block) error { + if h.engine.HasBlock(block.Hash(), block.NumberU64()) { + return nil + } + // Schedule the block for import h.blockFetcher.Enqueue(peer.ID(), block) @@ -216,7 +221,7 @@ func (h *ethHandler) handleBlockBroadcast(peer *eth.Peer, block *types.Block) er // calculate the head hash and TD that the peer truly must have. var ( trueHead = block.ParentHash() - trueBN = block.Number() + trueBN = new(big.Int).Sub(block.Number(), big.NewInt(1)) ) // Update the peer's total difficulty if better than the previous if _, bn := peer.Head(); trueBN.Cmp(bn) > 0 { From 9b9c20d2da9022ad9d7df020724ef105f8488632 Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Fri, 22 Sep 2023 10:04:02 +0800 Subject: [PATCH 12/42] fix(p2p): fix addconsensus and removeconsensus --- p2p/server.go | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/p2p/server.go b/p2p/server.go index 241b00ef37..ac9a3bb160 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -381,33 +381,17 @@ func (srv *Server) RemovePeer(node *enode.Node) { // server is shut down. If the connection fails for any reason, the server will // attempt to reconnect the peer. func (srv *Server) AddConsensusPeer(node *enode.Node) { - srv.dialsched.addConsensus(node) + select { + case srv.addconsensus <- node: + case <-srv.quit: + } } // RemoveConsensusPeer disconnects from the given consensus node func (srv *Server) RemoveConsensusPeer(node *enode.Node) { - var ( - ch chan *PeerEvent - sub event.Subscription - ) - // Disconnect the peer on the main loop. - srv.doPeerOp(func(peers map[enode.ID]*Peer) { - srv.dialsched.removeConsensus(node) - if peer := peers[node.ID()]; peer != nil { - ch = make(chan *PeerEvent, 1) - sub = srv.peerFeed.Subscribe(ch) - peer.Disconnect(DiscRequested) - } - }) - srv.log.Trace("Removing consensus node from dialstate", "node", node) - // Wait for the peer connection to end. - if ch != nil { - defer sub.Unsubscribe() - for ev := range ch { - if ev.Peer == node.ID() && ev.Type == PeerEventTypeDrop { - return - } - } + select { + case srv.removeconsensus <- node: + case <-srv.quit: } } From 494123b690c43176a412eeb90ae0f3d791ed3bb6 Mon Sep 17 00:00:00 2001 From: benbaley Date: Fri, 22 Sep 2023 10:14:46 +0800 Subject: [PATCH 13/42] fix sha3Uncles --- core/types/block.go | 4 +++- internal/ethapi/api.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/types/block.go b/core/types/block.go index 53ab93b06f..ab0f5dc039 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -41,7 +41,9 @@ import ( ) var ( - EmptyRootHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") + EmptyRootHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") + EmptyUncleHash = rlpHash([]*Header(nil)) + // Extra field in the block header, maximum length ExtraMaxSize = 97 HttpEthCompatible = false diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 6355f729a7..522755c39f 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1118,7 +1118,7 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} { if types.HttpEthCompatible { m["nonce"] = hexutil.Bytes(head.Nonce[0:8]) m["timestamp"] = hexutil.Uint64(head.Time / 1000) - m["sha3Uncles"] = common.ZeroHash + m["sha3Uncles"] = types.EmptyUncleHash m["difficulty"] = (*hexutil.Big)(head.Number) } From abd19d28d75eb1bb32aeb01338c215b4dd33ba04 Mon Sep 17 00:00:00 2001 From: benbaley Date: Fri, 22 Sep 2023 10:20:22 +0800 Subject: [PATCH 14/42] fix bugs --- cmd/utils/flags.go | 2 +- core/blockchain.go | 11 ++++++----- core/blockchain_cache.go | 2 +- miner/worker.go | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 0ef9e96fa4..bb3a6014d7 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1324,7 +1324,7 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) ethapi.Backend } else { backend, err := eth.New(stack, cfg) if err != nil { - Fatalf("Failed to register the Ethereum service: %v", err) + Fatalf("Failed to register the PlatON service: %v", err) } stack.RegisterAPIs(tracers.APIs(backend.APIBackend)) return backend.APIBackend diff --git a/core/blockchain.go b/core/blockchain.go index 3ae8463fc1..e681e80266 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -368,10 +368,11 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par var recover bool head := bc.CurrentBlock() - if layer := rawdb.ReadSnapshotRecoveryNumber(bc.db); layer != nil && *layer > head.NumberU64() { - log.Warn("Enabling snapshot recovery", "chainhead", head.NumberU64(), "diskbase", *layer) - recover = true - } + // Repair not supported + //if layer := rawdb.ReadSnapshotRecoveryNumber(bc.db); layer != nil && *layer > head.NumberU64() { + // log.Warn("Enabling snapshot recovery", "chainhead", head.NumberU64(), "diskbase", *layer) + // recover = true + //} bc.snaps, _ = snapshot.New(bc.db, bc.stateCache.TrieDB(), bc.cacheConfig.SnapshotLimit, head.Root(), !bc.cacheConfig.SnapshotWait, true, recover) } // Take ownership of this particular state @@ -1774,7 +1775,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er return it.index, err } // No validation errors for the first block (or chain prefix skipped) - for ; block != nil && err == nil; block, err = it.next() { + for ; block != nil && (err == nil || errors.Is(err, ErrKnownBlock)); block, err = it.next() { // If the chain is terminating, stop processing blocks if bc.insertStopped() { log.Debug("Abort during block processing") diff --git a/core/blockchain_cache.go b/core/blockchain_cache.go index a419df91cc..ae79a8ea50 100644 --- a/core/blockchain_cache.go +++ b/core/blockchain_cache.go @@ -328,7 +328,7 @@ func (bcc *BlockChainCache) executeBlock(block *types.Block, parent *types.Block t := time.Now() //to execute receipts, err := bcc.ProcessDirectly(block, state, parent) - log.Debug("Execute block", "number", block.Number(), "hash", block.Hash(), + log.Debug("Execute block", "number", block.Number(), "hash", block.Hash(), "stateRoot", block.Root().String(), "parentNumber", parent.Number(), "parentHash", parent.Hash(), "duration", time.Since(t), "makeState", elapse, "err", err) if err == nil { //save the receipts and state to consensusCache diff --git a/miner/worker.go b/miner/worker.go index d32fe5f771..d653d8e2ee 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -617,7 +617,7 @@ func (w *worker) taskLoop() { w.blockChainCache.WriteReceipts(sealHash, task.receipts, task.block.NumberU64()) w.blockChainCache.AddSealBlock(sealHash, task.block.NumberU64()) task.state.UpdateSnaps() - log.Debug("Add seal block to blockchain cache", "sealHash", sealHash, "number", task.block.NumberU64()) + log.Debug("Add seal block to blockchain cache", "sealHash", sealHash, "number", task.block.NumberU64(), "stateRoot", task.block.Root().String()) if err := cbftEngine.Seal(w.chain, task.block, w.prepareResultCh, stopCh, w.prepareCompleteCh); err != nil { log.Warn("Block sealing failed on bft engine", "err", err) w.commitWorkEnv.setCommitStatusIdle() From 2b25819e78a596938019bc45bac7db143a284420 Mon Sep 17 00:00:00 2001 From: benbaley Date: Fri, 22 Sep 2023 10:23:21 +0800 Subject: [PATCH 15/42] Modify the judgment of the fork logic in the handshake process --- consensus/cbft/network/handler.go | 9 ++++----- consensus/cbft/sync_process.go | 8 +++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/consensus/cbft/network/handler.go b/consensus/cbft/network/handler.go index 14c3862461..f504efba1e 100644 --- a/consensus/cbft/network/handler.go +++ b/consensus/cbft/network/handler.go @@ -392,11 +392,10 @@ func (h *EngineManager) handler(p *p2p.Peer, rw p2p.MsgReadWriter) error { return fmt.Errorf("illegal node: {%s}", peer.PeerID()) } - // If blockNumber in the local is better than the remote - // then determine if there is a fork. - if cbftStatus.QCBn.Uint64() > remoteStatus.QCBn.Uint64() { - err = h.engine.BlockExists(remoteStatus.QCBn.Uint64(), remoteStatus.QCBlock) - } + // QCBn fork allowed and does not require check + //if cbftStatus.QCBn.Uint64() > remoteStatus.QCBn.Uint64() { + // err = h.engine.BlockExists(remoteStatus.QCBn.Uint64(), remoteStatus.QCBlock) + //} if cbftStatus.LockBn.Uint64() > remoteStatus.LockBn.Uint64() { err = h.engine.BlockExists(remoteStatus.LockBn.Uint64(), remoteStatus.LockBlock) } diff --git a/consensus/cbft/sync_process.go b/consensus/cbft/sync_process.go index 67ec4ee439..0ec3bfc23a 100644 --- a/consensus/cbft/sync_process.go +++ b/consensus/cbft/sync_process.go @@ -802,9 +802,11 @@ func (cbft *Cbft) BlockExists(blockNumber uint64, blockHash common.Hash) error { return } block := cbft.blockTree.FindBlockByHash(blockHash) - if block = cbft.blockChain.GetBlock(blockHash, blockNumber); block == nil { - result <- fmt.Errorf("not found block by hash:%s, number:%d", blockHash.TerminalString(), blockNumber) - return + if block == nil { + if block = cbft.blockChain.GetBlock(blockHash, blockNumber); block == nil { + result <- fmt.Errorf("not found block by hash:%s, number:%d", blockHash.TerminalString(), blockNumber) + return + } } if block.Hash() != blockHash || blockNumber != block.NumberU64() { result <- fmt.Errorf("not match from block, hash:%s, number:%d, queriedHash:%s, queriedNumber:%d", From 40d3ca58798ba07c7339535a9e3db65dcf231a5a Mon Sep 17 00:00:00 2001 From: benbaley Date: Fri, 22 Sep 2023 10:33:31 +0800 Subject: [PATCH 16/42] fix rs race and misdisconnect --- accounts/abi/bind/backends/simulated.go | 2 +- core/blockchain.go | 7 +++++- core/blockchain_cache.go | 2 +- core/chain_makers.go | 6 ++--- miner/worker.go | 2 +- miner/worker_test.go | 2 +- p2p/server.go | 30 ++++++------------------- 7 files changed, 20 insertions(+), 31 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 068c93eb0a..0ff31ffb98 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -117,7 +117,7 @@ func (b *SimulatedBackend) Commit() { panic(err) // This cannot happen unless the simulator is wrong, fail in that case } stateDB, _ := b.blockchain.State() - b.blockchain.WriteBlockWithState(b.pendingBlock, b.pendingReceipts, nil, stateDB, true) + b.blockchain.WriteBlockWithState(b.pendingBlock, b.pendingReceipts, nil, stateDB, true, nil) b.rollback() } diff --git a/core/blockchain.go b/core/blockchain.go index e681e80266..1eb0409583 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1472,10 +1472,15 @@ func (bc *BlockChain) WriteBlockWithoutState(block *types.Block) (err error) { } // WriteBlockWithState writes the block and all associated state to the database. -func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) { +func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, + emitHeadEvent bool, cbftBridgeUpdateChainState func()) (status WriteStatus, err error) { bc.wg.Add(1) defer bc.wg.Done() + if cbftBridgeUpdateChainState != nil { + cbftBridgeUpdateChainState() + } + // Make sure no inconsistent state is leaked during insertion currentBlock := bc.CurrentBlock() if block.NumberU64() <= currentBlock.NumberU64() { diff --git a/core/blockchain_cache.go b/core/blockchain_cache.go index ae79a8ea50..7c85953734 100644 --- a/core/blockchain_cache.go +++ b/core/blockchain_cache.go @@ -370,7 +370,7 @@ func (bcc *BlockChainCache) WriteBlock(block *types.Block) error { // Commit block and state to database. //block.SetExtraData(extraData) log.Debug("Write extra data", "txs", len(block.Transactions()), "extra", len(block.ExtraData())) - _, err := bcc.WriteBlockWithState(block, _receipts, nil, state, true) + _, err := bcc.WriteBlockWithState(block, _receipts, nil, state, true, nil) if err != nil { log.Error("Failed writing block to chain", "hash", block.Hash(), "number", block.NumberU64(), "err", err) return fmt.Errorf("failed writing block to chain, number:%d, hash:%s, err:%s", block.NumberU64(), block.Hash().String(), err.Error()) diff --git a/core/chain_makers.go b/core/chain_makers.go index 8a794fc12e..1628c2ec24 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -249,7 +249,7 @@ func GenerateBlockChain2(config *params.ChainConfig, parent *types.Block, engine // Finalize and seal the block block, _ := b.engine.Finalize(chainreader, b.header, statedb, b.txs, b.receipts) - _, err := blockchain.WriteBlockWithState(block, b.receipts, nil, statedb, false) + _, err := blockchain.WriteBlockWithState(block, b.receipts, nil, statedb, false, nil) if err != nil { panic(err) } @@ -291,7 +291,7 @@ func GenerateBlockChain3(config *params.ChainConfig, parent *types.Block, engine // Finalize and seal the block block, _ := b.engine.Finalize(chainreader, b.header, statedb, b.txs, b.receipts) - _, err := chain.WriteBlockWithState(block, b.receipts, nil, statedb, false) + _, err := chain.WriteBlockWithState(block, b.receipts, nil, statedb, false, nil) if err != nil { panic(err) } @@ -346,7 +346,7 @@ func GenerateBlockChain(config *params.ChainConfig, parent *types.Block, engine // Finalize and seal the block block, _ := b.engine.Finalize(chainreader, b.header, statedb, b.txs, b.receipts) - _, err := blockchain.WriteBlockWithState(block, b.receipts, nil, statedb, false) + _, err := blockchain.WriteBlockWithState(block, b.receipts, nil, statedb, false, nil) if err != nil { panic(err) } diff --git a/miner/worker.go b/miner/worker.go index d653d8e2ee..2f2fe6d4d9 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -722,7 +722,7 @@ func (w *worker) resultLoop() { log.Debug("Write extra data", "txs", len(block.Transactions()), "extra", len(block.ExtraData())) // update 3-chain state cbftResult.ChainStateUpdateCB() - _, err := w.chain.WriteBlockWithState(block, receipts, logs, _state, true) + _, err := w.chain.WriteBlockWithState(block, receipts, logs, _state, true, cbftResult.ChainStateUpdateCB) if err != nil { if cbftResult.SyncState != nil { cbftResult.SyncState <- err diff --git a/miner/worker_test.go b/miner/worker_test.go index 7850a9eded..95c32d615d 100644 --- a/miner/worker_test.go +++ b/miner/worker_test.go @@ -190,7 +190,7 @@ func newTestWorker(t *testing.T, chainConfig *params.ChainConfig, miningConfig * } // block write to real chain - _, err = w.chain.WriteBlockWithState(cbftResult.Block, nil, nil, stateDB, false) + _, err = w.chain.WriteBlockWithState(cbftResult.Block, nil, nil, stateDB, false, nil) if nil != err { panic(err) } diff --git a/p2p/server.go b/p2p/server.go index b7903fe489..8b0b40eb2b 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -381,33 +381,17 @@ func (srv *Server) RemovePeer(node *enode.Node) { // server is shut down. If the connection fails for any reason, the server will // attempt to reconnect the peer. func (srv *Server) AddConsensusPeer(node *enode.Node) { - srv.dialsched.addConsensus(node) + select { + case srv.addconsensus <- node: + case <-srv.quit: + } } // RemoveConsensusPeer disconnects from the given consensus node func (srv *Server) RemoveConsensusPeer(node *enode.Node) { - var ( - ch chan *PeerEvent - sub event.Subscription - ) - // Disconnect the peer on the main loop. - srv.doPeerOp(func(peers map[enode.ID]*Peer) { - srv.dialsched.removeConsensus(node) - if peer := peers[node.ID()]; peer != nil { - ch = make(chan *PeerEvent, 1) - sub = srv.peerFeed.Subscribe(ch) - peer.Disconnect(DiscRequested) - } - }) - srv.log.Trace("Removing consensus node from dialstate", "node", node) - // Wait for the peer connection to end. - if ch != nil { - defer sub.Unsubscribe() - for ev := range ch { - if ev.Peer == node.ID() && ev.Type == PeerEventTypeDrop { - return - } - } + select { + case srv.removeconsensus <- node: + case <-srv.quit: } } From e6765163a76d586aeb3e1602152f85349755bded Mon Sep 17 00:00:00 2001 From: benbaley Date: Fri, 22 Sep 2023 10:44:10 +0800 Subject: [PATCH 17/42] remove wal write fun --- accounts/abi/bind/backends/simulated.go | 2 +- core/blockchain.go | 7 +------ core/blockchain_cache.go | 2 +- core/chain_makers.go | 6 +++--- miner/worker.go | 2 +- miner/worker_test.go | 2 +- 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 0ff31ffb98..068c93eb0a 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -117,7 +117,7 @@ func (b *SimulatedBackend) Commit() { panic(err) // This cannot happen unless the simulator is wrong, fail in that case } stateDB, _ := b.blockchain.State() - b.blockchain.WriteBlockWithState(b.pendingBlock, b.pendingReceipts, nil, stateDB, true, nil) + b.blockchain.WriteBlockWithState(b.pendingBlock, b.pendingReceipts, nil, stateDB, true) b.rollback() } diff --git a/core/blockchain.go b/core/blockchain.go index 1eb0409583..e681e80266 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1472,15 +1472,10 @@ func (bc *BlockChain) WriteBlockWithoutState(block *types.Block) (err error) { } // WriteBlockWithState writes the block and all associated state to the database. -func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, - emitHeadEvent bool, cbftBridgeUpdateChainState func()) (status WriteStatus, err error) { +func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) { bc.wg.Add(1) defer bc.wg.Done() - if cbftBridgeUpdateChainState != nil { - cbftBridgeUpdateChainState() - } - // Make sure no inconsistent state is leaked during insertion currentBlock := bc.CurrentBlock() if block.NumberU64() <= currentBlock.NumberU64() { diff --git a/core/blockchain_cache.go b/core/blockchain_cache.go index 7c85953734..ae79a8ea50 100644 --- a/core/blockchain_cache.go +++ b/core/blockchain_cache.go @@ -370,7 +370,7 @@ func (bcc *BlockChainCache) WriteBlock(block *types.Block) error { // Commit block and state to database. //block.SetExtraData(extraData) log.Debug("Write extra data", "txs", len(block.Transactions()), "extra", len(block.ExtraData())) - _, err := bcc.WriteBlockWithState(block, _receipts, nil, state, true, nil) + _, err := bcc.WriteBlockWithState(block, _receipts, nil, state, true) if err != nil { log.Error("Failed writing block to chain", "hash", block.Hash(), "number", block.NumberU64(), "err", err) return fmt.Errorf("failed writing block to chain, number:%d, hash:%s, err:%s", block.NumberU64(), block.Hash().String(), err.Error()) diff --git a/core/chain_makers.go b/core/chain_makers.go index 1628c2ec24..8a794fc12e 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -249,7 +249,7 @@ func GenerateBlockChain2(config *params.ChainConfig, parent *types.Block, engine // Finalize and seal the block block, _ := b.engine.Finalize(chainreader, b.header, statedb, b.txs, b.receipts) - _, err := blockchain.WriteBlockWithState(block, b.receipts, nil, statedb, false, nil) + _, err := blockchain.WriteBlockWithState(block, b.receipts, nil, statedb, false) if err != nil { panic(err) } @@ -291,7 +291,7 @@ func GenerateBlockChain3(config *params.ChainConfig, parent *types.Block, engine // Finalize and seal the block block, _ := b.engine.Finalize(chainreader, b.header, statedb, b.txs, b.receipts) - _, err := chain.WriteBlockWithState(block, b.receipts, nil, statedb, false, nil) + _, err := chain.WriteBlockWithState(block, b.receipts, nil, statedb, false) if err != nil { panic(err) } @@ -346,7 +346,7 @@ func GenerateBlockChain(config *params.ChainConfig, parent *types.Block, engine // Finalize and seal the block block, _ := b.engine.Finalize(chainreader, b.header, statedb, b.txs, b.receipts) - _, err := blockchain.WriteBlockWithState(block, b.receipts, nil, statedb, false, nil) + _, err := blockchain.WriteBlockWithState(block, b.receipts, nil, statedb, false) if err != nil { panic(err) } diff --git a/miner/worker.go b/miner/worker.go index 2f2fe6d4d9..d653d8e2ee 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -722,7 +722,7 @@ func (w *worker) resultLoop() { log.Debug("Write extra data", "txs", len(block.Transactions()), "extra", len(block.ExtraData())) // update 3-chain state cbftResult.ChainStateUpdateCB() - _, err := w.chain.WriteBlockWithState(block, receipts, logs, _state, true, cbftResult.ChainStateUpdateCB) + _, err := w.chain.WriteBlockWithState(block, receipts, logs, _state, true) if err != nil { if cbftResult.SyncState != nil { cbftResult.SyncState <- err diff --git a/miner/worker_test.go b/miner/worker_test.go index 95c32d615d..7850a9eded 100644 --- a/miner/worker_test.go +++ b/miner/worker_test.go @@ -190,7 +190,7 @@ func newTestWorker(t *testing.T, chainConfig *params.ChainConfig, miningConfig * } // block write to real chain - _, err = w.chain.WriteBlockWithState(cbftResult.Block, nil, nil, stateDB, false, nil) + _, err = w.chain.WriteBlockWithState(cbftResult.Block, nil, nil, stateDB, false) if nil != err { panic(err) } From 41409cdbc693511c3a79798296be319a2e02b505 Mon Sep 17 00:00:00 2001 From: benbaley Date: Fri, 22 Sep 2023 15:11:02 +0800 Subject: [PATCH 18/42] update version to 1.4.2 --- core/parallel_context.go | 2 +- core/parallel_state_processor.go | 2 +- params/version.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/parallel_context.go b/core/parallel_context.go index d699021166..5183956017 100644 --- a/core/parallel_context.go +++ b/core/parallel_context.go @@ -175,7 +175,7 @@ func (ctx *ParallelContext) buildTransferFailedResult(idx int, err error, needRe tx := ctx.GetTx(idx) log.Debug("Execute trasnfer failed", "blockNumber", ctx.header.Number.Uint64(), "txIdx", idx, "txHash", ctx.GetTx(idx).Hash().TerminalString(), "gasPool", ctx.gp.Gas(), "txGasLimit", tx.Gas(), "txFrom", tx.FromAddr(ctx.signer).String(), "txTo", tx.To().String(), - "txValue", tx.Value().Uint64(), "needRefundGasPool", needRefundGasPool, "error", err.Error()) + "txValue", tx.Value(), "needRefundGasPool", needRefundGasPool, "error", err.Error()) } func (ctx *ParallelContext) buildTransferSuccessResult(idx int, fromStateObject, toStateObject *state.ParallelStateObject, txGasUsed uint64, minerEarnings *big.Int) { diff --git a/core/parallel_state_processor.go b/core/parallel_state_processor.go index ad8b2a8bb5..9a7c438f71 100644 --- a/core/parallel_state_processor.go +++ b/core/parallel_state_processor.go @@ -65,7 +65,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat txHaveCal = txHaveCal + txs tasks-- case <-timeout.C: - log.Warn("Parallel cal tx from time out", "num", block.Number(), "left_task", tasks, "total_task", cap(block.CalTxFromCH), "txcal", txHaveCal) + log.Warn("Parallel cal tx from timeout", "num", block.Number(), "left_task", tasks, "total_task", cap(block.CalTxFromCH), "txcal", txHaveCal) tasks = 0 } } diff --git a/params/version.go b/params/version.go index 8a5742a428..8c58e428de 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ const ( //These versions are meaning the current code version. VersionMajor = 1 // Major version component of the current release VersionMinor = 4 // Minor version component of the current release - VersionPatch = 1 // Patch version component of the current release + VersionPatch = 2 // Patch version component of the current release VersionMeta = "unstable" // Version metadata to append to the version string //CAUTION: DO NOT MODIFY THIS ONCE THE CHAIN HAS BEEN INITIALIZED!!! From 4fdeeabdf5b7f26823d69d8f2f1c748eeb13cd1a Mon Sep 17 00:00:00 2001 From: niuxiaojie81 <85773309@qq.com> Date: Fri, 22 Sep 2023 17:27:50 +0800 Subject: [PATCH 19/42] fix preCheck --- core/parallel_context.go | 4 ++-- core/parallel_executor.go | 4 ++-- core/parallel_state_processor.go | 2 +- miner/worker.go | 1 - 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/core/parallel_context.go b/core/parallel_context.go index d699021166..80065a3f84 100644 --- a/core/parallel_context.go +++ b/core/parallel_context.go @@ -175,7 +175,7 @@ func (ctx *ParallelContext) buildTransferFailedResult(idx int, err error, needRe tx := ctx.GetTx(idx) log.Debug("Execute trasnfer failed", "blockNumber", ctx.header.Number.Uint64(), "txIdx", idx, "txHash", ctx.GetTx(idx).Hash().TerminalString(), "gasPool", ctx.gp.Gas(), "txGasLimit", tx.Gas(), "txFrom", tx.FromAddr(ctx.signer).String(), "txTo", tx.To().String(), - "txValue", tx.Value().Uint64(), "needRefundGasPool", needRefundGasPool, "error", err.Error()) + "txValue", tx.Value(), "needRefundGasPool", needRefundGasPool, "error", err.Error()) } func (ctx *ParallelContext) buildTransferSuccessResult(idx int, fromStateObject, toStateObject *state.ParallelStateObject, txGasUsed uint64, minerEarnings *big.Int) { @@ -201,7 +201,7 @@ func (ctx *ParallelContext) buildTransferSuccessResult(idx int, fromStateObject, ctx.SetResult(idx, result) log.Trace("Execute trasnfer success", "blockNumber", ctx.header.Number.Uint64(), "txIdx", idx, "txHash", tx.Hash().TerminalString(), "gasPool", ctx.gp.Gas(), "txGasLimit", tx.Gas(), "txUsedGas", txGasUsed, "txFrom", tx.FromAddr(ctx.signer).String(), "txTo", tx.To().String(), - "txValue", tx.Value().Uint64(), "minerEarnings", minerEarnings.Uint64()) + "txValue", tx.Value(), "minerEarnings", minerEarnings.Uint64()) } func (ctx *ParallelContext) batchMerge(originIdxList []int) { diff --git a/core/parallel_executor.go b/core/parallel_executor.go index 640634098f..4ac8c3bc2e 100644 --- a/core/parallel_executor.go +++ b/core/parallel_executor.go @@ -158,7 +158,7 @@ func (exe *Executor) preCheck(msg types.Message, fromObj *state.ParallelStateObj // check balance mgval := new(big.Int).Mul(new(big.Int).SetUint64(msg.Gas()), msg.GasPrice()) balanceCheck := mgval - if msg.GasFeeCap() != nil { + if gte150 { balanceCheck = new(big.Int).SetUint64(msg.Gas()) balanceCheck = balanceCheck.Mul(balanceCheck, msg.GasFeeCap()) balanceCheck.Add(balanceCheck, msg.Value()) @@ -223,7 +223,7 @@ func (exe *Executor) executeParallelTx(ctx *ParallelContext, idx int, intrinsicG minerEarnings := new(big.Int).Mul(new(big.Int).SetUint64(intrinsicGas), effectiveTip) // sender fee fee := new(big.Int).Mul(new(big.Int).SetUint64(intrinsicGas), msg.GasPrice()) - log.Trace("Execute parallel tx", "baseFee", ctx.header.BaseFee, "gasTipCap", msg.GasTipCap(), "gasFeeCap", msg.GasFeeCap(), "gasPrice", msg.GasPrice(), "effectiveTip", effectiveTip) + log.Trace("Execute parallel tx", "baseFee", ctx.header.BaseFee, "gasTipCap", msg.GasTipCap(), "gasFeeCap", msg.GasFeeCap(), "gasPrice", msg.GasPrice(), "effectiveTip", effectiveTip, "intrinsicGas", intrinsicGas) cost := new(big.Int).Add(msg.Value(), fee) if fromObj.GetBalance().Cmp(cost) < 0 { ctx.buildTransferFailedResult(idx, errInsufficientBalanceForGas, true) diff --git a/core/parallel_state_processor.go b/core/parallel_state_processor.go index ad8b2a8bb5..9a7c438f71 100644 --- a/core/parallel_state_processor.go +++ b/core/parallel_state_processor.go @@ -65,7 +65,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat txHaveCal = txHaveCal + txs tasks-- case <-timeout.C: - log.Warn("Parallel cal tx from time out", "num", block.Number(), "left_task", tasks, "total_task", cap(block.CalTxFromCH), "txcal", txHaveCal) + log.Warn("Parallel cal tx from timeout", "num", block.Number(), "left_task", tasks, "total_task", cap(block.CalTxFromCH), "txcal", txHaveCal) tasks = 0 } } diff --git a/miner/worker.go b/miner/worker.go index e9e519f5ca..e9107ed46a 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -758,7 +758,6 @@ func (w *worker) resultLoop() { log.Debug("Pending task", "exist", exist) var _receipts []*types.Receipt var _state *state.StateDB - //todo remove extra magic number if exist && w.engine.(consensus.Bft).IsSignedBySelf(sealhash, block.Header()) { _receipts = task.receipts _state = task.state From 46d761c643247b98c5a2f867c6eecea981e8642f Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Fri, 22 Sep 2023 17:47:46 +0800 Subject: [PATCH 20/42] fix init addconsensus and removeconsensus --- p2p/server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/p2p/server.go b/p2p/server.go index 8b0b40eb2b..0b400ba587 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -511,6 +511,8 @@ func (srv *Server) Start() (err error) { srv.removetrusted = make(chan *enode.Node) srv.peerOp = make(chan peerOpFunc) srv.peerOpDone = make(chan struct{}) + srv.addconsensus = make(chan *enode.Node) + srv.removeconsensus = make(chan *enode.Node) if err := srv.setupLocalNode(); err != nil { return err From a1372686e5658594e395e4c1409c16745db0086d Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Fri, 22 Sep 2023 17:57:46 +0800 Subject: [PATCH 21/42] fix init addconsensus and removeconsensus --- p2p/server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/p2p/server.go b/p2p/server.go index ac9a3bb160..594d5717ce 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -511,6 +511,8 @@ func (srv *Server) Start() (err error) { srv.removetrusted = make(chan *enode.Node) srv.peerOp = make(chan peerOpFunc) srv.peerOpDone = make(chan struct{}) + srv.addconsensus = make(chan *enode.Node) + srv.removeconsensus = make(chan *enode.Node) if err := srv.setupLocalNode(); err != nil { return err From 16e2e00c834cf5265e3bef8485d1128e67093b22 Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Tue, 26 Sep 2023 15:11:17 +0800 Subject: [PATCH 22/42] update p2p --- p2p/server.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/p2p/server.go b/p2p/server.go index 594d5717ce..955893cce4 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -847,7 +847,7 @@ running: } if consensusNodes[c.node.ID()] { - c.flags |= consensusDialedConn + c.set(consensusDialedConn, true) } // TODO: track in-progress inbound node IDs (pre-Peer) to avoid dialing them. @@ -906,7 +906,8 @@ running: func (srv *Server) postHandshakeChecks(peers map[enode.ID]*Peer, inboundCount int, c *conn) error { // Disconnect over limit non-consensus node. - if srv.consensus && len(peers) >= srv.MaxPeers && c.is(consensusDialedConn) && srv.numConsensusPeer(peers) < srv.MaxConsensusPeers { + numConsensusPeer := srv.numConsensusPeer(peers) + if srv.consensus && len(peers) >= srv.MaxPeers && c.is(consensusDialedConn) && numConsensusPeer < srv.MaxConsensusPeers { for _, p := range peers { if p.rw.is(inboundConn|dynDialedConn) && !p.rw.is(trustedConn|staticDialedConn|consensusDialedConn) { srv.log.Debug("Disconnect over limit connection", "peer", p.ID(), "flags", p.rw.flags, "peers", len(peers)) @@ -917,7 +918,7 @@ func (srv *Server) postHandshakeChecks(peers map[enode.ID]*Peer, inboundCount in } switch { - case c.is(consensusDialedConn) && srv.numConsensusPeer(peers) >= srv.MaxConsensusPeers: + case c.is(consensusDialedConn) && numConsensusPeer >= srv.MaxConsensusPeers: return DiscTooManyConsensusPeers case !srv.consensus && c.is(consensusDialedConn) && len(peers) >= srv.MaxPeers: return DiscTooManyPeers From be0f7f30f043481f349948cab8c23d3bd2f82237 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 11:11:32 +0000 Subject: [PATCH 23/42] Bump github.com/btcsuite/btcd Bumps [github.com/btcsuite/btcd](https://github.com/btcsuite/btcd) from 0.22.0-beta.0.20220111032746-97732e52810c to 0.23.2. - [Release notes](https://github.com/btcsuite/btcd/releases) - [Changelog](https://github.com/btcsuite/btcd/blob/master/CHANGES) - [Commits](https://github.com/btcsuite/btcd/commits/v0.23.2) --- updated-dependencies: - dependency-name: github.com/btcsuite/btcd dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- go.mod | 7 +++++-- go.sum | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index c351a13bce..a50f946090 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/AlayaNetwork/graphql-go v1.2.1-0.20211227063951-8d66eefcb4e3 github.com/PlatONnetwork/wagon v0.6.1-0.20201026015350-67507c2a7b96 github.com/VictoriaMetrics/fastcache v1.5.7 - github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c github.com/btcsuite/btcd/btcutil v1.1.0 github.com/cespare/cp v0.1.0 github.com/davecgh/go-spew v1.1.1 @@ -64,6 +63,11 @@ require ( gotest.tools/v3 v3.4.0 // indirect ) +require ( + github.com/herumi/bls v1.37.0 + golang.org/x/net v0.9.0 +) + require ( github.com/AlayaNetwork/Alaya-Go v0.16.2 // indirect github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect @@ -86,7 +90,6 @@ require ( github.com/tklauser/numcpus v0.6.0 // indirect github.com/twitchyliquid64/golang-asm v0.0.0-20190126203739-365674df15fc // indirect golang.org/x/mod v0.10.0 // indirect - golang.org/x/net v0.9.0 // indirect google.golang.org/protobuf v1.27.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 8c77ee000e..47f94ff43e 100644 --- a/go.sum +++ b/go.sum @@ -119,6 +119,8 @@ github.com/graph-gophers/graphql-go v1.3.0/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLt github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d h1:dg1dEPuWpEqDnvIw251EVy4zlP8gWbsGj4BsUKCRpYs= github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/herumi/bls v1.37.0 h1:EKPaFujxWsxSMlfN1NeR9GTfVOeAsAaNRGbdBfn9lBE= +github.com/herumi/bls v1.37.0/go.mod h1:CnmR5QZ/QBnBE8Z55O+OtmUc6ICUdrOW9fwSRQwz5Bo= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.1.1 h1:4JywC80b+/hSfljFlEBLHrrh+CIONLDz9NuFl0af4Mw= From 432f59f1b8480174aefc655e045b5f21a079d3e3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:16:16 +0000 Subject: [PATCH 24/42] Bump github.com/influxdata/influxdb Bumps [github.com/influxdata/influxdb](https://github.com/influxdata/influxdb) from 1.2.3-0.20180221223340-01288bdb0883 to 1.7.6. - [Release notes](https://github.com/influxdata/influxdb/releases) - [Changelog](https://github.com/influxdata/influxdb/blob/v1.7.6/CHANGELOG.md) - [Commits](https://github.com/influxdata/influxdb/commits/v1.7.6) --- updated-dependencies: - dependency-name: github.com/influxdata/influxdb dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- go.mod | 8 ++++++-- go.sum | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c351a13bce..b5e8740f59 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/holiman/bloomfilter/v2 v2.0.3 github.com/holiman/uint256 v1.1.1 github.com/huin/goupnp v1.0.1-0.20210310174557-0ca763054c88 - github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883 + github.com/influxdata/influxdb v1.7.6 github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458 github.com/jedisct1/go-minisign v0.0.0-20211028175153-1c139d1cc84b github.com/julienschmidt/httprouter v1.3.0 @@ -64,6 +64,11 @@ require ( gotest.tools/v3 v3.4.0 // indirect ) +require ( + github.com/herumi/bls v1.37.0 + golang.org/x/net v0.9.0 +) + require ( github.com/AlayaNetwork/Alaya-Go v0.16.2 // indirect github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect @@ -86,7 +91,6 @@ require ( github.com/tklauser/numcpus v0.6.0 // indirect github.com/twitchyliquid64/golang-asm v0.0.0-20190126203739-365674df15fc // indirect golang.org/x/mod v0.10.0 // indirect - golang.org/x/net v0.9.0 // indirect google.golang.org/protobuf v1.27.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 8c77ee000e..5f5b4445a6 100644 --- a/go.sum +++ b/go.sum @@ -119,6 +119,8 @@ github.com/graph-gophers/graphql-go v1.3.0/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLt github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d h1:dg1dEPuWpEqDnvIw251EVy4zlP8gWbsGj4BsUKCRpYs= github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/herumi/bls v1.37.0 h1:EKPaFujxWsxSMlfN1NeR9GTfVOeAsAaNRGbdBfn9lBE= +github.com/herumi/bls v1.37.0/go.mod h1:CnmR5QZ/QBnBE8Z55O+OtmUc6ICUdrOW9fwSRQwz5Bo= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.1.1 h1:4JywC80b+/hSfljFlEBLHrrh+CIONLDz9NuFl0af4Mw= @@ -128,8 +130,9 @@ github.com/huin/goupnp v0.0.0-20161224104101-679507af18f3/go.mod h1:MZ2ZmwcBpvOo github.com/huin/goupnp v1.0.1-0.20210310174557-0ca763054c88 h1:bcAj8KroPf552TScjFPIakjH2/tdIrIH8F+cc4v4SRo= github.com/huin/goupnp v1.0.1-0.20210310174557-0ca763054c88/go.mod h1:nNs7wvRfN1eKaMknBydLNQU6146XQim8t4h+q90biWo= github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= -github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883 h1:FSeK4fZCo8u40n2JMnyAsd6x7+SbvoOMHvQOU/n10P4= github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY= +github.com/influxdata/influxdb v1.7.6 h1:8mQ7A/V+3noMGCt/P9pD09ISaiz9XvgCk303UYA3gcs= +github.com/influxdata/influxdb v1.7.6/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY= github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458 h1:6OvNmYgJyexcZ3pYbTI9jWx5tHo1Dee/tWbLMfPe2TA= github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jedisct1/go-minisign v0.0.0-20211028175153-1c139d1cc84b h1:ZGiXF8sz7PDk6RgkP+A/SFfUD0ZR/AgG6SpRNEDKZy8= From c8e01f5d68444fac8c81fd049e33b1abb56b0195 Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Sun, 8 Oct 2023 16:33:48 +0800 Subject: [PATCH 25/42] update for bls Verify Contract --- common/vm/inner_contract.go | 1 + core/blockchain_reactor.go | 2 +- core/tx_pool.go | 2 +- core/vm/contracts.go | 75 +++++++++++++++++++++++++++++++++++-- core/vm/evm.go | 21 ++++++++--- params/protocol_params.go | 2 + 6 files changed, 91 insertions(+), 12 deletions(-) diff --git a/common/vm/inner_contract.go b/common/vm/inner_contract.go index baa5b609ee..f5f4787805 100644 --- a/common/vm/inner_contract.go +++ b/common/vm/inner_contract.go @@ -28,6 +28,7 @@ var ( DelegateRewardPoolAddr = common.HexToAddress("0x1000000000000000000000000000000000000006") // The PlatON Precompiled contract addr for delegate reward ValidatorInnerContractAddr = common.HexToAddress("0x2000000000000000000000000000000000000000") // The PlatON Precompiled contract addr for cbft inner VrfInnerContractAddr = common.HexToAddress("0x3000000000000000000000000000000000000001") // The PlatON Precompiled contract addr for vrf inner + BlsVerifyContractAddr = common.HexToAddress("0x3000000000000000000000000000000000000002") // The PlatON Precompiled contract addr for bls verify ) type PrecompiledContractCheck interface { diff --git a/core/blockchain_reactor.go b/core/blockchain_reactor.go index 4ea114ae28..88192b66ae 100644 --- a/core/blockchain_reactor.go +++ b/core/blockchain_reactor.go @@ -365,7 +365,7 @@ func (bcr *BlockChainReactor) EndBlocker(header *types.Header, state xcom.StateD func (bcr *BlockChainReactor) VerifyTx(tx *types.Transaction, to common.Address, rules params.Rules) error { - if !vm.IsPlatONPrecompiledContract(to, rules) { + if !vm.IsPlatONPrecompiledContract(to, rules, false) { return nil } diff --git a/core/tx_pool.go b/core/tx_pool.go index 646dba23d5..527ad33cee 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -800,7 +800,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { // Verify inner contract tx if nil != tx.To() { - if err := bcr.VerifyTx(tx, *(tx.To()), pool.chainconfig.Rules(pool.chainconfig.NewtonBlock)); nil != err { + if err := bcr.VerifyTx(tx, *(tx.To()), pool.chainconfig.Rules(pool.resetHead.Number())); nil != err { log.Error("Failed to verify tx", "txHash", tx.Hash().Hex(), "to", tx.To().Hex(), "err", err) return fmt.Errorf("%s: %s", ErrPlatONTxDataInvalid.Error(), err.Error()) } diff --git a/core/vm/contracts.go b/core/vm/contracts.go index ca14d38a1c..62dfe44433 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -21,6 +21,7 @@ import ( "encoding/binary" "errors" "fmt" + "github.com/PlatONnetwork/PlatON-Go/crypto/bls" "math/big" "github.com/PlatONnetwork/PlatON-Go/crypto/bls12381" @@ -179,7 +180,7 @@ var PlatONPrecompiledContracts = map[common.Address]PrecompiledContract{ vm.DelegateRewardPoolAddr: &DelegateRewardContract{}, } -var PlatONPrecompiledContracts120 = map[common.Address]PrecompiledContract{ +var PlatONPrecompiledContractsNewton = map[common.Address]PrecompiledContract{ vm.ValidatorInnerContractAddr: &validatorInnerContract{}, // add by economic model vm.StakingContractAddr: &StakingContract{}, @@ -191,6 +192,19 @@ var PlatONPrecompiledContracts120 = map[common.Address]PrecompiledContract{ vm.VrfInnerContractAddr: &vrf{}, } +var PlatONPrecompiledContractsPauli = map[common.Address]PrecompiledContract{ + vm.ValidatorInnerContractAddr: &validatorInnerContract{}, + // add by economic model + vm.StakingContractAddr: &StakingContract{}, + vm.RestrictingContractAddr: &RestrictingContract{}, + vm.SlashingContractAddr: &SlashingContract{}, + vm.GovContractAddr: &GovContract{}, + vm.RewardManagerPoolAddr: &rewardEmpty{}, + vm.DelegateRewardPoolAddr: &DelegateRewardContract{}, + vm.VrfInnerContractAddr: &vrf{}, + vm.BlsVerifyContractAddr: &blsSignVerify{}, +} + // ActivePrecompiles returns the precompiles enabled with the current configuration. func ActivePrecompiles(state xcom.StateDB) []common.Address { if gov.Gte150VersionState(state) { @@ -244,9 +258,14 @@ func IsEVMPrecompiledContract(addr common.Address, rules params.Rules, gte150Ver return false } -func IsPlatONPrecompiledContract(addr common.Address, rules params.Rules) bool { +func IsPlatONPrecompiledContract(addr common.Address, rules params.Rules, gte150Version bool) bool { + if rules.IsPauli || gte150Version { + if _, ok := PlatONPrecompiledContractsPauli[addr]; ok { + return true + } + } if rules.IsNewton { - if _, ok := PlatONPrecompiledContracts120[addr]; ok { + if _, ok := PlatONPrecompiledContractsNewton[addr]; ok { return true } } else { @@ -261,7 +280,7 @@ func IsPrecompiledContract(addr common.Address, rules params.Rules, gte150Versio if IsEVMPrecompiledContract(addr, rules, gte150Version) { return true } else { - return IsPlatONPrecompiledContract(addr, rules) + return IsPlatONPrecompiledContract(addr, rules, gte150Version) } } @@ -1181,3 +1200,51 @@ func (v vrf) Run(input []byte) ([]byte, error) { } return randomNumbers, nil } + +var ( + errBlsSignVerifyInvalidInputLength = errors.New("invalid input length") + errBlsSignVerifyFailed = errors.New("bls sign verify failed") +) + +type blsSignVerify struct { + Evm *EVM +} + +func (b blsSignVerify) RequiredGas(input []byte) uint64 { + return params.BlsVerifyGas +} + +// input由 签名+消息+n个bls公钥组成 +// 签名长度 64 +// 消息长度 32 +// bls公钥长度 96*n + +func (b blsSignVerify) Run(input []byte) ([]byte, error) { + if len(input) == 0 || len(input) == 96 || len(input)%96 != 0 { + return nil, errBlsSignVerifyInvalidInputLength + } + + var ( + sig bls.Sign + msg []byte + pubKey = new(bls.PublicKey) + ) + if err := sig.Deserialize(getData(input, 0, 64)); err != nil { + return nil, err + } + + for i := 1; i < len(input)/96; i++ { + pub := new(bls.PublicKey) + if err := pub.Deserialize(getData(input, uint64(96*i), 96)); err != nil { + return nil, err + } + pubKey.Add(pub) + } + + msg = getData(input, 64, 32) + + if !sig.Verify(pubKey, string(msg)) { + return nil, errBlsSignVerifyFailed + } + return nil, nil +} diff --git a/core/vm/evm.go b/core/vm/evm.go index 028cd64815..fe6dfd52e4 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -67,12 +67,20 @@ func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, err if p := precompiles[*contract.CodeAddr]; p != nil { return RunPrecompiledContract(p, input, contract) } - if p := PlatONPrecompiledContracts120[*contract.CodeAddr]; p != nil { + + platONPrecompiledContracts := PlatONPrecompiledContracts + if gov.Gte150VersionState(evm.StateDB) { + platONPrecompiledContracts = PlatONPrecompiledContractsPauli + } else if evm.chainRules.IsNewton { + platONPrecompiledContracts = PlatONPrecompiledContractsNewton + } + + if p := platONPrecompiledContracts[*contract.CodeAddr]; p != nil { switch p.(type) { case *vrf: - if evm.chainRules.IsNewton { - return RunPrecompiledContract(&vrf{Evm: evm}, input, contract) - } + return RunPrecompiledContract(&vrf{Evm: evm}, input, contract) + case *blsSignVerify: + return RunPrecompiledContract(&blsSignVerify{Evm: evm}, input, contract) case *validatorInnerContract: vic := &validatorInnerContract{ Contract: contract, @@ -298,12 +306,13 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas ) if !evm.StateDB.Exist(addr) { precompiles := PrecompiledContractsByzantium - if gov.Gte150VersionState(evm.StateDB) { + gte150 := gov.Gte150VersionState(evm.StateDB) + if gte150 { precompiles = PrecompiledContractsBerlin2 } else if evm.chainRules.IsHubble { precompiles = PrecompiledContractsBerlin } - if precompiles[addr] == nil && !IsPlatONPrecompiledContract(addr, evm.chainConfig.Rules(evm.Context.BlockNumber)) && value.Sign() == 0 { + if precompiles[addr] == nil && !IsPlatONPrecompiledContract(addr, evm.chainConfig.Rules(evm.Context.BlockNumber), gte150) && value.Sign() == 0 { // Calling a non existing account, don't do anything, but ping the tracer if evm.Config.Debug { if evm.depth == 0 { diff --git a/params/protocol_params.go b/params/protocol_params.go index f8eb1e9b04..287789041d 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -157,6 +157,8 @@ const ( Bls12381MapG1Gas uint64 = 5500 // Gas price for BLS12-381 mapping field element to G1 operation Bls12381MapG2Gas uint64 = 110000 // Gas price for BLS12-381 mapping field element to G2 operation + BlsVerifyGas uint64 = 21000 // Gas price for BLS12-381 mapping field element to G2 operation + // The Refund Quotient is the cap on how much of the used gas can be refunded. Before EIP-3529, // up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529 RefundQuotient uint64 = 2 From 87ef1a9c0d3052d5c28bc6583c148dc1c5e28b34 Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Mon, 9 Oct 2023 11:25:17 +0800 Subject: [PATCH 26/42] fix test --- eth/handler_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/eth/handler_test.go b/eth/handler_test.go index 4f2eeecc0c..857853bcc0 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -182,7 +182,15 @@ func newTestHandlerWithBlocks2(blocks int) *testHandler { Alloc: core.GenesisAlloc{testAddr: {Balance: big.NewInt(1000000)}}, }) parent := genesis.MustCommit(db) - chain := core.GenerateBlockChain2(params.TestChainConfig, parent, consensus.NewFakerWithDataBase(db), db, blocks, nil) + + errCh := make(chan error, 1) + + engine := consensus.NewFakerWithDataBase(db) + + errCh <- engine.InsertChain(parent) + <-errCh + + chain := core.GenerateBlockChain2(params.TestChainConfig, parent, engine, db, blocks, nil) txpool := newTestTxPool() handler, _ := newHandler(&handlerConfig{ From 0eec1a369fa6f3aea04b61653cd35d7c84463b74 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Oct 2023 23:43:38 +0000 Subject: [PATCH 27/42] Bump golang.org/x/net from 0.9.0 to 0.17.0 Bumps [golang.org/x/net](https://github.com/golang/net) from 0.9.0 to 0.17.0. - [Commits](https://github.com/golang/net/compare/v0.9.0...v0.17.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- go.mod | 9 +++++---- go.sum | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index f80fbcda86..bfbb8a6618 100644 --- a/go.mod +++ b/go.mod @@ -49,10 +49,10 @@ require ( github.com/stretchr/testify v1.7.0 github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tealeg/xlsx v1.0.5 - golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 + golang.org/x/crypto v0.14.0 golang.org/x/sync v0.1.0 - golang.org/x/sys v0.7.0 - golang.org/x/text v0.9.0 + golang.org/x/sys v0.13.0 + golang.org/x/text v0.13.0 golang.org/x/time v0.3.0 golang.org/x/tools v0.8.0 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 @@ -64,8 +64,9 @@ require ( ) require ( + github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c github.com/herumi/bls v1.37.0 - golang.org/x/net v0.9.0 + golang.org/x/net v0.17.0 ) require ( diff --git a/go.sum b/go.sum index 5f5b4445a6..b99e0b9e1f 100644 --- a/go.sum +++ b/go.sum @@ -269,8 +269,9 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= @@ -289,8 +290,10 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -325,20 +328,25 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20171227012246-e19ae1496984/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From ad488729f62fc163efc5592c274003bb1ff5ae71 Mon Sep 17 00:00:00 2001 From: niuxiaojie81 <85773309@qq.com> Date: Thu, 12 Oct 2023 11:25:39 +0800 Subject: [PATCH 28/42] Remove legacy unnecessary code --- consensus/bft_mock.go | 58 +++--------------------------------------- core/cbfttypes/type.go | 41 ----------------------------- core/events.go | 10 -------- 3 files changed, 3 insertions(+), 106 deletions(-) diff --git a/consensus/bft_mock.go b/consensus/bft_mock.go index 8452230855..cd682095a9 100644 --- a/consensus/bft_mock.go +++ b/consensus/bft_mock.go @@ -292,48 +292,11 @@ func (bm *BftMock) ShouldSeal(curTime time.Time) (bool, error) { return true, nil } -// OnBlockSignature received a new block signature -// Need to verify if the signature is signed by nodeID -func (bm *BftMock) OnBlockSignature(chain ChainReader, nodeID enode.IDv0, sig *cbfttypes.BlockSignature) error { - return nil -} - -// OnNewBlock processes the BFT signatures -func (bm *BftMock) OnNewBlock(chain ChainReader, block *types.Block) error { - return nil -} - -// OnPong processes the BFT signatures -func (bm *BftMock) OnPong(nodeID enode.IDv0, netLatency int64) error { - return nil - -} - -// OnBlockSynced sends a signal if a block synced from other peer. -func (bm *BftMock) OnBlockSynced() { - -} - -// CheckConsensusNode is a fake interface, no need to implement. -func (bm *BftMock) CheckConsensusNode(nodeID enode.IDv0) (bool, error) { - return true, nil -} - // IsConsensusNode is a fake interface, no need to implement. func (bm *BftMock) IsConsensusNode() bool { return true } -// HighestLogicalBlock is a fake interface, no need to implement. -func (bm *BftMock) HighestLogicalBlock() *types.Block { - return nil -} - -// HighestConfirmedBlock is a fake interface, no need to implement. -func (bm *BftMock) HighestConfirmedBlock() *types.Block { - return nil -} - // GetBlock is a fake interface, no need to implement. func (bm *BftMock) GetBlock(hash common.Hash, number uint64) *types.Block { return nil @@ -364,32 +327,17 @@ func (bm *BftMock) GetBlockByHashAndNum(hash common.Hash, number uint64) *types. return nil } -// Status is a fake interface, no need to implement. -func (bm *BftMock) Status() string { - return "" -} - // CurrentBlock is a fake interface, no need to implement. func (bm *BftMock) CurrentBlock() *types.Block { - //if len(bm.Blocks) == 0 { - // h := types.Header{Number: big.NewInt(0)} - // return types.NewBlockWithHeader(&h) - //} - //return bm.Blocks[len(bm.Blocks)-1] return bm.Current } // TracingSwitch is a fake interface, no need to implement. -func (bm *BftMock) TracingSwitch(flag int8) { - -} +func (bm *BftMock) TracingSwitch(flag int8) {} -func (bm *BftMock) Pause() { +func (bm *BftMock) Pause() {} -} -func (bm *BftMock) Resume() { - -} +func (bm *BftMock) Resume() {} func (bm *BftMock) Syncing() bool { return false diff --git a/core/cbfttypes/type.go b/core/cbfttypes/type.go index 0db6477a9e..5fd07c1557 100644 --- a/core/cbfttypes/type.go +++ b/core/cbfttypes/type.go @@ -23,7 +23,6 @@ import ( "errors" "fmt" "math" - "math/big" "sort" "github.com/PlatONnetwork/PlatON-Go/common/hexutil" @@ -38,24 +37,6 @@ import ( "github.com/PlatONnetwork/PlatON-Go/crypto/bls" ) -// Block's Signature info -type BlockSignature struct { - SignHash common.Hash // Signature hash,header[0:32] - Hash common.Hash // Block hash,header[:] - Number *big.Int - Signature *common.BlockConfirmSign -} - -func (bs *BlockSignature) Copy() *BlockSignature { - sign := *bs.Signature - return &BlockSignature{ - SignHash: bs.SignHash, - Hash: bs.Hash, - Number: new(big.Int).Set(bs.Number), - Signature: &sign, - } -} - type UpdateChainStateFn func(qcState, lockState, commitState *protocols.State) type CbftResult struct { @@ -65,28 +46,6 @@ type CbftResult struct { ChainStateUpdateCB func() } -type ProducerState struct { - count int - miner common.Address -} - -func (ps *ProducerState) Add(miner common.Address) { - if ps.miner == miner { - ps.count++ - } else { - ps.miner = miner - ps.count = 1 - } -} - -func (ps *ProducerState) Get() (common.Address, int) { - return ps.miner, ps.count -} - -func (ps *ProducerState) Validate(period int) bool { - return ps.count < period -} - type AddValidatorEvent struct { Node *enode.Node } diff --git a/core/events.go b/core/events.go index 434675db8e..3f5738ead8 100644 --- a/core/events.go +++ b/core/events.go @@ -18,7 +18,6 @@ package core import ( "github.com/PlatONnetwork/PlatON-Go/common" - "github.com/PlatONnetwork/PlatON-Go/core/cbfttypes" "github.com/PlatONnetwork/PlatON-Go/core/types" ) @@ -28,15 +27,6 @@ type NewTxsEvent struct{ Txs []*types.Transaction } // NewMinedBlockEvent is posted when a block has been imported. type NewMinedBlockEvent struct{ Block *types.Block } -type PrepareMinedBlockEvent struct { - Block *types.Block - // ConsensusNodes []discover.NodeID -} -type BlockSignatureEvent struct { - BlockSignature *cbfttypes.BlockSignature - // ConsensusNodes []discover.NodeID -} - // RemovedLogsEvent is posted when a reorg happens type RemovedLogsEvent struct{ Logs []*types.Log } From e59a46634c925dde470c51a52eea7f84a639e3de Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Thu, 12 Oct 2023 17:27:10 +0800 Subject: [PATCH 29/42] fix test --- core/snapshotdb/db_test.go | 2 +- core/snapshotdb/snapshotdb_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/snapshotdb/db_test.go b/core/snapshotdb/db_test.go index 4f8ffd1aec..1f5cc572cf 100644 --- a/core/snapshotdb/db_test.go +++ b/core/snapshotdb/db_test.go @@ -107,7 +107,7 @@ func TestRecover(t *testing.T) { return } for _, value := range baseDBArr { - v, err := ch.db.baseDB.Get(value.key, nil) + v, err := ch.db.Get(ch.db.current.highest.Hash, value.key) if err != nil { t.Error("should be nil", err) return diff --git a/core/snapshotdb/snapshotdb_test.go b/core/snapshotdb/snapshotdb_test.go index 3f5965af57..f2cd9cbde8 100644 --- a/core/snapshotdb/snapshotdb_test.go +++ b/core/snapshotdb/snapshotdb_test.go @@ -593,11 +593,11 @@ func TestSnapshotDB_Ranking4(t *testing.T) { itr.Release() return o } - v := f(common.ZeroHash, "aaa", 1000) + v := f(ch.db.current.highest.Hash, "aaa", 1000) if err := v.compareWithkvs(generatekvs); err != nil { t.Error(err) } - v2 := f(common.ZeroHash, "aaa", 0) + v2 := f(ch.db.current.highest.Hash, "aaa", 0) if err := v2.compareWithkvs(generatekvs); err != nil { t.Error(err) } @@ -755,8 +755,8 @@ func TestSnapshotDB_WalkBaseDB(t *testing.T) { t.Run("kv should compare", func(t *testing.T) { var kvGetFromWalk kvs f := func(num *big.Int, iter iterator.Iterator) error { - if num.Int64() != 2 { - return fmt.Errorf("basenum is wrong:%v,should be 2", num) + if num.Int64() != 1 { + return fmt.Errorf("basenum is wrong:%v,should be 1", num) } for iter.Next() { k, v := make([]byte, len(iter.Key())), make([]byte, len(iter.Value())) @@ -858,7 +858,7 @@ func TestSnapshotDB_Compaction_del(t *testing.T) { } delkey := baseDBkv[0].key delVal := baseDBkv[0].value - v, err := ch.db.GetBaseDB(delkey) + v, err := ch.db.Get(ch.db.current.highest.Hash, delkey) if err != nil { t.Error(err) return @@ -872,7 +872,7 @@ func TestSnapshotDB_Compaction_del(t *testing.T) { t.Error(err) } - _, err = ch.db.GetBaseDB(delkey) + _, err = ch.db.Get(ch.db.current.highest.Hash, delkey) if err != ErrNotFound { t.Error(err) return From c3a79d7d22779ca795c61a7cec0d5541a5e8ac42 Mon Sep 17 00:00:00 2001 From: benbaley Date: Thu, 12 Oct 2023 18:47:33 +0800 Subject: [PATCH 30/42] fix ut failed --- eth/handler_test.go | 1 + eth/sync_test.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/eth/handler_test.go b/eth/handler_test.go index c29f7c9392..65d9a47597 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -207,4 +207,5 @@ func newTestHandlerWithBlocks2(blocks int) *testHandler { func (b *testHandler) close() { b.handler.Stop() b.chain.Stop() + b.db.Close() } diff --git a/eth/sync_test.go b/eth/sync_test.go index eec4a8a67d..cd936ee6c4 100644 --- a/eth/sync_test.go +++ b/eth/sync_test.go @@ -38,7 +38,7 @@ func testFastSyncDisabling(t *testing.T, protocol uint) { t.Parallel() // Create an empty handler and ensure it's in fast sync mode - empty := newTestHandler2() + empty := newTestHandler() if atomic.LoadUint32(&empty.handler.fastSync) == 0 { t.Fatalf("fast sync disabled on pristine blockchain") } From ded4f1d8841378306c0301091d0f0613b15c407d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Oct 2023 02:27:35 +0000 Subject: [PATCH 31/42] Bump github.com/btcsuite/btcd Bumps [github.com/btcsuite/btcd](https://github.com/btcsuite/btcd) from 0.22.0-beta.0.20220111032746-97732e52810c to 0.23.2. - [Release notes](https://github.com/btcsuite/btcd/releases) - [Changelog](https://github.com/btcsuite/btcd/blob/master/CHANGES) - [Commits](https://github.com/btcsuite/btcd/commits/v0.23.2) --- updated-dependencies: - dependency-name: github.com/btcsuite/btcd dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index bfbb8a6618..16837f0877 100644 --- a/go.mod +++ b/go.mod @@ -64,7 +64,6 @@ require ( ) require ( - github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c github.com/herumi/bls v1.37.0 golang.org/x/net v0.17.0 ) From 655fa374f8249a35f2b6c345e83a1e7252f27693 Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Wed, 18 Oct 2023 11:17:49 +0800 Subject: [PATCH 32/42] fix dialPeers count --- p2p/dial.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/p2p/dial.go b/p2p/dial.go index ba194d48f6..64ab44c45c 100644 --- a/p2p/dial.go +++ b/p2p/dial.go @@ -289,7 +289,7 @@ loop: d.doneSinceLastLog++ case c := <-d.addPeerCh: - if c.is(dynDialedConn) || c.is(staticDialedConn) || c.is(consensusDialedConn) { + if !c.is(inboundConn) && (c.is(dynDialedConn) || c.is(staticDialedConn) || c.is(consensusDialedConn)) { d.dialPeers++ } id := c.node.ID() @@ -302,7 +302,7 @@ loop: // TODO: cancel dials to connected peers case c := <-d.remPeerCh: - if c.is(dynDialedConn) || c.is(staticDialedConn) || c.is(consensusDialedConn) { + if !c.is(inboundConn) && (c.is(dynDialedConn) || c.is(staticDialedConn) || c.is(consensusDialedConn)) { d.dialPeers-- } delete(d.peers, c.node.ID()) From fd5abd940bf24b63e8f46958a54f7cd4c8167a3a Mon Sep 17 00:00:00 2001 From: benbaley Date: Tue, 24 Oct 2023 12:08:37 +0800 Subject: [PATCH 33/42] go mod tidy --- go.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/go.mod b/go.mod index 16837f0877..bfbb8a6618 100644 --- a/go.mod +++ b/go.mod @@ -64,6 +64,7 @@ require ( ) require ( + github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c github.com/herumi/bls v1.37.0 golang.org/x/net v0.17.0 ) From 5c052d3bf13f58cfe8737b9a0c42462f89cc0110 Mon Sep 17 00:00:00 2001 From: benbaley Date: Tue, 24 Oct 2023 12:18:27 +0800 Subject: [PATCH 34/42] go mod tidy --- go.mod | 6 +++--- go.sum | 33 +++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 491d8d963a..a7f0900160 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( github.com/rs/cors v1.7.0 github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4 - github.com/stretchr/testify v1.7.0 + github.com/stretchr/testify v1.8.0 github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tealeg/xlsx v1.0.5 golang.org/x/crypto v0.14.0 @@ -61,15 +61,14 @@ require ( gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6 gopkg.in/urfave/cli.v1 v1.20.0 - gopkg.in/yaml.v2 v2.4.0 // indirect gotest.tools v2.2.0+incompatible gotest.tools/v3 v3.4.0 // indirect ) - require ( github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c github.com/herumi/bls v1.37.0 + github.com/influxdata/influxdb-client-go/v2 v2.12.3 golang.org/x/net v0.17.0 ) @@ -83,6 +82,7 @@ require ( github.com/go-ole/go-ole v1.2.4 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/google/go-cmp v0.5.9 // indirect + github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect diff --git a/go.sum b/go.sum index 166c621157..a6e308a2f6 100644 --- a/go.sum +++ b/go.sum @@ -9,9 +9,8 @@ github.com/PlatONnetwork/wagon v0.6.1-0.20201026015350-67507c2a7b96 h1:BA5xEQQrv github.com/PlatONnetwork/wagon v0.6.1-0.20201026015350-67507c2a7b96/go.mod h1:zPWloKR2Ep7uqrhyLyE483NCxlAlQnbPsQUJXWN6bVM= github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk= github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= +github.com/VictoriaMetrics/fastcache v1.5.7 h1:4y6y0G8PRzszQUYIQHHssv/jgPHAb5qQuuDNdCbyAgw= github.com/VictoriaMetrics/fastcache v1.5.7/go.mod h1:ptDBkNMQI4RtmVo8VS/XwRY6RoTu1dAWCbrk+6WsEM8= -github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= -github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= @@ -48,14 +47,12 @@ github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deckarep/golang-set v1.7.1 h1:SCQV0S6gTtp6itiFrTqI+pfmJ4LN85S1YzhDf9rTHJQ= github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo= github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= -github.com/deepmap/oapi-codegen v1.6.0/go.mod h1:ryDa9AgbELGeB+YEXE1dR53yAjHwFvE9iAUlWl9Al3M= github.com/deepmap/oapi-codegen v1.8.2 h1:SegyeYGcdi0jLLrpbCMoJxnUUn8GBXHsvr4rbzjuhfU= github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRktEqrX88CvjIw= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= @@ -83,7 +80,6 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI= github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= -github.com/getkin/kin-openapi v0.53.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4= github.com/getkin/kin-openapi v0.61.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs= @@ -115,7 +111,6 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219/go.mod h1:/X8TswGSh1pIozq4ZwCfxS0WA5JGXguxk94ar/4c87Y= @@ -143,21 +138,22 @@ github.com/herumi/bls v1.37.0 h1:EKPaFujxWsxSMlfN1NeR9GTfVOeAsAaNRGbdBfn9lBE= github.com/herumi/bls v1.37.0/go.mod h1:CnmR5QZ/QBnBE8Z55O+OtmUc6ICUdrOW9fwSRQwz5Bo= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= +github.com/holiman/uint256 v1.1.1 h1:4JywC80b+/hSfljFlEBLHrrh+CIONLDz9NuFl0af4Mw= github.com/holiman/uint256 v1.1.1/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= -github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM= -github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huin/goupnp v0.0.0-20161224104101-679507af18f3/go.mod h1:MZ2ZmwcBpvOoJ22IJsc7va19ZwoheaBk43rKg12SKag= -github.com/huin/goupnp v1.0.2 h1:RfGLP+h3mvisuWEyybxNq5Eft3NWhHLPeUN72kpKZoI= -github.com/huin/goupnp v1.0.2/go.mod h1:0dxJBVBHqTMjIUMkESDTNgOOx/Mw5wYIfyFmdzSamkM= +github.com/huin/goupnp v1.0.1-0.20210310174557-0ca763054c88 h1:bcAj8KroPf552TScjFPIakjH2/tdIrIH8F+cc4v4SRo= +github.com/huin/goupnp v1.0.1-0.20210310174557-0ca763054c88/go.mod h1:nNs7wvRfN1eKaMknBydLNQU6146XQim8t4h+q90biWo= github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY= github.com/influxdata/influxdb v1.7.6 h1:8mQ7A/V+3noMGCt/P9pD09ISaiz9XvgCk303UYA3gcs= github.com/influxdata/influxdb v1.7.6/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY= +github.com/influxdata/influxdb-client-go/v2 v2.12.3 h1:28nRlNMRIV4QbtIUvxhWqaxn0IpXeMSkY/uJa/O/vC4= +github.com/influxdata/influxdb-client-go/v2 v2.12.3/go.mod h1:IrrLUbCjjfkmRuaCiGQg4m2GbkaeJDcuWoxiWdQEbA0= +github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7wlPfJLvMCdtV4zPulc4uCPrlywQOmbFOhgQNU= +github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo= github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458 h1:6OvNmYgJyexcZ3pYbTI9jWx5tHo1Dee/tWbLMfPe2TA= github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= -github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= -github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jedisct1/go-minisign v0.0.0-20211028175153-1c139d1cc84b h1:ZGiXF8sz7PDk6RgkP+A/SFfUD0ZR/AgG6SpRNEDKZy8= github.com/jedisct1/go-minisign v0.0.0-20211028175153-1c139d1cc84b/go.mod h1:hQmNrgofl+IY/8L+n20H6E6PWBBTokdsv+q49j0QhsU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -285,12 +281,15 @@ github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8 github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= @@ -313,6 +312,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= @@ -323,6 +324,7 @@ golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -335,6 +337,7 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= @@ -372,7 +375,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -385,6 +387,7 @@ golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -402,6 +405,8 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From ab3522b2189d0e89117080cf8acefde4bb5ad00a Mon Sep 17 00:00:00 2001 From: benbaley Date: Tue, 24 Oct 2023 12:28:15 +0800 Subject: [PATCH 35/42] go mod tidy --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index a7f0900160..ea1e1258f3 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/hashicorp/go-bexpr v0.1.10 github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d github.com/holiman/bloomfilter/v2 v2.0.3 - github.com/holiman/uint256 v1.1.1 + github.com/holiman/uint256 v1.2.0 github.com/huin/goupnp v1.0.1-0.20210310174557-0ca763054c88 github.com/influxdata/influxdb v1.7.6 github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458 From 23cf2dff58ca1d0257adac4f0de6c3e5b3ff854c Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Tue, 24 Oct 2023 14:54:34 +0800 Subject: [PATCH 36/42] update dial consensus peer --- miner/worker.go | 3 -- p2p/consensus_dialed.go | 4 +- p2p/dial.go | 83 +++++++++++++++++++++++++++-------------- p2p/server.go | 27 +++++++++----- 4 files changed, 75 insertions(+), 42 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index e9107ed46a..4ca1ab5f4a 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -438,9 +438,6 @@ func (w *worker) newWorkLoop(recommit time.Duration) { timestamp time.Time // timestamp for each round of mining. ) - vdEvent := w.mux.Subscribe(cbfttypes.UpdateValidatorEvent{}) - defer vdEvent.Unsubscribe() - timer := time.NewTimer(0) defer timer.Stop() <-timer.C // discard the initial tick diff --git a/p2p/consensus_dialed.go b/p2p/consensus_dialed.go index 1351b8d23d..459a87882f 100644 --- a/p2p/consensus_dialed.go +++ b/p2p/consensus_dialed.go @@ -52,12 +52,12 @@ func (tasks *dialedTasks) AddTask(task *dialTask) error { return nil } -func (tasks *dialedTasks) RemoveTask(NodeID *enode.Node) error { +func (tasks *dialedTasks) RemoveTask(NodeID enode.ID) error { log.Info("[before remove]Consensus dialed task list before RemoveTask operation", "task queue", tasks.description()) if !tasks.isEmpty() { for i, t := range tasks.queue { - if t.dest.ID() == NodeID.ID() { + if t.dest.ID() == NodeID { tasks.queue = append(tasks.queue[:i], tasks.queue[i+1:]...) break } diff --git a/p2p/dial.go b/p2p/dial.go index ba194d48f6..a9e2805c24 100644 --- a/p2p/dial.go +++ b/p2p/dial.go @@ -122,7 +122,10 @@ type dialScheduler struct { static map[enode.ID]*dialTask staticPool []*dialTask - consensus *dialedTasks + consensus bool + consensusPeers int + updateConsensusPeersCh chan int + consensusPool *dialedTasks // The dial history keeps recently dialed nodes. Members of history are not dialed. history expHeap @@ -170,20 +173,21 @@ func (cfg dialConfig) withDefaults() dialConfig { func newDialScheduler(config dialConfig, it enode.Iterator, setupFunc dialSetupFunc) *dialScheduler { d := &dialScheduler{ - dialConfig: config.withDefaults(), - setupFunc: setupFunc, - dialing: make(map[enode.ID]*dialTask), - static: make(map[enode.ID]*dialTask), - peers: make(map[enode.ID]struct{}), - doneCh: make(chan *dialTask), - nodesIn: make(chan *enode.Node), - addStaticCh: make(chan *enode.Node), - remStaticCh: make(chan *enode.Node), - addPeerCh: make(chan *conn), - remPeerCh: make(chan *conn), - addconsensus: make(chan *enode.Node), - removeconsensus: make(chan *enode.Node), - consensus: NewDialedTasks(config.MaxConsensusPeers*2, nil), + dialConfig: config.withDefaults(), + setupFunc: setupFunc, + dialing: make(map[enode.ID]*dialTask), + static: make(map[enode.ID]*dialTask), + peers: make(map[enode.ID]struct{}), + doneCh: make(chan *dialTask), + nodesIn: make(chan *enode.Node), + addStaticCh: make(chan *enode.Node), + remStaticCh: make(chan *enode.Node), + addPeerCh: make(chan *conn), + remPeerCh: make(chan *conn), + addconsensus: make(chan *enode.Node), + removeconsensus: make(chan *enode.Node), + updateConsensusPeersCh: make(chan int), + consensusPool: NewDialedTasks(config.MaxConsensusPeers*2, nil), } d.lastStatsLog = d.clock.Now() d.ctx, d.cancel = context.WithCancel(context.Background()) @@ -215,6 +219,17 @@ func (d *dialScheduler) removeStatic(n *enode.Node) { } } +func (d *dialScheduler) setConsensus(status bool) { + d.consensus = status +} + +func (d *dialScheduler) updateConsensusNun(n int) { + select { + case d.updateConsensusPeersCh <- n: + case <-d.ctx.Done(): + } +} + func (d *dialScheduler) addConsensus(n *enode.Node) { select { case d.addconsensus <- n: @@ -234,7 +249,7 @@ func (d *dialScheduler) removeConsensusFromQueue(n *enode.Node) { } func (d *dialScheduler) initRemoveConsensusPeerFn(removeConsensusPeerFn removeConsensusPeerFn) { - d.consensus.InitRemoveConsensusPeerFn(removeConsensusPeerFn) + d.consensusPool.InitRemoveConsensusPeerFn(removeConsensusPeerFn) } // peerAdded updates the peer set. @@ -264,8 +279,8 @@ loop: for { // Launch new dials if slots are available. slots := d.freeDialSlots() - slots -= d.startConsensusDials(slots) slots -= d.startStaticDials(slots) + slots -= d.startConsensusDials(slots) if slots > 0 { nodesCh = d.nodesIn } else { @@ -289,7 +304,7 @@ loop: d.doneSinceLastLog++ case c := <-d.addPeerCh: - if c.is(dynDialedConn) || c.is(staticDialedConn) || c.is(consensusDialedConn) { + if c.is(dynDialedConn) || c.is(staticDialedConn) { d.dialPeers++ } id := c.node.ID() @@ -302,7 +317,7 @@ loop: // TODO: cancel dials to connected peers case c := <-d.remPeerCh: - if c.is(dynDialedConn) || c.is(staticDialedConn) || c.is(consensusDialedConn) { + if c.is(dynDialedConn) || c.is(staticDialedConn) { d.dialPeers-- } delete(d.peers, c.node.ID()) @@ -333,10 +348,12 @@ loop: } case node := <-d.addconsensus: log.Warn("dial adding consensus node", "node", node) - d.consensus.AddTask(&dialTask{flags: consensusDialedConn, dest: node}) + d.consensusPool.AddTask(newDialTask(node, dynDialedConn|consensusDialedConn)) case node := <-d.removeconsensus: - d.consensus.RemoveTask(node) - + d.consensusPool.RemoveTask(node.ID()) + case num := <-d.updateConsensusPeersCh: + d.log.Debug("update added consensus peers num", "num", num) + d.consensusPeers = num case <-historyExp: d.expireHistory() @@ -461,22 +478,32 @@ func (d *dialScheduler) startStaticDials(n int) (started int) { } func (d *dialScheduler) startConsensusDials(n int) (started int) { + if !d.consensus { + return + } + // 如果没有多余得slot,但是共识连接数量不够,那么每次额外拿出最多3个slot来执行,使得旧的连接可以被踢掉 + if n <= 0 && d.MaxConsensusPeers > d.consensusPeers { + n = d.MaxConsensusPeers - d.consensusPeers + } + if n > 3 { + n = 3 + } + // Create dials for consensus nodes if they are not connected. - i := 0 - for _, t := range d.consensus.ListTask() { - if i >= n { + for _, t := range d.consensusPool.ListTask() { + if started >= n { break } err := d.checkDial(t.dest) switch err { case errNetRestrict, errSelf: - d.consensus.RemoveTask(t.dest) + d.consensusPool.RemoveTask(t.dest.ID()) case nil: d.startDial(t) - i++ + started++ } } - return i + return started } // updateStaticPool attempts to move the given static dial back into staticPool. diff --git a/p2p/server.go b/p2p/server.go index 955893cce4..d8f84c654b 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -780,25 +780,30 @@ running: // to the consensus node set. srv.log.Trace("Adding consensus node", "node", n) id := n.ID() - if bytes.Equal(crypto.Keccak256(srv.ourHandshake.ID), id[:]) { + if srv.localnode.ID() == id { srv.log.Debug("We are become an consensus node") srv.consensus = true + srv.dialsched.setConsensus(true) } else { srv.dialsched.addConsensus(n) } consensusNodes[id] = true if p, ok := peers[id]; ok { - srv.log.Debug("Add consensus flag", "peer", id) p.rw.set(consensusDialedConn, true) + srv.dialsched.updateConsensusNun(srv.numConsensusPeer(peers)) + srv.log.Debug("Add consensus flag", "peer", id, "flag", p.rw.flags) } case n := <-srv.removeconsensus: // This channel is used by RemoveConsensusNode to remove an enode // from the consensus node set. srv.log.Trace("Removing consensus node", "node", n) id := n.ID() - if bytes.Equal(crypto.Keccak256(srv.ourHandshake.ID), id[:]) { - srv.log.Debug("We are not an consensus node") - srv.consensus = false + if srv.localnode.ID() == id { + if bytes.Equal(crypto.Keccak256(srv.ourHandshake.ID), id[:]) { + srv.log.Debug("We are not an consensus node") + srv.consensus = false + srv.dialsched.setConsensus(false) + } } srv.dialsched.removeConsensus(n) if _, ok := consensusNodes[n.ID()]; ok { @@ -806,10 +811,8 @@ running: } if p, ok := peers[n.ID()]; ok { p.rw.set(consensusDialedConn, false) - if !p.rw.is(staticDialedConn | trustedConn | inboundConn) { - p.rw.set(dynDialedConn, true) - } - srv.log.Debug("Remove consensus flag", "peer", n.ID(), "consensus", srv.consensus) + srv.dialsched.updateConsensusNun(srv.numConsensusPeer(peers)) + srv.log.Debug("Remove consensus flag", "peer", n.ID(), "consensus", srv.consensus, "flag", p.rw.flags) if len(peers) > srv.MaxPeers && !p.rw.is(staticDialedConn|trustedConn) { srv.log.Debug("Disconnect non-consensus node", "peer", n.ID(), "flags", p.rw.flags, "peers", len(peers), "consensus", srv.consensus) p.Disconnect(DiscRequested) @@ -863,6 +866,9 @@ running: peers[c.node.ID()] = p srv.log.Debug("Adding p2p peer", "peercount", len(peers), "id", p.ID(), "conn", c.flags, "addr", p.RemoteAddr(), "name", p.Name()) srv.dialsched.peerAdded(c) + if srv.consensus { + srv.dialsched.updateConsensusNun(srv.numConsensusPeer(peers)) + } if p.Inbound() { inboundCount++ } @@ -875,6 +881,9 @@ running: delete(peers, pd.ID()) srv.log.Debug("Removing p2p peer", "peercount", len(peers), "id", pd.ID(), "duration", d, "req", pd.requested, "err", pd.err) srv.dialsched.peerRemoved(pd.rw) + if srv.consensus { + srv.dialsched.updateConsensusNun(srv.numConsensusPeer(peers)) + } if pd.Inbound() { inboundCount-- } From bca07a3e02ac3ebb940cf04c0c6c93f1d1105372 Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Tue, 24 Oct 2023 15:01:23 +0800 Subject: [PATCH 37/42] update --- p2p/dial.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/p2p/dial.go b/p2p/dial.go index a9e2805c24..13b31ab7c4 100644 --- a/p2p/dial.go +++ b/p2p/dial.go @@ -484,9 +484,9 @@ func (d *dialScheduler) startConsensusDials(n int) (started int) { // 如果没有多余得slot,但是共识连接数量不够,那么每次额外拿出最多3个slot来执行,使得旧的连接可以被踢掉 if n <= 0 && d.MaxConsensusPeers > d.consensusPeers { n = d.MaxConsensusPeers - d.consensusPeers - } - if n > 3 { - n = 3 + if n > 3 { + n = 3 + } } // Create dials for consensus nodes if they are not connected. From 8e0e803ad310c33771e8abce6784e9b4b7a3a810 Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Thu, 26 Oct 2023 13:05:35 +0800 Subject: [PATCH 38/42] fix --- consensus/cbft/validator/validator.go | 8 ++++++++ core/cbfttypes/type.go | 4 +++- p2p/dial.go | 8 ++------ p2p/discover/v4_udp.go | 7 +++++-- p2p/discover/v4wire/v4wire.go | 20 -------------------- p2p/server.go | 24 +++++++++++++++++++++--- 6 files changed, 39 insertions(+), 32 deletions(-) diff --git a/consensus/cbft/validator/validator.go b/consensus/cbft/validator/validator.go index fdc6fa7b27..a3cc34643d 100644 --- a/consensus/cbft/validator/validator.go +++ b/consensus/cbft/validator/validator.go @@ -419,6 +419,14 @@ func (vp *ValidatorPool) Update(blockNumber uint64, epoch uint64, eventMux *even isValidatorAfter := vp.isValidator(epoch, vp.nodeID) + if isValidatorBefore || isValidatorAfter { + nodes := make(map[enode.ID]struct{}) + for _, validator := range vp.currentValidators.Nodes { + nodes[validator.NodeID] = struct{}{} + } + eventMux.Post(cbfttypes.UpdateValidatorEvent{Nodes: nodes}) + } + if isValidatorBefore { // If we are still a consensus node, that adding // new validators as consensus peer, and removing diff --git a/core/cbfttypes/type.go b/core/cbfttypes/type.go index 5fd07c1557..fd50b15f39 100644 --- a/core/cbfttypes/type.go +++ b/core/cbfttypes/type.go @@ -54,7 +54,9 @@ type RemoveValidatorEvent struct { Node *enode.Node } -type UpdateValidatorEvent struct{} +type UpdateValidatorEvent struct { + Nodes map[enode.ID]struct{} +} type ValidateNode struct { Index uint32 `json:"index"` diff --git a/p2p/dial.go b/p2p/dial.go index 13b31ab7c4..5ee758b51f 100644 --- a/p2p/dial.go +++ b/p2p/dial.go @@ -122,7 +122,6 @@ type dialScheduler struct { static map[enode.ID]*dialTask staticPool []*dialTask - consensus bool consensusPeers int updateConsensusPeersCh chan int consensusPool *dialedTasks @@ -219,10 +218,6 @@ func (d *dialScheduler) removeStatic(n *enode.Node) { } } -func (d *dialScheduler) setConsensus(status bool) { - d.consensus = status -} - func (d *dialScheduler) updateConsensusNun(n int) { select { case d.updateConsensusPeersCh <- n: @@ -478,9 +473,10 @@ func (d *dialScheduler) startStaticDials(n int) (started int) { } func (d *dialScheduler) startConsensusDials(n int) (started int) { - if !d.consensus { + if len(d.consensusPool.ListTask()) == 0 { return } + // 如果没有多余得slot,但是共识连接数量不够,那么每次额外拿出最多3个slot来执行,使得旧的连接可以被踢掉 if n <= 0 && d.MaxConsensusPeers > d.consensusPeers { n = d.MaxConsensusPeers - d.consensusPeers diff --git a/p2p/discover/v4_udp.go b/p2p/discover/v4_udp.go index f3b762500e..49d3841737 100644 --- a/p2p/discover/v4_udp.go +++ b/p2p/discover/v4_udp.go @@ -161,7 +161,6 @@ func ListenV4(c UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv4, error) { if cfg.ChainID != nil { bytes_ChainId, _ := rlp.EncodeToBytes(cfg.ChainID) - cRest = []rlp.RawValue{bytes_ChainId, bytes_ChainId} log.Info("UDP set chain ID", "chainId", cfg.ChainID, "bytes_ChainId", bytes_ChainId) } if cfg.PIP7ChainID != nil { @@ -364,6 +363,7 @@ func (t *UDPv4) RequestENR(n *enode.Node) (*enode.Node, error) { req := &v4wire.ENRRequest{ Expiration: uint64(time.Now().Add(expiration).Unix()), + Rest: cRestPIP7, } packet, hash, err := v4wire.Encode(t.priv, req) if err != nil { @@ -572,7 +572,7 @@ func (t *UDPv4) handlePacket(from *net.UDPAddr, buf []byte) error { packet := t.wrapPacket(rawpacket) fromID := fromKey.ID() if err == nil && packet.preverify != nil { - if !reflect.DeepEqual(rawpacket.Fork(), cRest) && !reflect.DeepEqual(rawpacket.Fork(), cRestPIP7) { + if !reflect.DeepEqual(rawpacket.Fork(), cRestPIP7) { return errData } err = packet.preverify(packet, from, fromID, fromKey) @@ -798,9 +798,12 @@ func (t *UDPv4) verifyENRRequest(h *packetHandlerV4, from *net.UDPAddr, fromID e } func (t *UDPv4) handleENRRequest(h *packetHandlerV4, from *net.UDPAddr, fromID enode.ID, mac []byte) { + req := h.Packet.(*v4wire.ENRRequest) + t.send(from, fromID, &v4wire.ENRResponse{ ReplyTok: mac, Record: *t.localNode.Node().Record(), + Rest: req.Rest, }) } diff --git a/p2p/discover/v4wire/v4wire.go b/p2p/discover/v4wire/v4wire.go index 4bbf7614be..4889eae5f7 100644 --- a/p2p/discover/v4wire/v4wire.go +++ b/p2p/discover/v4wire/v4wire.go @@ -23,7 +23,6 @@ import ( "crypto/elliptic" "errors" "fmt" - "io" "math/big" "net" "time" @@ -195,16 +194,6 @@ func (req *Ping) Fork() []rlp.RawValue { return req.ForkID } -func (req *Ping) EncodeRLP(w io.Writer) error { - return rlp.Encode(w, PingV1{ - Version: req.Version, - From: req.From, - To: req.To, - Expiration: req.Expiration, - Rest: req.ForkID, - }) -} - func (req *Ping) DecodeRLP(s *rlp.Stream) error { // Retrieve the entire receipt blob as we need to try multiple decoders blob, err := s.Raw() @@ -259,15 +248,6 @@ func (req *Pong) Fork() []rlp.RawValue { return req.ForkID } -func (req *Pong) EncodeRLP(w io.Writer) error { - return rlp.Encode(w, PongV1{ - To: req.To, - ReplyTok: req.ReplyTok, - Expiration: req.Expiration, - Rest: req.ForkID, - }) -} - func (req *Pong) DecodeRLP(s *rlp.Stream) error { // Retrieve the entire receipt blob as we need to try multiple decoders blob, err := s.Raw() diff --git a/p2p/server.go b/p2p/server.go index d8f84c654b..cd1b446186 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -783,7 +783,6 @@ running: if srv.localnode.ID() == id { srv.log.Debug("We are become an consensus node") srv.consensus = true - srv.dialsched.setConsensus(true) } else { srv.dialsched.addConsensus(n) } @@ -802,7 +801,6 @@ running: if bytes.Equal(crypto.Keccak256(srv.ourHandshake.ID), id[:]) { srv.log.Debug("We are not an consensus node") srv.consensus = false - srv.dialsched.setConsensus(false) } } srv.dialsched.removeConsensus(n) @@ -1268,7 +1266,7 @@ func (srv *Server) StartWatching(eventMux *event.TypeMux) { } func (srv *Server) watching() { - events := srv.eventMux.Subscribe(cbfttypes.AddValidatorEvent{}, cbfttypes.RemoveValidatorEvent{}) + events := srv.eventMux.Subscribe(cbfttypes.AddValidatorEvent{}, cbfttypes.RemoveValidatorEvent{}, cbfttypes.UpdateValidatorEvent{}) defer events.Unsubscribe() for { @@ -1285,6 +1283,26 @@ func (srv *Server) watching() { case cbfttypes.RemoveValidatorEvent: srv.log.Trace("Received RemoveValidatorEvent", "nodeID", data.Node.ID().String()) srv.RemoveConsensusPeer(data.Node) + case cbfttypes.UpdateValidatorEvent: + if _, ok := data.Nodes[srv.localnode.ID()]; ok { + srv.doPeerOp(func(peers map[enode.ID]*Peer) { + for id, peer := range peers { + if _, ok := data.Nodes[id]; ok { + peer.rw.set(consensusDialedConn, true) + } else { + peer.rw.set(consensusDialedConn, false) + } + } + srv.dialsched.updateConsensusNun(srv.numConsensusPeer(peers)) + }) + } else { + srv.doPeerOp(func(peers map[enode.ID]*Peer) { + for _, peer := range peers { + peer.rw.set(consensusDialedConn, false) + } + srv.dialsched.updateConsensusNun(0) + }) + } default: srv.log.Error("Received unexcepted event") } From 53b65812a6e4cb2d22a314406e0a12b6295ab0ec Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Thu, 26 Oct 2023 15:25:31 +0800 Subject: [PATCH 39/42] fix --- consensus/cbft/validator/validator.go | 10 ++++------ p2p/server.go | 10 ++++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/consensus/cbft/validator/validator.go b/consensus/cbft/validator/validator.go index a3cc34643d..909ee05ecc 100644 --- a/consensus/cbft/validator/validator.go +++ b/consensus/cbft/validator/validator.go @@ -419,13 +419,11 @@ func (vp *ValidatorPool) Update(blockNumber uint64, epoch uint64, eventMux *even isValidatorAfter := vp.isValidator(epoch, vp.nodeID) - if isValidatorBefore || isValidatorAfter { - nodes := make(map[enode.ID]struct{}) - for _, validator := range vp.currentValidators.Nodes { - nodes[validator.NodeID] = struct{}{} - } - eventMux.Post(cbfttypes.UpdateValidatorEvent{Nodes: nodes}) + nodes := make(map[enode.ID]struct{}) + for _, validator := range vp.currentValidators.Nodes { + nodes[validator.NodeID] = struct{}{} } + eventMux.Post(cbfttypes.UpdateValidatorEvent{Nodes: nodes}) if isValidatorBefore { // If we are still a consensus node, that adding diff --git a/p2p/server.go b/p2p/server.go index cd1b446186..b140895696 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -798,10 +798,8 @@ running: srv.log.Trace("Removing consensus node", "node", n) id := n.ID() if srv.localnode.ID() == id { - if bytes.Equal(crypto.Keccak256(srv.ourHandshake.ID), id[:]) { - srv.log.Debug("We are not an consensus node") - srv.consensus = false - } + srv.log.Debug("We are not an consensus node") + srv.consensus = false } srv.dialsched.removeConsensus(n) if _, ok := consensusNodes[n.ID()]; ok { @@ -1293,6 +1291,8 @@ func (srv *Server) watching() { peer.rw.set(consensusDialedConn, false) } } + srv.log.Debug("We are become an consensus node") + srv.consensus = true srv.dialsched.updateConsensusNun(srv.numConsensusPeer(peers)) }) } else { @@ -1300,6 +1300,8 @@ func (srv *Server) watching() { for _, peer := range peers { peer.rw.set(consensusDialedConn, false) } + srv.log.Debug("We are not an consensus node") + srv.consensus = false srv.dialsched.updateConsensusNun(0) }) } From e3637c70bba07721092f4871a2ffee785d878696 Mon Sep 17 00:00:00 2001 From: niuxiaojie81 <85773309@qq.com> Date: Fri, 27 Oct 2023 16:36:32 +0800 Subject: [PATCH 40/42] =?UTF-8?q?=E6=A0=A1=E9=AA=8CHeader=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E6=A0=B9=E6=8D=AE=E4=B8=8D=E5=90=8C=E6=83=85=E5=86=B5?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=88=96=E5=BC=82=E6=AD=A5=E4=BB=8ECbft?= =?UTF-8?q?=E4=B8=AD=E8=8E=B7=E5=8F=96parent=E5=8C=BA=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consensus/bft_mock.go | 2 +- consensus/cbft/cbft.go | 30 +++++++++++++++++++++++++++--- consensus/consensus.go | 2 +- core/blockchain.go | 5 +++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/consensus/bft_mock.go b/consensus/bft_mock.go index cd682095a9..1cdd3bd71c 100644 --- a/consensus/bft_mock.go +++ b/consensus/bft_mock.go @@ -165,7 +165,7 @@ func (bm *BftMock) Author(header *types.Header) (common.Address, error) { // VerifyHeader checks whether a header conforms to the consensus rules of a // given engine. Verifying the seal may be done optionally here, or explicitly // via the VerifySeal method. -func (bm *BftMock) VerifyHeader(chain ChainReader, header *types.Header, seal bool) error { +func (bm *BftMock) VerifyHeader(chain ChainReader, header *types.Header, async bool) error { if bm.fakeFail == header.Number.Uint64() { return fmt.Errorf("failed verifyHeader on bftMock") } diff --git a/consensus/cbft/cbft.go b/consensus/cbft/cbft.go index 9042801742..6e60c17662 100644 --- a/consensus/cbft/cbft.go +++ b/consensus/cbft/cbft.go @@ -641,7 +641,7 @@ func (cbft *Cbft) Author(header *types.Header) (common.Address, error) { return header.Coinbase, nil } -func (cbft *Cbft) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error { +func (cbft *Cbft) VerifyHeader(chain consensus.ChainReader, header *types.Header, async bool) error { // Short circuit if the header is known, or its parent not number := header.Number.Uint64() if chain.GetHeader(header.Hash(), number) != nil { @@ -650,7 +650,12 @@ func (cbft *Cbft) VerifyHeader(chain consensus.ChainReader, header *types.Header parent := chain.GetHeader(header.ParentHash, number-1) if parent == nil { - parentBlock := cbft.GetBlockWithoutLock(header.ParentHash, number-1) + var parentBlock *types.Block + if async { + parentBlock = cbft.GetBlockWithLock(header.ParentHash, number-1) + } else { + parentBlock = cbft.GetBlockWithoutLock(header.ParentHash, number-1) + } if parentBlock != nil { parent = parentBlock.Header() } @@ -738,7 +743,7 @@ func (cbft *Cbft) verifyHeaderWorker(chain consensus.ChainReader, headers []*typ if index == 0 { parent = chain.GetHeader(headers[0].ParentHash, headers[0].Number.Uint64()-1) if parent == nil { - parentBlock := cbft.GetBlockWithoutLock(headers[0].ParentHash, headers[0].Number.Uint64()-1) + parentBlock := cbft.GetBlockWithLock(headers[0].ParentHash, headers[0].Number.Uint64()-1) if parentBlock != nil { parent = parentBlock.Header() } @@ -1312,6 +1317,25 @@ func (cbft *Cbft) GetBlock(hash common.Hash, number uint64) *types.Block { return <-result } +// GetBlockWithLock synchronously obtains blocks according to the specified number and hash. +func (cbft *Cbft) GetBlockWithLock(hash common.Hash, number uint64) *types.Block { + result := make(chan *types.Block, 1) + + cbft.asyncCallCh <- func() { + block, _ := cbft.blockTree.FindBlockAndQC(hash, number) + if block == nil { + if eb := cbft.state.FindBlock(hash, number); eb != nil { + block = eb + } else { + cbft.log.Debug("Get block failed", "hash", hash, "number", number) + } + } + result <- block + } + + return <-result +} + // GetBlockWithoutLock returns the block corresponding to the specified number and hash. func (cbft *Cbft) GetBlockWithoutLock(hash common.Hash, number uint64) *types.Block { block, _ := cbft.blockTree.FindBlockAndQC(hash, number) diff --git a/consensus/consensus.go b/consensus/consensus.go index a3fba47c6f..eff698936a 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -81,7 +81,7 @@ type Engine interface { // VerifyHeader checks whether a header conforms to the consensus rules of a // given engine. Verifying the seal may be done optionally here, or explicitly // via the VerifySeal method. - VerifyHeader(chain ChainReader, header *types.Header, seal bool) error + VerifyHeader(chain ChainReader, header *types.Header, async bool) error // VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers // concurrently. The method returns a quit channel to abort the operations and diff --git a/core/blockchain.go b/core/blockchain.go index 934e09658c..2f8f2cf999 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1538,13 +1538,14 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er headers[i] = block.Header() seals[i] = verifySeals } - abort, results := bc.engine.VerifyHeaders(bc, headers, seals) - defer close(abort) // Pause engine bc.engine.Pause() defer bc.engine.Resume() + abort, results := bc.engine.VerifyHeaders(bc, headers, seals) + defer close(abort) + // Peek the error for the first block to decide the directing import logic it := newInsertIterator(chain, results, bc.Validator()) block, err := it.next() From 1ebc677ec0540ce0d369fb32d1a5d6bd657c0412 Mon Sep 17 00:00:00 2001 From: niuxiaojie81 <85773309@qq.com> Date: Mon, 30 Oct 2023 16:18:44 +0800 Subject: [PATCH 41/42] Increase the number of cache blocks downloaded --- eth/downloader/queue.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index b4534377a3..784ac23c8e 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -40,8 +40,8 @@ const ( ) var ( - blockCacheMaxItems = 128 // Maximum number of blocks to cache before throttling the download - blockCacheInitialItems = 128 // Initial number of blocks to start fetching, before we know the sizes of the blocks + blockCacheMaxItems = 1024 // Maximum number of blocks to cache before throttling the download + blockCacheInitialItems = 256 // Initial number of blocks to start fetching, before we know the sizes of the blocks blockCacheMemory = 256 * 1024 * 1024 // Maximum amount of memory to use for block caching blockCacheSizeWeight = 0.1 // Multiplier to approximate the average block size based on past ones ) From cf2fb086efa2cb766bed3cfbe3bbbdc94c03b5a9 Mon Sep 17 00:00:00 2001 From: niuxiaojie81 <85773309@qq.com> Date: Mon, 30 Oct 2023 16:23:32 +0800 Subject: [PATCH 42/42] snapshot enable by default --- cmd/utils/flags.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 6d018d449d..d8a81ba536 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -282,9 +282,9 @@ var ( Usage: "Time interval to regenerate the trie cache journal", Value: ethconfig.Defaults.TrieCleanCacheRejournal, } - SnapshotFlag = cli.BoolFlag{ + SnapshotFlag = cli.BoolTFlag{ Name: "snapshot", - Usage: `Enables snapshot-database mode`, + Usage: `Enables snapshot-database mode (default = enable)`, } BloomFilterSizeFlag = cli.Uint64Flag{ Name: "bloomfilter.size",