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

staking: Add revocations #30

Merged
merged 8 commits into from
Jan 6, 2020
Merged

Conversation

JoeGruffins
Copy link
Member

closes #29

Add a button to enable revocation of all missed and expired tickets.

Use a lot of code from dcrwallet and dcrd to revoke tickets. It's still very rough so don't look too closely, but it's working.

There is one thing I would like @buck54321 to comment on, I get this message sometimes when revoking multiple tickets:
2019-12-20 10:58:42,411 account ERROR revokeTickets(389) error getting tx: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 139999400998656 and this is thread id 139999383426816.

I understand the general problem that it's a concurrency issue, but I'm not quite sure of the cause or the best way to handle it. Thanks!

@JoeGruffins JoeGruffins changed the title staking: Add revocations [WIP] staking: Add revocations Dec 20, 2019
@JoeGruffins
Copy link
Member Author

I really wish "draft" was the default.

Copy link
Member

@buck54321 buck54321 left a comment

Choose a reason for hiding this comment

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

This is looking good. I'll treat this as in draft until you remove WIP, but I left a couple comments for now.

The database concurrency error is annoying. You'll need to track down whatever query is causing it, and make sure to create a new connection. Note that if the db is used contextually, such as in DcrdataBlockchain.tx, a new connection is created by default.

The database issues will be smoothed out in the upcoming db work.

pydecred/dcrdata.py Outdated Show resolved Hide resolved
ui/screens.py Outdated
Comment on lines 1154 to 1162
revokeBtn = app.getButton(TINY, "Revoke")
revokeBtn.clicked.connect(self.revokeTickets)
votingWgt, _ = Q.makeSeries(Q.HORIZONTAL, agendaBtn, revokeBtn)
self.layout.addWidget(votingWgt)
Copy link
Member

Choose a reason for hiding this comment

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

Consider adding a QLabel that says "no tickets to revoke", then hiding the label and showing the button only after checking the revocation count on SYNC_SIGNAL.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hiding the button anyway. Do we need to show anything when there's nothing to revoke?

@JoeGruffins JoeGruffins force-pushed the revocations branch 3 times, most recently from 47cfe1a to 17185bf Compare December 24, 2019 12:40
@JoeGruffins JoeGruffins changed the title [WIP] staking: Add revocations staking: Add revocations Dec 24, 2019
@JoeGruffins
Copy link
Member Author

ok, let me have it

@buck54321 buck54321 mentioned this pull request Dec 24, 2019
Copy link
Member

@buck54321 buck54321 left a comment

Choose a reason for hiding this comment

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

Mostly just comments about raising exceptions and some typos. A couple substantive questions though.

Most of the functions you've translated didn't have explicit testing in dcrd, but one test you could implement is TestSignatures from dcrd/dcrec/secp256k1. Maybe take a peek around dcrd and see if there are others.

pydecred/txscript.py Outdated Show resolved Hide resolved
pydecred/account.py Outdated Show resolved Hide resolved
Comment on lines 457 to 460
else:
log.error("did not find redeem script for hash %s" % redeemHash)
errored = True
continue
Copy link
Member

Choose a reason for hiding this comment

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

Indentation is wrong here. I really thought black would have caught this.

Copy link
Member Author

@JoeGruffins JoeGruffins Dec 31, 2019

Choose a reason for hiding this comment

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

Raising an exception now. But not sure about the indentation.

Copy link
Member

Choose a reason for hiding this comment

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

Oh. I was reading that wrong. Indentation is correct.

Copy link
Member

Choose a reason for hiding this comment

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

You could do this cleanly in two lines

redeemScript = next((decodeBA(p.purchaseInfo.script) for p in self.stakePools if p.purchaseInfo.ticketAddress == redeemHash.string()), None)
assert redeemScript is not None

although that first line is a little tedious. for ... else is weird to see in the wild.

Copy link
Member Author

Choose a reason for hiding this comment

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

How's it look now?

pydecred/txscript.py Outdated Show resolved Hide resolved
pydecred/txscript.py Outdated Show resolved Hide resolved
pydecred/txscript.py Outdated Show resolved Hide resolved
pydecred/txscript.py Outdated Show resolved Hide resolved
pydecred/txscript.py Outdated Show resolved Hide resolved
pydecred/txscript.py Outdated Show resolved Hide resolved
ui/screens.py Show resolved Hide resolved
Add a button to enable revocation of all missed and expired tickets.
 - Add basic dcrdata revoke ticket test.
 - Add documentation.
 - Format with black.
 - Move txscript functions around.
Also add more parsing checks for signature. Raise more exceptions. Log
how many tickets revoked upon successful revocation.
@JoeGruffins
Copy link
Member Author

Still need to look into more tests.

@JoeGruffins
Copy link
Member Author

Added TestSignatures. Wasn't sure of the best place to put the test so just made a new file. Although it's in pydecred as part of txscript, perhaps it belongs in crypto?

@@ -0,0 +1,290 @@
from tinydecred.crypto.bytearray import ByteArray
from tinydecred.pydecred.txscript import Signature
Copy link
Member Author

Choose a reason for hiding this comment

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

Forgot the copyright thing

Copy link
Member

@buck54321 buck54321 left a comment

Choose a reason for hiding this comment

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

Looking good. A couple of last things.

Please either lower-case the voting button or upper-case the revoke button.

image

See dcrd's TestSignTxOutput for some tests that might be relevant. I've already started that test function, but it doesn't cover all of TD's capabilities anymore. Looks like I should have added some there back in #7 too.

pydecred/dcrdata.py Show resolved Hide resolved
@JoeGruffins
Copy link
Member Author

changed voting to lower case.

I add two tests to the sign tx output and started to add basic multisig but stopped when I realized we also need script-hash signing to test the same as dcrd.

Moar tests?

Add tests for signing txoutput. Not complete. Add ability to create
multisig scripts.
Copy link
Member

@buck54321 buck54321 left a comment

Choose a reason for hiding this comment

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

Looks great. Nice work, @JoeGruffins.

@buck54321 buck54321 merged commit b19f05b into decred:master Jan 6, 2020
JoeGruffins added a commit to JoeGruffins/tinydecred that referenced this pull request Jan 7, 2020
staking: Add revocations. 

Additional multi-sig script support.

Add signature test coverage.

UI: Add a button to enable revocation of all missed and expired tickets.
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.

staking: Add revocations
2 participants