Skip to content

Commit

Permalink
mining: Add ticket exhaustion check.
Browse files Browse the repository at this point in the history
This modifies the mining template creation logic to make use of the new
ability to check if the template would result in an unrecoverable chain
due to inevitable ticket exhaustion along with an associated new mining
rule error.
  • Loading branch information
davecgh committed Oct 5, 2020
1 parent 4063b55 commit 19af5ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/mining/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const (
// to a msgblock.
ErrTransactionAppend

// ErrTicketExhaustion indicates that there will not be enough mature
// tickets by the end of the next ticket maturity period to progress the
// chain.
ErrTicketExhaustion

// ErrCheckConnectBlock indicates that a newly created block template
// failed blockchain.CheckConnectBlock.
ErrCheckConnectBlock
Expand All @@ -57,6 +62,7 @@ var miningErrorCodeStrings = map[MiningErrorCode]string{
ErrGetTopBlock: "ErrGetTopBlock",
ErrGettingDifficulty: "ErrGettingDifficulty",
ErrTransactionAppend: "ErrTransactionAppend",
ErrTicketExhaustion: "ErrTicketExhaustion",
ErrCheckConnectBlock: "ErrCheckConnectBlock",
ErrFraudProofIndex: "ErrFraudProofIndex",
ErrFetchTxStore: "ErrFetchTxStore",
Expand Down
8 changes: 8 additions & 0 deletions internal/mining/mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,14 @@ mempoolLoop:
}
}

// Ensure that mining the block would not cause the chain to become
// unrecoverable due to ticket exhaustion.
err = g.chain.CheckTicketExhaustion(&best.Hash, uint8(freshStake))
if err != nil {
log.Debug(err)
return nil, miningRuleError(ErrTicketExhaustion, err.Error())
}

// Get the ticket revocations (SSRtx tx) and store them and their
// number.
revocations := 0
Expand Down

0 comments on commit 19af5ba

Please sign in to comment.