From f25f7984438e21599de6cff8193e458cc10e700e Mon Sep 17 00:00:00 2001 From: turtlebasket Date: Thu, 22 Sep 2022 23:18:08 +0000 Subject: [PATCH] new auction tx & event emission includes hw specs [UNTESTED] --- go.mod | 1 - go.sum | 2 - .../keeper/msg_server_new_auction.go | 42 +++++++++++++++++++ x/colinearcore/types/keys.go | 9 ++-- 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 30cc3b9..4774928 100644 --- a/go.mod +++ b/go.mod @@ -88,7 +88,6 @@ require ( github.com/gorilla/handlers v1.5.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect github.com/gtank/merlin v0.1.1 // indirect github.com/gtank/ristretto255 v0.1.2 // indirect diff --git a/go.sum b/go.sum index ad897ba..07b1083 100644 --- a/go.sum +++ b/go.sum @@ -734,8 +734,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= diff --git a/x/colinearcore/keeper/msg_server_new_auction.go b/x/colinearcore/keeper/msg_server_new_auction.go index 26da787..6db6b2a 100644 --- a/x/colinearcore/keeper/msg_server_new_auction.go +++ b/x/colinearcore/keeper/msg_server_new_auction.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "encoding/json" "errors" "fmt" "math/big" @@ -87,6 +88,12 @@ found: LeaseEnd: msg.LeaseEnd, // remaining payout -> null // Remaining: "0", + Gpus: msg.Gpus, + } + + // validate hardware + if err := k.ValidateAuctionHardware(ctx, auction); err != nil { + return nil, err } spendable := k.bank.SpendableCoins(ctx, senderAddr) @@ -111,12 +118,22 @@ found: k.Keeper.SetNextAuction(ctx, types.NextAuction{AuctionId: next.AuctionId}) + gpuList, err := json.Marshal(msg.Gpus) + if err != nil { + return nil, fmt.Errorf("failed to marshal gpu list %v", msg.Gpus) + } + ctx.EventManager().EmitEvent( sdk.NewEvent( types.AuctionCreatedEventType, sdk.NewAttribute(types.AuctionCreatedIndex, auction.Index), sdk.NewAttribute(types.AuctionCreatedEventCreator, msg.Creator), sdk.NewAttribute(types.AuctionCreatedCeiling, msg.Ceiling), + sdk.NewAttribute(types.AuctionCreatedCpuCores, msg.CpuArch.String()), + sdk.NewAttribute(types.AuctionCreatedCpuArch, msg.CpuArch.String()), + sdk.NewAttribute(types.AuctionCreatedGpus, string(gpuList)), + sdk.NewAttribute(types.AuctionCreatedMemMb, fmt.Sprint(msg.MemMb)), + sdk.NewAttribute(types.AuctionCreatedStorage, fmt.Sprint(msg.StorageGb)), ), ) @@ -124,3 +141,28 @@ found: AuctionId: strconv.FormatUint(next.AuctionId, 10), }, nil } + +func (k *Keeper) ValidateAuctionHardware(ctx sdk.Context, a types.Auction) error { + + if a.Gpus == nil { + return errors.New("GPU list not found") + } + + for _, gpu := range a.Gpus { + if _, ok := k.GetParams(ctx).GpuModels[gpu]; !ok { + return fmt.Errorf("GPU model %s invalid", gpu) + } + } + + // move these to module params later + + if a.CpuCores == 0 || a.CpuCores > 12 { + return errors.New("CPU Cores must be between 0 and 12") + } + + if a.StorageGb < 25 || a.StorageGb > 2000 { + return fmt.Errorf("storage must be between 25GB and 2TB (got %dGB)", a.StorageGb) + } + + return nil +} diff --git a/x/colinearcore/types/keys.go b/x/colinearcore/types/keys.go index b374fe6..a495ce9 100644 --- a/x/colinearcore/types/keys.go +++ b/x/colinearcore/types/keys.go @@ -37,10 +37,11 @@ const ( AuctionCreatedIndex = "auction-id" AuctionCreatedCeiling = "ceiling" // hardware - // AuctionCreatedGpu = "gpu" - // AuctionCreatedCpuArch = "cpu-arch" - // AuctionCreatedMemMb = "mem-mb" - // AuctionCreatedStorage = "storage" + AuctionCreatedGpus = "gpus" + AuctionCreatedCpuArch = "cpu-arch" + AuctionCreatedCpuCores = "cpu-cores" + AuctionCreatedMemMb = "mem-mb" + AuctionCreatedStorage = "storage-gb" ) const (