Skip to content

Commit

Permalink
Merge branch 'development' into yuko-#374-allow_OMS_IMS_OMP_to_shutdo…
Browse files Browse the repository at this point in the history
…wn_cleanly

# Conflicts:
#	comms/src/inbound_message_service/msg_processing_worker.rs
  • Loading branch information
Yuko Roodt committed Jun 20, 2019
2 parents 95807fa + ac1393a commit b9b1418
Show file tree
Hide file tree
Showing 55 changed files with 1,298 additions and 417 deletions.
2 changes: 1 addition & 1 deletion RFC/src/RFC-0010_CodeStructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ domain layer directories, corresponding to the two network layers that make up t
- `crypto`: All cryptographic services, including a Curve25519 implementation
- `storage`: Data persistence services, including an LMDB persistence implementation
- `merklemountainrange`: An independant implementation of a merkle mountain range
- `derive`: A crate to contain #[derive(...)] macros
- `derive`: A crate to contain `derive(...)` macros

1. `base_layer` is a domain-layer directory and contains:
- `blockchain`: The Tari consensus code
Expand Down
13 changes: 0 additions & 13 deletions RFC/src/RFC-0370_TariCollections.md

This file was deleted.

5 changes: 0 additions & 5 deletions RFC/src/RFC-0371_TokenWallet.md

This file was deleted.

5 changes: 0 additions & 5 deletions RFC/src/RFC-0372_TCP2PComm.md

This file was deleted.

6 changes: 0 additions & 6 deletions RFC/src/RFC-0373_TCInstructionAPI.md

This file was deleted.

6 changes: 0 additions & 6 deletions RFC/src/RFC-0374_TCAssetManagement.md

This file was deleted.

6 changes: 0 additions & 6 deletions RFC/src/RFC-0375_TCWalletBridge.md

This file was deleted.

Empty file.
5 changes: 0 additions & 5 deletions RFC/src/RFC-0530_P2PPayments.md

This file was deleted.

6 changes: 0 additions & 6 deletions RFC/src/RFC-0550_VNFees.md

This file was deleted.

60 changes: 27 additions & 33 deletions RFC/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,35 @@
- [RFC-1000: Tari Use cases](RFC-1000_TariUseCases.md)
- [RFC-0010: Tari code structure and organisation](RFC-0010_CodeStructure.md)
- [RFC-0100: The Tari Base Layer](RFC-0100_BaseLayer.md)
- [RFC-0110: Base nodes](RFC-0110_BaseNodes.md)
- [RFC-0130: Mining](RFC-0130_Mining.md)
- [RFC-0140: Sync and Seeding](RFC-0140_Syncing_and_seeding.md)
- [RFC-0150: Wallets](RFC-0150_Wallets.md)
- [RFC-0151: Transaction protocol](RFC-0151_TransactionProtocol.md)
- [RFC-0170: Network Communication Protocol](RFC-0170_NetworkCommunicationProtocol.md)
- [RFC-0110: Base nodes](RFC-0110_BaseNodes.md)
- [RFC-0130: Mining](RFC-0130_Mining.md)
- [RFC-0140: Sync and Seeding](RFC-0140_Syncing_and_seeding.md)
- [RFC-0150: Wallets](RFC-0150_Wallets.md)
- [RFC-0151: Transaction protocol](RFC-0151_TransactionProtocol.md)
- [RFC-0170: Network Communication Protocol](RFC-0170_NetworkCommunicationProtocol.md)
- [RFC-0171: Message Serialisation](RFC-0171_MessageSerialisation.md)
- [RFC-0172: Peer to Peer Messaging Protocol](RFC-0172_PeerToPeerMessagingProtocol.md)
- [RFC-0190: Mempool](RFC-0190_Mempool.md)
- [Tari-specific extensions to Mimblewimble](BaseLayerExtensions.md)
- [RFC-0220: Asset checkpoints](RFC-0220_AssetCheckpoints.md)
- [RFC-0230: Hash time locked contracts](RFC-0230_HTLC.md)
- [RFC-0322: Validator Node Registration](RFC-0322_VNRegistration.md)
- [RFC-0341: Asset registration](RFC-0341_AssetRegistration.md)
- [RFC-0190: Mempool](RFC-0190_Mempool.md)
- [Tari-specific extensions to Mimblewimble](BaseLayerExtensions.md)
- [RFC-0220: Asset checkpoints](RFC-0220_AssetCheckpoints.md)
- [RFC-0230: Hash time locked contracts](RFC-0230_HTLC.md)
- [RFC-0322: Validator Node Registration](RFC-0322_VNRegistration.md)
- [RFC-0341: Asset registration](RFC-0341_AssetRegistration.md)
- [RFC-0300: The Digital Assets Network](RFC-0300_DAN.md)
- [RFC-0301: Namespace Registration](RFC-0301_NamespaceRegistration.md)
- [RFC-0302: Validator Nodes](RFC-0302_ValidatorNodes.md)
- [RFC-0304: Validator Node committee selection](RFC-0304_VNCommittees.md)
- [Asset Management](AssetManagement.md)
- [RFC-0311: Digital Asset templates](RFC-0311_AssetTemplates.md)
- [RFC-0313: The asset read-only API](RFC-0313_AssetReadAPI.md)
- [RFC-0315: Asset transfer mechanism](RFC-0315_AssetTransfer.md)
- [RFC-0316: Asset retirement](RFC-0316_AssetRetirement.md)
- [RFC-0340: Validator Node Consensus](RFC-0340_VNConsensusOverview.md)
- [RFC-0342: Validator node instructions](RFC-0342_VNInstructions.md)
- [RFC-0343: The VN consensus algorithm](RFC-0343_VNConsensusAlgorithm.md)
- [RFC-0350: DAN Dispute resolution mechanism](RFC-0350_DisputeResolution.md)
- [RFC-0370: Tari Collections](RFC-0370_TariCollections.md)
- [RFC-0371: Token wallet](RFC-0371_TokenWallet.md)
- [RFC-0372: Tari Collections Peer-to-peer communication](RFC-0372_TCP2PComm.md)
- [RFC-0373: Instruction API](RFC-0373_TCInstructionAPI.md)
- [RFC-0374: Asset Creation and management](RFC-0374_TCAssetManagement.md)
- [RFC-0375: Tari wallet bridge](RFC-0375_TCWalletBridge.md)
- [RFC-0301: Namespace Registration](RFC-0301_NamespaceRegistration.md)
- [RFC-0302: Validator Nodes](RFC-0302_ValidatorNodes.md)
- [RFC-0304: Validator Node committee selection](RFC-0304_VNCommittees.md)
- [Asset Management](AssetManagement.md)
- [RFC-0311: Digital Asset templates](RFC-0311_AssetTemplates.md)
- [RFC-0313: The asset read-only API](RFC-0313_AssetReadAPI.md)
- [RFC-0315: Asset transfer mechanism](RFC-0315_AssetTransfer.md)
- [RFC-0316: Asset retirement](RFC-0316_AssetRetirement.md)
- [RFC-0340: Validator Node Consensus](RFC-0340_VNConsensusOverview.md)
- [RFC-0342: Validator node instructions](RFC-0342_VNInstructions.md)
- [RFC-0343: The VN consensus algorithm](RFC-0343_VNConsensusAlgorithm.md)
- [RFC-0350: DAN Dispute resolution mechanism](RFC-0350_DisputeResolution.md)
- [RFC-0500: Tari payment channels](RFC-0500_PaymentChannels.md)
- [RFC-0530: Peer-to-peer payments](RFC-0530_P2PPayments.md)
- [RFC-0550: Instruction fees](RFC-0550_VNFees.md)
- [Glossary](Glossary.md)
- [RFC-0400: Tari Application Suite](RFC-0400_TariApplications.md)
- [RFC-1000: Tari Use Cases](RFC-1000_TariUseCases.md)

- [Glossary](Glossary.md)
109 changes: 109 additions & 0 deletions base_layer/core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ impl Block {
pub fn check_pow(&self) -> Result<(), TransactionError> {
Ok(())
}

/// This function will calculate the pow for the block and fill out the pow header field
pub fn calculate_pow(&mut self) -> Result<(), TransactionError> {
// todo
Ok(())
}
}

//---------------------------------------- AggregateBody ----------------------------------------------------//
Expand Down Expand Up @@ -157,4 +163,107 @@ impl From<Transaction> for AggregateBody {
}
}

#[derive(Default)]
pub struct BlockBuilder {
pub header: BlockHeader,
pub inputs: Vec<TransactionInput>,
pub outputs: Vec<TransactionOutput>,
pub kernels: Vec<TransactionKernel>,
}

impl BlockBuilder {
pub fn new() -> BlockBuilder {
BlockBuilder {
header: BlockBuilder::gen_blank_header(),
inputs: Vec::new(),
outputs: Vec::new(),
kernels: Vec::new(),
}
}

/// This function adds a header to the block
pub fn with_header(&mut self, header: BlockHeader) -> &Self {
self.header = header;
self
}

/// This function adds the provided transaction inputs to the block
pub fn add_inputs(mut self, inputs: &mut Vec<TransactionInput>) -> Self {
self.inputs.append(inputs);
self
}

/// This function adds the provided transaction outputs to the block
pub fn add_outputs(mut self, outputs: &mut Vec<TransactionOutput>) -> Self {
self.outputs.append(outputs);
self
}

/// This function adds the provided transaction kernels to the block
pub fn add_kernels(mut self, kernels: &mut Vec<TransactionKernel>) -> Self {
self.kernels.append(kernels);
self
}

/// This functions add the provided transactions to the block
pub fn with_transactions(mut self, txs: Vec<Transaction>) -> Self {
let mut iter = txs.into_iter();
loop {
match iter.next() {
Some(mut tx) => {
self = self.add_inputs(&mut tx.body.inputs);
self = self.add_outputs(&mut tx.body.outputs);
self = self.add_kernels(&mut tx.body.kernels);
self.header.total_kernel_offset = self.header.total_kernel_offset + tx.offset;
},
None => break,
}
}
self
}

/// This functions add the provided transactions to the block
pub fn add_transaction(mut self, mut tx: Transaction) -> Self {
self = self.add_inputs(&mut tx.body.inputs);
self = self.add_outputs(&mut tx.body.outputs);
self = self.add_kernels(&mut tx.body.kernels);
self.header.total_kernel_offset = self.header.total_kernel_offset + tx.offset;
self
}

/// This will add the given coinbase UTXO to the block
pub fn with_coinbase_utxo(mut self, coinbase_utxo: TransactionOutput, coinbase_kernel: TransactionKernel) -> Self {
self.kernels.push(coinbase_kernel);
self.outputs.push(coinbase_utxo);
self
}

/// This will finish construction of the block and create the block
pub fn build(self) -> Block {
let mut block = Block {
header: self.header,
body: AggregateBody::new(self.inputs, self.outputs, self.kernels),
};
block.body.sort();
block
}

/// This will finish construction of the block, do proof of work and create the block
pub fn build_with_pow(self) -> Block {
let mut block = Block {
header: self.header,
body: AggregateBody::new(self.inputs, self.outputs, self.kernels),
};
block.body.sort();
block
.calculate_pow()
.expect("failure to calculate the block proof of work");
block
}

/// This is just a wrapper function to return a blank header
fn gen_blank_header() -> BlockHeader {
BlockHeader::default()
}
}
//---------------------------------------- Tests ----------------------------------------------------//
19 changes: 18 additions & 1 deletion base_layer/core/src/blockheader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
// Version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0.

use crate::{pow::ProofOfWork, types::*};
use chrono::{DateTime, Utc};
use chrono::{DateTime, NaiveDate, Utc};
use digest::Input;
use serde::{Deserialize, Serialize};
use tari_crypto::ristretto::*;
use tari_utilities::{ByteArray, Hashable};

type BlockHash = [u8; 32];
Expand Down Expand Up @@ -64,6 +65,22 @@ impl BlockHeader {
}
}

impl Default for BlockHeader {
fn default() -> Self {
BlockHeader {
version: BLOCKCHAIN_VERSION,
height: 0,
prev_hash: [0; 32],
timestamp: DateTime::<Utc>::from_utc(NaiveDate::from_ymd(1900, 1, 1).and_hms(1, 1, 1), Utc),
output_mmr: [0; 32],
range_proof_mmr: [0; 32],
kernel_mmr: [0; 32],
total_kernel_offset: RistrettoSecretKey::from(0),
pow: ProofOfWork {},
}
}
}

impl Hashable for BlockHeader {
fn hash(&self) -> Vec<u8> {
HashDigest::new()
Expand Down
3 changes: 3 additions & 0 deletions base_layer/core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ pub const MAX_RANGE_PROOF_RANGE: usize = 32; // 2^32 This is the only way to pro
#[cfg(not(test))]
pub const MAX_RANGE_PROOF_RANGE: usize = 64; // 2^64

/// Current version of the blockchain
pub const BLOCKCHAIN_VERSION: u16 = 0;

// Set up some "global" services for the Tari blockchain - These are most likely not threadsafe as written, but haven't
// checked.
lazy_static! {
Expand Down
5 changes: 4 additions & 1 deletion base_layer/p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ tari_utilities = { version = "0.0.1", path = "../../infrastructure/tari_util"}
rmp-serde = "0.13.7"
serde = "1.0.90"
serde_derive = "1.0.90"
threadpool = "1.7.1"
derive-error = "0.0.4"
log = "0.4.6"
rand = "0.6.5"

[dev-dependencies]
rand = "0.6.5"
Loading

0 comments on commit b9b1418

Please sign in to comment.