-
Notifications
You must be signed in to change notification settings - Fork 182
fix: avoid cloning block headers in validate_block
#6254
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
Conversation
WalkthroughAddress handling is simplified across validation, state RPC, and power actor modules by removing intermediate conversion steps and relying on Into trait implementations instead of explicit conversion function calls. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
| let v_state_manager = state_manager.clone(); | ||
| let v_base_tipset = base_tipset.clone(); | ||
| let v_header = header.clone(); | ||
| let v_block = block.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
block is an Arc pointer while header is a large struct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/shim/address.rs (1)
346-362: Address ↔ Address_v4 conversions are correct; reference From impl is optionalThe owned and borrowed conversions to
Address_v4are correct and zero‑cost since they just expose the inner field. Theimpl<'a> From<&'a Address> for &'a Address_v4is also sound, but givenAddressalready derefs toAddress_v4, that extraFromimpl is mostly redundant and could be dropped to keep the conversion surface simpler if you want to reduce overlap.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/fil_cns/validation.rs(2 hunks)src/rpc/methods/state.rs(1 hunks)src/shim/actors/builtin/power/mod.rs(9 hunks)src/shim/address.rs(1 hunks)src/state_manager/mod.rs(4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: hanabi1224
Repo: ChainSafe/forest PR: 5930
File: build.rs:64-77
Timestamp: 2025-08-13T09:43:20.301Z
Learning: hanabi1224 prefers hard compile-time errors in build scripts rather than runtime safeguards or collision detection, believing it's better to fail fast and fix root causes of issues like malformed snapshot names.
Learnt from: hanabi1224
Repo: ChainSafe/forest PR: 6057
File: src/cli/subcommands/f3_cmd.rs:0-0
Timestamp: 2025-09-09T10:37:17.947Z
Learning: hanabi1224 prefers having default timeouts (like 10m for --no-progress-timeout) to prevent commands from hanging indefinitely, even when the timeout flag isn't explicitly provided by users. This fail-fast approach is preferred over requiring explicit flag usage.
📚 Learning: 2025-09-02T10:05:34.350Z
Learnt from: akaladarshi
Repo: ChainSafe/forest PR: 5923
File: src/rpc/registry/actors/miner.rs:221-223
Timestamp: 2025-09-02T10:05:34.350Z
Learning: For miner actor ChangeOwnerAddress and ChangeOwnerAddressExported methods: versions 8-10 use bare Address as parameter type, while versions 11+ use ChangeOwnerAddressParams. This reflects the evolution of the Filecoin miner actor parameter structures across versions.
Applied to files:
src/shim/actors/builtin/power/mod.rssrc/state_manager/mod.rssrc/fil_cns/validation.rs
🧬 Code graph analysis (1)
src/shim/actors/builtin/power/mod.rs (2)
src/shim/address.rs (15)
new_id(142-144)from(311-313)from(317-319)from(323-325)from(329-331)from(335-337)from(341-343)from(347-349)from(353-355)from(359-361)from(365-371)from(375-377)from(381-387)from(391-393)from(397-401)src/shim/actors/convert.rs (1)
from_policy_v13_to_v9(156-221)
🔇 Additional comments (10)
src/rpc/methods/state.rs (1)
1836-1844: StateListMiners now directly returns miner addresses from power stateUsing
state.list_all_miners(ctx.store())?directly matches theOk = Vec<Address>signature and removes an unnecessary conversion layer; behavior stays the same and is simpler.src/fil_cns/validation.rs (2)
99-110: Miner validation now clones the block Arc instead of the headerCloning
Arc<Block>for the spawned miner validation task avoids cloning the header, keeps lifetimes simple, and is cheap; passing&v_block.header.miner_addressis safe and avoids extra allocations.
223-237: validate_miner correctly uses the new miner_power address APIUsing
miner_addr: &Addressdirectly instate.miner_power(state_manager.blockstore(), miner_addr)aligns with the refactored power state API and removes now‑unnecessary address conversions without changing semantics.src/shim/actors/builtin/power/mod.rs (3)
6-18: Power actor imports and ADDRESS constant are now explicit and consistentPulling in
shim::address::Addressalongside FVM2 TokenAmount/StoragePower and definingADDRESSas the FVM2 power actor ID clarifies the types in play and matches how other modules talk to the power actor.
97-157: list_all_miners now returns shim Addresses uniformly for all versionsFor V12–V17, pushing
addr.into()from the claims map keys into theVec<Address>unifies miner address handling with earlier versions and with RPC/state callers; conversions are centralized via the Address From/Into impls, avoiding bespoke helpers.
223-261: miner_power and nominal power checks consistently take shim::AddressSwitching
miner_powerto accept&Addressand usingminer.into()per actor version, plus passing&miner.into()/miner.id()?inminer_nominal_power_meets_consensus_minimum, removes scattered address-conversion code and keeps all power checks driven by the shim address type, while preserving the underlying actor API expectations.src/state_manager/mod.rs (4)
386-395: is_miner_slashed now uses the shim Address directly for miner_powerCalling
spas.miner_power(self.blockstore(), addr)?.is_none()is consistent with the new power state API and keeps the slashed check’s semantics unchanged.
420-432: get_power uses shim::Address for both miner power and consensus-minimum checkPassing
maddrdirectly intominer_powerandminer_nominal_power_meets_consensus_minimumremoves redundant conversions while keeping the error paths and “has minimum power” behavior identical.
858-865: eligible_to_mine reads miner power via the updated Address-based APIUsing
power_state.miner_power(self.blockstore(), address)?matches the rest of the refactor and still enforces the same non-empty power-claim requirement before further eligibility checks.
1488-1492: miner_get_base_info and miner_has_min_power are aligned with the new power APIBoth the
get_power(&lb_state_root, Some(&addr))?call inminer_get_base_infoandps.miner_nominal_power_meets_consensus_minimum(policy, self.blockstore(), addr)inminer_has_min_powernow use shim::Address consistently, simplifying address handling without changing the underlying power semantics.Also applies to: 1515-1526
Summary of changes
Changes introduced in this pull request:
validate_blockAddress@fvm4 inminer_powerReference issue to close (if applicable)
Closes
Other information and links
Change checklist
Summary by CodeRabbit