Skip to content

Commit

Permalink
feat(upgrade): create v0.26.0 network upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <troian.ap@gmail.com>
  • Loading branch information
troian committed Sep 14, 2023
1 parent ac8bc43 commit 365302a
Show file tree
Hide file tree
Showing 8 changed files with 419 additions and 11 deletions.
5 changes: 5 additions & 0 deletions meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"skipped": false,
"from_binary": "v0.22.8",
"from_version": "v0.22.0"
},
"v0.26.0": {
"skipped": false,
"from_binary": "v0.24.2",
"from_version": "v0.24.0"
}
}
}
19 changes: 8 additions & 11 deletions tests/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ var (
nodeTestStagePostUpgrade: "postupgrade",
}

testStageMapStr = map[testStage]string{
testStagePreUpgrade: "preupgrade",
testStageUpgrade: "upgrade",
testStagePostUpgrade: "postupgrade",
}

testModuleStatusMapStr = map[testModuleStatus]string{
testModuleStatusUnexpected: "unexpected",
testModuleStatusNotChecked: "notchecked",
Expand Down Expand Up @@ -563,13 +557,12 @@ loop:

if stageCount == 0 {
l.t.Log("all nodes performed upgrade")
for _, val := range l.validators {
_ = val.pubsub.Publish(eventShutdown{})
}

postUpgradeWorker := uttypes.GetPostUpgradeWorker(l.upgradeName)
if postUpgradeWorker == nil {
l.t.Log("no post upgrade handlers found. submitting shutdown")
_ = bus.Publish(postUpgradeTestDone{})

break loop
}

Expand All @@ -593,6 +586,10 @@ loop:
})
}
case postUpgradeTestDone:
for _, val := range l.validators {
_ = val.pubsub.Publish(eventShutdown{})
}

break loop
}
}
Expand Down Expand Up @@ -764,7 +761,7 @@ func executeCommand(ctx context.Context, env []string, cmd string, args ...strin
}

func (l *validator) run() error {
lStdout, err := os.Create(fmt.Sprintf("%s/%s-stdout.log", l.params.home, l.params.name))
lStdout, err := os.Create(fmt.Sprintf("%s/logs/%s-stdout.log", l.params.home, l.params.name))
if err != nil {
return err
}
Expand All @@ -773,7 +770,7 @@ func (l *validator) run() error {
_ = lStdout.Close()
}()

lStderr, err := os.Create(fmt.Sprintf("%s/%s-stderr.log", l.params.home, l.params.name))
lStderr, err := os.Create(fmt.Sprintf("%s/logs/%s-stderr.log", l.params.home, l.params.name))
if err != nil {
return err
}
Expand Down
176 changes: 176 additions & 0 deletions tests/upgrade/v0.26.0/postupgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
//go:build e2e.upgrade

// Package v0_26_0
// nolint revive
package v0_26_0

import (
"context"
"fmt"
"strings"
"testing"

// v1beta2dtypes "github.com/akash-network/akash-api/go/node/deployment/v1beta2"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/authz"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

astaking "github.com/akash-network/akash-api/go/node/staking/v1beta3"

"github.com/akash-network/node/app"
uttypes "github.com/akash-network/node/tests/upgrade/types"
)

func init() {
uttypes.RegisterPostUpgradeWorker("v0.26.0", &postUpgrade{})
}

type postUpgrade struct{}

var _ uttypes.TestWorker = (*postUpgrade)(nil)

func (pu *postUpgrade) Run(ctx context.Context, t *testing.T, params uttypes.TestParams) {
encodingConfig := app.MakeEncodingConfig()

rpcClient, err := client.NewClientFromNode(params.Node)
require.NoError(t, err)

cctx := client.Context{}.
WithCodec(encodingConfig.Marshaler).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithLegacyAmino(encodingConfig.Amino).
WithAccountRetriever(authtypes.AccountRetriever{}).
WithBroadcastMode(flags.BroadcastBlock).
WithHomeDir(params.Home).
WithChainID(params.ChainID).
WithNodeURI(params.Node).
WithClient(rpcClient)

kr, err := client.NewKeyringFromBackend(cctx, params.KeyringBackend)
require.NoError(t, err)

cctx = cctx.WithKeyring(kr)

validateValidatorsCommission(ctx, cctx, t)
validateDeploymentAuthz(ctx, cctx, t)
}

func validateDeploymentAuthz(ctx context.Context, cctx client.Context, t *testing.T) {
authQc := authtypes.NewQueryClient(cctx)
authzQc := authz.NewQueryClient(cctx)

var pkey []byte

accs := make([]sdk.AccAddress, 0, 100000)

for {
var pgn *query.PageRequest
if pkey != nil {
pgn = &query.PageRequest{
Key: pkey,
}
}

result, err := authQc.Accounts(ctx, &authtypes.QueryAccountsRequest{
Pagination: pgn,
})

require.NoError(t, err)

for _, accI := range result.Accounts {
var acc authtypes.AccountI
err := cctx.Codec.UnpackAny(accI, &acc)
require.NoError(t, err)

accs = append(accs, acc.GetAddress())
}

if pg := result.Pagination; pg != nil && len(pg.NextKey) > 0 {
pkey = pg.NextKey
} else {
break
}
}

for _, acc := range accs {
result, err := authzQc.GranterGrants(ctx, &authz.QueryGranterGrantsRequest{Granter: acc.String()})
require.NoError(t, err)

if len(result.Grants) == 0 {
continue
}

for _, grant := range result.Grants {
assert.NotEqual(t,
"/akash.deployment.v1beta2.DepositDeploymentAuthorization",
grant.Authorization.GetTypeUrl(),
"detected non-migrated v1beta2.DepositDeploymentAuthorization. granter: (%s), grantee: (%s)", grant.Granter, grant.Grantee)
// authzOld := &v1beta2dtypes.DepositDeploymentAuthorization{}
//
// err := cctx.Codec.UnpackAny(grant.Authorization, authzOld)
// assert.Error(t, err, "detected non-migrated v1beta2.DepositDeploymentAuthorization. granter: (%s), grantee: (%s)", grant.Granter, grant.Grantee)
}
}
}

func validateValidatorsCommission(ctx context.Context, cctx client.Context, t *testing.T) {
pqc := proposal.NewQueryClient(cctx)
res, err := pqc.Params(ctx, &proposal.QueryParamsRequest{
Subspace: stakingtypes.ModuleName,
Key: string(stakingtypes.KeyMaxValidators),
})
require.NoError(t, err)

require.NoError(t, err)

res, err = pqc.Params(ctx, &proposal.QueryParamsRequest{
Subspace: astaking.ModuleName,
Key: string(astaking.KeyMinCommissionRate),
})
require.NoError(t, err)

minCommission, err := sdk.NewDecFromStr(strings.Trim(res.Param.Value, "\""))
require.NoError(t, err)

sqc := stakingtypes.NewQueryClient(cctx)

var pkey []byte

for {
var pgn *query.PageRequest
if pkey != nil {
pgn = &query.PageRequest{
Key: pkey,
}
}

result, err := sqc.Validators(ctx, &stakingtypes.QueryValidatorsRequest{
Pagination: pgn,
})
require.NoError(t, err)

for _, validator := range result.Validators {
assert.True(t, validator.Commission.Rate.GTE(minCommission),
fmt.Sprintf("invalid commission Rate for validator (%s). (%s%%) < (%s%%)MinCommission",
validator.OperatorAddress, validator.Commission.Rate.String(), minCommission.String()))

assert.True(t, validator.Commission.MaxRate.GTE(minCommission),
fmt.Sprintf("invalid commission MaxRate for validator (%s). (%s%%) < (%s%%)MinCommission",
validator.OperatorAddress, validator.Commission.MaxRate.String(), minCommission.String()))
}

if pg := result.Pagination; pg != nil && len(pg.NextKey) > 0 {
pkey = pg.NextKey
} else {
break
}
}
}
7 changes: 7 additions & 0 deletions tests/upgrade/workers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build e2e.upgrade

package upgrade

import (
_ "github.com/akash-network/node/tests/upgrade/v0.26.0"
)
4 changes: 4 additions & 0 deletions upgrades/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Goal of the upgrade here
Add new upgrades after this line based on the template above
-----

##### v0.26.0

1. Enforce **Minimum Validators commission** using onchain parameter. Default value is set to 5%. This is carry-over from v0.24.0 upgrade, as this change was dry-run

##### v0.24.0

1. Update following stores to the `v1beta3`:
Expand Down
11 changes: 11 additions & 0 deletions upgrades/software/v0.26.0/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Package v0_26_0
// nolint revive
package v0_26_0

import (
utypes "github.com/akash-network/node/upgrades/types"
)

func init() {
utypes.RegisterUpgrade(UpgradeName, initUpgrade)
}
Loading

0 comments on commit 365302a

Please sign in to comment.