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

Fix miner constructor params and proving period offset calculation #740

Merged
merged 4 commits into from
Oct 13, 2020
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
3 changes: 2 additions & 1 deletion tests/conformance_tests/tests/conformance_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ lazy_static! {
Regex::new(r"test-vectors/corpus/vm_violations/x--state_mutation--after-transaction.json").unwrap(),
Regex::new(r"test-vectors/corpus/vm_violations/x--state_mutation--readonly.json").unwrap(),

// Same as marked tests above -- Go impl has the incorrect behaviour
Regex::new(r"fil_1_storageminer-SubmitWindowedPoSt-SysErrSenderInvalid-").unwrap(),

// Extracted miner faults
Regex::new(r"fil_1_storageminer-DeclareFaults-Ok-").unwrap(),
Expand All @@ -49,7 +51,6 @@ lazy_static! {
Regex::new(r"fil_1_storageminer-PreCommitSector-").unwrap(),
Regex::new(r"fil_1_storageminer-ProveCommitSector-SysErrOutOfGas-").unwrap(),
Regex::new(r"fil_1_storageminer-AddLockedFund-Ok-").unwrap(),
Regex::new(r"fil_1_storageminer-SubmitWindowedPoSt-SysErrSenderInvalid-").unwrap(),
Regex::new(r"fil_1_storageminer-WithdrawBalance-Ok-").unwrap(),
Regex::new(r"fil_1_storageminer-PreCommitSector-SysErrOutOfGas-").unwrap(),
Regex::new(r"fil_1_storageminer-ChangePeerID-Ok-").unwrap(),
Expand Down
12 changes: 6 additions & 6 deletions vm/actor/src/builtin/miner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use crate::{
};
use address::{Address, Payload, Protocol};
use bitfield::BitField;
use byteorder::{BigEndian, ByteOrder};
use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
use cid::{multihash::Blake2b256, Cid};
use clock::ChainEpoch;
use crypto::DomainSeparationTag::{
Expand Down Expand Up @@ -3173,14 +3173,15 @@ fn assign_proving_period_offset(
blake2b: impl FnOnce(&[u8]) -> Result<[u8; 32], Box<dyn StdError>>,
) -> Result<ChainEpoch, Box<dyn StdError>> {
let mut my_addr = addr.marshal_cbor()?;
BigEndian::write_i64(&mut my_addr, current_epoch);
my_addr.write_i64::<BigEndian>(current_epoch)?;

let digest = blake2b(&my_addr)?;

let mut offset: ChainEpoch = BigEndian::read_i64(&digest);
offset %= WPOST_PROVING_PERIOD;
let mut offset: u64 = BigEndian::read_u64(&digest);
offset %= WPOST_PROVING_PERIOD as u64;

Ok(offset)
// Conversion from i64 to u64 is safe because it's % WPOST_PROVING_PERIOD which is i64
Ok(offset as ChainEpoch)
}

/// Computes the epoch at which a proving period should start such that it is greater than the current epoch, and
Expand Down Expand Up @@ -3314,7 +3315,6 @@ impl ActorCode for Actor {
{
match FromPrimitive::from_u64(method) {
Some(Method::Constructor) => {
check_empty_params(params)?;
Self::constructor(rt, params.deserialize()?)?;
Ok(Serialized::default())
}
Expand Down
19 changes: 12 additions & 7 deletions vm/actor/src/builtin/power/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,25 @@ impl Actor {
rt.validate_immediate_caller_type(CALLER_TYPES_SIGNABLE.iter())?;
let value = rt.message().value_received().clone();

let constructor_params = Serialized::serialize(MinerConstructorParams {
owner: params.owner,
worker: params.worker,
seal_proof_type: params.seal_proof_type,
peer_id: params.peer,
multi_addresses: params.multiaddrs,
control_addresses: Default::default(),
})?;

let init::ExecReturn {
id_address,
robust_address,
} = rt
.send(
*INIT_ACTOR_ADDR,
init::Method::Exec as u64,
Serialized::serialize(MinerConstructorParams {
owner: params.owner,
worker: params.worker,
control_addresses: Default::default(),
seal_proof_type: params.seal_proof_type,
peer_id: params.peer.0,
multi_addresses: params.multiaddrs,
Serialized::serialize(init::ExecParams {
code_cid: MINER_ACTOR_CODE_ID.clone(),
constructor_params,
})?,
value,
)?
Expand Down
5 changes: 3 additions & 2 deletions vm/actor/src/builtin/power/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::{smooth::FilterEstimate, DealWeight};
use address::Address;
use clock::ChainEpoch;
use encoding::{tuple::*, BytesDe, Cbor};
use encoding::{serde_bytes, tuple::*, BytesDe, Cbor};
use fil_types::{RegisteredSealProof, SectorSize, StoragePower};
use num_bigint::bigint_ser;
use vm::{Serialized, TokenAmount};
Expand All @@ -23,7 +23,8 @@ pub struct CreateMinerParams {
pub owner: Address,
pub worker: Address,
pub seal_proof_type: RegisteredSealProof,
pub peer: BytesDe,
#[serde(with = "serde_bytes")]
pub peer: Vec<u8>,
pub multiaddrs: Vec<BytesDe>,
}
impl Cbor for CreateMinerParams {}
Expand Down