-
Notifications
You must be signed in to change notification settings - Fork 184
Move some functionality from miner to SelectCoinsForStaking + Respect the coin reserve setting + Randomize UTXO order #1525
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
Move some functionality from miner to SelectCoinsForStaking + Respect the coin reserve setting + Randomize UTXO order #1525
Conversation
…eserve. Correct logging message to what the data actually shows. updated
|
Very happy to see these optimizations. This by itself is leisure, because the selection of UTXO's to stake is a local node issue as long as they are validly spendable. I think it, along with the succeeding randomizer should go in Fern. |
jamescowens
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.
See comments for consideration
cyrossignol
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.
Looks good so far! To reduce confusion, we may also want to update the help text for the -reservebalance option, reservebalance RPC, and "Reserve" field in the UI under Settings -> Options... to make it clear for someone with only a few, large UTXOs that a reserve setting that appears reasonable may actually disqualify most of their coins from staking. For example, if I buy 50k GRC three times (150k) and set a reserve of 50%, I can only stake 50k each time. It makes sense, but it might confuse unfamiliar users.
|
i believe reserve balance help should be updated. this allows all utxos to stake still unless there is only enough balance left to cover reserve. |
jamescowens
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.
Agreed.
…ctCoinsForStaking to have miner report the error to MinerStatus
… instead of being ordered with set by txid
|
I think it is good. Running this on two of my testnet nodes along with @cyrossignol's SuperblockValidator class. |
|
Tests well for me on testnet. Changed reserve setting in the UI on the fly and the coinweight and tooltip changed correctly. When reserve set very high, coinweight went down to the correct total of the few eligible UTXO's. When reserve set >= balance, tootip correctly shows not staking, entire balance reserved. CPU use looks low and my testnet Windows wallet has several hundred UTXO's. |
This reverts commit 516d986.
…false or vector coins is empty and returns false we return 0; even thou nWeight would technically already be zero
cyrossignol
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.
Looks good!
src/wallet.cpp
Outdated
| return false; | ||
|
|
||
| if (setCoins.empty()) | ||
| if (vCoins.empty()) |
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.
Minor stuff: we can remove this check now that SelectCoinsForStaking() returns false when it finds no UTXOs.
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.
yes we can its only a few extra cycles anyway
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.
perhaps i should check if either are empty and send back the appropriate reason?
if (vCoinsRet.empty())
{
if (fMiner)
sError = vCoins.empty() ? _("No mature coins") : _("No utxos available due to reserve balance");
return false;
}
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.
lmk i think that would be better instead of no mature coins sending back no utxos available due to reserve
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.
This vCoins in GetStakeWeight() is different from the one in SelectCoinsForStaking(). I don't think you need to do that because you're already returning false and setting the reason for vCoins.empty() above this:
Gridcoin-Research/src/wallet.cpp
Lines 1531 to 1537 in 5f24441
| if (vCoins.empty()) | |
| { | |
| if (fMiner) | |
| sError = _("No mature coins"); | |
| return false; | |
| } |
That will happen before the function filters the UTXOs, so we should get the right message for both cases as you already wrote it.
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.
oh ya so i'll put it back to way it was and remove that check in GetStakeWeight then, correct
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.
Yep, that should do it. I think this is finished 🙂
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.
thank you.
5f24441 to
a0a58fb
Compare
Added - Add testnet desktop launcher action for Linux #1516 (@caraka) - Shuffle vSideStakeAlloc if necessary to support sidestaking to more than 6 destinations #1532 (@jamescowens) - New Superblock format preparations for Fern #1526, #1542 (@jamescowens, @cyrossignol) - Multisigtools - Consolidate multisig unspent #1529 (@iFoggz) - Scanforunspent #1547 (@iFoggz) - consolidatemsunspent and scanforunspent bug fix #1561 (@iFoggz) - New banning misbehavior handling and Peers Tab on Debug Console #1537 (@jamescowens) - Reimplement getunconfirmedbalance rpc #1548 (@jamescowens) - Add CLI switch to display binary version #1553 (@cyrossignol) Changed - Select smallest coins for contracts #1519 (@iFoggz) - Move some functionality from miner to SelectCoinsForStaking + Respect the coin reserve setting + Randomize UTXO order #1525 (@iFoggz) - For voting - if url does not contain http then add it #1531 (@iFoggz) - Backport newer serialization facilities from Bitcoin #1535 (@cyrossignol) - Refactor ThreadSocketHandler2() Inactivity checks #1538 (@iFoggz) - Update outdated checkpoints #1539 (@barton2526) - Change needed to build Gridcoin for OSX using homebrew #1540 (@Git-Jiro) - Optimize scraper traffic for expiring manifests #1542 (@jamescowens) - Move legacy neural vote warnings to debug log level #1560 (@cyrossignol) - Change banlist save interval to 5 minutes #1564 (@jamescowens) - Change default rpcconsole.ui window size to better support new Peers tab #1566 (@jamescowens) Removed - Remove deprecated RSA weight and legacy kernel #1507 (@cyrossignol) Fixed - Clean up compiler warnings #1521 (@cyrossignol) - Handle missing external CPID in client_state.xml #1530 (@cyrossignol) - Support boost 1.70+ #1533 (@iFoggz) - Fix diagnostics failed to make connection to NTP server #1545 (@Git-Jiro) - Install manpages in correct system location #1546 (@Git-Jiro) - Fix ability to show help and version without a config file #1553 (@cyrossignol) - Refactor QT UI variable names to be more consistent, Fix Difficulty default #1563 (@barton2526) - Fix two regressions in previous UI refactor #1565 (@barton2526) - Fix "Owed" amount in output of "magnitude" RPC method #1569 (@cyrossignol)
Currently there is not guaranteed way to respect a reserve coin setting. After some discussion with jim and jims formula we have made a way that the reserve coin setting will be respected in all cases.
Added:
(S - R) >= valuefor determining if a utxo can stake based on the base and the reserve amount set. This is(Spendable - Reserve) >= utxo value. This also allows all utxos to still stake when the conditions are met.SelectCoinsForStakingto determine if the miner is requesting the dataSelectCoinsForStakingcan send back a false in return now under various conditions.Removed:
nValueInas it is unusedSelectCoinsForStaking. The number sent in always *2.Changed:
AvailableCoinsForStakingand miner was a second unneeded check.SelectCoinsForStakingas a more appropriate locationSelectCoinsForStakingSelectCoinsForStakingto remove unnecessary extra variable in set pair forsetCoinsRetSelectCoinsForStakingwhen debug2 enabled and miner calling the functionTODO:
GetStakeWeightto remove the age check of coins sinceAvailableCoinsForStakingalready does thisI'm sure @denravonska and @jamescowens will request changes. i've tested this on testnet for 3 days under various conditions without issues.