Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject unvotable tickets. #93

Merged
merged 2 commits into from
Jun 3, 2020
Merged

Reject unvotable tickets. #93

merged 2 commits into from
Jun 3, 2020

Conversation

jholdstock
Copy link
Member

/payfee and /getaddress will now only accept tickets which are immature or live.

Closes #56

/payfee and /getaddress will now only accept tickets which are immature or live.

// CanTicketVote checks determines whether a ticket is able to vote at some
// point in the future by checking that it is currently either immature or live.
func (c *DcrdRPC) CanTicketVote(ticketHash string, netParams *chaincfg.Params) (bool, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davecgh could you give this function a once-over please?

rpc/dcrd.go Outdated
return false, err
}

// Tickets which older than (TicketMaturity+TicketExpiry) are too old to vote.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing are.

rpc/dcrd.go Outdated
}

// Tickets which older than (TicketMaturity+TicketExpiry) are too old to vote.
if rawTx.Confirmations > int64(uint32(netParams.TicketMaturity)+netParams.TicketExpiry) {
Copy link
Member

@davecgh davecgh Jun 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks off by one to me. Tickets don't become live until the block after they reach ticket maturity.

This can be seen by noticing that the first tickets were mined in block 257 and didn't become live until 257+256+1 = 514 by looking at the fact the pool size became nonzero at that point.

Then, those tickets would have expired 40960 blocks after the point they became live. Ergo, a ticket mined in block 257 that didn't get selected would expire in block 514+ 40960 = 41474, and as luck would have it for this example, one of those tickets actually did end up expiring and was revoked in the aforementioned block.

So, running the numbers with what it would look like at block 41473 (one block before expiration) would give:

Confirmations = 41473 - 257 (block it was mined in) + 1 (including the block it was mined in) = 41217.
TicketMaturity + TicketExpiry = 40960 + 256 = 41216

Then if 41217 > 41216 is true, which is incorrect, because it wouldn't expire until the next block.

@jholdstock
Copy link
Member Author

Thanks for explaining that Dave, I've added a +1 to accommodate.

@dajohi dajohi merged commit 4feed5e into decred:master Jun 3, 2020
@jholdstock jholdstock deleted the immature branch January 25, 2022 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure tickets are either immature or live
3 participants