Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(market): check boundaries for resource offer #94

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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
}

Check warning on line 16 in go/node/market/v1beta4/bid.go

View check run for this annotation

Codecov / codecov/patch

go/node/market/v1beta4/bid.go#L13-L16

Added lines #L13 - L16 were not covered by tests

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

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

Check warning on line 22 in go/node/market/v1beta4/bid.go

View check run for this annotation

Codecov / codecov/patch

go/node/market/v1beta4/bid.go#L18-L22

Added lines #L18 - L22 were not covered by tests

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

Check warning on line 28 in go/node/market/v1beta4/bid.go

View check run for this annotation

Codecov / codecov/patch

go/node/market/v1beta4/bid.go#L24-L28

Added lines #L24 - L28 were not covered by tests

ru[ro.Resources.ID] = nil

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

Check warning on line 34 in go/node/market/v1beta4/bid.go

View check run for this annotation

Codecov / codecov/patch

go/node/market/v1beta4/bid.go#L30-L34

Added lines #L30 - L34 were not covered by tests

// TODO @troian check resources boundaries
}

return true

Check warning on line 39 in go/node/market/v1beta4/bid.go

View check run for this annotation

Codecov / codecov/patch

go/node/market/v1beta4/bid.go#L39

Added line #L39 was not covered by tests
}

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

func ResourceOfferFromRU(ru v1beta3.ResourceUnits) ResourcesOffer {
func ResourceOfferFromRU(ru dtypes.ResourceUnits) ResourcesOffer {

Check warning on line 71 in go/node/market/v1beta4/bid.go

View check run for this annotation

Codecov / codecov/patch

go/node/market/v1beta4/bid.go#L71

Added line #L71 was not covered by tests
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 @@

return res
}

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

Check warning on line 140 in go/node/types/v1beta3/resources.go

View check run for this annotation

Codecov / codecov/patch

go/node/types/v1beta3/resources.go#L135-L140

Added lines #L135 - L140 were not covered by tests

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

Check warning on line 144 in go/node/types/v1beta3/resources.go

View check run for this annotation

Codecov / codecov/patch

go/node/types/v1beta3/resources.go#L142-L144

Added lines #L142 - L144 were not covered by tests

return true

Check warning on line 146 in go/node/types/v1beta3/resources.go

View check run for this annotation

Codecov / codecov/patch

go/node/types/v1beta3/resources.go#L146

Added line #L146 was not covered by tests
}

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

Check warning on line 154 in go/node/types/v1beta3/resources.go

View check run for this annotation

Codecov / codecov/patch

go/node/types/v1beta3/resources.go#L149-L154

Added lines #L149 - L154 were not covered by tests

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

Check warning on line 158 in go/node/types/v1beta3/resources.go

View check run for this annotation

Codecov / codecov/patch

go/node/types/v1beta3/resources.go#L156-L158

Added lines #L156 - L158 were not covered by tests

return true

Check warning on line 160 in go/node/types/v1beta3/resources.go

View check run for this annotation

Codecov / codecov/patch

go/node/types/v1beta3/resources.go#L160

Added line #L160 was not covered by tests
}

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

Check warning on line 168 in go/node/types/v1beta3/resources.go

View check run for this annotation

Codecov / codecov/patch

go/node/types/v1beta3/resources.go#L163-L168

Added lines #L163 - L168 were not covered by tests

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

Check warning on line 172 in go/node/types/v1beta3/resources.go

View check run for this annotation

Codecov / codecov/patch

go/node/types/v1beta3/resources.go#L170-L172

Added lines #L170 - L172 were not covered by tests

return true

Check warning on line 174 in go/node/types/v1beta3/resources.go

View check run for this annotation

Codecov / codecov/patch

go/node/types/v1beta3/resources.go#L174

Added line #L174 was not covered by tests
}

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

Check warning on line 180 in go/node/types/v1beta3/resources.go

View check run for this annotation

Codecov / codecov/patch

go/node/types/v1beta3/resources.go#L177-L180

Added lines #L177 - L180 were not covered by tests

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

Check warning on line 185 in go/node/types/v1beta3/resources.go

View check run for this annotation

Codecov / codecov/patch

go/node/types/v1beta3/resources.go#L182-L185

Added lines #L182 - L185 were not covered by tests

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

Check warning on line 189 in go/node/types/v1beta3/resources.go

View check run for this annotation

Codecov / codecov/patch

go/node/types/v1beta3/resources.go#L187-L189

Added lines #L187 - L189 were not covered by tests

}

return true

Check warning on line 193 in go/node/types/v1beta3/resources.go

View check run for this annotation

Codecov / codecov/patch

go/node/types/v1beta3/resources.go#L193

Added line #L193 was not covered by tests
}