-
Notifications
You must be signed in to change notification settings - Fork 48
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: ADR-004: Application links expiration time #723
Conversation
TODO: - fix migrations - tests
- added tests for appLinkParams - fixed migration errors
- missing benchmarks
Codecov Report
@@ Coverage Diff @@
## master #723 +/- ##
==========================================
- Coverage 82.43% 80.51% -1.93%
==========================================
Files 168 172 +4
Lines 14290 14818 +528
==========================================
+ Hits 11780 11930 +150
- Misses 2023 2380 +357
- Partials 487 508 +21
Continue to review full report at Codecov.
|
fixed some bugs in the expiration time calculation
expiration_time params - fixed sims tests
added bench test workflow
x/profiles/module.go
Outdated
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) { | ||
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { | ||
// TODO should we emit an event for this? | ||
am.keeper.DeleteExpiredApplicationLinks(ctx) |
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.
should we emit some events for this?
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, we should emit one event for each deleted link. I don't know whether it would be better to do this here or inside the DeleteExpiredApplicationLinks
method though
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 think we can follow how we did with other keeper's methods and put it inside the DeleteExpiredApplicationLinks
method.
x/profiles/types/models_params.go
Outdated
DefaultMinDTagLength = sdk.NewInt(3) | ||
DefaultMaxDTagLength = sdk.NewInt(30) | ||
DefaultMaxBioLength = sdk.NewInt(1000) | ||
DefaultAppLinksExpirationTime = time.Hour * 24 * 7 * 4 * 6 // This duration is equal to roughly 5.5 months time in minutes 241920 |
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 took the DefaultUnbondingTime
param as an example:
https://github.com/cosmos/cosmos-sdk/blob/6ea204994443edc7841df4f0dc86ee5b4edc8377/x/staking/types/params.go#L21.
The expiration time default param is a duration of time of roughly 6 months.
Why roughly? Because not all months last the same.
So basically:
DefaultExpirationTime
= 241920 minutes -> 5.5 months -> 168 days.
It's not a definitive default param, I would like to discuss with you what should be a reasonable amount of time before a link expires. IMO, it should not be less than 3 months.
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 set it to be 4382.91 hours considering one mean year has 8765.82 hours (see here). This could give us the duration closes to 6 months
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.
Since we can't sum decimals in time params calculation I've added an ExpirationTimeCorrectionFactor
that I calculated as follow:
- 4382.91 hours are 182 days;
DefaultAppLinksExpirationTime
were 168 days;- 182 - 168 = 14 days = 20160 minutes;
DefaultAppLinksExpirationTime
+ 20160 minutes = 262080 = 5.9835 Months.
added on-chain-upgrade test specs to on-chain-upgrade.yml
.github/workflows/bench.yml
Outdated
@@ -0,0 +1,42 @@ | |||
name: Benchmarks |
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.
This workflow uses benchstat a common go tool for comparing different benchmarks results.
In our case, the workflow will compare the master
branch benchmark's result with the ones of a new PR which is IMO very useful to let us understand if we have introduced a performance regression.
In order to make this properly working, bench tests should be written when we consider it's the case.
…ation-impl' into leonardo/application-links-expiration-impl
Signed-off-by: Riccardo Montagnin <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
I've updated all the code and how the migrations are handled to work best. I would like to ask @dadamu to review the code and also fix the now failing test (it's always the one related to the JSON within the profiles module). Once that's done I think we can merge this |
…application-links-expiration-impl
## Description This PR adds a new workflow to run benchmarks tests during each PR/commit to the master branch. Thanks to @bragaz for the original work done inside #723. --- ### 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... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html) - [ ] included the necessary unit and integration [tests](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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)
Signed-off-by: Riccardo Montagnin <[email protected]>
…application-links-expiration-impl
Signed-off-by: Riccardo Montagnin <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
|
||
i := int64(0) | ||
for ; iterator.Valid(); iterator.Next() { | ||
trimmedPrefixKey := bytes.TrimPrefix(iterator.Key(), types.ExpiringAppLinkTimePrefix) |
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.
Can you add a comment to describe Key()
and Value()
of iterator representing here?
It would be helpful to understand this closure.
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.
Sure, added!
Signed-off-by: Riccardo Montagnin <[email protected]>
b.Run("iterate and delete expired links", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
b.ReportAllocs() | ||
profiles.BeginBlocker(ctx, k) |
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.
This method is out of keeper range, it would be better to have a specified function like DeleteExpiredApplicationLinks
.
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've moved it to be inside the profiles
package as it should be (since it's testing the BeginBlocker
method). I removed the DeleteExpiredApplicationLinks
as in my opinion it was pointless to have that method only so that we could write benchmark tests when we could simply have done it this way
Signed-off-by: Riccardo Montagnin <[email protected]>
return v5.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc, m.keeper.legacyAmino) | ||
} | ||
|
||
// Migrate6to7 migrates from version 6 to 7. | ||
func (m Migrator) Migrate6to7(ctx sdk.Context) error { |
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 am confused the version, v6.MigrateStore
is actually migrating to v6 from v5 although the method is called Migrate6to7
. Is that consensus version different from legacy store version?
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.
That was actually an error within comments themselves. I've now updated them to make it more clear. Generally, the Migrate<X>to<X+1>
calls the v<X>
package that handles the migration from X
to X+1
properly. So in this case Migrate6to7
calls the v6
package that migrates from 6
to 7
(latest version).
The only thing wrong here was the comment on the v6.MigrateStore
function. It migrates from 6
to 7
(and not 5
to 6
as it was written). I've now fixed it
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.
@RiccardoM Thanks for the explanation. But it would be another problem that v6.MigrateStore
actually migrates v5types
to the current type v6
like this.
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.
Yeah, that is because inside the migration from v5
to v6
the types didn't change. So now we have to migrate from v5
to v7
(current version). I've updated the comments to make this more clear
Signed-off-by: Riccardo Montagnin <[email protected]>
@@ -40,14 +40,14 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { | |||
registry.RegisterImplementations((*exported.VestingAccount)(nil), &Profile{}) | |||
registry.RegisterImplementations((*authtypes.GenesisAccount)(nil), &Profile{}) | |||
registry.RegisterInterface( | |||
"desmos.profiles.v2.AddressData", | |||
"desmos.profiles.v3.AddressData", |
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.
Another question related to version. Should we set the version here to consensus version? e.g., desmos.profiles.v7.AddressData
.
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.
As well as the query route. To be like /desmos/profiles/v7/profiles/{user}
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.
No, these types should reflect the Protobuf versioning (which is different from the module consensus versioning). We should update them only when we change the Protobuf definitions, as they change less often than the module consensus version (see from v4 to v5 where we didn't change a single Protobuf version but we had to do a migration to add new keys)
Signed-off-by: Riccardo Montagnin <[email protected]>
Co-authored-by: Paul <[email protected]>
Co-authored-by: Paul <[email protected]>
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.
Ready to go to me.
Description
Closes: #516
Superseeds: #562
This PR introduce a new field
ExpirationTime
in theAppLinks
object.It will allow to automatically delete app links when they expires.
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
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...
!
in the type prefix if API or client breaking change