Skip to content

docs: clarify validator drain runbook#212

Open
dongcool wants to merge 2 commits into
mainfrom
docs/drain-runbook-sync
Open

docs: clarify validator drain runbook#212
dongcool wants to merge 2 commits into
mainfrom
docs/drain-runbook-sync

Conversation

@dongcool
Copy link
Copy Markdown
Collaborator

@dongcool dongcool commented May 8, 2026

Summary

This PR updates the validator drain documentation to make the operational runbook explicit.

Problem

The existing drain instructions described the basic drain-unstake / drain-withdraw flow, but they did not clearly require syncing validator accounting
with the staking pool before selecting the drain amount. They also did not mention the base_stake_amount = 0 precondition that the contract enforces.

Update

The drain runbook now documents the required sequence:

  • Set validator weight to 0.
  • Set validator base stake amount to 0.
  • Run epoch_update_rewards before drain and wait for the callback to succeed.
  • Run sync_balance_from_validator and wait for the callback to succeed.
  • Settle any meaningful unstaked balance before drain-unstake.
  • Verify the relevant get_validator fields before drain-unstake and before drain-withdraw.

Summary by CodeRabbit

  • Documentation
    • Expanded "Manage → Drain" into a detailed step-by-step procedure: frames Drain as a manager operation, requires selecting drain amounts from up-to-date balances, handles callback failure/retry before proceeding, settles unstaked balances once thresholds are met, verifies validator state before unstaking and again after 4 epochs, and clarifies how drained funds are restarted into epoch stake requests for restaking.

Review Change Stack

@linguists
Copy link
Copy Markdown
Collaborator

linguists commented May 11, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

📝 Walkthrough

Walkthrough

The README.md "Manage → Drain" section is expanded from a brief 4-step outline into a comprehensive drain procedure. The documentation now details setting validator weight/base stake to zero, syncing validator accounting with explicit failure-retry behavior, verifying intermediate validator state before and after drain-unstake, settling unstaked balances, and how drain-withdraw restarts drained funds into epoch stake requests.

Changes

Drain Procedure Documentation

Layer / File(s) Summary
Drain Procedure Documentation
README.md
The "Manage → Drain" section is expanded with detailed step-by-step drain procedure, including requirements to sync validator accounting with retry behavior on callback failures, verification checklists for validator state (weights, base stake, pending release, draining flags, unstaked thresholds) before unstaking and again after 4 epochs, conditional epoch_withdraw of unstaked balances when threshold met with re-sync, and clarification that drain-withdraw re-adds drained funds to epoch stake requests for restaking.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I trim the weight, I count each score,
I wait four sleeps and check once more.
Sync, withdraw, then send anew—
A rabbit hums as stakes accrue. 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'docs: clarify validator drain runbook' directly and specifically summarizes the main change: expanding and clarifying the validator drain documentation in the README.md file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/drain-runbook-sync

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
README.md (1)

99-100: ⚡ Quick win

Make the unstaked settlement threshold explicit in protocol units.

Using “>= 1 NEAR” is readable, but runbooks are safer when they specify the exact comparison basis (human-readable NEAR vs on-chain yoctoNEAR) and why this threshold is chosen. A short note here would reduce operator ambiguity.

🤖 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 `@README.md` around lines 99 - 100, Clarify the unstaked settlement threshold
by specifying the on-chain units and rationale: update the sentence referencing
get_validator and unstaked_amount to use an explicit yoctoNEAR comparison (e.g.,
"unstaked_amount >= 1 NEAR (>= 1_000_000_000_000_000_000_000_000 yoctoNEAR)")
and add a short parenthetical explaining the basis for choosing 1 NEAR (e.g.,
minimum operator cost/rounding safety), so operators know the exact on-chain
comparison and why epoch_withdraw should be called.
🤖 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 `@README.md`:
- Line 110: The instruction "After 4 epochs, verify `get_validator` again" is
ambiguous; change it to a specific anchor such as "4 full epochs after the
successful `drain-unstake` callback has been confirmed on-chain (i.e., after the
`drain-unstake` transaction finalization)". Update the README step to explicitly
state "4 full epochs after successful `drain-unstake` callback confirmation" so
readers know to wait for transaction finalization and the callback success
before calling `get_validator` or attempting withdrawals.

---

Nitpick comments:
In `@README.md`:
- Around line 99-100: Clarify the unstaked settlement threshold by specifying
the on-chain units and rationale: update the sentence referencing get_validator
and unstaked_amount to use an explicit yoctoNEAR comparison (e.g.,
"unstaked_amount >= 1 NEAR (>= 1_000_000_000_000_000_000_000_000 yoctoNEAR)")
and add a short parenthetical explaining the basis for choosing 1 NEAR (e.g.,
minimum operator cost/rounding safety), so operators know the exact on-chain
comparison and why epoch_withdraw should be called.
🪄 Autofix (Beta)

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

Run ID: 165802ce-4178-48c8-b683-324f01f44cec

📥 Commits

Reviewing files that changed from the base of the PR and between 7620e4e and 32c774c.

📒 Files selected for processing (1)
  • README.md

Comment thread README.md Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
README.md (1)

105-111: 💤 Low value

Consider rephrasing for better readability.

The verification checklist items all follow the pattern "field is value", which is clear but slightly repetitive. Consider introducing the list with a phrase like "Verify the following fields:" and then using a more concise format.

📝 Alternative phrasing
-4. Verify `get_validator` before `drain-unstake`:
-   - `weight` is `0`.
-   - `base_stake_amount` is `0`.
-   - `pending_release` is `false`.
-   - `unstaked_amount` is less than `1 NEAR`
-     (`1_000_000_000_000_000_000_000_000 yoctoNEAR`).
-   - `draining` is `false`.
+4. Verify `get_validator` returns the following before `drain-unstake`:
+   - `weight`: `0`
+   - `base_stake_amount`: `0`
+   - `pending_release`: `false`
+   - `unstaked_amount`: less than `1 NEAR`
+     (`1_000_000_000_000_000_000_000_000 yoctoNEAR`)
+   - `draining`: `false`
🤖 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 `@README.md` around lines 105 - 111, Update the README section that instructs
to "Verify `get_validator` before `drain-unstake`" by introducing a short header
like "Verify the following fields via get_validator before running
drain-unstake:" and convert the repetitive sentences into a compact checklist
(e.g., "weight: 0", "base_stake_amount: 0", "pending_release: false",
"unstaked_amount: < 1 NEAR (1_000_000_000_000_000_000_000_000 yoctoNEAR)",
"draining: false") so the same information remains but reads more concisely and
consistently.
🤖 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 `@README.md`:
- Around line 113-114: Clarify the epoch counting by anchoring it explicitly to
the callback success of the drain-unstake transaction: update the sentence
referencing "4 full epochs have passed since the `drain-unstake` transaction
finalized and its callback succeeded" to state that you must first wait for the
`drain-unstake` transaction's callback to succeed, then count 4 complete epochs
from the moment the callback succeeded, and only after those 4 full epochs run
the `get_validator` verification; reference the `drain-unstake` transaction and
the `get_validator` check to make the sequence unambiguous.

---

Nitpick comments:
In `@README.md`:
- Around line 105-111: Update the README section that instructs to "Verify
`get_validator` before `drain-unstake`" by introducing a short header like
"Verify the following fields via get_validator before running drain-unstake:"
and convert the repetitive sentences into a compact checklist (e.g., "weight:
0", "base_stake_amount: 0", "pending_release: false", "unstaked_amount: < 1 NEAR
(1_000_000_000_000_000_000_000_000 yoctoNEAR)", "draining: false") so the same
information remains but reads more concisely and consistently.
🪄 Autofix (Beta)

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

Run ID: 02135f92-223d-4eae-b3ae-e83a6da97644

📥 Commits

Reviewing files that changed from the base of the PR and between 32c774c and fdb0fd5.

📒 Files selected for processing (1)
  • README.md

Comment thread README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants