Skip to content

Comments

Move validator metadata DB writes into validatorState#5008

Open
DracoLi wants to merge 1 commit intomasterfrom
dl/pchain-validator-write
Open

Move validator metadata DB writes into validatorState#5008
DracoLi wants to merge 1 commit intomasterfrom
dl/pchain-validator-write

Conversation

@DracoLi
Copy link
Contributor

@DracoLi DracoLi commented Feb 19, 2026

Why this should be merged

Validator metadata DB writes (puts and deletes) were split between writeCurrentStakers and WriteValidatorMetadata, making the mutation logic harder to follow. This consolidates all DB writes into validatorState, so writeCurrentStakers first stages changes and WriteValidatorMetadata handles all persistence in one place.

How this works

Add AddValidatorMetadata to the validatorState interface, which registers new metadata and marks it dirty for the next write. DeleteValidatorMetadata now also tracks pending deletes. WriteValidatorMetadata processes deletes before puts and accepts KeyValueWriterDeleter instead of KeyValueWriter.

How this was tested

New unit tests

Need to be documented in RELEASES.md?

No

…rState

- Add AddValidatorMetadata to register and mark new entries for writing
- Track pending deletes in DeleteValidatorMetadata for batch processing
- Remove direct DB writes from writeCurrentStakers
@DracoLi DracoLi force-pushed the dl/pchain-validator-write branch from 96a1cda to fe7d4cc Compare February 20, 2026 16:46
@DracoLi DracoLi marked this pull request as ready for review February 20, 2026 18:42
@DracoLi DracoLi requested a review from a team as a code owner February 20, 2026 18:42
Copilot AI review requested due to automatic review settings February 20, 2026 18:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors validator metadata database operations to consolidate all writes within the validatorState interface, improving code organization and separation of concerns. Previously, metadata DB writes were split between writeCurrentStakers and WriteValidatorMetadata, making the flow harder to follow.

Changes:

  • Added AddValidatorMetadata method to stage new validator metadata for persistence
  • Enhanced DeleteValidatorMetadata to track pending delete operations
  • Moved all metadata DB write logic into WriteValidatorMetadata, which now processes deletes before puts
  • Updated WriteValidatorMetadata to accept KeyValueWriterDeleter instead of KeyValueWriter to support delete operations

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
vms/platformvm/state/state.go Refactored writeCurrentStakers to use AddValidatorMetadata for adds and moved WriteValidatorMetadata call to the end of the function; removed direct DB operations
vms/platformvm/state/metadata_validator.go Added AddValidatorMetadata method, updated DeleteValidatorMetadata to track pending deletes, and enhanced WriteValidatorMetadata to process all DB operations (deletes first, then puts)
vms/platformvm/state/metadata_validator_test.go Added comprehensive tests for the new AddValidatorMetadata method and various delete scenarios (delete after write, add-then-delete, delete-then-re-add)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant