Skip to content

Commit 0cc2d30

Browse files
envestccclaude
andcommitted
feat(staking): add applyVoterWeightDelta helper for handler hooks (IIP-59)
Defines the single entry point that subsequent handler hooks (PR 2.5) will use to keep the VoterWeightView in sync with on-chain bucket changes. No callers yet — the helper is no-op when the feature flag is off and when delta is zero, so PR 2.5 can wire it next to existing candidate.AddVote / candidate.SubVote sites without first checking the flag. The helper sits next to ensureVoterWeightView so all IIP-59 view-mutation concerns are co-located. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 044dc42 commit 0cc2d30

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

action/protocol/staking/voter_weight_view.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,26 @@ func (p *Protocol) ensureVoterWeightView(ctx context.Context, sm protocol.StateM
105105
return nil
106106
}
107107

108+
// applyVoterWeightDelta is the single entry point every staking handler
109+
// uses to keep the IIP-59 VoterWeightView in sync with on-chain bucket
110+
// changes. It is a no-op when the feature flag has not activated yet (view
111+
// remains nil) and when delta is zero, so callers can wire it next to any
112+
// existing candidate.AddVote / candidate.SubVote site without first
113+
// checking the flag.
114+
//
115+
// candIdentifier must be the candidate's identifier address (not operator)
116+
// — same key the view uses internally. voter is the bucket owner.
117+
func applyVoterWeightDelta(csm CandidateStateManager, candIdentifier address.Address, voter address.Address, delta *big.Int) {
118+
if delta == nil || delta.Sign() == 0 {
119+
return
120+
}
121+
view := csm.DirtyView()
122+
if view == nil || view.voterWeights == nil {
123+
return
124+
}
125+
view.voterWeights.Apply(hash.BytesToHash160(candIdentifier.Bytes()), voter, delta)
126+
}
127+
108128
// readVoterWeightDigest returns the persisted view digest, if present.
109129
func readVoterWeightDigest(sm protocol.StateReader) (hash.Hash256, error) {
110130
d := &voterWeightDigest{}

0 commit comments

Comments
 (0)