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

fix: bug on oracle fetching #1750

Merged
merged 12 commits into from
Mar 1, 2024
Merged

Conversation

mustermeiszer
Copy link
Collaborator

@mustermeiszer mustermeiszer commented Feb 29, 2024

Description

The current oracle does check local representation of wrongly.

Changes and Descriptions

  • Fix checking local representation of local to variant, instead of variant to local
  • Add integration tests for the OracleRatioProvider

Checklist:

  • I have added Rust doc comments to structs, enums, traits and functions
  • I have made corresponding changes to the documentation
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works

@mustermeiszer
Copy link
Collaborator Author

@wischli this must go in before #1749

Comment on lines 84 to 91
assert_eq!(
orml_asset_registry::Metadata::<T>::get(LocalUSDC.id()),
None
);
assert_eq!(
orml_asset_registry::Metadata::<T>::get(DomainUSDC.id()),
None
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@wischli @lemunozm these assertions are triggered. Why on earth should this storage be populated already? I either am looking at the reason without seeing it, or something is really off here.

Copy link
Contributor

@lemunozm lemunozm Mar 1, 2024

Choose a reason for hiding this comment

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

Could this be due to the migration being performed before initializing the tests? Our migration populates the state with those currencies IIRC

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh man. That could be. Haha. But then it is not working as intended. As the local representation is missing on asset 100_001. I will try to use different ids.

Thanks @lemunozm!

Copy link
Contributor

@wischli wischli Mar 1, 2024

Choose a reason for hiding this comment

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

But here we are using id 100_0001 instead of 100_001 LpEthUsdc. I suppose the local asset id of 1 is the issue then. Compiling right now with my cherry-pick for disabling migrations in std: 0e53752

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, works now! Eagle eye @lemunozm 🎯

Copy link
Contributor

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

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

LGTM. I think the currencies testing API now is more versatile.

Maybe we could extend the integration-tests with some pallet-token-mux call to ensure the whole use case is working well

Comment on lines 90 to 92
transferability: CrossChainTransferability::Xcm(XcmMetadata {
fee_per_second: Some(1_000),
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering why Usd6 has this property but Usd12 and Usd18 do not. Could we use the same for all of them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just copy pasted everything. Not sure, why it was there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we want to have default transferability here instead?

10u128.pow(self.decimals())
}

fn symbol(&self) -> &'static str;
Copy link
Contributor

Choose a reason for hiding this comment

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

Most of the time, we do not care about the symbol for testing. Could we use a default method here with some random/empty string? Maybe "Unnamed" or so.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed!

@wischli wischli added the I2-bug The code fails to follow expected behaviour. label Mar 1, 2024
@wischli wischli added this to the Centrifuge 1025 milestone Mar 1, 2024
@mustermeiszer mustermeiszer added the D0-ready Pull request can be merged without special precaution and notification. label Mar 1, 2024
@mustermeiszer
Copy link
Collaborator Author

Maybe we could extend the integration-tests with some pallet-token-mux call to ensure the whole use case is working well

I agree that this would be useful. But I do not have time for that. I am testing everything in demo at the moment. Thats also where I found this issue. I think the best would be to merge #1720 and then write integration test verifying the whole flow...

@mustermeiszer mustermeiszer enabled auto-merge (squash) March 1, 2024 09:26
Copy link
Contributor

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

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

Just want to change one thing that I think it's important to modify/clarify.

Everything else looks great!

Comment on lines 94 to 96
#[cfg(feature = "std")]
pub type UpgradeAltair1034 = ();

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe there exists a way to tune RuntimeEnv to avoid this issue from the tests? I do not like adding this addition to the runtime too much with the aim of avoiding migrations in testing. Future readers of this will not know why this is so, and we can be subject to unexpected behavior in the future. I would add a comment at least explain why this

Copy link
Contributor

Choose a reason for hiding this comment

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

Another option is tweaking the block creation in RuntimeEnv somehow to skip the migration. Not sure if this is something easy to do

Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is my forced change which should not have been pushed to this branch in the first place, I will just revert it. However, it improves integration test time because it blocks migrations for each node we spawn.

What unexpected behaviour are you fearing here @lemunozm? I think it is unexpected that migrations run for integration tests which is fixed this way. It's not the nicest solution but it does the job quickly without imposing any risk.

Copy link
Collaborator Author

@mustermeiszer mustermeiszer Mar 1, 2024

Choose a reason for hiding this comment

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

Fixed in 4f41f24

Copy link
Contributor

Choose a reason for hiding this comment

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

However, it improves integration test time because it blocks migrations for each node we spawn.

Good point!

What unexpected behaviour are you fearing here @lemunozm?

Could some uses of the node underlying it exist that compile the runtime as std and where do we expect some kind of migration, maybe some migration testing or so? Probably not now but it scared me 🙏🏻

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed in 4f41f24

Love the solution! Maybe this can even be ported to fudge to avoid migrations there too (not mandatory for this PR)

wischli
wischli previously approved these changes Mar 1, 2024
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

The Usd6 still has XCM transferability enabled. Apart from that LGTM!

Comment on lines +70 to +76
// NOTE: Setting the current on-chain runtime version to the latest one, to
// prevent running migrations
parachain_ext.execute_with(|| {
frame_system::LastRuntimeUpgrade::<T>::put(LastRuntimeUpgradeInfo::from(
<T as frame_system::Config>::Version::get(),
))
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome change, thanks for that!

Comment on lines 90 to 92
transferability: CrossChainTransferability::Xcm(XcmMetadata {
fee_per_second: Some(1_000),
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we want to have default transferability here instead?

@mustermeiszer
Copy link
Collaborator Author

The Usd6 still has XCM transferability enabled. Apart from that LGTM!

transferability: CrossChainTransferability::Xcm(XcmMetadata {
fee_per_second: Some(1_000),
}),

That is comming from main, so I am not keen on changing that here. @lemunozm your commit apparently.

@lemunozm
Copy link
Contributor

lemunozm commented Mar 1, 2024

TBH, I do not remember. Maybe a copy-paste from another place. I would put there what you think is cleaner/defaulted/simpler (probably what @wischli said)

@lemunozm
Copy link
Contributor

lemunozm commented Mar 1, 2024

So we know now the reason 😆, we needed it for the proxy cross-change tests.

I think this is a change added by @cdamian (who could explain the whys better) in the PR I opened about proxies, that's why git blame tell about me. Maybe we can create a currency in our own proxy tests for cross-chain things with the required metadata, using the new way of doing it. WDYT?

@mustermeiszer
Copy link
Collaborator Author

@lemunozm fixed. Can you approve if you are happy?

@mustermeiszer
Copy link
Collaborator Author

Will force merge as @wischli approved and @lemunozm is off the next week. I anyways addressed all issues from Luis.

@mustermeiszer mustermeiszer disabled auto-merge March 1, 2024 15:41
@mustermeiszer mustermeiszer merged commit 472d1af into main Mar 1, 2024
9 checks passed
@wischli wischli deleted the fix/oracle-local-representation-bug branch March 1, 2024 16:12
@lemunozm
Copy link
Contributor

lemunozm commented Mar 1, 2024

Sorry for my late review!

Really cool the new register_currency() method 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D0-ready Pull request can be merged without special precaution and notification. I2-bug The code fails to follow expected behaviour.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants