Skip to content

Commit

Permalink
Merge pull request #2999 from Sifchain/release/0.13.4
Browse files Browse the repository at this point in the history
Release/0.13.4
  • Loading branch information
joneskm authored Jul 7, 2022
2 parents cdcaaac + 04e7d11 commit c7cfe3f
Show file tree
Hide file tree
Showing 96 changed files with 9,903 additions and 2,214 deletions.
29 changes: 26 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"os"

sifchainAnte "github.com/Sifchain/sifnode/app/ante"
"github.com/Sifchain/sifnode/x/admin"
adminkeeper "github.com/Sifchain/sifnode/x/admin/keeper"
admintypes "github.com/Sifchain/sifnode/x/admin/types"
"github.com/Sifchain/sifnode/x/clp"
clpkeeper "github.com/Sifchain/sifnode/x/clp/keeper"
clptypes "github.com/Sifchain/sifnode/x/clp/types"
Expand Down Expand Up @@ -145,6 +148,7 @@ var (
ethbridge.AppModuleBasic{},
dispensation.AppModuleBasic{},
tokenregistry.AppModuleBasic{},
admin.AppModuleBasic{},
vesting.AppModuleBasic{},
)

Expand Down Expand Up @@ -217,6 +221,7 @@ type SifchainApp struct {
EthbridgeKeeper ethbridgekeeper.Keeper
DispensationKeeper dispkeeper.Keeper
TokenRegistryKeeper tokenregistrytypes.Keeper
AdminKeeper adminkeeper.Keeper

mm *module.Manager
sm *module.SimulationManager
Expand All @@ -227,6 +232,14 @@ func NewSifApp(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
homePath string, invCheckPeriod uint, encodingConfig simappparams.EncodingConfig,
appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp),
) *SifchainApp {
return NewSifAppWithBlacklist(logger, db, traceStore, loadLatest, skipUpgradeHeights, homePath, invCheckPeriod, encodingConfig, appOpts, []sdk.AccAddress{}, baseAppOptions...)
}

func NewSifAppWithBlacklist(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
homePath string, invCheckPeriod uint, encodingConfig simappparams.EncodingConfig,
appOpts servertypes.AppOptions, blackListedAddresses []sdk.AccAddress, baseAppOptions ...func(*baseapp.BaseApp),
) *SifchainApp {
appCodec := encodingConfig.Marshaler
legacyAmino := encodingConfig.Amino
Expand Down Expand Up @@ -255,6 +268,7 @@ func NewSifApp(
clptypes.StoreKey,
oracletypes.StoreKey,
tokenregistrytypes.StoreKey,
admintypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -292,11 +306,16 @@ func NewSifApp(
maccPerms,
)

addrs := app.ModuleAccountAddrs()
for _, addr := range blackListedAddresses {
addrs[addr.String()] = true
}

app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey],
app.AccountKeeper,
app.GetSubspace(banktypes.ModuleName),
app.ModuleAccountAddrs(),
addrs,
)

app.FeegrantKeeper = feegrantkeeper.NewKeeper(
Expand Down Expand Up @@ -340,13 +359,15 @@ func NewSifApp(
)
skipUpgradeHeights[0] = true
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp)
app.TokenRegistryKeeper = tokenregistrykeeper.NewKeeper(appCodec, keys[tokenregistrytypes.StoreKey])
app.AdminKeeper = adminkeeper.NewKeeper(appCodec, keys[admintypes.StoreKey])
app.TokenRegistryKeeper = tokenregistrykeeper.NewKeeper(appCodec, keys[tokenregistrytypes.StoreKey], app.AdminKeeper)
app.ClpKeeper = clpkeeper.NewKeeper(
appCodec,
keys[clptypes.StoreKey],
app.BankKeeper,
app.AccountKeeper,
app.TokenRegistryKeeper,
app.AdminKeeper,
app.MintKeeper,
app.GetSubspace(clptypes.ModuleName),
)
Expand Down Expand Up @@ -405,7 +426,7 @@ func NewSifApp(
app.BankKeeper,
app.OracleKeeper,
app.AccountKeeper,
app.TokenRegistryKeeper,
app.AdminKeeper,
keys[ethbridgetypes.StoreKey],
)

Expand Down Expand Up @@ -464,6 +485,7 @@ func NewSifApp(
ethbridge.NewAppModule(app.OracleKeeper, app.BankKeeper, app.AccountKeeper, app.EthbridgeKeeper, &appCodec),
dispensation.NewAppModule(app.DispensationKeeper, app.BankKeeper, app.AccountKeeper),
tokenregistry.NewAppModule(app.TokenRegistryKeeper, &appCodec),
admin.NewAppModule(app.AdminKeeper, &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
Expand Down Expand Up @@ -505,6 +527,7 @@ func NewSifApp(
ibctransfertypes.ModuleName,
feegrant.ModuleName,
tokenregistrytypes.ModuleName,
admintypes.ModuleName,
clptypes.ModuleName,
oracletypes.ModuleName,
ethbridge.ModuleName,
Expand Down
3 changes: 2 additions & 1 deletion app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package app

import (
"encoding/json"
"github.com/stretchr/testify/assert"
"os"
"testing"

"github.com/stretchr/testify/assert"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/store/rootmulti"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand Down
13 changes: 11 additions & 2 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package app

import (
adminkeeper "github.com/Sifchain/sifnode/x/admin/keeper"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
m "github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

const releaseVersion = "0.13.3"
const releaseVersion = "0.13.4"

func SetupHandlers(app *SifchainApp) {
app.UpgradeKeeper.SetUpgradeHandler(releaseVersion, func(ctx sdk.Context, plan types.Plan, vm m.VersionMap) (m.VersionMap, error) {
app.Logger().Info("Running upgrade handler for " + releaseVersion)

adminMigrator := adminkeeper.NewMigrator(app.AdminKeeper)
err := adminMigrator.InitialMigration(ctx)
if err != nil {
panic(err)
}

return app.mm.RunMigrations(ctx, app.configurator, vm)
})

Expand All @@ -21,7 +28,9 @@ func SetupHandlers(app *SifchainApp) {
panic(err)
}
if upgradeInfo.Name == releaseVersion && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{}
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{"admin"},
}
// Use upgrade store loader for the initial loading of all stores when app starts,
// it checks if version == upgradeHeight and applies store upgrades before loading the stores,
// so that new stores start with the correct version (the current height of chain),
Expand Down
13 changes: 9 additions & 4 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ var DefaultConsensusParams = &abci.ConsensusParams{
},
}

func setup(withGenesis bool, invCheckPeriod uint) (*SifchainApp, GenesisState) {
func setup(withGenesis bool, invCheckPeriod uint, blacklist []sdk.AccAddress) (*SifchainApp, GenesisState) {
db := dbm.NewMemDB()
encCdc := MakeTestEncodingConfig()
app := NewSifApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, EmptyAppOptions{})
app := NewSifAppWithBlacklist(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, EmptyAppOptions{}, blacklist)
if withGenesis {
return app, NewDefaultGenesisState(encCdc.Marshaler)
}
Expand All @@ -52,7 +52,12 @@ func setup(withGenesis bool, invCheckPeriod uint) (*SifchainApp, GenesisState) {

// Setup initializes a new SimApp. A Nop logger is set in SimApp.
func Setup(isCheckTx bool) *SifchainApp {
app, genesisState := setup(!isCheckTx, 5)
return SetupWithBlacklist(isCheckTx, []sdk.AccAddress{})
}

// Setup initializes a new SimApp. A Nop logger is set in SimApp.
func SetupWithBlacklist(isCheckTx bool, blacklist []sdk.AccAddress) *SifchainApp {
app, genesisState := setup(!isCheckTx, 5, blacklist)

if !isCheckTx {
// init chain must be called to stop deliverState from being nil
Expand All @@ -73,7 +78,7 @@ func Setup(isCheckTx bool) *SifchainApp {
}

func SetupFromGenesis(isCheckTx bool, genesisTransformer func(*SifchainApp, GenesisState) GenesisState) *SifchainApp {
app, genesisState := setup(!isCheckTx, 5)
app, genesisState := setup(!isCheckTx, 5, []sdk.AccAddress{})

genesisState = genesisTransformer(app, genesisState)

Expand Down
31 changes: 23 additions & 8 deletions cmd/sifnoded/cmd/setwhitelistadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/spf13/cobra"

tokenregistrytypes "github.com/Sifchain/sifnode/x/tokenregistry/types"
admintypes "github.com/Sifchain/sifnode/x/admin/types"
)

func SetGenesisWhitelisterAdminCmd(defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "set-genesis-whitelister-admin [address_or_key_name]",
Short: "Add a genesis account to genesis.json that has permission to edit token whitelist.",
Short: "Add a genesis account to genesis.json that has permission to manage admin accounts.",
Long: `Add a genesis account to genesis.json. The provided account must specify
the account address or key name. If a key name is given,
the address will be looked up in the local Keybase.
Expand Down Expand Up @@ -55,19 +55,34 @@ the address will be looked up in the local Keybase.
if err != nil {
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
}
state := tokenregistrytypes.UnmarshalGenesis(cdc, appState[tokenregistrytypes.ModuleName])
account := tokenregistrytypes.AdminAccounts{AdminAccounts: []*tokenregistrytypes.AdminAccount{
state := admintypes.UnmarshalGenesis(cdc, appState[admintypes.ModuleName])
state.AdminAccounts = []*admintypes.AdminAccount{
{
AdminAddress: addr.String(),
AdminType: tokenregistrytypes.AdminType_TOKENREGISTRY,
AdminType: admintypes.AdminType_ADMIN,
},
}}
state.AdminAccounts = &account
{
AdminAddress: addr.String(),
AdminType: admintypes.AdminType_TOKENREGISTRY,
},
{
AdminAddress: addr.String(),
AdminType: admintypes.AdminType_PMTPREWARDS,
},
{
AdminAddress: addr.String(),
AdminType: admintypes.AdminType_CLPDEX,
},
{
AdminAddress: addr.String(),
AdminType: admintypes.AdminType_ETHBRIDGE,
},
}
stateBz, err := json.Marshal(state)
if err != nil {
return fmt.Errorf("failed to marshal auth genesis state: %w", err)
}
appState[tokenregistrytypes.ModuleName] = stateBz
appState[admintypes.ModuleName] = stateBz
appStateJSON, err := json.Marshal(appState)
if err != nil {
return fmt.Errorf("failed to marshal application genesis state: %w", err)
Expand Down
46 changes: 46 additions & 0 deletions docs/tutorials/lppd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
1. Initialize and start the chain. From the repo root run the following:

```
make init
make run
```

2. Create pool - add one million dollars of usdt and price rowan at 10c:

```
sifnoded tx clp create-pool \
--from sif \
--keyring-backend test \
--symbol cusdt \
--nativeAmount 10000000000000000000000000 \
--externalAmount 1000000000000 \
--fees 100000000000000000rowan \
--chain-id localnet \
--broadcast-mode block \
-y
```

3. Query the lppd parameters:

```
sifnoded q clp lppd-params
```

4. Set a new lppd policy:

```
sifnoded tx clp set-lppd-params \
--from sif \
--keyring-backend test \
--chain-id localnet \
--broadcast-mode block \
-y \
--path <( echo '[
{
"distribution_period_block_rate": "0.01",
"distribution_period_start_block": 1000,
"distribution_period_mod": 10,
"distribution_period_end_block": 433000
}
]' )
```
67 changes: 67 additions & 0 deletions docs/tutorials/upgrades.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
1. Initialize the chain

```
make init
```

2. Decrease the governance voting period time before first start;


```bash
echo "$(jq '.app_state.gov.voting_params.voting_period = "60s"' $HOME/.sifnoded/config/genesis.json)" > $HOME/.sifnoded/config/genesis.json
```

3. Start the chain:

```
make run
```

4. List upgrade proposals:

```
sifnoded q gov proposals --chain-id localnet
```

5. Raise an upgrade proposal:


```bash
sifnoded tx gov submit-proposal software-upgrade plan_name \
--from sif \
--deposit 10000000000000000000stake \
--upgrade-height 30 \
--upgrade-info '{"binaries":{"linux/amd64":"url_with_checksum"}}' \
--title test_release \
--description "Test Release" \
--keyring-backend test \
--chain-id localnet \
--broadcast-mode block \
--fees 100000000000000000rowan \
-y
```

6. Check deposits:

```
sifnoded q gov deposits 1
```

7. Vote on proposal:

```
sifnoded tx gov vote 1 yes --from sif --chain-id localnet --keyring-backend test -y --broadcast-mode block
```

The node will have a consensus failure when it reaches the "upgrade-height". Restarting the node will not be enough for the chain to continue a new sifnoded release is required

8. Make a new sifnoded release:

i. Update "version" file content to "plan_name"
ii. Update "app/setup_handlers.go" "releaseVersion" constant to "plan_name"

6. Run the new release:

```
make run
```
19 changes: 19 additions & 0 deletions proto/sifnode/admin/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
syntax = "proto3";
package sifnode.admin.v1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "sifnode/admin/v1/types.proto";

option go_package = "github.com/Sifchain/sifnode/x/admin/types";

// Query defines the gRPC querier service.
service Query {
rpc ListAccounts(ListAccountsRequest) returns (ListAccountsResponse) {}
}

message ListAccountsRequest {}

message ListAccountsResponse {
repeated AdminAccount keys = 2;
}
Loading

0 comments on commit c7cfe3f

Please sign in to comment.