-
Notifications
You must be signed in to change notification settings - Fork 85
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
Loans: Moment as Seconds & Millis explicitly #1575
Conversation
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.
Do you in the same run change it for all pallets?
Until I get exhausted 😆 |
ActivePricing::External(pricing) => Ok(now | ||
>= pricing | ||
.last_updated(pool_id)? | ||
.into_seconds() | ||
.ensure_add(*secs)?), |
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 was actually a bug. Test were unable to catch this, because we were treating the oracle as seconds too.
Now, since the Moment
type coming from the oracles and Seconds
from loans are different types we are protected. This kind of issue can be checked now at compile time, forcing you to call into_seconds()
to convert among them.
I think is not a severe bug, but not sure if we need to make an upgrade to this.
cc @hieronx @mustermeiszer
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 was the bug here? Oracles are actually millies?
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.
Assuming we hit this, this means
now
is given in secondslast_updated
is given in milli-secondssecs
is given in seconds
The widest false positive in the Ok(bool)
logic we can get will then be at most 0.999
seconds, and as we are not caring for that in the compatrison we will anyways never hit that, right?
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, orml_oracle
sets the timestamp as milliseconds.
Exactly, so right now, this trigger can not be triggered.
/// Type to represent milliseconds | ||
pub type Millis = u64; | ||
|
||
/// Type to represent seconds | ||
pub type Seconds = u64; |
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.
An interesting improvement for this would be having them as wrapper types to avoid mixing them in the runtimes. By now, for pallets that use both as pallet-loans
, having one by Config
solves this issue, forcing to convert them though into_seconds()
This is finished and can be merged |
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.
Thanks! That was tedious.
|
||
impl IntoSeconds for Millis { | ||
fn into_seconds(self) -> Seconds { | ||
self / 1000 |
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.
Safe-math?
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.
A division by 1000
can never crash
ActivePricing::External(pricing) => Ok(now | ||
>= pricing | ||
.last_updated(pool_id)? | ||
.into_seconds() | ||
.ensure_add(*secs)?), |
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 was the bug here? Oracles are actually millies?
ActivePricing::External(pricing) => Ok(now | ||
>= pricing | ||
.last_updated(pool_id)? | ||
.into_seconds() | ||
.ensure_add(*secs)?), |
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.
Assuming we hit this, this means
now
is given in secondslast_updated
is given in milli-secondssecs
is given in seconds
The widest false positive in the Ok(bool)
logic we can get will then be at most 0.999
seconds, and as we are not caring for that in the compatrison we will anyways never hit that, right?
Thanks for the review! As a note aside, related to this PR #1380, probably |
Description
Fixes: #1360
Instead of having an agnostic
Moment
type, this PR modifies the codebase to reason aboutSeconds
orMillis
and avoid mixing them in pallets.Changes and Descriptions
Seconds
andMillis
types (by now, there are incfg_traits
, but all this machinery should be moved to a futurecfg_utils
: Internal dependencies organization #1380).Moment
type, which is a too-open name. The name is still used for traits agnostic of the time unit.pallet-loans
Checklist
pallet-loans
implpallet-loans
testspallet-interest-accrual
implpallet-pools
implpallet-pools
testspermission
types => Because internally it retrived seconds, I modify them to use directly the newSeconds
type. But I'm not sure if a more correct solution would be to make permission types more independent from secs. Although it would require a refactor to use it from pallet-pool-system correctly I guess. By now, I think usingSeconds
directly simplifies things.pallet-liquidity-pools
pallet-registry