Skip to content

Commit

Permalink
refactor(core, proto)!: define app genesis state in proto (#1346)
Browse files Browse the repository at this point in the history
## Summary
Defines `astria.protocol.genesis.v1alpha1.GenesisAppState`, replacing
the Rust-as-JSON definition.

## Background
All protocol relevant Astria types are supposed to be defined in
Astria's protobuf spec. With
#1285 having redefined the memos
as protobuf message, this patch migrates the last type to protobuf spec.

## Changes
- Define `astria.protocol.genesis.v1alpha1.GenesisAppState` and related
protobuf messages
- Remove the `astria-core::sequencer::GenesisState` module
- Update Sequencer in terms of the protobuf type
- Update all charts and snapshots (especially the genesis template)

## Testing
All tests have been updated to use the new types, including snapshot
tests. The genesis state is only read at `init-chain` and does not
affect the evaluation of the state machine. Hence no tests should change
as long as the same data is passed in (which is reflected by
`tests-breaking-changes` leading to the same hash).

## Breaking Changelist
This is a breaking change because an old sequencer would not understand
a new (json-formatted) genesis app state and vise versa.

## Related issues
Closes #1347
  • Loading branch information
SuperFluffy authored Aug 22, 2024
1 parent 10b196a commit acff940
Show file tree
Hide file tree
Showing 29 changed files with 2,077 additions and 657 deletions.
2 changes: 1 addition & 1 deletion charts/sequencer/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.19.1
version: 0.20.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
Expand Down
18 changes: 9 additions & 9 deletions charts/sequencer/files/cometbft/config/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
"app_state": {
"native_asset_base_denomination": "{{ .Values.genesis.nativeAssetBaseDenomination }}",
"fees": {
"transfer_base_fee": {{ .Values.genesis.fees.transferBaseFee }},
"sequence_base_fee": {{ .Values.genesis.fees.sequenceBaseFee }},
"sequence_byte_cost_multiplier": {{ .Values.genesis.fees.sequenceByteCostMultiplier }},
"init_bridge_account_base_fee": {{ .Values.genesis.fees.initBridgeAccountBaseFee }},
"bridge_lock_byte_cost_multiplier": {{ .Values.genesis.fees.bridgeLockByteCostMultiplier }},
"bridge_sudo_change_fee": {{ .Values.genesis.fees.bridgeSudoChangeFee }},
"ics20_withdrawal_base_fee": {{ .Values.genesis.fees.ics20WithdrawalBaseFee }}
"transfer_base_fee": {{ include "sequencer.toUint128Proto" .Values.genesis.fees.transferBaseFee }},
"sequence_base_fee": {{ include "sequencer.toUint128Proto" .Values.genesis.fees.sequenceBaseFee }},
"sequence_byte_cost_multiplier": {{ include "sequencer.toUint128Proto" .Values.genesis.fees.sequenceByteCostMultiplier }},
"init_bridge_account_base_fee": {{ include "sequencer.toUint128Proto" .Values.genesis.fees.initBridgeAccountBaseFee }},
"bridge_lock_byte_cost_multiplier": {{ include "sequencer.toUint128Proto" .Values.genesis.fees.bridgeLockByteCostMultiplier }},
"bridge_sudo_change_fee": {{ include "sequencer.toUint128Proto" .Values.genesis.fees.bridgeSudoChangeFee }},
"ics20_withdrawal_base_fee": {{ include "sequencer.toUint128Proto" .Values.genesis.fees.ics20WithdrawalBaseFee }}
},
"allowed_fee_assets": [
{{- range $index, $value := .Values.genesis.allowedFeeAssets }}
{{- if $index }},{{- end }}
"{{ $value }}"
{{- end }}
],
"ibc_params": {
"ibc_parameters": {
"ibc_enabled": {{ .Values.genesis.ibc.enabled }},
"inbound_ics20_transfers_enabled": {{ .Values.genesis.ibc.inboundEnabled }},
"outbound_ics20_transfers_enabled": {{ .Values.genesis.ibc.outboundEnabled }}
Expand All @@ -30,7 +30,7 @@
{{- if $index }},{{- end }}
{
"address": {{ include "sequencer.address" $value.address }},
"balance": {{ toString $value.balance | replace "\"" "" }}
"balance": {{ include "sequencer.toUint128Proto" ( toString $value.balance | replace "\"" "" ) }}
}
{{- end }}
],
Expand Down
4 changes: 4 additions & 0 deletions charts/sequencer/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ name: {{ .Values.moniker }}-sequencer-metrics
{{/* New sequencer address */}}
{{- define "sequencer.address"}}{ "bech32m": "{{ . }}" }
{{- end }}

{{/* uint64 fee converted to a astria proto Uint128 with only lo set */}}
{{- define "sequencer.toUint128Proto"}}{ "lo": {{ . }} }
{{- end }}
2 changes: 1 addition & 1 deletion crates/astria-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ base64-serde = ["dep:base64-serde"]
brotli = ["dep:brotli"]

[dev-dependencies]
astria-core = { path = ".", features = ["serde"] }
insta = { workspace = true, features = ["json"] }
rand = { workspace = true }
tempfile = { workspace = true }
astria-core = { path = ".", features = ["serde"] }
19 changes: 18 additions & 1 deletion crates/astria-core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ use zeroize::{
ZeroizeOnDrop,
};

use crate::primitive::v1::ADDRESS_LEN;
use crate::primitive::v1::{
Address,
AddressError,
ADDRESS_LEN,
};

/// An Ed25519 signing key.
// *Implementation note*: this is currently a refinement type around
Expand Down Expand Up @@ -82,6 +86,19 @@ impl SigningKey {
pub fn address_bytes(&self) -> [u8; ADDRESS_LEN] {
self.verification_key().address_bytes()
}

/// Attempts to create an Astria bech32m `[Address]` with the given prefix.
///
/// # Errors
/// Returns an [`AddressError`] if an address could not be constructed
/// with the given prefix. Usually if the prefix was too long or contained
/// characters not allowed by bech32m.
pub fn try_address(&self, prefix: &str) -> Result<Address, AddressError> {
Address::builder()
.prefix(prefix)
.array(self.address_bytes())
.try_build()
}
}

impl Debug for SigningKey {
Expand Down
126 changes: 126 additions & 0 deletions crates/astria-core/src/generated/astria.protocol.genesis.v1alpha1.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit acff940

Please sign in to comment.