multi: Remove treasury flag from CheckSSGenVotes.
This updates the stake.CheckSSGenVotes function to remove the treasury agenda check, but still retain the logic to reject vote transactions that contain a null data script in the last output but don't have a transaction version equal to the treasury transaction version. This is now safe since: - The treasury agenda has activated - There are no transactions that violate this rule in any blocks prior to the agenda activating
This commit is contained in:
parent
50684f8152
commit
e587ae33e1
@ -977,9 +977,9 @@ func GetSSGenTreasuryVotes(PkScript []byte) ([]TreasuryVoteTuple, error) {
|
||||
// designating what the remaining data that is pushed is. In the case of
|
||||
// 'TV' (Treasury Vote) it checks for a <hash><vote> tuple. For example:
|
||||
// OP_RETURN OP_DATA_X 'T','V' <N hashvote_tuple>
|
||||
// NOTE: This output is only appended when the treasury agenda is active
|
||||
// and a treasury spend is being voted on.
|
||||
func CheckSSGenVotes(tx *wire.MsgTx, isTreasuryEnabled bool) ([]TreasuryVoteTuple, error) {
|
||||
// NOTE: This output is only appended when a treasury spend is being voted
|
||||
// on.
|
||||
func CheckSSGenVotes(tx *wire.MsgTx) ([]TreasuryVoteTuple, error) {
|
||||
// Check to make sure there aren't too many inputs.
|
||||
if len(tx.TxIn) != NumInputsPerSSGen {
|
||||
str := "SSgen tx has an invalid number of inputs"
|
||||
@ -1102,13 +1102,11 @@ func CheckSSGenVotes(tx *wire.MsgTx, isTreasuryEnabled bool) ([]TreasuryVoteTupl
|
||||
// data push that designates what the data is that follows the
|
||||
// discriminator. In the case of 'T','V' the next data push should be N
|
||||
// hashes. If it is we need to decrease the count on OP_SSGEN tests by
|
||||
// one. This check is only valid if the treasury agenda is active.
|
||||
// one.
|
||||
txOutLen := len(tx.TxOut)
|
||||
lastTxOut := tx.TxOut[len(tx.TxOut)-1]
|
||||
var votes []TreasuryVoteTuple
|
||||
if isTreasuryEnabled && IsNullDataScript(lastTxOut.Version,
|
||||
lastTxOut.PkScript) {
|
||||
|
||||
if IsNullDataScript(lastTxOut.Version, lastTxOut.PkScript) {
|
||||
txOutLen--
|
||||
|
||||
// We call this function in order to prevent rolling of
|
||||
@ -1151,7 +1149,7 @@ func CheckSSGenVotes(tx *wire.MsgTx, isTreasuryEnabled bool) ([]TreasuryVoteTupl
|
||||
// returns TSpend votes if there are any) to maintain consistency and backwards
|
||||
// compatibility.
|
||||
func CheckSSGen(tx *wire.MsgTx, isTreasuryEnabled bool) error {
|
||||
_, err := CheckSSGenVotes(tx, isTreasuryEnabled)
|
||||
_, err := CheckSSGenVotes(tx)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@ -686,6 +686,7 @@ func TestSSGenErrors(t *testing.T) {
|
||||
|
||||
// Verify optional OP_RETURN with no discriminator.
|
||||
var ssgenNoDiscriminator = dcrutil.NewTx(ssgenMsgTxNoDiscriminator)
|
||||
ssgenNoDiscriminator.SetVersion(wire.TxVersionTreasury)
|
||||
ssgenNoDiscriminator.SetTree(wire.TxTreeStake)
|
||||
ssgenNoDiscriminator.SetIndex(0)
|
||||
|
||||
@ -700,6 +701,7 @@ func TestSSGenErrors(t *testing.T) {
|
||||
|
||||
// Verify optional OP_RETURN with an invalid discriminator length.
|
||||
var ssgenInvalidDiscriminator = dcrutil.NewTx(ssgenMsgTxInvalidDiscriminator)
|
||||
ssgenInvalidDiscriminator.SetVersion(wire.TxVersionTreasury)
|
||||
ssgenInvalidDiscriminator.SetTree(wire.TxTreeStake)
|
||||
ssgenInvalidDiscriminator.SetIndex(0)
|
||||
|
||||
@ -714,6 +716,7 @@ func TestSSGenErrors(t *testing.T) {
|
||||
|
||||
// Verify optional OP_RETURN with an unknown discriminator.
|
||||
var ssgenInvalidDiscriminator2 = dcrutil.NewTx(ssgenMsgTxUnknownDiscriminator)
|
||||
ssgenInvalidDiscriminator2.SetVersion(wire.TxVersionTreasury)
|
||||
ssgenInvalidDiscriminator2.SetTree(wire.TxTreeStake)
|
||||
ssgenInvalidDiscriminator2.SetIndex(0)
|
||||
|
||||
@ -747,6 +750,7 @@ func TestSSGenErrors(t *testing.T) {
|
||||
|
||||
// Verify optional OP_RETURN with a valid discriminator but no vote.
|
||||
var ssgenInvalidTVNoVote = dcrutil.NewTx(ssgenMsgTxInvalidTV)
|
||||
ssgenInvalidTVNoVote.SetVersion(wire.TxVersionTreasury)
|
||||
ssgenInvalidTVNoVote.SetTree(wire.TxTreeStake)
|
||||
ssgenInvalidTVNoVote.SetIndex(0)
|
||||
|
||||
@ -761,6 +765,7 @@ func TestSSGenErrors(t *testing.T) {
|
||||
|
||||
// Verify optional OP_RETURN with a valid discriminator but a short vote.
|
||||
var ssgenInvalidTVNoVote2 = dcrutil.NewTx(ssgenMsgTxInvalidTV2)
|
||||
ssgenInvalidTVNoVote2.SetVersion(wire.TxVersionTreasury)
|
||||
ssgenInvalidTVNoVote2.SetTree(wire.TxTreeStake)
|
||||
ssgenInvalidTVNoVote2.SetIndex(0)
|
||||
|
||||
@ -776,6 +781,7 @@ func TestSSGenErrors(t *testing.T) {
|
||||
// Verify optional OP_RETURN with a valid discriminator one valid vote
|
||||
// and a short vote.
|
||||
var ssgenInvalidTVNoVote3 = dcrutil.NewTx(ssgenMsgTxInvalidTV3)
|
||||
ssgenInvalidTVNoVote3.SetVersion(wire.TxVersionTreasury)
|
||||
ssgenInvalidTVNoVote3.SetTree(wire.TxTreeStake)
|
||||
ssgenInvalidTVNoVote3.SetIndex(0)
|
||||
|
||||
@ -791,6 +797,7 @@ func TestSSGenErrors(t *testing.T) {
|
||||
// Verify optional OP_RETURN with a valid discriminator 7 valid votes
|
||||
// and a short vote.
|
||||
var ssgenInvalidTVNoVote4 = dcrutil.NewTx(ssgenMsgTxInvalidTV4)
|
||||
ssgenInvalidTVNoVote4.SetVersion(wire.TxVersionTreasury)
|
||||
ssgenInvalidTVNoVote4.SetTree(wire.TxTreeStake)
|
||||
ssgenInvalidTVNoVote4.SetIndex(0)
|
||||
|
||||
@ -806,6 +813,7 @@ func TestSSGenErrors(t *testing.T) {
|
||||
// Verify optional OP_RETURN with a valid discriminator 7 valid votes
|
||||
// but with an invalid OP_PUSHDATAX encoding..
|
||||
var ssgenInvalidTVNoVote5 = dcrutil.NewTx(ssgenMsgTxInvalidTV5)
|
||||
ssgenInvalidTVNoVote5.SetVersion(wire.TxVersionTreasury)
|
||||
ssgenInvalidTVNoVote5.SetTree(wire.TxTreeStake)
|
||||
ssgenInvalidTVNoVote5.SetIndex(0)
|
||||
|
||||
@ -820,6 +828,7 @@ func TestSSGenErrors(t *testing.T) {
|
||||
|
||||
// Verify invalid treasury vote bits (too many bits).
|
||||
var ssgenInvalidTVote = dcrutil.NewTx(ssgenMsgTxInvalidTVote)
|
||||
ssgenInvalidTVote.SetVersion(wire.TxVersionTreasury)
|
||||
ssgenInvalidTVote.SetTree(wire.TxTreeStake)
|
||||
ssgenInvalidTVote.SetIndex(0)
|
||||
|
||||
@ -834,6 +843,7 @@ func TestSSGenErrors(t *testing.T) {
|
||||
|
||||
// Verify invalid treasury vote bits (no bits).
|
||||
var ssgenInvalidTVote2 = dcrutil.NewTx(ssgenMsgTxInvalidTVote2)
|
||||
ssgenInvalidTVote2.SetVersion(wire.TxVersionTreasury)
|
||||
ssgenInvalidTVote2.SetTree(wire.TxTreeStake)
|
||||
ssgenInvalidTVote2.SetIndex(0)
|
||||
|
||||
@ -848,6 +858,7 @@ func TestSSGenErrors(t *testing.T) {
|
||||
|
||||
// Verify duplicate tspend hash.
|
||||
var ssgenInvalidTVote3 = dcrutil.NewTx(ssgenMsgTxInvalidTVote3)
|
||||
ssgenInvalidTVote3.SetVersion(wire.TxVersionTreasury)
|
||||
ssgenInvalidTVote3.SetTree(wire.TxTreeStake)
|
||||
ssgenInvalidTVote3.SetIndex(0)
|
||||
|
||||
|
||||
@ -1003,8 +1003,7 @@ func (b *BlockChain) tSpendCountVotes(prevNode *blockNode, tspend *dcrutil.Tx) (
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range xblock.STransactions() {
|
||||
votes, err := stake.CheckSSGenVotes(v.MsgTx(),
|
||||
yesTreasury)
|
||||
votes, err := stake.CheckSSGenVotes(v.MsgTx())
|
||||
if err != nil {
|
||||
// Not an SSGEN
|
||||
continue
|
||||
|
||||
@ -3741,7 +3741,7 @@ func TestTSpendVoteCountSynthetic(t *testing.T) {
|
||||
tspendHash: tspendHash,
|
||||
vote: 0x01, // Yes
|
||||
}})
|
||||
_, err = stake.CheckSSGenVotes(yesVote, yesTreasury)
|
||||
_, err = stake.CheckSSGenVotes(yesVote)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -3751,7 +3751,7 @@ func TestTSpendVoteCountSynthetic(t *testing.T) {
|
||||
tspendHash: tspendHash,
|
||||
vote: 0x02, // No
|
||||
}})
|
||||
_, err = stake.CheckSSGenVotes(noVote, yesTreasury)
|
||||
_, err = stake.CheckSSGenVotes(noVote)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -2487,7 +2487,7 @@ func checkTicketRedeemerCommitments(ticketHash *chainhash.Hash,
|
||||
// one from the length of TxOut slice.
|
||||
var extra int
|
||||
if isTreasuryEnabled {
|
||||
tvt, _ := stake.CheckSSGenVotes(msgTx, isTreasuryEnabled)
|
||||
tvt, _ := stake.CheckSSGenVotes(msgTx)
|
||||
if tvt != nil {
|
||||
extra = 1
|
||||
}
|
||||
@ -2717,7 +2717,7 @@ func checkVoteInputs(subsidyCache *standalone.SubsidyCache, tx *dcrutil.Tx,
|
||||
if isTreasuryEnabled {
|
||||
// If we have votes we need to subtract them from the next
|
||||
// check.
|
||||
tvt, _ := stake.CheckSSGenVotes(msgTx, isTreasuryEnabled)
|
||||
tvt, _ := stake.CheckSSGenVotes(msgTx)
|
||||
if tvt != nil {
|
||||
extra = 1
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user