Skip to content
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

Voting bot for stake off #2327

Merged
merged 66 commits into from
Jan 20, 2020
Merged

Voting bot for stake off #2327

merged 66 commits into from
Jan 20, 2020

Conversation

yerdua
Copy link
Contributor

@yerdua yerdua commented Dec 20, 2019

Description

This implements a voting bot, that runs roughly once an epoch and votes on validator groups. For each voting bot account, it does this process:

  1. activates any pending votes (votes cast in the previous epoch)
  2. randomly selects which of the voting bots are participating in the current round
  3. For each bot, it decides based on the performance of the group they're currently voting for (if any), if they should change their vote, or keep it as is.
  4. For each bot that is changing its vote, it chooses which strategy to use to pick a group to vote for: a) weighted-random based on scores of currently-elected validators, b) unweighted-random selection of an unelected group
  5. It uses the strategy chosen in step 4 to pick a new group
  6. Revokes old vote
  7. Casts a vote for that new group

Tested

I ran the following celotool command, pointed at baklava staging, and confirmed that voting occurred.
celotool bots auto-vote --celoProvider https://baklavastaging-forno.celo-testnet.org

I confirmed that the cronjob gets deployed and then voting happens on schedule with this command:
celotool deploy initial voting-bot -e baklavastaging

Other changes

fixed a typo or two

Related issues

yerdua added 27 commits December 5, 2019 17:50
…le value. set it to 1 for baklava"

This reverts commit 3beee57.
@yerdua yerdua assigned nambrot and unassigned yerdua Jan 15, 2020
Copy link
Contributor

@jfoutts-celo jfoutts-celo left a comment

Choose a reason for hiding this comment

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

It would be nice to observe how the bots would vote on Baklava before turning them loose.

Should we start them with a small amount of gold and analyze their actions before giving them more?

const validators = await kit.contracts.getValidators()

const validatorSigners = await election.getCurrentValidatorSigners()
const validatorAccounts = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use validators.getRegisteredValidators() here? Do we want to include previously elected (but currently unelected) validators?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I understand it, the only validators that have a score are ones that are currently elected. If I am mistaken about that, then sure, this can be changed. This function could probably remain intact otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that when incumbent validators lose election, their validator score remains whatever it was for the last epoch they were elected.

celocli validator:list | grep 0\\. | wc -l
Fetching Validators... done
     120

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, you're right. They seem to preserve the score from when they were last elected.

However, that, in itself, does not lead to a decision on what should happen with this line of code.

# Number of gold-holding bots that vote for validator groups
VOTING_BOTS=100
# 10,000 CG
VOTING_BOT_BALANCE=10000000000000000000000
Copy link
Contributor

Choose a reason for hiding this comment

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

With only 10k Celo Gold, will the bots have enough impact?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what @timmoreton suggested. At this amount, each bot has slightly less than each validator. (Each validator gets 12k, and each group gets 12k).

Tim - what was your rationale for that amount? Is this still in line with the level of impact we want each bot to have?

I think it's fine to have this as a starting point. We can adjust if we want more impact - either by adding more bots, or giving each bot more gold. Given the current setup function, adding more bot accounts is a bit easier than increasing the locked gold for existing ones.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, right. I think I forgot that essentially all the validator groups would be tied.


// Handle the case where the group the bot is currently voting for does not have a score
if (
!currentGroup ||
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm concerned the bots first votes could decimate the incumbency. (At least if they're run with enough gold, say 25k. Otherwise I'm concerned there will be little impact.)

To avoid maybe:

  • Run bots once with VOTING_BOT_EXPLORE_PROBABILITY=0, long enough that all of the bots are voting for the incumbency.
  • Restart bots with VOTING_BOT_EXPLORE_PROBABILITY=1, so that any displacement of incumbency is based on score.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That could work. I'm not sure setting VOTING_BOT_EXPLORE_PROBABILITY=1 is the best idea. I think having some bots voting based on good performance is useful. Maybe like.... 0.8?

Copy link
Contributor

@jfoutts-celo jfoutts-celo left a comment

Choose a reason for hiding this comment

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

Code LGTM!

@yerdua yerdua merged commit 8e26ae0 into master Jan 20, 2020
@yerdua yerdua deleted the yerdua/stake-off-voting-bot branch January 20, 2020 17:23
aaronmgdr added a commit that referenced this pull request Jan 21, 2020
* master: (25 commits)
  Add react-testing-utils + Fix Analytics (#2437)
  collect coverage on web (#2415)
  Add callouts to serve text messages in regions (#2458)
  [Wallet] Historical currency conversions in the transaction feed (#2446)
  CLI relock fix (#2464)
  Update copyright year + inline button  (#2468)
  Voting bot for stake off (#2327)
  Change order of profile info (#2454)
  [Wallet] Fix type check regression for components wrapped by our custom `withTranslation` (#2457)
  Unfreeze rewards by default (#2452)
  Baklava and baklavastaging deploys (#2421)
  Fix coin colors  (#2441)
  Make governance CLI more usable (#2428)
  Slashing params for stake off phase 2 (#2418)
  [Wallet] Rollback zeroSync toggle in case it was not successful (#2434)
  [Wallet] Cleanup unused StateProps references (#2439)
  Add unit tests and cli checks for validator hotfix interaction (#2340)
  Add proper Spanish translations (#2427)
  Catch exceptions during polling (#2432)
  Add unfreeze-contracts command to celotool (#2433)
  ...

# Conflicts:
#	packages/web/src/brandkit/common/MobileMenu.test.tsx
#	yarn.lock
aaronmgdr added a commit that referenced this pull request Jan 21, 2020
* master:
  Add react-testing-utils + Fix Analytics (#2437)
  collect coverage on web (#2415)
  Add callouts to serve text messages in regions (#2458)
  [Wallet] Historical currency conversions in the transaction feed (#2446)
  CLI relock fix (#2464)
  Update copyright year + inline button  (#2468)
  Voting bot for stake off (#2327)
  Change order of profile info (#2454)
  [Wallet] Fix type check regression for components wrapped by our custom `withTranslation` (#2457)
  Unfreeze rewards by default (#2452)

# Conflicts:
#	packages/web/src/analytics/analytics.test.ts
#	packages/web/src/brandkit/common/MobileMenu.test.tsx
#	yarn.lock
aaronmgdr added a commit that referenced this pull request Jan 22, 2020
* master:
  add celo.org/about#contributors id (#2488)
  [Wallet] Fix integration build firebase db url on Android (#2495)
  Fixes governance CLI bugs encountered while running election contract upgrade (#2482)
  Add validator:signed-blocks command and fix validator:status bug (#2456)
  Bump @celo/celocli version to 0.0.34 (#2420)
  Fix Logo + backers number change (#2453)
  Improve election efficiency by short circuiting (#2475)
  Page for Experience / BrandKit / Composition (#2462)
  Configure the time to wait for text messages (#2450)
  Add react-testing-utils + Fix Analytics (#2437)
  collect coverage on web (#2415)
  Add callouts to serve text messages in regions (#2458)
  [Wallet] Historical currency conversions in the transaction feed (#2446)
  CLI relock fix (#2464)
  Update copyright year + inline button  (#2468)
  Voting bot for stake off (#2327)
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.

Voting bot for stake off
4 participants