Updating the definitions for structs by Sansh2356 · Pull Request #123 · braidpool/braidpool · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.lock

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

50 changes: 41 additions & 9 deletions README.md
7 changes: 5 additions & 2 deletions braidpool-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ hex = "0.4.3"
num-bigint = "0.4.6"
ordered-float = "5.0.0"
transitive = "1.1.0"
bitcoin = { git = "https://github.com/braidpool/rust-bitcoin.git" }
bitcoin = { git = "https://github.com/braidpool/rust-bitcoin.git" ,features=["serde"]}
serde = {version = "1.0.219", features=["derive"]}
serde_json = "1.0.140"
secp256k1 = "0.30.0"

[lib]
name = "braidpool_primitives"
path = "src/lib.rs"
path = "src/lib.rs"
83 changes: 42 additions & 41 deletions braidpool-primitives/src/bead/mod.rs
Original file line number Diff line number Diff line change
@@ -1,60 +1,55 @@
#![allow(unused)]
// Standard Imports
use ::serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::net::SocketAddr;

// Bitcoin primitives
use bitcoin::Address;
use bitcoin::absolute::Time;
use bitcoin::ecdsa::Signature;
use bitcoin::p2p::Address as P2P_Address;
use bitcoin::secp256k1::PublicKey;
use bitcoin::transaction::TransactionExt;
use bitcoin::{BlockHeader, CompactTarget, Transaction};

use bitcoin::{BlockHeader, Transaction};
// Custom Imports
use crate::utils::BeadHash;
use crate::utils::bitcoin::MerklePathProof;

// Type Aliases
type TransactionWithMerklePath = (Transaction, MerklePathProof);

pub struct Bead {
pub block_header: BlockHeader,
pub bead_hash: BeadHash,
pub coinbase_transaction: TransactionWithMerklePath,
pub payout_update_transaction: TransactionWithMerklePath,
#[derive(Clone, Debug, Serialize)]

pub struct CommittedMetadata {
// Committed Braidpool Metadata,
pub lesser_difficulty_target: CompactTarget,
pub parents: HashSet<(BeadHash, Time)>,
pub transaction_cnt: u32,
pub transactions: Vec<Transaction>,

pub parents: HashSet<BeadHash>,
pub payout_address: Address,
//timestamp when the bead was created
pub observed_time_at_node: Time,
pub comm_pub_key: PublicKey,
pub miner_ip: SocketAddr,
}
#[derive(Clone, Debug, Serialize)]

impl Bead {
// All public definitions go in here!
#[inline]
pub fn is_transaction_included_in_block(
&self,
transaction_with_proof: &TransactionWithMerklePath,
) -> bool {
transaction_with_proof
.1
.calculate_corresponding_merkle_root()
== self.block_header.merkle_root
}
pub struct UnCommittedMetadata {
//Uncomitted Metadata
//timestamp when the bead was broadcasted
pub extra_nonce: i32,
pub broadcast_timestamp: Time,
pub signature: Signature,
pub parent_bead_timestamps: HashSet<Time>,
}
#[derive(Clone, Debug, Serialize)]

pub struct Bead {
pub block_header: BlockHeader,
pub committed_metadata: CommittedMetadata,
pub uncommitted_metadata: UnCommittedMetadata,
}

impl Bead {
pub fn is_valid_bead(&self) -> bool {
// Check whether the transactions are included in the block!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is always returning true without any condition. Is this a part of defined behaviour? And where are these removed checks handled in the codebase?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function will be either removed or updated it is not the purpose of this current PR @zaidmstrr , another PR i am working upon as of now that will add and update these changes .

if self.is_transaction_included_in_block(&self.coinbase_transaction) == false {
false
} else if self.is_transaction_included_in_block(&self.payout_update_transaction) == false {
false
} else if self.coinbase_transaction.0.is_coinbase() == false {
false
} else if self.bead_hash != self.block_header.block_hash() {
false
} else {
true
}
// Check whether the transactions are included in the block
true
}

pub fn get_coinbase_transaction(&self) -> Transaction {
// TODO: Implement this function.
unimplemented!()
Expand All @@ -67,7 +62,13 @@ impl Bead {
}

impl Bead {
// All private function definitions go here!
// All private function definitions go here
//TODO : To implement a reverse mapping since we will be including the
//consensus determining attribute in the committed portion and those which
//will be used afterward such as in retargeting algorithms such as the parentbead_timestamps they shall be
//included inside the uncommitted portion but the order must be same as that of the hashset of parents_bead_hashes present
//inside the committed metadata
pub fn reverse_mapping_parentbead_with_timestamp() {}
}

#[cfg(test)]
Expand Down
78 changes: 78 additions & 0 deletions braidpool-primitives/src/bead/tests.rs
Loading