Skip to content

refactor(params,common/countdown): consolidate exp-timeout validation rules #2877

Open

Description

@gzliudan

Summary

The XDPoS v2 exponential-timeout rules are validated in two places that duplicate the same domain rules in two formulas and two numeric domains:

  • params/config_backfill.go validateV2ExpTimeoutConfig (chain-config/genesis path): checks MaxExponent >= 32 against a literal 32, base^max_exponent >= 2^32, and — since fix(common/countdown,params): correct the exponential timeout arithmetic and validate its bounds #2836 — timeout_period * base^max_exponent against the time.Duration range using a float computation.
  • common/countdown/exp_duration.go sanityCheck (runtime path, called from NewExpTimeoutDuration and SetParams): checks the same maxExponent and base^maxExponent rules against the maxExponentUpperbound constant, while GetTimeoutDuration saturates the product at math.MaxInt64 with integer arithmetic.

Future edits risk changing one side and missing the other. #2836 extended this pre-existing duplication by adding the duration-range rule on both sides in two idioms; it kept the duplication deliberately, per the minimal-change policy for that fix.

Proposal

Consolidate the rules in common/countdown — e.g. export a validation function covering the maxExponent upper bound, the base^maxExponent bound and the duration * base^maxExponent duration-range bound — and have validateV2ExpTimeoutConfig call it, keeping the params-side fieldPath error formatting.

Notes

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions