Skip to content

Commit

Permalink
introduce protocol types for WalletProtocol
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Dec 15, 2022
1 parent 9051216 commit 019d453
Show file tree
Hide file tree
Showing 23 changed files with 2,772 additions and 26 deletions.
165 changes: 165 additions & 0 deletions chia-protocol/src/chia_protocol.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
use chia_streamable_macro::Streamable;

use crate::chia_error;
use crate::message_struct;
use crate::streamable_struct;
use crate::Bytes;
use crate::Streamable;

#[cfg(feature = "py-bindings")]
use crate::from_json_dict::FromJsonDict;
#[cfg(feature = "py-bindings")]
use crate::to_json_dict::ToJsonDict;
#[cfg(feature = "py-bindings")]
use chia_py_streamable_macro::PyStreamable;
#[cfg(feature = "py-bindings")]
use pyo3::prelude::*;

#[repr(u8)]
pub enum ProtocolMessageTypes {
// Shared protocol (all services)
Handshake = 1,

// Harvester protocol (harvester <-> farmer)
HarvesterHandshake = 3,
// NewSignagePointHarvester = 4 Changed to 66 in new protocol
NewProofOfSpace = 5,
RequestSignatures = 6,
RespondSignatures = 7,

// Farmer protocol (farmer <-> fullNode)
NewSignagePoint = 8,
DeclareProofOfSpace = 9,
RequestSignedValues = 10,
SignedValues = 11,
FarmingInfo = 12,

// Timelord protocol (timelord <-> fullNode)
NewPeakTimelord = 13,
NewUnfinishedBlockTimelord = 14,
NewInfusionPointVdf = 15,
NewSignagePointVdf = 16,
NewEndOfSubSlotVdf = 17,
RequestCompactProofOfTime = 18,
RespondCompactProofOfTime = 19,

// Full node protocol (fullNode <-> fullNode)
NewPeak = 20,
NewTransaction = 21,
RequestTransaction = 22,
RespondTransaction = 23,
RequestProofOfWeight = 24,
RespondProofOfWeight = 25,
RequestBlock = 26,
RespondBlock = 27,
RejectBlock = 28,
RequestBlocks = 29,
RespondBlocks = 30,
RejectBlocks = 31,
NewUnfinishedBlock = 32,
RequestUnfinishedBlock = 33,
RespondUnfinishedBlock = 34,
NewSignagePointOrEndOfSubSlot = 35,
RequestSignagePointOrEndOfSubSlot = 36,
RespondSignagePoint = 37,
RespondEndOfSubSlot = 38,
RequestMempoolTransactions = 39,
RequestCompactVdf = 40,
RespondCompactVdf = 41,
NewCompactVdf = 42,
RequestPeers = 43,
RespondPeers = 44,
NoneResponse = 91,

// Wallet protocol (wallet <-> fullNode)
RequestPuzzleSolution = 45,
RespondPuzzleSolution = 46,
RejectPuzzleSolution = 47,
SendTransaction = 48,
TransactionAck = 49,
NewPeakWallet = 50,
RequestBlockHeader = 51,
RespondBlockHeader = 52,
RejectHeaderRequest = 53,
RequestRemovals = 54,
RespondRemovals = 55,
RejectRemovalsRequest = 56,
RequestAdditions = 57,
RespondAdditions = 58,
RejectAdditionsRequest = 59,
RequestHeaderBlocks = 60,
RejectHeaderBlocks = 61,
RespondHeaderBlocks = 62,

// Introducer protocol (introducer <-> fullNode)
RequestPeersIntroducer = 63,
RespondPeersIntroducer = 64,

// Simulator protocol
FarmNewBlock = 65,

// New harvester protocol
NewSignagePointHarvester = 66,
RequestPlots = 67,
RespondPlots = 68,
PlotSyncStart = 78,
PlotSyncLoaded = 79,
PlotSyncRemoved = 80,
PlotSyncInvalid = 81,
PlotSyncKeysMissing = 82,
PlotSyncDuplicates = 83,
PlotSyncDone = 84,
PlotSyncResponse = 85,

// More wallet protocol
CoinStateUpdate = 69,
RegisterForPhUpdates = 70,
RespondToPhUpdate = 71,
RegisterForCoinUpdates = 72,
RespondToCoinUpdates = 73,
RequestChildren = 74,
RespondChildren = 75,
RequestSesInfo = 76,
RespondSesInfo = 77,
RequestBlockHeaders = 86,
RejectBlockHeaders = 87,
RespondBlockHeaders = 88,
RequestFeeEstimates = 89,
RespondFeeEstimates = 90,
}

pub trait ChiaProtocolMessage {
fn msg_type() -> ProtocolMessageTypes;
}

#[repr(u8)]
pub enum NodeType {
FullNode = 1,
Harvester = 2,
Farmer = 3,
Timelord = 4,
Introducer = 5,
Wallet = 6,
DataLayer = 7,
}

streamable_struct! (Message {
msg_type: u8,
id: Option<u16>,
data: Bytes,
});

message_struct! (Handshake {
// Network id, usually the genesis challenge of the blockchain
network_id: String,
// Protocol version to determine which messages the peer supports
protocol_version: String,
// Version of the software, to debug and determine feature support
software_version: String,
// Which port the server is listening on
server_port: u16,
// NodeType (full node, wallet, farmer, etc.)
node_type: u8,
// Key value dict to signal support for additional capabilities/features
capabilities: Vec<(u16, String)>,
});
32 changes: 32 additions & 0 deletions chia-protocol/src/classgroup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::chia_error;
use crate::streamable_struct;
use crate::Bytes100;
use crate::Streamable;
use chia_streamable_macro::Streamable;

#[cfg(feature = "py-bindings")]
use crate::from_json_dict::FromJsonDict;
#[cfg(feature = "py-bindings")]
use crate::to_json_dict::ToJsonDict;
#[cfg(feature = "py-bindings")]
use chia_py_streamable_macro::PyStreamable;
#[cfg(feature = "py-bindings")]
use pyo3::prelude::*;

streamable_struct!(ClassgroupElement { data: Bytes100 });

#[cfg(feature = "py-bindings")]
#[cfg_attr(feature = "py-bindings", pymethods)]
impl ClassgroupElement {
#[staticmethod]
pub fn get_default_element() -> ClassgroupElement {
let mut data = [0_u8; 100];
data[0] = 0x08;
ClassgroupElement { data: data.into() }
}

#[staticmethod]
pub fn get_size(_constants: pyo3::PyObject) -> i32 {
100
}
}
22 changes: 22 additions & 0 deletions chia-protocol/src/coin_spend.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use chia_streamable_macro::Streamable;

use crate::chia_error;
use crate::coin::Coin;
use crate::program::Program;
use crate::streamable::Streamable;
use crate::streamable_struct;

#[cfg(feature = "py-bindings")]
use crate::from_json_dict::FromJsonDict;
#[cfg(feature = "py-bindings")]
use crate::to_json_dict::ToJsonDict;
#[cfg(feature = "py-bindings")]
use chia_py_streamable_macro::PyStreamable;
#[cfg(feature = "py-bindings")]
use pyo3::prelude::*;

streamable_struct!(CoinSpend {
coin: Coin,
puzzle_reveal: Program,
solution: Program,
});
25 changes: 25 additions & 0 deletions chia-protocol/src/end_of_sub_slot_bundle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use chia_streamable_macro::Streamable;

use crate::chia_error;
use crate::streamable_struct;
use crate::ChallengeChainSubSlot;
use crate::InfusedChallengeChainSubSlot;
use crate::RewardChainSubSlot;
use crate::Streamable;
use crate::SubSlotProofs;

#[cfg(feature = "py-bindings")]
use crate::from_json_dict::FromJsonDict;
#[cfg(feature = "py-bindings")]
use crate::to_json_dict::ToJsonDict;
#[cfg(feature = "py-bindings")]
use chia_py_streamable_macro::PyStreamable;
#[cfg(feature = "py-bindings")]
use pyo3::prelude::*;

streamable_struct! (EndOfSubSlotBundle {
challenge_chain: ChallengeChainSubSlot,
infused_challenge_chain: Option<InfusedChallengeChainSubSlot>,
reward_chain: RewardChainSubSlot,
proofs: SubSlotProofs,
});
32 changes: 32 additions & 0 deletions chia-protocol/src/fee_estimate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use chia_streamable_macro::Streamable;

use crate::chia_error;
use crate::streamable_struct;
use crate::Streamable;

#[cfg(feature = "py-bindings")]
use crate::from_json_dict::FromJsonDict;
#[cfg(feature = "py-bindings")]
use crate::to_json_dict::ToJsonDict;
#[cfg(feature = "py-bindings")]
use chia_py_streamable_macro::PyStreamable;
#[cfg(feature = "py-bindings")]
use pyo3::prelude::*;

streamable_struct!(FeeRate {
// Represents Fee Rate in mojos divided by CLVM Cost.
// Performs XCH/mojo conversion.
// Similar to 'Fee per cost'.
mojos_per_clvm_cost: u64,
});

streamable_struct! (FeeEstimate {
error: Option<String>,
time_target: u64, // unix time stamp in seconds
estimated_fee_rate: FeeRate, // Mojos per clvm cost
});

streamable_struct! (FeeEstimateGroup {
error: Option<String>,
estimates: Vec<FeeEstimate>,
});
59 changes: 59 additions & 0 deletions chia-protocol/src/foliage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use chia_streamable_macro::Streamable;

use crate::chia_error;
use crate::streamable_struct;
use crate::Bytes32;
use crate::Coin;
use crate::G2Element;
use crate::PoolTarget;
use crate::Streamable;

#[cfg(feature = "py-bindings")]
use crate::from_json_dict::FromJsonDict;
#[cfg(feature = "py-bindings")]
use crate::to_json_dict::ToJsonDict;
#[cfg(feature = "py-bindings")]
use chia_py_streamable_macro::PyStreamable;
#[cfg(feature = "py-bindings")]
use pyo3::prelude::*;

streamable_struct! (TransactionsInfo {
// Information that goes along with each transaction block
generator_root: Bytes32, // sha256 of the block generator in this block
generator_refs_root: Bytes32, // sha256 of the concatenation of the generator ref list entries
aggregated_signature: G2Element,
fees: u64, // This only includes user fees, not block rewards
cost: u64, // This is the total cost of this block, including CLVM cost, cost of program size and conditions
reward_claims_incorporated: Vec<Coin>, // These can be in any order
});

streamable_struct!(FoliageTransactionBlock {
// Information that goes along with each transaction block that is relevant for light clients
prev_transaction_block_hash: Bytes32,
timestamp: u64,
filter_hash: Bytes32,
additions_root: Bytes32,
removals_root: Bytes32,
transactions_info_hash: Bytes32,
});

streamable_struct! (FoliageBlockData {
// Part of the block that is signed by the plot key
unfinished_reward_block_hash: Bytes32,
pool_target: PoolTarget,
pool_signature: Option<G2Element>, // Iff ProofOfSpace has a pool pk
farmer_reward_puzzle_hash: Bytes32,
extension_data: Bytes32, // Used for future updates. Can be any 32 byte value initially
});

streamable_struct! (Foliage {
// The entire foliage block, containing signature and the unsigned back pointer
// The hash of this is the "header hash". Note that for unfinished blocks, the prev_block_hash
// Is the prev from the signage point, and can be replaced with a more recent block
prev_block_hash: Bytes32,
reward_block_hash: Bytes32,
foliage_block_data: FoliageBlockData,
foliage_block_data_signature: G2Element,
foliage_transaction_block_hash: Option<Bytes32>,
foliage_transaction_block_signature: Option<G2Element>,
});
34 changes: 34 additions & 0 deletions chia-protocol/src/fullblock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use chia_streamable_macro::Streamable;

use crate::chia_error;
use crate::streamable_struct;
use crate::EndOfSubSlotBundle;
use crate::Program;
use crate::RewardChainBlock;
use crate::Streamable;
use crate::VDFProof;
use crate::{Foliage, FoliageTransactionBlock, TransactionsInfo};

#[cfg(feature = "py-bindings")]
use crate::from_json_dict::FromJsonDict;
#[cfg(feature = "py-bindings")]
use crate::to_json_dict::ToJsonDict;
#[cfg(feature = "py-bindings")]
use chia_py_streamable_macro::PyStreamable;
#[cfg(feature = "py-bindings")]
use pyo3::prelude::*;

streamable_struct! (FullBlock {
finished_sub_slots: Vec<EndOfSubSlotBundle>,
reward_chain_block: RewardChainBlock,
challenge_chain_sp_proof: Option<VDFProof>, // # If not first sp in sub-slot
challenge_chain_ip_proof: VDFProof,
reward_chain_sp_proof: Option<VDFProof>, // # If not first sp in sub-slot
reward_chain_ip_proof: VDFProof,
infused_challenge_chain_ip_proof: Option<VDFProof>, // # Iff deficit < 4
foliage: Foliage, // # Reward chain foliage data
foliage_transaction_block: Option<FoliageTransactionBlock>, // # Reward chain foliage data (tx block)
transactions_info: Option<TransactionsInfo>, // Reward chain foliage data (tx block additional)
transactions_generator: Option<Program>, // Program that generates transactions
transactions_generator_ref_list: Vec<u32>, // List of block heights of previous generators referenced in this block
});
Loading

0 comments on commit 019d453

Please sign in to comment.