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

add pre_validate #109

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

add pre_validate #109

wants to merge 10 commits into from

Conversation

Art3miX
Copy link
Contributor

@Art3miX Art3miX commented Nov 24, 2024

To mock the api used in contracts, we are using the MockApi type from the cosmwasm_std testing module, the api is only used to verify addresses, so we only need to provide the prefix and the MockApi should be working correctly.

The other big change is that we can't validate the config before we update the config with the addresses instead of ids of the accounts, so now instead of instantiating a library right after we change the config, we first loop over libraries and change the config for all of them, and pre_validate them, and then we loop over libraries again and instantiate them.
This is better because now before we instantiate any library, we first check them all.

To optimize even more, we might want to move the processor and authorization instantiation to after we validate the libraries, this way we will have a complete separation between "setup" step and "instantiate" step.

@Art3miX Art3miX linked an issue Nov 24, 2024 that may be closed by this pull request
program-manager/src/library.rs Outdated Show resolved Hide resolved
program-manager/src/domain/cosmos_cw.rs Outdated Show resolved Hide resolved
@Art3miX Art3miX requested a review from stiiifff November 26, 2024 09:53
@@ -133,6 +134,8 @@ impl CosmosCosmwasmConnector {
code_ids: code_ids.clone(),
chain_name: chain_info.name.clone(),
prefix: chain_info.prefix.clone(),
api: cosmwasm_std::testing::MockApi::default()
.with_prefix(Box::leak(Box::new(chain_info.prefix.clone()))),
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't think of a way where this can go wrong but it'd be nice to add some comments about why Box::leak is fine here. Guess we could also have a chain prefix enum (with to/from string impl) which would make it static so we wouldn't need to deal with boxing like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @bekauz and @stiiifff
We have a weird play with the connectors, because they are not cached for the entire program, because the manager is not a program, rather a library, so they are cached for the functions (init , update, migrate).
This was leaking the prefix on every time we call a function, not much, and can easily fixed with a server restart, but still, it is a leak.

I just copied the MockApi from cosmwas_std, and changed the api to accept String instead of the static str, which doesn't leak memory now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also allowed us to remove our helpers for it and just use the mock api.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to add a comment mentioning from which repo the code was copied, as well as which tag / commit. Also, add a license header to the file (from the original project).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use pre_validate of libraries in manager
3 participants