Skip to content

Commit

Permalink
Merge pull request #1776 from Sifchain/testnet
Browse files Browse the repository at this point in the history
[ChainOps] Latest release to master.
  • Loading branch information
intl-man authored Aug 24, 2021
2 parents 9ceec37 + 988a3d6 commit 35744c0
Show file tree
Hide file tree
Showing 480 changed files with 90,192 additions and 23,039 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.txt
flags: server
verbose: true
verbose: true
1 change: 0 additions & 1 deletion .github/workflows/ui-stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:
- develop
- master
- testnet
- feature/cosmos-0.42

jobs:
build_ui_stack:
Expand Down
35 changes: 24 additions & 11 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package app

import (
tokenregistrykeeper "github.com/Sifchain/sifnode/x/tokenregistry/keeper"
tmos "github.com/tendermint/tendermint/libs/os"
"io"
"math/big"
"net/http"
Expand Down Expand Up @@ -45,7 +47,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer"
ibctransferkeeper "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/keeper"
ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types"
ibc "github.com/cosmos/cosmos-sdk/x/ibc/core"
Expand Down Expand Up @@ -74,7 +75,6 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

Expand All @@ -88,9 +88,12 @@ import (
"github.com/Sifchain/sifnode/x/ethbridge"
ethbridgekeeper "github.com/Sifchain/sifnode/x/ethbridge/keeper"
ethbridgetypes "github.com/Sifchain/sifnode/x/ethbridge/types"
ibctransferoverride "github.com/Sifchain/sifnode/x/ibctransfer"
"github.com/Sifchain/sifnode/x/oracle"
oraclekeeper "github.com/Sifchain/sifnode/x/oracle/keeper"
oracletypes "github.com/Sifchain/sifnode/x/oracle/types"
"github.com/Sifchain/sifnode/x/tokenregistry"
tokenregistrytypes "github.com/Sifchain/sifnode/x/tokenregistry/types"
)

const appName = "sifnode"
Expand All @@ -113,12 +116,13 @@ var (
slashing.AppModuleBasic{},
evidence.AppModuleBasic{},
ibc.AppModuleBasic{},
transfer.AppModuleBasic{},
ibctransferoverride.AppModuleBasic{},

clp.AppModuleBasic{},
oracle.AppModuleBasic{},
ethbridge.AppModuleBasic{},
dispensation.AppModuleBasic{},
tokenregistry.AppModuleBasic{},
)

maccPerms = map[string][]string{
Expand Down Expand Up @@ -179,10 +183,11 @@ type SifchainApp struct {
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedIBCMockKeeper capabilitykeeper.ScopedKeeper

ClpKeeper clpkeeper.Keeper
OracleKeeper oraclekeeper.Keeper
EthbridgeKeeper ethbridgekeeper.Keeper
DispensationKeeper dispkeeper.Keeper
ClpKeeper clpkeeper.Keeper
OracleKeeper oraclekeeper.Keeper
EthbridgeKeeper ethbridgekeeper.Keeper
DispensationKeeper dispkeeper.Keeper
TokenRegistryKeeper tokenregistrytypes.Keeper

mm *module.Manager
sm *module.SimulationManager
Expand Down Expand Up @@ -220,6 +225,7 @@ func NewSifApp(
ethbridgetypes.StoreKey,
clptypes.StoreKey,
oracletypes.StoreKey,
tokenregistrytypes.StoreKey,
)

tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand All @@ -236,6 +242,10 @@ func NewSifApp(
memKeys: memKeys,
}

if homePath == "" {
homePath = DefaultNodeHome
}

app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])

// set the BaseApp's parameter store
Expand Down Expand Up @@ -269,14 +279,14 @@ func NewSifApp(
app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName),
)

app.TokenRegistryKeeper = tokenregistrykeeper.NewKeeper(appCodec, keys[tokenregistrytypes.StoreKey])
// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *stakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
)

app.ClpKeeper = clpkeeper.NewKeeper(appCodec, keys[clptypes.StoreKey], app.BankKeeper, app.AccountKeeper, app.GetSubspace(clptypes.ModuleName))
app.ClpKeeper = clpkeeper.NewKeeper(appCodec, keys[clptypes.StoreKey], app.BankKeeper, app.AccountKeeper, app.TokenRegistryKeeper, app.GetSubspace(clptypes.ModuleName))

app.OracleKeeper = oraclekeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -305,7 +315,7 @@ func NewSifApp(
// The mapping represents height to bool. if the value is true for a height that height
// will be skipped even if we have a update proposal for it
skipUpgradeHeights[0] = true
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, DefaultNodeHome)
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath)
SetupHandlers(app)

// Create IBC Keeper
Expand Down Expand Up @@ -335,7 +345,7 @@ func NewSifApp(
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,
)
transferModule := transfer.NewAppModule(app.TransferKeeper)
transferModule := ibctransferoverride.NewAppModule(app.TransferKeeper, app.TokenRegistryKeeper, app.BankKeeper, appCodec)

// NOTE: the IBC mock keeper and application module is used only for testing core IBC. Do
// note replicate if you do not need to test core IBC or light clients.
Expand Down Expand Up @@ -377,12 +387,14 @@ func NewSifApp(
oracle.NewAppModule(app.OracleKeeper),
ethbridge.NewAppModule(app.OracleKeeper, app.BankKeeper, app.AccountKeeper, app.EthbridgeKeeper, &appCodec),
dispensation.NewAppModule(app.DispensationKeeper, app.BankKeeper, app.AccountKeeper),
tokenregistry.NewAppModule(app.TokenRegistryKeeper, &appCodec),
)

// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
// CanWithdrawInvariant invariant.
app.mm.SetOrderBeginBlockers(
capabilitytypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
upgradetypes.ModuleName,
Expand Down Expand Up @@ -415,6 +427,7 @@ func NewSifApp(
oracletypes.ModuleName,
ethbridge.ModuleName,
dispensation.ModuleName,
tokenregistry.ModuleName,
)

app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
Expand Down
200 changes: 200 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,212 @@ import (
"os"
"testing"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/store/rootmulti"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/pkg/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"
)

func TestAppUpgrade_CannotDeleteLatestVersion(t *testing.T) {
// Skip this test that shows how SDK allows stores to get into irrecoverable state and panics
// TODO: Open PR on SDK with this test.
t.Skip()
encCfg := MakeTestEncodingConfig()
db := dbm.NewMemDB()
app := NewSifApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db,
nil,
false,
map[int64]bool{},
DefaultNodeHome,
0,
encCfg,
EmptyAppOptions{},
)
err := app.LoadLatestVersion()
require.NoError(t, err)

genesisState := NewDefaultGenesisState(encCfg.Marshaler)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)

// Initialize the chain
app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
},
)

// Commit enough to trigger beginning of pruning soon
for i := 1; i < 105; i++ {
app.BeginBlock(abci.RequestBeginBlock{Header: types.Header{Height: int64(i)}})
app.EndBlock(abci.RequestEndBlock{Height: int64(i)})
app.Commit()
}

app = NewSifApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db,
nil,
false,
map[int64]bool{},
DefaultNodeHome,
0,
encCfg,
EmptyAppOptions{},
func(app *baseapp.BaseApp) {
cms := rootmulti.NewStore(db)
cms.SetPruning(storetypes.PruneDefault)
app.SetCMS(cms)
},
)
// Mount and load newStore which will be loaded with version 0,
// because it did not load with an "add" upgrade to set it's initialVersion,
// while the other stores will be at version = blockHeight (i.e 1 here).
app.MountKVStores(map[string]*sdk.KVStoreKey{
"newStore": sdk.NewKVStoreKey("newStore"),
})
err = app.LoadLatestVersion()
require.NoError(t, err)

// Commit until just before default pruning is triggered
for i := 105; i <= 109; i++ {
app.BeginBlock(abci.RequestBeginBlock{Header: types.Header{Height: int64(i)}})
app.EndBlock(abci.RequestEndBlock{Height: int64(i)})
app.Commit()
}

// Next commit will panic when trying to prune a height on the new store,
// that is >= the current version of the new store.
defer func() {
err := recover()
require.EqualError(t, err.(error), errors.Errorf("cannot delete latest saved version (%d)", 6).Error())
}()

app.BeginBlock(abci.RequestBeginBlock{Header: types.Header{Height: int64(110)}})
app.EndBlock(abci.RequestEndBlock{Height: int64(110)})
app.Commit()
}

func TestAppUpgrade_CannotLoadCorruptStoreUsingLatestHeight(t *testing.T) {
// Skip this test that shows how SDK allows stores to get installed with 0 height,
// then, after pruning halts chain, it becomes impossible to load them at correct height,
// loosing any data that was added since last upgrade.
// Trying to rename (i.e copy) also fails as old store still errors.
t.Skip()
encCfg := MakeTestEncodingConfig()
db := dbm.NewMemDB()
app := NewSifApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db,
nil,
false,
map[int64]bool{},
DefaultNodeHome,
0,
encCfg,
EmptyAppOptions{},
)
err := app.LoadLatestVersion()
require.NoError(t, err)

genesisState := NewDefaultGenesisState(encCfg.Marshaler)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)

// Initialize the chain
app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
},
)

// Commit enough to trigger beginning of pruning soon
for i := 1; i < 105; i++ {
app.BeginBlock(abci.RequestBeginBlock{Header: types.Header{Height: int64(i)}})
app.EndBlock(abci.RequestEndBlock{Height: int64(i)})
app.Commit()
}

app = NewSifApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db,
nil,
false,
map[int64]bool{},
DefaultNodeHome,
0,
encCfg,
EmptyAppOptions{},
func(app *baseapp.BaseApp) {
cms := rootmulti.NewStore(db)
cms.SetPruning(storetypes.PruneDefault)
app.SetCMS(cms)
},
)
// Mount and load newStore which will be loaded with version 0,
// because it did not load with an "add" upgrade to set it's initialVersion,
// while the other stores will be at version = blockHeight (i.e 1 here).
app.MountKVStores(map[string]*sdk.KVStoreKey{
"newStore": sdk.NewKVStoreKey("newStore"),
})
err = app.LoadLatestVersion()
require.NoError(t, err)

// Commit until just before default pruning is triggered
for i := 105; i <= 109; i++ {
app.BeginBlock(abci.RequestBeginBlock{Header: types.Header{Height: int64(i)}})
app.EndBlock(abci.RequestEndBlock{Height: int64(i)})
app.Commit()
}

// Try to recover the store by setting an "add" store upgrade,
// after it has already been committed to above, before setting initial height.
app = NewSifApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db,
nil,
false,
map[int64]bool{},
DefaultNodeHome,
0,
encCfg,
EmptyAppOptions{},
func(app *baseapp.BaseApp) {
cms := rootmulti.NewStore(db)
cms.SetPruning(storetypes.PruneDefault)
app.SetCMS(cms)
},
)
// Mount and load newStore which will be loaded with version 0,
// because it did not load with an "add" upgrade to set it's initialVersion,
// while the other stores will be at version = blockHeight (i.e 1 here).
app.MountKVStores(map[string]*sdk.KVStoreKey{
"newStore": sdk.NewKVStoreKey("newStore"),
})
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(110, &storetypes.StoreUpgrades{
Added: []string{"newStore"},
}))

// Trigger the upgrade store loader set above, instead of the default store loader.
// Load will error when trying to load new store at current block height,
// because it is > the latest store version (i.e there is an earlier version of the store).
err = app.LoadLatestVersion()
require.Error(t, err)
require.Contains(t, err.Error(), errors.Errorf("initial version set to %v, but found earlier version %v", 110, 1).Error())
}

func TestGetMaccPerms(t *testing.T) {
dup := GetMaccPerms()
require.Equal(t, maccPerms, dup, "duplicated module account permissions differed from actual module account permissions")
Expand Down
Loading

0 comments on commit 35744c0

Please sign in to comment.