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

feat: runtime: Add send_generalized #1126

Merged
merged 3 commits into from
Jan 30, 2023
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
11 changes: 9 additions & 2 deletions actors/cron/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use fil_actors_runtime::runtime::{ActorCode, Runtime};
use fil_actors_runtime::{actor_dispatch, actor_error, ActorError, SYSTEM_ACTOR_ADDR};
use fil_actors_runtime::{
actor_dispatch, actor_error, extract_send_result, ActorError, SYSTEM_ACTOR_ADDR,
};

use fvm_ipld_encoding::tuple::*;
use fvm_shared::econ::TokenAmount;
Expand Down Expand Up @@ -56,7 +58,12 @@ impl Actor {
let st: State = rt.state()?;
for entry in st.entries {
// Intentionally ignore any error when calling cron methods
let res = rt.send(&entry.receiver, entry.method_num, None, TokenAmount::zero());
let res = extract_send_result(rt.send_simple(
&entry.receiver,
entry.method_num,
None,
TokenAmount::zero(),
));
if let Err(e) = res {
log::error!(
"cron failed to send entry to {}, send error code {}",
Expand Down
5 changes: 3 additions & 2 deletions actors/datacap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use num_derive::FromPrimitive;

use fil_actors_runtime::runtime::{ActorCode, Runtime};
use fil_actors_runtime::{
actor_dispatch, actor_error, ActorContext, ActorError, AsActorError, SYSTEM_ACTOR_ADDR,
actor_dispatch, actor_error, extract_send_result, ActorContext, ActorError, AsActorError,
SYSTEM_ACTOR_ADDR,
};
use fvm_ipld_encoding::ipld_block::IpldBlock;

Expand Down Expand Up @@ -406,7 +407,7 @@ where
value: TokenAmount,
) -> Result<Response, ErrorNumber> {
// The Runtime discards some of the information from the syscall :-(
let res = self.rt.send(to, method, params, value);
let res = extract_send_result(self.rt.send_simple(to, method, params, value));

let rec = match res {
Ok(ret) => Response { exit_code: ExitCode::OK, return_data: ret },
Expand Down
6 changes: 3 additions & 3 deletions actors/init/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use fil_actors_runtime::runtime::builtins::Type;
use fil_actors_runtime::runtime::{ActorCode, Runtime};

use fil_actors_runtime::{
actor_dispatch, actor_error, ActorContext, ActorError, SYSTEM_ACTOR_ADDR,
actor_dispatch, actor_error, extract_send_result, ActorContext, ActorError, SYSTEM_ACTOR_ADDR,
};
use fvm_shared::address::Address;
use fvm_shared::{ActorID, METHOD_CONSTRUCTOR};
Expand Down Expand Up @@ -95,12 +95,12 @@ impl Actor {
rt.create_actor(params.code_cid, id_address, None)?;

// Invoke constructor
rt.send(
extract_send_result(rt.send_simple(
&Address::new_id(id_address),
METHOD_CONSTRUCTOR,
params.constructor_params.into(),
rt.message().value_received(),
)
))
.context("constructor failed")?;

Ok(ExecReturn { id_address: Address::new_id(id_address), robust_address })
Expand Down
99 changes: 56 additions & 43 deletions actors/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::{BTreeMap, BTreeSet};

use cid::multihash::{Code, MultihashDigest, MultihashGeneric};
use cid::Cid;
use fil_actors_runtime::FIRST_ACTOR_SPECIFIC_EXIT_CODE;
use fil_actors_runtime::{extract_send_result, FIRST_ACTOR_SPECIFIC_EXIT_CODE};
use frc46_token::token::types::{BalanceReturn, TransferFromParams, TransferFromReturn};
use fvm_ipld_bitfield::BitField;
use fvm_ipld_blockstore::Blockstore;
Expand Down Expand Up @@ -151,7 +151,12 @@ impl Actor {
Ok(ex)
})?;

rt.send(&recipient, METHOD_SEND, None, amount_extracted.clone())?;
extract_send_result(rt.send_simple(
&recipient,
METHOD_SEND,
None,
amount_extracted.clone(),
))?;

Ok(WithdrawBalanceReturn { amount_withdrawn: amount_extracted })
}
Expand Down Expand Up @@ -211,12 +216,15 @@ impl Actor {
}

let caller = rt.message().caller();
let caller_status: ext::miner::IsControllingAddressReturn = deserialize_block(rt.send(
&Address::new_id(provider_id),
ext::miner::IS_CONTROLLING_ADDRESS_EXPORTED,
IpldBlock::serialize_cbor(&ext::miner::IsControllingAddressParam { address: caller })?,
TokenAmount::zero(),
)?)?;
let caller_status: ext::miner::IsControllingAddressReturn =
deserialize_block(extract_send_result(rt.send_simple(
&Address::new_id(provider_id),
ext::miner::IS_CONTROLLING_ADDRESS_EXPORTED,
IpldBlock::serialize_cbor(&ext::miner::IsControllingAddressParam {
address: caller,
})?,
TokenAmount::zero(),
))?)?;
if !caller_status.is_controlling {
return Err(actor_error!(
forbidden,
Expand Down Expand Up @@ -438,15 +446,15 @@ impl Actor {

// notify clients ignoring any errors
for (i, valid_deal) in valid_deals.iter().enumerate() {
_ = rt.send(
_ = extract_send_result(rt.send_simple(
&valid_deal.proposal.client,
MARKET_NOTIFY_DEAL_METHOD,
IpldBlock::serialize_cbor(&MarketNotifyDealParams {
proposal: valid_deal.serialized_proposal.to_vec(),
deal_id: new_deal_ids[i],
})?,
TokenAmount::zero(),
);
));
}

Ok(PublishStorageDealsReturn { ids: new_deal_ids, valid_deals: valid_input_bf })
Expand Down Expand Up @@ -841,7 +849,12 @@ impl Actor {
})?;

if !amount_slashed.is_zero() {
rt.send(&BURNT_FUNDS_ACTOR_ADDR, METHOD_SEND, None, amount_slashed)?;
extract_send_result(rt.send_simple(
&BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
None,
amount_slashed,
))?;
}
Ok(())
}
Expand Down Expand Up @@ -1109,14 +1122,13 @@ fn transfer_from(
rt: &mut impl Runtime,
params: TransferFromParams,
) -> Result<Vec<AllocationID>, ActorError> {
let ret = rt
.send(
&DATACAP_TOKEN_ACTOR_ADDR,
ext::datacap::TRANSFER_FROM_METHOD as u64,
IpldBlock::serialize_cbor(&params)?,
TokenAmount::zero(),
)
.context(format!("failed to send transfer to datacap {:?}", params))?;
let ret = extract_send_result(rt.send_simple(
&DATACAP_TOKEN_ACTOR_ADDR,
ext::datacap::TRANSFER_FROM_METHOD as u64,
IpldBlock::serialize_cbor(&params)?,
TokenAmount::zero(),
))
.context(format!("failed to send transfer to datacap {:?}", params))?;
let ret: TransferFromReturn = ret
.with_context_code(ExitCode::USR_ASSERTION_FAILED, || "return expected".to_string())?
.deserialize()?;
Expand All @@ -1128,14 +1140,13 @@ fn transfer_from(
// Invokes BalanceOf on the data cap token actor.
fn balance_of(rt: &mut impl Runtime, owner: &Address) -> Result<TokenAmount, ActorError> {
let params = IpldBlock::serialize_cbor(owner)?;
let ret = rt
.send(
&DATACAP_TOKEN_ACTOR_ADDR,
ext::datacap::BALANCE_OF_METHOD as u64,
params,
TokenAmount::zero(),
)
.context(format!("failed to query datacap balance of {}", owner))?;
let ret = extract_send_result(rt.send_simple(
&DATACAP_TOKEN_ACTOR_ADDR,
ext::datacap::BALANCE_OF_METHOD as u64,
params,
TokenAmount::zero(),
))
.context(format!("failed to query datacap balance of {}", owner))?;
let ret: BalanceReturn = ret
.with_context_code(ExitCode::USR_ASSERTION_FAILED, || "return expected".to_string())?
.deserialize()?;
Expand Down Expand Up @@ -1278,15 +1289,15 @@ fn deal_proposal_is_internally_valid(
// Generate unsigned bytes
let proposal_bytes = serialize(&proposal.proposal, "deal proposal")?;

rt.send(
extract_send_result(rt.send_simple(
&proposal.proposal.client,
ext::account::AUTHENTICATE_MESSAGE_METHOD,
IpldBlock::serialize_cbor(&ext::account::AuthenticateMessageParams {
signature: signature_bytes,
message: proposal_bytes.to_vec(),
})?,
TokenAmount::zero(),
)
))
.map_err(|e| e.wrap("proposal authentication failed"))?;
Ok(())
}
Expand Down Expand Up @@ -1321,12 +1332,13 @@ fn request_miner_control_addrs(
rt: &mut impl Runtime,
miner_id: ActorID,
) -> Result<(Address, Address, Vec<Address>), ActorError> {
let addrs: ext::miner::GetControlAddressesReturnParams = deserialize_block(rt.send(
&Address::new_id(miner_id),
ext::miner::CONTROL_ADDRESSES_METHOD,
None,
TokenAmount::zero(),
)?)?;
let addrs: ext::miner::GetControlAddressesReturnParams =
deserialize_block(extract_send_result(rt.send_simple(
&Address::new_id(miner_id),
ext::miner::CONTROL_ADDRESSES_METHOD,
None,
TokenAmount::zero(),
))?)?;

Ok((addrs.owner, addrs.worker, addrs.control_addresses))
}
Expand Down Expand Up @@ -1359,12 +1371,12 @@ fn escrow_address(

/// Requests the current epoch target block reward from the reward actor.
fn request_current_baseline_power(rt: &mut impl Runtime) -> Result<StoragePower, ActorError> {
let ret: ThisEpochRewardReturn = deserialize_block(rt.send(
let ret: ThisEpochRewardReturn = deserialize_block(extract_send_result(rt.send_simple(
&REWARD_ACTOR_ADDR,
ext::reward::THIS_EPOCH_REWARD_METHOD,
None,
TokenAmount::zero(),
)?)?;
))?)?;
Ok(ret.this_epoch_baseline_power)
}

Expand All @@ -1373,12 +1385,13 @@ fn request_current_baseline_power(rt: &mut impl Runtime) -> Result<StoragePower,
fn request_current_network_power(
rt: &mut impl Runtime,
) -> Result<(StoragePower, StoragePower), ActorError> {
let ret: ext::power::CurrentTotalPowerReturnParams = deserialize_block(rt.send(
&STORAGE_POWER_ACTOR_ADDR,
ext::power::CURRENT_TOTAL_POWER_METHOD,
None,
TokenAmount::zero(),
)?)?;
let ret: ext::power::CurrentTotalPowerReturnParams =
deserialize_block(extract_send_result(rt.send_simple(
&STORAGE_POWER_ACTOR_ADDR,
ext::power::CURRENT_TOTAL_POWER_METHOD,
None,
TokenAmount::zero(),
))?)?;
Ok((ret.raw_byte_power, ret.quality_adj_power))
}

Expand Down
Loading