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

Optimize validators storage #61

Merged
merged 18 commits into from
Feb 3, 2022
Merged

Conversation

maurolacy
Copy link
Contributor

@maurolacy maurolacy commented Feb 1, 2022

Closes #42.

After a lot of wrestling, added a couple integration tests to see Item fail.

I was determined to do this as part of tgrade-valset integration tests, as I think this might be useful in the future. That required adding the "tgrade" feature to cosmwasm-vm. Will publish that in a cosmwasm PR (CosmWasm/cosmwasm#1208) and we decide what to do with it there.

Creating as Draft, as this is just the failure case at the moment. Will work in the proposed fix next.

Of course, tests will not pass until a new cosmwasm-vm supporting the "tgrade" feature is released.

@maurolacy maurolacy requested review from ethanfrey and hashedone and removed request for ethanfrey February 1, 2022 16:20
Comment on lines +379 to +387
let admin_res = ADMIN.get(deps.as_ref());
if let Err(err) = admin_res {
let not_found = matches!(err, StdError::NotFound { .. });
if !not_found {
return Err(ContractError::AdminError(AdminError::NotAdmin {}));
}
} else {
return Err(ContractError::AdminError(AdminError::NotAdmin {}));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's probably a simpler / nicer way to do this.

Copy link
Contributor

Choose a reason for hiding this comment

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

we should add such method to admin.

Copy link
Contributor

Choose a reason for hiding this comment

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

wait... if this is only for tests, we do not want this in production build at all.
how about feature-gating it with #[cfg(features = "integration")] and you make such a build for the wasm used in integration test? Then no worries about it as this code path isn't in production at all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Will do this tomorrow.

Copy link
Contributor Author

@maurolacy maurolacy Feb 4, 2022

Choose a reason for hiding this comment

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

Forgot to remove this in the first iteration.

Then, tried to do it in a follow-up, but hit dependency / feature problems with compiling the wasm using the integration feature.

I'll post my working copy and we can see if there's a way around those problems (other than keeping / removing the entry point entirely).

Update: See #77.

@maurolacy maurolacy force-pushed the 42-optimize-validators-storage branch from 48f42d5 to de18d26 Compare February 2, 2022 18:03
@maurolacy maurolacy marked this pull request as ready for review February 2, 2022 18:23
Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Looks good.

Please make all this integration test code feature gated.
Also ensure we have longer addresses, maybe 1 with 20 byte as bech32, other as 32 byte

Comment on lines +379 to +387
let admin_res = ADMIN.get(deps.as_ref());
if let Err(err) = admin_res {
let not_found = matches!(err, StdError::NotFound { .. });
if !not_found {
return Err(ContractError::AdminError(AdminError::NotAdmin {}));
}
} else {
return Err(ContractError::AdminError(AdminError::NotAdmin {}));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

we should add such method to admin.

Comment on lines +379 to +387
let admin_res = ADMIN.get(deps.as_ref());
if let Err(err) = admin_res {
let not_found = matches!(err, StdError::NotFound { .. });
if !not_found {
return Err(ContractError::AdminError(AdminError::NotAdmin {}));
}
} else {
return Err(ContractError::AdminError(AdminError::NotAdmin {}));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

wait... if this is only for tests, we do not want this in production build at all.
how about feature-gating it with #[cfg(features = "integration")] and you make such a build for the wasm used in integration test? Then no worries about it as this code path isn't in production at all

@maurolacy maurolacy force-pushed the 42-optimize-validators-storage branch from 189a67b to db375ac Compare February 3, 2022 07:41
@maurolacy maurolacy added the breaking Breaking changes (API or State) label Feb 3, 2022
Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

One last change requested, so we get proper test numbers

use tgrade_valset::msg::ExecuteMsg;
use tgrade_valset::state::ValidatorInfo;

// Copied from test_helpers
// returns a list of addresses that are set in the tg4-stake contract
fn addrs(count: u32) -> Vec<String> {
(1..=count).map(|x| format!("operator-{:03}", x)).collect()
(1..=count)
.map(|x| bech32::encode("tgrade", format!("operator-{:03}", x).to_base32(), Variant::Bech32).unwrap())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is getting closer, but not realistic.

The two cases I refer to are
(1) 20 unencoded bytes before the bech32
(2) 32 unencoded bytes before the bech32

I would replace format!("operator-{:03}", x).to_base32() with
format!("20-byte-operator-{:03}", x) which is 20 bytes

I guess we can skip the 32 byte variant for now as it is unlikely anyone uses contracts, but it would be interesting to test as a true upper limit

@maurolacy maurolacy added the breaking-state Storage breaking: Requires migration label Feb 3, 2022
@maurolacy maurolacy merged commit 182afd0 into main Feb 3, 2022
@maurolacy maurolacy deleted the 42-optimize-validators-storage branch February 3, 2022 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaking changes (API or State) breaking-state Storage breaking: Requires migration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

valset: Optimize VALIDATORS storage
2 participants