-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
add pre_validate #109
Conversation
@@ -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()))), |
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 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?
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 @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.
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.
also allowed us to remove our helpers for it and just use the mock api.
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.
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).
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.