Skip to content

Commit

Permalink
Revert "Merge branch 'fix/remove-unused-modules'"
Browse files Browse the repository at this point in the history
This reverts commit 1243063, reversing
changes made to 6e50b3a.

The PR 21 is removed from this branch show that the consensus warn CI
can pass.
  • Loading branch information
MaxMustermann2 committed Apr 5, 2024
1 parent 907e02b commit a63a6f9
Show file tree
Hide file tree
Showing 13 changed files with 542 additions and 356 deletions.
467 changes: 209 additions & 258 deletions app/app.go

Large diffs are not rendered by default.

142 changes: 120 additions & 22 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"encoding/json"
"fmt"

"cosmossdk.io/simapp"

Expand All @@ -16,7 +17,9 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
claimstypes "github.com/evmos/evmos/v14/x/claims/types"
evmtypes "github.com/evmos/evmos/v14/x/evm/types"
inflationtypes "github.com/evmos/evmos/v14/x/inflation/types"

"github.com/evmos/evmos/v14/encoding"
)
Expand Down Expand Up @@ -54,12 +57,19 @@ func NewDefaultGenesisState(cdc codec.Codec) simapp.GenesisState {
evmGenesis.Params.EvmDenom = utils.BaseDenom
defaultGenesis[evmtypes.ModuleName] = cdc.MustMarshalJSON(&evmGenesis)

// inflation module
inflationGenesis := inflationtypes.GenesisState{}
rawGenesis = defaultGenesis[inflationtypes.ModuleName]
cdc.MustUnmarshalJSON(rawGenesis, &inflationGenesis)
inflationGenesis.Params.MintDenom = utils.BaseDenom
defaultGenesis[inflationtypes.ModuleName] = cdc.MustMarshalJSON(&inflationGenesis)

// claims module
// claimsGenesis := claimstypes.GenesisState{}
// rawGenesis = defaultGenesis[claimstypes.ModuleName]
// cdc.MustUnmarshalJSON(rawGenesis, &claimsGenesis)
// claimsGenesis.Params.ClaimsDenom = utils.BaseDenom
// defaultGenesis[claimstypes.ModuleName] = cdc.MustMarshalJSON(&claimsGenesis)
claimsGenesis := claimstypes.GenesisState{}
rawGenesis = defaultGenesis[claimstypes.ModuleName]
cdc.MustUnmarshalJSON(rawGenesis, &claimsGenesis)
claimsGenesis.Params.ClaimsDenom = utils.BaseDenom
defaultGenesis[claimstypes.ModuleName] = cdc.MustMarshalJSON(&claimsGenesis)

return defaultGenesis
}
Expand All @@ -69,8 +79,7 @@ func NewDefaultGenesisState(cdc codec.Codec) simapp.GenesisState {
func (app *ExocoreApp) ExportAppStateAndValidators(
forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string,
) (servertypes.ExportedApp, error) {
// Creates context with current height and checks txs for ctx to be usable by start of next
// block
// Creates context with current height and checks txs for ctx to be usable by start of next block
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})

// We export at last height + 1, because that's the height at which
Expand Down Expand Up @@ -107,52 +116,141 @@ func (app *ExocoreApp) ExportAppStateAndValidators(
// NOTE zero height genesis is a temporary feature which will be deprecated
//
// in favor of export at a block height
func (app *ExocoreApp) prepForZeroHeightGenesis(
ctx sdk.Context,
_ []string,
) error {
// allowedAddrsMap := make(map[string]bool)

// for _, addr := range jailAllowedAddrs {
// _, err := sdk.ValAddressFromBech32(addr)
// if err != nil {
// return err
// }
// allowedAddrsMap[addr] = true
// }
func (app *ExocoreApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) error {
applyAllowedAddrs := false

// check if there is a allowed address list
if len(jailAllowedAddrs) > 0 {
applyAllowedAddrs = true
}

allowedAddrsMap := make(map[string]bool)

for _, addr := range jailAllowedAddrs {
_, err := sdk.ValAddressFromBech32(addr)
if err != nil {
return err
}
allowedAddrsMap[addr] = true
}

/* Just to be safe, assert the invariants on current state. */
app.CrisisKeeper.AssertInvariants(ctx)

/* Handle fee distribution state. */

// TODO(mm): replace with new reward distribution keeper.
// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
return false
})

// withdraw all delegator rewards
dels := app.StakingKeeper.GetAllDelegations(ctx)
for _, delegation := range dels {
valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
if err != nil {
return err
}

delAddr, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress)
if err != nil {
return err
}
_, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr)
}

// clear validator slash events
app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx)

// clear validator historical rewards
app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx)

// set context height to zero
height := ctx.BlockHeight()
ctx = ctx.WithBlockHeight(0)

// reinitialize all validators
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
feePool := app.DistrKeeper.GetFeePool(ctx)
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)

err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
// this lets us stop in case there's an error
return err != nil
})

// reinitialize all delegations
for _, del := range dels {
valAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress)
if err != nil {
return err
}
delAddr, err := sdk.AccAddressFromBech32(del.DelegatorAddress)
if err != nil {
return err
}
err = app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr)
if err != nil {
return err
}
err = app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr)
if err != nil {
return err
}
}

// reset context height
ctx = ctx.WithBlockHeight(height)

/* Handle staking state. */

// not supported: iterate through redelegations, reset creation height
// iterate through redelegations, reset creation height
app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
for i := range red.Entries {
red.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetRedelegation(ctx, red)
return false
})

// iterate through unbonding delegations, reset creation height
app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
for i := range ubd.Entries {
ubd.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
return false
})

// Iterate through validators by power descending, reset bond heights, and
// update bond intra-tx counters.
store := ctx.KVStore(app.keys[stakingtypes.StoreKey])
iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
counter := int16(0)

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
validator, found := app.StakingKeeper.GetValidator(ctx, addr)
if !found {
return fmt.Errorf("expected validator %s not found", addr)
}

validator.UnbondingHeight = 0
if applyAllowedAddrs && !allowedAddrsMap[addr.String()] {
validator.Jailed = true
}

app.StakingKeeper.SetValidator(ctx, validator)
counter++
}

if err := iter.Close(); err != nil {
return err
}

if _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil {
return err
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,14 @@ replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
// use Cosmos-SDK fork to enable Ledger functionality
github.com/cosmos/cosmos-sdk => github.com/evmos/cosmos-sdk v0.47.4-evmos.2
//github.com/cosmos/cosmos-sdk => ../cosmos-sdk
//fix cosmos-sdk error
github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.10
// use Evmos geth fork
github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc2
// use exocore fork of evmos TODO
github.com/evmos/evmos/v14 => github.com/MaxMustermann2/evmos/v14 v14.0.0-20240326155756-4f464426e972
// use exocore fork of evmos
github.com/evmos/evmos/v14 => github.com/ExocoreNetwork/evmos/v14 v14.1.1-0.20240205024453-5e8090e42ef4
//github.com/evmos/evmos/v14 => ../ExocoreNetwork/evmos
// Security Advisory https://github.com/advisories/GHSA-h395-qcrw-5vmq
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1
// replace broken goleveldb
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,10 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/ExocoreNetwork/evmos/v14 v14.1.1-0.20240205024453-5e8090e42ef4 h1:55qBGHyCOvxxu4kxh+IY6T1pElfyQey5vRKTs25Gc6s=
github.com/ExocoreNetwork/evmos/v14 v14.1.1-0.20240205024453-5e8090e42ef4/go.mod h1:Hi3CAMxAE+H7Fs7sSHsHKb4DZIURk+trop+mMrjlZqw=
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/MaxMustermann2/evmos/v14 v14.0.0-20240326155756-4f464426e972 h1:6oBb1Zhtar2hzju1Fv7cZ8mZVJoJ+K5DvbHt/nW0fyU=
github.com/MaxMustermann2/evmos/v14 v14.0.0-20240326155756-4f464426e972/go.mod h1:Hi3CAMxAE+H7Fs7sSHsHKb4DZIURk+trop+mMrjlZqw=
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
Expand Down
21 changes: 11 additions & 10 deletions precompiles/delegation/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/evmos/evmos/v14/utils"
"github.com/evmos/evmos/v14/x/evm/statedb"
evmtypes "github.com/evmos/evmos/v14/x/evm/types"
)
Expand Down Expand Up @@ -96,11 +97,11 @@ func (s *DelegationPrecompileSuite) TestRunDelegateToThroughClientChain() {
}
commonMalleate := func() (common.Address, []byte) {
// prepare the call input for delegation test
// valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress)
// s.Require().NoError(err)
// val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr)
// coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18)))
// s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...))
valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress)
s.Require().NoError(err)
val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr)
coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18)))
s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...))
input, err := s.precompile.Pack(
delegation.MethodDelegateToThroughClientChain,
uint16(clientChainLzID),
Expand Down Expand Up @@ -338,11 +339,11 @@ func (s *DelegationPrecompileSuite) TestRunUnDelegateFromThroughClientChain() {
}
commonMalleate := func() (common.Address, []byte) {
// prepare the call input for delegation test
// valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress)
// s.Require().NoError(err)
// val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr)
// coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18)))
// s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...))
valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress)
s.Require().NoError(err)
val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr)
coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18)))
s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...))
input, err := s.precompile.Pack(
delegation.MethodUndelegateFromThroughClientChain,
uint16(clientChainLzID),
Expand Down
12 changes: 7 additions & 5 deletions precompiles/deposit/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"github.com/ExocoreNetwork/exocore/precompiles/deposit"
assetstype "github.com/ExocoreNetwork/exocore/x/assets/types"
deposittype "github.com/ExocoreNetwork/exocore/x/deposit/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/evmos/evmos/v14/utils"
evmtypes "github.com/evmos/evmos/v14/x/evm/types"
)

Expand Down Expand Up @@ -58,11 +60,11 @@ func (s *DepositPrecompileSuite) TestRunDepositTo() {
opAmount := big.NewInt(100)
assetAddr := usdtAddress
commonMalleate := func() (common.Address, []byte) {
// valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress)
// s.Require().NoError(err)
// val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr)
// coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18)))
// s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...))
valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress)
s.Require().NoError(err)
val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr)
coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18)))
s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...))
input, err := s.precompile.Pack(
deposit.MethodDepositTo,
uint16(clientChainLzID),
Expand Down
14 changes: 7 additions & 7 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1
#proto_dirs="proto/exocore/reward/v1beta1"
#echo $proto_dirs
for dir in $proto_dirs; do
proto_files=$(find "${dir}" -maxdepth 3 -name '*.proto')
for file in $proto_files; do
# Check if the go_package in the file is pointing to evmos
if grep -q "option go_package.*exocore" "$file"; then
buf generate --template proto/buf.gen.gogo.yaml "$file"
fi
done
proto_files=$(find "${dir}" -maxdepth 3 -name '*.proto')
for file in $proto_files; do
# Check if the go_package in the file is pointing to evmos
if grep -q "option go_package.*exocore" "$file"; then
buf generate --template proto/buf.gen.gogo.yaml "$file"
fi
done
done

# move proto files to the right places
Expand Down
Loading

0 comments on commit a63a6f9

Please sign in to comment.