Skip to content

Commit

Permalink
Change runtime address parameters to a reference (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
lyswifter authored Aug 29, 2022
1 parent 3d98e82 commit 63c5033
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion actors/cron/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Actor {
for entry in st.entries {
// Intentionally ignore any error when calling cron methods
let res = rt.send(
entry.receiver,
&entry.receiver,
entry.method_num,
RawBytes::default(),
TokenAmount::from(0u8),
Expand Down
2 changes: 1 addition & 1 deletion actors/init/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Actor {

// Invoke constructor
rt.send(
Address::new_id(id_address),
&Address::new_id(id_address),
METHOD_CONSTRUCTOR,
params.constructor_params,
rt.message().value_received(),
Expand Down
14 changes: 7 additions & 7 deletions actors/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ where
RT: Runtime<BS>,
{
let ret = rt.send(
Address::new_id(miner_id),
&Address::new_id(miner_id),
ext::miner::CONTROL_ADDRESSES_METHOD,
RawBytes::default(),
TokenAmount::zero(),
Expand Down Expand Up @@ -207,7 +207,7 @@ impl Actor {
Ok(ex)
})?;

rt.send(recipient, METHOD_SEND, RawBytes::default(), amount_extracted.clone())?;
rt.send(&recipient, METHOD_SEND, RawBytes::default(), amount_extracted.clone())?;

Ok(WithdrawBalanceReturn { amount_withdrawn: amount_extracted })
}
Expand Down Expand Up @@ -374,7 +374,7 @@ impl Actor {
// drop deals with a DealSize that cannot be fully covered by VerifiedClient's available DataCap
if deal.proposal.verified_deal {
if let Err(e) = rt.send(
*VERIFIED_REGISTRY_ACTOR_ADDR,
&VERIFIED_REGISTRY_ACTOR_ADDR,
crate::ext::verifreg::USE_BYTES_METHOD as u64,
RawBytes::serialize(UseBytesParams {
address: Address::new_id(client_id),
Expand Down Expand Up @@ -1028,7 +1028,7 @@ impl Actor {

for d in timed_out_verified_deals {
let res = rt.send(
*VERIFIED_REGISTRY_ACTOR_ADDR,
&VERIFIED_REGISTRY_ACTOR_ADDR,
ext::verifreg::RESTORE_BYTES_METHOD,
RawBytes::serialize(ext::verifreg::RestoreBytesParams {
address: d.client,
Expand All @@ -1050,7 +1050,7 @@ impl Actor {
}

if !amount_slashed.is_zero() {
rt.send(*BURNT_FUNDS_ACTOR_ADDR, METHOD_SEND, RawBytes::default(), amount_slashed)?;
rt.send(&BURNT_FUNDS_ACTOR_ADDR, METHOD_SEND, RawBytes::default(), amount_slashed)?;
}
Ok(())
}
Expand Down Expand Up @@ -1343,7 +1343,7 @@ where
RT: Runtime<BS>,
{
let rwret = rt.send(
*REWARD_ACTOR_ADDR,
&REWARD_ACTOR_ADDR,
ext::reward::THIS_EPOCH_REWARD_METHOD,
RawBytes::default(),
0.into(),
Expand All @@ -1362,7 +1362,7 @@ where
RT: Runtime<BS>,
{
let rwret = rt.send(
*STORAGE_POWER_ACTOR_ADDR,
&STORAGE_POWER_ACTOR_ADDR,
ext::power::CURRENT_TOTAL_POWER_METHOD,
RawBytes::default(),
0.into(),
Expand Down
31 changes: 16 additions & 15 deletions actors/miner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ impl Actor {
}

let res = rt.send(
*STORAGE_MARKET_ACTOR_ADDR,
&STORAGE_MARKET_ACTOR_ADDR,
ext::market::ACTIVATE_DEALS_METHOD,
RawBytes::serialize(ext::market::ActivateDealsParams {
deal_ids: update.deals.clone(),
Expand Down Expand Up @@ -1583,7 +1583,8 @@ impl Actor {

request_update_power(rt, power_delta)?;
if !to_reward.is_zero() {
if let Err(e) = rt.send(reporter, METHOD_SEND, RawBytes::default(), to_reward.clone()) {
if let Err(e) = rt.send(&reporter, METHOD_SEND, RawBytes::default(), to_reward.clone())
{
error!("failed to send reward: {}", e);
to_burn += to_reward;
}
Expand Down Expand Up @@ -2028,7 +2029,7 @@ impl Actor {
)?;

rt.send(
*STORAGE_POWER_ACTOR_ADDR,
&STORAGE_POWER_ACTOR_ADDR,
ext::power::SUBMIT_POREP_FOR_BULK_VERIFY_METHOD,
RawBytes::serialize(&svi)?,
BigInt::zero(),
Expand Down Expand Up @@ -3221,7 +3222,7 @@ impl Actor {
Ok((burn_amount, reward_amount))
})?;

if let Err(e) = rt.send(reporter, METHOD_SEND, RawBytes::default(), reward_amount) {
if let Err(e) = rt.send(&reporter, METHOD_SEND, RawBytes::default(), reward_amount) {
error!("failed to send reward: {}", e);
}

Expand Down Expand Up @@ -3316,7 +3317,7 @@ impl Actor {
})?;

if amount_withdrawn.is_positive() {
rt.send(info.beneficiary, METHOD_SEND, RawBytes::default(), amount_withdrawn.clone())?;
rt.send(&info.beneficiary, METHOD_SEND, RawBytes::default(), amount_withdrawn.clone())?;
}

burn_funds(rt, fee_to_burn)?;
Expand Down Expand Up @@ -3927,7 +3928,7 @@ where
let ser_params =
serialize(&ext::power::EnrollCronEventParams { event_epoch, payload }, "cron params")?;
rt.send(
*STORAGE_POWER_ACTOR_ADDR,
&STORAGE_POWER_ACTOR_ADDR,
ext::power::ENROLL_CRON_EVENT_METHOD,
ser_params,
TokenAmount::zero(),
Expand All @@ -3948,7 +3949,7 @@ where
let delta_clone = delta.clone();

rt.send(
*STORAGE_POWER_ACTOR_ADDR,
&STORAGE_POWER_ACTOR_ADDR,
ext::power::UPDATE_CLAIMED_POWER_METHOD,
RawBytes::serialize(ext::power::UpdateClaimedPowerParams {
raw_byte_delta: delta.raw,
Expand All @@ -3974,7 +3975,7 @@ where

for chunk in deal_ids.chunks(MAX_LENGTH) {
rt.send(
*STORAGE_MARKET_ACTOR_ADDR,
&STORAGE_MARKET_ACTOR_ADDR,
ext::market::ON_MINER_SECTORS_TERMINATE_METHOD,
RawBytes::serialize(ext::market::OnMinerSectorsTerminateParamsRef {
epoch,
Expand Down Expand Up @@ -4120,7 +4121,7 @@ where
}

let serialized = rt.send(
*STORAGE_MARKET_ACTOR_ADDR,
&STORAGE_MARKET_ACTOR_ADDR,
ext::market::VERIFY_DEALS_FOR_ACTIVATION_METHOD,
RawBytes::serialize(ext::market::VerifyDealsForActivationParamsRef { sectors })?,
TokenAmount::zero(),
Expand All @@ -4140,7 +4141,7 @@ where
{
let ret = rt
.send(
*REWARD_ACTOR_ADDR,
&REWARD_ACTOR_ADDR,
ext::reward::THIS_EPOCH_REWARD_METHOD,
Default::default(),
TokenAmount::zero(),
Expand All @@ -4161,7 +4162,7 @@ where
{
let ret = rt
.send(
*STORAGE_POWER_ACTOR_ADDR,
&STORAGE_POWER_ACTOR_ADDR,
ext::power::CURRENT_TOTAL_POWER_METHOD,
Default::default(),
TokenAmount::zero(),
Expand Down Expand Up @@ -4227,7 +4228,7 @@ where

if raw.protocol() != Protocol::BLS {
let ret = rt.send(
Address::new_id(resolved),
&Address::new_id(resolved),
ext::account::PUBKEY_ADDRESS_METHOD,
RawBytes::default(),
TokenAmount::zero(),
Expand All @@ -4252,7 +4253,7 @@ where
{
log::debug!("storage provder {} burning {}", rt.message().receiver(), amount);
if amount.is_positive() {
rt.send(*BURNT_FUNDS_ACTOR_ADDR, METHOD_SEND, RawBytes::default(), amount)?;
rt.send(&BURNT_FUNDS_ACTOR_ADDR, METHOD_SEND, RawBytes::default(), amount)?;
}
Ok(())
}
Expand All @@ -4264,7 +4265,7 @@ where
{
if !pledge_delta.is_zero() {
rt.send(
*STORAGE_POWER_ACTOR_ADDR,
&STORAGE_POWER_ACTOR_ADDR,
ext::power::UPDATE_PLEDGE_TOTAL_METHOD,
RawBytes::serialize(BigIntSer(pledge_delta))?,
TokenAmount::zero(),
Expand Down Expand Up @@ -4554,7 +4555,7 @@ where
let deal_weights = if !pre_commit.info.deal_ids.is_empty() {
// Check (and activate) storage deals associated to sector. Abort if checks failed.
let res = rt.send(
*STORAGE_MARKET_ACTOR_ADDR,
&STORAGE_MARKET_ACTOR_ADDR,
ext::market::ACTIVATE_DEALS_METHOD,
RawBytes::serialize(ext::market::ActivateDealsParams {
deal_ids: pre_commit.info.deal_ids.clone(),
Expand Down
2 changes: 1 addition & 1 deletion actors/multisig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ where
st.check_available(rt.current_balance(), &txn.value, rt.curr_epoch())
.map_err(|e| actor_error!(insufficient_funds, "insufficient funds unlocked: {}", e))?;

match rt.send(txn.to, txn.method, txn.params.clone(), txn.value.clone()) {
match rt.send(&txn.to, txn.method, txn.params.clone(), txn.value.clone()) {
Ok(ser) => {
out = ser;
}
Expand Down
4 changes: 2 additions & 2 deletions actors/paych/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl Actor {
}

if let Some(extra) = &sv.extra {
rt.send(extra.actor, extra.method, extra.data.clone(), TokenAmount::from(0u8))
rt.send(&extra.actor, extra.method, extra.data.clone(), TokenAmount::from(0u8))
.map_err(|e| e.wrap("spend voucher verification failed"))?;
}

Expand Down Expand Up @@ -313,7 +313,7 @@ impl Actor {
}

// send ToSend to `to`
rt.send(st.to, METHOD_SEND, RawBytes::default(), st.to_send)
rt.send(&st.to, METHOD_SEND, RawBytes::default(), st.to_send)
.map_err(|e| e.wrap("Failed to send funds to `to` address"))?;

// the remaining balance will be returned to "From" upon deletion.
Expand Down
10 changes: 5 additions & 5 deletions actors/power/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Actor {
let miner_actor_code_cid = rt.get_code_cid_for_type(Type::Miner);
let ext::init::ExecReturn { id_address, robust_address } = rt
.send(
*INIT_ACTOR_ADDR,
&INIT_ACTOR_ADDR,
ext::init::EXEC_METHOD,
RawBytes::serialize(init::ExecParams {
code_cid: miner_actor_code_cid,
Expand Down Expand Up @@ -253,7 +253,7 @@ impl Actor {

let rewret: ThisEpochRewardReturn = rt
.send(
*REWARD_ACTOR_ADDR,
&REWARD_ACTOR_ADDR,
ext::reward::Method::ThisEpochReward as MethodNum,
RawBytes::default(),
TokenAmount::zero(),
Expand All @@ -279,7 +279,7 @@ impl Actor {

// Update network KPA in reward actor
rt.send(
*REWARD_ACTOR_ADDR,
&REWARD_ACTOR_ADDR,
ext::reward::UPDATE_NETWORK_KPI,
this_epoch_raw_byte_power?,
TokenAmount::from(0_u32),
Expand Down Expand Up @@ -513,7 +513,7 @@ impl Actor {
continue;
}
if let Err(e) = rt.send(
m,
&m,
ext::miner::CONFIRM_SECTOR_PROOFS_VALID_METHOD,
RawBytes::serialize(&ext::miner::ConfirmSectorProofsParams {
sectors: successful,
Expand Down Expand Up @@ -608,7 +608,7 @@ impl Actor {
quality_adj_power_smoothed: st.this_epoch_qa_power_smoothed.clone(),
})?;
let res = rt.send(
event.miner_addr,
&event.miner_addr,
ext::miner::ON_DEFERRED_CRON_EVENT_METHOD,
params,
Default::default(),
Expand Down
4 changes: 2 additions & 2 deletions actors/reward/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl Actor {
// if this fails, we can assume the miner is responsible and avoid failing here.
let reward_params = ext::miner::ApplyRewardParams { reward: total_reward.clone(), penalty };
let res = rt.send(
Address::new_id(miner_id),
&Address::new_id(miner_id),
ext::miner::APPLY_REWARDS_METHOD,
RawBytes::serialize(&reward_params)?,
total_reward.clone(),
Expand All @@ -171,7 +171,7 @@ impl Actor {
e.exit_code()
);
let res =
rt.send(*BURNT_FUNDS_ACTOR_ADDR, METHOD_SEND, RawBytes::default(), total_reward);
rt.send(&BURNT_FUNDS_ACTOR_ADDR, METHOD_SEND, RawBytes::default(), total_reward);
if let Err(e) = res {
error!(
"failed to send unsent reward to the burnt funds actor, code: {:?}",
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/builtin/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ where
}

// send 0 balance to the account so an ID address for it is created and then try to resolve
rt.send(*address, METHOD_SEND, Default::default(), Default::default())
rt.send(address, METHOD_SEND, Default::default(), Default::default())
.map_err(|e| e.wrap(&format!("failed to send zero balance to address {}", address)))?;

if let Some(id) = rt.resolve_address(address) {
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/runtime/fvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ where

fn send(
&self,
to: Address,
to: &Address,
method: MethodNum,
params: RawBytes,
value: TokenAmount,
) -> Result<RawBytes, ActorError> {
if self.in_transaction {
return Err(actor_error!(assertion_failed; "send is not allowed during transaction"));
}
match fvm::send::send(&to, method, params, value) {
match fvm::send::send(to, method, params, value) {
Ok(ret) => {
if ret.exit_code.is_success() {
Ok(ret.return_data)
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub trait Runtime<BS: Blockstore>: Primitives + Verifier + RuntimePolicy {
/// invoking the target actor/method.
fn send(
&self,
to: Address,
to: &Address,
method: MethodNum,
params: RawBytes,
value: TokenAmount,
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ impl Runtime<MemoryBlockstore> for MockRuntime {

fn send(
&self,
to: Address,
to: &Address,
method: MethodNum,
params: RawBytes,
value: TokenAmount,
Expand All @@ -912,7 +912,7 @@ impl Runtime<MemoryBlockstore> for MockRuntime {
let expected_msg = self.expectations.borrow_mut().expect_sends.pop_front().unwrap();

assert!(
expected_msg.to == to
expected_msg.to == *to
&& expected_msg.method == method
&& expected_msg.params == params
&& expected_msg.value == value,
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/util/chaos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Actor {
{
rt.validate_immediate_caller_accept_any()?;

let result = rt.send(arg.to, arg.method, arg.params, arg.value);
let result = rt.send(&arg.to, arg.method, arg.params, arg.value);
if let Err(e) = result {
Ok(SendReturn { return_value: RawBytes::default(), code: e.exit_code() })
} else {
Expand Down
4 changes: 2 additions & 2 deletions test_vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ impl<'invocation, 'bs> Runtime<&'bs MemoryBlockstore> for InvocationCtx<'invocat

fn send(
&self,
to: Address,
to: &Address,
method: MethodNum,
params: RawBytes,
value: TokenAmount,
Expand All @@ -799,7 +799,7 @@ impl<'invocation, 'bs> Runtime<&'bs MemoryBlockstore> for InvocationCtx<'invocat
));
}

let new_actor_msg = InternalMessage { from: self.to(), to, value, method, params };
let new_actor_msg = InternalMessage { from: self.to(), to: *to, value, method, params };
let mut new_ctx = InvocationCtx {
v: self.v,
top: self.top.clone(),
Expand Down

0 comments on commit 63c5033

Please sign in to comment.