Skip to content

Commit

Permalink
Merge pull request #93 from Chia-Network/get_harvesters
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmarslender authored Aug 21, 2023
2 parents 6e25810 + 8e649e5 commit 4062eee
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 19 deletions.
21 changes: 21 additions & 0 deletions pkg/protocols/harvester.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package protocols

import (
"github.com/samber/mo"

"github.com/chia-network/go-chia-libs/pkg/types"
)

// Plot is the plot definition in the harvester protocol
// https://github.com/Chia-Network/chia-blockchain/blob/main/chia/protocols/harvester_protocol.py#L78
type Plot struct {
Filename string `json:"filename"`
Size uint8 `json:"size"`
PlotID types.Bytes32 `json:"plot_id"`
PoolPublicKey mo.Option[types.G1Element] `json:"pool_public_key"`
PoolContractPuzzleHash mo.Option[types.Bytes32] `json:"pool_contract_puzzle_hash"`
PlotPublicKey types.G1Element `json:"plot_public_key"`
FileSize uint64 `json:"file_size"`
TimeModified types.Timestamp `json:"time_modified"`
CompressionLevel mo.Option[uint8] `json:"compression_level"`
}
51 changes: 51 additions & 0 deletions pkg/rpc/farmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package rpc
import (
"net/http"

"github.com/samber/mo"

"github.com/chia-network/go-chia-libs/pkg/protocols"
"github.com/chia-network/go-chia-libs/pkg/rpcinterface"
"github.com/chia-network/go-chia-libs/pkg/types"
)

// FarmerService encapsulates farmer RPC methods
Expand Down Expand Up @@ -36,3 +40,50 @@ func (s *FarmerService) GetConnections(opts *GetConnectionsOptions) (*GetConnect

return c, resp, nil
}

// FarmerGetHarvestersOptions optoins for get_harvesters endpoint. Currently, accepts no options
type FarmerGetHarvestersOptions struct{}

// FarmerHarvester is a single harvester record returned by the farmer's get_harvesters endpoint
type FarmerHarvester struct {
Connection struct {
NodeID types.Bytes32 `json:"node_id"`
Host string `json:"host"`
Port uint16 `json:"port"`
} `json:"connection"`
Plots []protocols.Plot `json:"plots"`
FailedToOpenFilenames []string `json:"failed_to_open_filenames"`
NoKeyFilenames []string `json:"no_key_filenames"`
Duplicates []string `json:"duplicates"`
TotalPlotSize int `json:"total_plot_size"`
TotalEffectivePlotSize int `json:"total_effective_plot_size"`
Syncing mo.Option[struct {
Initial bool `json:"initial"`
PlotFilesProcessed uint32 `json:"plot_files_processed"`
PlotFilesTotal uint32 `json:"plot_files_total"`
}] `json:"syncing"`
LastSyncTime types.Timestamp `json:"last_sync_time"`
HarvestingMode mo.Option[types.HarvestingMode] `json:"harvesting_mode"`
}

// FarmerGetHarvestersResponse get_harvesters response format
type FarmerGetHarvestersResponse struct {
Response
Harvesters []FarmerHarvester `json:"harvesters"`
}

// GetHarvesters returns all harvester details for the farmer
func (s *FarmerService) GetHarvesters(opts *FarmerGetHarvestersOptions) (*FarmerGetHarvestersResponse, *http.Response, error) {
request, err := s.NewRequest("get_harvesters", opts)
if err != nil {
return nil, nil, err
}

c := &FarmerGetHarvestersResponse{}
resp, err := s.Do(request, c)
if err != nil {
return nil, resp, err
}

return c, resp, nil
}
4 changes: 2 additions & 2 deletions pkg/rpc/harvester.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/samber/mo"

"github.com/chia-network/go-chia-libs/pkg/protocols"
"github.com/chia-network/go-chia-libs/pkg/rpcinterface"
"github.com/chia-network/go-chia-libs/pkg/types"
)

// HarvesterService encapsulates harvester RPC methods
Expand Down Expand Up @@ -43,7 +43,7 @@ func (s *HarvesterService) GetConnections(opts *GetConnectionsOptions) (*GetConn
// HarvesterGetPlotsResponse get_plots response format
type HarvesterGetPlotsResponse struct {
Response
Plots mo.Option[[]types.PlotInfo] `json:"plots"`
Plots mo.Option[[]protocols.Plot] `json:"plots"`
FailedToOpenFilenames mo.Option[[]string] `json:"failed_to_open_filenames"`
NotFoundFilenames mo.Option[[]string] `json:"not_found_filenames"`
}
Expand Down
27 changes: 10 additions & 17 deletions pkg/types/harvester.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package types

import (
"github.com/samber/mo"
)

// EventHarvesterFarmingInfo is the event data for `farming_info` from the harvester
// https://github.com/Chia-Network/chia-blockchain/blob/main/chia/harvester/harvester_api.py#L232
type EventHarvesterFarmingInfo struct {
Expand All @@ -14,16 +10,13 @@ type EventHarvesterFarmingInfo struct {
Time float64 `json:"time"`
}

// PlotInfo contains information about a plot, as used in get_plots rpc
// There is also a PlotInfo type in chia, that is NOT used in the RPC, that has the first 5 fields as defined here
// https://github.com/Chia-Network/chia-blockchain/blob/main/chia/harvester/harvester.py#L139
type PlotInfo struct {
PoolPublicKey mo.Option[G1Element] `json:"pool_public_key"`
PoolContractPuzzleHash mo.Option[Bytes32] `json:"pool_contract_puzzle_hash"`
PlotPublicKey G1Element `json:"plot_public_key"`
FileSize uint64 `json:"file_size"`
TimeModified Timestamp `json:"time_modified"`
Filename string `json:"filename"`
PlotID Bytes32 `json:"plot_id"`
Size uint8 `json:"size"` // https://github.com/Chia-Network/chiapos/blob/main/src/prover_disk.hpp#L181
}
// HarvestingMode is the mode the harvester is using to harvest CPU or GPU
type HarvestingMode int

const (
// HarvestingModeCPU Using CPU to harvest
HarvestingModeCPU = HarvestingMode(1)

// HarvestingModeGPU Using CPU to harvest
HarvestingModeGPU = HarvestingMode(2)
)

0 comments on commit 4062eee

Please sign in to comment.