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

Add parameter to track credit types and associated precision #424

Closed
5 tasks
ruhatch opened this issue Jul 20, 2021 · 10 comments · Fixed by #428
Closed
5 tasks

Add parameter to track credit types and associated precision #424

ruhatch opened this issue Jul 20, 2021 · 10 comments · Fixed by #428
Assignees
Labels
Scope: x/ecocredit Issues that update the x/ecocredit module Type: Feature New feature or request

Comments

@ruhatch
Copy link
Contributor

ruhatch commented Jul 20, 2021

As part of integration with x/bank, we decided to have a single consistent precision for each type of credit, rather than being able to set precision per credit class. This issue should:

  • Add a governance parameter to x/ecocredit containing a map of credit types and precisions
  • Remove the ability to set precision on a per-class basis
  • Add credit type as a field on credit class
  • Enforce precisions of vaules based on the governance parameter
  • Ensure that precision cannot be updated via governance (at least until bank has support for decimals)
@ruhatch
Copy link
Contributor Author

ruhatch commented Jul 20, 2021

@aaronc how does this interact with #398?

Perhaps we have the parameter as a single map of type map[string]Unit, with:

type Unit struct {
        name      string
        precision uint32
}

e.g.

{
        "carbon": Unit {
                name:      "kg",
                precision: 6,
        },
        "biodiversity": Unit {
                name:      "hectares",
                precision: 3,
        },
}

@ruhatch ruhatch added Scope: x/ecocredit Issues that update the x/ecocredit module Type: Feature New feature or request labels Jul 20, 2021
@aaronc
Copy link
Member

aaronc commented Jul 20, 2021

This can replace #398

@technicallyty
Copy link
Contributor

technicallyty commented Jul 21, 2021

was the intention to use the proto map type? might be an issue: the safety of using protobuf maps isn't quite well defined yet see: cosmos/cosmos-sdk#9073 (comment)

perhaps we do something like this using repeated:

// Params defines the updatable global parameters of the ecocredit module for
// use with the x/params module.
message Params {
  // -- snip -- //

  // credit_types is a list of definitions for credit types
  repeated CreditType credit_types = 2;
}

message CreditType {
    string typeOf = 1;
    string unit = 2;
    uint32 precision = 3;
}

@aaronc
Copy link
Member

aaronc commented Jul 21, 2021

Let's use repeated 👍

@technicallyty
Copy link
Contributor

should we just rip out all set precision from the proto files and stuff? or is there a smoother way to depreciate it?

@ruhatch
Copy link
Contributor Author

ruhatch commented Jul 22, 2021

should we just rip out all set precision from the proto files and stuff? or is there a smoother way to depreciate it?

I think just rip it out! This isn't currently deployed, so we're changing the design to just have precision at the credit type level.

@aaronc
Copy link
Member

aaronc commented Jul 22, 2021

I would even goes as far as to say we might allow 6 as the only valid value for precision and then consider whether we loosen that in the future. What do you think @ruhatch?

@technicallyty
Copy link
Contributor

I would even goes as far as to say we might allow 6 as the only valid value for precision and then consider whether we loosen that in the future. What do you think @ruhatch?

related q: how do we enforce credit types as a gov param while simultaneously not allowing the precision to change? the validation function is stateless so i can't grab the existing params and check for changes.. so is just enforcing a hard 6 the solution for now?

@aaronc
Copy link
Member

aaronc commented Jul 22, 2021

I would even goes as far as to say we might allow 6 as the only valid value for precision and then consider whether we loosen that in the future. What do you think @ruhatch?

related q: how do we enforce credit types as a gov param while simultaneously not allowing the precision to change? the validation function is stateless so i can't grab the existing params and check for changes.. so is just enforcing a hard 6 the solution for now?

I think so. x/params is sort of broken anyway, we should have rewriting it as something in our roadmap (cosmos/cosmos-sdk#6983). An alternative would be just setting parameters directly in x/ecocredit without x/params when cosmos/cosmos-sdk#9438 is ready. But for now, I think hard-coded 6 is probably the solution.

@technicallyty technicallyty mentioned this issue Jul 22, 2021
19 tasks
@ruhatch
Copy link
Contributor Author

ruhatch commented Jul 23, 2021

I would even goes as far as to say we might allow 6 as the only valid value for precision and then consider whether we loosen that in the future. What do you think @ruhatch?

related q: how do we enforce credit types as a gov param while simultaneously not allowing the precision to change? the validation function is stateless so i can't grab the existing params and check for changes.. so is just enforcing a hard 6 the solution for now?

I think so. x/params is sort of broken anyway, we should have rewriting it as something in our roadmap (cosmos/cosmos-sdk#6983). An alternative would be just setting parameters directly in x/ecocredit without x/params when cosmos/cosmos-sdk#9438 is ready. But for now, I think hard-coded 6 is probably the solution.

Does that param issue mean that we can't validate param changes?

In that case I guess hardcoding seems like the best option for now and we can migrate it to a gov param once we can do validation and gov/group/param stuff is all a bit more stable?

ruhatch pushed a commit that referenced this issue Aug 9, 2021
+Adds credit types which includes type name, unit type (kg, tonne, etc), and precision (currently locked @ 6).
+Adds query to get all credit types on CLI and grpc/http
+Updates CreateClass tx command to include credit class arg
+Adds tests for validating the credit type params
-removes per-class precision setting functionality

Closes: #424
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: x/ecocredit Issues that update the x/ecocredit module Type: Feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants