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

feat(x/ecocredit): add buy/sell expiration #671

Merged
merged 18 commits into from
Jan 25, 2022

Conversation

ryanchristo
Copy link
Member

@ryanchristo ryanchristo commented Dec 15, 2021

Description

Closes: #636

Add expiration to buy and sell orders and remove expired buy and sell orders with BeginBlocker.


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)

@ryanchristo ryanchristo changed the title Ryan/636 buy sell expiration feat(x/ecocredit): add buy/sell expiration Dec 15, 2021
@codecov
Copy link

codecov bot commented Dec 15, 2021

Codecov Report

Merging #671 (54776f9) into master (3ff0a1c) will increase coverage by 0.21%.
The diff coverage is 89.55%.

❗ Current head 54776f9 differs from pull request most recent head 071c3bc. Consider uploading reports for the commit 071c3bc to get more accurate results

@@            Coverage Diff             @@
##           master     #671      +/-   ##
==========================================
+ Coverage   75.88%   76.10%   +0.21%     
==========================================
  Files         113      115       +2     
  Lines       18568    18834     +266     
==========================================
+ Hits        14090    14333     +243     
- Misses       3574     3587      +13     
- Partials      904      914      +10     
Flag Coverage Δ
experimental-codecov 76.21% <89.55%> (+0.21%) ⬆️
stable-codecov 68.93% <89.55%> (+0.36%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@ryanchristo ryanchristo added the Scope: x/ecocredit Issues that update the x/ecocredit module label Dec 17, 2021
@ryanchristo
Copy link
Member Author

ryanchristo commented Dec 17, 2021

pending #647

Base automatically changed from aleem/646-ecocredit-projects to master January 3, 2022 17:20
@@ -406,7 +406,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
// NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC)
app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, /* ecocredit.ModuleName, */
Copy link
Member Author

Choose a reason for hiding this comment

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

Any ideas why adding this would cause the tests to hang?

Copy link
Member Author

Choose a reason for hiding this comment

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

It times out after 10 minutes with the following error:

    tx.go:102: 
                Error Trace:    tx.go:102
                                                        suite.go:118
                                                        tx.go:50
                                                        modules_test.go:12
                Error:          Received unexpected error:
                                rpc error: code = NotFound desc = rpc error: code = NotFound desc = account regen1huayfhrzpkxxws60dxlzv6p3l6e95nau7yk3as not found: key not found
                Test:           TestEcocreditIntegration
panic: test timed out after 10m0s

Copy link
Contributor

@technicallyty technicallyty Jan 14, 2022

Choose a reason for hiding this comment

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

i'm wondering if this has anything to do with the ecocredit module not fulfilling the interface that actually contains the BeginBlock signature.

might need to : add this to the ecocredit/module/module.go file var _ module.AppModule = Module{} and implement the methods it says its missing. maybe that would work?

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 think it might be best to break this out into a separate issue. The ecocredit module does not implement the AppModule interface and in attempting to do so there are some conflicts with the RegisterServices method which uses a different Configurator. Opened #689.

@ryanchristo ryanchristo marked this pull request as ready for review January 13, 2022 18:20
@@ -406,7 +406,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
// NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC)
app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, /* ecocredit.ModuleName, */
Copy link
Contributor

Choose a reason for hiding this comment

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

is ecocredit commented out due to errors?

Copy link
Member Author

Choose a reason for hiding this comment

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

correct, not sure how to resolve at the moment: #671 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

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

let's leave it for a next task.

x/ecocredit/client/testsuite/query.go Outdated Show resolved Hide resolved
x/ecocredit/expected_keepers.go Show resolved Hide resolved
x/ecocredit/module/module.go Show resolved Hide resolved
x/ecocredit/abci.go Outdated Show resolved Hide resolved
x/ecocredit/msgs.go Outdated Show resolved Hide resolved
proto/regen/ecocredit/v1alpha2/events.proto Outdated Show resolved Hide resolved

// new_expiration is the optional timestamp when the sell order expires. When the
// expiration time is reached, the sell order is removed from state.
google.protobuf.Timestamp new_expiration = 7 [ (gogoproto.stdtime) = true ];
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we really want to use new_ prefix?

Copy link
Member Author

Choose a reason for hiding this comment

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

We are using new_quantity and new_ask_price so new_expiration made sense.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, we don't do that in general. The other parts were not yet released. Let's chat about naming in the discord or standup.

x/ecocredit/abci.go Outdated Show resolved Hide resolved
x/ecocredit/client/tx.go Show resolved Hide resolved
x/ecocredit/expected_keepers.go Show resolved Hide resolved
return err
}

if !m.Orders[i].AskPrice.Amount.IsPositive() {
if !order.AskPrice.Amount.IsPositive() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMHO, ValidateBasic should be minimalistic. All other validation should go in other function: cosmos/cosmos-sdk#10680

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like this is still in discussion. Maybe we can address this in all modules and all implementations of validate basic at a later point in time once there is an agreed upon solution?

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK

Copy link
Member

Choose a reason for hiding this comment

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

I think the stricter version is fine for now and that was more or less the outcome of the github discussion

x/ecocredit/msgs.go Outdated Show resolved Hide resolved
x/ecocredit/server/expiration.go Show resolved Hide resolved
x/ecocredit/server/expiration.go Show resolved Hide resolved
}

var sellOrders []*ecocredit.SellOrder
_, err = orm.ReadAll(sellOrdersIter, &sellOrders)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we only need to read the id, not the whole object.

Copy link
Member Author

Choose a reason for hiding this comment

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

True but I'm not sure we have a way to only read the id. As far as I can see, we have to load the whole object here but maybe I'm missing something?

Copy link
Member Author

Choose a reason for hiding this comment

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

Switched to LoadNext to consolidate within the loop as suggested but still loading the whole object. Let me know if I'm missing something that would allow reading the id only.

Copy link
Collaborator

Choose a reason for hiding this comment

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

LoadNext returns RowID. I think this is the ID you are looking for. So we can save empty bytes as the value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct but LoadNext still loads the whole object. We have to pass a proto message as the destination. RowID returns the id in bytes, which we can convert, but we already have the id from the loaded object.

}, uint64(0))
if err != nil {
panic(err.Error())
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Other way to avoid the round trip with de-serialization of index, would be to add a delete method to the index (we can make a task for that). CC: @aaronc

context: #671 (comment)

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.

I've updated the time parsing flow and organized the tests - they are more readable (and shorter).

x/ecocredit/client/tx.go Show resolved Hide resolved
Copy link
Contributor

@technicallyty technicallyty left a comment

Choose a reason for hiding this comment

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

👍🏻

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.

thanks for the work! we can handle the issue with the index removal roundtrip in a separate task.

x/ecocredit/client/tx.go Outdated Show resolved Hide resolved
x/ecocredit/client/tx.go Outdated Show resolved Hide resolved
@ryanchristo ryanchristo enabled auto-merge (squash) January 25, 2022 17:09
@ryanchristo ryanchristo merged commit 26cb432 into master Jan 25, 2022
@ryanchristo ryanchristo deleted the ryan/636-buy-sell-expiration branch January 25, 2022 17:13
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement buy/sell order expiration
5 participants