From 78849d51aec60ea942408357eb305105097f3afc Mon Sep 17 00:00:00 2001 From: Jin Date: Mon, 1 May 2023 08:16:10 +0800 Subject: [PATCH] BUG:Reorganization notification --- core/blockchain/blockchain.go | 20 +++++++++++--------- rpc/client/notificationhandlers.go | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/core/blockchain/blockchain.go b/core/blockchain/blockchain.go index 18fb9fde..fb33f80a 100644 --- a/core/blockchain/blockchain.go +++ b/core/blockchain/blockchain.go @@ -443,8 +443,8 @@ func (b *BlockChain) HasBlockInDB(h *hash.Hash) bool { // IsCurrent returns whether or not the chain believes it is current. Several // factors are used to guess, but the key factors that allow the chain to // believe it is current are: -// - Latest block height is after the latest checkpoint (if enabled) -// - Latest block has a timestamp newer than 24 hours ago +// - Latest block height is after the latest checkpoint (if enabled) +// - Latest block has a timestamp newer than 24 hours ago // // This function is safe for concurrent access. func (b *BlockChain) IsCurrent() bool { @@ -456,8 +456,8 @@ func (b *BlockChain) IsCurrent() bool { // isCurrent returns whether or not the chain believes it is current. Several // factors are used to guess, but the key factors that allow the chain to // believe it is current are: -// - Latest block height is after the latest checkpoint (if enabled) -// - Latest block has a timestamp newer than 24 hours ago +// - Latest block height is after the latest checkpoint (if enabled) +// - Latest block has a timestamp newer than 24 hours ago // // This function MUST be called with the chain state lock held (for reads). func (b *BlockChain) isCurrent() bool { @@ -628,11 +628,13 @@ func (b *BlockChain) reorganizeChain(ib meerdag.IBlock, detachNodes *list.List, oldBlocks = append(oldBlocks, ob.Block.GetHash()) } - b.sendNotification(Reorganization, &ReorganizationNotifyData{ - OldBlocks: oldBlocks, - NewBlock: newBlock.Hash(), - NewOrder: uint64(ib.GetOrder()), - }) + if len(oldBlocks) > 0 { + b.sendNotification(Reorganization, &ReorganizationNotifyData{ + OldBlocks: oldBlocks, + NewBlock: newBlock.Hash(), + NewOrder: uint64(ib.GetOrder()), + }) + } // Why the old order is the order that was removed by the new block, because the new block // must be one of the tip of the dag.This is very important for the following understanding. diff --git a/rpc/client/notificationhandlers.go b/rpc/client/notificationhandlers.go index 639e9965..fc4a6820 100644 --- a/rpc/client/notificationhandlers.go +++ b/rpc/client/notificationhandlers.go @@ -110,7 +110,7 @@ func parseReorganizationNtfnParams(params []json.RawMessage) (*hash.Hash, int64, // Unmarshal second parameter as an integer. var blockOrder int64 - err = json.Unmarshal(params[1], &blockOrder) + err = json.Unmarshal(params[2], &blockOrder) if err != nil { return nil, 0, nil, err }