Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG:Reorganization notification #402

Merged
merged 1 commit into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions core/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rpc/client/notificationhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down