From 5d4078305acf9b0779a2416e60885ee4d3ccc2ff Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Tue, 24 May 2022 15:22:46 +0800 Subject: [PATCH] Use Correct Math Library (#10742) * use correct math lib * one more case --- beacon-chain/core/validators/BUILD.bazel | 2 +- beacon-chain/core/validators/validator.go | 10 +++++----- time/slots/BUILD.bazel | 2 +- time/slots/slottime.go | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/beacon-chain/core/validators/BUILD.bazel b/beacon-chain/core/validators/BUILD.bazel index c9c5abc2b..c6a4f95a9 100644 --- a/beacon-chain/core/validators/BUILD.bazel +++ b/beacon-chain/core/validators/BUILD.bazel @@ -14,9 +14,9 @@ go_library( "//beacon-chain/state:go_default_library", "//config/params:go_default_library", "//consensus-types/primitives:go_default_library", + "//math:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//time/slots:go_default_library", - "@com_github_ethereum_go_ethereum//common/math:go_default_library", "@com_github_pkg_errors//:go_default_library", ], ) diff --git a/beacon-chain/core/validators/validator.go b/beacon-chain/core/validators/validator.go index 6bb7b6770..8a3a5f917 100644 --- a/beacon-chain/core/validators/validator.go +++ b/beacon-chain/core/validators/validator.go @@ -7,13 +7,13 @@ package validators import ( "context" - "github.com/ethereum/go-ethereum/common/math" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" + mathutil "github.com/prysmaticlabs/prysm/math" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/time/slots" ) @@ -73,10 +73,10 @@ func InitiateValidatorExit(ctx context.Context, s state.BeaconState, idx types.V exitQueueChurn := uint64(0) err = s.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error { if val.ExitEpoch() == exitQueueEpoch { - overflows := false - exitQueueChurn, overflows = math.SafeAdd(exitQueueChurn, 1) - if overflows { - return errors.New("exit queue churn overflows") + var mErr error + exitQueueChurn, mErr = mathutil.Add64(exitQueueChurn, 1) + if mErr != nil { + return mErr } } return nil diff --git a/time/slots/BUILD.bazel b/time/slots/BUILD.bazel index e1f40b15a..26c0a3e92 100644 --- a/time/slots/BUILD.bazel +++ b/time/slots/BUILD.bazel @@ -12,8 +12,8 @@ go_library( deps = [ "//config/params:go_default_library", "//consensus-types/primitives:go_default_library", + "//math:go_default_library", "//time:go_default_library", - "@com_github_ethereum_go_ethereum//common/math:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", ], diff --git a/time/slots/slottime.go b/time/slots/slottime.go index f60496a99..ce7fffb74 100644 --- a/time/slots/slottime.go +++ b/time/slots/slottime.go @@ -5,10 +5,10 @@ import ( "math" "time" - commonMath "github.com/ethereum/go-ethereum/common/math" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/config/params" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" + mathutil "github.com/prysmaticlabs/prysm/math" prysmTime "github.com/prysmaticlabs/prysm/time" ) @@ -222,9 +222,9 @@ func SyncCommitteePeriod(e types.Epoch) uint64 { // SyncCommitteePeriodStartEpoch returns the start epoch of a sync committee period. func SyncCommitteePeriodStartEpoch(e types.Epoch) (types.Epoch, error) { // Overflow is impossible here because of division of `EPOCHS_PER_SYNC_COMMITTEE_PERIOD`. - startEpoch, overflow := commonMath.SafeMul(SyncCommitteePeriod(e), uint64(params.BeaconConfig().EpochsPerSyncCommitteePeriod)) - if overflow { - return 0, errors.New("start epoch calculation overflow") + startEpoch, err := mathutil.Mul64(SyncCommitteePeriod(e), uint64(params.BeaconConfig().EpochsPerSyncCommitteePeriod)) + if err != nil { + return 0, err } return types.Epoch(startEpoch), nil }