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

Eco-credit Module Proof of Concept Init #125

Merged
merged 13 commits into from
Nov 5, 2020

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Nov 4, 2020

ref #78

Credit Module Proto Files

This includes protobuf files for the design outlined in #117, but it does so without leveraging the existing bank module. Instead the implementation (#119) does its own balance and supply tracking (IMHO more correctly than x/bank). As I've said before, we can definitely consider alternate designs (like #115 or whatever we find is needed by users). This is just the design I've had for over a year now (and originally PoC'ed in SF in Oct, 2019). It was pretty simple to implement and I'd just like to get it out there so we can iterate from there.

Decimal Balance Experiment

This design also includes an implementation of cosmos/cosmos-sdk#7113 done with https://github.com/cockroachdb/apd. This feels relevant especially concerning the problems we're having with sdk.Dec (cosmos/cosmos-sdk#7773. In particular, I wanted to try out apd, to see if it may be a suitable replacement for sdk.Dec.


Feel free to submit a Draft Pull Request as soon as you start working on something. Before you mark your PR as Ready For Review, make sure you've checked off the following boxes or indicated N/A (not applicable):

  • linked to a relevant issue or have written a clear description of the issue in the PR
  • wrote or updated tests
  • wrote or updated documentation
  • added an appropriate entry in CHANGELOG.md following https://keepachangelog.com

Thanks!

@codecov
Copy link

codecov bot commented Nov 4, 2020

Codecov Report

Merging #125 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #125   +/-   ##
=======================================
  Coverage   37.34%   37.34%           
=======================================
  Files          11       11           
  Lines         905      905           
=======================================
  Hits          338      338           
  Misses        561      561           
  Partials        6        6           

Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>
@aaronc
Copy link
Member Author

aaronc commented Nov 4, 2020

Other than those comments @blushi does this look okay to move forward with? You honestly have the most context from the registry side.

@aaronc aaronc requested review from clevinson and blushi November 4, 2020 19:40
proto/regen/ecocredit/v1alpha1/events.proto Show resolved Hide resolved
string class_id = 1;

// batch_denom is the unique ID of credit batch.
string batch_denom = 2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you be more precise here: is the batch_denom unique inside the given class, or globally?

Also, why we are calling it batch_denom ? Why not batch_id? I know that we use denom for an asset name, but here it's meaning (without a comment) is not very clear.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep I can add some clarifying language on denominations

string batch_denom = 2;

// issuer is the issuer of the credit batch.
string issuer = 3;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will be an address, right? Maybe let's put that in a comment:

// credit batch issuer account address

Copy link
Member Author

Choose a reason for hiding this comment

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

yep

// sender is the sender of the credits in the case that this event is the result of a transfer.
// It will not be set if credits were issued.
string sender = 2;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is only one issuer, so we don't need to code it here. In Ethereum, the standard is to put sender=0 (zero value) for minting / issuance transfers. Maybe we can use the same thing here (sender = "")?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Other idea, instead of oneof would be to add a boolean flag here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have to use oneof true, but they are mutually exclusive. I can just make sender = "" if that's preferred

Copy link
Collaborator

Choose a reason for hiding this comment

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

The whole thing is to eliminate theoneof and normalize the data in the RDBMS sense (so to not use the issuer field at all here). Adding a boolean flag is only cosmetic if we want to be explicit.

Copy link
Member Author

Choose a reason for hiding this comment

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

well i'm trying to distinguish between issuer and sender as roles...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I know. My point is that issuer is known and it must be the same as the batch issuer. By adding it here we denormalize the data.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, so I'm removing and just leaving sender = ""

string recipient = 3;

// batch_denom is the unique ID of credit batch.
string batch_denom = 4;
Copy link
Collaborator

Choose a reason for hiding this comment

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

ok, so I think this answers my comment above: batch_denom is unique globally.

Copy link
Member Author

Choose a reason for hiding this comment

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

yep


// retired_units are the units of credits in this issuance that are effectively retired by the issuer on receipt.
// Decimal values are acceptable within the precision returned by Query/Precision.
string retired_units = 3;
Copy link
Collaborator

Choose a reason for hiding this comment

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

As above, retired units are not tradeable - so doesn't it make sense to send it over?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure, but likely yes. A broker may specifically sell credits that can't be traded as part of the contract. Again a business discussion to have with Ron

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, there are cases where sold credits should be "auto-retired".

proto/regen/ecocredit/v1alpha1/tx.proto Outdated Show resolved Hide resolved
// credits are the credits being retired.
repeated RetireUnits credits = 2;

// RetireUnits are the units of the batch being retired.
Copy link
Collaborator

Choose a reason for hiding this comment

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

this description should use the same language as the comment in line 134. Also, related to the comment above about changing a vocabulary for units (in proto/regen/ecocredit/v1alpha1/events.proto)

string total_units = 4;

// metadata is any arbitrary metadata to attached to the credit batch.
bytes metadata = 5;
Copy link
Collaborator

Choose a reason for hiding this comment

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

related to the comment above - let's consider adding a certificate field.

Copy link
Member Author

Choose a reason for hiding this comment

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

again let's discuss metadata elsewhere. we don't have context on the engineering team to make these sorts of decisions


// units is the decimal number of credits that have been retired.
string units = 3;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should also add a Claim Subject or Claim Reference - which is used to link the credits retire events with real world event.

Copy link
Member Author

Choose a reason for hiding this comment

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

ditto, this should be part of RFC process

@robert-zaremba
Copy link
Collaborator

we can definitely consider alternate designs (like #115 or whatever we find is needed by users).

This model is almost compatible with #115 design (with small changes to Msg/Send and Msg/Retire).

Copy link
Member

@clevinson clevinson left a comment

Choose a reason for hiding this comment

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

Few comments on the retiring functionality, and whether users can transfer retired credits with this implementation, or what the purpose is of having retired_units as part of the SendUnits msg.

Happy for these to be resolved in a followup and use this as a starting point though.

message EventCreateBatch {

// class_id is the unique ID of credit class.
string class_id = 1;
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason that these identifiers (class_id) are string and not integer?

I guess for batch_denom its useful to have as a string, as that's the same type as denoms in the broader cosmos sdk, but for class_id how do you see these ID's being generated? In my head, this would have been an integer identifier, indexed (as in a relational database) and auto-incrementing

Copy link
Member Author

Choose a reason for hiding this comment

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

An integer converted to a string and so that it's obviously part of denom. We can reassess later

proto/regen/ecocredit/v1alpha1/events.proto Outdated Show resolved Hide resolved

// retired_units are the units of credits in this issuance that are effectively retired by the issuer on receipt.
// Decimal values are acceptable within the precision returned by Query/Precision.
string retired_units = 3;
Copy link
Member

Choose a reason for hiding this comment

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

Seems strange to allow sending of pre-retired credits. IMO retiring should be a separate action done intentionally by the holder of credits.

We already cover the "retire on issuance" use case in the BatchIssuance message, so why is this needed here as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not necessarily. I believe a broker may specifically only sell credits that are retired on sale. We need to discuss with Ron It may or may not be a use case but better to be on the safe side

Copy link
Member

Choose a reason for hiding this comment

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

agreed cf. #125 (comment)

aaronc and others added 2 commits November 4, 2020 18:41
Co-authored-by: Robert Zaremba <robert@zaremba.ch>
Co-authored-by: Cory <cjlevinson@gmail.com>
Copy link
Collaborator

@robert-zaremba robert-zaremba 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 to move forward. I will collect the questions / suggestion in an issue for review by a science and business team.

@aaronc
Copy link
Member Author

aaronc commented Nov 5, 2020

Looks good to move forward. I will collect the questions / suggestion in an issue for review by a science and business team.

thanks @robert-zaremba

aaronc and others added 2 commits November 4, 2020 19:08
Co-authored-by: Robert Zaremba <robert@zaremba.ch>
@aaronc aaronc merged commit c1ab122 into master Nov 5, 2020
@aaronc aaronc mentioned this pull request Nov 5, 2020
4 tasks
@ryanchristo ryanchristo deleted the aaronc/78-credit-module-poc-init branch July 2, 2022 22:02
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