From f2dd42f24bf0694c54949a8f3d8049175b81f70f Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Wed, 15 Nov 2023 14:22:52 -0800 Subject: [PATCH] fix(market): save resources offer to the bid Signed-off-by: Artur Troian --- go.mod | 3 ++- go.sum | 4 ++-- x/market/handler/handler_test.go | 9 ++++++--- x/market/handler/server.go | 6 +++++- x/market/keeper/keeper.go | 14 +++++++------- x/market/keeper/keeper_test.go | 6 ++++-- x/provider/handler/handler_test.go | 4 +++- 7 files changed, 29 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index af5aed77cc..34907697a4 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/akash-network/node go 1.21 require ( - github.com/akash-network/akash-api v0.0.32 + github.com/akash-network/akash-api v0.0.33 github.com/blang/semver/v4 v4.0.0 github.com/boz/go-lifecycle v0.1.1 github.com/cosmos/cosmos-sdk v0.45.16 @@ -37,6 +37,7 @@ require ( ) retract ( + v0.28.1 v0.28.0 v0.26.0 v0.22.1 diff --git a/go.sum b/go.sum index 0730dd35de..5d2d2a5ded 100644 --- a/go.sum +++ b/go.sum @@ -100,8 +100,8 @@ github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBA github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= -github.com/akash-network/akash-api v0.0.32 h1:YkvFWUyyK6WKsERAcWCxWoIDXFQLLioTZ5iVI6Bvbv4= -github.com/akash-network/akash-api v0.0.32/go.mod h1:pW5NnJNhxynCOUGEcgxa338GSU2qzMkpn3MMYcAY6O4= +github.com/akash-network/akash-api v0.0.33 h1:SvOht1F3BDz3el8XKC7lbRzc6D++kERs5wFRisMWzCY= +github.com/akash-network/akash-api v0.0.33/go.mod h1:pW5NnJNhxynCOUGEcgxa338GSU2qzMkpn3MMYcAY6O4= github.com/akash-network/cometbft v0.34.27-akash h1:V1dApDOr8Ee7BJzYyQ7Z9VBtrAul4+baMeA6C49dje0= github.com/akash-network/cometbft v0.34.27-akash/go.mod h1:BcCbhKv7ieM0KEddnYXvQZR+pZykTKReJJYf7YC7qhw= github.com/akash-network/ledger-go v0.14.3 h1:LCEFkTfgGA2xFMN2CtiKvXKE7dh0QSM77PJHCpSkaAo= diff --git a/x/market/handler/handler_test.go b/x/market/handler/handler_test.go index 093b06a59d..cb78c5769d 100644 --- a/x/market/handler/handler_test.go +++ b/x/market/handler/handler_test.go @@ -389,8 +389,9 @@ func TestCloseBidUnknownOrder(t *testing.T) { orderID := types.MakeOrderID(group.ID(), 1) provider := testutil.AccAddress(t) price := sdk.NewDecCoin(testutil.CoinDenom, sdk.NewInt(int64(rand.Uint16()))) + roffer := types.ResourceOfferFromRU(group.GroupSpec.Resources) - bid, err := suite.MarketKeeper().CreateBid(suite.Context(), orderID, provider, price) + bid, err := suite.MarketKeeper().CreateBid(suite.Context(), orderID, provider, price, roffer) require.NoError(t, err) suite.MarketKeeper().CreateLease(suite.Context(), bid) @@ -418,10 +419,12 @@ func (st *testSuite) createLease() (types.LeaseID, types.Bid, types.Order) { func (st *testSuite) createBid() (types.Bid, types.Order) { st.t.Helper() - order, _ := st.createOrder(testutil.Resources(st.t)) + order, gspec := st.createOrder(testutil.Resources(st.t)) provider := testutil.AccAddress(st.t) price := sdk.NewDecCoin(testutil.CoinDenom, sdk.NewInt(int64(rand.Uint16()))) - bid, err := st.MarketKeeper().CreateBid(st.Context(), order.ID(), provider, price) + roffer := types.ResourceOfferFromRU(gspec.Resources) + + bid, err := st.MarketKeeper().CreateBid(st.Context(), order.ID(), provider, price, roffer) require.NoError(st.t, err) require.Equal(st.t, order.ID(), bid.ID().OrderID()) require.Equal(st.t, price, bid.Price) diff --git a/x/market/handler/server.go b/x/market/handler/server.go index 6bdae78c2b..f96defcf1c 100644 --- a/x/market/handler/server.go +++ b/x/market/handler/server.go @@ -59,6 +59,10 @@ func (ms msgServer) CreateBid(goCtx context.Context, msg *types.MsgCreateBid) (* return nil, types.ErrBidOverOrder } + if !msg.ResourcesOffer.MatchGSpec(order.Spec) { + return nil, types.ErrCapabilitiesMismatch + } + provider, err := sdk.AccAddressFromBech32(msg.Provider) if err != nil { return nil, types.ErrEmptyProvider @@ -84,7 +88,7 @@ func (ms msgServer) CreateBid(goCtx context.Context, msg *types.MsgCreateBid) (* return nil, types.ErrCapabilitiesMismatch } - bid, err := ms.keepers.Market.CreateBid(ctx, msg.Order, provider, msg.Price) + bid, err := ms.keepers.Market.CreateBid(ctx, msg.Order, provider, msg.Price, msg.ResourcesOffer) if err != nil { return nil, err } diff --git a/x/market/keeper/keeper.go b/x/market/keeper/keeper.go index be37d7e93e..466dcd0a34 100644 --- a/x/market/keeper/keeper.go +++ b/x/market/keeper/keeper.go @@ -19,7 +19,7 @@ type IKeeper interface { Codec() codec.BinaryCodec StoreKey() sdk.StoreKey CreateOrder(ctx sdk.Context, gid dtypes.GroupID, spec dtypes.GroupSpec) (types.Order, error) - CreateBid(ctx sdk.Context, oid types.OrderID, provider sdk.AccAddress, price sdk.DecCoin) (types.Bid, error) + CreateBid(ctx sdk.Context, oid types.OrderID, provider sdk.AccAddress, price sdk.DecCoin, roffer types.ResourcesOffer) (types.Bid, error) CreateLease(ctx sdk.Context, bid types.Bid) OnOrderMatched(ctx sdk.Context, order types.Order) OnBidMatched(ctx sdk.Context, bid types.Bid) @@ -52,7 +52,6 @@ type Keeper struct { // NewKeeper creates and returns an instance for Market keeper func NewKeeper(cdc codec.BinaryCodec, skey sdk.StoreKey, pspace paramtypes.Subspace, ekeeper EscrowKeeper) IKeeper { - if !pspace.HasKeyTable() { pspace = pspace.WithKeyTable(types.ParamKeyTable()) } @@ -122,14 +121,15 @@ func (k Keeper) CreateOrder(ctx sdk.Context, gid dtypes.GroupID, spec dtypes.Gro } // CreateBid creates a bid for a order with given orderID, price for bid and provider -func (k Keeper) CreateBid(ctx sdk.Context, oid types.OrderID, provider sdk.AccAddress, price sdk.DecCoin) (types.Bid, error) { +func (k Keeper) CreateBid(ctx sdk.Context, oid types.OrderID, provider sdk.AccAddress, price sdk.DecCoin, roffer types.ResourcesOffer) (types.Bid, error) { store := ctx.KVStore(k.skey) bid := types.Bid{ - BidID: types.MakeBidID(oid, provider), - State: types.BidOpen, - Price: price, - CreatedAt: ctx.BlockHeight(), + BidID: types.MakeBidID(oid, provider), + State: types.BidOpen, + Price: price, + CreatedAt: ctx.BlockHeight(), + ResourcesOffer: roffer, } key := keys.BidKey(bid.ID()) diff --git a/x/market/keeper/keeper_test.go b/x/market/keeper/keeper_test.go index 846080b7f0..54d4dac40b 100644 --- a/x/market/keeper/keeper_test.go +++ b/x/market/keeper/keeper_test.go @@ -299,10 +299,12 @@ func createLease(t testing.TB, suite *state.TestSuite) types.LeaseID { func createBid(t testing.TB, suite *state.TestSuite) (types.Bid, types.Order) { t.Helper() ctx := suite.Context() - order, _ := createOrder(t, suite.Context(), suite.MarketKeeper()) + order, gspec := createOrder(t, suite.Context(), suite.MarketKeeper()) provider := testutil.AccAddress(t) price := testutil.AkashDecCoinRandom(t) - bid, err := suite.MarketKeeper().CreateBid(ctx, order.ID(), provider, price) + roffer := types.ResourceOfferFromRU(gspec.Resources) + + bid, err := suite.MarketKeeper().CreateBid(ctx, order.ID(), provider, price, roffer) require.NoError(t, err) assert.Equal(t, order.ID(), bid.ID().OrderID()) assert.Equal(t, price, bid.Price) diff --git a/x/provider/handler/handler_test.go b/x/provider/handler/handler_test.go index f785ef57d9..98ff213ba4 100644 --- a/x/provider/handler/handler_test.go +++ b/x/provider/handler/handler_test.go @@ -9,6 +9,7 @@ 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" @@ -234,8 +235,9 @@ func TestProviderUpdateAttributes(t *testing.T) { 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) + bid, err := suite.mkeeper.CreateBid(suite.ctx, order.ID(), addr, price, roffer) require.NoError(t, err) suite.mkeeper.CreateLease(suite.ctx, bid)