-
Notifications
You must be signed in to change notification settings - Fork 353
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
Problem: no well-tested implementation of subscriptions module (fix #295) #381
Conversation
TODO:
|
Codecov Report
@@ Coverage Diff @@
## master #381 +/- ##
===========================================
+ Coverage 12.26% 23.10% +10.84%
===========================================
Files 31 55 +24
Lines 4779 8742 +3963
===========================================
+ Hits 586 2020 +1434
- Misses 3935 6154 +2219
- Partials 258 568 +310
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
This pull request introduces 4 alerts when merging b87e296 into 8764b74 - view on LGTM.com new alerts:
|
1e01a29
to
e62c7cc
Compare
This pull request introduces 4 alerts when merging e62c7cc into 8764b74 - view on LGTM.com new alerts:
|
7a9d1e2
to
2b8692f
Compare
This pull request introduces 4 alerts when merging 2b8692f into 8764b74 - view on LGTM.com new alerts:
|
2b8692f
to
1d075c0
Compare
This pull request introduces 4 alerts when merging 1d075c0 into 91e5405 - view on LGTM.com new alerts:
|
49b3529
to
b5dbefc
Compare
This pull request introduces 4 alerts when merging b5dbefc into 91e5405 - view on LGTM.com new alerts:
|
b5dbefc
to
4ae9efd
Compare
This pull request introduces 4 alerts when merging 4ae9efd into 91e5405 - view on LGTM.com new alerts:
|
4ae9efd
to
808c38f
Compare
This pull request introduces 4 alerts when merging 0d42e76 into 66b3503 - view on LGTM.com new alerts:
|
there are a few conflicts with the latest master |
done |
it's here, the abci commit event happens once for each block, at the end of block processing. |
9533c1e
to
7b1f42b
Compare
done |
|
proto/subscription/v1/query.proto
Outdated
option (google.api.http).get = "/chainmain/subscription/v1beta1/plan/{plan_id}"; | ||
} | ||
|
||
rpc Plans(QueryPlansRequest) returns (QueryPlansResponse) { | ||
option (google.api.http).get = "/chainmain/subscription/v1beta1/plans"; | ||
} | ||
|
||
rpc Subscription(QuerySubscriptionRequest) returns (QuerySubscriptionResponse) { | ||
option (google.api.http).get = "/chainmain/subscription/v1beta1/subscription/{subscription_id}"; | ||
} | ||
|
||
rpc Subscriptions(QuerySubscriptionsRequest) returns (QuerySubscriptionsResponse) { | ||
option (google.api.http).get = "/chainmain/subscription/v1beta1/subscriptions"; | ||
} | ||
|
||
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { | ||
option (google.api.http).get = "/chainmain/subscription/v1beta1/params"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v1
instead of v1beta1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
x/subscription/client/cli/tx.go
Outdated
if err != nil { | ||
return err | ||
} | ||
// Get voting address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
owner address instead of voting address?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
x/subscription/keeper/keeper.go
Outdated
|
||
var gasPerCollection uint32 | ||
k.paramSpace.Get(ctx, types.KeyGasPerCollection, &gasPerCollection) | ||
ctx.GasMeter().ConsumeGas(sdk.Gas(gasPerCollection), "create subscription") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in spec, it says:
ConsumeGas( count_period(create_time, expiration_time, plan.cron_spec, plan.cron_tz) * GasPerCollection )
but here, it'll just charge a fixed param gasPerCollection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, forgot that, added now.
x/subscription/keeper/keeper.go
Outdated
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
types.EventTypeCreatePlan, | ||
sdk.NewAttribute(types.AttributeKeyPlanID, strconv.FormatInt(int64(plan.PlanId), 10)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens in these event emitting if PlanId/SubscriptionId doesn't fit in int64?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's actually a FormatUint
, I just changed to that.
But still, I think when PlanId/SubscriptionId overflow, it'll wrap around, could possibly cause id conflict.
Maybe it's better to just stop creating new items when this happens?
EDIT: added id overflow detection, return error when happend.
|
||
qCycles := remDays / daysPer4Y | ||
if qCycles == 25 { | ||
// TODO I think this path is never reached |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe year 2074 or something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this one, it don't reach here too, I've tried lots of cases. 😄
added
good idea, added now. |
Thanks! |
abc.go, func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
|
could you modify to cosmos.base.v1.Coin? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This namespace is defined in cosmos-sdk, I don't think we can change it ;D |
Yeah, these are all unix timestamps in seconds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can probably merge this by Friday -- so may be good to resolve conflicts + changelog entry for unreleased 2.0.0?
@yihuang one more test if it can be added -- init a Chain with https://github.com/crypto-org-chain/chain-main/releases/tag/v1.1.0 and then cosmovisor upgrade for v2 with subscriptions? probably some handler to init storage needs to be added? |
e9c1f20
to
70cb197
Compare
Done, reused the |
…rypto-org-chain#295) Solution: - implement basic calendar and crontab logic - implement the module add subscription integrationt test check SubscriptionEnabled parameter support timezone fix event emmision add README for implementation notes fix wording in comments and namings Change org name in proto package name Update app/app.go Co-authored-by: Tomas Tauber <2410580+tomtau@users.noreply.github.com> assert plan owner's balance add missing tzoffset to spec Add comments for storage Use more explicit ParseUint validate genesis state Custom bitset implementation lint issues improve coverage of calendar/cronspec/bitset improve coverage of keeper Add license/copyright of bitset v1beta -> v1 update sign-ness of types in spec quick test SecsToTM fix proto version name and comment change tzoffset to signed int32 return subscription_id in CreateSubscription api multiple CountPeriods when consume gas FormatInt -> FormatUint handle planID/subscriptionID overflow test count periods add v2.0.0 in CHANGELOG Extend cosmovior integration tests to test v2.0.0 migration
0af05d1
to
be24f1f
Compare
37f223f
to
47923ff
Compare
Solution:
- implement basic calendar and crontab logic
- implement the module
👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻
PR Checklist:
make
)make test
)go fmt
)golangci-lint run
)go list -json -m all | nancy sleuth
)Thank you for your code, it's appreciated! :)
This change is