Skip to content

Commit

Permalink
feat(upgrade): network upgrade v0.32.0
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 Mar 6, 2024
1 parent 88c34f8 commit 32d8340
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 70 deletions.
5 changes: 5 additions & 0 deletions meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"skipped": false,
"from_binary": "v0.28.2",
"from_version": "v0.28.0"
},
"v0.32.0": {
"skipped": false,
"from_binary": "v0.30.3",
"from_version": "v0.30.0"
}
}
}
8 changes: 8 additions & 0 deletions tests/upgrade/upgrade-v0.32.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"migrations": {
"market": {
"from": "4",
"to": "5"
}
}
}
1 change: 1 addition & 0 deletions tests/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ func TestUpgrade(t *testing.T) {
postUpgradeParams.ChainID = cfg.ChainID
postUpgradeParams.Node = "tcp://127.0.0.1:26657"
postUpgradeParams.KeyringBackend = "test"
postUpgradeParams.From = cfg.Work.Key

cmdr = valCmd

Expand Down
118 changes: 118 additions & 0 deletions tests/upgrade/v0.32.0/postupgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//go:build e2e.upgrade

// Package v0_32_0
// nolint revive
package v0_32_0

import (
"context"
"testing"

types "github.com/akash-network/akash-api/go/node/types/v1beta3"
sdkclient "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/stretchr/testify/require"

cltypes "github.com/akash-network/akash-api/go/node/client/types"
ptypes "github.com/akash-network/akash-api/go/node/provider/v1beta3"

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

func init() {
uttypes.RegisterPostUpgradeWorker("v0.32.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 := sdkclient.NewClientFromNode(params.Node)
require.NoError(t, err)

cctx := sdkclient.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).
WithSkipConfirmation(true).
WithFrom(params.From).
WithKeyringDir(params.Home)

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

info, err := kr.Key(params.From)
require.NoError(t, err)

cctx = cctx.WithFromName(info.GetName()).
WithFromAddress(info.GetAddress()).
WithKeyring(kr)

cl, err := client.DiscoverClient(ctx, cctx, cltypes.WithGasPrices("0.0025uakt"), cltypes.WithGas(flags.GasSetting{Simulate: false, Gas: 100000}))
require.NoError(t, err)
require.NotNil(t, cl)

cmsg := &ptypes.MsgCreateProvider{
Owner: cctx.GetFromAddress().String(),
HostURI: "https://example.com:443",
Info: ptypes.ProviderInfo{},
Attributes: types.Attributes{
{
Key: "test1",
Value: "test1",
},
},
}

err = cmsg.ValidateBasic()
require.NoError(t, err)

resp, err := cl.Tx().Broadcast(ctx, []sdk.Msg{cmsg})
require.NoError(t, err)
require.NotNil(t, resp)
require.IsType(t, &sdk.TxResponse{}, resp)

txResp := resp.(*sdk.TxResponse)

require.Equal(t, uint32(0), txResp.Code)

pmsg := &ptypes.MsgUpdateProvider{
Owner: cctx.GetFromAddress().String(),
HostURI: "https://example.com:443",
Info: ptypes.ProviderInfo{},
Attributes: types.Attributes{
{
Key: "test1",
Value: "test1",
},
},
}

err = cmsg.ValidateBasic()
require.NoError(t, err)

resp, err = cl.Tx().Broadcast(ctx, []sdk.Msg{pmsg})
require.NoError(t, err)
require.NotNil(t, resp)
require.IsType(t, &sdk.TxResponse{}, resp)

txResp = resp.(*sdk.TxResponse)

require.Equal(t, uint32(0), txResp.Code)
require.LessOrEqual(t, txResp.GasUsed, int64(100000))
}
1 change: 1 addition & 0 deletions tests/upgrade/workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ package upgrade

import (
_ "github.com/akash-network/node/tests/upgrade/v0.26.0"
_ "github.com/akash-network/node/tests/upgrade/v0.32.0"
)
10 changes: 9 additions & 1 deletion upgrades/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
| escrow | 2 |
| agov | 1 |
| inflation | 1 |
| market | 4 |
| market | 5 |
| provider | 2 |
| astaking | 1 |
| take | 1 |
Expand Down Expand Up @@ -43,6 +43,14 @@ Goal of the upgrade here
Add new upgrades after this line based on the template above
-----

##### v0.32.0

1. remove checking if provider has active leases during provider update transactions. This check was iterating thru all existing leases on the network causing gas and thus transaction fees go to up to 3AKT which is way above desired values. Initial intention of check was to prevent provider changing attributes that is in use by active leases. Akash Network team will reintroduce check by adding secondary indexes in future network upgrades.
2. remove secondary index for market store which was never user.

- Migrations
- market `4 -> 5`

##### v0.30.0

1. fix `MatchGSpec` which used during Bid validation. Previous upgrade **v0.28.0** brought up resources offer.Existing implementation of `MatchGSpec` improperly validates offer against group spec, which rejects bids on multi-service deployments with unequal amount of replicas.
Expand Down
14 changes: 14 additions & 0 deletions upgrades/software/v0.32.0/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Package v0_32_0
// nolint revive
package v0_32_0

import (
mv1beta4 "github.com/akash-network/akash-api/go/node/market/v1beta4"

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

func init() {
utypes.RegisterUpgrade(UpgradeName, initUpgrade)
utypes.RegisterMigration(mv1beta4.ModuleName, 4, newMarketMigration)
}
39 changes: 39 additions & 0 deletions upgrades/software/v0.32.0/market.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Package v0_32_0
// nolint revive
package v0_32_0

import (
types "github.com/akash-network/akash-api/go/node/market/v1beta4"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkmodule "github.com/cosmos/cosmos-sdk/types/module"

utypes "github.com/akash-network/node/upgrades/types"
"github.com/akash-network/node/x/market/keeper/keys/v1beta4"
)

type marketMigrations struct {
utypes.Migrator
}

func newMarketMigration(m utypes.Migrator) utypes.Migration {
return marketMigrations{Migrator: m}
}

func (m marketMigrations) GetHandler() sdkmodule.MigrationHandler {
return m.handler
}

// handler migrates market from version 3 to 4.
func (m marketMigrations) handler(ctx sdk.Context) error {
store := ctx.KVStore(m.StoreKey())
iter := sdk.KVStorePrefixIterator(store, types.LeasePrefix())
defer iter.Close()
for ; iter.Valid(); iter.Next() {
var val types.Lease
m.Codec().MustUnmarshal(iter.Value(), &val)

store.Delete(v1beta4.SecondaryLeaseKeyByProvider(val.LeaseID))
}

Check warning on line 36 in upgrades/software/v0.32.0/market.go

View check run for this annotation

Codecov / codecov/patch

upgrades/software/v0.32.0/market.go#L27-L36

Added lines #L27 - L36 were not covered by tests

return nil

Check warning on line 38 in upgrades/software/v0.32.0/market.go

View check run for this annotation

Codecov / codecov/patch

upgrades/software/v0.32.0/market.go#L38

Added line #L38 was not covered by tests
}
47 changes: 47 additions & 0 deletions upgrades/software/v0.32.0/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Package v0_32_0
// nolint revive
package v0_32_0

import (
"fmt"

"github.com/tendermint/tendermint/libs/log"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

apptypes "github.com/akash-network/node/app/types"
utypes "github.com/akash-network/node/upgrades/types"
)

const (
UpgradeName = "v0.32.0"
)

type upgrade struct {
*apptypes.App
log log.Logger
}

var _ utypes.IUpgrade = (*upgrade)(nil)

func initUpgrade(log log.Logger, app *apptypes.App) (utypes.IUpgrade, error) {
up := &upgrade{
App: app,
log: log.With("module", fmt.Sprintf("upgrade/%s", UpgradeName)),
}

return up, nil
}

func (up *upgrade) StoreLoader() *storetypes.StoreUpgrades {
return &storetypes.StoreUpgrades{}
}

func (up *upgrade) UpgradeHandler() upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return up.MM.RunMigrations(ctx, up.Configurator, fromVM)
}

Check warning on line 46 in upgrades/software/v0.32.0/upgrade.go

View check run for this annotation

Codecov / codecov/patch

upgrades/software/v0.32.0/upgrade.go#L45-L46

Added lines #L45 - L46 were not covered by tests
}
2 changes: 2 additions & 0 deletions upgrades/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package upgrades

import (
// nolint: revive
_ "github.com/akash-network/node/upgrades/software/v0.32.0"
// nolint: revive
_ "github.com/akash-network/node/upgrades/software/v0.30.0"
// nolint: revive
Expand Down
5 changes: 0 additions & 5 deletions x/market/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ func (k Keeper) CreateLease(ctx sdk.Context, bid types.Bid) {
types.NewEventLeaseCreated(lease.ID(), lease.Price).
ToSDKEvent(),
)

secondaryKeys := keys.SecondaryKeysForLease(lease.ID())
for _, secondaryKey := range secondaryKeys {
store.Set(secondaryKey, key)
}
}

// OnOrderMatched updates order state to matched
Expand Down
4 changes: 2 additions & 2 deletions x/market/keeper/keys/v1beta4/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func LeaseKey(id types.LeaseID) []byte {
return buf.Bytes()
}

func secondaryLeaseKeyByProvider(id types.LeaseID) []byte {
func SecondaryLeaseKeyByProvider(id types.LeaseID) []byte {

Check warning on line 117 in x/market/keeper/keys/v1beta4/key.go

View check run for this annotation

Codecov / codecov/patch

x/market/keeper/keys/v1beta4/key.go#L117

Added line #L117 was not covered by tests
buf := bytes.NewBuffer(types.SecondaryLeasePrefix())
buf.Write(address.MustLengthPrefix(sdkutil.MustAccAddressFromBech32(id.Provider)))
buf.Write(address.MustLengthPrefix(sdkutil.MustAccAddressFromBech32(id.Owner)))
Expand All @@ -132,7 +132,7 @@ func secondaryLeaseKeyByProvider(id types.LeaseID) []byte {

func SecondaryKeysForLease(id types.LeaseID) [][]byte {
return [][]byte{
secondaryLeaseKeyByProvider(id),
SecondaryLeaseKeyByProvider(id),

Check warning on line 135 in x/market/keeper/keys/v1beta4/key.go

View check run for this annotation

Codecov / codecov/patch

x/market/keeper/keys/v1beta4/key.go#L135

Added line #L135 was not covered by tests
}
}

Expand Down
35 changes: 1 addition & 34 deletions x/provider/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"

mtypes "github.com/akash-network/akash-api/go/node/market/v1beta4"
types "github.com/akash-network/akash-api/go/node/provider/v1beta3"

akashtypes "github.com/akash-network/akash-api/go/node/types/v1beta3"
Expand Down Expand Up @@ -224,42 +223,10 @@ func TestProviderUpdateAttributes(t *testing.T) {
err := suite.keeper.Create(suite.ctx, types.Provider(*createMsg))
require.NoError(t, err)

group := testutil.DeploymentGroup(t, testutil.DeploymentID(t), 0)

group.GroupSpec.Resources = testutil.Resources(t)
group.GroupSpec.Requirements = akashtypes.PlacementRequirements{
Attributes: createMsg.Attributes,
}

order, err := suite.mkeeper.CreateOrder(suite.ctx, group.ID(), group.GroupSpec)
require.NoError(t, err)

price := testutil.DecCoin(t)
roffer := mtypes.ResourceOfferFromRU(group.GroupSpec.Resources)

bid, err := suite.mkeeper.CreateBid(suite.ctx, order.ID(), addr, price, roffer)
require.NoError(t, err)

suite.mkeeper.CreateLease(suite.ctx, bid)

updateMsg.Attributes = nil
res, err := suite.handler(suite.ctx, updateMsg)
require.NoError(t, err)
require.NotNil(t, res)

t.Run("ensure event created", func(t *testing.T) {

iev := testutil.ParseProviderEvent(t, res.Events[4:])
require.IsType(t, types.EventProviderUpdated{}, iev)

dev := iev.(types.EventProviderUpdated)

require.Equal(t, updateMsg.Owner, dev.Owner.String())
})

updateMsg.Attributes = nil
res, err = suite.handler(suite.ctx, updateMsg)
require.Error(t, err, types.ErrIncompatibleAttributes.Error())
require.Nil(t, res)
}

func TestProviderDeleteExisting(t *testing.T) {
Expand Down

0 comments on commit 32d8340

Please sign in to comment.