Skip to content

[Core][Script][Wallet][RPC][Tests] Cold Staking#955

Merged
furszy merged 59 commits intoPIVX-Project:masterfrom
random-zebra:2019_coldStaking
Oct 23, 2019
Merged

[Core][Script][Wallet][RPC][Tests] Cold Staking#955
furszy merged 59 commits intoPIVX-Project:masterfrom
random-zebra:2019_coldStaking

Conversation

@random-zebra
Copy link

@random-zebra random-zebra commented Jul 18, 2019

Implements the "Cold Staking" system described in https://github.com/random-zebra/PIVX-Wiki/blob/master/Developer-Documentation/Specs/ColdStaking.mediawiki.

Closes #579.

The current changeset does not include any edit to the GUI, as it is being redesigned for v4.0.0 (#954).
The controls for cold staking will be added to the new interface in a separate PR if this upgrade is approved.

Enforcement activation height uses placeholder values for now.

Notable changes:

  • [Core]

    • Definition of the new type of address STAKING_ADDRESS.
    • Definition of a new standard transaction type TX_COLDSTAKE.
    • Block signature/validation change: sign blocks with the staker private key, verify the signature extracting the public key from the coinstake input.
    • Addition of CheckColdStake function, called by CheckTransaction, to check for the rules not verified by the script evaluation (equivalence of input and output scripts).
    • Addition of -coldstaking startup flag to disable cold staking while keeping hot staking enabled (if -staking=1). If -staking=0 then -coldstaking is automatically set to 0 too.
    • Definition of placeholders for the activation block height: 2880000 for main net, 2106100for test net, 251 for reg test.
    • Definition of threshold value for cold staking outputs
  • [Script]

    • Definition of a new opcode OP_CHECKCOLDSTAKEVERIFY
    • Definition of the output script P2CS
    • Definition of a fast test to recognize P2CS scripts by checking only few bytes.
    • Definition of the input scriptSig to spend P2CS scriptPubKey outputs
    • Addition of a boolean argument fColdStake to ExtractDestination to extract proper keyID from P2CS scripts.
  • [Wallet]

    • Introduction of new ismine types to recognize cold staking txes: ISMINE_COLD, ISMINE_SPENDABLE_DELEGATED.
    • Introduction of the concepts of "delegated" and "cold" balance (debit and credit)
    • Addition of a new boolean flag fStakeDelegationVoided to walletTx when voiding stake delegations.
    • Addition of 2 new boolean optional arguments to AvailableCoins to include cold and/or delegated coins in the selection.
    • Inclusion of delegated coins in SelectStakeCoins for cold staking.
    • Addition of the delegator whitelisting check in AvailableCoins.
  • [RPC]

    • Addition of an option to include delegated balance in getbalance, senfrom, sendmany and listtransactions.
    • Definition of new method getnewstakingaddress to generate a new staking address.
    • Definition of new method delegatestake to send a stake delegation transaction
    • Definition of new method delegatestakeraw to create a raw stake delegation transaction without sending it
    • Prevent the use of staking addresses as recipients in sendtoaddress.
    • Definition of new method getcoldstakingbalance to retrieve the cold balance of the wallet.
    • Addition of cold_staking_balance and delegated_balance to getwalletinfo/getinfo.
    • signrawtransaction: for P2CS, select the key used to sign based on what is found in the keystore. If the wallet has both keys, sign with the owner key.
    • Definition of new method delegatoradd to whitelist an owner address for cold staking.
    • Definition of new method delegatorremove to un-do the effect of delegatoradd.
    • Definition of new function listcoldutxos to show p2cs utxos belonging to the wallet (either as owner or staker).
    • Definition of new function liststakingaddresses to show the staking addresses generated by the wallet.
    • Definition of new function liststdelegators to show the delegator (owner) addresses whitelisted by the (cold) wallet.
  • [Tests]

    • Creation of the new feature_coldStaking.py functional test and addition of it to the test-runner.
  • [Misc/Clenup]

    • Remove extra declaration of EnsureWalletIsUnlocked in rpcdump.cpp
    • REGTEST: lower the confirmations to 15 (same as testnet) and fix the stakeModifier.

@random-zebra random-zebra force-pushed the 2019_coldStaking branch 2 times, most recently from 5fde942 to 2b3a4a4 Compare July 18, 2019 14:09
@random-zebra random-zebra changed the title [Core][Script][Wallet][RPC][Tests] Cold Staking [WIP] [Core][Script][Wallet][RPC][Tests] Cold Staking Jul 18, 2019
@giaki3003
Copy link

This looks great actually, good job @random-zebra
Just one thing about the name, this seems more like DPoS than actual Cold Staking to me, maybe the name can cause confusion later on? Just a quick thought

@random-zebra
Copy link
Author

@giaki3003 I think that it would cause more confusion, as "Cold" staking is a rather loose term, used for many forms of "proxied" or "offline" staking already, while DPoS is a specific consensus algorithm (which is not what we have here).

Anyway, that's open for debate. Feel free to add your opinion here, if you want: https://forum.pivx.org/index.php?threads/pivx-cold-staking.324/

@random-zebra random-zebra changed the title [WIP] [Core][Script][Wallet][RPC][Tests] Cold Staking [Core][Script][Wallet][RPC][Tests] Cold Staking Jul 19, 2019
@random-zebra random-zebra self-assigned this Jul 19, 2019
@giaki3003
Copy link

@random-zebra nothing major, just a thought since this reminds me of the similar delegated staking other PoS coins have, which they usually call TPoS/DPoS. Probably would only add extra confusion

@Warrows Warrows self-requested a review July 21, 2019 21:21
@random-zebra random-zebra added this to the 4.0.0 milestone Jul 25, 2019
@Fuzzbawls
Copy link
Collaborator

Needs Rebase

@random-zebra
Copy link
Author

rebased

@random-zebra random-zebra force-pushed the 2019_coldStaking branch 3 times, most recently from 48877c5 to 4ac877d Compare July 30, 2019 00:23
random-zebra and others added 9 commits October 23, 2019 02:35
…method.

[Wallet][Refactor] Inline getDebit/getCredit if else in updateAmount method.
to verify that the last output of cold stakes has the correct amount
regardless of the payee (which is checked in IsBlockPayeeValid).
This prevents possible abuse when SPORK_8 and/or SPORK_9-SPORK_13 are
disabled).

Also adjust/cleanup feature_coldStaking functional test
Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

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

ACK e498a06

Copy link

@furszy furszy left a comment

Choose a reason for hiding this comment

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

ACK e498a06

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: risk-free, proxy staking

5 participants