-
Notifications
You must be signed in to change notification settings - Fork 8
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(): add farmer protocol #120
Draft
n33pm
wants to merge
2
commits into
Chia-Network:main
Choose a base branch
from
xchiaeu:farmer-protocol
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package peerprotocol | ||
|
||
import ( | ||
"github.com/chia-network/go-chia-libs/pkg/protocols" | ||
) | ||
|
||
// FarmerProtocol is for interfacing with full nodes via the peer protocol | ||
type FarmerProtocol struct { | ||
*Connection | ||
} | ||
|
||
// NewFarmerProtocol returns a new instance of the full node protocol | ||
func NewFarmerProtocol(connection *Connection) (*FarmerProtocol, error) { | ||
return &FarmerProtocol{connection}, nil | ||
} | ||
|
||
// Handshake performs the handshake with the peer | ||
func (c *FarmerProtocol) Handshake() error { | ||
return c.handshake(protocols.NodeTypeFarmer) | ||
} | ||
|
||
// DeclareProofOfSpace sends a DeclareProofOfSpace message to the peer | ||
func (c *FarmerProtocol) DeclareProofOfSpace(data *protocols.DeclareProofOfSpace) error { | ||
return c.Do(protocols.ProtocolMessageTypeDeclareProofOfSpace, data) | ||
} | ||
|
||
func (c *FarmerProtocol) SignedValues(data *protocols.SignedValues) error { | ||
return c.Do(protocols.ProtocolMessageTypeSignedValues, data) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package peerprotocol | ||
|
||
import ( | ||
"errors" | ||
"github.com/chia-network/go-chia-libs/pkg/protocols" | ||
"time" | ||
) | ||
|
||
// ErrInvalidNodeType is returned when the node type is invalid | ||
var ErrInvalidNodeType = errors.New("invalid node type") | ||
|
||
type IHarvesterProtocol interface { | ||
Handshake(nodeType protocols.NodeType) error | ||
HarvesterHandshake(data *protocols.HarvesterHandshake) error | ||
NewSignagePointHarvester(data *protocols.NewSignagePointHarvester) error | ||
RequestSignatures(data *protocols.RequestSignatures) error | ||
ReadOne(timeout time.Duration) (*protocols.Message, error) | ||
} | ||
|
||
// HarvesterProtocol is for interfacing with full nodes via the peer protocol | ||
type HarvesterProtocol struct { | ||
conn *Connection | ||
} | ||
|
||
// NewHarvesterProtocol returns a new instance of the full node protocol | ||
func NewHarvesterProtocol(connection *Connection) (IHarvesterProtocol, error) { | ||
return &HarvesterProtocol{connection}, nil | ||
} | ||
|
||
// Handshake performs the handshake with the peer | ||
func (c *HarvesterProtocol) Handshake(nodeType protocols.NodeType) error { | ||
if nodeType != protocols.NodeTypeHarvester && nodeType != protocols.NodeTypeFarmer { | ||
return ErrInvalidNodeType | ||
} | ||
return c.conn.handshake(nodeType) | ||
} | ||
|
||
// HarvesterHandshake performs the handshake with the peer | ||
func (c *HarvesterProtocol) HarvesterHandshake(data *protocols.HarvesterHandshake) error { | ||
return c.conn.Do(protocols.ProtocolMessageTypeHarvesterHandshake, data) | ||
} | ||
|
||
// NewSignagePointHarvester sends a new signage point to the harvester | ||
func (c *HarvesterProtocol) NewSignagePointHarvester(data *protocols.NewSignagePointHarvester) error { | ||
return c.conn.Do(protocols.ProtocolMessageTypeNewSignagePointHarvester, data) | ||
} | ||
|
||
// RequestSignatures sends a request for signatures to the harvester | ||
func (c *HarvesterProtocol) RequestSignatures(data *protocols.RequestSignatures) error { | ||
return c.conn.Do(protocols.ProtocolMessageTypeRequestSignatures, data) | ||
} | ||
|
||
// ReadOne reads a single message from the connection | ||
func (c *HarvesterProtocol) ReadOne(timeout time.Duration) (*protocols.Message, error) { | ||
return c.conn.ReadOne(timeout) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package protocols | ||
|
||
import ( | ||
"github.com/chia-network/go-chia-libs/pkg/types" | ||
"github.com/samber/mo" | ||
) | ||
|
||
// SPSubSlotSourceData is the format for the sp_sub_slot_source_data response | ||
// https://github.com/Chia-Network/chia-blockchain/blob/main/chia/protocols/farmer_protocol.py#L26 | ||
type SPSubSlotSourceData struct { | ||
CCSubSlot types.ChallengeChainSubSlot `streamable:""` | ||
RCSubSlot types.RewardChainSubSlot `streamable:""` | ||
} | ||
|
||
// SPVDFSourceData is the format for the sp_vdf_source_data response | ||
// https://github.com/Chia-Network/chia-blockchain/blob/main/chia/protocols/farmer_protocol.py#L33 | ||
type SPVDFSourceData struct { | ||
CCVDF types.ClassgroupElement `streamable:""` | ||
RCVDF types.ClassgroupElement `streamable:""` | ||
} | ||
|
||
// NewSignagePoint is the format for the new_signage_point response | ||
// https://github.com/Chia-Network/chia-blockchain/blob/main/chia/protocols/farmer_protocol.py#L47 | ||
type NewSignagePoint struct { | ||
ChallengeHash types.Bytes32 `streamable:""` | ||
ChallengeChainSP types.Bytes32 `streamable:""` | ||
RewardChainSP types.Bytes32 `streamable:""` | ||
Difficulty uint64 `streamable:""` | ||
SubSlotIters uint64 `streamable:""` | ||
SignagePointIndex uint8 `streamable:""` | ||
PeakHeight uint32 `streamable:""` | ||
SPSourceData mo.Option[SignagePointSourceData] `streamable:""` | ||
} | ||
|
||
// SignagePointSourceData is the format for the signage_point_source_data response | ||
// https://github.com/Chia-Network/chia-blockchain/blob/main/chia/protocols/farmer_protocol.py#L40 | ||
type SignagePointSourceData struct { | ||
SubSlotData mo.Option[SPSubSlotSourceData] `streamable:""` | ||
VDFData mo.Option[SPVDFSourceData] `streamable:""` | ||
} | ||
|
||
// DeclareProofOfSpace matches to the farmer protocol type | ||
// https://github.com/Chia-Network/chia-blockchain/blob/main/chia/protocols/farmer_protocol.py#L60 | ||
type DeclareProofOfSpace struct { | ||
ChallengeHash types.Bytes32 `json:"challenge_hash" streamable:""` | ||
ChallengeChainSP types.Bytes32 `json:"challenge_chain_sp" streamable:""` | ||
SignagePointIndex uint8 `json:"signage_point_index" streamable:""` | ||
RewardChainSP types.Bytes32 `json:"reward_chain_sp" streamable:""` | ||
ProofOfSpace types.ProofOfSpace `json:"proof_of_space" streamable:""` | ||
ChallengeChainSPSignature types.G2Element `json:"challenge_chain_sp_signature" streamable:""` | ||
RewardChainSPSignature types.G2Element `json:"reward_chain_sp_signature" streamable:""` | ||
FarmerPuzzleHash types.Bytes32 `json:"farmer_puzzle_hash" streamable:""` | ||
PoolTarget mo.Option[types.PoolTarget] `json:"pool_target,omitempty" streamable:""` | ||
PoolSignature mo.Option[types.G2Element] `json:"pool_signature,omitempty" streamable:""` | ||
IncludeSignatureSourceData bool `json:"include_signature_source_data" streamable:""` | ||
} | ||
|
||
// RequestSignedValues is the format for the request_signed_values response | ||
// https://github.com/Chia-Network/chia-blockchain/blob/main/chia/protocols/farmer_protocol.py#L76 | ||
type RequestSignedValues struct { | ||
QualityString types.Bytes32 `streamable:""` | ||
FoliageBlockDataHash types.Bytes32 `streamable:""` | ||
FoliageTransactionBlockHash types.Bytes32 `streamable:""` | ||
FoliageBlockData mo.Option[types.FoliageBlockData] `streamable:""` | ||
FoliageTransactionBlockData mo.Option[types.FoliageTransactionBlock] `streamable:""` | ||
RCBlockUnfinished mo.Option[types.RewardChainBlockUnfinished] `streamable:""` | ||
} | ||
|
||
// FarmingInfo is the format for the farming_info response | ||
// https://github.com/Chia-Network/chia-blockchain/blob/main/chia/protocols/farmer_protocol.py#L87 | ||
type FarmingInfo struct { | ||
ChallengeHash types.Bytes32 `streamable:""` | ||
SPHash types.Bytes32 `streamable:""` | ||
Timestamp uint64 `streamable:""` | ||
Passed uint32 `streamable:""` | ||
Proofs uint32 `streamable:""` | ||
TotalPlots uint32 `streamable:""` | ||
LookupTime uint64 `streamable:""` | ||
} | ||
|
||
// SignedValues is the format for the signed_values response | ||
// https://github.com/Chia-Network/chia-blockchain/blob/main/chia/protocols/farmer_protocol.py#L99 | ||
type SignedValues struct { | ||
QualityString types.Bytes32 `streamable:""` | ||
FoliageBlockDataSignature types.G2Element `streamable:""` | ||
FoliageTransactionBlockSignature types.G2Element `streamable:""` | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious when the case is we already have a websocket connection vs an IP to connect to?
Is there a reason we can't just use the
peerPort
for this? I don't really see a difference between serverPort and peerPort (and they default to the same config value unless overridden with config option)