diff --git a/blockchain/standalone/treasury.go b/blockchain/standalone/treasury.go index fc3c4c60..93f1dbbd 100644 --- a/blockchain/standalone/treasury.go +++ b/blockchain/standalone/treasury.go @@ -17,8 +17,8 @@ func CalcTSpendExpiry(nextBlockHeight int64, tvi, multiplier uint64) uint32 { return uint32(maxTVI + 2) // + 2 to deal with Expiry handling in mempool. } -// IsTreasuryVoteInterval returns true if the passed height is on a Treasury -// Vote Interval. +// IsTreasuryVoteInterval returns true if the passed height is on a treasury +// vote interval (TVI) and is not 0. func IsTreasuryVoteInterval(height, tvi uint64) bool { return height%tvi == 0 && height != 0 } diff --git a/blockchain/treasury_test.go b/blockchain/treasury_test.go index f9489d62..c14fb7e4 100644 --- a/blockchain/treasury_test.go +++ b/blockchain/treasury_test.go @@ -586,8 +586,7 @@ func TestTSpendVoteCount(t *testing.T) { // Assert we are on a TVI and generate block. This should fail. startTip = g.TipName() - if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), - tvi) { + if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), tvi) { t.Fatalf("expected !TVI %v", g.Tip().Header.Height) } name = "btvinotenough0" @@ -619,8 +618,7 @@ func TestTSpendVoteCount(t *testing.T) { // Assert we are on a TVI and generate block. This should fail. startTip = g.TipName() - if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), - tvi) { + if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), tvi) { t.Fatalf("expected !TVI %v", g.Tip().Header.Height) } name = "btvinotenough1" @@ -654,8 +652,7 @@ func TestTSpendVoteCount(t *testing.T) { // Assert we are on a TVI and generate block. This should fail with No // vote (TSpend should not have been submitted). startTip = g.TipName() - if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), - tvi) { + if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), tvi) { t.Fatalf("expected !TVI %v", g.Tip().Header.Height) } name = "btvienough0" @@ -711,8 +708,7 @@ func TestTSpendVoteCount(t *testing.T) { // Assert TSpend expired startTip = g.TipName() - if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), - tvi) { + if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), tvi) { t.Fatalf("expected !TVI %v", g.Tip().Header.Height) } name = "bexpired0" @@ -791,8 +787,7 @@ func TestTSpendVoteCount(t *testing.T) { // Verify we are one vote shy of quorum startTip = g.TipName() - if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), - tvi) { + if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), tvi) { t.Fatalf("expected !TVI %v", g.Tip().Header.Height) } name = "bquorum0" @@ -848,8 +843,7 @@ func TestTSpendVoteCount(t *testing.T) { } // Verify TSpend can be added exactly on quorum. - if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), - tvi) { + if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), tvi) { t.Fatalf("expected !TVI %v", g.Tip().Header.Height) } name = "bquorum1" @@ -2598,8 +2592,7 @@ func TestTSpendSignature(t *testing.T) { } // Assert that we are on a TVI. - if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), - tvi) { + if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), tvi) { t.Fatalf("expected !TVI %v", g.Tip().Header.Height) } @@ -2810,8 +2803,7 @@ func TestTSpendSignatureInvalid(t *testing.T) { } // Assert that we are on a TVI. - if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), - tvi) { + if standalone.IsTreasuryVoteInterval(uint64(g.Tip().Header.Height), tvi) { t.Fatalf("expected !TVI %v", g.Tip().Header.Height) } diff --git a/blockchain/validate.go b/blockchain/validate.go index 1b0a2940..2116f8b9 100644 --- a/blockchain/validate.go +++ b/blockchain/validate.go @@ -3412,8 +3412,7 @@ func (b *BlockChain) consensusScriptVerifyFlags(node *blockNode) (txscript.Scrip // function assumes that the treasury agenda is enabled. func (b *BlockChain) tspendChecks(prevNode *blockNode, block *dcrutil.Block) error { blockHeight := prevNode.height + 1 - - isTVI := standalone.IsTreasuryVoteInterval(uint64(block.Height()), + isTVI := standalone.IsTreasuryVoteInterval(uint64(blockHeight), b.chainParams.TreasuryVoteInterval) var totalTSpendAmount int64 diff --git a/internal/rpcserver/rpcserver.go b/internal/rpcserver/rpcserver.go index c88646c1..328ae733 100644 --- a/internal/rpcserver/rpcserver.go +++ b/internal/rpcserver/rpcserver.go @@ -3289,9 +3289,10 @@ func handleGetTreasurySpendVotes(_ context.Context, s *Server, cmd interface{}) // functions will behave properly. expiry := tx.MsgTx().Expiry if !standalone.IsTreasuryVoteInterval(uint64(expiry-2), tvi) { - err := fmt.Errorf("tspend %s has incorrect expiry %d", tx.Hash(), expiry) + errStr := fmt.Sprintf("tspend %s has incorrect expiry %d", tx.Hash(), + expiry) context := "tspend without correct expiry" - return nil, rpcInternalError(err.Error(), context) + return nil, rpcInternalError(errStr, context) } // We only count votes for tspends that are inside their voting