Skip to content

Commit

Permalink
chore: review feedback
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Olshansky <[email protected]>
  • Loading branch information
bryanchriswhite and Olshansk committed Feb 10, 2025
1 parent efb6d49 commit 945c915
Show file tree
Hide file tree
Showing 15 changed files with 1,081 additions and 735 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions cmd/poktrolld/cmd/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ var (
flagLogOutput string
logger polylog.Logger

// DEV_NOTE: AutoCLI does not apply here because there is no gRPC service,
// message, or query. The purpose of this command is to facilitate the
// deterministic (i.e. reproducible) transformation from the Morse export
// data structure (MorseStateExport) into the Shannon import data structure
// (MorseAccountState). It does not interact with the network directly.
collectMorseAccountsCmd = &cobra.Command{
Use: "collect-morse-accounts [morse-state-export-path] [morse-account-state-path]",
Args: cobra.ExactArgs(2),
Expand Down Expand Up @@ -145,6 +150,10 @@ func validatePathIsFile(path string) error {

// transformMorseState consolidates the Morse account balance, application stake,
// and supplier stake for each account as an entry in the resulting MorseAccountState.
// NOTE: In Shannon terms, "supplier" is equivalent to the following in Morse terms:
// - "validator"
// - "node"
// - "servicer"
func transformMorseState(
inputState *migrationtypes.MorseStateExport,
morseWorkspace *morseImportWorkspace,
Expand Down Expand Up @@ -185,7 +194,7 @@ func collectInputAccountBalances(inputState *migrationtypes.MorseStateExport, mo
}

accountAddr := exportAccount.Value.Address.String()
if _, _, err := morseWorkspace.ensureAccount(accountAddr, exportAccount); err != nil {
if _, _, err := morseWorkspace.addAccount(accountAddr, exportAccount); err != nil {
return err
}

Expand Down Expand Up @@ -251,7 +260,7 @@ func collectInputApplicationStakes(inputState *migrationtypes.MorseStateExport,
)
}

morseWorkspace.lastAccTotalAppStake = morseWorkspace.lastAccTotalAppStake.Add(appStakeAmtUpokt)
morseWorkspace.accumulatedTotalAppStake = morseWorkspace.accumulatedTotalAppStake.Add(appStakeAmtUpokt)
}
return nil
}
Expand Down Expand Up @@ -279,7 +288,7 @@ func collectInputSupplierStakes(inputState *migrationtypes.MorseStateExport, mor
)
}

morseWorkspace.lastAccTotalSupplierStake = morseWorkspace.lastAccTotalSupplierStake.Add(supplierStakeAmtUpokt)
morseWorkspace.accumulatedTotalSupplierStake = morseWorkspace.accumulatedTotalSupplierStake.Add(supplierStakeAmtUpokt)
}
return nil
}
2 changes: 1 addition & 1 deletion cmd/poktrolld/cmd/migrate/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func newMorseStateExportAndAccountState(
) (morseStateExportBz []byte, morseAccountStateBz []byte) {
morseStateExport := &migrationtypes.MorseStateExport{
AppHash: "",
AppState: &migrationtypes.MorseAppState{
AppState: &migrationtypes.MorseTendermintAppState{
Application: &migrationtypes.MorseApplications{},
Auth: &migrationtypes.MorseAuth{},
Pos: &migrationtypes.MorsePos{},
Expand Down
67 changes: 30 additions & 37 deletions cmd/poktrolld/cmd/migrate/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ func newMorseImportWorkspace() *morseImportWorkspace {
accountState: &migrationtypes.MorseAccountState{
Accounts: make([]*migrationtypes.MorseAccount, 0),
},
lastAccTotalBalance: cosmosmath.ZeroInt(),
lastAccTotalAppStake: cosmosmath.ZeroInt(),
lastAccTotalSupplierStake: cosmosmath.ZeroInt(),
accumulatedTotalBalance: cosmosmath.ZeroInt(),
accumulatedTotalAppStake: cosmosmath.ZeroInt(),
accumulatedTotalSupplierStake: cosmosmath.ZeroInt(),
}
}

Expand All @@ -34,16 +34,15 @@ type morseImportWorkspace struct {
// the input MorseStateExport into the output MorseAccountState.
accountState *migrationtypes.MorseAccountState

// lastAccTotalBalance is the most recently accumulated balances of all Morse
// accumulatedTotalBalance is the most recently accumulated balances of all Morse
// accounts which have been processed.
lastAccTotalBalance cosmosmath.Int
// lastAccTotalAppStake is the most recently accumulated application stakes of
accumulatedTotalBalance cosmosmath.Int
// accumulatedTotalAppStake is the most recently accumulated application stakes of
// all Morse accounts which have been processed.
lastAccTotalAppStake cosmosmath.Int
// lastAccTotalSupplierStake is the most recently accumulated supplier stakes of
accumulatedTotalAppStake cosmosmath.Int
// accumulatedTotalSupplierStake is the most recently accumulated supplier stakes of
// all Morse accounts which have been processed.
lastAccTotalSupplierStake cosmosmath.Int

accumulatedTotalSupplierStake cosmosmath.Int
// numAccounts is the number of accounts that have been processed.
numAccounts uint64
// numApplications is the number of applications that have been processed.
Expand Down Expand Up @@ -71,10 +70,10 @@ func (miw *morseImportWorkspace) debugLogProgress(accountIdx int) {
Uint64("num_accounts", miw.numAccounts).
Uint64("num_applications", miw.numApplications).
Uint64("num_suppliers", miw.numSuppliers).
Str("total_balance", miw.lastAccTotalBalance.String()).
Str("total_app_stake", miw.lastAccTotalAppStake.String()).
Str("total_supplier_stake", miw.lastAccTotalSupplierStake.String()).
Str("grand_total", miw.lastAccGrandTotal().String()).
Str("total_balance", miw.accumulatedTotalBalance.String()).
Str("total_app_stake", miw.accumulatedTotalAppStake.String()).
Str("total_supplier_stake", miw.accumulatedTotalSupplierStake.String()).
Str("grand_total", miw.accumulatedTotalsSum().String()).
Msg("processing accounts...")
}

Expand All @@ -89,27 +88,27 @@ func (miw *morseImportWorkspace) infoLogComplete() error {
Uint64("num_accounts", miw.numAccounts).
Uint64("num_applications", miw.numApplications).
Uint64("num_suppliers", miw.numSuppliers).
Str("total_balance", miw.lastAccTotalBalance.String()).
Str("total_app_stake", miw.lastAccTotalAppStake.String()).
Str("total_supplier_stake", miw.lastAccTotalSupplierStake.String()).
Str("grand_total", miw.lastAccGrandTotal().String()).
Str("total_balance", miw.accumulatedTotalBalance.String()).
Str("total_app_stake", miw.accumulatedTotalAppStake.String()).
Str("total_supplier_stake", miw.accumulatedTotalSupplierStake.String()).
Str("grand_total", miw.accumulatedTotalsSum().String()).
Str("morse_account_state_hash", fmt.Sprintf("%x", accountStateHash)).
Msg("processing accounts complete")
return nil
}

// lastAccGrandTotal returns the sum of the lastAccTotalBalance, lastAccTotalAppStake,
// and lastAccTotalSupplierStake.
func (miw *morseImportWorkspace) lastAccGrandTotal() cosmosmath.Int {
return miw.lastAccTotalBalance.
Add(miw.lastAccTotalAppStake).
Add(miw.lastAccTotalSupplierStake)
// accumulatedTotalsSum returns the sum of the accumulatedTotalBalance,
// accumulatedTotalAppStake, and accumulatedTotalSupplierStake.
func (miw *morseImportWorkspace) accumulatedTotalsSum() cosmosmath.Int {
return miw.accumulatedTotalBalance.
Add(miw.accumulatedTotalAppStake).
Add(miw.accumulatedTotalSupplierStake)
}

// ensureAccount ensures that the given address is present in the accounts slice
// and that its corresponding address is in the addressToIdx map. If the address
// is not present, it is added to the accounts slice and the addressToIdx map.
func (miw *morseImportWorkspace) ensureAccount(
// addAccount adds the account with the given address to the accounts slice and
// its corresponding address is in the addressToIdx map.
// If the address is already present, an error is returned.
func (miw *morseImportWorkspace) addAccount(
addr string,
exportAccount *migrationtypes.MorseAuthAccount,
) (accountIdx uint64, balance cosmostypes.Coin, err error) {
Expand All @@ -118,15 +117,9 @@ func (miw *morseImportWorkspace) ensureAccount(

var ok bool
if accountIdx, ok = miw.addressToIdx[addr]; ok {
logger.Warn().Str("address", addr).Msg("unexpected workspace state: account already exists")

importAccount := miw.accountState.Accounts[accountIdx]
// Each account should have EXACTLY one token denomination.
if len(importAccount.Coins) != 1 {
err := ErrMorseStateTransform.Wrapf("account %q has multiple token denominations: %s", addr, importAccount.Coins)
return 0, cosmostypes.Coin{}, err
}
balance = importAccount.Coins[0]
return 0, cosmostypes.Coin{}, ErrMorseStateTransform.Wrapf(
"unexpected workspace state: account already exists (%s)", addr,
)
} else {
accountIdx = miw.nextIdx()
importAccount := &migrationtypes.MorseAccount{
Expand Down
8 changes: 8 additions & 0 deletions docusaurus/docs/operate/morse_migration/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Morse -> Shannon Migration",
"position": 4,
"link": {
"type": "generated-index",
"description": "Morse to Shannon network migration documentation"
}
}
Loading

0 comments on commit 945c915

Please sign in to comment.