standalone: IsTVI code consistency pass.
This improves the accuracy of the comment on the IsTreasuryVoteInterval function and also makes all code related to it more consistent with the rest of the codebase.
This commit is contained in:
parent
ea6a7aa69e
commit
fee0eefb54
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user