Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 committed Apr 8, 2024
2 parents ace29eb + 09bdbdc commit 263ddd2
Show file tree
Hide file tree
Showing 14 changed files with 333 additions and 548 deletions.
467 changes: 258 additions & 209 deletions app/app.go

Large diffs are not rendered by default.

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

import (
"encoding/json"
"fmt"

"cosmossdk.io/simapp"

Expand All @@ -17,9 +16,7 @@ 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 @@ -57,20 +54,6 @@ 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)

return defaultGenesis
}

Expand All @@ -79,7 +62,8 @@ 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 @@ -116,141 +100,44 @@ 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, 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
}
func (app *ExocoreApp) prepForZeroHeightGenesis(
ctx sdk.Context,
_ []string,
) error {
// TODO: use the []string to mark validators as jailed.

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

/* Handle fee distribution state. */

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

// 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. */

// 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
})
// not supported: iterate through redelegations, reset creation height

// 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: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,12 @@ 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
github.com/evmos/evmos/v14 => github.com/ExocoreNetwork/evmos/v14 v14.1.1-0.20240205024453-5e8090e42ef4
//github.com/evmos/evmos/v14 => ../ExocoreNetwork/evmos
// use exocore fork of evmos TODO
github.com/evmos/evmos/v14 => github.com/ExocoreNetwork/evmos/v14 v14.1.1-0.20240408040728-a6f685cfebb9
// 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,8 +545,8 @@ 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/ExocoreNetwork/evmos/v14 v14.1.1-0.20240408040728-a6f685cfebb9 h1:/jL9TiINGniPOG2bRfLmyCFSwMy/vFZ1Ta0OoE+xJaE=
github.com/ExocoreNetwork/evmos/v14 v14.1.1-0.20240408040728-a6f685cfebb9/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/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
Expand Down
11 changes: 0 additions & 11 deletions precompiles/delegation/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ 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 @@ -98,11 +97,6 @@ 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...))
input, err := s.precompile.Pack(
delegation.MethodDelegateToThroughClientChain,
uint16(clientChainLzID),
Expand Down Expand Up @@ -340,11 +334,6 @@ 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...))
input, err := s.precompile.Pack(
delegation.MethodUndelegateFromThroughClientChain,
uint16(clientChainLzID),
Expand Down
7 changes: 0 additions & 7 deletions precompiles/deposit/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ 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 @@ -60,11 +58,6 @@ 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...))
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 263ddd2

Please sign in to comment.