Skip to content

Commit

Permalink
chore: lint (#41)
Browse files Browse the repository at this point in the history
* lintjobs

* fix links
  • Loading branch information
Vritra4 authored Jan 8, 2024
1 parent 13f89ba commit 4cc5287
Show file tree
Hide file tree
Showing 26 changed files with 178 additions and 66 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ This repository hosts `initiad`, the first implementation of a cosmos zone with

## Documentation & Introduction

You can find an introduction to the Initia and how to use the initiad binary as a delegator, validator or node operator as well as how moveVM on the Initia works in the [documentation](https://app.gitbook.com/o/f40ATI6dfRXMHEcAFnUO/s/rnGS4UFboF67ZTvcmbIH/learn).
You can find an introduction to the Initia and how to use the initiad binary as a delegator, validator or node operator as well as how moveVM on the Initia works in the [documentation](https://app.gitbook.com/o/VC1Rsak51RJaeaQhM2YE/s/pUvrGia2zAh06hjawOb6/developers/initiad).

Alternatively, whether you're new to blockchain technology or interested in getting involved, the Initia [Tutorial](https://app.gitbook.com/o/f40ATI6dfRXMHEcAFnUO/s/rnGS4UFboF67ZTvcmbIH/tutorials) will guide you through everything. The tutorial walks you through the basics of blockchain technology, to interacting, creating your own smart contract, and beyond.

## Note Operators

If you're interested in running an node on the current Initia, check out the docs to [Run a Public Node](https://app.gitbook.com/o/f40ATI6dfRXMHEcAFnUO/s/rnGS4UFboF67ZTvcmbIH/nodes/run-a-public-node).
If you're interested in running an node on the current Initia, check out the docs to [Run a Public Node](https://app.gitbook.com/o/VC1Rsak51RJaeaQhM2YE/s/pUvrGia2zAh06hjawOb6/node-operators/running-initia-node).

## Validators

Expand All @@ -25,8 +25,8 @@ If you still want to participate on the Initia, check out becoming a delegator.

## Contract Developers

If you want to build a move smart contract on Initia, check out becoming contract developer. Information on how to build and deploy contract can be found at the [documentation](https://app.gitbook.com/o/f40ATI6dfRXMHEcAFnUO/s/rnGS4UFboF67ZTvcmbIH/tutorials/first-move-smart-contract-with-initia).
If you want to build a move smart contract on Initia, check out becoming contract developer. Information on how to build and deploy contract can be found at the [documentation](https://app.gitbook.com/o/VC1Rsak51RJaeaQhM2YE/s/pUvrGia2zAh06hjawOb6/developers/contracts).

## Testnet

To participate in or utilize the current Initia testnet, take a look at the [initia/testnets](https://github.com/initia-labs/testnets) repository.
To participate in or utilize the current Initia testnet, take a look at the [initia/networks](https://github.com/initia-labs/networks) repository.
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,9 @@ func (app *InitiaApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap())
if err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()); err != nil {
panic(err)
}
return app.ModuleManager.InitGenesis(ctx, app.appCodec, genesisState)
}

Expand Down
38 changes: 30 additions & 8 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ func (app *InitiaApp) ExportAppStateAndValidators(
height := app.LastBlockHeight() + 1
if forZeroHeight {
height = 0
app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
err := app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
if err != nil {
return servertypes.ExportedApp{}, err
}
}

genState, err := app.ModuleManager.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
Expand Down Expand Up @@ -115,10 +118,16 @@ func (app *InitiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs
}

// clear validator slash events
app.DistrKeeper.ValidatorSlashEvents.Clear(ctx, nil)
err = app.DistrKeeper.ValidatorSlashEvents.Clear(ctx, nil)
if err != nil {
return err
}

// clear validator historical rewards
app.DistrKeeper.ValidatorHistoricalRewards.Clear(ctx, nil)
err = app.DistrKeeper.ValidatorHistoricalRewards.Clear(ctx, nil)
if err != nil {
return err
}

// set context height to zero
height := ctx.BlockHeight()
Expand All @@ -144,7 +153,10 @@ func (app *InitiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs
}

feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.FeePool.Set(ctx, feePool)
err = app.DistrKeeper.FeePool.Set(ctx, feePool)
if err != nil {
return true, err
}

if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, valAddr); err != nil {
panic(err)
Expand Down Expand Up @@ -181,7 +193,7 @@ func (app *InitiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs
/* Handle staking state. */

// iterate through redelegations, reset creation height
app.StakingKeeper.IterateRedelegations(ctx, func(red stakingtypes.Redelegation) (stop bool, err error) {
err = app.StakingKeeper.IterateRedelegations(ctx, func(red stakingtypes.Redelegation) (stop bool, err error) {
for i := range red.Entries {
red.Entries[i].CreationHeight = 0
}
Expand All @@ -191,9 +203,12 @@ func (app *InitiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs
}
return false, nil
})
if err != nil {
return err
}

// iterate through unbonding delegations, reset creation height
app.StakingKeeper.IterateUnbondingDelegations(ctx, func(ubd stakingtypes.UnbondingDelegation) (stop bool, err error) {
err = app.StakingKeeper.IterateUnbondingDelegations(ctx, func(ubd stakingtypes.UnbondingDelegation) (stop bool, err error) {
for i := range ubd.Entries {
ubd.Entries[i].CreationHeight = 0
}
Expand All @@ -204,6 +219,9 @@ func (app *InitiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs

return false, nil
})
if err != nil {
return err
}

// Iterate through validators by power descending, reset bond heights, and
// update bond intra-tx counters.
Expand All @@ -213,7 +231,9 @@ func (app *InitiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs
validator.Jailed = true
}

app.StakingKeeper.SetValidator(ctx, validator)
if err := app.StakingKeeper.SetValidator(ctx, validator); err != nil {
return true, err
}
return false, nil
})
if err != nil {
Expand All @@ -231,7 +251,9 @@ func (app *InitiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs
ctx,
func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) {
info.StartHeight = 0
app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
if err := app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info); err != nil {
panic(err)
}
return false
},
)
Expand Down
8 changes: 6 additions & 2 deletions app/hook/bridge_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ func (h BridgeHook) BridgeCreated(
}

// register challenger as channel relayer
h.IBCPermKeeper.SetChannelRelayer(sdkCtx, channelID, challenger)
if err = h.IBCPermKeeper.SetChannelRelayer(sdkCtx, channelID, challenger); err != nil {
return err
}
}

return nil
Expand All @@ -72,7 +74,9 @@ func (h BridgeHook) BridgeChallengerUpdated(
}

// update relayer to a new challenger
h.IBCPermKeeper.SetChannelRelayer(sdkCtx, channelID, challenger)
if err = h.IBCPermKeeper.SetChannelRelayer(sdkCtx, channelID, challenger); err != nil {
return err
}
}

return nil
Expand Down
20 changes: 16 additions & 4 deletions x/distribution/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@ func NonNegativeOutstandingInvariant(k Keeper) sdk.Invariant {
var count int
var outstanding customtypes.DecPools

k.ValidatorOutstandingRewards.Walk(ctx, nil, func(addr []byte, rewards customtypes.ValidatorOutstandingRewards) (stop bool, err error) {
err := k.ValidatorOutstandingRewards.Walk(ctx, nil, func(addr []byte, rewards customtypes.ValidatorOutstandingRewards) (stop bool, err error) {
outstanding = rewards.GetRewards()
if outstanding.IsAnyNegative() {
count++
msg += fmt.Sprintf("\t%v has negative outstanding coins: %v\n", sdk.ValAddress(addr), outstanding)
}
return false, nil
})
if err != nil {
panic(err)
}
broken := count != 0

return sdk.FormatInvariant(types.ModuleName, "nonnegative outstanding",
Expand Down Expand Up @@ -127,22 +130,28 @@ func ReferenceCountInvariant(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {

valCount := uint64(0)
k.stakingKeeper.IterateValidators(ctx, func(val stakingtypes.ValidatorI) (stop bool, err error) {
err := k.stakingKeeper.IterateValidators(ctx, func(val stakingtypes.ValidatorI) (stop bool, err error) {
valCount++
return false, nil
})
if err != nil {
panic(err)
}

dels, err := k.stakingKeeper.GetAllSDKDelegations(ctx)
if err != nil {
panic(err)
}

slashCount := uint64(0)
k.ValidatorSlashEvents.Walk(ctx, nil,
err = k.ValidatorSlashEvents.Walk(ctx, nil,
func(_ collections.Triple[[]byte, uint64, uint64], _ customtypes.ValidatorSlashEvent) (stop bool, err error) {
slashCount++
return false, nil
})
if err != nil {
panic(err)
}

// one record per validator (last tracked period), one record per
// delegation (previous period), one record per slash (previous period)
Expand All @@ -167,10 +176,13 @@ func ModuleAccountInvariant(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {

var expectedCoins sdk.DecCoins
k.ValidatorOutstandingRewards.Walk(ctx, nil, func(_ []byte, rewards customtypes.ValidatorOutstandingRewards) (stop bool, err error) {
err := k.ValidatorOutstandingRewards.Walk(ctx, nil, func(_ []byte, rewards customtypes.ValidatorOutstandingRewards) (stop bool, err error) {
expectedCoins = expectedCoins.Add(rewards.Rewards.Sum()...)
return false, nil
})
if err != nil {
panic(err)
}

feePool, err := k.FeePool.Get(ctx)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions x/distribution/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ func (k Keeper) WithdrawValidatorCommission(ctx context.Context, valAddr sdk.Val
}

commissions, remainder := accumCommission.Commissions.TruncateDecimal()
k.ValidatorAccumulatedCommissions.Set(ctx, valAddr, customtypes.ValidatorAccumulatedCommission{Commissions: remainder}) // leave remainder to withdraw later
// leave remainder to withdraw later
if err = k.ValidatorAccumulatedCommissions.Set(ctx, valAddr, customtypes.ValidatorAccumulatedCommission{Commissions: remainder}); err != nil {
return nil, err
}

// update outstanding
outstandingRewards, err := k.GetValidatorOutstandingRewards(ctx, valAddr)
Expand Down Expand Up @@ -219,12 +222,15 @@ func (k Keeper) WithdrawValidatorCommission(ctx context.Context, valAddr sdk.Val

// GetTotalRewards returns the total amount of fee distribution rewards held in the store
func (k Keeper) GetTotalRewards(ctx context.Context) (totalRewards sdk.DecCoins) {
k.ValidatorOutstandingRewards.Walk(ctx, nil,
err := k.ValidatorOutstandingRewards.Walk(ctx, nil,
func(_ []byte, rewards customtypes.ValidatorOutstandingRewards) (stop bool, err error) {
totalRewards = totalRewards.Add(rewards.Rewards.Sum()...)
return false, nil
},
)
if err != nil {
panic(err)
}

return totalRewards
}
Expand Down
2 changes: 1 addition & 1 deletion x/genutil/client/cli/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
return fmt.Errorf("failed to get accounts from any: %w", err)
}

if accs.Contains(sdk.AccAddress(addr)) {
if accs.Contains(addr) {
return fmt.Errorf("cannot add account at existing address %s", addr)
}

Expand Down
5 changes: 4 additions & 1 deletion x/gov/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func EndBlocker(ctx sdk.Context, k *keeper.Keeper) error {
}

if ctx.BlockTime().After(lastEmergencyProposalTallyTimestamp.Add(params.EmergencyTallyInterval)) {
k.EmergencyProposals.Walk(ctx, nil, func(proposalID uint64, _ []byte) (stop bool, err error) {
err = k.EmergencyProposals.Walk(ctx, nil, func(proposalID uint64, _ []byte) (stop bool, err error) {
proposal, err := k.Proposals.Get(ctx, proposalID)
if err != nil {
return false, err
Expand Down Expand Up @@ -179,6 +179,9 @@ func EndBlocker(ctx sdk.Context, k *keeper.Keeper) error {

return false, nil
})
if err != nil {
return err
}

if err := k.LastEmergencyProposalTallyTimestamp.Set(ctx, ctx.BlockTime()); err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion x/gov/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k
panic(fmt.Sprintf("expected module account was %s but we got %s", balance.String(), totalDeposits.String()))
}

k.LastEmergencyProposalTallyTimestamp.Set(ctx, data.LastEmergencyProposalTallyTimestamp)
if err = k.LastEmergencyProposalTallyTimestamp.Set(ctx, data.LastEmergencyProposalTallyTimestamp); err != nil {
panic(err)
}
}

// ExportGenesis - output genesis parameters
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (keeper Keeper) Tally(ctx context.Context, proposal v1.Proposal) (quorumRea
return false, err
}

return false, keeper.Votes.Remove(ctx, collections.Join(vote.ProposalId, sdk.AccAddress(voter)))
return false, keeper.Votes.Remove(ctx, collections.Join(vote.ProposalId, voter))
})
if err != nil {
return false, false, false, tallyResults, err
Expand Down
5 changes: 4 additions & 1 deletion x/ibc/perm/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genesisState types.GenesisState) {
// ExportGenesis exports ibc-perm module's channel relayers.
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
channelRelayers := []types.ChannelRelayer{}
k.IterateChannelRelayer(ctx, func(channelRelayer types.ChannelRelayer) (bool, error) {
err := k.IterateChannelRelayer(ctx, func(channelRelayer types.ChannelRelayer) (bool, error) {
channelRelayers = append(channelRelayers, channelRelayer)
return false, nil
})
if err != nil {
panic(err)
}

return &types.GenesisState{
ChannelRelayers: channelRelayers,
Expand Down
2 changes: 1 addition & 1 deletion x/ibc/testing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func ApplyValSetChanges(tb testing.TB, valSet *tmtypes.ValidatorSet, valUpdates
func GenerateString(length uint) string {
bytes := make([]byte, length)
for i := range bytes {
bytes[i] = charset[rand.Intn(len(charset))]
bytes[i] = charset[rand.Intn(len(charset))] //nolint weak random number generator is acceptable here
}
return string(bytes)
}
5 changes: 4 additions & 1 deletion x/move/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState {
var resources []types.Resource
var tableEntries []types.TableEntry
var tableInfos []types.TableInfo
k.IterateVMStore(ctx, func(
err = k.IterateVMStore(ctx, func(
module *types.Module,
resource *types.Resource,
tableInfo *types.TableInfo,
Expand All @@ -163,6 +163,9 @@ func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState {
}

})
if err != nil {
panic(err)
}

dexKeeper := NewDexKeeper(&k)

Expand Down
25 changes: 20 additions & 5 deletions x/move/keeper/whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,16 @@ func (k Keeper) Whitelist(ctx context.Context, msg types.MsgWhitelist) error {

// append denomLP reward weight to distribution keeper
rewardWeights = append(rewardWeights, distrtypes.RewardWeight{Denom: denomLP, Weight: msg.RewardWeight})
k.distrKeeper.SetRewardWeights(ctx, rewardWeights)
err = k.distrKeeper.SetRewardWeights(ctx, rewardWeights)
if err != nil {
return err
}

// store dex pair
dexKeeper.setDexPair(ctx, metadataQuote, metadataLP)
err = dexKeeper.setDexPair(ctx, metadataQuote, metadataLP)
if err != nil {
return err
}

// execute register if global store not found
if found, err := k.HasStakingState(ctx, metadataLP); err != nil {
Expand Down Expand Up @@ -243,11 +249,20 @@ func (k Keeper) Delist(ctx context.Context, msg types.MsgDelist) error {

// remove coinLP reward weight from the distribution reward weights
rewardWeights = append(rewardWeights[:rewardWeightIndex], rewardWeights[rewardWeightIndex+1:]...)
k.distrKeeper.SetRewardWeights(ctx, rewardWeights)
err = k.distrKeeper.SetRewardWeights(ctx, rewardWeights)
if err != nil {
return err
}

// delete dex pair
dexKeeper.deleteDexPair(ctx, metadataA)
dexKeeper.deleteDexPair(ctx, metadataB)
err = dexKeeper.deleteDexPair(ctx, metadataA)
if err != nil {
return err
}
err = dexKeeper.deleteDexPair(ctx, metadataB)
if err != nil {
return err
}

return nil
}
2 changes: 1 addition & 1 deletion x/mstaking/keeper/alias_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (k Keeper) IterateDelegations(
// return all delegations used during genesis dump
// TODO: remove this func, change all usage for iterate functionality
func (k Keeper) GetAllSDKDelegations(ctx context.Context) (delegations []types.Delegation, err error) {
k.Delegations.Walk(ctx, nil, func(key collections.Pair[[]byte, []byte], del types.Delegation) (stop bool, err error) {
err = k.Delegations.Walk(ctx, nil, func(key collections.Pair[[]byte, []byte], del types.Delegation) (stop bool, err error) {
delegations = append(delegations, del)
return false, nil
})
Expand Down
Loading

0 comments on commit 4cc5287

Please sign in to comment.