Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block stream benchmark tests #1798

66 changes: 45 additions & 21 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"attest/trusted",
"attest/untrusted",
"attest/verifier",
"attest/verifier/types",
"common",
"connection",
"connection/test-utils",
Expand All @@ -27,6 +28,7 @@ members = [
"consensus/enclave/mock",
"consensus/mint-client",
"consensus/scp",
"consensus/scp/core",
"consensus/scp/play",
"consensus/service",
"consensus/service/config",
Expand Down
5 changes: 4 additions & 1 deletion api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ links = "mc-api"

[dependencies]
mc-account-keys = { path = "../account-keys" }
mc-attest-core = { path = "../attest/core" }
mc-attest-verifier-types = { path = "../attest/verifier/types" }
mc-common = { path = "../common" }
mc-consensus-scp-core = { path = "../consensus/scp/core" }
mc-crypto-keys = { path = "../crypto/keys" }
mc-crypto-multisig = { path = "../crypto/multisig" }
mc-transaction-core = { path = "../transaction/core" }
Expand All @@ -34,6 +36,7 @@ mc-util-build-script = { path = "../util/build/script" }
cargo-emit = "0.2.1"

[dev-dependencies]
mc-consensus-scp-core = { path = "../consensus/scp/core", features = ["test_utils"] }
mc-crypto-x509-test-vectors = { path = "../crypto/x509/test-vectors" }
mc-test-vectors-b58-encodings = { path = "../test-vectors/b58-encodings" }
mc-transaction-core-test-utils = { path = "../transaction/core/test-utils" }
Expand Down
1 change: 1 addition & 0 deletions api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fn main() {
"blockchain.proto",
"external.proto",
"printable.proto",
"quorum_set.proto",
"watcher.proto",
],
);
Expand Down
28 changes: 27 additions & 1 deletion api/proto/blockchain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

syntax = "proto3";
import "external.proto";
import "quorum_set.proto";

package blockchain;

Expand Down Expand Up @@ -70,17 +71,42 @@ message BlockSignature {
uint64 signed_at = 3;
}

message BlockMetadata {
/// The Block ID.
BlockID block_id = 1;

/// Quorum set configuration at the time of externalization.
quorum_set.QuorumSet quorum_set = 2;

/// IAS report for the enclave which generated the signature.
external.VerificationReport verification_report = 3;
}

message SignedBlockMetadata {
/// Metadata signed by the consensus node.
BlockMetadata contents = 1;

/// Message signing key (signer).
external.Ed25519Public node_key = 2;

/// Signature using `node_key` over the Digestible encoding of `contents`.
external.Ed25519Signature signature = 3;
}

// Version 1 of an archived block.
// Note: The block.version field within the block may or may not be equal to 1.
message ArchiveBlockV1 {
// Block
// The block (header).
Block block = 1;

// Contents of the block.
BlockContents block_contents = 2;

// Block signature, when available.
BlockSignature signature = 3;

/// Additional signed metadata about this block.
SignedBlockMetadata metadata = 4;
}

// An archived block.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
syntax = "proto3";

package quorum_set;

import "external.proto";
option go_package = "mobilecoin/api";

message Node {
string responder_id = 1;
Expand Down
24 changes: 21 additions & 3 deletions api/src/convert/archive_block.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) 2018-2022 The MobileCoin Foundation

//! Convert to/from blockchain::ArchiveBlock

use crate::{blockchain, convert::ConversionError};
use mc_transaction_core::{Block, BlockContents, BlockData, BlockSignature};
use crate::{blockchain, ConversionError};
use mc_transaction_core::{Block, BlockContents, BlockData, BlockSignature, SignedBlockMetadata};
use std::convert::TryFrom;

/// Convert mc_transaction_core::BlockData --> blockchain::ArchiveBlock.
Expand All @@ -14,6 +16,9 @@ impl From<&BlockData> for blockchain::ArchiveBlock {
if let Some(signature) = src.signature() {
archive_block_v1.set_signature(signature.into());
}
if let Some(metadata) = src.metadata() {
archive_block_v1.set_metadata(metadata.into());
}

archive_block
}
Expand Down Expand Up @@ -43,8 +48,19 @@ impl TryFrom<&blockchain::ArchiveBlock> for BlockData {
.map_err(|_| ConversionError::InvalidSignature)?;
}

let metadata = archive_block_v1
.metadata
.as_ref()
.map(SignedBlockMetadata::try_from)
.transpose()?;

if block.contents_hash == block_contents.hash() {
Ok(BlockData::new(block, block_contents, signature))
Ok(BlockData::new_with_metadata(
block,
block_contents,
signature,
metadata,
))
} else {
Err(ConversionError::InvalidContents)
}
Expand Down Expand Up @@ -74,9 +90,11 @@ impl TryFrom<&blockchain::ArchiveBlocks> for Vec<BlockData> {
// Ensure blocks_data form a legitimate chain of blocks.
if blocks_data
.iter()
// Verify that the block ID is consistent with the cached parent ID.
.all(|data| data.block().is_block_id_valid())
&& blocks_data
.windows(2)
// Verify that the cached parent ID match the previous block's ID.
.all(|window| window[1].block().parent_id == window[0].block().id)
{
Ok(blocks_data)
Expand Down
Loading