From ccf024f7715684960cb758550af2c80e4c609e26 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Mon, 5 Oct 2020 00:34:47 -0500 Subject: [PATCH] mining: Add ticket exhaustion check. 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. --- internal/mining/error.go | 6 ++++++ internal/mining/mining.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/internal/mining/error.go b/internal/mining/error.go index 0952fd3970..c2616f853b 100644 --- a/internal/mining/error.go +++ b/internal/mining/error.go @@ -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 @@ -57,6 +62,7 @@ var miningErrorCodeStrings = map[MiningErrorCode]string{ ErrGetTopBlock: "ErrGetTopBlock", ErrGettingDifficulty: "ErrGettingDifficulty", ErrTransactionAppend: "ErrTransactionAppend", + ErrTicketExhaustion: "ErrTicketExhaustion", ErrCheckConnectBlock: "ErrCheckConnectBlock", ErrFraudProofIndex: "ErrFraudProofIndex", ErrFetchTxStore: "ErrFetchTxStore", diff --git a/internal/mining/mining.go b/internal/mining/mining.go index b6d6807433..a49967948e 100644 --- a/internal/mining/mining.go +++ b/internal/mining/mining.go @@ -1843,6 +1843,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