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

refactor(ecocredit)!: migrate core ecocredit msg_server to use ORM #723

Closed
wants to merge 34 commits into from

Conversation

technicallyty
Copy link
Contributor

@technicallyty technicallyty commented Feb 3, 2022

Description

beginning of ecocredit ORM refactor

Closes: #696

Closes: #707


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@@ -50,14 +54,13 @@ func NewIntegrationTestSuite(fixtureFactory testutil.FixtureFactory, paramSpace

func (s *IntegrationTestSuite) SetupSuite() {
Copy link
Contributor Author

@technicallyty technicallyty Feb 5, 2022

Choose a reason for hiding this comment

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

I think we should consider refactoring all these separate integration test into smaller, bite sized unit tests, and then just have one big integration test. imo it makes more sense at these tests look more like unit tests than integration anyways

it's a bit confusing to figure my way around this code. the batch info test is broken and the case thats failing has a hard coded batch denom to search for. i'm not really even sure what the best approach to fixing that test would be other than obliterating the existing test structure to fit my needs..

should we create an issue to move these smaller tests into unit tests? @aaronc @ryanchristo @robert-zaremba thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I agree. A lot of these tests are written like unit tests already. I think it makes sense to separate them out and to simply the integration tests in a separate issue. You should be able to trace the batch denom issue without obliterating the existing structure. Would be happy to take a look if you get stuck.

@@ -4,7 +4,7 @@ package regen.ecocredit.basket.v1beta1;

import "regen/ecocredit/basket/v1beta1/types.proto";

option go_package = "github.com/regen-network/regen-ledger/x/ecocredit/v1beta1";
option go_package = "github.com/regen-network/regen-ledger/x/ecocredit/basket/v1beta1";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

code wasn't being generated for these packages, i assume they were being overwritten by core which gets written last? all code from these sub packages get generated now

x/ecocredit/server/core/query_server.go Outdated Show resolved Hide resolved
@technicallyty technicallyty marked this pull request as ready for review February 7, 2022 22:18
Copy link
Member

@ryanchristo ryanchristo left a comment

Choose a reason for hiding this comment

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

Looking great. Nice work! Still working through the review. A few comments to start.

proto/regen/ecocredit/v1beta1/events.proto Outdated Show resolved Hide resolved
proto/regen/ecocredit/v1beta1/tx.proto Outdated Show resolved Hide resolved
Comment on lines +35 to +37
if s == "" {
s = "0"
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we throw an error if the string is empty? I think it might be safer to require a value to be explicitly set rather than assuming an empty string should be 0.

Copy link
Contributor Author

@technicallyty technicallyty Feb 8, 2022

Choose a reason for hiding this comment

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

i found a few places where were we would explicitly check for the empty string case and then set it to "0" anyway, so it felt like a good way to reduce that.

are there any specific cases where we'd prefer to error here instead of defaulting to 0?

Copy link
Member

@aaronc aaronc Feb 8, 2022

Choose a reason for hiding this comment

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

If we want to handle "", no need to parse anything just return a zero value.

Seems like we'd check for "" elsewhere if we actually want a nullable case so I think this default is okay

x/ecocredit/server/core/msg_server.go Outdated Show resolved Hide resolved
x/ecocredit/server/core/msg_server.go Outdated Show resolved Hide resolved
Comment on lines 466 to 469
// delete the old issuers
if err = s.stateStore.ClassIssuerStore().DeleteBy(ctx, ecocreditv1beta1.ClassIssuerClassIdIssuerIndexKey{}.WithClassId(class.Name)); err != nil {
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we use Update rather than deleting the old and inserting the new one by one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the primary key is made up of the classID+issuer_address, so it wouldn't work in this case. if it had a simple row ID primary key with class+issuer indexes, i could do that - i'm not sure on the benchmarks of either case though, could look into some metrics for ORM ops if we value it

x/ecocredit/server/core/msg_server.go Outdated Show resolved Hide resolved
x/ecocredit/server/core/operations.go Outdated Show resolved Hide resolved
@technicallyty technicallyty mentioned this pull request Feb 8, 2022
8 tasks
proto/regen/ecocredit/v1beta1/events.proto Outdated Show resolved Hide resolved
proto/regen/ecocredit/v1beta1/events.proto Outdated Show resolved Hide resolved
x/ecocredit/denom.go Show resolved Hide resolved
x/ecocredit/server/core/invariants_test.go Outdated Show resolved Hide resolved
x/ecocredit/server/core/msg_server.go Outdated Show resolved Hide resolved
Copy link
Member

@aaronc aaronc left a comment

Choose a reason for hiding this comment

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

Implementation generally looks good. A few things to clean-up. Some of them can be in follow-ups as they're related to existing design choices

x/ecocredit/server/core/msg_server.go Outdated Show resolved Hide resolved
x/ecocredit/server/core/msg_server.go Outdated Show resolved Hide resolved
x/ecocredit/server/core/msg_server.go Outdated Show resolved Hide resolved
projectID := req.ProjectId
if projectID == "" {
found := false
for !found {
Copy link
Member

Choose a reason for hiding this comment

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

why do we need a loop here? something seems not quite right here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was actually your suggestion in the original projects PR 😄 - #647 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

we need to loop to avoid a clash but the way this loop is structured is just confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you have any suggestions to make it clearer? i had thought it was pretty straightforward but open to suggestions

x/ecocredit/server/core/msg_server.go Outdated Show resolved Hide resolved
x/ecocredit/server/core/msg_server.go Outdated Show resolved Hide resolved
x/ecocredit/server/core/msg_server.go Outdated Show resolved Hide resolved
x/ecocredit/server/core/msg_server.go Outdated Show resolved Hide resolved
@technicallyty
Copy link
Contributor Author

this PR is now more in line with the architecture used for #732. There's quite a lot of code in here, so I can opt to split this into chunks and submit multiple, smaller PR's.

I've implemented the msg server and query servers for v1beta1 proto files with unit tests. It is not wired up to the existing msg_server yet, as that require moving around more things and making an already large diff even larger.

Would appreciate any feedback/ideas on how to proceed from here! @aaronc @ryanchristo @clevinson :-)

@technicallyty technicallyty marked this pull request as draft February 28, 2022 22:51
@ryanchristo
Copy link
Member

This pull request is being broken up into smaller pull requests.

@blushi
Copy link
Member

blushi commented Mar 4, 2022

This pull request is being broken up into smaller pull requests.

should we just close this then?

@blushi blushi removed their assignment Mar 4, 2022
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.

ecocredit: remove credit type sequences x/ecocredit: migrate ecocredit storage model to ORM
4 participants