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

Merit Based Sortition / Permeability of Inferer, Forecaster, Reputer Active Set #548

Closed
wants to merge 79 commits into from

Conversation

relyt29
Copy link
Contributor

@relyt29 relyt29 commented Aug 26, 2024

Purpose of Changes and their Description

Due to the scaling constraints of running a blockchain, we can't process all of the inferences, forecasts, and reputation bundles given to us for rewards.

At the time of payload acceptance (both worker and reputer), we only accept up to MaxTopXToReward inferences, forecasts, and reputations to process and store on chain. We use a skimming the top algorithm: we accept everything up until we hit the max amount permissible, and then any subsequent payloads replace the payload of the actor with the lowest Exponential Moving Average (EMA) score in the existing set we have already accepted. We do not filter at this point who is allowed to submit payloads other than only "top N by score" accepted.

We also avoid caculating EMA scores for every actor. Because the calculation of scores requires complete knowledge of the network loss for the epoch, EMA score calculation happens at time of reputer nonce closure (in endblock), upon the final set of payloads submitted at that point.

We order EMA scores into "active" and "passive" sets of inferers, forecasters, and reputers using score EMAs and quantiles. FindTopNByScoreDesc sorts the set of actors based on their scores (roughly, their distance from the combined network loss) and only keeps the moduleParams.MaxTopXToReward actors (where X is one of inferers, forecasters, or reputers). In order to smooth out the effect of any particular epoch in the scores of actors, we use Exponential Moving Averages of scores with a new alpha parameter moduleParams.MeritSortitionAlpha - this replaces the latest scores data structures in the keeper, so latestXScoresByX becomes xScoreEma in the keeper.

In order to allow for permeability in the active set, i.e. to allow new players without established reputation to get a chance to upload payloads, we take the topic.ActiveXQuantile quantile of all the scores (e.g. the 20th percentile), and assign everyone in the passive set the quantile score as their score. This introduces churn in the bottom quantile of the active set, allowing players without established reputation to break into the active set and submit payloads if they are decently good.

Bullet point list of changes follows:

  • Added new fields to the Topic struct for active quantiles: topics now include active_inferer/forecaster/reputer_quantile parameter between 0 and 1 for permeability.
  • Introduced a merit sortition alpha parameter for weighting previous score EMAs:
  • Refactored the FindTopNByScoreDesc function to not rely on a heap data structure
  • Moved score calculation logic into the actor_utils package and updated the rewards system to get score EMAs from the keeper at time of rewards, rather than calculate scores at time of rewards.
  • Renamed util_sort to sortition to better reflect its purpose.
  • Moved validations from the types package into the msg server where they are performed.
  • Changed the behavior of worker and reputer payload submissions to no longer filter them at the time of submission. Instead, active set management for inferers, forecasters, and reputers is now done at the time of reputer nonce closure.
  • Updated proto files to reflect changes in score querying, renaming endpoints from "LatestScore" to "ScoreEma":
  • Moved IsBetweenZeroAndOneExclusive function into the math package for broader use.
  • Moved types/msg_create_topic.go into the msg_server package.
  • Renames the query server tests from KeeperTestSuite to QueryServerTestSuite

Reviewers: The most important changes to focus on in this PR occur in:

  • x/emissions/keeper/actor_utils/losses.go
  • x/emissions/keeper/msgserver/msg_server_worker_payload.go
  • x/emissions/keeper/msgserver/msg_server_reputer_payload.go

Link(s) to Ticket(s) or Issue(s) resolved by this PR

PROTO-2204, PROTO-1813, RES-297

This is built upon / replaces #421

Are these changes tested and documented?

  • Implemented and tested quantile calculations, including CSV-based simulation matching testing.
  • Updated keeper tests and added new tests for quantile calculations and score EMAs.

In progress:

  • If tested, please describe how. If not, why tests are not needed.
  • If documented, please describe where. If not, describe why docs are not needed.
  • Added to Unreleased section of CHANGELOG.md?

Still Left Todo

  • Fix failing CI
  • Tests
    • Existing Unit tests to pass
    • New Unit tests to cover new functionality
    • integration tests
  • Migrations for upgrade
  • Changelog.txt to be updated
  • address the todos littered in the PR comments (BAD!)

kpeluso and others added 30 commits August 20, 2024 15:28
…e-hard-actor-limit-permeable-by-updating-emas-of
…he-hard-actor-limit-permeable-by-updating-emas-of
…e-hard-actor-limit-permeable-by-updating-emas-of
relyt29 and others added 21 commits August 28, 2024 15:23
…Inference.Inferer and msg.Sender == MsgInsertWorkerPayload.WorkerDataBundle.Forecast.Forecaster
…-based-sortition' into tyler/proto-2204-implement-merit-based-sortition
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
v           ✰  Thanks for creating a PR! You're awesome! ✰
v Please note that maintainers will only review those PRs with a
completed PR template.
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >  -->

## Purpose of Changes and their Description

* Add migration to migrate topics to new v3 emissions structure
* Add migration handler that also clears out any data that may have been
witnessed NaNs due to insufficient validation bug (already addressed in
`dev` branch.

## Link(s) to Ticket(s) or Issue(s) resolved by this PR

## Are these changes tested and documented?

- [x] If tested, please describe how. If not, why tests are not needed.
   - Unit tests provided
- [ ] If documented, please describe where. If not, describe why docs
are not needed.
- [ ] Added to `Unreleased` section of `CHANGELOG.md`?

## Still Left Todo

Still need to move new global param to inside the topic + cascade change
to migration + throughout.
…thub:allora-network/allora-chain into tyler/proto-2204-implement-merit-based-sortition
…s on task reward alpha failing test"

This reverts commit 75df6b5.
@relyt29
Copy link
Contributor Author

relyt29 commented Aug 30, 2024

closing in favor of #556

@relyt29 relyt29 closed this Aug 30, 2024
kpeluso added a commit that referenced this pull request Aug 30, 2024
…er/Reputer inside Bundle (#554)

## Purpose of Changes and their Description

This PR prevents an attack where someone uploading a WorkerPayload or
ReputerPayload could upload a payload that has a valid signature upon a
bundle, but the inferer, forecaster, or reputer listed as responsible
for the data of the bundle, was not actually the person who signed the
bundle.

E.g. Alice uploads a WorkerPayload that has a signature from alice that
is valid. But inside the signed Bundle, the bundle says that Bob said
that the inference was 400 - even though Bob didn't sign the actual
payload.

## Link(s) to Ticket(s) or Issue(s) resolved by this PR

This was discovered independently by me while working on #548 and does
not have a ticket.

## Are these changes tested and documented?

Our existing test suite at least covers the happy path, when actors are
well behaved.

This PR adds the following four tests to cover authorization checks:
* `TestMsgInsertWorkerPayloadWorkerNotMatchSignature`
* `TestMsgInsertWorkerPayloadInfererNotMatchSignature`
* `TestMsgInsertWorkerPayloadForecasterNotMatchSignature`
* `TestMsgInsertReputerPayloadReputerNotMatchSignature`

No documentation changes.

This PR has been added to the `Unreleased` section of `CHANGELOG.md`?

---------

Co-authored-by: michael <[email protected]>
Co-authored-by: Kenny P <[email protected]>
Co-authored-by: RedBird96 <[email protected]>
Co-authored-by: Kenny <[email protected]>
kpeluso pushed a commit that referenced this pull request Aug 30, 2024
@kpeluso kpeluso deleted the tyler/proto-2204-implement-merit-based-sortition branch December 5, 2024 08:23
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.

4 participants