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 JailMsg inconsistencies #20

Closed
ethanfrey opened this issue Jan 13, 2022 · 5 comments · Fixed by #39
Closed

Fix JailMsg inconsistencies #20

ethanfrey opened this issue Jan 13, 2022 · 5 comments · Fixed by #39
Assignees

Comments

@ethanfrey
Copy link
Contributor

This arose from https://github.com/confio/tgrade/pull/231/files#diff-8db14e10b9ef925e19d3a5efe4e78d5557798674beff468817945ab6a31ec08aR93-R99

When querying JailingPeriod, we now get:

"jailed_until":{"forever":{}}
"jailed_until":{"until":"1587556801000000000"}}}

However, when we make a JailMsg we produce:

"duration": "forever"
"duration": {"duration": "1587556801000000000"}

The first one is annoying to parse in other languages (easiest if everything is a struct or all strings, don't mix). The second one is a bit of stutter and inconsistent with the Jailing Period.

I propose using the same JSON format for both of them, so JailingDuration would look like:

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum JailingDuration {
    Until(Duration),
    Forever{},
}
@maurolacy
Copy link
Contributor

maurolacy commented Jan 13, 2022

It's tempting to ditch the 'forever' and return to the '0 means forever' format.

@ethanfrey
Copy link
Contributor Author

I agree. I believe multiple devs were arguing against the "impurity" of it.

I think we need to remember with these exposed types, that we are designing a JSON API, not a Rust / Go / etc struct, so we need to work on cleanest interchange format.

I am open to other approaches here, but the current maps very poorly to JSON (and Go)

@ueco-jb ueco-jb self-assigned this Jan 18, 2022
@ueco-jb
Copy link

ueco-jb commented Jan 18, 2022

I believe multiple devs were arguing against the "impurity" of it.

You've made some comments on review that were listened to. No one else, at least not in my reviews nor messages that I've read.

@maurolacy

return to the '0 means forever' format.

Since currently we keep JAIL as map of address and basically Expiration (currently wrapped around JailingPeriod):

pub const JAIL: Map<&Addr, Expiration> = Map::new("jail");

and if we stick to 0, then we'd have to compute actuall expiration every read.
https://github.com/confio/poe-contracts/blob/main/contracts/tgrade-valset/src/contract.rs#L227
this is basically:

let expiration = duration.after(&env.block);

so currently 0 would mean that prisoner is instantly free. To work around that, we'd have to keep only jail time in map (so Duration instead of Expiration) - but then we lose information when jail started. That would make us keep extra information..

Summary:

  1. JAIL keeps info about Expiration.
  2. Expiration cannot be 0.
  3. If JAIL doesn't keep Expiration but Duration (with valid 0==infinity), how does one tell when Jail started?

@ethanfrey
Copy link
Contributor Author

ethanfrey commented Jan 21, 2022

@ueco-jb good point.
Let's not collapse down to 0.

@maurolacy
Copy link
Contributor

The solution to that would be to use Forever internally, but map it to 0 on the API. Just saying. I'm OK with keeping it as it is now, particularly since the maps are already implemented on the other side.

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 a pull request may close this issue.

3 participants