Skip to content

Commit

Permalink
CNS-362: re-apply all the changes in the original CNS-362 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-lava committed May 8, 2023
1 parent 5640d23 commit 9b9c686
Show file tree
Hide file tree
Showing 16 changed files with 954 additions and 158 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ issues:

linters-settings:
dogsled:
max-blank-identifiers: 3
max-blank-identifiers: 5
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
Expand Down
3 changes: 2 additions & 1 deletion x/conflict/keeper/msg_server_detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ func setupForConflictTests(t *testing.T, numOfProviders int) testStruct {
// init keepers state
var balance int64 = 100000

// setup consumer
ts.consumer = common.CreateNewAccount(ts.ctx, *ts.keepers, balance)

// setup consumer
// setup providers
for i := 0; i < numOfProviders; i++ {
ts.Providers = append(ts.Providers, common.CreateNewAccount(ts.ctx, *ts.keepers, balance))
}
Expand Down
21 changes: 16 additions & 5 deletions x/pairing/keeper/pairing.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,24 @@ func (k Keeper) getProjectStrictestPolicy(ctx sdk.Context, project projectstypes
}

planPolicy := plan.GetPlanPolicy()
policies := []*projectstypes.Policy{project.AdminPolicy, project.SubscriptionPolicy, &planPolicy}
policies := []*projectstypes.Policy{&planPolicy}
if project.SubscriptionPolicy != nil {
policies = append(policies, project.SubscriptionPolicy)
}
if project.AdminPolicy != nil {
policies = append(policies, project.AdminPolicy)
}

if !projectstypes.CheckChainIdExistsInPolicies(chainID, policies) {
return 0, 0, "", 0, fmt.Errorf("chain ID not found in any of the policies")
}

geolocation := k.CalculateEffectiveGeolocationFromPolicies(policies)

providersToPair := k.CalculateEffectiveProvidersToPairFromPolicies(policies)
if providersToPair == uint64(math.MaxUint64) {
return 0, 0, "", 0, fmt.Errorf("could not calculate providersToPair value: all policies are nil")
}

sub, found := k.subscriptionKeeper.GetSubscription(ctx, project.GetSubscription())
if !found {
Expand All @@ -194,15 +204,16 @@ func (k Keeper) CalculateEffectiveGeolocationFromPolicies(policies []*projectsty
}

func (k Keeper) CalculateEffectiveProvidersToPairFromPolicies(policies []*projectstypes.Policy) uint64 {
var providersToPairValues []uint64
providersToPair := uint64(math.MaxUint64)

for _, policy := range policies {
if policy != nil {
providersToPairValues = append(providersToPairValues, policy.GetMaxProvidersToPair())
val := policy.GetMaxProvidersToPair()
if policy != nil && val < providersToPair {
providersToPair = val
}
}

return commontypes.FindMin(providersToPairValues)
return providersToPair
}

func (k Keeper) CalculateEffectiveAllowedCuPerEpochFromPolicies(policies []*projectstypes.Policy, cuUsedInProject uint64, cuLeftInSubscription uint64) uint64 {
Expand Down
Loading

0 comments on commit 9b9c686

Please sign in to comment.