-
Notifications
You must be signed in to change notification settings - Fork 455
feat(gnoland): genesis tx metadata + chain replay at initial height #5489
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
Open
moul
wants to merge
15
commits into
master
Choose a base branch
from
feat/genesis-tx-metadata
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ccc49cb
feat(gnoland): support chain upgrade genesis replay with original cha…
33b17e1
feat(tm2): add InitialHeight to GenesisDoc for chain upgrades
moul 9e6dd7f
feat(gnoland): improve hardfork genesis replay mechanism
moul 773a01c
test(tm2): add coverage for GenesisDoc.InitialHeight in consensus rep…
moul f67f3ca
chore(adr): rename ADR to pr5489
moul 5801781
feat(gnoland): replace OriginalChainID with PastChainIDs allowlist
moul 0ae7333
fix(gnoland): only override genesis tx timestamp when metadata.Timest…
moul beda29e
test(gnoland): add isPastChainID unit tests + multi-chain replay test
moul aec7ff6
Merge branch 'master' into feat/genesis-tx-metadata
moul a19bae5
fix(gnoland): gofmt/goimports formatting in app_test.go
moul b4e87a7
fix(test): use single account with correct seq for multi-chain replay…
moul 28502eb
fix: address tbruyelle review comments on PR #5489
moul 9fca49a
fix(blockchain): allow empty block store when InitialHeight > 1
moul 5d0e278
fix(tm2): support InitialHeight > 1 across consensus, state, store an…
moul d9360e2
Merge branch 'master' into feat/genesis-tx-metadata
moul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
gno.land/adr/pr5489_genesis_tx_metadata_initial_height.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # ADR: Genesis TX Metadata and Initial Height for Chain Upgrades | ||
|
|
||
| ## Context | ||
|
|
||
| Chain hard forks require replaying historical transactions in a new chain's | ||
| genesis. Historical transactions were signed with the old chain's ID; during | ||
| genesis replay the ante handler must verify signatures against the chain ID | ||
| that was in effect when the tx was originally executed. | ||
|
|
||
| A chain may go through multiple upgrades — a genesis could contain transactions | ||
| originating from several past chains (e.g. `gnoland1` and `gnoland-1`). Using | ||
| a single `OriginalChainID` field is fragile: it assumes all historical txs come | ||
| from one chain. Instead, we use a `PastChainIDs` allowlist and a per-tx | ||
| `ChainID` so each transaction is verified against its own originating chain ID. | ||
|
|
||
| ## Decision | ||
|
|
||
| ### `GnoTxMetadata` extensions | ||
|
|
||
| Three fields on `GnoTxMetadata` (populated by tx-archive export): | ||
|
|
||
| - **`Timestamp`** (`int64`): Unix timestamp of the original block. When | ||
| non-zero, overrides the block header time during replay. Zero means "use | ||
| the genesis block time" — it never clobbers the header with Unix epoch. | ||
| - **`BlockHeight`** (`int64`): Original block height of the tx. When > 0, | ||
| the context's block header height is set to this value during replay, and | ||
| the tx goes through the full ante handler (real sig verification, account | ||
| numbers, sequences). | ||
| - **`ChainID`** (`string`): Originating chain ID. Used for per-tx chain ID | ||
| override during replay if `ChainID` is in `GnoGenesisState.PastChainIDs`. | ||
|
|
||
| ### `GnoGenesisState` extensions | ||
|
|
||
| Two new fields on `GnoGenesisState`: | ||
|
|
||
| - **`PastChainIDs`** (`[]string`): Allowlist of chain IDs from which | ||
| historical transactions originated. Only chain IDs present in this slice | ||
| can override the context chain ID during replay. Empty = no overrides. | ||
| - **`InitialHeight`** (`int64`): Informational field for tooling. Records the | ||
| block height the new chain should start from. The actual enforcement is at | ||
| the consensus layer via `GenesisDoc.InitialHeight`; this field is not read | ||
| by the app during InitChain. | ||
|
|
||
| ### `GenesisDoc.InitialHeight` (tm2) | ||
|
|
||
| Added to `tm2/pkg/bft/types.GenesisDoc`. When > 1, the consensus `Handshaker` | ||
| sets `state.LastBlockHeight = InitialHeight - 1` after `InitChain`, so the | ||
| first produced block has height `InitialHeight`. Validated to be non-negative. | ||
|
|
||
| ### How genesis replay works | ||
|
|
||
| 1. Genesis txs **without** metadata (or `BlockHeight = 0`) → current genesis | ||
| mode: package deploys, infinite gas, auto-account creation, no sig | ||
| verification. | ||
| 2. Genesis txs **with** `metadata.BlockHeight > 0` → normal mode: full sig | ||
| verification, real account numbers and sequences. | ||
| 3. Chain ID override applies only when all three conditions hold: | ||
| `BlockHeight > 0` AND `metadata.ChainID != ""` AND | ||
| `metadata.ChainID ∈ PastChainIDs`. | ||
| 4. Timestamp override applies when `metadata.Timestamp != 0`. | ||
| 5. After `InitChain`, the consensus layer reads `GenesisDoc.InitialHeight` and | ||
| advances `state.LastBlockHeight` so blocks start at the correct height. | ||
|
|
||
| ### Key properties | ||
|
|
||
| - Standard genesis txs (package deployments, etc.) are unaffected. | ||
| - Unrecognised chain IDs are never silently overridden — they fail as expected. | ||
| - A genesis spanning multiple past chains works: each tx uses its own chain ID. | ||
| - All new fields use `omitempty`; existing genesis files are unaffected. | ||
|
|
||
| ## Alternatives considered | ||
|
|
||
| 1. **Re-sign all transactions**: Requires access to all private keys. Not | ||
| feasible. | ||
| 2. **Skip sig verification entirely**: Reduces security guarantees. | ||
| 3. **Single `OriginalChainID string`**: Simpler but fragile — assumes all | ||
| historical txs come from one chain. Breaks for multi-hop upgrades | ||
| (chain A → chain B → chain C). | ||
| 4. **State-level override**: `OriginalChainID` applied uniformly to all | ||
| historical txs. `PastChainIDs` + per-tx `ChainID` is more precise: each tx | ||
| is verified against its own origin. | ||
|
|
||
| ## Consequences | ||
|
|
||
| - Genesis files for chain upgrades will be larger (all historical txs with | ||
| metadata). | ||
| - `InitialHeight` is enforced at the consensus layer (`GenesisDoc.InitialHeight` | ||
| → `Handshaker` → `state.LastBlockHeight`). `GnoGenesisState.InitialHeight` | ||
| is informational only — it is not read during `InitChain`. | ||
| - Future upgrades from `gnoland-1` to `gnoland-2` can set | ||
| `PastChainIDs: ["gnoland1", "gnoland-1"]` to replay the full history. | ||
|
|
||
| ## Open items | ||
|
|
||
| - Account number preservation: accounts are auto-assigned during balance | ||
| initialization. If the old chain had different account numbers, some txs | ||
| may fail replay. Workaround: order genesis balances so account numbers | ||
| align with the original chain. | ||
| - End-to-end test with a real chain halt → export → genesis assembly → | ||
| new chain start. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.