Skip to content

Commit

Permalink
Manifest chain id update
Browse files Browse the repository at this point in the history
  • Loading branch information
MissingNO57 committed Oct 7, 2024
1 parent 4b75271 commit 77f538c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
15 changes: 9 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func New(

app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
// register the governance hooks
),
)

Expand Down Expand Up @@ -758,9 +758,6 @@ func getNetworkInfo(app *App, ctx *sdk.Context, manifest *UpgradeManifest, expec
return nil, fmt.Errorf("network info not found for chain id: %s", ctx.ChainID())
}

manifest.MergeSourceChainID = expectedChainIdOfMergeSourceGenesis
manifest.DestinationChainID = ctx.ChainID()

return networkInfo, nil
}

Expand All @@ -779,7 +776,7 @@ func LoadAndParseMergeSourceInputFiles(app *App, ctx *sdk.Context, manifest *Upg

cudosConfig := NewCudosMergeConfig(networkInfo.CudosMerge)

genesisData, err := parseGenesisData(*cudosJsonData, cudosConfig, manifest)
genesisData, err := parseGenesisData(*cudosJsonData, cudosGenDoc, cudosConfig, manifest)
if err != nil {
return nil, nil, fmt.Errorf("failed to parse genesis data: %w", err)
}
Expand All @@ -792,7 +789,7 @@ func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) {
return app.mm.RunMigrations(ctx, cfg, fromVM)
})

app.UpgradeKeeper.SetUpgradeHandler("v0.14.0", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
app.UpgradeKeeper.SetUpgradeHandler("0.14.0", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {

manifest := NewUpgradeManifest()

Expand All @@ -801,6 +798,12 @@ func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) {
return nil, fmt.Errorf("cudos merge: %w", err)
}

manifest.DestinationChainBlockHeight = cudosGenesisData.blockHeight
manifest.DestinationChainID = cudosGenesisData.chainId

manifest.SourceChainBlockHeight = ctx.BlockHeight()
manifest.MergeSourceChainID = ctx.ChainID()

err = app.DeleteContractStates(ctx, networkInfo, manifest)
if err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion app/upgrade_cudos.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ const (

type GenesisData struct {
totalSupply sdk.Coins
blockHeight int64
chainId string

accounts *OrderedMap[string, *AccountInfo]
contracts *OrderedMap[string, *ContractInfo]
Expand Down Expand Up @@ -246,14 +248,16 @@ func CudosMergeUpgradeHandler(app *App, ctx sdk.Context, cudosCfg *CudosMergeCon
return nil
}

func parseGenesisData(jsonData map[string]interface{}, cudosCfg *CudosMergeConfig, manifest *UpgradeManifest) (*GenesisData, error) {
func parseGenesisData(jsonData map[string]interface{}, genDoc *tmtypes.GenesisDoc, cudosCfg *CudosMergeConfig, manifest *UpgradeManifest) (*GenesisData, error) {
genesisData := GenesisData{}

totalSupply, err := parseGenesisTotalSupply(jsonData)
if err != nil {
return nil, fmt.Errorf("failed to get total supply: %w", err)
}
genesisData.totalSupply = totalSupply
genesisData.blockHeight = genDoc.InitialHeight
genesisData.chainId = genDoc.ChainID

genesisData.contracts, err = parseGenesisWasmContracts(jsonData)
if err != nil {
Expand Down
31 changes: 17 additions & 14 deletions app/upgrade_v_11_4_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ const manifestFilenameBase = "upgrade_manifest.json"

type UpgradeManifest struct {
// Following 2 hash data members are intentionally without `omitempty` parameter in `json:...` decorator
GenesisFileSha256 string `json:"genesis_file_sha256"`
NetworkConfigFileSha256 string `json:"network_config_file_sha256"`
MergeSourceChainID string `json:"merge_source_chain_id"`
DestinationChainID string `json:"destination_chain_id"`
Reconciliation *UpgradeReconciliation `json:"reconciliation,omitempty"`
Contracts *Contracts `json:"contracts,omitempty"`
IBC *UpgradeIBCTransfers `json:"ibc,omitempty"`
Migration *UpgradeMigation `json:"migration,omitempty"`
MoveGenesisBalance *UpgradeMoveGenesisBalance `json:"move_genesis_balance,omitempty"`
Delegate *UpgradeDelegate `json:"delegate,omitempty"`
MoveMintedBalance *UpgradeMoveMintedBalance `json:"move_minted_balance,omitempty"`
VestingCollision *UpgradeVestingCollision `json:"vesting_collision,omitempty"`
MoveDelegations *UpgradeMoveDelegations `json:"move_delegation,omitempty"`
CreatedAccounts *UpgradeCreatedAccounts `json:"created_accounts,omitempty"`
GenesisFileSha256 string `json:"genesis_file_sha256"`
NetworkConfigFileSha256 string `json:"network_config_file_sha256"`
MergeSourceChainID string `json:"merge_source_chain_id"`
DestinationChainID string `json:"destination_chain_id"`
SourceChainBlockHeight int64 `json:"source_chain_block_height"`
DestinationChainBlockHeight int64 `json:"destination_chain_block_height"`

Reconciliation *UpgradeReconciliation `json:"reconciliation,omitempty"`
Contracts *Contracts `json:"contracts,omitempty"`
IBC *UpgradeIBCTransfers `json:"ibc,omitempty"`
Migration *UpgradeMigation `json:"migration,omitempty"`
MoveGenesisBalance *UpgradeMoveGenesisBalance `json:"move_genesis_balance,omitempty"`
Delegate *UpgradeDelegate `json:"delegate,omitempty"`
MoveMintedBalance *UpgradeMoveMintedBalance `json:"move_minted_balance,omitempty"`
VestingCollision *UpgradeVestingCollision `json:"vesting_collision,omitempty"`
MoveDelegations *UpgradeMoveDelegations `json:"move_delegation,omitempty"`
CreatedAccounts *UpgradeCreatedAccounts `json:"created_accounts,omitempty"`
}

func NewUpgradeManifest() *UpgradeManifest {
Expand Down

0 comments on commit 77f538c

Please sign in to comment.