Skip to content

Commit

Permalink
[context] tolerate empty candidate name (#4562)
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie authored Feb 24, 2025
1 parent 7c868d1 commit 05e3ac4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 11 additions & 0 deletions action/protocol/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/iotexproject/go-pkgs/hash"
"github.com/iotexproject/iotex-address/address"
"github.com/pkg/errors"

"github.com/iotexproject/iotex-core/v2/action"
"github.com/iotexproject/iotex-core/v2/blockchain/genesis"
"github.com/iotexproject/iotex-core/v2/pkg/log"
)
Expand Down Expand Up @@ -123,6 +125,7 @@ type (
FixUnproductiveDelegates bool
CorrectGasRefund bool
SufficentBalanceGuarantee bool
TolerateEmptyCandidateName bool
SkipSystemActionNonce bool
ValidateSystemAction bool
AllowCorrectChainIDOnly bool
Expand Down Expand Up @@ -280,6 +283,7 @@ func WithFeatureCtx(ctx context.Context) context.Context {
FixUnproductiveDelegates: g.IsOkhotsk(height),
CorrectGasRefund: g.IsOkhotsk(height),
SufficentBalanceGuarantee: g.IsOkhotsk(height),
TolerateEmptyCandidateName: !g.IsPalau(height),
SkipSystemActionNonce: g.IsPalau(height),
ValidateSystemAction: g.IsQuebec(height),
AllowCorrectChainIDOnly: g.IsQuebec(height),
Expand Down Expand Up @@ -307,6 +311,13 @@ func WithFeatureCtx(ctx context.Context) context.Context {
)
}

func (fCtx *FeatureCtx) Tolerate(err error) bool {
if fCtx.TolerateEmptyCandidateName && errors.Cause(err) == action.ErrInvalidCanName {
return true
}
return false
}

// GetFeatureCtx gets FeatureCtx.
func GetFeatureCtx(ctx context.Context) (FeatureCtx, bool) {
fc, ok := ctx.Value(featureContextKey{}).(FeatureCtx)
Expand Down
8 changes: 3 additions & 5 deletions action/protocol/generic_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func (v *GenericValidator) Validate(ctx context.Context, selp *action.SealedEnve
if caller == nil {
return errors.New("failed to get address")
}
if err = selp.Envelope.SanityCheck(); err != nil {
featureCtx := MustGetFeatureCtx(ctx)
if err = selp.Envelope.SanityCheck(); err != nil && !featureCtx.Tolerate(err) {
return err
}
// Reject action if nonce is too low
Expand All @@ -67,10 +68,7 @@ func (v *GenericValidator) Validate(ctx context.Context, selp *action.SealedEnve
return action.ErrSystemActionNonce
}
} else {
var (
nonce uint64
featureCtx = MustGetFeatureCtx(ctx)
)
var nonce uint64
if featureCtx.FixGasAndNonceUpdate || selp.Nonce() != 0 {
confirmedState, err := v.accountState(ctx, v.sr, caller)
if err != nil {
Expand Down

0 comments on commit 05e3ac4

Please sign in to comment.