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

Update Runtime to Support V5 Actors #1173

Merged
merged 16 commits into from
Jul 5, 2021
336 changes: 142 additions & 194 deletions Cargo.lock

Large diffs are not rendered by default.

50 changes: 48 additions & 2 deletions blockchain/chain/src/store/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,28 @@ where
}
}

pub async fn get_chain_randomness_looking_forward(
&self,
blocks: &TipsetKeys,
pers: DomainSeparationTag,
round: ChainEpoch,
entropy: &[u8],
) -> Result<[u8; 32], Box<dyn std::error::Error>> {
self.get_chain_randomness(blocks, pers, round, entropy, false)
.await
}

pub async fn get_chain_randomness_looking_backward(
&self,
blocks: &TipsetKeys,
pers: DomainSeparationTag,
round: ChainEpoch,
entropy: &[u8],
) -> Result<[u8; 32], Box<dyn std::error::Error>> {
self.get_chain_randomness(blocks, pers, round, entropy, true)
.await
}

/// Gets 32 bytes of randomness for ChainRand paramaterized by the DomainSeparationTag, ChainEpoch,
/// Entropy from the ticket chain.
pub async fn get_chain_randomness(
Expand All @@ -299,6 +321,7 @@ where
pers: DomainSeparationTag,
round: ChainEpoch,
entropy: &[u8],
lookback: bool,
) -> Result<[u8; 32], Box<dyn std::error::Error>> {
let ts = self.tipset_from_keys(blocks).await?;

Expand All @@ -308,7 +331,7 @@ where

let search_height = if round < 0 { 0 } else { round };

let rand_ts = self.tipset_by_height(search_height, ts, true).await?;
let rand_ts = self.tipset_by_height(search_height, ts, lookback).await?;

draw_randomness(
rand_ts
Expand All @@ -322,6 +345,28 @@ where
)
}

pub async fn get_beacon_randomness_looking_forward(
&self,
blocks: &TipsetKeys,
pers: DomainSeparationTag,
round: ChainEpoch,
entropy: &[u8],
) -> Result<[u8; 32], Box<dyn std::error::Error>> {
self.get_beacon_randomness(blocks, pers, round, entropy, false)
.await
}

pub async fn get_beacon_randomness_looking_backward(
&self,
blocks: &TipsetKeys,
pers: DomainSeparationTag,
round: ChainEpoch,
entropy: &[u8],
) -> Result<[u8; 32], Box<dyn std::error::Error>> {
self.get_beacon_randomness(blocks, pers, round, entropy, true)
.await
}

/// Gets 32 bytes of randomness for ChainRand paramaterized by the DomainSeparationTag, ChainEpoch,
/// Entropy from the latest beacon entry.
pub async fn get_beacon_randomness(
Expand All @@ -330,6 +375,7 @@ where
pers: DomainSeparationTag,
round: ChainEpoch,
entropy: &[u8],
lookback: bool,
) -> Result<[u8; 32], Box<dyn std::error::Error>> {
let ts = self.tipset_from_keys(blocks).await?;

Expand All @@ -339,7 +385,7 @@ where

let search_height = if round < 0 { 0 } else { round };

let rand_ts = self.tipset_by_height(search_height, ts, true).await?;
let rand_ts = self.tipset_by_height(search_height, ts, lookback).await?;

let be = self.latest_beacon_entry(&rand_ts).await?;

Expand Down
2 changes: 1 addition & 1 deletion blockchain/state_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bitfield = { package = "forest_bitfield", version = "0.1" }
serde = { version = "1.0", features = ["derive"] }
num-traits = "0.2.11"
tokio = { version = "1.0", features = ["sync"] }
filecoin-proofs-api = { version = "6.1", features = ["blst"], default_features = false }
filecoin-proofs-api = { version = "8", features = ["blst"], default_features = false }
futures = "0.3.5"
runtime = { package = "forest_runtime", version = "0.2" }
lazy_static = "1.4"
Expand Down
28 changes: 26 additions & 2 deletions blockchain/state_manager/src/chain_rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
) -> Result<[u8; 32], Box<dyn Error>> {
task::block_on(
self.cs
.get_chain_randomness(&self.blks, pers, round, entropy),
.get_chain_randomness_looking_backward(&self.blks, pers, round, entropy),
)
}

Expand All @@ -48,7 +48,31 @@ where
) -> Result<[u8; 32], Box<dyn Error>> {
task::block_on(
self.cs
.get_beacon_randomness(&self.blks, pers, round, entropy),
.get_beacon_randomness_looking_backward(&self.blks, pers, round, entropy),
)
}

fn get_chain_randomness_looking_forward(
&self,
pers: DomainSeparationTag,
round: ChainEpoch,
entropy: &[u8],
) -> Result<[u8; 32], Box<dyn Error>> {
task::block_on(
self.cs
.get_chain_randomness_looking_forward(&self.blks, pers, round, entropy),
)
}

fn get_beacon_randomness_looking_forward(
&self,
pers: DomainSeparationTag,
round: ChainEpoch,
entropy: &[u8],
) -> Result<[u8; 32], Box<dyn Error>> {
task::block_on(
self.cs
.get_beacon_randomness_looking_forward(&self.blks, pers, round, entropy),
)
}
}
2 changes: 2 additions & 0 deletions node/rpc/src/chain_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ where
DomainSeparationTag::from_i64(pers).ok_or("invalid DomainSeparationTag")?,
epoch,
&base64::decode(entropy)?,
epoch <= networks::UPGRADE_PLACEHOLDER_HEIGHT,
)
.await?)
}
Expand All @@ -300,6 +301,7 @@ where
DomainSeparationTag::from_i64(pers).ok_or("invalid DomainSeparationTag")?,
epoch,
&base64::decode(entropy)?,
epoch <= networks::UPGRADE_PLACEHOLDER_HEIGHT,
)
.await?)
}
38 changes: 38 additions & 0 deletions tests/conformance_tests/src/rand_replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,42 @@ impl Rand for ReplayingRand<'_> {
self.fallback.get_beacon_randomness(dst, epoch, entropy)
}
}
// TODO: Check if this is going to be correct for when we integrate v5 Actors test vectors
fn get_beacon_randomness_looking_forward(
&self,
dst: DomainSeparationTag,
epoch: ChainEpoch,
entropy: &[u8],
) -> Result<[u8; 32], Box<dyn StdError>> {
let rule = RandomnessRule {
kind: RandomnessKind::Beacon,
dst,
epoch,
entropy: entropy.to_vec(),
};
if let Some(bz) = self.matches(rule) {
Ok(bz)
} else {
self.fallback.get_beacon_randomness(dst, epoch, entropy)
}
}
// TODO: Check if this is going to be correct for when we integrate v5 Actors test vectors
fn get_chain_randomness_looking_forward(
&self,
dst: DomainSeparationTag,
epoch: ChainEpoch,
entropy: &[u8],
) -> Result<[u8; 32], Box<dyn StdError>> {
let rule = RandomnessRule {
kind: RandomnessKind::Chain,
dst,
epoch,
entropy: entropy.to_vec(),
};
if let Some(bz) = self.matches(rule) {
Ok(bz)
} else {
self.fallback.get_chain_randomness(dst, epoch, entropy)
}
}
}
22 changes: 22 additions & 0 deletions tests/conformance_tests/src/stubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ impl Rand for TestRand {
) -> Result<[u8; 32], Box<dyn StdError>> {
Ok(*b"i_am_random_____i_am_random_____")
}
fn get_beacon_randomness_looking_forward(
&self,
_: DomainSeparationTag,
_: ChainEpoch,
_: &[u8],
) -> Result<[u8; 32], Box<dyn StdError>> {
Ok(*b"i_am_random_____i_am_random_____")
}
fn get_chain_randomness_looking_forward(
&self,
_: DomainSeparationTag,
_: ChainEpoch,
_: &[u8],
) -> Result<[u8; 32], Box<dyn StdError>> {
Ok(*b"i_am_random_____i_am_random_____")
}
}

pub struct TestSyscalls;
Expand Down Expand Up @@ -49,4 +65,10 @@ impl Syscalls for TestSyscalls {
) -> Result<Option<ConsensusFault>, Box<dyn StdError>> {
Ok(None)
}
fn verify_aggregate_seals(
&self,
_: &fil_types::AggregateSealVerifyProofAndInfos,
) -> Result<(), Box<dyn StdError>> {
Ok(())
}
}
3 changes: 2 additions & 1 deletion types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ chrono = "0.4.9"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.56"
commcid = { path = "../utils/commcid", version = "0.1.1", optional = true }
filecoin-proofs-api = { version = "6.1", features = ["blst"], default_features = false, optional = true }
filecoin-proofs-api = { version = "8", features = ["blst"], default_features = false, optional = true }
vm = { package = "forest_vm", version = "0.3" }
cid = { package = "forest_cid", features = ["cbor"], version = "0.3" }
num-bigint = { path = "../utils/bigint", package = "forest_bigint", version = "0.1.1" }
Expand All @@ -29,6 +29,7 @@ forest_json_utils = { path = "../utils/json_utils", optional = true, version = "
lazy_static = "1.4"
async-std = "1.9"
git-version = "0.3.4"
rayon = "1"

[features]
json = ["base64", "forest_json_utils", "num-bigint/json"]
Expand Down
42 changes: 42 additions & 0 deletions types/src/sector/registered_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ impl RegisteredSealProof {
}
}

/// Seal proof type which defines the version and sector size.
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
pub enum RegisteredAggregateProof {
SnarkPackV1,
Invalid(i64),
}

macro_rules! i64_conversion {
($ty:ident; $( $var:ident => $val:expr, )*) => {
impl From<i64> for $ty {
Expand Down Expand Up @@ -283,6 +290,22 @@ i64_conversion! {
StackedDRG64GiBV1P1 => 9,
}

i64_conversion! {
RegisteredAggregateProof;
SnarkPackV1 => 0,
}
#[cfg(feature = "proofs")]
impl TryFrom<RegisteredAggregateProof> for filecoin_proofs_api::RegisteredAggregationProof {
type Error = String;
fn try_from(p: RegisteredAggregateProof) -> Result<Self, Self::Error> {
use RegisteredAggregateProof::*;
match p {
SnarkPackV1 => Ok(Self::SnarkPackV1),
Invalid(i) => Err(format!("unsupported aggregate proof type: {}", i)),
}
}
}

#[cfg(feature = "proofs")]
impl TryFrom<RegisteredSealProof> for filecoin_proofs_api::RegisteredSealProof {
type Error = String;
Expand Down Expand Up @@ -362,3 +385,22 @@ impl<'de> Deserialize<'de> for RegisteredSealProof {
Ok(Self::from(val))
}
}

impl Serialize for RegisteredAggregateProof {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
i64::from(*self).serialize(serializer)
}
}

impl<'de> Deserialize<'de> for RegisteredAggregateProof {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let val = i64::deserialize(deserializer)?;
Ok(Self::from(val))
}
}
25 changes: 24 additions & 1 deletion types/src/sector/seal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::{Randomness, RegisteredSealProof, SectorID, SectorNumber};
use crate::{
ActorID, Randomness, RegisteredAggregateProof, RegisteredSealProof, SectorID, SectorNumber,
};
use cid::Cid;
use clock::ChainEpoch;
use encoding::{serde_bytes, tuple::*};
Expand Down Expand Up @@ -42,3 +44,24 @@ pub struct SealVerifyParams {
pub sector_num: SectorNumber,
pub seal_rand_epoch: ChainEpoch,
}

/// Information needed to verify an aggregated seal proof.
#[derive(Clone, Debug, PartialEq, Serialize_tuple, Deserialize_tuple)]
pub struct AggregateSealVerifyInfo {
pub sector_number: SectorNumber,
pub randomness: SealRandomness,
pub interactive_randomness: InteractiveSealRandomness,

pub sealed_cid: Cid, // Commr
pub unsealed_cid: Cid, // Commd
}

#[derive(Clone, Debug, PartialEq, Serialize_tuple, Deserialize_tuple)]
pub struct AggregateSealVerifyProofAndInfos {
pub miner: ActorID,
pub seal_proof: RegisteredSealProof,
pub aggregate_proof: RegisteredAggregateProof,
#[serde(with = "serde_bytes")]
pub proof: Vec<u8>,
pub infos: Vec<AggregateSealVerifyInfo>,
}
Loading