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

prio nodes farmerbot #988

Merged
merged 11 commits into from
May 19, 2024
Prev Previous commit
Next Next commit
merge with development
  • Loading branch information
rawdaGastan committed May 7, 2024
commit 951b5e8eb6be3c0157d6e7013a83ac2aa5302681
7 changes: 6 additions & 1 deletion farmerbot/internal/farmerbot_test.go
Original file line number Diff line number Diff line change
@@ -33,7 +33,12 @@ func TestFarmerbot(t *testing.T) {
FarmID: 1,
IncludedNodes: []uint32{1, 2},
PriorityNodes: []uint32{2},
xmonader marked this conversation as resolved.
Show resolved Hide resolved
Power: power{WakeUpThreshold: 50},
Power: power{WakeUpThresholdPercentages: ThresholdPercentages{
CRU: 50,
SRU: 50,
MRU: 50,
HRU: 50,
}},
}

farmerbot, err := NewFarmerBot(ctx, inputs, "dev", aliceSeed, peer.KeyTypeSr25519)
44 changes: 34 additions & 10 deletions farmerbot/internal/power.go
Original file line number Diff line number Diff line change
@@ -171,18 +171,42 @@ func calculateResourceUsage(nodes map[uint32]node) (capacity, capacity) {
return usedResources, totalResources
}

func (f *FarmerBot) resourceUsageTooHigh(sub Substrate) error {
nodesKeys := make([]uint32, 0, len(f.nodes))
for k := range f.nodes {
nodesKeys = append(nodesKeys, k)
}
// TODO: add prio
func (f *FarmerBot) selectNodesToPowerOn(demand capacity) ([]node, error) {
var selectedNodes []node
remainingDemand := demand

for _, node := range f.nodes {
if node.powerState != off {
continue // Skip nodes that are already on or waking up
}

// Check if this node can contribute to the remaining demand
contribute := false
if remainingDemand.cru > 0 && uint64(node.Resources.CRU) >= remainingDemand.cru {
contribute = true
remainingDemand.cru -= uint64(node.Resources.CRU)
}
if remainingDemand.sru > 0 && uint64(node.Resources.SRU) >= remainingDemand.sru {
contribute = true
remainingDemand.sru -= uint64(node.Resources.SRU)
}
if remainingDemand.mru > 0 && uint64(node.Resources.MRU) >= remainingDemand.mru {
contribute = true
remainingDemand.mru -= uint64(node.Resources.MRU)
}
if remainingDemand.hru > 0 && uint64(node.Resources.HRU) >= remainingDemand.hru {
contribute = true
remainingDemand.hru -= uint64(node.Resources.HRU)
}

for i := 0; i < len(f.nodes); i++ {
nodeID := nodesKeys[i]
node := f.nodes[nodeID]
if contribute {
selectedNodes = append(selectedNodes, node)
}

if node.powerState == off {
return f.powerOn(sub, nodeID)
// Check if all demands have been met
if remainingDemand.cru <= 0 && remainingDemand.sru <= 0 && remainingDemand.mru <= 0 && remainingDemand.hru <= 0 {
break // All demands have been met, no need to check more nodes
}
}

Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.