feat(global-deployer): gd_init() method - #340
Conversation
|
Warning Review limit reached
Next review available in: 20 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThe PR consolidates GlobalDeployer functionality in ChangesGlobal Deployer modularization
Outlayer event rename
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Sandbox
participant GlobalDeployerContractClient
participant GlobalDeployer
participant State
Sandbox->>GlobalDeployerContractClient: Build approval and deployment actions
GlobalDeployerContractClient->>GlobalDeployer: gd_approve and gd_deploy
GlobalDeployer->>State: Validate and update approval state
GlobalDeployer->>GlobalDeployer: Execute deployment callback
GlobalDeployer->>State: Store deployed hash and clear approval
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
contracts/global-deployer/src/client.rs (2)
38-43: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove the blank line between the doc comment and the struct.
Line 39 separates the doc comment from
GdTransferOwnershipArgs. Keep the doc comment adjacent to the item for consistency withGdApproveArgs.♻️ Proposed change
/// Arguments for [`gd_transfer_ownership()`](GlobalDeployerContract::gd_transfer_ownership) method - #[derive(Serialize, Deserialize)] pub struct GdTransferOwnershipArgs<'a> {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@contracts/global-deployer/src/client.rs` around lines 38 - 43, Remove the blank line between the doc comment and the GdTransferOwnershipArgs declaration, keeping the comment directly adjacent to the struct as done for GdApproveArgs.
11-26: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding a
gd_initbinding.The contract exposes
gd_initas a payable init method. The client omits it, sotests/src/tests/global_deployer/mod.rsline 171 calls it through a rawFunctionCall::new("gd_init")with a string literal. A generated binding removes the string literal and keeps the deposit requirement documented in one place.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@contracts/global-deployer/src/client.rs` around lines 11 - 26, Add a payable gd_init method binding to the GlobalDeployerContract trait alongside the other call methods, matching the contract’s initialization signature and deposit requirement. Update the related test to invoke gd_init through the generated client method instead of a raw FunctionCall string literal.contracts/global-deployer/src/contract.rs (1)
66-85: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument the ownership lock risk and align the terminology.
gd_initsets the owner to the current account ID. If the caller does not transfer ownership in the same receipt and then deletes the access keys, no external account can callgd_approveorgd_transfer_ownership. The account is then permanently locked. The test attests/src/tests/global_deployer/mod.rslines 165-184 performs the transfer and the key deletion in one transaction, so the recommended flow works.State this consequence in the doc comment. Line 66 also says "admin", while the rest of the API uses "owner". Use "owner".
📝 Proposed doc change
- /// Initialize a global deployer on the existing account and set admin to current account ID. + /// Initialize a global deployer on the existing account and set the owner to the current + /// account ID. /// /// It's recommended to call this method in the same receipt right after `UseGlobalContract` action. + /// Transfer the ownership in the same receipt. If the ownership stays with this account and + /// all access keys are deleted, no account can call `gd_approve()` or + /// `gd_transfer_ownership()` anymore. /// Requires exactly 1yN attached.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@contracts/global-deployer/src/contract.rs` around lines 66 - 85, Update the gd_init doc comment to call the initialized account ID the “owner” instead of “admin,” and document that failing to transfer ownership in the same receipt before deleting access keys permanently locks the account because no external account can call gd_approve or gd_transfer_ownership. Preserve the existing recommended same-receipt flow guidance.tests/src/tests/global_deployer/mod.rs (1)
154-226: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winAdd negative coverage for
gd_init.The test covers the success path only.
gd_initcarries two guards that no test exercises:
- The
1yNrequirement, which rejects function-call access keys.- The
#[init]re-initialization guard, which must stop a secondgd_initfrom resetting the owner.Guard 2 is the security-relevant one. A test that calls
gd_initagain after ownership transfer proves that an attacker cannot reclaim ownership.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/src/tests/global_deployer/mod.rs` around lines 154 - 226, Extend test_gd_init with negative coverage for both gd_init guards: attempt initialization using a function-call access key and assert rejection, then invoke gd_init a second time after gd_transfer_ownership and assert it fails while gd_owner_id remains the original root account. Reuse the existing DeployerEnv setup and transaction helpers, preserving the current successful initialization and deployment assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@contracts/global-deployer/src/lib.rs`:
- Around line 5-6: Update the public documentation references in state.rs,
error.rs, and events.rs that link to crate::contract::GlobalDeployer, replacing
them with conditional links or plain code text so documentation resolves when
near-contract is disabled. Leave the contract module gating unchanged.
In `@contracts/global-deployer/src/state.rs`:
- Line 85: Update the digest-gated doctest import near the cfg(feature =
"digest") section to import State from the public defuse_global_deployer crate
instead of defuse_global_deployer_core, ensuring the example resolves within the
consolidated crate.
---
Nitpick comments:
In `@contracts/global-deployer/src/client.rs`:
- Around line 38-43: Remove the blank line between the doc comment and the
GdTransferOwnershipArgs declaration, keeping the comment directly adjacent to
the struct as done for GdApproveArgs.
- Around line 11-26: Add a payable gd_init method binding to the
GlobalDeployerContract trait alongside the other call methods, matching the
contract’s initialization signature and deposit requirement. Update the related
test to invoke gd_init through the generated client method instead of a raw
FunctionCall string literal.
In `@contracts/global-deployer/src/contract.rs`:
- Around line 66-85: Update the gd_init doc comment to call the initialized
account ID the “owner” instead of “admin,” and document that failing to transfer
ownership in the same receipt before deleting access keys permanently locks the
account because no external account can call gd_approve or
gd_transfer_ownership. Preserve the existing recommended same-receipt flow
guidance.
In `@tests/src/tests/global_deployer/mod.rs`:
- Around line 154-226: Extend test_gd_init with negative coverage for both
gd_init guards: attempt initialization using a function-call access key and
assert rejection, then invoke gd_init a second time after gd_transfer_ownership
and assert it fails while gd_owner_id remains the original root account. Reuse
the existing DeployerEnv setup and transaction helpers, preserving the current
successful initialization and deployment assertions.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: f68e7cde-cd0d-4dd8-8b57-7a6a50e320c3
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (17)
Cargo.tomlcontracts/global-deployer/Cargo.tomlcontracts/global-deployer/near-gds/Cargo.tomlcontracts/global-deployer/near-gds/src/main.rscontracts/global-deployer/src/client.rscontracts/global-deployer/src/contract.rscontracts/global-deployer/src/error.rscontracts/global-deployer/src/events.rscontracts/global-deployer/src/lib.rscontracts/global-deployer/src/state.rscontracts/outlayer/app/src/contract.rscontracts/outlayer/app/src/events.rscrates/global-deployer/core/Cargo.tomlcrates/testing/sandbox/Cargo.tomlcrates/testing/sandbox/src/extensions/global_deployer.rstests/src/tests/global_deployer/mod.rstests/src/tests/outlayer_app/mod.rs
💤 Files with no reviewable changes (1)
- crates/global-deployer/core/Cargo.toml
Summary by CodeRabbit
New Features
Improvements
OaEvent.Bug Fixes