Skip to content

Conversation

@random-zebra
Copy link

@random-zebra random-zebra commented Jan 15, 2020

  • 1st commit removes zPIV balance count in CWallet::MintableCoins() (as mints cannot stake anymore).

  • 2nd commit removes GetStakingBalance calls in BitcoinMiner and getstakingstatus RPC (thus removing "enoughcoins", leaving only "mintablecoins" field there).
    MintableCoins() already checks the staking balance and returns false if it is either non-positive or less than the reserve balance.

  • 3rd commit removes the depth requirement check from MintableCoins, moving it directly in AvailableCoins (no need to check for age anymore, only depth).

  • 4th commit introduces a performance improvement (which might be significative on wallets with many utxos). Since the only purpose of MintableCoins is to verify that there is at least one eligible utxo, there is no need to get the whole set of them from AvailableCoins.
    And since this function is checked often when staking (AvailableCoins is called again from within CreateCoinStake) it's better to introduce a way to outright return from it, as soon as a valid utxo is found. This commit also removes the extra LOCK(cs_main) in the function.

  • 5th commit reworks MintableCoins/AvailableCoins/CreateCoinStake to remove SelectStakeCoins and avoid duplicated code in yet another place.

  • 6th commit finally renames MintableCoins --> StakeableCoins to avoid possible confusion.

zPIV are not stakeable anymore. They shouldn't be counted here.
MintableCoins() already gets the staking balance and checks it against
the reserve balance. No need to do it twice.
This affects both BitcoinMiner and getstakingstatus RPC.
There is no need to return the whole set of stakeable utxos when we want
to check only if there is at least one.

Also remove extra LOCK(cs_main) in MintableCoins.
GetStakingBalance and AvailableCoins already take care of the lock.
@random-zebra random-zebra changed the title [Wallet] Cleanup mintable coins in staking status [Wallet] Refactor MintableCoins Jan 16, 2020
@random-zebra random-zebra force-pushed the 2020_wallet_mintableCoins branch 3 times, most recently from 719f299 to 64848d1 Compare January 16, 2020 18:30
@furszy
Copy link

furszy commented Jan 16, 2020

This is looking quite nice 👌

Use MintableCoins instead of SelectStakeCoins to avoid duplicated code
in yet another function, and remove extra checks in CreateCoinStake.

MintableCoins first argument is now a pointer defaulted to nullptr. When
the function is called with this default value, it checks for the
existence of *at least one* stakeable utxo. Otherwise populates the
vector referenced by the pointer with *all* stakeable utxos.
@random-zebra random-zebra force-pushed the 2020_wallet_mintableCoins branch from 64848d1 to 7431f09 Compare January 16, 2020 20:26
@random-zebra
Copy link
Author

This is ready for review. Been successfully (hot and cold) staking in main net and testnet with it.
The failing functional test is fixed in #1278 .

@Fuzzbawls Fuzzbawls added this to the 4.1.0 milestone Jan 18, 2020
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.

Great cleanup and working well

ACK 562892c

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 562892c

furszy added a commit that referenced this pull request Jan 19, 2020
562892c [Trivial] Rename MintableCoins() --> StakeableCoins() (random-zebra)
7431f09 [Wallet][Cleanup] Remove SelectStakeCoins (random-zebra)
33c3973 [Wallet] Faster lookup for MintableCoins (random-zebra)
bc6ae73 [Wallet] Check min depth requirement for stake inputs in AvailableCoins (random-zebra)
016a60e [Wallet][RPC] Remove GetStakingBalance calls to get staking status (random-zebra)
cf5f2d2 [Cleanup][Wallet] Don't count zPIV in MintableCoins() (random-zebra)

Pull request description:

  - 1st commit removes zPIV balance count in `CWallet::MintableCoins()` (as mints cannot stake anymore).

  - 2nd commit removes `GetStakingBalance` calls in BitcoinMiner and `getstakingstatus` RPC (thus removing "enoughcoins", leaving only "mintablecoins" field there).
  `MintableCoins()` already checks the staking balance and returns false if it is either non-positive or less than the reserve balance.

  - 3rd commit removes the depth requirement check from `MintableCoins`, moving it directly in `AvailableCoins` (no need to check for age anymore, only depth).

  - 4th commit introduces a performance improvement (which might be significative on wallets with many utxos). Since the only purpose of `MintableCoins` is to verify that there is *at least one* eligible utxo, there is no need to get the whole set of them from `AvailableCoins`.
  And since this function is checked often when staking (`AvailableCoins` is called again from within `CreateCoinStake`) it's better to introduce a way to outright return from it, as soon as a valid utxo is found. This commit also removes the extra `LOCK(cs_main)` in the function.

  - 5th commit reworks MintableCoins/AvailableCoins/CreateCoinStake to remove `SelectStakeCoins` and avoid duplicated code in yet another place.

  - 6th commit finally renames `MintableCoins` --> `StakeableCoins` to avoid possible confusion.

ACKs for top commit:
  Fuzzbawls:
    ACK 562892c
  furszy:
    ACK 562892c

Tree-SHA512: 80878f09973e841ac13da46766a08191d066f6298d0ef9d55a6ecfa9013125f73f85f61d8e0b469c5b7373a764e72e5187406fdea54ca1eaff84d762ae337146
@furszy furszy merged commit 562892c into PIVX-Project:master Jan 19, 2020
furszy added a commit that referenced this pull request Jan 21, 2020
7a8d755 [Tests] Remove '-staking' from extra-args (random-zebra)
72d5a31 [Tests] Fix/Update mining_pos_coldstaking test (random-zebra)
5ffa6b5 [Trivial] Rename mintablecoins --> stakeablecoins (random-zebra)
e781cd0 [Cleanup] zPIV Don't validate Accumulator Checkpoints anymore (random-zebra)
5b192e0 [Tests][Bug] Fix staking status in generate_pos() (random-zebra)

Pull request description:

  This is based on top of #1276 and #1277 which should be reviewed before.
  `generate_pos` framework function relies on the output of `getstakingstatus` RPC which was recently changed.
  Since #1245, "validtime" is not returned anymore (nor it was ever really needed here).
  Only things that we need in `generate_pos` are "walletunlocked" and "mintablecoins" (renamed "stakeablecoins").
  "enoughcoins" is going to be removed in #1277 , and "haveconnections" is not required on regtest.
  This also updates coldstaking test.

ACKs for top commit:
  Fuzzbawls:
    ACK 7a8d755
  furszy:
    ACK 7a8d755

Tree-SHA512: 0f45d8b3880d8d88258861fc85c04e0c62a834cede8991e1370afcaef05a2fb714a4441e201d0bdfd89251628e92aa51496182b8088917a8f3a9b740a21272f6
furszy added a commit that referenced this pull request Jan 26, 2020
799e3ad [Tests] Fix block version on RegTest (random-zebra)
00aae54 [Core][Cleanup] PoS: remove extra signature + IncrementExtraNonce (random-zebra)
389094f [Core] Remove StakeV1 in kernel and miner (random-zebra)

Pull request description:

  This removes the old StakeV1 function and does some minor optimizations in the miner code (removing redundant signature and IncrementExtraNonce calls).

  This is based on top of the following three pull requests and will be rebased after their merge into master.
  So, they should be reviewed before this one.
  - [x] #1276
  - [x] #1277
  - [x] #1278

ACKs for top commit:
  furszy:
    Staking working properly, ACK 799e3ad
  Fuzzbawls:
    ACK 799e3ad

Tree-SHA512: a3cde86fc3a7cdad39d8d322dbcc0da1e34d044c4f320700605a9952e67788c825b53516e5ff452e37cde127aaf902416168dc6384fe62954d336efe7aea23eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Block Generation Mining/Staking related issues Cleanup RPC Wallet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants