Skip to content

Conversation

@iFoggz
Copy link
Member

@iFoggz iFoggz commented Sep 9, 2019

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:

  • Use a formula of (S - R) >= value for 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.
  • Added bool to SelectCoinsForStaking to determine if the miner is requesting the data
  • SelectCoinsForStaking can send back a false in return now under various conditions.

Removed:

  • No longer use nValueIn as it is unused
  • No longer push a target value to SelectCoinsForStaking. The number sent in always *2.

Changed:

  • No longer check for coin age in miner as this is already done in AvailableCoinsForStaking and miner was a second unneeded check.
  • Move check for no coins to SelectCoinsForStaking as a more appropriate location
  • Move check to see if a reserve balance consumed more then the amount of coins in wallet to SelectCoinsForStaking
  • Refactor the pairing of coin and value in SelectCoinsForStaking to remove unnecessary extra variable in set pair for setCoinsRet
  • Add logging to SelectCoinsForStaking when debug2 enabled and miner calling the function

TODO:

  • In Future change the coin utxos sent to miner to be in random order since the wallet in mapped (sorted) in cases where a utxo has a high txid say starting with 'f' it can reduce the chance of that one staking since so many others that could have similar weights but lower txid.
  • Modify GetStakeWeight to remove the age check of coins since AvailableCoinsForStaking already does this

I'm sure @denravonska and @jamescowens will request changes. i've tested this on testnet for 3 days under various conditions without issues.

…eserve.

Correct logging message to what the data actually shows.

updated
@jamescowens
Copy link
Member

jamescowens commented Sep 10, 2019

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.

Copy link
Member

@jamescowens jamescowens left a 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

@jamescowens jamescowens removed the request for review from denravonska September 15, 2019 17:09
Copy link
Member

@cyrossignol cyrossignol left a 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.

@iFoggz
Copy link
Member Author

iFoggz commented Sep 16, 2019

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.

Copy link
Member

@jamescowens jamescowens left a comment

Choose a reason for hiding this comment

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

Agreed.

@jamescowens
Copy link
Member

I think it is good. Running this on two of my testnet nodes along with @cyrossignol's SuperblockValidator class.

@jamescowens jamescowens changed the title Move some functionality from miner to SelectCoinsForStaking + Respect the coin reserve setting Move some functionality from miner to SelectCoinsForStaking + Respect the coin reserve setting + Randomize UTXO order Sep 16, 2019
@jamescowens
Copy link
Member

jamescowens commented Sep 17, 2019

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.

…false or vector coins is empty and returns false we return 0; even thou nWeight would technically already be zero
Copy link
Member

@cyrossignol cyrossignol left a 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())
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member Author

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;
}

Copy link
Member Author

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

Copy link
Member

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:

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.

Copy link
Member Author

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

Copy link
Member

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 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

thank you.

@iFoggz iFoggz force-pushed the ChangeMinerBehaviour branch from 5f24441 to a0a58fb Compare September 17, 2019 21:45
@jamescowens jamescowens merged commit 89938c7 into gridcoin-community:development Sep 18, 2019
jamescowens added a commit that referenced this pull request Oct 22, 2019
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)
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.

3 participants