From 855d8ba290caa33673606eb20dcebbfec646a27f Mon Sep 17 00:00:00 2001 From: Chen Chen <34592639+envestcc@users.noreply.github.com> Date: Fri, 15 Mar 2024 01:36:19 +0800 Subject: [PATCH] [staking] reject endorse action before HF activated (#4187) --- action/protocol/staking/protocol.go | 4 ++++ action/protocol/staking/validations.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/action/protocol/staking/protocol.go b/action/protocol/staking/protocol.go index ca0808b0f6..dc6891b881 100644 --- a/action/protocol/staking/protocol.go +++ b/action/protocol/staking/protocol.go @@ -469,6 +469,10 @@ func (p *Protocol) Validate(ctx context.Context, act action.Action, sr protocol. return p.validateCandidateRegister(ctx, act) case *action.CandidateUpdate: return p.validateCandidateUpdate(ctx, act) + case *action.CandidateActivate: + return p.validateCandidateActivate(ctx, act) + case *action.CandidateEndorsement: + return p.validateCandidateEndorsement(ctx, act) } return nil } diff --git a/action/protocol/staking/validations.go b/action/protocol/staking/validations.go index 2b0acc41ae..0947dc337f 100644 --- a/action/protocol/staking/validations.go +++ b/action/protocol/staking/validations.go @@ -84,3 +84,17 @@ func (p *Protocol) validateCandidateUpdate(ctx context.Context, act *action.Cand } return nil } + +func (p *Protocol) validateCandidateEndorsement(ctx context.Context, act *action.CandidateEndorsement) error { + if protocol.MustGetFeatureCtx(ctx).DisableDelegateEndorsement { + return errors.Wrap(action.ErrInvalidAct, "candidate endorsement is disabled") + } + return nil +} + +func (p *Protocol) validateCandidateActivate(ctx context.Context, act *action.CandidateActivate) error { + if protocol.MustGetFeatureCtx(ctx).DisableDelegateEndorsement { + return errors.Wrap(action.ErrInvalidAct, "candidate activate is disabled") + } + return nil +}