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

add farm_free_ips field to node response #1201

Merged
merged 1 commit into from
Sep 23, 2024
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
10 changes: 6 additions & 4 deletions grid-proxy/internal/explorer/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ func nodeFromDBNode(info db.Node) types.Node {
Upload: info.UploadSpeed,
Download: info.DownloadSpeed,
},
GPUs: info.Gpus,
PriceUsd: math.Round(info.PriceUsd*1000) / 1000,
GPUs: info.Gpus,
PriceUsd: math.Round(info.PriceUsd*1000) / 1000,
FarmFreeIps: info.FarmFreeIps,
}
node.Status = nodestatus.DecideNodeStatus(node.Power, node.UpdatedAt)
node.Dedicated = info.FarmDedicated || info.NodeContractsCount == 0 || info.Renter != 0 || info.ExtraFee > 0
Expand Down Expand Up @@ -159,8 +160,9 @@ func nodeWithNestedCapacityFromDBNode(info db.Node) types.NodeWithNestedCapacity
Upload: info.UploadSpeed,
Download: info.DownloadSpeed,
},
GPUs: info.Gpus,
PriceUsd: math.Round(info.PriceUsd*1000) / 1000,
GPUs: info.Gpus,
PriceUsd: math.Round(info.PriceUsd*1000) / 1000,
FarmFreeIps: info.FarmFreeIps,
}
node.Status = nodestatus.DecideNodeStatus(node.Power, node.UpdatedAt)
node.Dedicated = info.FarmDedicated || info.NodeContractsCount == 0 || info.Renter != 0 || info.ExtraFee > 0
Expand Down
1 change: 1 addition & 0 deletions grid-proxy/internal/explorer/db/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ func (d *PostgresDatabase) nodeTableQuery(ctx context.Context, filter types.Node
"resources_cache.processor",
"resources_cache.upload_speed",
"resources_cache.download_speed",
"public_ips_cache.free_ips as farm_free_ips",
calculatedDiscountColumn,
).
Joins(`
Expand Down
1 change: 1 addition & 0 deletions grid-proxy/internal/explorer/db/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type Node struct {
UploadSpeed float64
DownloadSpeed float64
PriceUsd float64
FarmFreeIps uint
}

// NodePower struct is the farmerbot report for node status
Expand Down
2 changes: 2 additions & 0 deletions grid-proxy/pkg/types/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Node struct {
Speed Speed `json:"speed"`
GPUs []NodeGPU `json:"gpus"`
PriceUsd float64 `json:"price_usd" sort:"price_usd"`
FarmFreeIps uint `json:"farm_free_ips"`
_ string `sort:"free_cru"`
}

Expand Down Expand Up @@ -94,6 +95,7 @@ type NodeWithNestedCapacity struct {
Speed Speed `json:"speed"`
GPUs []NodeGPU `json:"gpus"`
PriceUsd float64 `json:"price_usd"`
FarmFreeIps uint `json:"farm_free_ips"`
}

// PublicConfig node public config
Expand Down
6 changes: 4 additions & 2 deletions grid-proxy/tests/queries/mock_client/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ func (g *GridProxyMockClient) Nodes(ctx context.Context, filter types.NodeFilter
Upload: g.data.Speeds[uint32(node.TwinID)].Upload,
Download: g.data.Speeds[uint32(node.TwinID)].Download,
},
PriceUsd: calcDiscount(calcNodePrice(g.data, node), limit.Balance),
PriceUsd: calcDiscount(calcNodePrice(g.data, node), limit.Balance),
FarmFreeIps: uint(g.data.FreeIPs[node.FarmID]),
})
}
}
Expand Down Expand Up @@ -282,7 +283,8 @@ func (g *GridProxyMockClient) Node(ctx context.Context, nodeID uint32) (res type
Upload: g.data.Speeds[uint32(node.TwinID)].Upload,
Download: g.data.Speeds[uint32(node.TwinID)].Download,
},
PriceUsd: calcNodePrice(g.data, node),
PriceUsd: calcNodePrice(g.data, node),
FarmFreeIps: uint(g.data.FreeIPs[node.FarmID]),
}
return
}
Expand Down
Loading