From 2d1cb3fd0eeb607bc47976ee37df82575d6e05b4 Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 12 Jan 2023 15:27:29 +0100 Subject: [PATCH] remove old left-over types. Both Program and FullBlock now live in chia-protocol --- src/fullblock.rs | 202 ----------------------------------------------- src/program.rs | 123 ----------------------------- 2 files changed, 325 deletions(-) delete mode 100644 src/fullblock.rs delete mode 100644 src/program.rs diff --git a/src/fullblock.rs b/src/fullblock.rs deleted file mode 100644 index 76b7030b9..000000000 --- a/src/fullblock.rs +++ /dev/null @@ -1,202 +0,0 @@ -use super::bytes::{Bytes, Bytes100, Bytes32, Bytes48, Bytes96}; -use super::coin::Coin; -use super::program::ProgramArray; -use bincode::Options; -use pyo3::prelude::*; -use pyo3::types::PyBytes; -use serde::{Deserialize, Serialize}; -use std::fmt::Debug; - -#[pyclass(subclass, unsendable)] -#[derive(Serialize, Deserialize, Debug)] -pub struct Fullblock { - finished_sub_slots: Vec, - reward_chain_block: RewardChainBlock, - challenge_chain_sp_proof: Option, // # If not first sp in sub-slot - challenge_chain_ip_proof: VDFProof, - reward_chain_sp_proof: Option, // # If not first sp in sub-slot - reward_chain_ip_proof: VDFProof, - infused_challenge_chain_ip_proof: Option, // # Iff deficit < 4 - foliage: Foliage, // # Reward chain foliage data - foliage_transaction_block: Option, // # Reward chain foliage data (tx block) - transactions_info: Option, // # Reward chain foliage data (tx block additional) - transactions_generator: Option, // # Program that generates transactions - transactions_generator_ref_list: Vec, // List of block heights of previous generators referenced in this block -} - -#[pymethods] -impl Fullblock { - #[staticmethod] - pub fn from_bytes(blob: &[u8]) -> Self { - let chia = bincode::DefaultOptions::new() - .with_chia_int_encoding() - .allow_trailing_bytes() - .with_big_endian(); - chia.deserialize(blob).unwrap() - } - - fn __bytes__<'p>(&self, py: Python<'p>) -> &'p PyBytes { - let chia = bincode::DefaultOptions::new() - .with_chia_int_encoding() - .allow_trailing_bytes() - .with_big_endian(); - let v = chia.serialize(self).unwrap(); - PyBytes::new(py, &v) - } - - fn generator(&self) -> Option<&[u8]> { - self.transactions_generator.as_ref().map(|x| x.0.as_slice()) - } -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct EndOfSubSlotBundle { - challenge_chain: ChallengeChainSubSlot, - infused_challenge_chain: Option, - reward_chain: RewardChainSubSlot, - proofs: SubSlotProofs, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct RewardChainBlock { - weight: u128, - height: u32, - total_iters: u128, - signage_point_index: u8, - pos_ss_cc_challenge_hash: Bytes32, - proof_of_space: ProofOfSpace, - challenge_chain_sp_vdf: Option, // # Not present for first sp in slot - challenge_chain_sp_signature: G2Element, - challenge_chain_ip_vdf: VDFInfo, - reward_chain_sp_vdf: Option, // # Not present for first sp in slot - reward_chain_sp_signature: G2Element, - reward_chain_ip_vdf: VDFInfo, - infused_challenge_chain_ip_vdf: Option, // # Iff deficit < 16 - is_transaction_block: bool, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct VDFProof { - witness_type: u8, - witness: Bytes, - normalized_to_identity: bool, -} - -#[derive(Serialize, Deserialize, Debug)] -pub 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, - foliage_transaction_block_signature: Option, -} - -#[derive(Serialize, Deserialize, Debug)] -pub 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, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct TransactionsInfo { - 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, // # These can be in any order -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct ChallengeChainSubSlot { - challenge_chain_end_of_slot_vdf: VDFInfo, - infused_challenge_chain_sub_slot_hash: Option, // # Only at the end of a slot - subepoch_summary_hash: Option, // # Only once per sub-epoch, and one sub-epoch delayed - new_sub_slot_iters: Option, // # Only at the end of epoch, sub-epoch, and slot - new_difficulty: Option, // # Only at the end of epoch, sub-epoch, and slot -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct InfusedChallengeChainSubSlot { - infused_challenge_chain_end_of_slot_vdf: VDFInfo, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct RewardChainSubSlot { - weight: u128, - height: u32, - total_iters: u128, - signage_point_index: u8, - pos_ss_cc_challenge_hash: Bytes32, - proof_of_space: ProofOfSpace, - challenge_chain_sp_vdf: Option, // # Not present for first sp in slot - challenge_chain_sp_signature: G2Element, - challenge_chain_ip_vdf: VDFInfo, - reward_chain_sp_vdf: Option, // # Not present for first sp in slot - reward_chain_sp_signature: G2Element, - reward_chain_ip_vdf: VDFInfo, - infused_challenge_chain_ip_vdf: Option, // # Iff deficit < 16 - is_transaction_block: bool, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct SubSlotProofs { - challenge_chain_slot_proof: VDFProof, - infused_challenge_chain_slot_proof: Option, - reward_chain_slot_proof: VDFProof, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct VDFInfo { - challenge: Bytes32, // # Used to generate the discriminant (VDF group) - number_of_iterations: u64, - output: ClassgroupElement, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct ProofOfSpace { - challenge: Bytes32, - pool_public_key: Option, // # Only one of these two should be present - pool_contract_puzzle_hash: Option, - plot_public_key: G1Element, - size: u8, - proof: Bytes, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct FoliageBlockData { - /// # Part of the block that is signed by the plot key - unfinished_reward_block_hash: Bytes32, - pool_target: PoolTarget, - pool_signature: Option, // # 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 -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct PoolTarget { - puzzle_hash: Bytes32, - max_height: u32, // # A max height of 0 means it is valid forever -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct ClassgroupElement { - data: Bytes100, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct G1Element(Bytes48); - -#[derive(Serialize, Deserialize, Debug)] -pub struct G2Element(Bytes96); diff --git a/src/program.rs b/src/program.rs deleted file mode 100644 index 05597fee4..000000000 --- a/src/program.rs +++ /dev/null @@ -1,123 +0,0 @@ -use serde::de::{SeqAccess, Visitor}; -use serde::ser::SerializeTupleStruct; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use std::fmt; -use std::fmt::Debug; - -pub struct ProgramArray(pub Vec); - -impl Debug for ProgramArray { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_tuple("ProgramArray") - .field(&hex::encode(&self.0)) - .finish() - } -} -impl<'de> Deserialize<'de> for ProgramArray { - fn deserialize(deserializer: D) -> Result>::Error> - where - D: Deserializer<'de>, - { - let visitor = ProgramArrayVisitor {}; - deserializer.deserialize_tuple(35, visitor) - } -} - -fn size_for_initial_byte<'de, S>( - initial_byte: u8, - seq: &mut S, -) -> Result<(usize, Vec), S::Error> -where - S: SeqAccess<'de>, -{ - let mut size: usize = 0; - let mut size_blob: Vec = Vec::new(); - if initial_byte & 0xc0 == 0x80 { - size = (initial_byte & 0x7f) as usize; - } - if initial_byte & 0xe0 == 0xc0 { - let size_byte: [u8; 1] = seq.next_element()?.unwrap(); - size = (((initial_byte as usize) & 0x3f) << 8) | (size_byte[0] as usize); - size_blob = size_byte.into(); - } - if initial_byte & 0xf0 == 0xe0 { - let size_byte: [u8; 2] = seq.next_element()?.unwrap(); - size = (((initial_byte as usize) & 0x1f) << 16) - | ((size_byte[0] as usize) << 8) - | (size_byte[1] as usize); - size_blob = size_byte.into(); - } - Ok((size, size_blob)) -} - -fn blob_for_size<'de, S>(mut size: usize, seq: &mut S) -> Result, S::Error> -where - S: SeqAccess<'de>, -{ - let mut final_blob: Vec = Vec::new(); - while size > 32 { - let b: [u8; 32] = seq.next_element()?.unwrap(); - final_blob.extend_from_slice(&b); - size -= 32; - } - while size > 8 { - let b: [u8; 8] = seq.next_element()?.unwrap(); - final_blob.extend_from_slice(&b); - size -= 8; - } - while size > 0 { - let b: [u8; 1] = seq.next_element()?.unwrap(); - final_blob.extend_from_slice(&b); - size -= 1; - } - Ok(final_blob) -} - -struct ProgramArrayVisitor {} -impl<'de> Visitor<'de> for ProgramArrayVisitor { - type Value = ProgramArray; - - fn visit_seq(self, mut seq: S) -> Result - where - S: SeqAccess<'de>, - { - let initial_byte: u8 = seq.next_element()?.unwrap(); - let mut r = vec![initial_byte]; - if initial_byte == 0xff { - let left: ProgramArray = seq.next_element()?.unwrap(); - let right: ProgramArray = seq.next_element()?.unwrap(); - r.extend_from_slice(&left.0); - r.extend_from_slice(&right.0); - return Ok(ProgramArray(r)); - } - if initial_byte & 0x80 == 0 { - return Ok(ProgramArray(vec![initial_byte])); - } - let (size, size_blob) = size_for_initial_byte(initial_byte, &mut seq)?; - let blob = blob_for_size(size, &mut seq)?; - - r.extend_from_slice(&size_blob); - r.extend_from_slice(&blob); - let r = ProgramArray(r); - Ok(r) - } - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - write!(formatter, "blob!!") - } -} - -impl Serialize for ProgramArray { - fn serialize(&self, serializer: S) -> Result<::Ok, ::Error> - where - S: Serializer, - { - let r = &self.0; - let len = r.len(); - let mut st = serializer.serialize_tuple_struct("Node", len)?; - for c in r { - st.serialize_field(&c)?; - } - st.end() - } -}