Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
TimmyExogenous committed Apr 9, 2024
2 parents 2726d1d + d28c021 commit ff6edf5
Show file tree
Hide file tree
Showing 61 changed files with 6,195 additions and 1,611 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ jobs:
profile: cover.out
local-prefix: github.com/ExocoreNetwork/exocore
# TODO: increase this threshold with time to 80
threshold-total: 10
threshold-total: 0
if: env.GIT_DIFF
# even if coverage is low, do not exit.
continue-on-error: true
- name: Generate artifact for PR
run: |
mkdir -p ./result/
Expand Down
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
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ require (
github.com/rs/cors v1.9.0 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/zondax/hid v0.9.1 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/net v0.23.0 // indirect
)

require (
Expand Down 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
6 changes: 4 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 Expand Up @@ -1698,6 +1698,8 @@ golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
18 changes: 3 additions & 15 deletions precompiles/delegation/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import (
"github.com/ExocoreNetwork/exocore/precompiles/delegation"
"github.com/ExocoreNetwork/exocore/x/assets/types"
assetstype "github.com/ExocoreNetwork/exocore/x/assets/types"
keeper2 "github.com/ExocoreNetwork/exocore/x/delegation/keeper"
delegationtype "github.com/ExocoreNetwork/exocore/x/delegation/types"
"github.com/ExocoreNetwork/exocore/x/deposit/keeper"
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"
"github.com/evmos/evmos/v14/x/evm/statedb"
evmtypes "github.com/evmos/evmos/v14/x/evm/types"
)
Expand Down Expand Up @@ -98,11 +96,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 All @@ -127,13 +120,13 @@ func (s *DelegationPrecompileSuite) TestRunDelegateToThroughClientChain() {
returnBytes []byte
}{
{
name: "fail - delegateToThroughClientChain transaction will fail because the exocoreLzAppAddress haven't been stored",
name: "fail - delegateToThroughClientChain transaction will fail because the exocoreLzAppAddress is mismatched",
malleate: func() (common.Address, []byte) {
return commonMalleate()
},
readOnly: false,
expPass: false,
errContains: assetstype.ErrNoParamsKey.Error(),
errContains: assetstype.ErrNotEqualToLzAppAddr.Error(),
},
{
name: "fail - delegateToThroughClientChain transaction will fail because the contract caller isn't the exoCoreLzAppAddr",
Expand Down Expand Up @@ -314,7 +307,7 @@ func (s *DelegationPrecompileSuite) TestRunUnDelegateFromThroughClientChain() {

delegateAsset := func(staker []byte, delegateAmount sdkmath.Int) {
// deposit asset for delegation test
delegateToParams := &keeper2.DelegationOrUndelegationParams{
delegateToParams := &delegationtype.DelegationOrUndelegationParams{
ClientChainLzID: 101,
Action: types.DelegateTo,
StakerAddress: staker,
Expand All @@ -340,11 +333,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
6 changes: 3 additions & 3 deletions precompiles/delegation/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (

exocmn "github.com/ExocoreNetwork/exocore/precompiles/common"
"github.com/ExocoreNetwork/exocore/x/assets/types"
keeper2 "github.com/ExocoreNetwork/exocore/x/delegation/keeper"
delegationtypes "github.com/ExocoreNetwork/exocore/x/delegation/types"
sdk "github.com/cosmos/cosmos-sdk/types"
cmn "github.com/evmos/evmos/v14/precompiles/common"
)

func (p Precompile) GetDelegationParamsFromInputs(ctx sdk.Context, args []interface{}) (*keeper2.DelegationOrUndelegationParams, error) {
func (p Precompile) GetDelegationParamsFromInputs(ctx sdk.Context, args []interface{}) (*delegationtypes.DelegationOrUndelegationParams, error) {
if len(args) != 6 {
return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, 6, len(args))
}
delegationParams := &keeper2.DelegationOrUndelegationParams{}
delegationParams := &delegationtypes.DelegationOrUndelegationParams{}
clientChainLzID, ok := args[0].(uint16)
if !ok {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, reflect.TypeOf(args[0]), clientChainLzID)
Expand Down
11 changes: 2 additions & 9 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 All @@ -87,13 +80,13 @@ func (s *DepositPrecompileSuite) TestRunDepositTo() {
returnBytes []byte
}{
{
name: "fail - depositTo transaction will fail because the exocoreLzAppAddress haven't been stored",
name: "fail - depositTo transaction will fail because the exocoreLzAppAddress is mismatched",
malleate: func() (common.Address, []byte) {
return commonMalleate()
},
readOnly: false,
expPass: false,
errContains: assetstype.ErrNoParamsKey.Error(),
errContains: assetstype.ErrNotEqualToLzAppAddr.Error(),
},
{
name: "fail - depositTo transaction will fail because the contract caller isn't the exoCoreLzAppAddr",
Expand Down
Loading

0 comments on commit ff6edf5

Please sign in to comment.