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

blockchain: Do not accept orphans/genesis block. #1057

Merged
merged 1 commit into from
Feb 19, 2018
Merged
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
16 changes: 11 additions & 5 deletions blockchain/accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ func (b *BlockChain) maybeAcceptBlock(block *dcrutil.Block, flags BehaviorFlags)
return false, err
}

// This function should never be called with orphan blocks or the
// genesis block.
if prevNode == nil {
prevHash := &block.MsgBlock().Header.PrevBlock
str := fmt.Sprintf("previous block %s is not known", prevHash)
return false, ruleError(ErrMissingParent, str)
}

blockHeight := block.Height()

// The block must pass all of the validation rules which depend on the
Expand Down Expand Up @@ -154,11 +162,9 @@ func (b *BlockChain) maybeAcceptBlock(block *dcrutil.Block, flags BehaviorFlags)
blockHeader := &block.MsgBlock().Header
newNode := newBlockNode(blockHeader,
stake.FindSpentTicketsInBlock(block.MsgBlock()))
if prevNode != nil {
newNode.parent = prevNode
newNode.height = blockHeight
newNode.workSum.Add(prevNode.workSum, newNode.workSum)
}
newNode.parent = prevNode
newNode.height = blockHeight
newNode.workSum.Add(prevNode.workSum, newNode.workSum)

// Fetching a stake node could enable a new DoS vector, so restrict
// this only to blocks that are recent in history.
Expand Down