Skip to content

Commit 0408a41

Browse files
Stebalienmriise
andcommitted
feat: use consts for addrs (#660)
* feat: use consts for addrs And expose actor IDs so we don't need to call `.id().unwrap()` to retrieve them. Co-authored-by: mriise <[email protected]>
1 parent f9a1713 commit 0408a41

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+391
-390
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actors/account/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Actor {
4040
BS: Blockstore,
4141
RT: Runtime<BS>,
4242
{
43-
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
43+
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
4444
match address.protocol() {
4545
Protocol::Secp256k1 | Protocol::BLS => {}
4646
protocol => {

actors/account/tests/account_actor_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ macro_rules! account_tests {
2727
caller_type: SYSTEM_ACTOR_CODE_ID.clone(),
2828
..Default::default()
2929
};
30-
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
30+
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
3131

3232
if exit_code.is_success() {
3333
rt.call::<AccountActor>(1, &RawBytes::serialize(addr).unwrap()).unwrap();

actors/cron/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Actor {
4747
BS: Blockstore,
4848
RT: Runtime<BS>,
4949
{
50-
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
50+
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
5151
rt.create(&State { entries: params.entries })?;
5252
Ok(())
5353
}
@@ -59,7 +59,7 @@ impl Actor {
5959
BS: Blockstore,
6060
RT: Runtime<BS>,
6161
{
62-
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
62+
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
6363

6464
let st: State = rt.state()?;
6565
for entry in st.entries {

actors/cron/tests/cron_actor_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn check_state(rt: &MockRuntime) {
1919
fn construct_runtime() -> MockRuntime {
2020
MockRuntime {
2121
receiver: Address::new_id(100),
22-
caller: *SYSTEM_ACTOR_ADDR,
22+
caller: SYSTEM_ACTOR_ADDR,
2323
caller_type: *SYSTEM_ACTOR_CODE_ID,
2424
..Default::default()
2525
}
@@ -114,14 +114,14 @@ fn epoch_tick_with_entries() {
114114
}
115115

116116
fn construct_and_verify(rt: &mut MockRuntime, params: &ConstructorParams) {
117-
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
117+
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
118118
let ret = rt.call::<CronActor>(1, &RawBytes::serialize(&params).unwrap()).unwrap();
119119
assert_eq!(RawBytes::default(), ret);
120120
rt.verify();
121121
}
122122

123123
fn epoch_tick_and_verify(rt: &mut MockRuntime) {
124-
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
124+
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
125125
let ret = rt.call::<CronActor>(2, &RawBytes::default()).unwrap();
126126
assert_eq!(RawBytes::default(), ret);
127127
rt.verify();

actors/init/tests/init_actor_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn check_state(rt: &MockRuntime) {
2727
fn construct_runtime() -> MockRuntime {
2828
MockRuntime {
2929
receiver: Address::new_id(1000),
30-
caller: *SYSTEM_ACTOR_ADDR,
30+
caller: SYSTEM_ACTOR_ADDR,
3131
caller_type: *SYSTEM_ACTOR_CODE_ID,
3232
..Default::default()
3333
}
@@ -163,7 +163,7 @@ fn create_storage_miner() {
163163
construct_and_verify(&mut rt);
164164

165165
// only the storage power actor can create a miner
166-
rt.set_caller(*POWER_ACTOR_CODE_ID, *STORAGE_POWER_ACTOR_ADDR);
166+
rt.set_caller(*POWER_ACTOR_CODE_ID, STORAGE_POWER_ACTOR_ADDR);
167167

168168
let unique_address = Address::new_actor(b"miner");
169169
rt.new_actor_addr = Some(unique_address);
@@ -248,7 +248,7 @@ fn sending_constructor_failure() {
248248
construct_and_verify(&mut rt);
249249

250250
// Only the storage power actor can create a miner
251-
rt.set_caller(*POWER_ACTOR_CODE_ID, *STORAGE_POWER_ACTOR_ADDR);
251+
rt.set_caller(*POWER_ACTOR_CODE_ID, STORAGE_POWER_ACTOR_ADDR);
252252

253253
// Assign new address for the storage actor miner
254254
let unique_address = Address::new_actor(b"miner");
@@ -288,7 +288,7 @@ fn sending_constructor_failure() {
288288
}
289289

290290
fn construct_and_verify(rt: &mut MockRuntime) {
291-
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
291+
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
292292
let params = ConstructorParams { network_name: "mock".to_string() };
293293
let ret =
294294
rt.call::<InitActor>(METHOD_CONSTRUCTOR, &RawBytes::serialize(&params).unwrap()).unwrap();

actors/market/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl Actor {
9797
BS: Blockstore,
9898
RT: Runtime<BS>,
9999
{
100-
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
100+
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
101101

102102
let st = State::new(rt.store()).map_err(|e| {
103103
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "Failed to create market state")
@@ -762,7 +762,7 @@ impl Actor {
762762
BS: Blockstore,
763763
RT: Runtime<BS>,
764764
{
765-
rt.validate_immediate_caller_is(std::iter::once(&*CRON_ACTOR_ADDR))?;
765+
rt.validate_immediate_caller_is(std::iter::once(&CRON_ACTOR_ADDR))?;
766766

767767
let mut amount_slashed = TokenAmount::zero();
768768
let curr_epoch = rt.curr_epoch();

actors/market/tests/cron_tick_deal_slashing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn slash_multiple_deals_in_the_same_epoch() {
238238
+ &deal_proposal2.provider_collateral
239239
+ &deal_proposal3.provider_collateral;
240240
rt.expect_send(
241-
*BURNT_FUNDS_ACTOR_ADDR,
241+
BURNT_FUNDS_ACTOR_ADDR,
242242
METHOD_SEND,
243243
RawBytes::default(),
244244
total_slashed,

actors/market/tests/cron_tick_timedout_deals.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn timed_out_deal_is_slashed_and_deleted() {
4141
// do a cron tick for it -> should time out and get slashed
4242
rt.set_epoch(process_epoch(START_EPOCH, deal_id));
4343
rt.expect_send(
44-
*BURNT_FUNDS_ACTOR_ADDR,
44+
BURNT_FUNDS_ACTOR_ADDR,
4545
METHOD_SEND,
4646
RawBytes::default(),
4747
deal_proposal.provider_collateral.clone(),
@@ -105,7 +105,7 @@ fn publishing_timed_out_deal_again_should_work_after_cron_tick_as_it_should_no_l
105105
// do a cron tick for it -> should time out and get slashed
106106
rt.set_epoch(process_epoch(START_EPOCH, deal_id));
107107
rt.expect_send(
108-
*BURNT_FUNDS_ACTOR_ADDR,
108+
BURNT_FUNDS_ACTOR_ADDR,
109109
METHOD_SEND,
110110
RawBytes::default(),
111111
deal_proposal.provider_collateral.clone(),
@@ -178,15 +178,15 @@ fn timed_out_and_verified_deals_are_slashed_deleted_and_sent_to_the_registry_act
178178
};
179179

180180
rt.expect_send(
181-
*VERIFIED_REGISTRY_ACTOR_ADDR,
181+
VERIFIED_REGISTRY_ACTOR_ADDR,
182182
ext::verifreg::RESTORE_BYTES_METHOD as u64,
183183
RawBytes::serialize(param1).unwrap(),
184184
TokenAmount::zero(),
185185
RawBytes::default(),
186186
ExitCode::OK,
187187
);
188188
rt.expect_send(
189-
*VERIFIED_REGISTRY_ACTOR_ADDR,
189+
VERIFIED_REGISTRY_ACTOR_ADDR,
190190
ext::verifreg::RESTORE_BYTES_METHOD as u64,
191191
RawBytes::serialize(param2).unwrap(),
192192
TokenAmount::zero(),
@@ -196,7 +196,7 @@ fn timed_out_and_verified_deals_are_slashed_deleted_and_sent_to_the_registry_act
196196

197197
let expected_burn = 3 * &deal1.provider_collateral;
198198
rt.expect_send(
199-
*BURNT_FUNDS_ACTOR_ADDR,
199+
BURNT_FUNDS_ACTOR_ADDR,
200200
METHOD_SEND,
201201
RawBytes::default(),
202202
expected_burn,

actors/market/tests/harness.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ pub fn setup() -> MockRuntime {
7979
]);
8080

8181
let mut rt = MockRuntime {
82-
receiver: *STORAGE_MARKET_ACTOR_ADDR,
83-
caller: *SYSTEM_ACTOR_ADDR,
82+
receiver: STORAGE_MARKET_ACTOR_ADDR,
83+
caller: SYSTEM_ACTOR_ADDR,
8484
caller_type: *INIT_ACTOR_CODE_ID,
8585
actor_code_cids,
8686
balance: RefCell::new(TokenAmount::from_whole(10)),
@@ -107,7 +107,7 @@ pub fn check_state_with_expected(rt: &MockRuntime, expected_patterns: &[Regex])
107107
acc.assert_expected(expected_patterns);
108108
}
109109
pub fn construct_and_verify(rt: &mut MockRuntime) {
110-
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
110+
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
111111
assert_eq!(
112112
RawBytes::default(),
113113
rt.call::<MarketActor>(METHOD_CONSTRUCTOR, &RawBytes::default()).unwrap()
@@ -362,7 +362,7 @@ pub fn cron_tick_and_assert_balances(
362362
let mut payment_end = d.end_epoch;
363363
if s.slash_epoch != EPOCH_UNDEFINED {
364364
rt.expect_send(
365-
*BURNT_FUNDS_ACTOR_ADDR,
365+
BURNT_FUNDS_ACTOR_ADDR,
366366
METHOD_SEND,
367367
RawBytes::default(),
368368
d.provider_collateral.clone(),
@@ -477,7 +477,7 @@ pub fn publish_deals(
477477
.unwrap();
478478

479479
rt.expect_send(
480-
*VERIFIED_REGISTRY_ACTOR_ADDR,
480+
VERIFIED_REGISTRY_ACTOR_ADDR,
481481
ext::verifreg::USE_BYTES_METHOD as u64,
482482
param,
483483
TokenAmount::zero(),
@@ -568,8 +568,8 @@ pub fn cron_tick(rt: &mut MockRuntime) {
568568
}
569569

570570
pub fn cron_tick_raw(rt: &mut MockRuntime) -> Result<RawBytes, ActorError> {
571-
rt.expect_validate_caller_addr(vec![*CRON_ACTOR_ADDR]);
572-
rt.set_caller(*CRON_ACTOR_CODE_ID, *CRON_ACTOR_ADDR);
571+
rt.expect_validate_caller_addr(vec![CRON_ACTOR_ADDR]);
572+
rt.set_caller(*CRON_ACTOR_CODE_ID, CRON_ACTOR_ADDR);
573573

574574
rt.call::<MarketActor>(Method::CronTick as u64, &RawBytes::default())
575575
}
@@ -592,15 +592,15 @@ pub fn expect_query_network_info(rt: &mut MockRuntime) {
592592
this_epoch_reward_smoothed: epoch_reward_smooth,
593593
};
594594
rt.expect_send(
595-
*REWARD_ACTOR_ADDR,
595+
REWARD_ACTOR_ADDR,
596596
RewardMethod::ThisEpochReward as u64,
597597
RawBytes::default(),
598598
TokenAmount::zero(),
599599
RawBytes::serialize(current_reward).unwrap(),
600600
ExitCode::OK,
601601
);
602602
rt.expect_send(
603-
*STORAGE_POWER_ACTOR_ADDR,
603+
STORAGE_POWER_ACTOR_ADDR,
604604
PowerMethod::CurrentTotalPower as u64,
605605
RawBytes::default(),
606606
TokenAmount::zero(),

actors/market/tests/market_actor_test.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ fn test_remove_all_error() {
5151
fn simple_construction() {
5252
let mut rt = MockRuntime {
5353
receiver: Address::new_id(100),
54-
caller: *SYSTEM_ACTOR_ADDR,
54+
caller: SYSTEM_ACTOR_ADDR,
5555
caller_type: *INIT_ACTOR_CODE_ID,
5656
..Default::default()
5757
};
5858

59-
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
59+
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
6060

6161
assert_eq!(
6262
RawBytes::default(),
@@ -793,7 +793,7 @@ fn provider_and_client_addresses_are_resolved_before_persisting_state_and_sent_t
793793
.unwrap();
794794

795795
rt.expect_send(
796-
*VERIFIED_REGISTRY_ACTOR_ADDR,
796+
VERIFIED_REGISTRY_ACTOR_ADDR,
797797
ext::verifreg::USE_BYTES_METHOD as u64,
798798
param,
799799
TokenAmount::zero(),
@@ -1239,7 +1239,7 @@ fn slash_a_deal_and_make_payment_for_another_deal_in_the_same_epoch() {
12391239

12401240
// cron tick will slash deal1 and make payment for deal2
12411241
rt.expect_send(
1242-
*BURNT_FUNDS_ACTOR_ADDR,
1242+
BURNT_FUNDS_ACTOR_ADDR,
12431243
METHOD_SEND,
12441244
RawBytes::default(),
12451245
d1.provider_collateral.clone(),
@@ -1472,7 +1472,7 @@ fn locked_fund_tracking_states() {
14721472
let curr = process_epoch(start_epoch, deal_id3);
14731473
rt.set_epoch(curr);
14741474
rt.expect_send(
1475-
*BURNT_FUNDS_ACTOR_ADDR,
1475+
BURNT_FUNDS_ACTOR_ADDR,
14761476
METHOD_SEND,
14771477
RawBytes::default(),
14781478
d3.provider_collateral.clone(),
@@ -1513,7 +1513,7 @@ fn locked_fund_tracking_states() {
15131513
clc = TokenAmount::zero();
15141514
plc = TokenAmount::zero();
15151515
rt.expect_send(
1516-
*BURNT_FUNDS_ACTOR_ADDR,
1516+
BURNT_FUNDS_ACTOR_ADDR,
15171517
METHOD_SEND,
15181518
RawBytes::default(),
15191519
d1.provider_collateral,

actors/market/tests/random_cron_epoch_during_publish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn cron_processing_of_deal_after_missed_activation_should_fail_and_slash() {
177177

178178
// FIXME: cron_tick calls 'VERIFIED_REGISTRY_ACTOR_ADDR' with the 'USE_BYTES_METHOD' method.
179179
rt.expect_send(
180-
*BURNT_FUNDS_ACTOR_ADDR,
180+
BURNT_FUNDS_ACTOR_ADDR,
181181
METHOD_SEND,
182182
RawBytes::default(),
183183
deal_proposal.provider_collateral.clone(),

actors/miner/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl Actor {
130130
BS: Blockstore,
131131
RT: Runtime<BS>,
132132
{
133-
rt.validate_immediate_caller_is(&[*INIT_ACTOR_ADDR])?;
133+
rt.validate_immediate_caller_is(std::iter::once(&INIT_ACTOR_ADDR))?;
134134

135135
check_control_addresses(rt.policy(), &params.control_addresses)?;
136136
check_peer_info(rt.policy(), &params.peer_id, &params.multi_addresses)?;
@@ -1880,7 +1880,7 @@ impl Actor {
18801880
BS: Blockstore,
18811881
RT: Runtime<BS>,
18821882
{
1883-
rt.validate_immediate_caller_is(iter::once(&*STORAGE_POWER_ACTOR_ADDR))?;
1883+
rt.validate_immediate_caller_is(iter::once(&STORAGE_POWER_ACTOR_ADDR))?;
18841884

18851885
// This should be enforced by the power actor. We log here just in case
18861886
// something goes wrong.
@@ -2902,7 +2902,7 @@ impl Actor {
29022902
let (pledge_delta_total, to_burn) = rt.transaction(|st: &mut State, rt| {
29032903
let mut pledge_delta_total = TokenAmount::zero();
29042904

2905-
rt.validate_immediate_caller_is(std::iter::once(&*REWARD_ACTOR_ADDR))?;
2905+
rt.validate_immediate_caller_is(std::iter::once(&REWARD_ACTOR_ADDR))?;
29062906

29072907
let (reward_to_lock, locked_reward_vesting_spec) =
29082908
locked_reward_from_reward(params.reward);
@@ -3196,7 +3196,7 @@ impl Actor {
31963196
BS: Blockstore,
31973197
RT: Runtime<BS>,
31983198
{
3199-
rt.validate_immediate_caller_is(std::iter::once(&*STORAGE_POWER_ACTOR_ADDR))?;
3199+
rt.validate_immediate_caller_is(std::iter::once(&STORAGE_POWER_ACTOR_ADDR))?;
32003200

32013201
let payload: CronEventPayload = from_slice(&params.event_payload).map_err(|e| {
32023202
actor_error!(
@@ -3767,7 +3767,7 @@ where
37673767
}
37683768
let ret: ext::market::ComputeDataCommitmentReturn = rt
37693769
.send(
3770-
&*STORAGE_MARKET_ACTOR_ADDR,
3770+
&STORAGE_MARKET_ACTOR_ADDR,
37713771
ext::market::COMPUTE_DATA_COMMITMENT_METHOD,
37723772
RawBytes::serialize(ext::market::ComputeDataCommitmentParamsRef {
37733773
inputs: data_commitment_inputs,

0 commit comments

Comments
 (0)