parent
98c082693d
commit
f25f798443
1
go.mod
1
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
|
||||
|
|
2
go.sum
2
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=
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 (
|
||||
|
|
Loading…
Reference in New Issue