Skip to content

Commit

Permalink
feat(market): check boundaries for resource offer (#94)
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian authored Nov 16, 2023
1 parent ec2d8fa commit dc61fbe
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
33 changes: 31 additions & 2 deletions go/node/market/v1beta4/bid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,42 @@ package v1beta4
import (
"sort"

"github.com/akash-network/akash-api/go/node/deployment/v1beta3"
dtypes "github.com/akash-network/akash-api/go/node/deployment/v1beta3"
)

type ResourcesOffer []ResourceOffer

var _ sort.Interface = (*ResourcesOffer)(nil)

func (s ResourcesOffer) MatchGSpec(gspec dtypes.GroupSpec) bool {
if len(s) == 0 {
return true
}

ru := make(map[uint32]*dtypes.ResourceUnit)

for _, res := range gspec.Resources {
ru[res.ID] = &res
}

for _, ro := range s {
res, exists := ru[ro.Resources.ID]
if !exists {
return false
}

ru[ro.Resources.ID] = nil

if res.Count != ro.Count {
return false
}

// TODO @troian check resources boundaries
}

return true
}

func (r *ResourceOffer) Dup() ResourceOffer {
return ResourceOffer{
Resources: r.Resources.Dup(),
Expand Down Expand Up @@ -39,7 +68,7 @@ func (s ResourcesOffer) Dup() ResourcesOffer {
return s
}

func ResourceOfferFromRU(ru v1beta3.ResourceUnits) ResourcesOffer {
func ResourceOfferFromRU(ru dtypes.ResourceUnits) ResourcesOffer {
res := make(ResourcesOffer, 0, len(ru))

for _, r := range ru {
Expand Down
61 changes: 61 additions & 0 deletions go/node/types/v1beta3/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,64 @@ func (m Volumes) Dup() Volumes {

return res
}

func (this *CPU) EqualUnits(that *CPU) bool {
if that == nil {
return this == nil
} else if this == nil {
return false
}

if !this.Units.Equal(&that.Units) {
return false
}

return true
}

func (this *GPU) EqualUnits(that *GPU) bool {
if that == nil {
return this == nil
} else if this == nil {
return false
}

if !this.Units.Equal(&that.Units) {
return false
}

return true
}

func (this *Memory) EqualUnits(that *Memory) bool {
if that == nil {
return this == nil
} else if this == nil {
return false
}

if !this.Quantity.Equal(&that.Quantity) {
return false
}

return true
}

func (this Volumes) EqualUnits(that Volumes) bool {
if len(this) != len(that) {
return false
}

for idx, vol := range this {
if vol.Name != that[idx].Name {
return false
}

if !vol.Quantity.Equal(&that[idx].Quantity) {
return false
}

}

return true
}

0 comments on commit dc61fbe

Please sign in to comment.