Skip to content

Commit

Permalink
Refetch duplicate-stake rejected block only if blockchain is up-to-date
Browse files Browse the repository at this point in the history
  • Loading branch information
mably committed May 15, 2015
1 parent 5d5d6ca commit a64a1c2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
1 change: 0 additions & 1 deletion blockchain/ppc.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,6 @@ func (b *BlockChain) GetKernelStakeModifier(hash *wire.ShaHash, timeSource Media
return stakeModifier, err
}


// WantedOrphan finds block wanted by given orphan block
//
// This function is safe for concurrent access.
Expand Down
16 changes: 4 additions & 12 deletions blockmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,19 +644,11 @@ func (b *blockManager) handleBlockMsg(bmsg *blockMsg) {
"latest block: %v", err)
} else {
bmsg.peer.PushGetBlocksMsg(locator, orphanRoot)
// ppc: getblocks may not obtain the ancestor block rejected
// earlier by duplicate-stake check so we ask for it again directly
// https://github.com/ppcoin/ppcoin/blob/v0.4.0ppc/src/main.cpp#L2052
b.refetchDuplicateStakeRejectedAncestorBlock(bmsg.peer, blockSha)
}

// ppc: getblocks may not obtain the ancestor block rejected
// earlier by duplicate-stake check so we ask for it again directly
// https://github.com/ppcoin/ppcoin/blob/v0.4.0ppc/src/main.cpp#L2052
if b.IsCurrent() {
wantedOrphan := b.blockChain.WantedOrphan(blockSha)
iv := wire.NewInvVect(wire.InvTypeBlock, wantedOrphan)
msgGetData := wire.NewMsgGetData()
msgGetData.AddInvVect(iv)
bmsg.peer.QueueMessage(msgGetData, nil)
}

} else {
// When the block is not an orphan, log information about it and
// update the chain state.
Expand Down
12 changes: 12 additions & 0 deletions ppc.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,15 @@ func (m *CPUMiner) SubmitMintBlock(mintBlock *wire.MsgBlock) bool {

return m.submitBlock(block)
}

// refetchDuplicateStakeRejectedAncestorBlock
func (b *blockManager) refetchDuplicateStakeRejectedAncestorBlock(
peer *peer, blockSha *wire.ShaHash) {
if b.IsCurrent() {
wantedOrphan := b.blockChain.WantedOrphan(blockSha)
iv := wire.NewInvVect(wire.InvTypeBlock, wantedOrphan)
msgGetData := wire.NewMsgGetData()
msgGetData.AddInvVect(iv)
peer.QueueMessage(msgGetData, nil)
}
}

0 comments on commit a64a1c2

Please sign in to comment.