Skip to content

Commit

Permalink
Windows support for POS, Updates to Chia APIs, adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luna committed Nov 5, 2023
1 parent 673e193 commit 1e1493c
Show file tree
Hide file tree
Showing 60 changed files with 1,124 additions and 1,102 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ members = [
"macros",
"proof_of_space",
"puzzles",
"serialize"
"serialize",
"tests"
]
10 changes: 8 additions & 2 deletions cli/src/wallet_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ pub async fn migrate_plot_nft(
info!("Searching for PlotNFT with LauncherID: {launcher_id}");
if let Some(mut plot_nft) = get_plotnft_by_launcher_id(client, launcher_id).await? {
info!("Checking if PlotNFT needs migration");
if plot_nft.pool_state.pool_url.as_ref() != Some(&pool_url) {
if plot_nft.pool_state.pool_url.as_ref() != Some(&pool_url)
|| (plot_nft.pool_state.pool_url.as_ref() == Some(&pool_url)
&& plot_nft.pool_state.state != FARMING_TO_POOL)
{
info!("Starting Migration");
let target_pool_state =
create_and_validate_target_state(&pool_url, pool_info, &plot_nft)?;
Expand Down Expand Up @@ -192,7 +195,10 @@ pub async fn migrate_plot_nft_with_owner_key(
info!("Searching for PlotNFT with LauncherID: {launcher_id}");
if let Some(mut plot_nft) = get_plotnft_by_launcher_id(client, launcher_id).await? {
info!("Checking if PlotNFT needs migration");
if plot_nft.pool_state.pool_url.as_ref() != Some(&pool_url) {
if plot_nft.pool_state.pool_url.as_ref() != Some(&pool_url)
|| (plot_nft.pool_state.pool_url.as_ref() == Some(&pool_url)
&& plot_nft.pool_state.state != FARMING_TO_POOL)
{
info!("Starting Migration");
let target_pool_state =
create_and_validate_target_state(&pool_url, pool_info, &plot_nft)?;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/wallets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ fn compute_memos_for_spend(
) -> Result<HashMap<Bytes32, Vec<Vec<u8>>>, Error> {
let (_, result) = coin_spend
.puzzle_reveal
.run_with_cost(INFINITE_COST, &coin_spend.solution.to_program()?)?;
.run_with_cost(INFINITE_COST, &coin_spend.solution.to_program())?;
let mut memos = HashMap::default();
let result_list = result.as_list();
for condition in result_list {
Expand Down
Empty file added clients/src/api/crawler.rs
Empty file.
Empty file added clients/src/api/data_layer.rs
Empty file.
Empty file added clients/src/api/farmer.rs
Empty file.
27 changes: 27 additions & 0 deletions clients/src/api/full_node.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::protocols::full_node::BlockCountMetrics;
use crate::protocols::full_node::FeeEstimate;
use async_trait::async_trait;
use dg_xch_core::blockchain::block_record::BlockRecord;
use dg_xch_core::blockchain::blockchain_state::BlockchainState;
Expand All @@ -23,8 +25,10 @@ pub trait FullnodeAPI {
start: u32,
end: u32,
exclude_header_hash: bool,
exclude_reorged: bool,
) -> Result<Vec<FullBlock>, Error>;
async fn get_all_blocks(&self, start: u32, end: u32) -> Result<Vec<FullBlock>, Error>;
async fn get_block_count_metrics(&self) -> Result<BlockCountMetrics, Error>;
async fn get_block_record_by_height(&self, height: u32) -> Result<BlockRecord, Error>;
async fn get_block_record(&self, header_hash: &Bytes32) -> Result<BlockRecord, Error>;
async fn get_block_records(&self, start: u32, end: u32) -> Result<Vec<BlockRecord>, Error>;
Expand Down Expand Up @@ -65,13 +69,27 @@ pub trait FullnodeAPI {
end_height: Option<u32>,
) -> Result<Vec<CoinRecord>, Error>;
async fn get_coin_record_by_name(&self, name: &Bytes32) -> Result<Option<CoinRecord>, Error>;
async fn get_coin_record_by_names(
&self,
names: &[Bytes32],
include_spent_coins: bool,
start_height: u32,
end_height: u32,
) -> Result<Vec<CoinRecord>, Error>;
async fn get_coin_records_by_parent_ids(
&self,
parent_ids: &[Bytes32],
include_spent_coins: bool,
start_height: u32,
end_height: u32,
) -> Result<Vec<CoinRecord>, Error>;
async fn get_coin_records_by_hint(
&self,
hint: &Bytes32,
include_spent_coins: bool,
start_height: u32,
end_height: u32,
) -> Result<Vec<CoinRecord>, Error>;
async fn push_tx(&self, spend_bundle: &SpendBundle) -> Result<TXStatus, Error>;
async fn get_puzzle_and_solution(
&self,
Expand All @@ -82,4 +100,13 @@ pub trait FullnodeAPI {
async fn get_all_mempool_tx_ids(&self) -> Result<Vec<String>, Error>;
async fn get_all_mempool_items(&self) -> Result<HashMap<String, MempoolItem>, Error>;
async fn get_mempool_item_by_tx_id(&self, tx_id: &str) -> Result<MempoolItem, Error>;
async fn get_mempool_items_by_coin_name(
&self,
coin_name: &Bytes32,
) -> Result<Vec<MempoolItem>, Error>;
async fn get_fee_estimate(
&self,
cost: Option<u64>,
target_times: &[u64],
) -> Result<FeeEstimate, Error>;
}
Empty file added clients/src/api/harvester.rs
Empty file.
19 changes: 19 additions & 0 deletions clients/src/api/responses.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::protocols::full_node::BlockCountMetrics;
use crate::protocols::full_node::FeeEstimate;
use dg_xch_core::blockchain::block_record::BlockRecord;
use dg_xch_core::blockchain::blockchain_state::BlockchainState;
use dg_xch_core::blockchain::coin_record::CoinRecord;
Expand Down Expand Up @@ -58,12 +60,23 @@ pub struct CoinSpendResp {
pub success: bool,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct FeeEstimateResp {
pub fee_estimate: FeeEstimate,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct FullBlockResp {
pub block: FullBlock,
pub success: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlockCountMetricsResp {
pub metrics: BlockCountMetrics,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct FullBlockAryResp {
pub blocks: Vec<FullBlock>,
Expand All @@ -88,6 +101,12 @@ pub struct MempoolItemResp {
pub success: bool,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MempoolItemAryResp {
pub mempool_items: Vec<MempoolItem>,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MempoolItemsResp {
pub mempool_items: HashMap<String, MempoolItem>,
Expand Down
Empty file added clients/src/api/timelord.rs
Empty file.
28 changes: 28 additions & 0 deletions clients/src/protocols/farmer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
// use dg_xch_core::blockchain::challenge_chain_subslot::ChallengeChainSubSlot;
// use dg_xch_core::blockchain::foliage_block_data::FoliageBlockData;
// use dg_xch_core::blockchain::foliage_transaction_block::FoliageTransactionBlock;
use dg_xch_core::blockchain::pool_target::PoolTarget;
use dg_xch_core::blockchain::proof_of_space::ProofOfSpace;
// use dg_xch_core::blockchain::reward_chain_subslot::RewardChainSubSlot;
use dg_xch_core::blockchain::sized_bytes::{Bytes32, Bytes96};
use dg_xch_macros::ChiaSerial;
use serde::{Deserialize, Serialize};

// #[derive(ChiaSerial, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
// pub struct SPSubSlotSourceData {
// cc_sub_slot: ChallengeChainSubSlot,
// rc_sub_slot: RewardChainSubSlot,
// }
//
//
// #[derive(ChiaSerial, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
// pub struct SPVDFSourceData {
// cc_vdf: Bytes100,
// rc_vdf: Bytes100,
// }
//
//
// #[derive(ChiaSerial, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
// pub struct SignagePointSourceData {
// sub_slot_data: Option<SPSubSlotSourceData>,
// vdf_data: Option<SPVDFSourceData>
// }

#[derive(ChiaSerial, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub struct NewSignagePoint {
pub challenge_hash: Bytes32,
Expand All @@ -12,6 +36,7 @@ pub struct NewSignagePoint {
pub difficulty: u64,
pub sub_slot_iters: u64,
pub signage_point_index: u8,
// pub sp_source_data: SignagePointSourceData
}

#[derive(ChiaSerial, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
Expand All @@ -26,13 +51,16 @@ pub struct DeclareProofOfSpace {
pub farmer_puzzle_hash: Bytes32,
pub pool_target: Option<PoolTarget>,
pub pool_signature: Option<Bytes96>,
// pub include_source_signature_data: Option<bool>,
}

#[derive(ChiaSerial, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub struct RequestSignedValues {
pub quality_string: Bytes32,
pub foliage_block_data_hash: Bytes32,
pub foliage_transaction_block_hash: Bytes32,
// pub foliage_block_data: Option<FoliageBlockData>,
// pub foliage_transaction_block_data: Option<FoliageTransactionBlock>
}

#[derive(ChiaSerial, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
Expand Down
26 changes: 26 additions & 0 deletions clients/src/protocols/full_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ pub struct RejectBlock {
pub height: u32,
}

#[derive(ChiaSerial, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub struct BlockCountMetrics {
pub compact_blocks: u64,
pub uncompact_blocks: u64,
pub hint_count: u64,
}

#[derive(ChiaSerial, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub struct RequestBlocks {
pub start_height: u32,
Expand Down Expand Up @@ -165,3 +172,22 @@ pub struct RequestPeers {}
pub struct RespondPeers {
pub peer_list: Vec<TimestampedPeerInfo>,
}

#[derive(ChiaSerial, Clone, PartialEq, Serialize, Deserialize, Debug)]
pub struct FeeEstimate {
estimates: Vec<u64>,
target_times: Vec<u64>,
current_fee_rate: f64,
mempool_size: u64,
mempool_fees: u64,
num_spends: u64,
mempool_max_size: u64,
full_node_synced: bool,
peak_height: u64,
last_peak_timestamp: u64,
node_time_utc: u64,
last_block_cost: u64,
fees_last_block: Option<u64>,
fee_rate_last_block: f64,
last_tx_block_height: u32,
}
21 changes: 21 additions & 0 deletions clients/src/protocols/harvester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ use dg_xch_core::blockchain::sized_bytes::{Bytes32, Bytes48, Bytes96};
use dg_xch_macros::ChiaSerial;
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
// use dg_xch_core::blockchain::challenge_chain_subslot::ChallengeChainSubSlot;
// use dg_xch_core::blockchain::foliage_block_data::FoliageBlockData;
// use dg_xch_core::blockchain::foliage_transaction_block::FoliageTransactionBlock;
// use dg_xch_core::blockchain::reward_chain_subslot::RewardChainSubSlot;
// use crate::protocols::pool::PostPartialPayload;

#[derive(ChiaSerial, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub struct PoolDifficulty {
Expand Down Expand Up @@ -46,14 +51,28 @@ pub struct NewProofOfSpace {
pub plot_identifier: String,
pub proof: ProofOfSpace,
pub signage_point_index: u8,
// pub include_source_signature_data: Option<bool>,
// pub farmer_reward_address_override: Option<Bytes32>,
}

// #[derive(ChiaSerial, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
// pub struct SignatureRequestSourceData {
// pub foliage_block_data: Option<FoliageBlockData>,
// pub foliage_transaction_block: Option<FoliageTransactionBlock>,
// pub cc_vdf: Option<Bytes100>,
// pub rc_vdf: Option<Bytes100>,
// pub cc_sub_slot: Option<ChallengeChainSubSlot>,
// pub rc_sub_slot: Option<RewardChainSubSlot>,
// pub partial: Option<PostPartialPayload>,
// }

#[derive(ChiaSerial, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub struct RequestSignatures {
pub plot_identifier: String,
pub challenge_hash: Bytes32,
pub sp_hash: Bytes32,
pub messages: Vec<Bytes32>,
// pub message_data: Option<Vec<SignatureRequestSourceData>>
}

#[derive(ChiaSerial, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
Expand All @@ -64,6 +83,8 @@ pub struct RespondSignatures {
pub local_pk: Bytes48,
pub farmer_pk: Bytes48,
pub message_signatures: Vec<(Bytes32, Bytes96)>,
// pub include_source_signature_data: Option<bool>,
// pub farmer_reward_address_override: Option<Bytes32>,
}

#[derive(ChiaSerial, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
Expand Down
Loading

0 comments on commit 1e1493c

Please sign in to comment.