-
Notifications
You must be signed in to change notification settings - Fork 725
[Wallet] Refactor MintableCoins #1277
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
[Wallet] Refactor MintableCoins #1277
Conversation
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.
719f299 to
64848d1
Compare
|
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.
64848d1 to
7431f09
Compare
|
This is ready for review. Been successfully (hot and cold) staking in main net and testnet with it. |
Fuzzbawls
left a comment
There was a problem hiding this 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
furszy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 562892c
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
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
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
1st commit removes zPIV balance count in
CWallet::MintableCoins()(as mints cannot stake anymore).2nd commit removes
GetStakingBalancecalls in BitcoinMiner andgetstakingstatusRPC (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 inAvailableCoins(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
MintableCoinsis to verify that there is at least one eligible utxo, there is no need to get the whole set of them fromAvailableCoins.And since this function is checked often when staking (
AvailableCoinsis called again from withinCreateCoinStake) 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 extraLOCK(cs_main)in the function.5th commit reworks MintableCoins/AvailableCoins/CreateCoinStake to remove
SelectStakeCoinsand avoid duplicated code in yet another place.6th commit finally renames
MintableCoins-->StakeableCoinsto avoid possible confusion.