Repository: ovrclk/akash
Pull request #1087 (2021-02-14 07:38:44)

feat(validation-limits): increase resource limits


Patch:
diff --git a/_run/common-commands.mk b/_run/common-commands.mk
index 6bb5a390..8d9c9989 100644
--- a/_run/common-commands.mk
+++ b/_run/common-commands.mk
@@ -44,6 +44,12 @@ deployment-create:
 		--dseq "$(DSEQ)" 			   \
 		--from "$(KEY_NAME)"
 
+.PHONY: deployment-deposit
+deployment-deposit:
+	$(AKASHCTL) tx deployment deposit "$(KEY_OPTS)" "$(CHAIN_OPTS)" "$(PRICE)" -y \
+		--dseq "$(DSEQ)" 			   \
+		--from "$(KEY_NAME)"
+
 .PHONY: deployment-update
 deployment-update:
 	$(AKASHCTL) tx deployment update "$(KEY_OPTS)" "$(SDL_PATH)" -y \
@@ -209,3 +215,7 @@ create-server-certificate:
 .PHONY: revoke-certificate
 revoke-certificate:
 	$(AKASHCTL) $(KEY_OPTS) $(CHAIN_OPTS) tx cert revoke --from=$(KEY_NAME) -y
+
+.PHONY: events-run
+events-run:
+	$(AKASHCTL) events
diff --git a/validation/manifest.go b/validation/manifest.go
index 35766244..fcf869a0 100644
--- a/validation/manifest.go
+++ b/validation/manifest.go
@@ -13,6 +13,13 @@ import (
 	dtypes "github.com/ovrclk/akash/x/deployment/types"
 )
 
+var (
+	serviceNameValidationRegex = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)
+	envVarValidatorRegex       = regexp.MustCompile(`^[-._a-zA-Z][-._a-zA-Z0-9]*$`)
+	hostnameRegex              = regexp.MustCompile(`^[[:alnum:],-,\.]+\.[[:alpha:]]{2,}$`)
+	hostnameMaxLen             = 255
+)
+
 // ValidateManifest does validation for manifest
 func ValidateManifest(m manifest.Manifest) error {
 	if len(m) == 0 {
@@ -63,9 +70,6 @@ func validateManifestGroup(group manifest.Group, helper *validateManifestGroupsH
 	return nil
 }
 
-var serviceNameValidationRegex = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)
-var envVarValidatorRegex = regexp.MustCompile(`^[-._a-zA-Z][-._a-zA-Z0-9]*$`)
-
 func validateManifestService(service manifest.Service, helper *validateManifestGroupsHelper) error {
 	if len(service.Name) == 0 {
 		return fmt.Errorf("%w: service name is empty", ErrInvalidManifest)
@@ -140,10 +144,6 @@ func validateServiceExpose(serviceName string, serviceExpose manifest.ServiceExp
 	return nil
 }
 
-var hostnameRegex = regexp.MustCompile(`^[[:alnum:],-,\.]+\.[[:alpha:]]{2,}$`)
-
-const hostnameMaxLen = 255
-
 func isValidHostname(hostname string) bool {
 	return len(hostname) <= hostnameMaxLen && hostnameRegex.MatchString(hostname)
 }
diff --git a/x/deployment/types/group_pricing_validation.go b/x/deployment/types/group_pricing_validation.go
index bfa96d14..934a1e1b 100644
--- a/x/deployment/types/group_pricing_validation.go
+++ b/x/deployment/types/group_pricing_validation.go
@@ -6,8 +6,6 @@ import (
 	sdk "github.com/cosmos/cosmos-sdk/types"
 	"github.com/ovrclk/akash/validation/constants"
 	"github.com/pkg/errors"
-
-	"github.com/ovrclk/akash/types/unit"
 )
 
 func validateGroupPricing(gspec GroupSpec) error {
@@ -43,12 +41,6 @@ func validateGroupPricing(gspec GroupSpec) error {
 		mem = mem.Add(memCount.Mul(sdk.NewIntFromUint64(uint64(resource.Count))))
 	}
 
-	minprice := mem.Mul(sdk.NewInt(validationConfig.MinGroupMemPrice)).Quo(sdk.NewInt(unit.Gi))
-
-	if price.Amount.LT(minprice) {
-		return errors.Errorf("group %v: price too low (%v >= %v fails)", gspec.GetName(), price, minprice)
-	}
-
 	return nil
 }
 
@@ -57,11 +49,11 @@ func validateUnitPricing(rg Resource) error {
 		return errors.Errorf("error: invalid price object")
 	}
 
-	if rg.Price.Amount.GT(sdk.NewIntFromUint64(uint64(validationConfig.MaxUnitPrice))) {
+	if rg.Price.Amount.GT(sdk.NewIntFromUint64(validationConfig.MaxUnitPrice)) {
 		return errors.Errorf("error: invalid unit price (%v > %v fails)", validationConfig.MaxUnitPrice, rg.Price)
 	}
 
-	if rg.Price.Amount.LT(sdk.NewIntFromUint64(uint64(validationConfig.MinUnitPrice))) {
+	if rg.Price.Amount.LT(sdk.NewIntFromUint64(validationConfig.MinUnitPrice)) {
 		return errors.Errorf("error: invalid unit price (%v < %v fails)", validationConfig.MinUnitPrice, rg.Price)
 	}
 	return nil
diff --git a/x/deployment/types/resource_list_validation.go b/x/deployment/types/resource_list_validation.go
index eec88d6c..a87a82d2 100644
--- a/x/deployment/types/resource_list_validation.go
+++ b/x/deployment/types/resource_list_validation.go
@@ -2,6 +2,7 @@ package types
 
 import (
 	"fmt"
+
 	sdk "github.com/cosmos/cosmos-sdk/types"
 	"github.com/ovrclk/akash/types"
 	"github.com/pkg/errors"
@@ -36,17 +37,17 @@ func ValidateResourceList(rlist types.ResourceGroup) error {
 		limits.add(gLimits)
 	}
 
-	if limits.cpu.GT(sdk.NewInt(validationConfig.MaxGroupCPU)) || limits.cpu.LTE(sdk.ZeroInt()) {
+	if limits.cpu.GT(sdk.NewIntFromUint64(validationConfig.MaxGroupCPU)) || limits.cpu.LTE(sdk.ZeroInt()) {
 		return errors.Errorf("group %v: invalid total CPU (%v > %v > %v fails)",
 			rlist.GetName(), validationConfig.MaxGroupCPU, limits.cpu, 0)
 	}
 
-	if limits.memory.GT(sdk.NewInt(validationConfig.MaxGroupMemory)) || limits.memory.LTE(sdk.ZeroInt()) {
+	if limits.memory.GT(sdk.NewIntFromUint64(validationConfig.MaxGroupMemory)) || limits.memory.LTE(sdk.ZeroInt()) {
 		return errors.Errorf("group %v: invalid total memory (%v > %v > %v fails)",
 			rlist.GetName(), validationConfig.MaxGroupMemory, limits.memory, 0)
 	}
 
-	if limits.storage.GT(sdk.NewInt(validationConfig.MaxGroupStorage)) || limits.storage.LTE(sdk.ZeroInt()) {
+	if limits.storage.GT(sdk.NewIntFromUint64(validationConfig.MaxGroupStorage)) || limits.storage.LTE(sdk.ZeroInt()) {
 		return errors.Errorf("group %v: invalid total storage (%v > %v > %v fails)",
 			rlist.GetName(), validationConfig.MaxGroupStorage, limits.storage, 0)
 	}
diff --git a/x/deployment/types/validation_config.go b/x/deployment/types/validation_config.go
index 1de1dc27..3e5baa45 100644
--- a/x/deployment/types/validation_config.go
+++ b/x/deployment/types/validation_config.go
@@ -1,51 +1,64 @@
 package types
 
+import "github.com/ovrclk/akash/types/unit"
+
 // This is the validation configuration that acts as a hard limit
 // on what the network accepts for deployments. This is never changed
 // and is the same across all members of the network
 
-var validationConfig = struct {
-	MaxUnitCPU     uint
-	MaxUnitMemory  uint
-	MaxUnitStorage uint
-	MaxUnitCount   uint
-	MaxUnitPrice   uint
+type ValidationConfig struct {
+
+	// MaxUnitCPU is the maximum number of milli (1/1000) cpu units a unit can consume.
+	MaxUnitCPU uint
+	// MaxUnitMemory is the maximum number of bytes of memory that a unit can consume
+	MaxUnitMemory uint64
+	// MaxUnitStorage is the maximum number of bytes of storage that a unit can consume
+	MaxUnitStorage uint64
+	// MaxUnitCount is the maximum number of replias of a service
+	MaxUnitCount uint
+	// MaxUnitPrice is the maximum price that a unit can have
+	MaxUnitPrice uint64
 
 	MinUnitCPU     uint
-	MinUnitMemory  uint
-	MinUnitStorage uint
+	MinUnitMemory  uint64
+	MinUnitStorage uint64
 	MinUnitCount   uint
-	MinUnitPrice   uint
+	MinUnitPrice   uint64
 
+	// MaxGroupCount is the maximum number of groups allowed per deployment
 	MaxGroupCount int
+	// MaxGroupUnits is the maximum number services per group
 	MaxGroupUnits int
 
-	MaxGroupCPU     int64
-	MaxGroupMemory  int64
-	MaxGroupStorage int64
+	// MaxGroupCPU is the maximum total amount of CPU requested per group
+	MaxGroupCPU uint64
+	// MaxGroupMemory is the maximum total amount of memory requested per group
+	MaxGroupMemory uint64
+	// MaxGroupStorage is the maximum total amount of storage requested per group
+	MaxGroupStorage uint64
+}
 
-	MinGroupMemPrice int64
-	MaxGroupMemPrice int64
-}{
-	MaxUnitCPU:     1000,
-	MaxUnitMemory:  1073741824,
-	MaxUnitStorage: 10 * 1073741824,
-	MaxUnitCount:   10,
-	MaxUnitPrice:   10000,
+var validationConfig = ValidationConfig{
+	MaxUnitCPU:     10 * 1000,     // 10 CPUs
+	MaxUnitMemory:  16 * unit.Gi,  // 16 Gi
+	MaxUnitStorage: 100 * unit.Gi, // 100 Gi
+	MaxUnitCount:   50,
+	MaxUnitPrice:   10000000, // 10akt
 
 	MinUnitCPU:     10,
-	MinUnitMemory:  1024,
-	MinUnitStorage: 1024,
+	MinUnitMemory:  unit.Mi,
+	MinUnitStorage: 5 * unit.Mi,
 	MinUnitCount:   1,
 	MinUnitPrice:   1,
 
-	MaxGroupCount: 10,
-	MaxGroupUnits: 10,
+	MaxGroupCount: 20,
+	MaxGroupUnits: 20,
 
-	MaxGroupCPU:     1000,
-	MaxGroupMemory:  1073741824,
-	MaxGroupStorage: 5368709120,
+	MaxGroupCPU:     20 * 1000,
+	MaxGroupMemory:  32 * unit.Gi,
+	MaxGroupStorage: 256 * unit.Gi,
+}
 
-	MinGroupMemPrice: 50,
-	MaxGroupMemPrice: 1048576,
+func GetValidationConfig() ValidationConfig {
+	return validationConfig
 }


Test patch:
diff --git a/provider/bidengine/order_test.go b/provider/bidengine/order_test.go
index 6b5bc9b2..34643a5d 100644
--- a/provider/bidengine/order_test.go
+++ b/provider/bidengine/order_test.go
@@ -50,13 +50,13 @@ func makeMocks(s *orderTestScaffold) {
 	groupResult.Group.GroupSpec.Resources = make([]dtypes.Resource, 1)
 
 	cpu := atypes.CPU{}
-	cpu.Units = atypes.NewResourceValue(11)
+	cpu.Units = atypes.NewResourceValue(uint64(dtypes.GetValidationConfig().MinUnitCPU))
 
 	memory := atypes.Memory{}
-	memory.Quantity = atypes.NewResourceValue(10000)
+	memory.Quantity = atypes.NewResourceValue(dtypes.GetValidationConfig().MinUnitMemory)
 
 	storage := atypes.Storage{}
-	storage.Quantity = atypes.NewResourceValue(4096)
+	storage.Quantity = atypes.NewResourceValue(dtypes.GetValidationConfig().MinUnitStorage)
 
 	clusterResources := atypes.ResourceUnits{
 		CPU:     &cpu,
@@ -66,7 +66,7 @@ func makeMocks(s *orderTestScaffold) {
 	price := sdk.NewInt64Coin(testutil.CoinDenom, 23)
 	resource := dtypes.Resource{
 		Resources: clusterResources,
-		Count:     10,
+		Count:     2,
 		Price:     price,
 	}
 
diff --git a/testutil/base.go b/testutil/base.go
index 963a9f52..12460451 100644
--- a/testutil/base.go
+++ b/testutil/base.go
@@ -59,6 +59,24 @@ func PlacementRequirements(t testing.TB) types.PlacementRequirements {
 	}
 }
 
+func RandCPUUnits() uint {
+	return RandRangeUint(
+		dtypes.GetValidationConfig().MinUnitCPU,
+		dtypes.GetValidationConfig().MaxUnitCPU)
+}
+
+func RandMemoryQuantity() uint64 {
+	return RandRangeUint64(
+		dtypes.GetValidationConfig().MinUnitMemory,
+		dtypes.GetValidationConfig().MaxUnitMemory)
+}
+
+func RandStorageQuantity() uint64 {
+	return RandRangeUint64(
+		dtypes.GetValidationConfig().MinUnitStorage,
+		dtypes.GetValidationConfig().MaxUnitStorage)
+}
+
 // Resources produces an attribute list for populating a Group's
 // 'Resources' fields.
 func Resources(t testing.TB) []dtypes.Resource {
@@ -71,13 +89,13 @@ func Resources(t testing.TB) []dtypes.Resource {
 		res := dtypes.Resource{
 			Resources: types.ResourceUnits{
 				CPU: &types.CPU{
-					Units: types.NewResourceValue(100),
+					Units: types.NewResourceValue(uint64(dtypes.GetValidationConfig().MinUnitCPU)),
 				},
 				Memory: &types.Memory{
-					Quantity: types.NewResourceValue(1024), // default min value is 1024
+					Quantity: types.NewResourceValue(dtypes.GetValidationConfig().MinUnitMemory),
 				},
 				Storage: &types.Storage{
-					Quantity: types.NewResourceValue(1024), // default min value is 1024
+					Quantity: types.NewResourceValue(dtypes.GetValidationConfig().MinUnitStorage),
 				},
 			},
 			Count: 1,
diff --git a/testutil/types.go b/testutil/types.go
index 9402c747..d246297a 100644
--- a/testutil/types.go
+++ b/testutil/types.go
@@ -25,29 +25,34 @@ import (
 	"github.com/ovrclk/akash/types"
 )
 
-const (
-	defaultMinCPUUnit     = 10
-	defaultMaxCPUUnit     = 500
-	defaultMinMemorySize  = 1024
-	defaultMaxMemorySize  = 1073741824
-	defaultMinStorageSize = 1024
-	defaultMaxStorageSize = 1073741824
-)
-
 func RandRangeInt(min, max int) int {
 	return rand.Intn(max-min) + min // nolint: gosec
 }
 
+func RandRangeUint(min, max uint) uint {
+	val := rand.Uint64() // nolint: gosec
+	val %= uint64(max - min)
+	val += uint64(min)
+	return uint(val)
+}
+
+func RandRangeUint64(min, max uint64) uint64 {
+	val := rand.Uint64() // nolint: gosec
+	val %= max - min
+	val += min
+	return val
+}
+
 func ResourceUnits(_ testing.TB) types.ResourceUnits {
 	return types.ResourceUnits{
 		CPU: &types.CPU{
-			Units: types.NewResourceValue(uint64(RandRangeInt(defaultMinCPUUnit, defaultMaxCPUUnit))),
+			Units: types.NewResourceValue(uint64(RandCPUUnits())),
 		},
 		Memory: &types.Memory{
-			Quantity: types.NewResourceValue(uint64(RandRangeInt(defaultMinMemorySize, defaultMaxMemorySize))),
+			Quantity: types.NewResourceValue(RandMemoryQuantity()),
 		},
 		Storage: &types.Storage{
-			Quantity: types.NewResourceValue(uint64(RandRangeInt(defaultMinStorageSize, defaultMaxStorageSize))),
+			Quantity: types.NewResourceValue(RandStorageQuantity()),
 		},
 	}
 }
diff --git a/validation/manifest_test.go b/validation/manifest_test.go
index eb71ea36..c80a87f0 100644
--- a/validation/manifest_test.go
+++ b/validation/manifest_test.go
@@ -2,23 +2,25 @@ package validation_test
 
 import (
 	"bytes"
+	"testing"
+
 	sdk "github.com/cosmos/cosmos-sdk/types"
 	"github.com/stretchr/testify/require"
-	"testing"
 
 	"github.com/stretchr/testify/assert"
 
 	"github.com/ovrclk/akash/manifest"
+	"github.com/ovrclk/akash/testutil"
 	akashtypes "github.com/ovrclk/akash/types"
 	"github.com/ovrclk/akash/validation"
 	dtypes "github.com/ovrclk/akash/x/deployment/types"
 )
 
-const (
-	randCPU1    uint64 = 10
-	randCPU2    uint64 = 5
-	randMemory  uint64 = 20
-	randStorage uint64 = 5
+var (
+	randCPU1    = uint64(testutil.RandCPUUnits())
+	randCPU2    = randCPU1 + 1
+	randMemory  = testutil.RandMemoryQuantity()
+	randStorage = testutil.RandStorageQuantity()
 )
 
 var randUnits1 = akashtypes.ResourceUnits{
@@ -249,19 +251,19 @@ func simpleResourceUnits() akashtypes.ResourceUnits {
 	return akashtypes.ResourceUnits{
 		CPU: &akashtypes.CPU{
 			Units: akashtypes.ResourceValue{
-				Val: sdk.NewInt(10),
+				Val: sdk.NewIntFromUint64(randCPU1),
 			},
 			Attributes: nil,
 		},
 		Memory: &akashtypes.Memory{
 			Quantity: akashtypes.ResourceValue{
-				Val: sdk.NewInt(1024),
+				Val: sdk.NewIntFromUint64(randMemory),
 			},
 			Attributes: nil,
 		},
 		Storage: &akashtypes.Storage{
 			Quantity: akashtypes.ResourceValue{
-				Val: sdk.NewInt(1025),
+				Val: sdk.NewIntFromUint64(randStorage),
 			},
 			Attributes: nil,
 		},
diff --git a/x/deployment/types/deployment_validation_test.go b/x/deployment/types/deployment_validation_test.go
index 8dcde84a..15b316ae 100644
--- a/x/deployment/types/deployment_validation_test.go
+++ b/x/deployment/types/deployment_validation_test.go
@@ -63,13 +63,13 @@ func validSimpleGroupSpec() types.GroupSpec {
 			},
 			Memory: &akashtypes.Memory{
 				Quantity: akashtypes.ResourceValue{
-					Val: sdk.NewInt(1024),
+					Val: sdk.NewIntFromUint64(types.GetValidationConfig().MinUnitMemory),
 				},
 				Attributes: nil,
 			},
 			Storage: &akashtypes.Storage{
 				Quantity: akashtypes.ResourceValue{
-					Val: sdk.NewInt(1025),
+					Val: sdk.NewIntFromUint64(types.GetValidationConfig().MinUnitStorage),
 				},
 				Attributes: nil,
 			},