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

Parameter JSON serialization must be deterministic #1614

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

msmania
Copy link
Contributor

@msmania msmania commented Oct 1, 2024

This is a fix for a regression introduced by Per-chain RTTM (#1580). When we store a map-type parameter, we use Codec.MarshalJSON that doen't guarantee the order of fields in a map. This causes consensus failure because a different order of fields in the parameter store generates a different merkle tree (= AppHash), resulting in chainhalt.

The proposed fix is to canonicalize the marshaled bytes by calling MustSortJSON before storing it in the tree.

Changing Subspace.Set is enough and a change in Subspace.SetWithSubkey won't be necessary because it's not used from anywhere, but we should keep consistency.

reviewpad:summary

This is a fix for a regression introduced by Per-chain RTTM (#1580).
When we store a map-type parameter, we use `Codec.MarshalJSON` that
doen't guarantee the order of fields in a map.  This causes consensus
failure because a different order of fields in the parameter store
generates a different merkle tree (= AppHash).

The proposed fix is to canonicalize the marshaled bytes by calling
`MustSortJSON` before storing it in the tree.
@msmania msmania added the bug Something isn't working label Oct 1, 2024
@msmania msmania requested a review from Olshansk October 1, 2024 23:59
@msmania msmania self-assigned this Oct 1, 2024
Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

@msmania LGTM and we can merge it as is.

In a followup PR, can we also tend to

  1. Fixing this: https://github.com/pokt-network/pocket-core/blob/staging/x/gov/keeper/subspace.go#L216

  2. Migrating the recovery guide to docs: https://www.notion.so/Recovery-guide-641ec21aead74cae806166f5f9e61394

@msmania msmania merged commit 003a959 into staging Oct 2, 2024
3 of 4 checks passed
@msmania msmania deleted the toshi/param-serialization branch October 2, 2024 01:54
msmania added a commit that referenced this pull request Oct 2, 2024
Due to a consensus breaking change to fix a regression in RC-0.11.1
(#1614), this patch is upgrading the protocol version to RC-0.12.0. That
regression caused the chainhalt in the testnet at height block. We're
rolling back the testnet to recover it. This version bump helps to make
sure all validators are runing the latest version.

reviewpad:summary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants