Skip to content

Commit

Permalink
Merge pull request casper-network#4635 from EdHastingsCasperAssociati…
Browse files Browse the repository at this point in the history
…on/feat-2.0-integration-pr

2.0 Integration
  • Loading branch information
EdHastingsCasperAssociation authored Apr 4, 2024
2 parents c4e0a96 + c502a1c commit 90cd6cf
Show file tree
Hide file tree
Showing 441 changed files with 17,157 additions and 15,355 deletions.
79 changes: 75 additions & 4 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 @@ -12,6 +12,7 @@ members = [
"types",
"utils/global-state-update-gen",
"utils/validation",
"binary_port"
]

default-members = [
Expand All @@ -25,6 +26,7 @@ default-members = [
"types",
"utils/global-state-update-gen",
"utils/validation",
"binary_port",
]

# Include debug symbols in the release build of `casper-engine-tests` so that `simple-transfer` will yield useful
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ resources/local/chainspec.toml: generate-chainspec.sh resources/local/chainspec.
@./$<

.PHONY: test-rs
test-rs: resources/local/chainspec.toml
$(LEGACY) $(DISABLE_LOGGING) $(CARGO) test --all-features $(CARGO_FLAGS) -- --nocapture
-k test-rs: resources/local/chainspec.toml
$(LEGACY) $(DISABLE_LOGGING) $(CARGO) test --all-features --no-fail-fast $(CARGO_FLAGS) -- --nocapture

.PHONY: resources/local/chainspec.toml
test-rs-no-default-features:
Expand Down Expand Up @@ -142,7 +142,7 @@ lint-smart-contracts:

.PHONY: audit-rs
audit-rs:
$(CARGO) audit --ignore RUSTSEC-2024-0006 --ignore RUSTSEC-2024-0003 --ignore RUSTSEC-2024-0019
$(CARGO) audit --ignore RUSTSEC-2024-0006 --ignore RUSTSEC-2024-0003 --ignore RUSTSEC-2024-0019 --ignore RUSTSEC-2024-0332

.PHONY: audit-as
audit-as:
Expand Down
30 changes: 30 additions & 0 deletions binary_port/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "casper-binary-port"
version = "1.0.0"
edition = "2018"
description = "Types for the casper node binary port"
documentation = "https://docs.rs/casper-binary-port"
readme = "README.md"
homepage = "https://casperlabs.io"
repository = "https://github.com/CasperLabs/casper-node/tree/master/binary_port"
license = "Apache-2.0"
exclude = ["proptest-regressions"]

[dependencies]
casper-types = { version = "3.0.0", path = "../types", features = ["datasize", "json-schema", "std"] }
serde = { version = "1.0.183", features = ["derive"] }
thiserror = "1.0.45"
serde-map-to-array = "1.1.0"
once_cell = { version = "1.5.2", optional = true }
schemars = { version = "0.8.16", features = ["preserve_order", "impl_json_schema"] }
bincode = "1.3.3"

[dev-dependencies]
casper-types = { path = "../types", features = ["datasize", "json-schema", "std", "testing"] }
rand = "0.8.3"
serde_json = "1"
serde_test = "1"

[package.metadata.docs.rs]
all-features = true
rustc-args = ["--cfg", "docsrs"]
16 changes: 16 additions & 0 deletions binary_port/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# `casper-binary-port`

[![LOGO](https://raw.githubusercontent.com/casper-network/casper-node/master/images/casper-association-logo-primary.svg)](https://casper.network/)

[![Build Status](https://drone-auto-casper-network.casperlabs.io/api/badges/casper-network/casper-node/status.svg?branch=dev)](http://drone-auto-casper-network.casperlabs.io/casper-network/casper-node)
[![Crates.io](https://img.shields.io/crates/v/casper-hashing)](https://crates.io/crates/casper-binary-port)
[![Documentation](https://docs.rs/casper-hashing/badge.svg)](https://docs.rs/casper-binary-port)
[![License](https://img.shields.io/badge/license-Apache-blue)](https://github.com/CasperLabs/casper-node/blob/master/LICENSE)

Types for the binary port on a casper network node.

[Node Operator Guide](https://docs.casperlabs.io/operators/)

## License

Licensed under the [Apache License Version 2.0](https://github.com/casper-network/casper-node/blob/master/LICENSE).
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use core::convert::TryFrom;

use crate::{
use casper_types::{
bytesrepr::{self, FromBytes, ToBytes},
BlockHeader, Digest, ProtocolVersion, Timestamp, Transaction,
ProtocolVersion, Transaction,
};
use alloc::vec::Vec;

use super::get_request::GetRequest;
use crate::get_request::GetRequest;

#[cfg(test)]
use rand::Rng;

use casper_types::testing::TestRng;
#[cfg(test)]
use crate::{testing::TestRng, Block, TestBlockV1Builder};
use rand::Rng;

/// The header of a binary request.
#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -92,16 +90,8 @@ pub enum BinaryRequest {
},
/// Request to execute a transaction speculatively.
TrySpeculativeExec {
/// State root on top of which to execute deploy.
state_root_hash: Digest,
/// Block time.
block_time: Timestamp,
/// Protocol version used when creating the original block.
protocol_version: ProtocolVersion,
/// Transaction to execute.
transaction: Transaction,
/// Block header of block at which we should perform speculative execution.
speculative_exec_at_block: BlockHeader,
},
}

Expand All @@ -122,18 +112,9 @@ impl BinaryRequest {
BinaryRequestTag::TryAcceptTransaction => Self::TryAcceptTransaction {
transaction: Transaction::random(rng),
},
BinaryRequestTag::TrySpeculativeExec => {
let block_v1 = TestBlockV1Builder::new().build(rng);
let block = Block::V1(block_v1);

Self::TrySpeculativeExec {
state_root_hash: Digest::random(rng),
block_time: Timestamp::random(rng),
protocol_version: ProtocolVersion::from_parts(rng.gen(), rng.gen(), rng.gen()),
transaction: Transaction::random(rng),
speculative_exec_at_block: block.take_header(),
}
}
BinaryRequestTag::TrySpeculativeExec => Self::TrySpeculativeExec {
transaction: Transaction::random(rng),
},
}
}
}
Expand All @@ -149,39 +130,15 @@ impl ToBytes for BinaryRequest {
match self {
BinaryRequest::Get(inner) => inner.write_bytes(writer),
BinaryRequest::TryAcceptTransaction { transaction } => transaction.write_bytes(writer),
BinaryRequest::TrySpeculativeExec {
transaction,
state_root_hash,
block_time,
protocol_version,
speculative_exec_at_block,
} => {
transaction.write_bytes(writer)?;
state_root_hash.write_bytes(writer)?;
block_time.write_bytes(writer)?;
protocol_version.write_bytes(writer)?;
speculative_exec_at_block.write_bytes(writer)
}
BinaryRequest::TrySpeculativeExec { transaction } => transaction.write_bytes(writer),
}
}

fn serialized_length(&self) -> usize {
match self {
BinaryRequest::Get(inner) => inner.serialized_length(),
BinaryRequest::TryAcceptTransaction { transaction } => transaction.serialized_length(),
BinaryRequest::TrySpeculativeExec {
transaction,
state_root_hash,
block_time,
protocol_version,
speculative_exec_at_block,
} => {
transaction.serialized_length()
+ state_root_hash.serialized_length()
+ block_time.serialized_length()
+ protocol_version.serialized_length()
+ speculative_exec_at_block.serialized_length()
}
BinaryRequest::TrySpeculativeExec { transaction } => transaction.serialized_length(),
}
}
}
Expand All @@ -204,20 +161,7 @@ impl TryFrom<(BinaryRequestTag, &[u8])> for BinaryRequest {
}
BinaryRequestTag::TrySpeculativeExec => {
let (transaction, remainder) = FromBytes::from_bytes(bytes)?;
let (state_root_hash, remainder) = FromBytes::from_bytes(remainder)?;
let (block_time, remainder) = FromBytes::from_bytes(remainder)?;
let (protocol_version, remainder) = FromBytes::from_bytes(remainder)?;
let (speculative_exec_at_block, remainder) = FromBytes::from_bytes(remainder)?;
(
BinaryRequest::TrySpeculativeExec {
transaction,
state_root_hash,
block_time,
protocol_version,
speculative_exec_at_block,
},
remainder,
)
(BinaryRequest::TrySpeculativeExec { transaction }, remainder)
}
};
if !remainder.is_empty() {
Expand Down Expand Up @@ -277,7 +221,7 @@ pub struct InvalidBinaryRequestTag(u8);
#[cfg(test)]
mod tests {
use super::*;
use crate::testing::TestRng;
use casper_types::testing::TestRng;

#[test]
fn header_bytesrepr_roundtrip() {
Expand Down
Loading

0 comments on commit 90cd6cf

Please sign in to comment.