Skip to content

Commit

Permalink
Merge pull request #329 from Chia-Network/full-node-protocol
Browse files Browse the repository at this point in the history
add Full node protocol
  • Loading branch information
arvidn authored Dec 4, 2023
2 parents 4d64f30 + 8a052a8 commit df9924f
Show file tree
Hide file tree
Showing 10 changed files with 1,106 additions and 38 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 37 additions & 3 deletions chia-protocol/fuzz/fuzz_targets/streamable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ pub fn test_streamable<T: Streamable + std::fmt::Debug + PartialEq>(obj: &T) {
corrupt_bytes.push(0);
assert!(T::from_bytes(&corrupt_bytes) == Err(chia_traits::Error::InputTooLarge));

// make sure input too short is an error
corrupt_bytes.truncate(bytes.len() - 1);
assert!(T::from_bytes(&corrupt_bytes) == Err(chia_traits::Error::EndOfBuffer));
if !bytes.is_empty() {
// make sure input too short is an error
corrupt_bytes.truncate(bytes.len() - 1);
assert!(T::from_bytes(&corrupt_bytes) == Err(chia_traits::Error::EndOfBuffer));
}
}
#[cfg(fuzzing)]
fn test<'a, T: Arbitrary<'a> + Streamable + std::fmt::Debug + PartialEq>(data: &'a [u8]) {
Expand Down Expand Up @@ -81,6 +83,11 @@ fuzz_target!(|data: &[u8]| {
test::<SubEpochChallengeSegment>(data);
test::<SubEpochSegments>(data);
test::<SubEpochSummary>(data);
test::<WeightProof>(data);
test::<TimestampedPeerInfo>(data);
test::<RecentChainData>(data);
test::<ProofBlockHeader>(data);
test::<SubEpochData>(data);

test::<Handshake>(data);

Expand Down Expand Up @@ -117,4 +124,31 @@ fuzz_target!(|data: &[u8]| {
test::<RespondSesInfo>(data);
test::<RequestFeeEstimates>(data);
test::<RespondFeeEstimates>(data);

// Full Node Protocol
test::<NewPeak>(data);
test::<NewTransaction>(data);
test::<RequestTransaction>(data);
test::<RespondTransaction>(data);
test::<RequestProofOfWeight>(data);
test::<RespondProofOfWeight>(data);
test::<RequestBlock>(data);
test::<RejectBlock>(data);
test::<RequestBlocks>(data);
test::<RespondBlocks>(data);
test::<RejectBlocks>(data);
test::<RespondBlock>(data);
test::<NewUnfinishedBlock>(data);
test::<RequestUnfinishedBlock>(data);
test::<RespondUnfinishedBlock>(data);
test::<NewSignagePointOrEndOfSubSlot>(data);
test::<RequestSignagePointOrEndOfSubSlot>(data);
test::<RespondSignagePoint>(data);
test::<RespondEndOfSubSlot>(data);
test::<RequestMempoolTransactions>(data);
test::<NewCompactVDF>(data);
test::<RequestCompactVDF>(data);
test::<RespondCompactVDF>(data);
test::<RequestPeers>(data);
test::<RespondPeers>(data);
});
6 changes: 3 additions & 3 deletions chia-protocol/src/chia_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ pub enum ProtocolMessageTypes {
RespondSignagePoint = 37,
RespondEndOfSubSlot = 38,
RequestMempoolTransactions = 39,
RequestCompactVdf = 40,
RespondCompactVdf = 41,
NewCompactVdf = 42,
RequestCompactVDF = 40,
RespondCompactVDF = 41,
NewCompactVDF = 42,
RequestPeers = 43,
RespondPeers = 44,
NoneResponse = 91,
Expand Down
138 changes: 138 additions & 0 deletions chia-protocol/src/full_node_protocol.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
use chia_streamable_macro::Streamable;

use crate::message_struct;
use crate::ChiaProtocolMessage;
use crate::EndOfSubSlotBundle;
use crate::FullBlock;
use crate::SpendBundle;
use crate::TimestampedPeerInfo;
use crate::UnfinishedBlock;
use crate::VDFInfo;
use crate::VDFProof;
use crate::WeightProof;
use crate::{Bytes, Bytes32};

message_struct!(NewPeak {
header_hash: Bytes32,
height: u32,
weight: u128,
fork_point_with_previous_peak: u32,
unfinished_reward_block_hash: Bytes32,
});

message_struct!(NewTransaction {
transaction_id: Bytes32,
cost: u64,
fees: u64,
});

message_struct!(RequestTransaction {
transaction_id: Bytes32,
});

message_struct!(RespondTransaction {
transaction: SpendBundle,
});

message_struct!(RequestProofOfWeight {
total_number_of_blocks: u32,
tip: Bytes32,
});

message_struct!(RespondProofOfWeight {
wp: WeightProof,
tip: Bytes32,
});

message_struct!(RequestBlock {
height: u32,
include_transaction_block: bool,
});

message_struct!(RejectBlock { height: u32 });

message_struct!(RequestBlocks {
start_height: u32,
end_height: u32,
include_transaction_block: bool,
});

message_struct!(RespondBlocks {
start_height: u32,
end_height: u32,
blocks: Vec<FullBlock>,
});

message_struct!(RejectBlocks {
start_height: u32,
end_height: u32,
});

message_struct!(RespondBlock { block: FullBlock });

message_struct!(NewUnfinishedBlock {
unfinished_reward_hash: Bytes32,
});

message_struct!(RequestUnfinishedBlock {
unfinished_reward_hash: Bytes32,
});

message_struct!(RespondUnfinishedBlock {
unfinished_block: UnfinishedBlock,
});

message_struct!(NewSignagePointOrEndOfSubSlot {
prev_challenge_hash: Option<Bytes32>,
challenge_hash: Bytes32,
index_from_challenge: u8,
last_rc_infusion: Bytes32,
});

message_struct!(RequestSignagePointOrEndOfSubSlot {
challenge_hash: Bytes32,
index_from_challenge: u8,
last_rc_infusion: Bytes32,
});

message_struct!(RespondSignagePoint {
index_from_challenge: u8,
challenge_chain_vdf: VDFInfo,
challenge_chain_proof: VDFProof,
reward_chain_vdf: VDFInfo,
reward_chain_proof: VDFProof,
});

message_struct!(RespondEndOfSubSlot {
end_of_slot_bundle: EndOfSubSlotBundle,
});

message_struct!(RequestMempoolTransactions { filter: Bytes });

message_struct!(NewCompactVDF {
height: u32,
header_hash: Bytes32,
field_vdf: u8,
vdf_info: VDFInfo,
});

message_struct!(RequestCompactVDF {
height: u32,
header_hash: Bytes32,
field_vdf: u8,
vdf_info: VDFInfo,
});

message_struct!(RespondCompactVDF {
height: u32,
header_hash: Bytes32,
field_vdf: u8,
vdf_info: VDFInfo,
vdf_proof: VDFProof,
});

message_struct!(RequestPeers {});

message_struct!(RespondPeers {
peer_list: Vec<TimestampedPeerInfo>,
});
4 changes: 4 additions & 0 deletions chia-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ pub mod coin_state;
pub mod end_of_sub_slot_bundle;
pub mod fee_estimate;
pub mod foliage;
pub mod full_node_protocol;
pub mod fullblock;
pub mod header_block;
pub mod message_struct;
pub mod peer_info;
pub mod pool_target;
pub mod program;
pub mod proof_of_space;
Expand All @@ -35,8 +37,10 @@ pub use crate::coin_state::*;
pub use crate::end_of_sub_slot_bundle::*;
pub use crate::fee_estimate::*;
pub use crate::foliage::*;
pub use crate::full_node_protocol::*;
pub use crate::fullblock::*;
pub use crate::header_block::*;
pub use crate::peer_info::*;
pub use crate::pool_target::*;
pub use crate::program::*;
pub use crate::proof_of_space::*;
Expand Down
9 changes: 9 additions & 0 deletions chia-protocol/src/peer_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use chia_streamable_macro::Streamable;

use crate::streamable_struct;

streamable_struct!(TimestampedPeerInfo {
host: String,
port: u16,
timestamp: u64,
});
Loading

0 comments on commit df9924f

Please sign in to comment.