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

gov: simplify governance-controlled parameter changes #4319

Merged
merged 7 commits into from
May 5, 2024
Merged

Conversation

hdevalence
Copy link
Member

@hdevalence hdevalence commented May 4, 2024

Describe your changes

This commit refactors the governance component to dramatically simplify the way
that governance-controlled parameter changes are performed. Previously, the
governance component duplicated all of the parameter data of all of the other
components, which had to be kept in sync in a complicated and error-prone way.

Now, parameter changes are specified and performed as key-value edits:

  • A parameter change proposal specifies a list of (component, key, value) pairs
  • The governance component can apply these without knowledge of other components' structures by operating on a serde_json::Value
  • The application can validate the changed parameters by deserializing a complete AppParameters from ProtoJSON.

The logic around applying these changes is also dramatically simplified. The
top-level app is responsible for all parameter changes. Components do not need
to track their own individual "dirty bit" for parameter changes. The governance
component can report to any other component when a parameter change was
scheduled to occur.

Another crucial improvement is that this code allows different parameters to be changed by different proposals, because changes are made to individual parameters, not to entire subsections.

In followup work, we should change the pcli interface to work with JSON
proposal data and delete the ProposalToml entirely.

Issue ticket number and link

None

Checklist before requesting a review

  • If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason:

    This commit changes how the governance system works. However, no migrations are necessary, because it ignores any previous data and writes new data in different places.

@hdevalence hdevalence changed the title WIP: new approach to declaring parameter changes in governance gov: simplify governance-controlled parameter changes May 4, 2024
@hdevalence hdevalence added the consensus-breaking breaking change to execution of on-chain data label May 4, 2024
@hdevalence hdevalence marked this pull request as ready for review May 4, 2024 22:30
This commit refactors the governance component to dramatically simplify the way
that governance-controlled parameter changes are performed.  Previously, the
governance component duplicated all of the parameter data of all of the other
components, which had to be kept in sync in a complicated and error-prone way.

Now, parameter changes are specified and performed as key-value edits:

- A parameter change proposal specifies a list of `(component, key, value)` pairs
- The governance component can apply these without knowledge of other components' structures by operating on a `serde_json::Value`
- The application can validate the changed parameters by deserializing a complete `AppParameters` from ProtoJSON.

The logic around applying these changes is also dramatically simplified. The
top-level app is responsible for all parameter changes. Components do not need
to track their own individual "dirty bit" for parameter changes. The governance
component can report to any other component when a parameter change was
scheduled to occur.

In followup work, we should change the `pcli` interface to work with JSON
proposal data and delete the `ProposalToml` entirely.
Copy link
Contributor

@cratelyn cratelyn left a comment

Choose a reason for hiding this comment

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

pending ci, this looks good to me. great work! i'm looking forward to talking about this more next week.

The existing logic didn't balance delegator vote transactions properly.  This
commit is the first step to fixing it.  The purpose of allowing the `Planner`
to have an async API was so that it could fetch data directly from the view
service, rather than having to implement our own async logic at the application
level (by saving stuff we want to query later).

However, the new planner logic doesn't seem to be correct, because adding the
`DelegatorVotePlan` gives an error that there were no actions to balance.
@hdevalence
Copy link
Member Author

It's not actually possible to make a delegator vote to test it, however, so it's not yet good to merge. The planner needs to be fixed to make this possible, this was a recent regression. I am working on that now.

The part of the web planner refactoring we wanted to bring over to the core
repo was the creation of a separate `ActionList` modeling a list of actions
that may or may not be balanced.  This commit pulls the planner into that
shape, and extends the `ActionList` design found in the web code in a few ways:

- The `ActionList` tracks a target fee internally, rather than leaving that to
  its caller. This allows us to handle cases like a swap claim, where we want
  to put the prepaid fee released by a swap claim towards the transaction fee,
  and not create dust outputs.

- The `ActionList` has the groundwork for supporting multi-asset fee payments,
  by not assuming that the fee is always in the staking token when accounting
  for fees. Later we can add an asset ID to the `GasPrices` and it should be
  a relatively drop-in extension.

- The `ActionList` can be used to create a `TransactionPlan` directly. In the
  future, we should consider restructuring the `view` crate to have most of
  its current contents behind a `svc` flag, allowing us to depend on the `view`
  crate from the wasm code and have a common `ActionList` impl between them,
  just different code that manipulates it.

Various API cleanups were necessary along the way.
@hdevalence
Copy link
Member Author

I restructured the Planner implementation in this repo to match the refactoring in the web repo:

The part of the web planner refactoring we wanted to bring over to the core
repo was the creation of a separate ActionList modeling a list of actions
that may or may not be balanced. This commit pulls the planner into that
shape, and extends the ActionList design found in the web code in a few ways:

  • The ActionList tracks a target fee internally, rather than leaving that to
    its caller. This allows us to handle cases like a swap claim, where we want
    to put the prepaid fee released by a swap claim towards the transaction fee,
    and not create dust outputs.

  • The ActionList has the groundwork for supporting multi-asset fee payments,
    by not assuming that the fee is always in the staking token when accounting
    for fees. Later we can add an asset ID to the GasPrices and it should be
    a relatively drop-in extension.

  • The ActionList can be used to create a TransactionPlan directly. In the
    future, we should consider restructuring the view crate to have most of
    its current contents behind a svc flag, allowing us to depend on the view
    crate from the wasm code and have a common ActionList impl between them,
    just different code that manipulates it.

Various API cleanups were necessary along the way.

cc @TalDerei -- might be interesting to you, sorry we had confusion about the goals there.

@hdevalence
Copy link
Member Author

I tested this code on a local devnet and was able to freely adjust parameters (and had all actions have correctly priced fees, too!).

@erwanor
Copy link
Member

erwanor commented May 5, 2024

Delegator/validator voting is supported by the planner thanks to @TalDerei quick follow-up

@erwanor
Copy link
Member

erwanor commented May 5, 2024

Ah I hadn’t looked at the planner rerefactor, so I actually don’t know

@hdevalence
Copy link
Member Author

Delegator/validator voting is supported by the planner thanks to @TalDerei quick follow-up

When I tried using it to exercise parameter changes there were balance errors, but I was able to build further on the cleaned-up code and get through it reasonably easily, so it was a great groundwork.

@hdevalence hdevalence merged commit ac169d7 into main May 5, 2024
13 checks passed
@hdevalence hdevalence deleted the gov-refactor branch May 5, 2024 17:42
@TalDerei
Copy link
Collaborator

TalDerei commented May 5, 2024

Can I propagate the planner changes to the web? Currently reviewing the changeset in this PR

@hdevalence
Copy link
Member Author

No, I’d rather make a plan of how to share code and get the plan right first, before we do more work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consensus-breaking breaking change to execution of on-chain data
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants