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

540 change runtime resolve address to return an actorid #549

Merged
merged 19 commits into from
Aug 29, 2022
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
7 changes: 4 additions & 3 deletions actors/init/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ impl Actor {

log::trace!("called exec; params.code_cid: {:?}", &params.code_cid);

let caller_code = rt.get_actor_code_cid(&rt.message().caller()).ok_or_else(|| {
actor_error!(illegal_state, "no code for caller as {}", rt.message().caller())
})?;
let caller_code =
rt.get_actor_code_cid(&rt.message().caller().id().unwrap()).ok_or_else(|| {
actor_error!(illegal_state, "no code for caller as {}", rt.message().caller())
})?;

log::trace!("caller code CID: {:?}", &caller_code);

Expand Down
55 changes: 31 additions & 24 deletions actors/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ fil_actors_runtime::wasm_trampoline!(Actor);

fn request_miner_control_addrs<BS, RT>(
rt: &mut RT,
miner_addr: Address,
miner_id: ActorID,
) -> Result<(Address, Address, Vec<Address>), ActorError>
where
BS: Blockstore,
RT: Runtime<BS>,
{
let ret = rt.send(
miner_addr,
Address::new_id(miner_id),
ext::miner::CONTROL_ADDRESSES_METHOD,
RawBytes::default(),
TokenAmount::zero(),
Expand Down Expand Up @@ -230,13 +230,13 @@ impl Actor {

// All deals should have the same provider so get worker once
let provider_raw = params.deals[0].proposal.provider;
let provider = rt.resolve_address(&provider_raw).ok_or_else(|| {
let provider_id = rt.resolve_address(&provider_raw).ok_or_else(|| {
actor_error!(not_found, "failed to resolve provider address {}", provider_raw)
})?;

let code_id = rt
.get_actor_code_cid(&provider)
.ok_or_else(|| actor_error!(illegal_argument, "no code ID for address {}", provider))?;
.get_actor_code_cid(&provider_id)
.ok_or_else(|| actor_error!(not_found, "no code ID for address {}", provider_id))?;

if rt.resolve_builtin_actor_type(&code_id) != Some(Type::Miner) {
return Err(actor_error!(
Expand All @@ -245,7 +245,7 @@ impl Actor {
));
}

let (_, worker, controllers) = request_miner_control_addrs(rt, provider)?;
let (_, worker, controllers) = request_miner_control_addrs(rt, provider_id)?;
let caller = rt.message().caller();
let mut caller_ok = caller == worker;
for controller in controllers.iter() {
Expand All @@ -259,7 +259,7 @@ impl Actor {
forbidden,
"caller {} is not worker or control address of provider {}",
caller,
provider
provider_id
));
}

Expand Down Expand Up @@ -291,14 +291,16 @@ impl Actor {
continue;
}

if deal.proposal.provider != provider && deal.proposal.provider != provider_raw {
if deal.proposal.provider != Address::new_id(provider_id)
&& deal.proposal.provider != provider_raw
{
info!(
"invalid deal {}: cannot publish deals from multiple providers in one batch",
di
);
continue;
}
let client = match rt.resolve_address(&deal.proposal.client) {
let client_id = match rt.resolve_address(&deal.proposal.client) {
Some(client) => client,
_ => {
info!(
Expand All @@ -310,17 +312,17 @@ impl Actor {
};

// drop deals with insufficient lock up to cover costs
let client_id = client.id().expect("resolved address should be an ID address");
let mut client_lockup =
total_client_lockup.get(&client_id).cloned().unwrap_or_default();
client_lockup += deal.proposal.client_balance_requirement();

let client_balance_ok = msm.balance_covered(client, &client_lockup).map_err(|e| {
e.downcast_default(
ExitCode::USR_ILLEGAL_STATE,
"failed to check client balance coverage",
)
})?;
let client_balance_ok =
msm.balance_covered(Address::new_id(client_id), &client_lockup).map_err(|e| {
e.downcast_default(
ExitCode::USR_ILLEGAL_STATE,
"failed to check client balance coverage",
)
})?;

if !client_balance_ok {
info!("invalid deal: {}: insufficient client funds to cover proposal cost", di);
Expand All @@ -329,8 +331,9 @@ impl Actor {

let mut provider_lockup = total_provider_lockup.clone();
provider_lockup += &deal.proposal.provider_collateral;
let provider_balance_ok =
msm.balance_covered(provider, &provider_lockup).map_err(|e| {
let provider_balance_ok = msm
.balance_covered(Address::new_id(provider_id), &provider_lockup)
.map_err(|e| {
e.downcast_default(
ExitCode::USR_ILLEGAL_STATE,
"failed to check provider balance coverage",
Expand All @@ -346,9 +349,11 @@ impl Actor {
// Normalise provider and client addresses in the proposal stored on chain.
// Must happen after signature verification and before taking cid.

deal.proposal.provider = provider;
deal.proposal.client = client;
let pcid = cid(rt, &deal.proposal)?;
deal.proposal.provider = Address::new_id(provider_id);
deal.proposal.client = Address::new_id(client_id);
let pcid = deal.proposal.cid().map_err(
|e| actor_error!(illegal_argument; "failed to take cid of proposal {}: {}", di, e),
)?;

// check proposalCids for duplication within message batch
// check state PendingProposals for duplication across messages
Expand All @@ -372,7 +377,7 @@ impl Actor {
*VERIFIED_REGISTRY_ACTOR_ADDR,
crate::ext::verifreg::USE_BYTES_METHOD as u64,
RawBytes::serialize(UseBytesParams {
address: client,
address: Address::new_id(client_id),
deal_size: BigInt::from(deal.proposal.piece_size.0),
})?,
TokenAmount::zero(),
Expand Down Expand Up @@ -1320,13 +1325,15 @@ where
.get_actor_code_cid(&nominal)
.ok_or_else(|| actor_error!(illegal_argument, "no code for address {}", nominal))?;

let nominal_addr = Address::new_id(nominal);

if rt.resolve_builtin_actor_type(&code_id) == Some(Type::Miner) {
// Storage miner actor entry; implied funds recipient is the associated owner address.
let (owner_addr, worker_addr, _) = request_miner_control_addrs(rt, nominal)?;
return Ok((nominal, owner_addr, vec![owner_addr, worker_addr]));
return Ok((nominal_addr, owner_addr, vec![owner_addr, worker_addr]));
}

Ok((nominal, nominal, vec![nominal]))
Ok((nominal_addr, nominal_addr, vec![nominal_addr]))
}

/// Requests the current epoch target block reward from the reward actor.
Expand Down
6 changes: 3 additions & 3 deletions actors/miner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4025,7 +4025,7 @@ where
));
}

Ok(resolved)
Ok(Address::new_id(resolved))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably just return the ActorID here, unless that causes lots of churn at caller.s

}

/// Resolves an address to an ID address and verifies that it is address of an account actor with an associated BLS key.
Expand All @@ -4052,7 +4052,7 @@ where

if raw.protocol() != Protocol::BLS {
let ret = rt.send(
resolved,
Address::new_id(resolved),
ext::account::PUBKEY_ADDRESS_METHOD,
RawBytes::default(),
TokenAmount::zero(),
Expand All @@ -4067,7 +4067,7 @@ where
));
}
}
Ok(resolved)
Ok(Address::new_id(resolved))
anorth marked this conversation as resolved.
Show resolved Hide resolved
}

fn burn_funds<BS, RT>(rt: &mut RT, amount: TokenAmount) -> Result<(), ActorError>
Expand Down
46 changes: 23 additions & 23 deletions actors/multisig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::BTreeSet;
use fil_actors_runtime::cbor::serialize_vec;
use fil_actors_runtime::runtime::{ActorCode, Primitives, Runtime};
use fil_actors_runtime::{
actor_error, cbor, make_empty_map, make_map_with_root, resolve_to_id_addr, ActorDowncast,
actor_error, cbor, make_empty_map, make_map_with_root, resolve_to_actor_id, ActorDowncast,
ActorError, Map, CALLER_TYPES_SIGNABLE, INIT_ACTOR_ADDR,
};
use fvm_ipld_blockstore::Blockstore;
Expand Down Expand Up @@ -73,18 +73,18 @@ impl Actor {
let mut resolved_signers = Vec::with_capacity(params.signers.len());
let mut dedup_signers = BTreeSet::new();
for signer in &params.signers {
let resolved = resolve_to_id_addr(rt, signer).map_err(|e| {
let resolved = resolve_to_actor_id(rt, signer).map_err(|e| {
e.downcast_default(
ExitCode::USR_ILLEGAL_STATE,
format!("failed to resolve addr {} to ID addr", signer),
format!("failed to resolve addr {} to ID", signer),
)
})?;
if !dedup_signers.insert(resolved.id().expect("address should be resolved")) {
if !dedup_signers.insert(resolved) {
return Err(
actor_error!(illegal_argument; "duplicate signer not allowed: {}", signer),
);
}
resolved_signers.push(resolved);
resolved_signers.push(Address::new_id(resolved));
}

if params.num_approvals_threshold > params.signers.len() as u64 {
Expand Down Expand Up @@ -299,10 +299,10 @@ impl Actor {
{
let receiver = rt.message().receiver();
rt.validate_immediate_caller_is(std::iter::once(&receiver))?;
let resolved_new_signer = resolve_to_id_addr(rt, &params.signer).map_err(|e| {
let resolved_new_signer = resolve_to_actor_id(rt, &params.signer).map_err(|e| {
e.downcast_default(
ExitCode::USR_ILLEGAL_STATE,
format!("failed to resolve address {}", params.signer),
format!("failed to resolve address {} to ID", params.signer),
)
})?;

Expand All @@ -314,12 +314,12 @@ impl Actor {
SIGNERS_MAX
));
}
if st.is_signer(&resolved_new_signer) {
if st.is_signer(&Address::new_id(resolved_new_signer)) {
return Err(actor_error!(forbidden, "{} is already a signer", resolved_new_signer));
}

// Add signer and increase threshold if set
st.signers.push(resolved_new_signer);
st.signers.push(Address::new_id(resolved_new_signer));
if params.increase {
st.num_approvals_threshold += 1;
}
Expand All @@ -336,15 +336,15 @@ impl Actor {
{
let receiver = rt.message().receiver();
rt.validate_immediate_caller_is(std::iter::once(&receiver))?;
let resolved_old_signer = resolve_to_id_addr(rt, &params.signer).map_err(|e| {
let resolved_old_signer = resolve_to_actor_id(rt, &params.signer).map_err(|e| {
e.downcast_default(
ExitCode::USR_ILLEGAL_STATE,
format!("failed to resolve address {}", params.signer),
format!("failed to resolve address {} to ID", params.signer),
)
})?;

rt.transaction(|st: &mut State, rt| {
if !st.is_signer(&resolved_old_signer) {
if !st.is_signer(&Address::new_id(resolved_old_signer)) {
return Err(actor_error!(forbidden, "{} is not a signer", resolved_old_signer));
}

Expand Down Expand Up @@ -374,13 +374,13 @@ impl Actor {
}

// Remove approvals from removed signer
st.purge_approvals(rt.store(), &resolved_old_signer).map_err(|e| {
st.purge_approvals(rt.store(), &Address::new_id(resolved_old_signer)).map_err(|e| {
e.downcast_default(
ExitCode::USR_ILLEGAL_STATE,
"failed to purge approvals of removed signer",
)
})?;
st.signers.retain(|s| s != &resolved_old_signer);
st.signers.retain(|s| s != &Address::new_id(resolved_old_signer));

Ok(())
})?;
Expand All @@ -396,35 +396,35 @@ impl Actor {
{
let receiver = rt.message().receiver();
rt.validate_immediate_caller_is(std::iter::once(&receiver))?;
let from_resolved = resolve_to_id_addr(rt, &params.from).map_err(|e| {
let from_resolved = resolve_to_actor_id(rt, &params.from).map_err(|e| {
e.downcast_default(
ExitCode::USR_ILLEGAL_STATE,
format!("failed to resolve address {}", params.from),
format!("failed to resolve address {} to ID", params.from),
)
})?;
let to_resolved = resolve_to_id_addr(rt, &params.to).map_err(|e| {
let to_resolved = resolve_to_actor_id(rt, &params.to).map_err(|e| {
e.downcast_default(
ExitCode::USR_ILLEGAL_STATE,
format!("failed to resolve address {}", params.to),
format!("failed to resolve address {} to ID", params.to),
)
})?;

rt.transaction(|st: &mut State, rt| {
if !st.is_signer(&from_resolved) {
if !st.is_signer(&Address::new_id(from_resolved)) {
return Err(actor_error!(forbidden; "{} is not a signer", from_resolved));
}

if st.is_signer(&to_resolved) {
if st.is_signer(&Address::new_id(to_resolved)) {
return Err(actor_error!(illegal_argument; "{} is already a signer", to_resolved));
}

// Remove signer from state (retain preserves order of elements)
st.signers.retain(|s| s != &from_resolved);
st.signers.retain(|s| s != &Address::new_id(from_resolved));

// Add new signer
st.signers.push(to_resolved);
st.signers.push(Address::new_id(to_resolved));

st.purge_approvals(rt.store(), &from_resolved).map_err(|e| {
st.purge_approvals(rt.store(), &Address::new_id(from_resolved)).map_err(|e| {
e.downcast_default(
ExitCode::USR_ILLEGAL_STATE,
"failed to purge approvals of removed signer",
Expand Down
16 changes: 9 additions & 7 deletions actors/paych/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

use fil_actors_runtime::runtime::builtins::Type;
use fil_actors_runtime::runtime::{ActorCode, Runtime};
use fil_actors_runtime::{actor_error, cbor, resolve_to_id_addr, ActorDowncast, ActorError, Array};
use fil_actors_runtime::{
actor_error, cbor, resolve_to_actor_id, ActorDowncast, ActorError, Array,
};
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::RawBytes;
use fvm_shared::address::Address;
Expand Down Expand Up @@ -73,10 +75,10 @@ impl Actor {
BS: Blockstore,
RT: Runtime<BS>,
{
let resolved = resolve_to_id_addr(rt, raw).map_err(|e| {
let resolved = resolve_to_actor_id(rt, raw).map_err(|e| {
e.downcast_default(
ExitCode::USR_ILLEGAL_STATE,
format!("failed to resolve address {}", raw),
format!("failed to resolve address {} to ID", raw),
)
})?;

Expand All @@ -94,7 +96,7 @@ impl Actor {
typ
))
} else {
Ok(resolved)
Ok(Address::new_id(resolved))
}
}

Expand Down Expand Up @@ -140,17 +142,17 @@ impl Actor {
})?;

let pch_addr = rt.message().receiver();
let svpch_id_addr = rt.resolve_address(&sv.channel_addr).ok_or_else(|| {
let svpch_id = rt.resolve_address(&sv.channel_addr).ok_or_else(|| {
actor_error!(
illegal_argument,
"voucher payment channel address {} does not resolve to an ID address",
sv.channel_addr
)
})?;
if pch_addr != svpch_id_addr {
if pch_addr != Address::new_id(svpch_id) {
return Err(actor_error!(illegal_argument;
"voucher payment channel address {} does not match receiver {}",
svpch_id_addr, pch_addr));
svpch_id, pch_addr));
}

if rt.curr_epoch() < sv.time_lock_min {
Expand Down
Loading