From 7dadc780b81535d082ac768871e3d59646e6f031 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Fri, 17 Sep 2021 16:55:24 -0500 Subject: [PATCH] Move Shared Packages into Math/ and IO/ (#9622) * amend * building * build * userprompt * imports * build val * gaz * io file Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> --- beacon-chain/cache/BUILD.bazel | 2 +- beacon-chain/cache/committee.go | 4 +- beacon-chain/core/altair/BUILD.bazel | 4 +- beacon-chain/core/altair/attestation_test.go | 6 +- beacon-chain/core/altair/epoch_precompute.go | 4 +- beacon-chain/core/altair/reward.go | 4 +- beacon-chain/core/altair/sync_committee.go | 4 +- beacon-chain/core/blocks/BUILD.bazel | 2 +- beacon-chain/core/blocks/deposit.go | 4 +- beacon-chain/core/epoch/BUILD.bazel | 2 +- beacon-chain/core/epoch/epoch_processing.go | 4 +- .../core/epoch/precompute/BUILD.bazel | 4 +- .../core/epoch/precompute/reward_penalty.go | 6 +- .../epoch/precompute/reward_penalty_test.go | 6 +- .../core/epoch/precompute/slashing.go | 4 +- beacon-chain/core/helpers/BUILD.bazel | 2 +- beacon-chain/core/helpers/beacon_committee.go | 4 +- .../core/helpers/weak_subjectivity.go | 4 +- beacon-chain/core/transition/BUILD.bazel | 2 +- .../core/transition/interop/BUILD.bazel | 2 +- .../transition/interop/write_block_to_disk.go | 4 +- .../transition/interop/write_state_to_disk.go | 4 +- beacon-chain/core/transition/transition.go | 4 +- beacon-chain/db/BUILD.bazel | 4 +- beacon-chain/db/kv/BUILD.bazel | 2 +- beacon-chain/db/kv/backup.go | 6 +- beacon-chain/db/kv/kv.go | 6 +- beacon-chain/db/restore.go | 14 ++-- beacon-chain/db/slasherkv/BUILD.bazel | 2 +- beacon-chain/db/slasherkv/kv.go | 6 +- beacon-chain/p2p/BUILD.bazel | 2 +- beacon-chain/p2p/utils.go | 4 +- beacon-chain/powchain/BUILD.bazel | 2 +- beacon-chain/powchain/service.go | 10 +-- beacon-chain/rpc/BUILD.bazel | 2 +- .../rpc/prysm/v1alpha1/node/BUILD.bazel | 2 +- .../rpc/prysm/v1alpha1/node/server.go | 4 +- beacon-chain/rpc/service.go | 4 +- beacon-chain/sync/initial-sync/BUILD.bazel | 2 +- .../sync/initial-sync/blocks_fetcher_peers.go | 2 +- cmd/beacon-chain/BUILD.bazel | 4 +- cmd/beacon-chain/main.go | 8 +-- cmd/client-stats/BUILD.bazel | 2 +- cmd/client-stats/main.go | 4 +- cmd/validator/BUILD.bazel | 4 +- cmd/validator/flags/BUILD.bazel | 2 +- cmd/validator/flags/flags.go | 12 ++-- cmd/validator/main.go | 8 +-- container/trie/BUILD.bazel | 2 +- container/trie/sparse_merkle.go | 4 +- crypto/keystore/BUILD.bazel | 2 +- crypto/keystore/key.go | 10 +-- deps.bzl | 2 +- {shared/fileutil => io/file}/BUILD.bazel | 2 +- {shared/fileutil => io/file}/fileutil.go | 2 +- {shared/fileutil => io/file}/fileutil_test.go | 68 +++++++++---------- {shared/logutil => io/logs}/BUILD.bazel | 2 +- {shared/logutil => io/logs}/logutil.go | 4 +- {shared/logutil => io/logs}/logutil_test.go | 2 +- {shared/logutil => io/logs}/stream.go | 2 +- {shared/logutil => io/logs}/stream_test.go | 2 +- {shared/promptutil => io/prompt}/BUILD.bazel | 4 +- {shared/promptutil => io/prompt}/prompt.go | 6 +- {shared/promptutil => io/prompt}/validate.go | 2 +- .../promptutil => io/prompt}/validate_test.go | 2 +- {shared/mathutil => math}/BUILD.bazel | 2 +- {shared/mathutil => math}/math_helper.go | 8 +-- {shared/mathutil => math}/math_helper_test.go | 32 ++++----- nogo_config.json | 2 +- runtime/tos/BUILD.bazel | 4 +- runtime/tos/tos.go | 14 ++-- runtime/tos/tos_test.go | 4 +- shared/cmd/BUILD.bazel | 2 +- shared/cmd/defaults.go | 16 ++--- shared/cmd/helpers.go | 6 +- shared/params/BUILD.bazel | 2 +- shared/params/loader.go | 4 +- shared/petnames/names.go | 2 +- testing/bls/utils/BUILD.bazel | 2 +- testing/bls/utils/utils.go | 4 +- tools/analyzers/properpermissions/analyzer.go | 4 +- .../testdata/custom_imports.go | 4 +- .../testdata/regular_imports.go | 4 +- tools/beacon-fuzz/BUILD.bazel | 2 +- tools/beacon-fuzz/main.go | 4 +- tools/benchmark-files-gen/BUILD.bazel | 2 +- tools/benchmark-files-gen/main.go | 12 ++-- tools/bootnode/BUILD.bazel | 2 +- tools/bootnode/bootnode.go | 4 +- tools/enr-calculator/BUILD.bazel | 2 +- tools/enr-calculator/main.go | 4 +- tools/genesis-state-gen/BUILD.bazel | 2 +- tools/genesis-state-gen/main.go | 10 +-- tools/interop/export-genesis/BUILD.bazel | 2 +- tools/interop/export-genesis/main.go | 4 +- tools/interop/split-keys/BUILD.bazel | 2 +- tools/interop/split-keys/main.go | 4 +- tools/keystores/BUILD.bazel | 4 +- tools/keystores/main.go | 22 +++--- validator/accounts/BUILD.bazel | 8 +-- validator/accounts/accounts_backup.go | 20 +++--- validator/accounts/accounts_backup_test.go | 6 +- validator/accounts/accounts_delete.go | 12 ++-- validator/accounts/accounts_exit.go | 16 ++--- validator/accounts/accounts_import.go | 20 +++--- validator/accounts/prompt/log.go | 5 -- .../{prompt => userprompt}/BUILD.bazel | 6 +- validator/accounts/userprompt/log.go | 5 ++ .../accounts/{prompt => userprompt}/prompt.go | 36 +++++----- validator/accounts/wallet/BUILD.bazel | 6 +- validator/accounts/wallet/wallet.go | 36 +++++----- validator/accounts/wallet_create.go | 20 +++--- validator/accounts/wallet_edit.go | 4 +- validator/accounts/wallet_recover.go | 22 +++--- validator/client/BUILD.bazel | 4 +- .../slashing_protection_interchange_test.go | 4 +- validator/client/wait_for_activation.go | 6 +- validator/db/BUILD.bazel | 4 +- validator/db/kv/BUILD.bazel | 2 +- validator/db/kv/backup.go | 6 +- validator/db/kv/db.go | 6 +- validator/db/migrate.go | 6 +- validator/db/restore.go | 14 ++-- validator/keymanager/derived/BUILD.bazel | 2 +- validator/keymanager/derived/mnemonic.go | 6 +- validator/keymanager/imported/BUILD.bazel | 4 +- validator/keymanager/imported/import.go | 6 +- validator/keymanager/imported/refresh.go | 4 +- validator/node/BUILD.bazel | 2 +- validator/node/node.go | 8 +-- validator/rpc/BUILD.bazel | 8 +-- validator/rpc/auth.go | 30 ++++---- validator/rpc/auth_test.go | 4 +- validator/rpc/server.go | 6 +- validator/rpc/wallet.go | 10 +-- validator/rpc/wallet_test.go | 8 +-- validator/slashing-protection/BUILD.bazel | 6 +- validator/slashing-protection/cli_export.go | 16 ++--- validator/slashing-protection/cli_import.go | 12 ++-- .../cli_import_export_test.go | 14 ++-- 140 files changed, 470 insertions(+), 470 deletions(-) rename {shared/fileutil => io/file}/BUILD.bazel (90%) rename {shared/fileutil => io/file}/fileutil.go (99%) rename {shared/fileutil => io/file}/fileutil_test.go (84%) rename {shared/logutil => io/logs}/BUILD.bazel (91%) rename {shared/logutil => io/logs}/logutil.go (95%) rename {shared/logutil => io/logs}/logutil_test.go (97%) rename {shared/logutil => io/logs}/stream.go (99%) rename {shared/logutil => io/logs}/stream_test.go (96%) rename {shared/promptutil => io/prompt}/BUILD.bazel (87%) rename {shared/promptutil => io/prompt}/prompt.go (97%) rename {shared/promptutil => io/prompt}/validate.go (99%) rename {shared/promptutil => io/prompt}/validate_test.go (99%) rename {shared/mathutil => math}/BUILD.bazel (87%) rename {shared/mathutil => math}/math_helper.go (94%) rename {shared/mathutil => math}/math_helper_test.go (84%) delete mode 100644 validator/accounts/prompt/log.go rename validator/accounts/{prompt => userprompt}/BUILD.bazel (86%) create mode 100644 validator/accounts/userprompt/log.go rename validator/accounts/{prompt => userprompt}/prompt.go (84%) diff --git a/beacon-chain/cache/BUILD.bazel b/beacon-chain/cache/BUILD.bazel index db86a9f6c..2f9532ef6 100644 --- a/beacon-chain/cache/BUILD.bazel +++ b/beacon-chain/cache/BUILD.bazel @@ -44,9 +44,9 @@ go_library( "//container/slice:go_default_library", "//crypto/hash:go_default_library", "//crypto/rand:go_default_library", + "//math:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/mathutil:go_default_library", "//shared/params:go_default_library", "@com_github_hashicorp_golang_lru//:go_default_library", "@com_github_patrickmn_go_cache//:go_default_library", diff --git a/beacon-chain/cache/committee.go b/beacon-chain/cache/committee.go index 9b62cb0d4..26c1d11b3 100644 --- a/beacon-chain/cache/committee.go +++ b/beacon-chain/cache/committee.go @@ -12,7 +12,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" lruwrpr "github.com/prysmaticlabs/prysm/cache/lru" "github.com/prysmaticlabs/prysm/container/slice" - "github.com/prysmaticlabs/prysm/shared/mathutil" + "github.com/prysmaticlabs/prysm/math" "github.com/prysmaticlabs/prysm/shared/params" ) @@ -79,7 +79,7 @@ func (c *CommitteeCache) Committee(slot types.Slot, seed [32]byte, index types.C committeeCountPerSlot = item.CommitteeCount / uint64(params.BeaconConfig().SlotsPerEpoch) } - indexOffSet, err := mathutil.Add64(uint64(index), uint64(slot.ModSlot(params.BeaconConfig().SlotsPerEpoch).Mul(committeeCountPerSlot))) + indexOffSet, err := math.Add64(uint64(index), uint64(slot.ModSlot(params.BeaconConfig().SlotsPerEpoch).Mul(committeeCountPerSlot))) if err != nil { return nil, err } diff --git a/beacon-chain/core/altair/BUILD.bazel b/beacon-chain/core/altair/BUILD.bazel index 5a4373529..751e7d6c1 100644 --- a/beacon-chain/core/altair/BUILD.bazel +++ b/beacon-chain/core/altair/BUILD.bazel @@ -31,11 +31,11 @@ go_library( "//beacon-chain/state/v2:go_default_library", "//crypto/bls:go_default_library", "//crypto/hash:go_default_library", + "//math:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/block:go_default_library", "//shared/attestationutil:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/mathutil:go_default_library", "//shared/params:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", @@ -68,11 +68,11 @@ go_test( "//beacon-chain/state/v2:go_default_library", "//container/trie:go_default_library", "//crypto/bls:go_default_library", + "//math:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/wrapper:go_default_library", "//shared/attestationutil:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/mathutil:go_default_library", "//shared/params:go_default_library", "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", diff --git a/beacon-chain/core/altair/attestation_test.go b/beacon-chain/core/altair/attestation_test.go index a3c3c0a38..600670c71 100644 --- a/beacon-chain/core/altair/attestation_test.go +++ b/beacon-chain/core/altair/attestation_test.go @@ -14,10 +14,10 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" stateAltair "github.com/prysmaticlabs/prysm/beacon-chain/state/v2" "github.com/prysmaticlabs/prysm/crypto/bls" + "github.com/prysmaticlabs/prysm/math" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper" "github.com/prysmaticlabs/prysm/shared/attestationutil" - "github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/require" @@ -631,7 +631,7 @@ func TestAttestationParticipationFlagIndices(t *testing.T) { Source: ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}, Target: ðpb.Checkpoint{}, }, - inputDelay: types.Slot(mathutil.IntegerSquareRoot(uint64(cfg.SlotsPerEpoch)) - 1), + inputDelay: types.Slot(math.IntegerSquareRoot(uint64(cfg.SlotsPerEpoch)) - 1), participationIndices: map[uint8]bool{ sourceFlagIndex: true, }, @@ -645,7 +645,7 @@ func TestAttestationParticipationFlagIndices(t *testing.T) { Source: ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}, Target: ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}, }, - inputDelay: types.Slot(mathutil.IntegerSquareRoot(uint64(cfg.SlotsPerEpoch)) - 1), + inputDelay: types.Slot(math.IntegerSquareRoot(uint64(cfg.SlotsPerEpoch)) - 1), participationIndices: map[uint8]bool{ sourceFlagIndex: true, targetFlagIndex: true, diff --git a/beacon-chain/core/altair/epoch_precompute.go b/beacon-chain/core/altair/epoch_precompute.go index fcfe808db..aee5219e7 100644 --- a/beacon-chain/core/altair/epoch_precompute.go +++ b/beacon-chain/core/altair/epoch_precompute.go @@ -8,7 +8,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" - "github.com/prysmaticlabs/prysm/shared/mathutil" + "github.com/prysmaticlabs/prysm/math" "github.com/prysmaticlabs/prysm/shared/params" "go.opencensus.io/trace" ) @@ -228,7 +228,7 @@ func AttestationsDelta(state state.BeaconStateAltair, bal *precompute.Balance, v cfg := params.BeaconConfig() increment := cfg.EffectiveBalanceIncrement factor := cfg.BaseRewardFactor - baseRewardMultiplier := increment * factor / mathutil.IntegerSquareRoot(bal.ActiveCurrentEpoch) + baseRewardMultiplier := increment * factor / math.IntegerSquareRoot(bal.ActiveCurrentEpoch) leak := helpers.IsInInactivityLeak(prevEpoch, finalizedEpoch) inactivityDenominator := cfg.InactivityScoreBias * cfg.InactivityPenaltyQuotientAltair diff --git a/beacon-chain/core/altair/reward.go b/beacon-chain/core/altair/reward.go index 28a7c73b7..cb7210226 100644 --- a/beacon-chain/core/altair/reward.go +++ b/beacon-chain/core/altair/reward.go @@ -5,7 +5,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" - "github.com/prysmaticlabs/prysm/shared/mathutil" + "github.com/prysmaticlabs/prysm/math" "github.com/prysmaticlabs/prysm/shared/params" ) @@ -56,5 +56,5 @@ func BaseRewardPerIncrement(activeBalance uint64) (uint64, error) { return 0, errors.New("active balance can't be 0") } cfg := params.BeaconConfig() - return cfg.EffectiveBalanceIncrement * cfg.BaseRewardFactor / mathutil.IntegerSquareRoot(activeBalance), nil + return cfg.EffectiveBalanceIncrement * cfg.BaseRewardFactor / math.IntegerSquareRoot(activeBalance), nil } diff --git a/beacon-chain/core/altair/sync_committee.go b/beacon-chain/core/altair/sync_committee.go index ff615a074..29374d306 100644 --- a/beacon-chain/core/altair/sync_committee.go +++ b/beacon-chain/core/altair/sync_committee.go @@ -12,9 +12,9 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/crypto/hash" + "github.com/prysmaticlabs/prysm/math" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/bytesutil" - "github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/params" ) @@ -178,7 +178,7 @@ func IsSyncCommitteeAggregator(sig []byte) (bool, error) { } cfg := params.BeaconConfig() - modulo := mathutil.Max(1, cfg.SyncCommitteeSize/cfg.SyncCommitteeSubnetCount/cfg.TargetAggregatorsPerSyncSubcommittee) + modulo := math.Max(1, cfg.SyncCommitteeSize/cfg.SyncCommitteeSubnetCount/cfg.TargetAggregatorsPerSyncSubcommittee) hashedSig := hash.Hash(sig) return bytesutil.FromBytes8(hashedSig[:8])%modulo == 0, nil } diff --git a/beacon-chain/core/blocks/BUILD.bazel b/beacon-chain/core/blocks/BUILD.bazel index cd7f5e7cf..c5083fbed 100644 --- a/beacon-chain/core/blocks/BUILD.bazel +++ b/beacon-chain/core/blocks/BUILD.bazel @@ -32,6 +32,7 @@ go_library( "//container/trie:go_default_library", "//crypto/bls:go_default_library", "//crypto/hash:go_default_library", + "//math:go_default_library", "//network/forks:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/block:go_default_library", @@ -39,7 +40,6 @@ go_library( "//shared/attestationutil:go_default_library", "//shared/bytesutil:go_default_library", "//shared/depositutil:go_default_library", - "//shared/mathutil:go_default_library", "//shared/params:go_default_library", "//shared/slashutil:go_default_library", "@com_github_pkg_errors//:go_default_library", diff --git a/beacon-chain/core/blocks/deposit.go b/beacon-chain/core/blocks/deposit.go index 9fad8e33d..1e7d03bf1 100644 --- a/beacon-chain/core/blocks/deposit.go +++ b/beacon-chain/core/blocks/deposit.go @@ -9,10 +9,10 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/container/trie" "github.com/prysmaticlabs/prysm/crypto/bls" + "github.com/prysmaticlabs/prysm/math" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/depositutil" - "github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/params" ) @@ -52,7 +52,7 @@ func ActivateValidatorWithEffectiveBalance(beaconState state.BeaconState, deposi if err != nil { return nil, err } - validator.EffectiveBalance = mathutil.Min(balance-balance%params.BeaconConfig().EffectiveBalanceIncrement, params.BeaconConfig().MaxEffectiveBalance) + validator.EffectiveBalance = math.Min(balance-balance%params.BeaconConfig().EffectiveBalanceIncrement, params.BeaconConfig().MaxEffectiveBalance) if validator.EffectiveBalance == params.BeaconConfig().MaxEffectiveBalance { validator.ActivationEligibilityEpoch = 0 diff --git a/beacon-chain/core/epoch/BUILD.bazel b/beacon-chain/core/epoch/BUILD.bazel index 5be096071..b22308453 100644 --- a/beacon-chain/core/epoch/BUILD.bazel +++ b/beacon-chain/core/epoch/BUILD.bazel @@ -14,9 +14,9 @@ go_library( "//beacon-chain/core/validators:go_default_library", "//beacon-chain/state:go_default_library", "//config/features:go_default_library", + "//math:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//shared/attestationutil:go_default_library", - "//shared/mathutil:go_default_library", "//shared/params:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", diff --git a/beacon-chain/core/epoch/epoch_processing.go b/beacon-chain/core/epoch/epoch_processing.go index c9e7c2751..c086b0088 100644 --- a/beacon-chain/core/epoch/epoch_processing.go +++ b/beacon-chain/core/epoch/epoch_processing.go @@ -15,9 +15,9 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/features" + "github.com/prysmaticlabs/prysm/math" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/attestationutil" - "github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/params" ) @@ -185,7 +185,7 @@ func ProcessSlashings(state state.BeaconState, slashingMultiplier uint64) (state // a callback is used here to apply the following actions to all validators // below equally. increment := params.BeaconConfig().EffectiveBalanceIncrement - minSlashing := mathutil.Min(totalSlashing*slashingMultiplier, totalBalance) + minSlashing := math.Min(totalSlashing*slashingMultiplier, totalBalance) err = state.ApplyToEveryValidator(func(idx int, val *ethpb.Validator) (bool, *ethpb.Validator, error) { correctEpoch := (currentEpoch + exitLength/2) == val.WithdrawableEpoch if val.Slashed && correctEpoch { diff --git a/beacon-chain/core/epoch/precompute/BUILD.bazel b/beacon-chain/core/epoch/precompute/BUILD.bazel index 7e892e6db..972d21f2e 100644 --- a/beacon-chain/core/epoch/precompute/BUILD.bazel +++ b/beacon-chain/core/epoch/precompute/BUILD.bazel @@ -19,10 +19,10 @@ go_library( "//beacon-chain/core:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/state:go_default_library", + "//math:go_default_library", "//monitoring/tracing:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//shared/attestationutil:go_default_library", - "//shared/mathutil:go_default_library", "//shared/params:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", @@ -46,9 +46,9 @@ go_test( "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v1:go_default_library", + "//math:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//shared/attestationutil:go_default_library", - "//shared/mathutil:go_default_library", "//shared/params:go_default_library", "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", diff --git a/beacon-chain/core/epoch/precompute/reward_penalty.go b/beacon-chain/core/epoch/precompute/reward_penalty.go index 6170a4ea6..21503531e 100644 --- a/beacon-chain/core/epoch/precompute/reward_penalty.go +++ b/beacon-chain/core/epoch/precompute/reward_penalty.go @@ -6,7 +6,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" - "github.com/prysmaticlabs/prysm/shared/mathutil" + "github.com/prysmaticlabs/prysm/math" "github.com/prysmaticlabs/prysm/shared/params" ) @@ -69,7 +69,7 @@ func AttestationsDelta(state state.ReadOnlyBeaconState, pBal *Balance, vp []*Val prevEpoch := core.PrevEpoch(state) finalizedEpoch := state.FinalizedCheckpointEpoch() - sqrtActiveCurrentEpoch := mathutil.IntegerSquareRoot(pBal.ActiveCurrentEpoch) + sqrtActiveCurrentEpoch := math.IntegerSquareRoot(pBal.ActiveCurrentEpoch) for i, v := range vp { rewards[i], penalties[i] = attestationDelta(pBal, sqrtActiveCurrentEpoch, v, prevEpoch, finalizedEpoch) } @@ -158,7 +158,7 @@ func ProposersDelta(state state.ReadOnlyBeaconState, pBal *Balance, vp []*Valida rewards := make([]uint64, numofVals) totalBalance := pBal.ActiveCurrentEpoch - balanceSqrt := mathutil.IntegerSquareRoot(totalBalance) + balanceSqrt := math.IntegerSquareRoot(totalBalance) // Balance square root cannot be 0, this prevents division by 0. if balanceSqrt == 0 { balanceSqrt = 1 diff --git a/beacon-chain/core/epoch/precompute/reward_penalty_test.go b/beacon-chain/core/epoch/precompute/reward_penalty_test.go index aa6baf473..8b6fc78ab 100644 --- a/beacon-chain/core/epoch/precompute/reward_penalty_test.go +++ b/beacon-chain/core/epoch/precompute/reward_penalty_test.go @@ -12,8 +12,8 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" + "github.com/prysmaticlabs/prysm/math" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" @@ -314,7 +314,7 @@ func TestProposerDeltaPrecompute_HappyCase(t *testing.T) { require.NoError(t, err) baseReward := v[0].CurrentEpochEffectiveBalance * params.BeaconConfig().BaseRewardFactor / - mathutil.IntegerSquareRoot(b.ActiveCurrentEpoch) / params.BeaconConfig().BaseRewardsPerEpoch + math.IntegerSquareRoot(b.ActiveCurrentEpoch) / params.BeaconConfig().BaseRewardsPerEpoch proposerReward := baseReward / params.BeaconConfig().ProposerRewardQuotient assert.Equal(t, proposerReward, r[proposerIndex], "Unexpected proposer reward") @@ -372,6 +372,6 @@ func baseReward(state state.ReadOnlyBeaconState, index types.ValidatorIndex) (ui } effectiveBalance := val.EffectiveBalance() baseReward := effectiveBalance * params.BeaconConfig().BaseRewardFactor / - mathutil.IntegerSquareRoot(totalBalance) / params.BeaconConfig().BaseRewardsPerEpoch + math.IntegerSquareRoot(totalBalance) / params.BeaconConfig().BaseRewardsPerEpoch return baseReward, nil } diff --git a/beacon-chain/core/epoch/precompute/slashing.go b/beacon-chain/core/epoch/precompute/slashing.go index 01b6f9c89..22d74f561 100644 --- a/beacon-chain/core/epoch/precompute/slashing.go +++ b/beacon-chain/core/epoch/precompute/slashing.go @@ -5,8 +5,8 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" + "github.com/prysmaticlabs/prysm/math" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/params" ) @@ -23,7 +23,7 @@ func ProcessSlashingsPrecompute(s state.BeaconState, pBal *Balance) error { totalSlashing += slashing } - minSlashing := mathutil.Min(totalSlashing*params.BeaconConfig().ProportionalSlashingMultiplier, pBal.ActiveCurrentEpoch) + minSlashing := math.Min(totalSlashing*params.BeaconConfig().ProportionalSlashingMultiplier, pBal.ActiveCurrentEpoch) epochToWithdraw := currentEpoch + exitLength/2 var hasSlashing bool diff --git a/beacon-chain/core/helpers/BUILD.bazel b/beacon-chain/core/helpers/BUILD.bazel index 1f2f6c98c..5807388d7 100644 --- a/beacon-chain/core/helpers/BUILD.bazel +++ b/beacon-chain/core/helpers/BUILD.bazel @@ -41,10 +41,10 @@ go_library( "//container/trie:go_default_library", "//crypto/bls:go_default_library", "//crypto/hash:go_default_library", + "//math:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/block:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/mathutil:go_default_library", "//shared/params:go_default_library", "//time:go_default_library", "@com_github_ferranbt_fastssz//:go_default_library", diff --git a/beacon-chain/core/helpers/beacon_committee.go b/beacon-chain/core/helpers/beacon_committee.go index 81ffd9e36..84fc5fcb5 100644 --- a/beacon-chain/core/helpers/beacon_committee.go +++ b/beacon-chain/core/helpers/beacon_committee.go @@ -15,9 +15,9 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/container/slice" "github.com/prysmaticlabs/prysm/crypto/hash" + "github.com/prysmaticlabs/prysm/math" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/bytesutil" - "github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/params" ) @@ -127,7 +127,7 @@ func BeaconCommittee( committeesPerSlot := SlotCommitteeCount(uint64(len(validatorIndices))) - indexOffset, err := mathutil.Add64(uint64(committeeIndex), uint64(slot.ModSlot(params.BeaconConfig().SlotsPerEpoch).Mul(committeesPerSlot))) + indexOffset, err := math.Add64(uint64(committeeIndex), uint64(slot.ModSlot(params.BeaconConfig().SlotsPerEpoch).Mul(committeesPerSlot))) if err != nil { return nil, errors.Wrap(err, "could not add calculate index offset") } diff --git a/beacon-chain/core/helpers/weak_subjectivity.go b/beacon-chain/core/helpers/weak_subjectivity.go index 4a21e0c86..f39c6b1fe 100644 --- a/beacon-chain/core/helpers/weak_subjectivity.go +++ b/beacon-chain/core/helpers/weak_subjectivity.go @@ -11,8 +11,8 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/state" + "github.com/prysmaticlabs/prysm/math" eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/params" ) @@ -94,7 +94,7 @@ func ComputeWeakSubjectivityPeriod(st state.ReadOnlyBeaconState) (types.Epoch, e if T*(200+3*D) < t*(200+12*D) { epochsForValidatorSetChurn := N * (t*(200+12*D) - T*(200+3*D)) / (600 * delta * (2*t + T)) epochsForBalanceTopUps := N * (200 + 3*D) / (600 * Delta) - wsp += mathutil.Max(epochsForValidatorSetChurn, epochsForBalanceTopUps) + wsp += math.Max(epochsForValidatorSetChurn, epochsForBalanceTopUps) } else { wsp += 3 * N * D * t / (200 * Delta * (T - t)) } diff --git a/beacon-chain/core/transition/BUILD.bazel b/beacon-chain/core/transition/BUILD.bazel index 6d69689c1..05c5ace3b 100644 --- a/beacon-chain/core/transition/BUILD.bazel +++ b/beacon-chain/core/transition/BUILD.bazel @@ -39,12 +39,12 @@ go_library( "//config/features:go_default_library", "//crypto/bls:go_default_library", "//crypto/hash:go_default_library", + "//math:go_default_library", "//monitoring/tracing:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/block:go_default_library", "//runtime/version:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/mathutil:go_default_library", "//shared/params:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library", diff --git a/beacon-chain/core/transition/interop/BUILD.bazel b/beacon-chain/core/transition/interop/BUILD.bazel index ce7cb9749..5bc780d20 100644 --- a/beacon-chain/core/transition/interop/BUILD.bazel +++ b/beacon-chain/core/transition/interop/BUILD.bazel @@ -15,8 +15,8 @@ go_library( deps = [ "//beacon-chain/state:go_default_library", "//config/features:go_default_library", + "//io/file:go_default_library", "//proto/prysm/v1alpha1/block:go_default_library", - "//shared/fileutil:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", ], ) diff --git a/beacon-chain/core/transition/interop/write_block_to_disk.go b/beacon-chain/core/transition/interop/write_block_to_disk.go index 642886891..944e8c794 100644 --- a/beacon-chain/core/transition/interop/write_block_to_disk.go +++ b/beacon-chain/core/transition/interop/write_block_to_disk.go @@ -6,8 +6,8 @@ import ( "path" "github.com/prysmaticlabs/prysm/config/features" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block" - "github.com/prysmaticlabs/prysm/shared/fileutil" ) // WriteBlockToDisk as a block ssz. Writes to temp directory. Debug! @@ -27,7 +27,7 @@ func WriteBlockToDisk(block block.SignedBeaconBlock, failed bool) { log.WithError(err).Error("Failed to ssz encode block") return } - if err := fileutil.WriteFile(fp, enc); err != nil { + if err := file.WriteFile(fp, enc); err != nil { log.WithError(err).Error("Failed to write to disk") } } diff --git a/beacon-chain/core/transition/interop/write_state_to_disk.go b/beacon-chain/core/transition/interop/write_state_to_disk.go index 26d9f487d..5f342ea9d 100644 --- a/beacon-chain/core/transition/interop/write_state_to_disk.go +++ b/beacon-chain/core/transition/interop/write_state_to_disk.go @@ -7,7 +7,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/features" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" ) // WriteStateToDisk as a state ssz. Writes to temp directory. Debug! @@ -22,7 +22,7 @@ func WriteStateToDisk(state state.ReadOnlyBeaconState) { log.WithError(err).Error("Failed to ssz encode state") return } - if err := fileutil.WriteFile(fp, enc); err != nil { + if err := file.WriteFile(fp, enc); err != nil { log.WithError(err).Error("Failed to write to disk") } } diff --git a/beacon-chain/core/transition/transition.go b/beacon-chain/core/transition/transition.go index 6f0c4fe5e..c69a4f7f0 100644 --- a/beacon-chain/core/transition/transition.go +++ b/beacon-chain/core/transition/transition.go @@ -17,10 +17,10 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" + "github.com/prysmaticlabs/prysm/math" "github.com/prysmaticlabs/prysm/monitoring/tracing" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block" "github.com/prysmaticlabs/prysm/runtime/version" - "github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/params" "go.opencensus.io/trace" ) @@ -332,7 +332,7 @@ func VerifyOperationLengths(_ context.Context, state state.BeaconState, b block. if state.Eth1DepositIndex() > eth1Data.DepositCount { return nil, fmt.Errorf("expected state.deposit_index %d <= eth1data.deposit_count %d", state.Eth1DepositIndex(), eth1Data.DepositCount) } - maxDeposits := mathutil.Min(params.BeaconConfig().MaxDeposits, eth1Data.DepositCount-state.Eth1DepositIndex()) + maxDeposits := math.Min(params.BeaconConfig().MaxDeposits, eth1Data.DepositCount-state.Eth1DepositIndex()) // Verify outstanding deposits are processed up to max number of deposits if uint64(len(body.Deposits())) != maxDeposits { return nil, fmt.Errorf("incorrect outstanding deposits in block body, wanted: %d, got: %d", diff --git a/beacon-chain/db/BUILD.bazel b/beacon-chain/db/BUILD.bazel index 64559394a..8289ef9a7 100644 --- a/beacon-chain/db/BUILD.bazel +++ b/beacon-chain/db/BUILD.bazel @@ -18,9 +18,9 @@ go_library( deps = [ "//beacon-chain/db/iface:go_default_library", "//beacon-chain/db/kv:go_default_library", + "//io/file:go_default_library", + "//io/prompt:go_default_library", "//shared/cmd:go_default_library", - "//shared/fileutil:go_default_library", - "//shared/promptutil:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@com_github_urfave_cli_v2//:go_default_library", diff --git a/beacon-chain/db/kv/BUILD.bazel b/beacon-chain/db/kv/BUILD.bazel index 777d6cb20..ecfc80544 100644 --- a/beacon-chain/db/kv/BUILD.bazel +++ b/beacon-chain/db/kv/BUILD.bazel @@ -45,6 +45,7 @@ go_library( "//beacon-chain/state/v2:go_default_library", "//config/features:go_default_library", "//container/slice:go_default_library", + "//io/file:go_default_library", "//monitoring/progress:go_default_library", "//monitoring/tracing:go_default_library", "//proto/prysm/v1alpha1:go_default_library", @@ -52,7 +53,6 @@ go_library( "//proto/prysm/v1alpha1/wrapper:go_default_library", "//runtime/version:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/fileutil:go_default_library", "//shared/params:go_default_library", "@com_github_dgraph_io_ristretto//:go_default_library", "@com_github_ethereum_go_ethereum//common:go_default_library", diff --git a/beacon-chain/db/kv/backup.go b/beacon-chain/db/kv/backup.go index d8e8317a1..7024ebdd4 100644 --- a/beacon-chain/db/kv/backup.go +++ b/beacon-chain/db/kv/backup.go @@ -6,7 +6,7 @@ import ( "path" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/shared/params" bolt "go.etcd.io/bbolt" "go.opencensus.io/trace" @@ -23,7 +23,7 @@ func (s *Store) Backup(ctx context.Context, outputDir string, permissionOverride var backupsDir string var err error if outputDir != "" { - backupsDir, err = fileutil.ExpandPath(outputDir) + backupsDir, err = file.ExpandPath(outputDir) if err != nil { return err } @@ -38,7 +38,7 @@ func (s *Store) Backup(ctx context.Context, outputDir string, permissionOverride return errors.New("no head block") } // Ensure the backups directory exists. - if err := fileutil.HandleBackupDir(backupsDir, permissionOverride); err != nil { + if err := file.HandleBackupDir(backupsDir, permissionOverride); err != nil { return err } backupPath := path.Join(backupsDir, fmt.Sprintf("prysm_beacondb_at_slot_%07d.backup", head.Block().Slot())) diff --git a/beacon-chain/db/kv/kv.go b/beacon-chain/db/kv/kv.go index 1d81ff316..7ffbe969f 100644 --- a/beacon-chain/db/kv/kv.go +++ b/beacon-chain/db/kv/kv.go @@ -14,7 +14,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promauto" prombolt "github.com/prysmaticlabs/prombbolt" "github.com/prysmaticlabs/prysm/beacon-chain/db/iface" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/shared/params" bolt "go.etcd.io/bbolt" ) @@ -95,12 +95,12 @@ func KVStoreDatafilePath(dirPath string) string { // path specified, creates the kv-buckets based on the schema, and stores // an open connection db object as a property of the Store struct. func NewKVStore(ctx context.Context, dirPath string, config *Config) (*Store, error) { - hasDir, err := fileutil.HasDir(dirPath) + hasDir, err := file.HasDir(dirPath) if err != nil { return nil, err } if !hasDir { - if err := fileutil.MkdirAll(dirPath); err != nil { + if err := file.MkdirAll(dirPath); err != nil { return nil, err } } diff --git a/beacon-chain/db/restore.go b/beacon-chain/db/restore.go index a147369b2..cbd51723c 100644 --- a/beacon-chain/db/restore.go +++ b/beacon-chain/db/restore.go @@ -7,9 +7,9 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/beacon-chain/db/kv" + "github.com/prysmaticlabs/prysm/io/file" + "github.com/prysmaticlabs/prysm/io/prompt" "github.com/prysmaticlabs/prysm/shared/cmd" - "github.com/prysmaticlabs/prysm/shared/fileutil" - "github.com/prysmaticlabs/prysm/shared/promptutil" "github.com/urfave/cli/v2" ) @@ -22,9 +22,9 @@ func Restore(cliCtx *cli.Context) error { targetDir := cliCtx.String(cmd.RestoreTargetDirFlag.Name) restoreDir := path.Join(targetDir, kv.BeaconNodeDbDirName) - if fileutil.FileExists(path.Join(restoreDir, kv.DatabaseFileName)) { - resp, err := promptutil.ValidatePrompt( - os.Stdin, dbExistsYesNoPrompt, promptutil.ValidateYesOrNo, + if file.FileExists(path.Join(restoreDir, kv.DatabaseFileName)) { + resp, err := prompt.ValidatePrompt( + os.Stdin, dbExistsYesNoPrompt, prompt.ValidateYesOrNo, ) if err != nil { return errors.Wrap(err, "could not validate choice") @@ -34,10 +34,10 @@ func Restore(cliCtx *cli.Context) error { return nil } } - if err := fileutil.MkdirAll(restoreDir); err != nil { + if err := file.MkdirAll(restoreDir); err != nil { return err } - if err := fileutil.CopyFile(sourceFile, path.Join(restoreDir, kv.DatabaseFileName)); err != nil { + if err := file.CopyFile(sourceFile, path.Join(restoreDir, kv.DatabaseFileName)); err != nil { return err } diff --git a/beacon-chain/db/slasherkv/BUILD.bazel b/beacon-chain/db/slasherkv/BUILD.bazel index 58e7d974e..9ea8b5ab9 100644 --- a/beacon-chain/db/slasherkv/BUILD.bazel +++ b/beacon-chain/db/slasherkv/BUILD.bazel @@ -16,9 +16,9 @@ go_library( "//beacon-chain/core:go_default_library", "//beacon-chain/db/iface:go_default_library", "//beacon-chain/slasher/types:go_default_library", + "//io/file:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/fileutil:go_default_library", "//shared/params:go_default_library", "@com_github_ferranbt_fastssz//:go_default_library", "@com_github_golang_snappy//:go_default_library", diff --git a/beacon-chain/db/slasherkv/kv.go b/beacon-chain/db/slasherkv/kv.go index db94b54bd..2794c06b4 100644 --- a/beacon-chain/db/slasherkv/kv.go +++ b/beacon-chain/db/slasherkv/kv.go @@ -10,7 +10,7 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/beacon-chain/db/iface" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/shared/params" bolt "go.etcd.io/bbolt" ) @@ -40,12 +40,12 @@ type Store struct { // path specified, creates the kv-buckets based on the schema, and stores // an open connection db object as a property of the Store struct. func NewKVStore(ctx context.Context, dirPath string, config *Config) (*Store, error) { - hasDir, err := fileutil.HasDir(dirPath) + hasDir, err := file.HasDir(dirPath) if err != nil { return nil, err } if !hasDir { - if err := fileutil.MkdirAll(dirPath); err != nil { + if err := file.MkdirAll(dirPath); err != nil { return nil, err } } diff --git a/beacon-chain/p2p/BUILD.bazel b/beacon-chain/p2p/BUILD.bazel index c58ac7160..03c50799d 100644 --- a/beacon-chain/p2p/BUILD.bazel +++ b/beacon-chain/p2p/BUILD.bazel @@ -55,6 +55,7 @@ go_library( "//cmd/beacon-chain/flags:go_default_library", "//config/features:go_default_library", "//crypto/hash:go_default_library", + "//io/file:go_default_library", "//monitoring/tracing:go_default_library", "//network:go_default_library", "//network/forks:go_default_library", @@ -64,7 +65,6 @@ go_library( "//runtime:go_default_library", "//runtime/version:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/fileutil:go_default_library", "//shared/params:go_default_library", "//shared/runutil:go_default_library", "//time:go_default_library", diff --git a/beacon-chain/p2p/utils.go b/beacon-chain/p2p/utils.go index 604abab3f..a72a300c7 100644 --- a/beacon-chain/p2p/utils.go +++ b/beacon-chain/p2p/utils.go @@ -18,11 +18,11 @@ import ( "github.com/libp2p/go-libp2p-core/crypto" "github.com/pkg/errors" "github.com/prysmaticlabs/go-bitfield" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/network" pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/metadata" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper" - "github.com/prysmaticlabs/prysm/shared/fileutil" "github.com/sirupsen/logrus" "google.golang.org/protobuf/proto" ) @@ -127,7 +127,7 @@ func metaDataFromConfig(cfg *Config) (metadata.Metadata, error) { if err != nil { return nil, err } - if err := fileutil.WriteFile(defaultKeyPath, dst); err != nil { + if err := file.WriteFile(defaultKeyPath, dst); err != nil { return nil, err } return wrapper.WrappedMetadataV0(metaData), nil diff --git a/beacon-chain/powchain/BUILD.bazel b/beacon-chain/powchain/BUILD.bazel index 4bc3969d1..60af155d2 100644 --- a/beacon-chain/powchain/BUILD.bazel +++ b/beacon-chain/powchain/BUILD.bazel @@ -33,13 +33,13 @@ go_library( "//container/trie:go_default_library", "//contracts/deposit-contract:go_default_library", "//crypto/hash:go_default_library", + "//io/logs:go_default_library", "//monitoring/clientstats:go_default_library", "//monitoring/tracing:go_default_library", "//network:go_default_library", "//network/authorization:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/logutil:go_default_library", "//shared/params:go_default_library", "//time:go_default_library", "@com_github_ethereum_go_ethereum//:go_default_library", diff --git a/beacon-chain/powchain/service.go b/beacon-chain/powchain/service.go index 14e7f1121..66fac68a3 100644 --- a/beacon-chain/powchain/service.go +++ b/beacon-chain/powchain/service.go @@ -34,13 +34,13 @@ import ( v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/container/trie" contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract" + "github.com/prysmaticlabs/prysm/io/logs" "github.com/prysmaticlabs/prysm/monitoring/clientstats" "github.com/prysmaticlabs/prysm/network" "github.com/prysmaticlabs/prysm/network/authorization" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" protodb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/bytesutil" - "github.com/prysmaticlabs/prysm/shared/logutil" "github.com/prysmaticlabs/prysm/shared/params" prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/sirupsen/logrus" @@ -493,7 +493,7 @@ func (s *Service) waitForConnection() { s.updateConnectedETH1(true) s.runError = nil log.WithFields(logrus.Fields{ - "endpoint": logutil.MaskCredentialsLogging(s.currHttpEndpoint.Url), + "endpoint": logs.MaskCredentialsLogging(s.currHttpEndpoint.Url), }).Info("Connected to eth1 proof-of-work chain") return } @@ -522,7 +522,7 @@ func (s *Service) waitForConnection() { for { select { case <-ticker.C: - log.Debugf("Trying to dial endpoint: %s", logutil.MaskCredentialsLogging(s.currHttpEndpoint.Url)) + log.Debugf("Trying to dial endpoint: %s", logs.MaskCredentialsLogging(s.currHttpEndpoint.Url)) errConnect := s.connectToPowChain() if errConnect != nil { errorLogger(errConnect, "Could not connect to powchain endpoint") @@ -541,7 +541,7 @@ func (s *Service) waitForConnection() { s.updateConnectedETH1(true) s.runError = nil log.WithFields(logrus.Fields{ - "endpoint": logutil.MaskCredentialsLogging(s.currHttpEndpoint.Url), + "endpoint": logs.MaskCredentialsLogging(s.currHttpEndpoint.Url), }).Info("Connected to eth1 proof-of-work chain") return } @@ -953,7 +953,7 @@ func (s *Service) fallbackToNextEndpoint() { } s.updateCurrHttpEndpoint(s.httpEndpoints[nextIndex]) if nextIndex != currIndex { - log.Infof("Falling back to alternative endpoint: %s", logutil.MaskCredentialsLogging(s.currHttpEndpoint.Url)) + log.Infof("Falling back to alternative endpoint: %s", logs.MaskCredentialsLogging(s.currHttpEndpoint.Url)) } } diff --git a/beacon-chain/rpc/BUILD.bazel b/beacon-chain/rpc/BUILD.bazel index 6fe5ae31a..6b7aab686 100644 --- a/beacon-chain/rpc/BUILD.bazel +++ b/beacon-chain/rpc/BUILD.bazel @@ -35,10 +35,10 @@ go_library( "//beacon-chain/state/stategen:go_default_library", "//beacon-chain/sync:go_default_library", "//config/features:go_default_library", + "//io/logs:go_default_library", "//monitoring/tracing:go_default_library", "//proto/eth/service:go_default_library", "//proto/prysm/v1alpha1:go_default_library", - "//shared/logutil:go_default_library", "//shared/params:go_default_library", "@com_github_grpc_ecosystem_go_grpc_middleware//:go_default_library", "@com_github_grpc_ecosystem_go_grpc_middleware//recovery:go_default_library", diff --git a/beacon-chain/rpc/prysm/v1alpha1/node/BUILD.bazel b/beacon-chain/rpc/prysm/v1alpha1/node/BUILD.bazel index 85ca39aa7..17d98c78a 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/node/BUILD.bazel +++ b/beacon-chain/rpc/prysm/v1alpha1/node/BUILD.bazel @@ -10,9 +10,9 @@ go_library( "//beacon-chain/db:go_default_library", "//beacon-chain/p2p:go_default_library", "//beacon-chain/sync:go_default_library", + "//io/logs:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//runtime/version:go_default_library", - "//shared/logutil:go_default_library", "@com_github_libp2p_go_libp2p_core//network:go_default_library", "@com_github_libp2p_go_libp2p_core//peer:go_default_library", "@io_bazel_rules_go//proto/wkt:empty_go_proto", diff --git a/beacon-chain/rpc/prysm/v1alpha1/node/server.go b/beacon-chain/rpc/prysm/v1alpha1/node/server.go index de865a721..854827e42 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/node/server.go +++ b/beacon-chain/rpc/prysm/v1alpha1/node/server.go @@ -17,10 +17,10 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/beacon-chain/sync" + "github.com/prysmaticlabs/prysm/io/logs" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/runtime/version" - "github.com/prysmaticlabs/prysm/shared/logutil" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -31,7 +31,7 @@ import ( // providing RPC endpoints for verifying a beacon node's sync status, genesis and // version information, and services the node implements and runs. type Server struct { - LogsStreamer logutil.Streamer + LogsStreamer logs.Streamer StreamLogsBufferSize int SyncChecker sync.Checker Server *grpc.Server diff --git a/beacon-chain/rpc/service.go b/beacon-chain/rpc/service.go index 794c0efb7..871e7079f 100644 --- a/beacon-chain/rpc/service.go +++ b/beacon-chain/rpc/service.go @@ -39,10 +39,10 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" chainSync "github.com/prysmaticlabs/prysm/beacon-chain/sync" "github.com/prysmaticlabs/prysm/config/features" + "github.com/prysmaticlabs/prysm/io/logs" "github.com/prysmaticlabs/prysm/monitoring/tracing" ethpbservice "github.com/prysmaticlabs/prysm/proto/eth/service" ethpbv1alpha1 "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/shared/logutil" "github.com/prysmaticlabs/prysm/shared/params" "github.com/sirupsen/logrus" "go.opencensus.io/plugin/ocgrpc" @@ -211,7 +211,7 @@ func (s *Service) Start() { } nodeServer := &nodev1alpha1.Server{ - LogsStreamer: logutil.NewStreamServer(), + LogsStreamer: logs.NewStreamServer(), StreamLogsBufferSize: 1000, // Enough to handle bursts of beacon node logs for gRPC streaming. BeaconDB: s.cfg.BeaconDB, Server: s.grpcServer, diff --git a/beacon-chain/sync/initial-sync/BUILD.bazel b/beacon-chain/sync/initial-sync/BUILD.bazel index d2b94cb17..06e9a5bc4 100644 --- a/beacon-chain/sync/initial-sync/BUILD.bazel +++ b/beacon-chain/sync/initial-sync/BUILD.bazel @@ -29,12 +29,12 @@ go_library( "//beacon-chain/sync:go_default_library", "//cmd/beacon-chain/flags:go_default_library", "//crypto/rand:go_default_library", + "//math:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/block:go_default_library", "//runtime:go_default_library", "//shared/abool:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/mathutil:go_default_library", "//shared/params:go_default_library", "//time:go_default_library", "@com_github_kevinms_leakybucket_go//:go_default_library", diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher_peers.go b/beacon-chain/sync/initial-sync/blocks_fetcher_peers.go index 3532da025..98a565620 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher_peers.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher_peers.go @@ -10,7 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers/scorers" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" - "github.com/prysmaticlabs/prysm/shared/mathutil" + mathutil "github.com/prysmaticlabs/prysm/math" "github.com/prysmaticlabs/prysm/shared/params" prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/sirupsen/logrus" diff --git a/cmd/beacon-chain/BUILD.bazel b/cmd/beacon-chain/BUILD.bazel index 728a77281..59f3cd001 100644 --- a/cmd/beacon-chain/BUILD.bazel +++ b/cmd/beacon-chain/BUILD.bazel @@ -19,14 +19,14 @@ go_library( "//cmd/beacon-chain/db:go_default_library", "//cmd/beacon-chain/flags:go_default_library", "//config/features:go_default_library", + "//io/file:go_default_library", + "//io/logs:go_default_library", "//monitoring/journald:go_default_library", "//runtime/debug:go_default_library", "//runtime/maxprocs:go_default_library", "//runtime/tos:go_default_library", "//runtime/version:go_default_library", "//shared/cmd:go_default_library", - "//shared/fileutil:go_default_library", - "//shared/logutil:go_default_library", "@com_github_ethereum_go_ethereum//log:go_default_library", "@com_github_ipfs_go_log_v2//:go_default_library", "@com_github_joonix_log//:go_default_library", diff --git a/cmd/beacon-chain/main.go b/cmd/beacon-chain/main.go index 7d00e8f1b..b3e8170e0 100644 --- a/cmd/beacon-chain/main.go +++ b/cmd/beacon-chain/main.go @@ -15,14 +15,14 @@ import ( dbcommands "github.com/prysmaticlabs/prysm/cmd/beacon-chain/db" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/config/features" + "github.com/prysmaticlabs/prysm/io/file" + "github.com/prysmaticlabs/prysm/io/logs" "github.com/prysmaticlabs/prysm/monitoring/journald" "github.com/prysmaticlabs/prysm/runtime/debug" _ "github.com/prysmaticlabs/prysm/runtime/maxprocs" "github.com/prysmaticlabs/prysm/runtime/tos" "github.com/prysmaticlabs/prysm/runtime/version" "github.com/prysmaticlabs/prysm/shared/cmd" - "github.com/prysmaticlabs/prysm/shared/fileutil" - "github.com/prysmaticlabs/prysm/shared/logutil" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" prefixed "github.com/x-cray/logrus-prefixed-formatter" @@ -163,7 +163,7 @@ func main() { logFileName := ctx.String(cmd.LogFileName.Name) if logFileName != "" { - if err := logutil.ConfigurePersistentLogging(logFileName); err != nil { + if err := logs.ConfigurePersistentLogging(logFileName); err != nil { log.WithError(err).Error("Failed to configuring logging to disk.") } } @@ -197,7 +197,7 @@ func main() { func startNode(ctx *cli.Context) error { // Fix data dir for Windows users. - outdatedDataDir := filepath.Join(fileutil.HomeDir(), "AppData", "Roaming", "Eth2") + outdatedDataDir := filepath.Join(file.HomeDir(), "AppData", "Roaming", "Eth2") currentDataDir := ctx.String(cmd.DataDirFlag.Name) if err := cmd.FixDefaultDataDir(outdatedDataDir, currentDataDir); err != nil { return err diff --git a/cmd/client-stats/BUILD.bazel b/cmd/client-stats/BUILD.bazel index 24748965b..472e2b57b 100644 --- a/cmd/client-stats/BUILD.bazel +++ b/cmd/client-stats/BUILD.bazel @@ -12,11 +12,11 @@ go_library( visibility = ["//visibility:private"], deps = [ "//cmd/client-stats/flags:go_default_library", + "//io/logs:go_default_library", "//monitoring/clientstats:go_default_library", "//monitoring/journald:go_default_library", "//runtime/version:go_default_library", "//shared/cmd:go_default_library", - "//shared/logutil:go_default_library", "@com_github_joonix_log//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@com_github_urfave_cli_v2//:go_default_library", diff --git a/cmd/client-stats/main.go b/cmd/client-stats/main.go index f1679f80a..a7cd1c908 100644 --- a/cmd/client-stats/main.go +++ b/cmd/client-stats/main.go @@ -8,11 +8,11 @@ import ( joonix "github.com/joonix/log" "github.com/prysmaticlabs/prysm/cmd/client-stats/flags" + "github.com/prysmaticlabs/prysm/io/logs" "github.com/prysmaticlabs/prysm/monitoring/clientstats" "github.com/prysmaticlabs/prysm/monitoring/journald" "github.com/prysmaticlabs/prysm/runtime/version" "github.com/prysmaticlabs/prysm/shared/cmd" - "github.com/prysmaticlabs/prysm/shared/logutil" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" prefixed "github.com/x-cray/logrus-prefixed-formatter" @@ -80,7 +80,7 @@ func main() { logFileName := ctx.String(cmd.LogFileName.Name) if logFileName != "" { - if err := logutil.ConfigurePersistentLogging(logFileName); err != nil { + if err := logs.ConfigurePersistentLogging(logFileName); err != nil { log.WithError(err).Error("Failed to configuring logging to disk.") } } diff --git a/cmd/validator/BUILD.bazel b/cmd/validator/BUILD.bazel index 2b880a0e9..979b1a733 100644 --- a/cmd/validator/BUILD.bazel +++ b/cmd/validator/BUILD.bazel @@ -21,14 +21,14 @@ go_library( "//cmd/validator/slashing-protection:go_default_library", "//cmd/validator/wallet:go_default_library", "//config/features:go_default_library", + "//io/file:go_default_library", + "//io/logs:go_default_library", "//monitoring/journald:go_default_library", "//runtime/debug:go_default_library", "//runtime/maxprocs:go_default_library", "//runtime/tos:go_default_library", "//runtime/version:go_default_library", "//shared/cmd:go_default_library", - "//shared/fileutil:go_default_library", - "//shared/logutil:go_default_library", "//validator/node:go_default_library", "@com_github_joonix_log//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", diff --git a/cmd/validator/flags/BUILD.bazel b/cmd/validator/flags/BUILD.bazel index 832a59e64..abb3fea23 100644 --- a/cmd/validator/flags/BUILD.bazel +++ b/cmd/validator/flags/BUILD.bazel @@ -13,7 +13,7 @@ go_library( "//validator:__subpackages__", ], deps = [ - "//shared/fileutil:go_default_library", + "//io/file:go_default_library", "@com_github_urfave_cli_v2//:go_default_library", ], ) diff --git a/cmd/validator/flags/flags.go b/cmd/validator/flags/flags.go index 840e3d361..bee8cc8bd 100644 --- a/cmd/validator/flags/flags.go +++ b/cmd/validator/flags/flags.go @@ -7,7 +7,7 @@ import ( "runtime" "time" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" "github.com/urfave/cli/v2" ) @@ -207,10 +207,10 @@ var ( Value: "", } // ExitAllFlag allows stakers to select all validating keys for exit. This will still require the staker - // to confirm a prompt for this action given it is a dangerous one. + // to confirm a userprompt for this action given it is a dangerous one. ExitAllFlag = &cli.BoolFlag{ Name: "exit-all", - Usage: "Exit all validators. This will still require the staker to confirm a prompt for the action", + Usage: "Exit all validators. This will still require the staker to confirm a userprompt for the action", } // BackupPasswordFile for encrypting accounts a user wishes to back up. BackupPasswordFile = &cli.StringFlag{ @@ -273,10 +273,10 @@ var ( Usage: "Kind of keymanager, either imported, derived, or remote, specified during wallet creation", Value: "", } - // SkipDepositConfirmationFlag skips the y/n confirmation prompt for sending a deposit to the deposit contract. + // SkipDepositConfirmationFlag skips the y/n confirmation userprompt for sending a deposit to the deposit contract. SkipDepositConfirmationFlag = &cli.BoolFlag{ Name: "skip-deposit-confirmation", - Usage: "Skips the y/n confirmation prompt for sending a deposit to the deposit contract", + Usage: "Skips the y/n confirmation userprompt for sending a deposit to the deposit contract", Value: false, } // EnableWebFlag enables controlling the validator client via the Prysm web ui. This is a work in progress. @@ -308,7 +308,7 @@ var ( // DefaultValidatorDir returns OS-specific default validator directory. func DefaultValidatorDir() string { // Try to place the data folder in the user's home dir - home := fileutil.HomeDir() + home := file.HomeDir() if home != "" { if runtime.GOOS == "darwin" { return filepath.Join(home, "Library", "Eth2Validators") diff --git a/cmd/validator/main.go b/cmd/validator/main.go index b5fdf8e3a..35649fff8 100644 --- a/cmd/validator/main.go +++ b/cmd/validator/main.go @@ -17,14 +17,14 @@ import ( slashingprotectioncommands "github.com/prysmaticlabs/prysm/cmd/validator/slashing-protection" walletcommands "github.com/prysmaticlabs/prysm/cmd/validator/wallet" "github.com/prysmaticlabs/prysm/config/features" + "github.com/prysmaticlabs/prysm/io/file" + "github.com/prysmaticlabs/prysm/io/logs" "github.com/prysmaticlabs/prysm/monitoring/journald" "github.com/prysmaticlabs/prysm/runtime/debug" _ "github.com/prysmaticlabs/prysm/runtime/maxprocs" "github.com/prysmaticlabs/prysm/runtime/tos" "github.com/prysmaticlabs/prysm/runtime/version" "github.com/prysmaticlabs/prysm/shared/cmd" - "github.com/prysmaticlabs/prysm/shared/fileutil" - "github.com/prysmaticlabs/prysm/shared/logutil" "github.com/prysmaticlabs/prysm/validator/node" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" @@ -155,13 +155,13 @@ func main() { logFileName := ctx.String(cmd.LogFileName.Name) if logFileName != "" { - if err := logutil.ConfigurePersistentLogging(logFileName); err != nil { + if err := logs.ConfigurePersistentLogging(logFileName); err != nil { log.WithError(err).Error("Failed to configuring logging to disk.") } } // Fix data dir for Windows users. - outdatedDataDir := filepath.Join(fileutil.HomeDir(), "AppData", "Roaming", "Eth2Validators") + outdatedDataDir := filepath.Join(file.HomeDir(), "AppData", "Roaming", "Eth2Validators") currentDataDir := flags.DefaultValidatorDir() if err := cmd.FixDefaultDataDir(outdatedDataDir, currentDataDir); err != nil { log.WithError(err).Error("Cannot update data directory") diff --git a/container/trie/BUILD.bazel b/container/trie/BUILD.bazel index ae39f2d64..16034261a 100644 --- a/container/trie/BUILD.bazel +++ b/container/trie/BUILD.bazel @@ -10,9 +10,9 @@ go_library( visibility = ["//visibility:public"], deps = [ "//crypto/hash:go_default_library", + "//math:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/mathutil:go_default_library", ], ) diff --git a/container/trie/sparse_merkle.go b/container/trie/sparse_merkle.go index 15b144f2d..17155f469 100644 --- a/container/trie/sparse_merkle.go +++ b/container/trie/sparse_merkle.go @@ -8,9 +8,9 @@ import ( "fmt" "github.com/prysmaticlabs/prysm/crypto/hash" + "github.com/prysmaticlabs/prysm/math" protodb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/bytesutil" - "github.com/prysmaticlabs/prysm/shared/mathutil" ) // SparseMerkleTrie implements a sparse, general purpose Merkle trie to be used @@ -180,7 +180,7 @@ func VerifyMerkleBranch(root, item []byte, merkleIndex int, proof [][]byte, dept } node := bytesutil.ToBytes32(item) for i := 0; i <= int(depth); i++ { - if (uint64(merkleIndex) / mathutil.PowerOf2(uint64(i)) % 2) != 0 { + if (uint64(merkleIndex) / math.PowerOf2(uint64(i)) % 2) != 0 { node = hash.Hash(append(proof[i], node[:]...)) } else { node = hash.Hash(append(node[:], proof[i]...)) diff --git a/crypto/keystore/BUILD.bazel b/crypto/keystore/BUILD.bazel index dc1ea2d61..4589b6a1c 100644 --- a/crypto/keystore/BUILD.bazel +++ b/crypto/keystore/BUILD.bazel @@ -12,7 +12,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//crypto/bls:go_default_library", - "//shared/fileutil:go_default_library", + "//io/file:go_default_library", "//time:go_default_library", "@com_github_minio_sha256_simd//:go_default_library", "@com_github_pborman_uuid//:go_default_library", diff --git a/crypto/keystore/key.go b/crypto/keystore/key.go index cdbbe35bb..15740841c 100644 --- a/crypto/keystore/key.go +++ b/crypto/keystore/key.go @@ -27,7 +27,7 @@ import ( "github.com/pborman/uuid" "github.com/prysmaticlabs/prysm/crypto/bls" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" ) const ( @@ -159,15 +159,15 @@ func storeNewRandomKey(ks keyStore, password string) error { return ks.StoreKey(ks.JoinPath(keyFileName(key.PublicKey)), key, password) } -func writeKeyFile(file string, content []byte) error { +func writeKeyFile(fname string, content []byte) error { // Create the keystore directory with appropriate permissions // in case it is not present yet. - if err := fileutil.MkdirAll(filepath.Dir(file)); err != nil { + if err := file.MkdirAll(filepath.Dir(fname)); err != nil { return err } // Atomic write: create a temporary hidden file first // then move it into place. TempFile assigns mode 0600. - f, err := ioutil.TempFile(filepath.Dir(file), "."+filepath.Base(file)+".tmp") + f, err := ioutil.TempFile(filepath.Dir(fname), "."+filepath.Base(fname)+".tmp") if err != nil { return err } @@ -185,5 +185,5 @@ func writeKeyFile(file string, content []byte) error { if err := f.Close(); err != nil { return err } - return os.Rename(f.Name(), file) + return os.Rename(f.Name(), fname) } diff --git a/deps.bzl b/deps.bzl index e07780daf..67028f1d1 100644 --- a/deps.bzl +++ b/deps.bzl @@ -433,7 +433,7 @@ def prysm_deps(): go_repository( name = "com_github_c_bata_go_prompt", - importpath = "github.com/c-bata/go-prompt", + importpath = "github.com/c-bata/go-userprompt", sum = "h1:uyKRz6Z6DUyj49QVijyM339UJV9yhbr70gESwbNU3e0=", version = "v0.2.2", ) diff --git a/shared/fileutil/BUILD.bazel b/io/file/BUILD.bazel similarity index 90% rename from shared/fileutil/BUILD.bazel rename to io/file/BUILD.bazel index ad07ccd9e..a3e0e7658 100644 --- a/shared/fileutil/BUILD.bazel +++ b/io/file/BUILD.bazel @@ -3,7 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", srcs = ["fileutil.go"], - importpath = "github.com/prysmaticlabs/prysm/shared/fileutil", + importpath = "github.com/prysmaticlabs/prysm/io/file", visibility = ["//visibility:public"], deps = [ "//shared/params:go_default_library", diff --git a/shared/fileutil/fileutil.go b/io/file/fileutil.go similarity index 99% rename from shared/fileutil/fileutil.go rename to io/file/fileutil.go index 735bcc68e..b9a92546d 100644 --- a/shared/fileutil/fileutil.go +++ b/io/file/fileutil.go @@ -1,4 +1,4 @@ -package fileutil +package file import ( "crypto/sha256" diff --git a/shared/fileutil/fileutil_test.go b/io/file/fileutil_test.go similarity index 84% rename from shared/fileutil/fileutil_test.go rename to io/file/fileutil_test.go index 412433fa5..344b33a44 100644 --- a/shared/fileutil/fileutil_test.go +++ b/io/file/fileutil_test.go @@ -13,7 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with go-ethereum. If not, see . -package fileutil_test +package file_test import ( "bufio" @@ -25,7 +25,7 @@ import ( "sort" "testing" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" @@ -42,7 +42,7 @@ func TestPathExpansion(t *testing.T) { } require.NoError(t, os.Setenv("DDDXXX", "/tmp")) for test, expected := range tests { - expanded, err := fileutil.ExpandPath(test) + expanded, err := file.ExpandPath(test) require.NoError(t, err) assert.Equal(t, expected, expanded) } @@ -52,7 +52,7 @@ func TestMkdirAll_AlreadyExists_WrongPermissions(t *testing.T) { dirName := t.TempDir() + "somedir" err := os.MkdirAll(dirName, os.ModePerm) require.NoError(t, err) - err = fileutil.MkdirAll(dirName) + err = file.MkdirAll(dirName) assert.ErrorContains(t, "already exists without proper 0700 permissions", err) } @@ -60,7 +60,7 @@ func TestMkdirAll_AlreadyExists_Override(t *testing.T) { dirName := t.TempDir() + "somedir" err := os.MkdirAll(dirName, params.BeaconIoConfig().ReadWriteExecutePermissions) require.NoError(t, err) - assert.NoError(t, fileutil.MkdirAll(dirName)) + assert.NoError(t, file.MkdirAll(dirName)) } func TestHandleBackupDir_AlreadyExists_Override(t *testing.T) { @@ -70,7 +70,7 @@ func TestHandleBackupDir_AlreadyExists_Override(t *testing.T) { info, err := os.Stat(dirName) require.NoError(t, err) assert.Equal(t, "drwxr-xr-x", info.Mode().String()) - assert.NoError(t, fileutil.HandleBackupDir(dirName, true)) + assert.NoError(t, file.HandleBackupDir(dirName, true)) info, err = os.Stat(dirName) require.NoError(t, err) assert.Equal(t, "drwx------", info.Mode().String()) @@ -83,7 +83,7 @@ func TestHandleBackupDir_AlreadyExists_No_Override(t *testing.T) { info, err := os.Stat(dirName) require.NoError(t, err) assert.Equal(t, "drwxr-xr-x", info.Mode().String()) - err = fileutil.HandleBackupDir(dirName, false) + err = file.HandleBackupDir(dirName, false) assert.ErrorContains(t, "dir already exists without proper 0700 permissions", err) info, err = os.Stat(dirName) require.NoError(t, err) @@ -92,7 +92,7 @@ func TestHandleBackupDir_AlreadyExists_No_Override(t *testing.T) { func TestHandleBackupDir_NewDir(t *testing.T) { dirName := t.TempDir() + "somedir" - require.NoError(t, fileutil.HandleBackupDir(dirName, true)) + require.NoError(t, file.HandleBackupDir(dirName, true)) info, err := os.Stat(dirName) require.NoError(t, err) assert.Equal(t, "drwx------", info.Mode().String()) @@ -100,9 +100,9 @@ func TestHandleBackupDir_NewDir(t *testing.T) { func TestMkdirAll_OK(t *testing.T) { dirName := t.TempDir() + "somedir" - err := fileutil.MkdirAll(dirName) + err := file.MkdirAll(dirName) assert.NoError(t, err) - exists, err := fileutil.HasDir(dirName) + exists, err := file.HasDir(dirName) require.NoError(t, err) assert.Equal(t, true, exists) } @@ -113,7 +113,7 @@ func TestWriteFile_AlreadyExists_WrongPermissions(t *testing.T) { require.NoError(t, err) someFileName := filepath.Join(dirName, "somefile.txt") require.NoError(t, ioutil.WriteFile(someFileName, []byte("hi"), os.ModePerm)) - err = fileutil.WriteFile(someFileName, []byte("hi")) + err = file.WriteFile(someFileName, []byte("hi")) assert.ErrorContains(t, "already exists without proper 0600 permissions", err) } @@ -123,7 +123,7 @@ func TestWriteFile_AlreadyExists_OK(t *testing.T) { require.NoError(t, err) someFileName := filepath.Join(dirName, "somefile.txt") require.NoError(t, ioutil.WriteFile(someFileName, []byte("hi"), params.BeaconIoConfig().ReadWritePermissions)) - assert.NoError(t, fileutil.WriteFile(someFileName, []byte("hi"))) + assert.NoError(t, file.WriteFile(someFileName, []byte("hi"))) } func TestWriteFile_OK(t *testing.T) { @@ -131,8 +131,8 @@ func TestWriteFile_OK(t *testing.T) { err := os.MkdirAll(dirName, os.ModePerm) require.NoError(t, err) someFileName := filepath.Join(dirName, "somefile.txt") - require.NoError(t, fileutil.WriteFile(someFileName, []byte("hi"))) - exists := fileutil.FileExists(someFileName) + require.NoError(t, file.WriteFile(someFileName, []byte("hi"))) + exists := file.FileExists(someFileName) assert.Equal(t, true, exists) } @@ -141,7 +141,7 @@ func TestCopyFile(t *testing.T) { err := ioutil.WriteFile(fName, []byte{1, 2, 3}, params.BeaconIoConfig().ReadWritePermissions) require.NoError(t, err) - err = fileutil.CopyFile(fName, fName+"copy") + err = file.CopyFile(fName, fName+"copy") assert.NoError(t, err) defer func() { assert.NoError(t, os.Remove(fName+"copy")) @@ -182,64 +182,64 @@ func TestCopyDir(t *testing.T) { require.NoError(t, os.MkdirAll(filepath.Join(tmpDir1, "subfolder1"), 0777)) require.NoError(t, os.MkdirAll(filepath.Join(tmpDir1, "subfolder2"), 0777)) for _, fd := range fds { - require.NoError(t, fileutil.WriteFile(filepath.Join(tmpDir1, fd.path), fd.content)) - assert.Equal(t, true, fileutil.FileExists(filepath.Join(tmpDir1, fd.path))) - assert.Equal(t, false, fileutil.FileExists(filepath.Join(tmpDir2, fd.path))) + require.NoError(t, file.WriteFile(filepath.Join(tmpDir1, fd.path), fd.content)) + assert.Equal(t, true, file.FileExists(filepath.Join(tmpDir1, fd.path))) + assert.Equal(t, false, file.FileExists(filepath.Join(tmpDir2, fd.path))) } // Make sure that files are copied into non-existent directory only. If directory exists function exits. - assert.ErrorContains(t, "destination directory already exists", fileutil.CopyDir(tmpDir1, t.TempDir())) - require.NoError(t, fileutil.CopyDir(tmpDir1, tmpDir2)) + assert.ErrorContains(t, "destination directory already exists", file.CopyDir(tmpDir1, t.TempDir())) + require.NoError(t, file.CopyDir(tmpDir1, tmpDir2)) // Now, all files should have been copied. for _, fd := range fds { - assert.Equal(t, true, fileutil.FileExists(filepath.Join(tmpDir2, fd.path))) + assert.Equal(t, true, file.FileExists(filepath.Join(tmpDir2, fd.path))) assert.Equal(t, true, deepCompare(t, filepath.Join(tmpDir1, fd.path), filepath.Join(tmpDir2, fd.path))) } - assert.Equal(t, true, fileutil.DirsEqual(tmpDir1, tmpDir2)) + assert.Equal(t, true, file.DirsEqual(tmpDir1, tmpDir2)) } func TestDirsEqual(t *testing.T) { t.Run("non-existent source directory", func(t *testing.T) { - assert.Equal(t, false, fileutil.DirsEqual(filepath.Join(t.TempDir(), "nonexistent"), t.TempDir())) + assert.Equal(t, false, file.DirsEqual(filepath.Join(t.TempDir(), "nonexistent"), t.TempDir())) }) t.Run("non-existent dest directory", func(t *testing.T) { - assert.Equal(t, false, fileutil.DirsEqual(t.TempDir(), filepath.Join(t.TempDir(), "nonexistent"))) + assert.Equal(t, false, file.DirsEqual(t.TempDir(), filepath.Join(t.TempDir(), "nonexistent"))) }) t.Run("non-empty directory", func(t *testing.T) { // Start with directories that do not have the same contents. tmpDir1, tmpFileNames := tmpDirWithContents(t) tmpDir2 := filepath.Join(t.TempDir(), "newfolder") - assert.Equal(t, false, fileutil.DirsEqual(tmpDir1, tmpDir2)) + assert.Equal(t, false, file.DirsEqual(tmpDir1, tmpDir2)) // Copy dir, and retest (hashes should match now). - require.NoError(t, fileutil.CopyDir(tmpDir1, tmpDir2)) - assert.Equal(t, true, fileutil.DirsEqual(tmpDir1, tmpDir2)) + require.NoError(t, file.CopyDir(tmpDir1, tmpDir2)) + assert.Equal(t, true, file.DirsEqual(tmpDir1, tmpDir2)) // Tamper the data, make sure that hashes do not match anymore. require.NoError(t, os.Remove(filepath.Join(tmpDir1, tmpFileNames[2]))) - assert.Equal(t, false, fileutil.DirsEqual(tmpDir1, tmpDir2)) + assert.Equal(t, false, file.DirsEqual(tmpDir1, tmpDir2)) }) } func TestHashDir(t *testing.T) { t.Run("non-existent directory", func(t *testing.T) { - hash, err := fileutil.HashDir(filepath.Join(t.TempDir(), "nonexistent")) + hash, err := file.HashDir(filepath.Join(t.TempDir(), "nonexistent")) assert.ErrorContains(t, "no such file or directory", err) assert.Equal(t, "", hash) }) t.Run("empty directory", func(t *testing.T) { - hash, err := fileutil.HashDir(t.TempDir()) + hash, err := file.HashDir(t.TempDir()) assert.NoError(t, err) assert.Equal(t, "hashdir:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=", hash) }) t.Run("non-empty directory", func(t *testing.T) { tmpDir, _ := tmpDirWithContents(t) - hash, err := fileutil.HashDir(tmpDir) + hash, err := file.HashDir(tmpDir) assert.NoError(t, err) assert.Equal(t, "hashdir:oSp9wRacwTIrnbgJWcwTvihHfv4B2zRbLYa0GZ7DDk0=", hash) }) @@ -266,7 +266,7 @@ func TestDirFiles(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - outFiles, err := fileutil.DirFiles(tt.path) + outFiles, err := file.DirFiles(tt.path) require.NoError(t, err) sort.Strings(outFiles) @@ -317,7 +317,7 @@ func TestRecursiveFileFind(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - found, _, err := fileutil.RecursiveFileFind(tt.name, tt.root) + found, _, err := file.RecursiveFileFind(tt.name, tt.root) require.NoError(t, err) assert.DeepEqual(t, tt.found, found) @@ -421,7 +421,7 @@ func TestHasReadWritePermissions(t *testing.T) { t.Fatalf("Could not delete temp dir: %v", err) } }) - got, err := fileutil.HasReadWritePermissions(fullPath) + got, err := file.HasReadWritePermissions(fullPath) if (err != nil) != tt.wantErr { t.Errorf("HasReadWritePermissions() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/shared/logutil/BUILD.bazel b/io/logs/BUILD.bazel similarity index 91% rename from shared/logutil/BUILD.bazel rename to io/logs/BUILD.bazel index 0cdedaa6b..d7e53099b 100644 --- a/shared/logutil/BUILD.bazel +++ b/io/logs/BUILD.bazel @@ -6,7 +6,7 @@ go_library( "logutil.go", "stream.go", ], - importpath = "github.com/prysmaticlabs/prysm/shared/logutil", + importpath = "github.com/prysmaticlabs/prysm/io/logs", visibility = ["//visibility:public"], deps = [ "//cache/lru:go_default_library", diff --git a/shared/logutil/logutil.go b/io/logs/logutil.go similarity index 95% rename from shared/logutil/logutil.go rename to io/logs/logutil.go index b66c22649..a40d8bce8 100644 --- a/shared/logutil/logutil.go +++ b/io/logs/logutil.go @@ -1,6 +1,6 @@ -// Package logutil creates a Multi writer instance that +// Package logs creates a Multi writer instance that // write all logs that are written to stdout. -package logutil +package logs import ( "io" diff --git a/shared/logutil/logutil_test.go b/io/logs/logutil_test.go similarity index 97% rename from shared/logutil/logutil_test.go rename to io/logs/logutil_test.go index e1209eea2..85d914566 100644 --- a/shared/logutil/logutil_test.go +++ b/io/logs/logutil_test.go @@ -1,4 +1,4 @@ -package logutil +package logs import ( "testing" diff --git a/shared/logutil/stream.go b/io/logs/stream.go similarity index 99% rename from shared/logutil/stream.go rename to io/logs/stream.go index 75ce3d841..a73935b6b 100644 --- a/shared/logutil/stream.go +++ b/io/logs/stream.go @@ -1,4 +1,4 @@ -package logutil +package logs import ( "io" diff --git a/shared/logutil/stream_test.go b/io/logs/stream_test.go similarity index 96% rename from shared/logutil/stream_test.go rename to io/logs/stream_test.go index acec95250..819fab54c 100644 --- a/shared/logutil/stream_test.go +++ b/io/logs/stream_test.go @@ -1,4 +1,4 @@ -package logutil +package logs import ( "testing" diff --git a/shared/promptutil/BUILD.bazel b/io/prompt/BUILD.bazel similarity index 87% rename from shared/promptutil/BUILD.bazel rename to io/prompt/BUILD.bazel index 241382ce0..dc5d36062 100644 --- a/shared/promptutil/BUILD.bazel +++ b/io/prompt/BUILD.bazel @@ -6,10 +6,10 @@ go_library( "prompt.go", "validate.go", ], - importpath = "github.com/prysmaticlabs/prysm/shared/promptutil", + importpath = "github.com/prysmaticlabs/prysm/io/prompt", visibility = ["//visibility:public"], deps = [ - "//shared/fileutil:go_default_library", + "//io/file:go_default_library", "@com_github_logrusorgru_aurora//:go_default_library", "@com_github_nbutton23_zxcvbn_go//:go_default_library", "@com_github_pkg_errors//:go_default_library", diff --git a/shared/promptutil/prompt.go b/io/prompt/prompt.go similarity index 97% rename from shared/promptutil/prompt.go rename to io/prompt/prompt.go index e8c71f208..3234142a0 100644 --- a/shared/promptutil/prompt.go +++ b/io/prompt/prompt.go @@ -1,4 +1,4 @@ -package promptutil +package prompt import ( "bufio" @@ -10,7 +10,7 @@ import ( "github.com/logrusorgru/aurora" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" "golang.org/x/crypto/ssh/terminal" @@ -128,7 +128,7 @@ func InputPassword( ) (string, error) { if cliCtx.IsSet(passwordFileFlag.Name) { passwordFilePathInput := cliCtx.String(passwordFileFlag.Name) - passwordFilePath, err := fileutil.ExpandPath(passwordFilePathInput) + passwordFilePath, err := file.ExpandPath(passwordFilePathInput) if err != nil { return "", errors.Wrap(err, "could not determine absolute path of password file") } diff --git a/shared/promptutil/validate.go b/io/prompt/validate.go similarity index 99% rename from shared/promptutil/validate.go rename to io/prompt/validate.go index f282293a3..829ce0bfc 100644 --- a/shared/promptutil/validate.go +++ b/io/prompt/validate.go @@ -1,4 +1,4 @@ -package promptutil +package prompt import ( "errors" diff --git a/shared/promptutil/validate_test.go b/io/prompt/validate_test.go similarity index 99% rename from shared/promptutil/validate_test.go rename to io/prompt/validate_test.go index 7106834bd..86043db09 100644 --- a/shared/promptutil/validate_test.go +++ b/io/prompt/validate_test.go @@ -1,4 +1,4 @@ -package promptutil +package prompt import ( "io/ioutil" diff --git a/shared/mathutil/BUILD.bazel b/math/BUILD.bazel similarity index 87% rename from shared/mathutil/BUILD.bazel rename to math/BUILD.bazel index f8889bf8c..a07d49000 100644 --- a/shared/mathutil/BUILD.bazel +++ b/math/BUILD.bazel @@ -3,7 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", srcs = ["math_helper.go"], - importpath = "github.com/prysmaticlabs/prysm/shared/mathutil", + importpath = "github.com/prysmaticlabs/prysm/math", visibility = ["//visibility:public"], deps = ["@com_github_thomaso_mirodin_intmath//u64:go_default_library"], ) diff --git a/shared/mathutil/math_helper.go b/math/math_helper.go similarity index 94% rename from shared/mathutil/math_helper.go rename to math/math_helper.go index dbca7ae27..6a36841a9 100644 --- a/shared/mathutil/math_helper.go +++ b/math/math_helper.go @@ -1,9 +1,9 @@ -// Package mathutil includes important helpers for Ethereum such as fast integer square roots. -package mathutil +// Package math includes important helpers for Ethereum such as fast integer square roots. +package math import ( "errors" - "math" + stdmath "math" "math/bits" "github.com/thomaso-mirodin/intmath/u64" @@ -37,7 +37,7 @@ func IntegerSquareRoot(n uint64) uint64 { return u64.Sqrt(n) } - return uint64(math.Sqrt(float64(n))) + return uint64(stdmath.Sqrt(float64(n))) } // CeilDiv8 divides the input number by 8 diff --git a/shared/mathutil/math_helper_test.go b/math/math_helper_test.go similarity index 84% rename from shared/mathutil/math_helper_test.go rename to math/math_helper_test.go index 858733eb8..7c1a0bb9c 100644 --- a/shared/mathutil/math_helper_test.go +++ b/math/math_helper_test.go @@ -1,10 +1,10 @@ -package mathutil_test +package math_test import ( - "math" + stdmath "math" "testing" - "github.com/prysmaticlabs/prysm/shared/mathutil" + "github.com/prysmaticlabs/prysm/math" "github.com/prysmaticlabs/prysm/shared/testutil/require" ) @@ -80,28 +80,28 @@ func TestIntegerSquareRoot(t *testing.T) { } for _, testVals := range tt { - require.Equal(t, testVals.root, mathutil.IntegerSquareRoot(testVals.number)) + require.Equal(t, testVals.root, math.IntegerSquareRoot(testVals.number)) } } func BenchmarkIntegerSquareRootBelow52Bits(b *testing.B) { val := uint64(1 << 33) for i := 0; i < b.N; i++ { - require.Equal(b, uint64(92681), mathutil.IntegerSquareRoot(val)) + require.Equal(b, uint64(92681), math.IntegerSquareRoot(val)) } } func BenchmarkIntegerSquareRootAbove52Bits(b *testing.B) { val := uint64(1 << 62) for i := 0; i < b.N; i++ { - require.Equal(b, uint64(1<<31), mathutil.IntegerSquareRoot(val)) + require.Equal(b, uint64(1<<31), math.IntegerSquareRoot(val)) } } func BenchmarkIntegerSquareRoot_WithDatatable(b *testing.B) { val := uint64(1024) for i := 0; i < b.N; i++ { - require.Equal(b, uint64(32), mathutil.IntegerSquareRoot(val)) + require.Equal(b, uint64(32), math.IntegerSquareRoot(val)) } } @@ -133,7 +133,7 @@ func TestCeilDiv8(t *testing.T) { } for _, tt := range tests { - require.Equal(t, tt.div8, mathutil.CeilDiv8(tt.number)) + require.Equal(t, tt.div8, math.CeilDiv8(tt.number)) } } @@ -164,7 +164,7 @@ func TestIsPowerOf2(t *testing.T) { }, } for _, tt := range tests { - require.Equal(t, tt.b, mathutil.IsPowerOf2(tt.a)) + require.Equal(t, tt.b, math.IsPowerOf2(tt.a)) } } @@ -191,7 +191,7 @@ func TestPowerOf2(t *testing.T) { }, } for _, tt := range tests { - require.Equal(t, tt.b, mathutil.PowerOf2(tt.a)) + require.Equal(t, tt.b, math.PowerOf2(tt.a)) } } @@ -228,7 +228,7 @@ func TestMaxValue(t *testing.T) { }, } for _, tt := range tests { - require.Equal(t, tt.result, mathutil.Max(tt.a, tt.b)) + require.Equal(t, tt.result, math.Max(tt.a, tt.b)) } } @@ -265,7 +265,7 @@ func TestMinValue(t *testing.T) { }, } for _, tt := range tests { - require.Equal(t, tt.result, mathutil.Min(tt.a, tt.b)) + require.Equal(t, tt.result, math.Min(tt.a, tt.b)) } } @@ -290,7 +290,7 @@ func TestMul64(t *testing.T) { {args: args{1 << 63, 2}, res: 0, err: true}, } for _, tt := range tests { - got, err := mathutil.Mul64(tt.args.a, tt.args.b) + got, err := math.Mul64(tt.args.a, tt.args.b) if tt.err && err == nil { t.Errorf("Mul64() Expected Error = %v, want error", tt.err) continue @@ -317,12 +317,12 @@ func TestAdd64(t *testing.T) { {args: args{1 << 31, 1 << 31}, res: 4294967296, err: false}, {args: args{1 << 63, 1 << 63}, res: 0, err: true}, {args: args{1 << 63, 1}, res: 9223372036854775809, err: false}, - {args: args{math.MaxUint64, 1}, res: 0, err: true}, - {args: args{math.MaxUint64, 0}, res: math.MaxUint64, err: false}, + {args: args{stdmath.MaxUint64, 1}, res: 0, err: true}, + {args: args{stdmath.MaxUint64, 0}, res: stdmath.MaxUint64, err: false}, {args: args{1 << 63, 2}, res: 9223372036854775810, err: false}, } for _, tt := range tests { - got, err := mathutil.Add64(tt.args.a, tt.args.b) + got, err := math.Add64(tt.args.a, tt.args.b) if tt.err && err == nil { t.Errorf("Add64() Expected Error = %v, want error", tt.err) continue diff --git a/nogo_config.json b/nogo_config.json index 1dbc8cdef..bf8b14d6a 100644 --- a/nogo_config.json +++ b/nogo_config.json @@ -151,7 +151,7 @@ }, "exclude_files": { ".*_test\\.go": "Tests are ok", - "shared/fileutil/fileutil.go": "Package which defines the proper rules" + "io/file/fileutil.go": "Package which defines the proper rules" } } } diff --git a/runtime/tos/BUILD.bazel b/runtime/tos/BUILD.bazel index ef013f767..cb605e835 100644 --- a/runtime/tos/BUILD.bazel +++ b/runtime/tos/BUILD.bazel @@ -6,9 +6,9 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/runtime/tos", visibility = ["//visibility:public"], deps = [ + "//io/file:go_default_library", + "//io/prompt:go_default_library", "//shared/cmd:go_default_library", - "//shared/fileutil:go_default_library", - "//shared/promptutil:go_default_library", "@com_github_logrusorgru_aurora//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@com_github_urfave_cli_v2//:go_default_library", diff --git a/runtime/tos/tos.go b/runtime/tos/tos.go index 9a69d52c6..ca74d87fd 100644 --- a/runtime/tos/tos.go +++ b/runtime/tos/tos.go @@ -6,9 +6,9 @@ import ( "strings" "github.com/logrusorgru/aurora" + "github.com/prysmaticlabs/prysm/io/file" + "github.com/prysmaticlabs/prysm/io/prompt" "github.com/prysmaticlabs/prysm/shared/cmd" - "github.com/prysmaticlabs/prysm/shared/fileutil" - "github.com/prysmaticlabs/prysm/shared/promptutil" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) @@ -41,7 +41,7 @@ func VerifyTosAcceptedOrPrompt(ctx *cli.Context) error { return nil } - if fileutil.FileExists(filepath.Join(ctx.String(cmd.DataDirFlag.Name), acceptTosFilename)) { + if file.FileExists(filepath.Join(ctx.String(cmd.DataDirFlag.Name), acceptTosFilename)) { return nil } if ctx.Bool(cmd.AcceptTosFlag.Name) { @@ -49,7 +49,7 @@ func VerifyTosAcceptedOrPrompt(ctx *cli.Context) error { return nil } - input, err := promptutil.DefaultPrompt(au.Bold(acceptTosPromptText).String(), "decline") + input, err := prompt.DefaultPrompt(au.Bold(acceptTosPromptText).String(), "decline") if err != nil { return errors.New(acceptTosPromptErrText) } @@ -64,16 +64,16 @@ func VerifyTosAcceptedOrPrompt(ctx *cli.Context) error { // saveTosAccepted creates a file when Tos accepted. func saveTosAccepted(ctx *cli.Context) { dataDir := ctx.String(cmd.DataDirFlag.Name) - dataDirExists, err := fileutil.HasDir(dataDir) + dataDirExists, err := file.HasDir(dataDir) if err != nil { log.WithError(err).Warnf("error checking directory: %s", dataDir) } if !dataDirExists { - if err := fileutil.MkdirAll(dataDir); err != nil { + if err := file.MkdirAll(dataDir); err != nil { log.WithError(err).Warnf("error creating directory: %s", dataDir) } } - if err := fileutil.WriteFile(filepath.Join(dataDir, acceptTosFilename), []byte("")); err != nil { + if err := file.WriteFile(filepath.Join(dataDir, acceptTosFilename), []byte("")); err != nil { log.WithError(err).Warnf("error writing %s to file: %s", cmd.AcceptTosFlag.Name, filepath.Join(dataDir, acceptTosFilename)) } diff --git a/runtime/tos/tos_test.go b/runtime/tos/tos_test.go index 6b7ea9db8..755447ddb 100644 --- a/runtime/tos/tos_test.go +++ b/runtime/tos/tos_test.go @@ -25,14 +25,14 @@ func TestVerifyTosAcceptedOrPrompt(t *testing.T) { os.Stdin = tmpfile defer func() { os.Stdin = origStdin }() - // prompt decline + // userprompt decline _, err = tmpfile.Write([]byte("decline")) require.NoError(t, err) _, err = tmpfile.Seek(0, 0) require.NoError(t, err) require.ErrorContains(t, "you have to accept Terms and Conditions", VerifyTosAcceptedOrPrompt(context)) - // prompt accept + // userprompt accept err = tmpfile.Truncate(0) require.NoError(t, err) _, err = tmpfile.Seek(0, 0) diff --git a/shared/cmd/BUILD.bazel b/shared/cmd/BUILD.bazel index 6687c153f..7f401c2e6 100644 --- a/shared/cmd/BUILD.bazel +++ b/shared/cmd/BUILD.bazel @@ -14,7 +14,7 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/shared/cmd", visibility = ["//visibility:public"], deps = [ - "//shared/fileutil:go_default_library", + "//io/file:go_default_library", "//shared/params:go_default_library", "@com_github_golang_mock//gomock:go_default_library", "@com_github_pkg_errors//:go_default_library", diff --git a/shared/cmd/defaults.go b/shared/cmd/defaults.go index 9508c705b..35916e667 100644 --- a/shared/cmd/defaults.go +++ b/shared/cmd/defaults.go @@ -22,14 +22,14 @@ import ( "path/filepath" "runtime" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" ) // DefaultDataDir is the default data directory to use for the databases and other // persistence requirements. func DefaultDataDir() string { // Try to place the data folder in the user's home dir - home := fileutil.HomeDir() + home := file.HomeDir() if home != "" { if runtime.GOOS == "darwin" { return filepath.Join(home, "Library", "Eth2") @@ -52,17 +52,17 @@ func FixDefaultDataDir(prevDataDir, curDataDir string) error { } // Clean paths. - prevDataDir, err := fileutil.ExpandPath(prevDataDir) + prevDataDir, err := file.ExpandPath(prevDataDir) if err != nil { return err } - curDataDir, err = fileutil.ExpandPath(curDataDir) + curDataDir, err = file.ExpandPath(curDataDir) if err != nil { return err } // See if shared directory is found (if it is -- we need to move it to non-shared destination). - prevDataDirExists, err := fileutil.HasDir(prevDataDir) + prevDataDirExists, err := file.HasDir(prevDataDir) if err != nil { return err } @@ -74,7 +74,7 @@ func FixDefaultDataDir(prevDataDir, curDataDir string) error { if curDataDir == "" { curDataDir = DefaultDataDir() } - selectedDirExists, err := fileutil.HasDir(curDataDir) + selectedDirExists, err := file.HasDir(curDataDir) if err != nil { return err } @@ -94,7 +94,7 @@ func FixDefaultDataDir(prevDataDir, curDataDir string) error { log.Warnf("Outdated data directory is found: %s. "+ "Copying its contents to the new data folder: %s", prevDataDir, curDataDir) - if err := fileutil.CopyDir(prevDataDir, curDataDir); err != nil { + if err := file.CopyDir(prevDataDir, curDataDir); err != nil { return err } log.Infof("All files from the outdated data directory %s have been moved to %s.", prevDataDir, curDataDir) @@ -107,7 +107,7 @@ func FixDefaultDataDir(prevDataDir, curDataDir string) error { if err != nil { return err } - if removeConfirmed && fileutil.DirsEqual(prevDataDir, curDataDir) { + if removeConfirmed && file.DirsEqual(prevDataDir, curDataDir) { if err := os.RemoveAll(prevDataDir); err != nil { return fmt.Errorf("cannot remove outdated directory or one of its files: %w", err) } diff --git a/shared/cmd/helpers.go b/shared/cmd/helpers.go index 765371fa2..e65f84677 100644 --- a/shared/cmd/helpers.go +++ b/shared/cmd/helpers.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) @@ -86,7 +86,7 @@ func ExpandSingleEndpointIfFile(ctx *cli.Context, flag *cli.StringFlag) error { case strings.HasPrefix(web3endpoint, "ws://"): case strings.HasPrefix(web3endpoint, "wss://"): default: - web3endpoint, err := fileutil.ExpandPath(ctx.String(flag.Name)) + web3endpoint, err := file.ExpandPath(ctx.String(flag.Name)) if err != nil { return errors.Wrapf(err, "could not expand path for %s", web3endpoint) } @@ -111,7 +111,7 @@ func ExpandWeb3EndpointsIfFile(ctx *cli.Context, flags *cli.StringSliceFlag) err case strings.HasPrefix(rawValue, "ws://"): case strings.HasPrefix(rawValue, "wss://"): default: - web3endpoint, err := fileutil.ExpandPath(rawValue) + web3endpoint, err := file.ExpandPath(rawValue) if err != nil { return errors.Wrapf(err, "could not expand path for %s", rawValue) } diff --git a/shared/params/BUILD.bazel b/shared/params/BUILD.bazel index 247aa2c99..b23b85645 100644 --- a/shared/params/BUILD.bazel +++ b/shared/params/BUILD.bazel @@ -20,8 +20,8 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/shared/params", visibility = ["//visibility:public"], deps = [ + "//math:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/mathutil:go_default_library", "@com_github_ethereum_go_ethereum//params:go_default_library", "@com_github_mohae_deepcopy//:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", diff --git a/shared/params/loader.go b/shared/params/loader.go index 920a94a94..2066e84fe 100644 --- a/shared/params/loader.go +++ b/shared/params/loader.go @@ -6,7 +6,7 @@ import ( "strings" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/shared/mathutil" + "github.com/prysmaticlabs/prysm/math" log "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" ) @@ -45,7 +45,7 @@ func LoadChainConfigFile(chainConfigFileName string) { } } // recompute SqrRootSlotsPerEpoch constant to handle non-standard values of SlotsPerEpoch - conf.SqrRootSlotsPerEpoch = types.Slot(mathutil.IntegerSquareRoot(uint64(conf.SlotsPerEpoch))) + conf.SqrRootSlotsPerEpoch = types.Slot(math.IntegerSquareRoot(uint64(conf.SlotsPerEpoch))) log.Debugf("Config file values: %+v", conf) OverrideBeaconConfig(conf) } diff --git a/shared/petnames/names.go b/shared/petnames/names.go index cfcf3bb08..bd0eed7f6 100644 --- a/shared/petnames/names.go +++ b/shared/petnames/names.go @@ -8,7 +8,7 @@ import ( ) var ( - adjectives = []string{"able", "above", "absolute", "accepted", "accurate", "ace", "active", "actual", "adapted", "adapting", "adequate", "adjusted", "advanced", "alert", "alive", "allowed", "allowing", "amazed", "amazing", "ample", "amused", "amusing", "apparent", "apt", "arriving", "artistic", "assured", "assuring", "awaited", "awake", "aware", "balanced", "becoming", "beloved", "better", "big", "blessed", "bold", "boss", "brave", "brief", "bright", "bursting", "busy", "calm", "capable", "capital", "careful", "caring", "casual", "causal", "central", "certain", "champion", "charmed", "charming", "cheerful", "chief", "choice", "civil", "classic", "clean", "clear", "clever", "climbing", "close", "closing", "coherent", "comic", "communal", "complete", "composed", "concise", "concrete", "content", "cool", "correct", "cosmic", "crack", "creative", "credible", "crisp", "crucial", "cuddly", "cunning", "curious", "current", "cute", "daring", "darling", "dashing", "dear", "decent", "deciding", "deep", "definite", "delicate", "desired", "destined", "devoted", "direct", "discrete", "distinct", "diverse", "divine", "dominant", "driven", "driving", "dynamic", "eager", "easy", "electric", "elegant", "emerging", "eminent", "enabled", "enabling", "endless", "engaged", "engaging", "enhanced", "enjoyed", "enormous", "enough", "epic", "equal", "equipped", "eternal", "ethical", "evident", "evolved", "evolving", "exact", "excited", "exciting", "exotic", "expert", "factual", "fair", "faithful", "famous", "fancy", "fast", "feasible", "fine", "finer", "firm", "first", "fit", "fitting", "fleet", "flexible", "flowing", "fluent", "flying", "fond", "frank", "free", "fresh", "full", "fun", "funky", "funny", "game", "generous", "gentle", "genuine", "giving", "glad", "glorious", "glowing", "golden", "good", "gorgeous", "grand", "grateful", "great", "growing", "grown", "guided", "guiding", "handy", "happy", "hardy", "harmless", "healthy", "helped", "helpful", "helping", "heroic", "hip", "holy", "honest", "hopeful", "hot", "huge", "humane", "humble", "humorous", "ideal", "immense", "immortal", "immune", "improved", "in", "included", "infinite", "informed", "innocent", "inspired", "integral", "intense", "intent", "internal", "intimate", "inviting", "joint", "just", "keen", "key", "kind", "knowing", "known", "large", "lasting", "leading", "learning", "legal", "legible", "lenient", "liberal", "light", "liked", "literate", "live", "living", "logical", "loved", "loving", "loyal", "lucky", "magical", "magnetic", "main", "major", "many", "massive", "master", "mature", "maximum", "measured", "meet", "merry", "mighty", "mint", "model", "modern", "modest", "moral", "more", "moved", "moving", "musical", "mutual", "national", "native", "natural", "nearby", "neat", "needed", "neutral", "new", "next", "nice", "noble", "normal", "notable", "noted", "novel", "obliging", "on", "one", "open", "optimal", "optimum", "organic", "oriented", "outgoing", "patient", "peaceful", "perfect", "pet", "picked", "pleasant", "pleased", "pleasing", "poetic", "polished", "polite", "popular", "positive", "possible", "powerful", "precious", "precise", "premium", "prepared", "present", "pretty", "primary", "prime", "pro", "probable", "profound", "promoted", "prompt", "proper", "proud", "proven", "pumped", "pure", "quality", "quick", "quiet", "rapid", "rare", "rational", "ready", "real", "refined", "regular", "related", "relative", "relaxed", "relaxing", "relevant", "relieved", "renewed", "renewing", "resolved", "rested", "rich", "right", "robust", "romantic", "ruling", "sacred", "safe", "saved", "saving", "secure", "select", "selected", "sensible", "set", "settled", "settling", "sharing", "sharp", "shining", "simple", "sincere", "singular", "skilled", "smart", "smashing", "smiling", "smooth", "social", "solid", "sought", "sound", "special", "splendid", "square", "stable", "star", "steady", "sterling", "still", "stirred", "stirring", "striking", "strong", "stunning", "subtle", "suitable", "suited", "summary", "sunny", "super", "superb", "supreme", "sure", "sweeping", "sweet", "talented", "teaching", "tender", "thankful", "thorough", "tidy", "tight", "together", "tolerant", "top", "topical", "tops", "touched", "touching", "tough", "true", "trusted", "trusting", "trusty", "ultimate", "unbiased", "uncommon", "unified", "unique", "united", "up", "upright", "upward", "usable", "useful", "valid", "valued", "vast", "verified", "viable", "vital", "vocal", "wanted", "warm", "wealthy", "welcome", "welcomed", "well", "whole", "willing", "winning", "wired", "wise", "witty", "wondrous", "workable", "working", "worthy"} + adjectives = []string{"able", "above", "absolute", "accepted", "accurate", "ace", "active", "actual", "adapted", "adapting", "adequate", "adjusted", "advanced", "alert", "alive", "allowed", "allowing", "amazed", "amazing", "ample", "amused", "amusing", "apparent", "apt", "arriving", "artistic", "assured", "assuring", "awaited", "awake", "aware", "balanced", "becoming", "beloved", "better", "big", "blessed", "bold", "boss", "brave", "brief", "bright", "bursting", "busy", "calm", "capable", "capital", "careful", "caring", "casual", "causal", "central", "certain", "champion", "charmed", "charming", "cheerful", "chief", "choice", "civil", "classic", "clean", "clear", "clever", "climbing", "close", "closing", "coherent", "comic", "communal", "complete", "composed", "concise", "concrete", "content", "cool", "correct", "cosmic", "crack", "creative", "credible", "crisp", "crucial", "cuddly", "cunning", "curious", "current", "cute", "daring", "darling", "dashing", "dear", "decent", "deciding", "deep", "definite", "delicate", "desired", "destined", "devoted", "direct", "discrete", "distinct", "diverse", "divine", "dominant", "driven", "driving", "dynamic", "eager", "easy", "electric", "elegant", "emerging", "eminent", "enabled", "enabling", "endless", "engaged", "engaging", "enhanced", "enjoyed", "enormous", "enough", "epic", "equal", "equipped", "eternal", "ethical", "evident", "evolved", "evolving", "exact", "excited", "exciting", "exotic", "expert", "factual", "fair", "faithful", "famous", "fancy", "fast", "feasible", "fine", "finer", "firm", "first", "fit", "fitting", "fleet", "flexible", "flowing", "fluent", "flying", "fond", "frank", "free", "fresh", "full", "fun", "funky", "funny", "game", "generous", "gentle", "genuine", "giving", "glad", "glorious", "glowing", "golden", "good", "gorgeous", "grand", "grateful", "great", "growing", "grown", "guided", "guiding", "handy", "happy", "hardy", "harmless", "healthy", "helped", "helpful", "helping", "heroic", "hip", "holy", "honest", "hopeful", "hot", "huge", "humane", "humble", "humorous", "ideal", "immense", "immortal", "immune", "improved", "in", "included", "infinite", "informed", "innocent", "inspired", "integral", "intense", "intent", "internal", "intimate", "inviting", "joint", "just", "keen", "key", "kind", "knowing", "known", "large", "lasting", "leading", "learning", "legal", "legible", "lenient", "liberal", "light", "liked", "literate", "live", "living", "logical", "loved", "loving", "loyal", "lucky", "magical", "magnetic", "main", "major", "many", "massive", "master", "mature", "maximum", "measured", "meet", "merry", "mighty", "mint", "model", "modern", "modest", "moral", "more", "moved", "moving", "musical", "mutual", "national", "native", "natural", "nearby", "neat", "needed", "neutral", "new", "next", "nice", "noble", "normal", "notable", "noted", "novel", "obliging", "on", "one", "open", "optimal", "optimum", "organic", "oriented", "outgoing", "patient", "peaceful", "perfect", "pet", "picked", "pleasant", "pleased", "pleasing", "poetic", "polished", "polite", "popular", "positive", "possible", "powerful", "precious", "precise", "premium", "prepared", "present", "pretty", "primary", "prime", "pro", "probable", "profound", "promoted", "userprompt", "proper", "proud", "proven", "pumped", "pure", "quality", "quick", "quiet", "rapid", "rare", "rational", "ready", "real", "refined", "regular", "related", "relative", "relaxed", "relaxing", "relevant", "relieved", "renewed", "renewing", "resolved", "rested", "rich", "right", "robust", "romantic", "ruling", "sacred", "safe", "saved", "saving", "secure", "select", "selected", "sensible", "set", "settled", "settling", "sharing", "sharp", "shining", "simple", "sincere", "singular", "skilled", "smart", "smashing", "smiling", "smooth", "social", "solid", "sought", "sound", "special", "splendid", "square", "stable", "star", "steady", "sterling", "still", "stirred", "stirring", "striking", "strong", "stunning", "subtle", "suitable", "suited", "summary", "sunny", "super", "superb", "supreme", "sure", "sweeping", "sweet", "talented", "teaching", "tender", "thankful", "thorough", "tidy", "tight", "together", "tolerant", "top", "topical", "tops", "touched", "touching", "tough", "true", "trusted", "trusting", "trusty", "ultimate", "unbiased", "uncommon", "unified", "unique", "united", "up", "upright", "upward", "usable", "useful", "valid", "valued", "vast", "verified", "viable", "vital", "vocal", "wanted", "warm", "wealthy", "welcome", "welcomed", "well", "whole", "willing", "winning", "wired", "wise", "witty", "wondrous", "workable", "working", "worthy"} adverbs = []string{"abnormally", "absolutely", "accurately", "actively", "actually", "adequately", "admittedly", "adversely", "allegedly", "amazingly", "annually", "apparently", "arguably", "awfully", "badly", "barely", "basically", "blatantly", "blindly", "briefly", "brightly", "broadly", "carefully", "centrally", "certainly", "cheaply", "cleanly", "clearly", "closely", "commonly", "completely", "constantly", "conversely", "correctly", "curiously", "currently", "daily", "deadly", "deeply", "definitely", "directly", "distinctly", "duly", "eagerly", "early", "easily", "eminently", "endlessly", "enormously", "entirely", "equally", "especially", "evenly", "evidently", "exactly", "explicitly", "externally", "extremely", "factually", "fairly", "finally", "firmly", "firstly", "forcibly", "formally", "formerly", "frankly", "freely", "frequently", "friendly", "fully", "generally", "gently", "genuinely", "ghastly", "gladly", "globally", "gradually", "gratefully", "greatly", "grossly", "happily", "hardly", "heartily", "heavily", "hideously", "highly", "honestly", "hopefully", "hopelessly", "horribly", "hugely", "humbly", "ideally", "illegally", "immensely", "implicitly", "incredibly", "indirectly", "infinitely", "informally", "inherently", "initially", "instantly", "intensely", "internally", "jointly", "jolly", "kindly", "largely", "lately", "legally", "lightly", "likely", "literally", "lively", "locally", "logically", "loosely", "loudly", "lovely", "luckily", "mainly", "manually", "marginally", "mentally", "merely", "mildly", "miserably", "mistakenly", "moderately", "monthly", "morally", "mostly", "multiply", "mutually", "namely", "nationally", "naturally", "nearly", "neatly", "needlessly", "newly", "nicely", "nominally", "normally", "notably", "noticeably", "obviously", "oddly", "officially", "only", "openly", "optionally", "overly", "painfully", "partially", "partly", "perfectly", "personally", "physically", "plainly", "pleasantly", "poorly", "positively", "possibly", "precisely", "preferably", "presently", "presumably", "previously", "primarily", "privately", "probably", "promptly", "properly", "publicly", "purely", "quickly", "quietly", "radically", "randomly", "rapidly", "rarely", "rationally", "readily", "really", "reasonably", "recently", "regularly", "reliably", "remarkably", "remotely", "repeatedly", "rightly", "roughly", "routinely", "sadly", "safely", "scarcely", "secondly", "secretly", "seemingly", "sensibly", "separately", "seriously", "severely", "sharply", "shortly", "similarly", "simply", "sincerely", "singularly", "slightly", "slowly", "smoothly", "socially", "solely", "specially", "steadily", "strangely", "strictly", "strongly", "subtly", "suddenly", "suitably", "supposedly", "surely", "terminally", "terribly", "thankfully", "thoroughly", "tightly", "totally", "trivially", "truly", "typically", "ultimately", "unduly", "uniformly", "uniquely", "unlikely", "urgently", "usefully", "usually", "utterly", "vaguely", "vastly", "verbally", "vertically", "vigorously", "violently", "virtually", "visually", "weekly", "wholly", "widely", "wildly", "willingly", "wrongly", "yearly"} names = []string{"ox", "ant", "ape", "asp", "bat", "bee", "boa", "bug", "cat", "cod", "cow", "cub", "doe", "dog", "eel", "eft", "elf", "elk", "emu", "ewe", "fly", "fox", "gar", "gnu", "hen", "hog", "imp", "jay", "kid", "kit", "koi", "lab", "man", "owl", "pig", "pug", "pup", "ram", "rat", "ray", "yak", "bass", "bear", "bird", "boar", "buck", "bull", "calf", "chow", "clam", "colt", "crab", "crow", "dane", "deer", "dodo", "dory", "dove", "drum", "duck", "fawn", "fish", "flea", "foal", "fowl", "frog", "gnat", "goat", "grub", "gull", "hare", "hawk", "ibex", "joey", "kite", "kiwi", "lamb", "lark", "lion", "loon", "lynx", "mako", "mink", "mite", "mole", "moth", "mule", "mutt", "newt", "orca", "oryx", "pika", "pony", "puma", "seal", "shad", "slug", "sole", "stag", "stud", "swan", "tahr", "teal", "tick", "toad", "tuna", "wasp", "wolf", "worm", "wren", "yeti", "adder", "akita", "alien", "aphid", "bison", "boxer", "bream", "bunny", "burro", "camel", "chimp", "civet", "cobra", "coral", "corgi", "crane", "dingo", "drake", "eagle", "egret", "filly", "finch", "gator", "gecko", "ghost", "ghoul", "goose", "guppy", "heron", "hippo", "horse", "hound", "husky", "hyena", "koala", "krill", "leech", "lemur", "liger", "llama", "louse", "macaw", "midge", "molly", "moose", "moray", "mouse", "panda", "perch", "prawn", "quail", "racer", "raven", "rhino", "robin", "satyr", "shark", "sheep", "shrew", "skink", "skunk", "sloth", "snail", "snake", "snipe", "squid", "stork", "swift", "swine", "tapir", "tetra", "tiger", "troll", "trout", "viper", "wahoo", "whale", "zebra", "alpaca", "amoeba", "baboon", "badger", "beagle", "bedbug", "beetle", "bengal", "bobcat", "caiman", "cattle", "cicada", "collie", "condor", "cougar", "coyote", "dassie", "donkey", "dragon", "earwig", "falcon", "feline", "ferret", "gannet", "gibbon", "glider", "goblin", "gopher", "grouse", "guinea", "hermit", "hornet", "iguana", "impala", "insect", "jackal", "jaguar", "jennet", "kitten", "kodiak", "lizard", "locust", "maggot", "magpie", "mammal", "mantis", "marlin", "marmot", "marten", "martin", "mayfly", "minnow", "monkey", "mullet", "muskox", "ocelot", "oriole", "osprey", "oyster", "parrot", "pigeon", "piglet", "poodle", "possum", "python", "quagga", "rabbit", "raptor", "rodent", "roughy", "salmon", "sawfly", "serval", "shiner", "shrimp", "spider", "sponge", "tarpon", "thrush", "tomcat", "toucan", "turkey", "turtle", "urchin", "vervet", "walrus", "weasel", "weevil", "wombat", "anchovy", "anemone", "bluejay", "buffalo", "bulldog", "buzzard", "caribou", "catfish", "chamois", "cheetah", "chicken", "chigger", "cowbird", "crappie", "crawdad", "cricket", "dogfish", "dolphin", "firefly", "garfish", "gazelle", "gelding", "giraffe", "gobbler", "gorilla", "goshawk", "grackle", "griffon", "grizzly", "grouper", "haddock", "hagfish", "halibut", "hamster", "herring", "jackass", "javelin", "jawfish", "jaybird", "katydid", "ladybug", "lamprey", "lemming", "leopard", "lioness", "lobster", "macaque", "mallard", "mammoth", "manatee", "mastiff", "meerkat", "mollusk", "monarch", "mongrel", "monitor", "monster", "mudfish", "muskrat", "mustang", "narwhal", "oarfish", "octopus", "opossum", "ostrich", "panther", "peacock", "pegasus", "pelican", "penguin", "phoenix", "piranha", "polecat", "primate", "quetzal", "raccoon", "rattler", "redbird", "redfish", "reptile", "rooster", "sawfish", "sculpin", "seagull", "skylark", "snapper", "spaniel", "sparrow", "sunbeam", "sunbird", "sunfish", "tadpole", "termite", "terrier", "unicorn", "vulture", "wallaby", "walleye", "warthog", "whippet", "wildcat", "aardvark", "airedale", "albacore", "anteater", "antelope", "arachnid", "barnacle", "basilisk", "blowfish", "bluebird", "bluegill", "bonefish", "bullfrog", "cardinal", "chipmunk", "cockatoo", "crayfish", "dinosaur", "doberman", "duckling", "elephant", "escargot", "flamingo", "flounder", "foxhound", "glowworm", "goldfish", "grubworm", "hedgehog", "honeybee", "hookworm", "humpback", "kangaroo", "killdeer", "kingfish", "labrador", "lacewing", "ladybird", "lionfish", "longhorn", "mackerel", "malamute", "marmoset", "mamoswine", "moccasin", "mongoose", "monkfish", "mosquito", "pangolin", "parakeet", "pheasant", "pipefish", "platypus", "polliwog", "porpoise", "reindeer", "ringtail", "sailfish", "scorpion", "seahorse", "seasnail", "sheepdog", "shepherd", "silkworm", "squirrel", "stallion", "starfish", "starling", "stingray", "stinkbug", "sturgeon", "terrapin", "titmouse", "tortoise", "treefrog", "werewolf", "woodcock"} ) diff --git a/testing/bls/utils/BUILD.bazel b/testing/bls/utils/BUILD.bazel index 1b9de7023..dc51345cd 100644 --- a/testing/bls/utils/BUILD.bazel +++ b/testing/bls/utils/BUILD.bazel @@ -7,7 +7,7 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/testing/bls/utils", visibility = ["//testing/bls:__subpackages__"], deps = [ - "//shared/fileutil:go_default_library", + "//io/file:go_default_library", "//shared/testutil/require:go_default_library", "@io_bazel_rules_go//go/tools/bazel:go_default_library", ], diff --git a/testing/bls/utils/utils.go b/testing/bls/utils/utils.go index 324af9192..d09f1251a 100644 --- a/testing/bls/utils/utils.go +++ b/testing/bls/utils/utils.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/bazelbuild/rules_go/go/tools/bazel" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/shared/testutil/require" ) @@ -24,7 +24,7 @@ func RetrieveFiles(name string, t *testing.T) ([]string, [][]byte) { // Remove .yml suffix fName := strings.TrimSuffix(f.Name(), ".yaml") fileNames = append(fileNames, fName) - data, err := fileutil.ReadFileAsBytes(path.Join(filepath, f.Name())) + data, err := file.ReadFileAsBytes(path.Join(filepath, f.Name())) require.NoError(t, err) fileContent = append(fileContent, data) } diff --git a/tools/analyzers/properpermissions/analyzer.go b/tools/analyzers/properpermissions/analyzer.go index 1c9b3dd20..fe5ffc373 100644 --- a/tools/analyzers/properpermissions/analyzer.go +++ b/tools/analyzers/properpermissions/analyzer.go @@ -1,7 +1,7 @@ // Package properpermissions implements a static analyzer to ensure that Prysm does not // use ioutil.MkdirAll or os.WriteFile as they are unsafe when it comes to guaranteeing // file permissions and not overriding existing permissions. Instead, users are warned -// to utilize shared/fileutil as the canonical solution. +// to utilize shared/file as the canonical solution. package properpermissions import ( @@ -19,7 +19,7 @@ const Doc = "Tool to enforce usage of Prysm's internal file-writing utils instea var ( errUnsafePackage = errors.New( - "os and ioutil dir and file writing functions are not permissions-safe, use shared/fileutil", + "os and ioutil dir and file writing functions are not permissions-safe, use shared/file", ) disallowedFns = []string{"MkdirAll", "WriteFile"} ) diff --git a/tools/analyzers/properpermissions/testdata/custom_imports.go b/tools/analyzers/properpermissions/testdata/custom_imports.go index d0febfa76..87c2ced0b 100644 --- a/tools/analyzers/properpermissions/testdata/custom_imports.go +++ b/tools/analyzers/properpermissions/testdata/custom_imports.go @@ -13,7 +13,7 @@ import ( func UseAliasedPackages() { randPath, _ := rand.Int(rand.Reader, big.NewInt(1000000)) p := filepath.Join(tempDir(), fmt.Sprintf("/%d", randPath)) - _ = osAlias.MkdirAll(p, osAlias.ModePerm) // want "os and ioutil dir and file writing functions are not permissions-safe, use shared/fileutil" + _ = osAlias.MkdirAll(p, osAlias.ModePerm) // want "os and ioutil dir and file writing functions are not permissions-safe, use shared/file" someFile := filepath.Join(p, "some.txt") - _ = ioAlias.WriteFile(someFile, []byte("hello"), osAlias.ModePerm) // want "os and ioutil dir and file writing functions are not permissions-safe, use shared/fileutil" + _ = ioAlias.WriteFile(someFile, []byte("hello"), osAlias.ModePerm) // want "os and ioutil dir and file writing functions are not permissions-safe, use shared/file" } diff --git a/tools/analyzers/properpermissions/testdata/regular_imports.go b/tools/analyzers/properpermissions/testdata/regular_imports.go index d56813b0f..795a73a4c 100644 --- a/tools/analyzers/properpermissions/testdata/regular_imports.go +++ b/tools/analyzers/properpermissions/testdata/regular_imports.go @@ -21,7 +21,7 @@ func tempDir() string { func UseOsMkdirAllAndWriteFile() { randPath, _ := rand.Int(rand.Reader, big.NewInt(1000000)) p := filepath.Join(tempDir(), fmt.Sprintf("/%d", randPath)) - _ = os.MkdirAll(p, os.ModePerm) // want "os and ioutil dir and file writing functions are not permissions-safe, use shared/fileutil" + _ = os.MkdirAll(p, os.ModePerm) // want "os and ioutil dir and file writing functions are not permissions-safe, use shared/file" someFile := filepath.Join(p, "some.txt") - _ = ioutil.WriteFile(someFile, []byte("hello"), os.ModePerm) // want "os and ioutil dir and file writing functions are not permissions-safe, use shared/fileutil" + _ = ioutil.WriteFile(someFile, []byte("hello"), os.ModePerm) // want "os and ioutil dir and file writing functions are not permissions-safe, use shared/file" } diff --git a/tools/beacon-fuzz/BUILD.bazel b/tools/beacon-fuzz/BUILD.bazel index 0454f03f9..72fc4db76 100644 --- a/tools/beacon-fuzz/BUILD.bazel +++ b/tools/beacon-fuzz/BUILD.bazel @@ -6,7 +6,7 @@ go_library( name = "go_default_library", srcs = ["main.go"], deps = [ - "//shared/fileutil:go_default_library", + "//io/file:go_default_library", ], importpath = "github.com/prysmaticlabs/prysm/tools/beacon-fuzz", visibility = ["//visibility:private"], diff --git a/tools/beacon-fuzz/main.go b/tools/beacon-fuzz/main.go index 6038a78c3..88b18c038 100644 --- a/tools/beacon-fuzz/main.go +++ b/tools/beacon-fuzz/main.go @@ -10,7 +10,7 @@ import ( "strconv" "text/template" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" ) var ( @@ -56,7 +56,7 @@ func main() { } res := execTmpl(tpl, input{Package: "testing", MapStr: sszBytesToMapStr(m)}) - if err := fileutil.WriteFile(*output, res.Bytes()); err != nil { + if err := file.WriteFile(*output, res.Bytes()); err != nil { panic(err) } } diff --git a/tools/benchmark-files-gen/BUILD.bazel b/tools/benchmark-files-gen/BUILD.bazel index ec81d4aa6..717f35679 100644 --- a/tools/benchmark-files-gen/BUILD.bazel +++ b/tools/benchmark-files-gen/BUILD.bazel @@ -13,9 +13,9 @@ go_library( "//beacon-chain/core/transition:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v1:go_default_library", + "//io/file:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/wrapper:go_default_library", - "//shared/fileutil:go_default_library", "//shared/interop:go_default_library", "//shared/params:go_default_library", "//shared/testutil:go_default_library", diff --git a/tools/benchmark-files-gen/main.go b/tools/benchmark-files-gen/main.go index 2f0702457..7357e7b1a 100644 --- a/tools/benchmark-files-gen/main.go +++ b/tools/benchmark-files-gen/main.go @@ -15,9 +15,9 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" + "github.com/prysmaticlabs/prysm/io/file" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper" - "github.com/prysmaticlabs/prysm/shared/fileutil" "github.com/prysmaticlabs/prysm/shared/interop" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil" @@ -47,7 +47,7 @@ func main() { } } - if err := fileutil.MkdirAll(*outputDir); err != nil { + if err := file.MkdirAll(*outputDir); err != nil { log.Fatal(err) } @@ -80,7 +80,7 @@ func generateGenesisBeaconState() error { if err != nil { return err } - return fileutil.WriteFile(path.Join(*outputDir, benchmark.GenesisFileName), beaconBytes) + return file.WriteFile(path.Join(*outputDir, benchmark.GenesisFileName), beaconBytes) } func generateMarshalledFullStateAndBlock() error { @@ -153,7 +153,7 @@ func generateMarshalledFullStateAndBlock() error { if err != nil { return err } - if err := fileutil.WriteFile(path.Join(*outputDir, benchmark.BState1EpochFileName), beaconBytes); err != nil { + if err := file.WriteFile(path.Join(*outputDir, benchmark.BState1EpochFileName), beaconBytes); err != nil { return err } @@ -168,7 +168,7 @@ func generateMarshalledFullStateAndBlock() error { return err } - return fileutil.WriteFile(path.Join(*outputDir, benchmark.FullBlockFileName), blockBytes) + return file.WriteFile(path.Join(*outputDir, benchmark.FullBlockFileName), blockBytes) } func generate2FullEpochState() error { @@ -203,7 +203,7 @@ func generate2FullEpochState() error { return err } - return fileutil.WriteFile(path.Join(*outputDir, benchmark.BstateEpochFileName), beaconBytes) + return file.WriteFile(path.Join(*outputDir, benchmark.BstateEpochFileName), beaconBytes) } func genesisBeaconState() (state.BeaconState, error) { diff --git a/tools/bootnode/BUILD.bazel b/tools/bootnode/BUILD.bazel index 0c828698a..e03318f50 100644 --- a/tools/bootnode/BUILD.bazel +++ b/tools/bootnode/BUILD.bazel @@ -11,12 +11,12 @@ go_library( visibility = ["//visibility:private"], deps = [ "//beacon-chain/core/helpers:go_default_library", + "//io/logs:go_default_library", "//network:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//runtime/maxprocs:go_default_library", "//runtime/version:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/logutil:go_default_library", "//shared/params:go_default_library", "//shared/runutil:go_default_library", "@com_github_ethereum_go_ethereum//crypto:go_default_library", diff --git a/tools/bootnode/bootnode.go b/tools/bootnode/bootnode.go index 03229cc30..4e943cd4b 100644 --- a/tools/bootnode/bootnode.go +++ b/tools/bootnode/bootnode.go @@ -33,12 +33,12 @@ import ( "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/io/logs" "github.com/prysmaticlabs/prysm/network" pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" _ "github.com/prysmaticlabs/prysm/runtime/maxprocs" "github.com/prysmaticlabs/prysm/runtime/version" "github.com/prysmaticlabs/prysm/shared/bytesutil" - "github.com/prysmaticlabs/prysm/shared/logutil" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/runutil" "github.com/sirupsen/logrus" @@ -69,7 +69,7 @@ func main() { flag.Parse() if *logFileName != "" { - if err := logutil.ConfigurePersistentLogging(*logFileName); err != nil { + if err := logs.ConfigurePersistentLogging(*logFileName); err != nil { log.WithError(err).Error("Failed to configuring logging to disk.") } } diff --git a/tools/enr-calculator/BUILD.bazel b/tools/enr-calculator/BUILD.bazel index 6498be10f..575588d23 100644 --- a/tools/enr-calculator/BUILD.bazel +++ b/tools/enr-calculator/BUILD.bazel @@ -10,8 +10,8 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/tools/enr-calculator", visibility = ["//visibility:private"], deps = [ + "//io/file:go_default_library", "//runtime/maxprocs:go_default_library", - "//shared/fileutil:go_default_library", "@com_github_ethereum_go_ethereum//p2p/enode:go_default_library", "@com_github_ethereum_go_ethereum//p2p/enr:go_default_library", "@com_github_libp2p_go_libp2p_core//crypto:go_default_library", diff --git a/tools/enr-calculator/main.go b/tools/enr-calculator/main.go index a5bf0c68d..0bc181282 100644 --- a/tools/enr-calculator/main.go +++ b/tools/enr-calculator/main.go @@ -11,8 +11,8 @@ import ( "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/enr" "github.com/libp2p/go-libp2p-core/crypto" + "github.com/prysmaticlabs/prysm/io/file" _ "github.com/prysmaticlabs/prysm/runtime/maxprocs" - "github.com/prysmaticlabs/prysm/shared/fileutil" log "github.com/sirupsen/logrus" ) @@ -68,7 +68,7 @@ func main() { log.Info(localNode.Node().String()) if *outfile != "" { - err := fileutil.WriteFile(*outfile, []byte(localNode.Node().String())) + err := file.WriteFile(*outfile, []byte(localNode.Node().String())) if err != nil { panic(err) } diff --git a/tools/genesis-state-gen/BUILD.bazel b/tools/genesis-state-gen/BUILD.bazel index 3a42c86e7..0b328b80b 100644 --- a/tools/genesis-state-gen/BUILD.bazel +++ b/tools/genesis-state-gen/BUILD.bazel @@ -10,8 +10,8 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/tools/genesis-state-gen", visibility = ["//visibility:private"], deps = [ + "//io/file:go_default_library", "//proto/prysm/v1alpha1:go_default_library", - "//shared/fileutil:go_default_library", "//shared/interop:go_default_library", "//shared/params:go_default_library", "@com_github_ghodss_yaml//:go_default_library", diff --git a/tools/genesis-state-gen/main.go b/tools/genesis-state-gen/main.go index 7d9829ad3..914a349a0 100644 --- a/tools/genesis-state-gen/main.go +++ b/tools/genesis-state-gen/main.go @@ -12,8 +12,8 @@ import ( "strings" "github.com/ghodss/yaml" + "github.com/prysmaticlabs/prysm/io/file" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/shared/fileutil" "github.com/prysmaticlabs/prysm/shared/interop" "github.com/prysmaticlabs/prysm/shared/params" ) @@ -58,7 +58,7 @@ func main() { var err error if *depositJSONFile != "" { inputFile := *depositJSONFile - expanded, err := fileutil.ExpandPath(inputFile) + expanded, err := file.ExpandPath(inputFile) if err != nil { log.Printf("Could not expand file path %s: %v", inputFile, err) return @@ -98,7 +98,7 @@ func main() { log.Printf("Could not ssz marshal the genesis beacon state: %v", err) return } - if err := fileutil.WriteFile(*sszOutputFile, encodedState); err != nil { + if err := file.WriteFile(*sszOutputFile, encodedState); err != nil { log.Printf("Could not write encoded genesis beacon state to file: %v", err) return } @@ -110,7 +110,7 @@ func main() { log.Printf("Could not yaml marshal the genesis beacon state: %v", err) return } - if err := fileutil.WriteFile(*yamlOutputFile, encodedState); err != nil { + if err := file.WriteFile(*yamlOutputFile, encodedState); err != nil { log.Printf("Could not write encoded genesis beacon state to file: %v", err) return } @@ -122,7 +122,7 @@ func main() { log.Printf("Could not json marshal the genesis beacon state: %v", err) return } - if err := fileutil.WriteFile(*jsonOutputFile, encodedState); err != nil { + if err := file.WriteFile(*jsonOutputFile, encodedState); err != nil { log.Printf("Could not write encoded genesis beacon state to file: %v", err) return } diff --git a/tools/interop/export-genesis/BUILD.bazel b/tools/interop/export-genesis/BUILD.bazel index bf9b06cde..abb027bcc 100644 --- a/tools/interop/export-genesis/BUILD.bazel +++ b/tools/interop/export-genesis/BUILD.bazel @@ -9,7 +9,7 @@ go_library( deps = [ "//beacon-chain/db:go_default_library", "//beacon-chain/db/kv:go_default_library", - "//shared/fileutil:go_default_library", + "//io/file:go_default_library", ], ) diff --git a/tools/interop/export-genesis/main.go b/tools/interop/export-genesis/main.go index 207ecc346..d2ce9a153 100644 --- a/tools/interop/export-genesis/main.go +++ b/tools/interop/export-genesis/main.go @@ -7,7 +7,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/db/kv" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" ) // A basic tool to extract genesis.ssz from existing beaconchain.db. @@ -41,7 +41,7 @@ func main() { if err != nil { panic(err) } - if err := fileutil.WriteFile(os.Args[2], b); err != nil { + if err := file.WriteFile(os.Args[2], b); err != nil { panic(err) } fmt.Println("done") diff --git a/tools/interop/split-keys/BUILD.bazel b/tools/interop/split-keys/BUILD.bazel index 8aa41915c..b9bffebca 100644 --- a/tools/interop/split-keys/BUILD.bazel +++ b/tools/interop/split-keys/BUILD.bazel @@ -7,7 +7,7 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/tools/interop/split-keys", visibility = ["//visibility:private"], deps = [ - "//shared/fileutil:go_default_library", + "//io/file:go_default_library", "//validator/accounts/wallet:go_default_library", "//validator/keymanager:go_default_library", "//validator/keymanager/derived:go_default_library", diff --git a/tools/interop/split-keys/main.go b/tools/interop/split-keys/main.go index 17915ab96..9e03b8bbb 100644 --- a/tools/interop/split-keys/main.go +++ b/tools/interop/split-keys/main.go @@ -20,7 +20,7 @@ import ( "os" "path" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/validator/keymanager" "github.com/prysmaticlabs/prysm/validator/keymanager/derived" @@ -56,7 +56,7 @@ func main() { } log.Printf("Splitting %d keys across %d wallets\n", len(privKeys), *numberOfWalletsFlag) - wPass, err := fileutil.ReadFileAsBytes(*walletPasswordFileFlag) + wPass, err := file.ReadFileAsBytes(*walletPasswordFileFlag) if err != nil { log.Fatal(err) } diff --git a/tools/keystores/BUILD.bazel b/tools/keystores/BUILD.bazel index 67ede1868..13adb1ed8 100644 --- a/tools/keystores/BUILD.bazel +++ b/tools/keystores/BUILD.bazel @@ -8,8 +8,8 @@ go_library( visibility = ["//visibility:private"], deps = [ "//crypto/bls:go_default_library", - "//shared/fileutil:go_default_library", - "//shared/promptutil:go_default_library", + "//io/file:go_default_library", + "//io/prompt:go_default_library", "//validator/keymanager:go_default_library", "@com_github_google_uuid//:go_default_library", "@com_github_logrusorgru_aurora//:go_default_library", diff --git a/tools/keystores/main.go b/tools/keystores/main.go index 85ca2b6ac..20a178e2e 100644 --- a/tools/keystores/main.go +++ b/tools/keystores/main.go @@ -18,8 +18,8 @@ import ( "github.com/logrusorgru/aurora" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/crypto/bls" - "github.com/prysmaticlabs/prysm/shared/fileutil" - "github.com/prysmaticlabs/prysm/shared/promptutil" + "github.com/prysmaticlabs/prysm/io/file" + "github.com/prysmaticlabs/prysm/io/prompt" "github.com/prysmaticlabs/prysm/validator/keymanager" "github.com/urfave/cli/v2" keystorev4 "github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4" @@ -90,14 +90,14 @@ func decrypt(cliCtx *cli.Context) error { if keystorePath == "" { return errors.New("--keystore must be set") } - fullPath, err := fileutil.ExpandPath(keystorePath) + fullPath, err := file.ExpandPath(keystorePath) if err != nil { return errors.Wrapf(err, "could not expand path: %s", keystorePath) } password := cliCtx.String(passwordFlag.Name) isPasswordSet := cliCtx.IsSet(passwordFlag.Name) if !isPasswordSet { - password, err = promptutil.PasswordPrompt("Input the keystore(s) password", func(s string) error { + password, err = prompt.PasswordPrompt("Input the keystore(s) password", func(s string) error { // Any password is valid. return nil }) @@ -105,7 +105,7 @@ func decrypt(cliCtx *cli.Context) error { return err } } - isDir, err := fileutil.HasDir(fullPath) + isDir, err := file.HasDir(fullPath) if err != nil { return errors.Wrapf(err, "could not check if path exists: %s", fullPath) } @@ -137,7 +137,7 @@ func encrypt(cliCtx *cli.Context) error { password := cliCtx.String(passwordFlag.Name) isPasswordSet := cliCtx.IsSet(passwordFlag.Name) if !isPasswordSet { - password, err = promptutil.PasswordPrompt("Input the keystore(s) password", func(s string) error { + password, err = prompt.PasswordPrompt("Input the keystore(s) password", func(s string) error { // Any password is valid. return nil }) @@ -153,12 +153,12 @@ func encrypt(cliCtx *cli.Context) error { if outputPath == "" { return errors.New("--output-path must be set") } - fullPath, err := fileutil.ExpandPath(outputPath) + fullPath, err := file.ExpandPath(outputPath) if err != nil { return errors.Wrapf(err, "could not expand path: %s", outputPath) } - if fileutil.FileExists(fullPath) { - response, err := promptutil.ValidatePrompt( + if file.FileExists(fullPath) { + response, err := prompt.ValidatePrompt( os.Stdin, fmt.Sprintf("file at path %s already exists, are you sure you want to overwrite it? [y/n]", fullPath), func(s string) error { @@ -170,7 +170,7 @@ func encrypt(cliCtx *cli.Context) error { }, ) if err != nil { - return errors.Wrap(err, "could not validate prompt confirmation") + return errors.Wrap(err, "could not validate userprompt confirmation") } if response == "n" { return nil @@ -208,7 +208,7 @@ func encrypt(cliCtx *cli.Context) error { if err != nil { return errors.Wrap(err, "could not json marshal keystore") } - if err := fileutil.WriteFile(fullPath, encodedFile); err != nil { + if err := file.WriteFile(fullPath, encodedFile); err != nil { return errors.Wrapf(err, "could not write file at path: %s", fullPath) } fmt.Printf( diff --git a/validator/accounts/BUILD.bazel b/validator/accounts/BUILD.bazel index 0d9338b91..c3857b1be 100644 --- a/validator/accounts/BUILD.bazel +++ b/validator/accounts/BUILD.bazel @@ -27,15 +27,15 @@ go_library( "//beacon-chain/core/blocks:go_default_library", "//cmd/validator/flags:go_default_library", "//crypto/bls:go_default_library", + "//io/file:go_default_library", + "//io/prompt:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//shared/bytesutil:go_default_library", "//shared/cmd:go_default_library", - "//shared/fileutil:go_default_library", "//shared/params:go_default_library", "//shared/petnames:go_default_library", - "//shared/promptutil:go_default_library", "//validator/accounts/iface:go_default_library", - "//validator/accounts/prompt:go_default_library", + "//validator/accounts/userprompt:go_default_library", "//validator/accounts/wallet:go_default_library", "//validator/client:go_default_library", "//validator/keymanager:go_default_library", @@ -72,11 +72,11 @@ go_test( deps = [ "//cmd/validator/flags:go_default_library", "//crypto/bls:go_default_library", + "//io/file:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/validator-client:go_default_library", "//shared/bytesutil:go_default_library", "//shared/event:go_default_library", - "//shared/fileutil:go_default_library", "//shared/params:go_default_library", "//shared/petnames:go_default_library", "//shared/testutil/assert:go_default_library", diff --git a/validator/accounts/accounts_backup.go b/validator/accounts/accounts_backup.go index 842ea0e77..0a365a687 100644 --- a/validator/accounts/accounts_backup.go +++ b/validator/accounts/accounts_backup.go @@ -14,12 +14,12 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/cmd/validator/flags" "github.com/prysmaticlabs/prysm/crypto/bls" + "github.com/prysmaticlabs/prysm/io/file" + "github.com/prysmaticlabs/prysm/io/prompt" "github.com/prysmaticlabs/prysm/shared/bytesutil" - "github.com/prysmaticlabs/prysm/shared/fileutil" "github.com/prysmaticlabs/prysm/shared/petnames" - "github.com/prysmaticlabs/prysm/shared/promptutil" "github.com/prysmaticlabs/prysm/validator/accounts/iface" - "github.com/prysmaticlabs/prysm/validator/accounts/prompt" + "github.com/prysmaticlabs/prysm/validator/accounts/userprompt" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/validator/keymanager" "github.com/prysmaticlabs/prysm/validator/keymanager/derived" @@ -62,7 +62,7 @@ func BackupAccountsCli(cliCtx *cli.Context) error { } // Input the directory where they wish to backup their accounts. - backupDir, err := prompt.InputDirectory(cliCtx, backupPromptText, flags.BackupDirFlag) + backupDir, err := userprompt.InputDirectory(cliCtx, backupPromptText, flags.BackupDirFlag) if err != nil { return errors.Wrap(err, "could not parse keys directory") } @@ -73,20 +73,20 @@ func BackupAccountsCli(cliCtx *cli.Context) error { cliCtx, flags.BackupPublicKeysFlag, pubKeys, - prompt.SelectAccountsBackupPromptText, + userprompt.SelectAccountsBackupPromptText, ) if err != nil { return errors.Wrap(err, "could not filter public keys for backup") } // Ask the user for their desired password for their backed up accounts. - backupsPassword, err := promptutil.InputPassword( + backupsPassword, err := prompt.InputPassword( cliCtx, flags.BackupPasswordFile, "Enter a new password for your backed up accounts", "Confirm new password", true, - promptutil.ValidatePasswordInput, + prompt.ValidatePasswordInput, ) if err != nil { return errors.Wrap(err, "could not determine password for backed up accounts") @@ -120,7 +120,7 @@ func BackupAccountsCli(cliCtx *cli.Context) error { return zipKeystoresToOutputDir(keystoresToBackup, backupDir) } -// Ask user to select accounts via an interactive prompt. +// Ask user to select accounts via an interactive userprompt. func selectAccounts(selectionPrompt string, pubKeys [][48]byte) (filteredPubKeys []bls.PublicKey, err error) { pubKeyStrings := make([]string, len(pubKeys)) for i, pk := range pubKeys { @@ -201,13 +201,13 @@ func zipKeystoresToOutputDir(keystoresToBackup []*keymanager.Keystore, outputDir if len(keystoresToBackup) == 0 { return errors.New("nothing to backup") } - if err := fileutil.MkdirAll(outputDir); err != nil { + if err := file.MkdirAll(outputDir); err != nil { return errors.Wrapf(err, "could not create directory at path: %s", outputDir) } // Marshal and zip all keystore files together and write the zip file // to the specified output directory. archivePath := filepath.Join(outputDir, archiveFilename) - if fileutil.FileExists(archivePath) { + if file.FileExists(archivePath) { return errors.Errorf("Zip file already exists in directory: %s", archivePath) } // We create a new file to store our backup.zip. diff --git a/validator/accounts/accounts_backup_test.go b/validator/accounts/accounts_backup_test.go index 8e4ad54b1..9fe8be984 100644 --- a/validator/accounts/accounts_backup_test.go +++ b/validator/accounts/accounts_backup_test.go @@ -12,7 +12,7 @@ import ( "testing" "time" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" @@ -97,7 +97,7 @@ func TestBackupAccounts_Noninteractive_Derived(t *testing.T) { // We check a backup.zip file was created at the output path. zipFilePath := filepath.Join(backupDir, archiveFilename) - assert.DeepEqual(t, true, fileutil.FileExists(zipFilePath)) + assert.DeepEqual(t, true, file.FileExists(zipFilePath)) // We attempt to unzip the file and verify the keystores do match our accounts. f, err := os.Open(zipFilePath) @@ -187,7 +187,7 @@ func TestBackupAccounts_Noninteractive_Imported(t *testing.T) { // We check a backup.zip file was created at the output path. zipFilePath := filepath.Join(backupDir, archiveFilename) - assert.DeepEqual(t, true, fileutil.FileExists(zipFilePath)) + assert.DeepEqual(t, true, file.FileExists(zipFilePath)) // We attempt to unzip the file and verify the keystores do match our accounts. f, err := os.Open(zipFilePath) diff --git a/validator/accounts/accounts_delete.go b/validator/accounts/accounts_delete.go index 3c752243f..568caf96c 100644 --- a/validator/accounts/accounts_delete.go +++ b/validator/accounts/accounts_delete.go @@ -8,10 +8,10 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/cmd/validator/flags" + "github.com/prysmaticlabs/prysm/io/prompt" "github.com/prysmaticlabs/prysm/shared/bytesutil" - "github.com/prysmaticlabs/prysm/shared/promptutil" "github.com/prysmaticlabs/prysm/validator/accounts/iface" - "github.com/prysmaticlabs/prysm/validator/accounts/prompt" + "github.com/prysmaticlabs/prysm/validator/accounts/userprompt" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/validator/keymanager" "github.com/prysmaticlabs/prysm/validator/keymanager/derived" @@ -45,7 +45,7 @@ func DeleteAccountCli(cliCtx *cli.Context) error { cliCtx, flags.DeletePublicKeysFlag, validatingPublicKeys, - prompt.SelectAccountsDeletePromptText, + userprompt.SelectAccountsDeletePromptText, ) if err != nil { return errors.Wrap(err, "could not filter public keys for deletion") @@ -61,8 +61,8 @@ func DeleteAccountCli(cliCtx *cli.Context) error { if !cliCtx.IsSet(flags.DeletePublicKeysFlag.Name) { if len(filteredPubKeys) == 1 { promptText := "Are you sure you want to delete 1 account? (%s) Y/N" - resp, err := promptutil.ValidatePrompt( - os.Stdin, fmt.Sprintf(promptText, au.BrightGreen(formattedPubKeys[0])), promptutil.ValidateYesOrNo, + resp, err := prompt.ValidatePrompt( + os.Stdin, fmt.Sprintf(promptText, au.BrightGreen(formattedPubKeys[0])), prompt.ValidateYesOrNo, ) if err != nil { return err @@ -77,7 +77,7 @@ func DeleteAccountCli(cliCtx *cli.Context) error { } else { promptText = fmt.Sprintf(promptText, len(filteredPubKeys), au.BrightGreen(allAccountStr)) } - resp, err := promptutil.ValidatePrompt(os.Stdin, promptText, promptutil.ValidateYesOrNo) + resp, err := prompt.ValidatePrompt(os.Stdin, promptText, prompt.ValidateYesOrNo) if err != nil { return err } diff --git a/validator/accounts/accounts_exit.go b/validator/accounts/accounts_exit.go index 656af149c..3fd062a57 100644 --- a/validator/accounts/accounts_exit.go +++ b/validator/accounts/accounts_exit.go @@ -12,13 +12,13 @@ import ( grpcutil "github.com/prysmaticlabs/prysm/api/grpc" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/cmd/validator/flags" + "github.com/prysmaticlabs/prysm/io/prompt" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/cmd" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/promptutil" "github.com/prysmaticlabs/prysm/validator/accounts/iface" - "github.com/prysmaticlabs/prysm/validator/accounts/prompt" + "github.com/prysmaticlabs/prysm/validator/accounts/userprompt" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/validator/client" "github.com/prysmaticlabs/prysm/validator/keymanager" @@ -147,7 +147,7 @@ func interact( cliCtx, flags.VoluntaryExitPublicKeysFlag, validatingPublicKeys, - prompt.SelectAccountsVoluntaryExitPromptText, + userprompt.SelectAccountsVoluntaryExitPromptText, ) if err != nil { return nil, nil, errors.Wrap(err, "could not filter public keys for voluntary exit") @@ -163,8 +163,8 @@ func interact( if !cliCtx.IsSet(flags.VoluntaryExitPublicKeysFlag.Name) { if len(filteredPubKeys) == 1 { promptText := "Are you sure you want to perform a voluntary exit on 1 account? (%s) Y/N" - resp, err := promptutil.ValidatePrompt( - r, fmt.Sprintf(promptText, au.BrightGreen(formattedPubKeys[0])), promptutil.ValidateYesOrNo, + resp, err := prompt.ValidatePrompt( + r, fmt.Sprintf(promptText, au.BrightGreen(formattedPubKeys[0])), prompt.ValidateYesOrNo, ) if err != nil { return nil, nil, err @@ -181,7 +181,7 @@ func interact( } else { promptText = fmt.Sprintf(promptText, len(filteredPubKeys), au.BrightGreen(allAccountStr)) } - resp, err := promptutil.ValidatePrompt(r, promptText, promptutil.ValidateYesOrNo) + resp, err := prompt.ValidatePrompt(r, promptText, prompt.ValidateYesOrNo) if err != nil { return nil, nil, err } @@ -203,8 +203,8 @@ func interact( promptQuestion := "If you still want to continue with the voluntary exit, please input a phrase found at the end " + "of the page from the above URL" promptText := fmt.Sprintf("%s\n%s\n%s\n%s", promptHeader, promptDescription, promptURL, promptQuestion) - resp, err := promptutil.ValidatePrompt(r, promptText, func(input string) error { - return promptutil.ValidatePhrase(input, exitPassphrase) + resp, err := prompt.ValidatePrompt(r, promptText, func(input string) error { + return prompt.ValidatePhrase(input, exitPassphrase) }) if err != nil { return nil, nil, err diff --git a/validator/accounts/accounts_import.go b/validator/accounts/accounts_import.go index c3fff8905..c0ed16da0 100644 --- a/validator/accounts/accounts_import.go +++ b/validator/accounts/accounts_import.go @@ -16,11 +16,11 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/cmd/validator/flags" "github.com/prysmaticlabs/prysm/crypto/bls" + "github.com/prysmaticlabs/prysm/io/file" + "github.com/prysmaticlabs/prysm/io/prompt" "github.com/prysmaticlabs/prysm/shared/bytesutil" - "github.com/prysmaticlabs/prysm/shared/fileutil" - "github.com/prysmaticlabs/prysm/shared/promptutil" "github.com/prysmaticlabs/prysm/validator/accounts/iface" - "github.com/prysmaticlabs/prysm/validator/accounts/prompt" + "github.com/prysmaticlabs/prysm/validator/accounts/userprompt" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/validator/keymanager" "github.com/prysmaticlabs/prysm/validator/keymanager/imported" @@ -83,7 +83,7 @@ type ImportAccountsConfig struct { // values necessary to run the function. func ImportAccountsCli(cliCtx *cli.Context) error { w, err := wallet.OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*wallet.Wallet, error) { - walletDir, err := prompt.InputDirectory(cliCtx, prompt.WalletDirPromptText, flags.WalletDirFlag) + walletDir, err := userprompt.InputDirectory(cliCtx, userprompt.WalletDirPromptText, flags.WalletDirFlag) if err != nil { return nil, err } @@ -151,12 +151,12 @@ func ImportAccountsCli(cliCtx *cli.Context) error { return importPrivateKeyAsAccount(cliCtx, w, k) } - keysDir, err := prompt.InputDirectory(cliCtx, prompt.ImportKeysDirPromptText, flags.KeysDirFlag) + keysDir, err := userprompt.InputDirectory(cliCtx, userprompt.ImportKeysDirPromptText, flags.KeysDirFlag) if err != nil { return errors.Wrap(err, "could not parse keys directory") } // Consider that the keysDir might be a path to a specific file and handle accordingly. - isDir, err := fileutil.HasDir(keysDir) + isDir, err := file.HasDir(keysDir) if err != nil { return errors.Wrap(err, "could not determine if path is a directory") } @@ -205,8 +205,8 @@ func ImportAccountsCli(cliCtx *cli.Context) error { } accountsPassword = string(data) } else { - accountsPassword, err = promptutil.PasswordPrompt( - "Enter the password for your imported accounts", promptutil.NotEmpty, + accountsPassword, err = prompt.PasswordPrompt( + "Enter the password for your imported accounts", prompt.NotEmpty, ) if err != nil { return fmt.Errorf("could not read account password: %w", err) @@ -241,11 +241,11 @@ func ImportAccounts(ctx context.Context, cfg *ImportAccountsConfig) error { // the Prysm validator's accounts. func importPrivateKeyAsAccount(cliCtx *cli.Context, wallet *wallet.Wallet, km *imported.Keymanager) error { privKeyFile := cliCtx.String(flags.ImportPrivateKeyFileFlag.Name) - fullPath, err := fileutil.ExpandPath(privKeyFile) + fullPath, err := file.ExpandPath(privKeyFile) if err != nil { return errors.Wrapf(err, "could not expand file path for %s", privKeyFile) } - if !fileutil.FileExists(fullPath) { + if !file.FileExists(fullPath) { return fmt.Errorf("file %s does not exist", fullPath) } privKeyHex, err := ioutil.ReadFile(fullPath) // #nosec G304 diff --git a/validator/accounts/prompt/log.go b/validator/accounts/prompt/log.go deleted file mode 100644 index e909277a0..000000000 --- a/validator/accounts/prompt/log.go +++ /dev/null @@ -1,5 +0,0 @@ -package prompt - -import "github.com/sirupsen/logrus" - -var log = logrus.WithField("prefix", "prompt") diff --git a/validator/accounts/prompt/BUILD.bazel b/validator/accounts/userprompt/BUILD.bazel similarity index 86% rename from validator/accounts/prompt/BUILD.bazel rename to validator/accounts/userprompt/BUILD.bazel index c2f658d87..caf7ef524 100644 --- a/validator/accounts/prompt/BUILD.bazel +++ b/validator/accounts/userprompt/BUILD.bazel @@ -6,12 +6,12 @@ go_library( "log.go", "prompt.go", ], - importpath = "github.com/prysmaticlabs/prysm/validator/accounts/prompt", + importpath = "github.com/prysmaticlabs/prysm/validator/accounts/userprompt", visibility = ["//validator:__subpackages__"], deps = [ "//cmd/validator/flags:go_default_library", - "//shared/fileutil:go_default_library", - "//shared/promptutil:go_default_library", + "//io/file:go_default_library", + "//io/prompt:go_default_library", "//validator/keymanager/remote:go_default_library", "@com_github_logrusorgru_aurora//:go_default_library", "@com_github_manifoldco_promptui//:go_default_library", diff --git a/validator/accounts/userprompt/log.go b/validator/accounts/userprompt/log.go new file mode 100644 index 000000000..044a03d8f --- /dev/null +++ b/validator/accounts/userprompt/log.go @@ -0,0 +1,5 @@ +package userprompt + +import "github.com/sirupsen/logrus" + +var log = logrus.WithField("prefix", "userprompt") diff --git a/validator/accounts/prompt/prompt.go b/validator/accounts/userprompt/prompt.go similarity index 84% rename from validator/accounts/prompt/prompt.go rename to validator/accounts/userprompt/prompt.go index 6525562fd..e4be99e38 100644 --- a/validator/accounts/prompt/prompt.go +++ b/validator/accounts/userprompt/prompt.go @@ -1,4 +1,4 @@ -package prompt +package userprompt import ( "fmt" @@ -9,8 +9,8 @@ import ( "github.com/manifoldco/promptui" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/cmd/validator/flags" - "github.com/prysmaticlabs/prysm/shared/fileutil" - "github.com/prysmaticlabs/prysm/shared/promptutil" + "github.com/prysmaticlabs/prysm/io/file" + "github.com/prysmaticlabs/prysm/io/prompt" "github.com/prysmaticlabs/prysm/validator/keymanager/remote" "github.com/urfave/cli/v2" ) @@ -20,7 +20,7 @@ const ( ImportKeysDirPromptText = "Enter the directory or filepath where your keystores to import are located" // DataDirDirPromptText for the validator database directory. DataDirDirPromptText = "Enter the directory of the validator database you would like to use" - // SlashingProtectionJSONPromptText for the EIP-3076 slashing protection JSON prompt. + // SlashingProtectionJSONPromptText for the EIP-3076 slashing protection JSON userprompt. SlashingProtectionJSONPromptText = "Enter the the filepath of your EIP-3076 Slashing Protection JSON from your previously used validator client" // WalletDirPromptText for the wallet. WalletDirPromptText = "Enter a wallet directory" @@ -38,11 +38,11 @@ var au = aurora.NewAurora(true) func InputDirectory(cliCtx *cli.Context, promptText string, flag *cli.StringFlag) (string, error) { directory := cliCtx.String(flag.Name) if cliCtx.IsSet(flag.Name) { - return fileutil.ExpandPath(directory) + return file.ExpandPath(directory) } // Append and log the appropriate directory name depending on the flag used. if flag.Name == flags.WalletDirFlag.Name { - ok, err := fileutil.HasDir(directory) + ok, err := file.HasDir(directory) if err != nil { return "", errors.Wrapf(err, "could not check if wallet dir %s exists", directory) } @@ -52,14 +52,14 @@ func InputDirectory(cliCtx *cli.Context, promptText string, flag *cli.StringFlag } } - inputtedDir, err := promptutil.DefaultPrompt(au.Bold(promptText).String(), directory) + inputtedDir, err := prompt.DefaultPrompt(au.Bold(promptText).String(), directory) if err != nil { return "", err } if inputtedDir == directory { return directory, nil } - return fileutil.ExpandPath(inputtedDir) + return file.ExpandPath(inputtedDir) } // InputRemoteKeymanagerConfig via the cli. @@ -72,16 +72,16 @@ func InputRemoteKeymanagerConfig(cliCtx *cli.Context) (*remote.KeymanagerOpts, e log.Info("Input desired configuration") var err error if addr == "" { - addr, err = promptutil.ValidatePrompt( + addr, err = prompt.ValidatePrompt( os.Stdin, "Remote gRPC address (such as host.example.com:4000)", - promptutil.NotEmpty) + prompt.NotEmpty) if err != nil { return nil, err } } if requireTls && crt == "" { - crt, err = promptutil.ValidatePrompt( + crt, err = prompt.ValidatePrompt( os.Stdin, "Path to TLS crt (such as /path/to/client.crt)", validateCertPath) @@ -90,7 +90,7 @@ func InputRemoteKeymanagerConfig(cliCtx *cli.Context) (*remote.KeymanagerOpts, e } } if requireTls && key == "" { - key, err = promptutil.ValidatePrompt( + key, err = prompt.ValidatePrompt( os.Stdin, "Path to TLS key (such as /path/to/client.key)", validateCertPath) @@ -99,7 +99,7 @@ func InputRemoteKeymanagerConfig(cliCtx *cli.Context) (*remote.KeymanagerOpts, e } } if requireTls && ca == "" { - ca, err = promptutil.ValidatePrompt( + ca, err = prompt.ValidatePrompt( os.Stdin, "Path to certificate authority (CA) crt (such as /path/to/ca.crt)", validateCertPath) @@ -110,19 +110,19 @@ func InputRemoteKeymanagerConfig(cliCtx *cli.Context) (*remote.KeymanagerOpts, e crtPath, keyPath, caPath := "", "", "" if crt != "" { - crtPath, err = fileutil.ExpandPath(strings.TrimRight(crt, "\r\n")) + crtPath, err = file.ExpandPath(strings.TrimRight(crt, "\r\n")) if err != nil { return nil, errors.Wrapf(err, "could not determine absolute path for %s", crt) } } if key != "" { - keyPath, err = fileutil.ExpandPath(strings.TrimRight(key, "\r\n")) + keyPath, err = file.ExpandPath(strings.TrimRight(key, "\r\n")) if err != nil { return nil, errors.Wrapf(err, "could not determine absolute path for %s", crt) } } if ca != "" { - caPath, err = fileutil.ExpandPath(strings.TrimRight(ca, "\r\n")) + caPath, err = file.ExpandPath(strings.TrimRight(ca, "\r\n")) if err != nil { return nil, errors.Wrapf(err, "could not determine absolute path for %s", crt) } @@ -145,10 +145,10 @@ func validateCertPath(input string) error { if input == "" { return errors.New("crt path cannot be empty") } - if !promptutil.IsValidUnicode(input) { + if !prompt.IsValidUnicode(input) { return errors.New("not valid unicode") } - if !fileutil.FileExists(input) { + if !file.FileExists(input) { return fmt.Errorf("no crt found at path: %s", input) } return nil diff --git a/validator/accounts/wallet/BUILD.bazel b/validator/accounts/wallet/BUILD.bazel index dde94a2a8..7860bf97f 100644 --- a/validator/accounts/wallet/BUILD.bazel +++ b/validator/accounts/wallet/BUILD.bazel @@ -13,10 +13,10 @@ go_library( ], deps = [ "//cmd/validator/flags:go_default_library", - "//shared/fileutil:go_default_library", - "//shared/promptutil:go_default_library", + "//io/file:go_default_library", + "//io/prompt:go_default_library", "//validator/accounts/iface:go_default_library", - "//validator/accounts/prompt:go_default_library", + "//validator/accounts/userprompt:go_default_library", "//validator/keymanager:go_default_library", "//validator/keymanager/derived:go_default_library", "//validator/keymanager/imported:go_default_library", diff --git a/validator/accounts/wallet/wallet.go b/validator/accounts/wallet/wallet.go index c5a59129d..4e34398ea 100644 --- a/validator/accounts/wallet/wallet.go +++ b/validator/accounts/wallet/wallet.go @@ -11,10 +11,10 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/cmd/validator/flags" - "github.com/prysmaticlabs/prysm/shared/fileutil" - "github.com/prysmaticlabs/prysm/shared/promptutil" + "github.com/prysmaticlabs/prysm/io/file" + "github.com/prysmaticlabs/prysm/io/prompt" "github.com/prysmaticlabs/prysm/validator/accounts/iface" - "github.com/prysmaticlabs/prysm/validator/accounts/prompt" + accountsprompt "github.com/prysmaticlabs/prysm/validator/accounts/userprompt" "github.com/prysmaticlabs/prysm/validator/keymanager" "github.com/prysmaticlabs/prysm/validator/keymanager/derived" "github.com/prysmaticlabs/prysm/validator/keymanager/imported" @@ -97,7 +97,7 @@ func New(cfg *Config) *Wallet { // Exists checks if directory at walletDir exists func Exists(walletDir string) (bool, error) { - dirExists, err := fileutil.HasDir(walletDir) + dirExists, err := file.HasDir(walletDir) if err != nil { return false, errors.Wrap(err, "could not parse wallet directory") } @@ -113,7 +113,7 @@ func Exists(walletDir string) (bool, error) { // IsValid checks if a folder contains a single key directory such as `derived`, `remote` or `imported`. // Returns true if one of those subdirectories exist, false otherwise. func IsValid(walletDir string) (bool, error) { - expanded, err := fileutil.ExpandPath(walletDir) + expanded, err := file.ExpandPath(walletDir) if err != nil { return false, err } @@ -173,7 +173,7 @@ func OpenWalletOrElseCli(cliCtx *cli.Context, otherwise func(cliCtx *cli.Context return nil, errors.New(InvalidWalletErrMsg) } - walletDir, err := prompt.InputDirectory(cliCtx, prompt.WalletDirPromptText, flags.WalletDirFlag) + walletDir, err := accountsprompt.InputDirectory(cliCtx, accountsprompt.WalletDirPromptText, flags.WalletDirFlag) if err != nil { return nil, err } @@ -231,7 +231,7 @@ func OpenWallet(_ context.Context, cfg *Config) (*Wallet, error) { // SaveWallet persists the wallet's directories to disk. func (w *Wallet) SaveWallet() error { - if err := fileutil.MkdirAll(w.accountsPath); err != nil { + if err := file.MkdirAll(w.accountsPath); err != nil { return errors.Wrap(err, "could not create wallet directory") } return nil @@ -299,17 +299,17 @@ func (w *Wallet) InitializeKeymanager(ctx context.Context, cfg iface.InitKeymana // WriteFileAtPath within the wallet directory given the desired path, filename, and raw data. func (w *Wallet) WriteFileAtPath(_ context.Context, filePath, fileName string, data []byte) error { accountPath := filepath.Join(w.accountsPath, filePath) - hasDir, err := fileutil.HasDir(accountPath) + hasDir, err := file.HasDir(accountPath) if err != nil { return err } if !hasDir { - if err := fileutil.MkdirAll(accountPath); err != nil { + if err := file.MkdirAll(accountPath); err != nil { return errors.Wrapf(err, "could not create path: %s", accountPath) } } fullPath := filepath.Join(accountPath, fileName) - if err := fileutil.WriteFile(fullPath, data); err != nil { + if err := file.WriteFile(fullPath, data); err != nil { return errors.Wrapf(err, "could not write %s", filePath) } log.WithFields(logrus.Fields{ @@ -322,12 +322,12 @@ func (w *Wallet) WriteFileAtPath(_ context.Context, filePath, fileName string, d // ReadFileAtPath within the wallet directory given the desired path and filename. func (w *Wallet) ReadFileAtPath(_ context.Context, filePath, fileName string) ([]byte, error) { accountPath := filepath.Join(w.accountsPath, filePath) - hasDir, err := fileutil.HasDir(accountPath) + hasDir, err := file.HasDir(accountPath) if err != nil { return nil, err } if !hasDir { - if err := fileutil.MkdirAll(accountPath); err != nil { + if err := file.MkdirAll(accountPath); err != nil { return nil, errors.Wrapf(err, "could not create path: %s", accountPath) } } @@ -350,7 +350,7 @@ func (w *Wallet) ReadFileAtPath(_ context.Context, filePath, fileName string) ([ // with a regex pattern. func (w *Wallet) FileNameAtPath(_ context.Context, filePath, fileName string) (string, error) { accountPath := filepath.Join(w.accountsPath, filePath) - if err := fileutil.MkdirAll(accountPath); err != nil { + if err := file.MkdirAll(accountPath); err != nil { return "", errors.Wrapf(err, "could not create path: %s", accountPath) } fullPath := filepath.Join(accountPath, fileName) @@ -369,7 +369,7 @@ func (w *Wallet) FileNameAtPath(_ context.Context, filePath, fileName string) (s // for reading if it exists at the wallet path. func (w *Wallet) ReadKeymanagerConfigFromDisk(_ context.Context) (io.ReadCloser, error) { configFilePath := filepath.Join(w.accountsPath, KeymanagerConfigFileName) - if !fileutil.FileExists(configFilePath) { + if !file.FileExists(configFilePath) { return nil, fmt.Errorf("no keymanager config file found at path: %s", w.accountsPath) } w.configFilePath = configFilePath @@ -382,7 +382,7 @@ func (w *Wallet) ReadKeymanagerConfigFromDisk(_ context.Context) (io.ReadCloser, func (w *Wallet) WriteKeymanagerConfigToDisk(_ context.Context, encoded []byte) error { configFilePath := filepath.Join(w.accountsPath, KeymanagerConfigFileName) // Write the config file to disk. - if err := fileutil.WriteFile(configFilePath, encoded); err != nil { + if err := file.WriteFile(configFilePath, encoded); err != nil { return errors.Wrapf(err, "could not write config to path: %s", configFilePath) } log.WithField("configFilePath", configFilePath).Debug("Wrote keymanager config file to disk") @@ -425,7 +425,7 @@ func InputPassword( ) (string, error) { if cliCtx.IsSet(passwordFileFlag.Name) { passwordFilePathInput := cliCtx.String(passwordFileFlag.Name) - data, err := fileutil.ReadFileAsBytes(passwordFilePathInput) + data, err := file.ReadFileAsBytes(passwordFilePathInput) if err != nil { return "", errors.Wrap(err, "could not read file as bytes") } @@ -439,13 +439,13 @@ func InputPassword( var walletPassword string var err error for !hasValidPassword { - walletPassword, err = promptutil.PasswordPrompt(promptText, passwordValidator) + walletPassword, err = prompt.PasswordPrompt(promptText, passwordValidator) if err != nil { return "", fmt.Errorf("could not read account password: %w", err) } if confirmPassword { - passwordConfirmation, err := promptutil.PasswordPrompt(ConfirmPasswordPromptText, passwordValidator) + passwordConfirmation, err := prompt.PasswordPrompt(ConfirmPasswordPromptText, passwordValidator) if err != nil { return "", fmt.Errorf("could not read password confirmation: %w", err) } diff --git a/validator/accounts/wallet_create.go b/validator/accounts/wallet_create.go index 3be4014c4..7936f6e62 100644 --- a/validator/accounts/wallet_create.go +++ b/validator/accounts/wallet_create.go @@ -10,9 +10,9 @@ import ( "github.com/manifoldco/promptui" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/cmd/validator/flags" - "github.com/prysmaticlabs/prysm/shared/promptutil" + "github.com/prysmaticlabs/prysm/io/prompt" "github.com/prysmaticlabs/prysm/validator/accounts/iface" - "github.com/prysmaticlabs/prysm/validator/accounts/prompt" + "github.com/prysmaticlabs/prysm/validator/accounts/userprompt" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/validator/keymanager" "github.com/prysmaticlabs/prysm/validator/keymanager/derived" @@ -127,17 +127,17 @@ func extractKeymanagerKindFromCli(cliCtx *cli.Context) (keymanager.Kind, error) } func extractWalletCreationConfigFromCli(cliCtx *cli.Context, keymanagerKind keymanager.Kind) (*CreateWalletConfig, error) { - walletDir, err := prompt.InputDirectory(cliCtx, prompt.WalletDirPromptText, flags.WalletDirFlag) + walletDir, err := userprompt.InputDirectory(cliCtx, userprompt.WalletDirPromptText, flags.WalletDirFlag) if err != nil { return nil, err } - walletPassword, err := promptutil.InputPassword( + walletPassword, err := prompt.InputPassword( cliCtx, flags.WalletPasswordFileFlag, wallet.NewWalletPasswordPromptText, wallet.ConfirmPasswordPromptText, true, /* Should confirm password */ - promptutil.ValidatePasswordInput, + prompt.ValidatePasswordInput, ) if err != nil { return nil, err @@ -160,14 +160,14 @@ func extractWalletCreationConfigFromCli(cliCtx *cli.Context, keymanagerKind keym createWalletConfig.NumAccounts = int(numAccounts) } if keymanagerKind == keymanager.Derived && !skipMnemonic25thWord && !has25thWordFile { - resp, err := promptutil.ValidatePrompt( - os.Stdin, newMnemonicPassphraseYesNoText, promptutil.ValidateYesOrNo, + resp, err := prompt.ValidatePrompt( + os.Stdin, newMnemonicPassphraseYesNoText, prompt.ValidateYesOrNo, ) if err != nil { return nil, errors.Wrap(err, "could not validate choice") } if strings.EqualFold(resp, "y") { - mnemonicPassphrase, err := promptutil.InputPassword( + mnemonicPassphrase, err := prompt.InputPassword( cliCtx, flags.Mnemonic25thWordFileFlag, newMnemonicPassphrasePromptText, @@ -187,7 +187,7 @@ func extractWalletCreationConfigFromCli(cliCtx *cli.Context, keymanagerKind keym } } if keymanagerKind == keymanager.Remote { - opts, err := prompt.InputRemoteKeymanagerConfig(cliCtx) + opts, err := userprompt.InputRemoteKeymanagerConfig(cliCtx) if err != nil { return nil, errors.Wrap(err, "could not input remote keymanager config") } @@ -264,7 +264,7 @@ func inputKeymanagerKind(cliCtx *cli.Context) (keymanager.Kind, error) { } selection, _, err := promptSelect.Run() if err != nil { - return keymanager.Imported, fmt.Errorf("could not select wallet type: %w", prompt.FormatPromptError(err)) + return keymanager.Imported, fmt.Errorf("could not select wallet type: %w", userprompt.FormatPromptError(err)) } return keymanager.Kind(selection), nil } diff --git a/validator/accounts/wallet_edit.go b/validator/accounts/wallet_edit.go index 7f3835ead..04dedb99e 100644 --- a/validator/accounts/wallet_edit.go +++ b/validator/accounts/wallet_edit.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/validator/accounts/prompt" + "github.com/prysmaticlabs/prysm/validator/accounts/userprompt" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/validator/keymanager" "github.com/prysmaticlabs/prysm/validator/keymanager/remote" @@ -38,7 +38,7 @@ func EditWalletConfigurationCli(cliCtx *cli.Context) error { log.Info("Current configuration") // Prints the current configuration to stdout. fmt.Println(opts) - newCfg, err := prompt.InputRemoteKeymanagerConfig(cliCtx) + newCfg, err := userprompt.InputRemoteKeymanagerConfig(cliCtx) if err != nil { return errors.Wrap(err, "could not get keymanager config") } diff --git a/validator/accounts/wallet_recover.go b/validator/accounts/wallet_recover.go index 91368321e..2a211b149 100644 --- a/validator/accounts/wallet_recover.go +++ b/validator/accounts/wallet_recover.go @@ -11,8 +11,8 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/cmd/validator/flags" - "github.com/prysmaticlabs/prysm/shared/promptutil" - "github.com/prysmaticlabs/prysm/validator/accounts/prompt" + "github.com/prysmaticlabs/prysm/io/prompt" + "github.com/prysmaticlabs/prysm/validator/accounts/userprompt" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/validator/keymanager" "github.com/prysmaticlabs/prysm/validator/keymanager/derived" @@ -56,14 +56,14 @@ func RecoverWalletCli(cliCtx *cli.Context) error { skipMnemonic25thWord := cliCtx.IsSet(flags.SkipMnemonic25thWordCheckFlag.Name) has25thWordFile := cliCtx.IsSet(flags.Mnemonic25thWordFileFlag.Name) if !skipMnemonic25thWord && !has25thWordFile { - resp, err := promptutil.ValidatePrompt( - os.Stdin, mnemonicPassphraseYesNoText, promptutil.ValidateYesOrNo, + resp, err := prompt.ValidatePrompt( + os.Stdin, mnemonicPassphraseYesNoText, prompt.ValidateYesOrNo, ) if err != nil { return errors.Wrap(err, "could not validate choice") } if strings.EqualFold(resp, "y") { - mnemonicPassphrase, err := promptutil.InputPassword( + mnemonicPassphrase, err := prompt.InputPassword( cliCtx, flags.Mnemonic25thWordFileFlag, mnemonicPassphrasePromptText, @@ -82,17 +82,17 @@ func RecoverWalletCli(cliCtx *cli.Context) error { config.Mnemonic25thWord = mnemonicPassphrase } } - walletDir, err := prompt.InputDirectory(cliCtx, prompt.WalletDirPromptText, flags.WalletDirFlag) + walletDir, err := userprompt.InputDirectory(cliCtx, userprompt.WalletDirPromptText, flags.WalletDirFlag) if err != nil { return err } - walletPassword, err := promptutil.InputPassword( + walletPassword, err := prompt.InputPassword( cliCtx, flags.WalletPasswordFileFlag, wallet.NewWalletPasswordPromptText, wallet.ConfirmPasswordPromptText, true, /* Should confirm password */ - promptutil.ValidatePasswordInput, + prompt.ValidatePasswordInput, ) if err != nil { return err @@ -178,7 +178,7 @@ func inputMnemonic(cliCtx *cli.Context) (mnemonicPhrase string, err error) { languages = append(languages, k) } sort.Strings(languages) - selectedLanguage, err := promptutil.ValidatePrompt( + selectedLanguage, err := prompt.ValidatePrompt( os.Stdin, fmt.Sprintf("Enter the language of your seed phrase: %s", strings.Join(languages, ", ")), func(input string) error { @@ -192,7 +192,7 @@ func inputMnemonic(cliCtx *cli.Context) (mnemonicPhrase string, err error) { return "", fmt.Errorf("could not get mnemonic language: %w", err) } bip39.SetWordList(allowedLanguages[selectedLanguage]) - mnemonicPhrase, err = promptutil.ValidatePrompt( + mnemonicPhrase, err = prompt.ValidatePrompt( os.Stdin, "Enter the seed phrase for the wallet you would like to recover", ValidateMnemonic) @@ -210,7 +210,7 @@ func inputNumAccounts(cliCtx *cli.Context) (int64, error) { } return numAccounts, nil } - numAccounts, err := promptutil.ValidatePrompt(os.Stdin, "Enter how many accounts you would like to generate from the mnemonic", promptutil.ValidateNumber) + numAccounts, err := prompt.ValidatePrompt(os.Stdin, "Enter how many accounts you would like to generate from the mnemonic", prompt.ValidateNumber) if err != nil { return 0, err } diff --git a/validator/client/BUILD.bazel b/validator/client/BUILD.bazel index e43187e48..1e46a7207 100644 --- a/validator/client/BUILD.bazel +++ b/validator/client/BUILD.bazel @@ -30,6 +30,7 @@ go_library( "//crypto/bls:go_default_library", "//crypto/hash:go_default_library", "//crypto/rand:go_default_library", + "//math:go_default_library", "//monitoring/tracing:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/block:go_default_library", @@ -39,7 +40,6 @@ go_library( "//shared/blockutil:go_default_library", "//shared/bytesutil:go_default_library", "//shared/event:go_default_library", - "//shared/mathutil:go_default_library", "//shared/mputil:go_default_library", "//shared/params:go_default_library", "//shared/slashutil:go_default_library", @@ -109,13 +109,13 @@ go_test( "//cache/lru:go_default_library", "//config/features:go_default_library", "//crypto/bls:go_default_library", + "//io/file:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/validator-client:go_default_library", "//proto/prysm/v1alpha1/wrapper:go_default_library", "//runtime:go_default_library", "//shared/bytesutil:go_default_library", "//shared/event:go_default_library", - "//shared/fileutil:go_default_library", "//shared/params:go_default_library", "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", diff --git a/validator/client/slashing_protection_interchange_test.go b/validator/client/slashing_protection_interchange_test.go index 627dea55c..d4a602a0f 100644 --- a/validator/client/slashing_protection_interchange_test.go +++ b/validator/client/slashing_protection_interchange_test.go @@ -10,9 +10,9 @@ import ( "github.com/bazelbuild/rules_go/go/tools/bazel" "github.com/prysmaticlabs/prysm/config/features" + "github.com/prysmaticlabs/prysm/io/file" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper" - "github.com/prysmaticlabs/prysm/shared/fileutil" "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/require" interchangeformat "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format" @@ -65,7 +65,7 @@ func setupEIP3076SpecTests(t *testing.T) []*eip3076TestCase { for _, ff := range testFolders { if strings.Contains(ff.ShortPath, "eip3076_spec_tests") && strings.Contains(ff.ShortPath, "generated/") { - enc, err := fileutil.ReadFileAsBytes(ff.Path) + enc, err := file.ReadFileAsBytes(ff.Path) require.NoError(t, err) testCase := &eip3076TestCase{} require.NoError(t, json.Unmarshal(enc, testCase)) diff --git a/validator/client/wait_for_activation.go b/validator/client/wait_for_activation.go index 57e10b8ba..082599008 100644 --- a/validator/client/wait_for_activation.go +++ b/validator/client/wait_for_activation.go @@ -6,10 +6,10 @@ import ( "time" "github.com/pkg/errors" + "github.com/prysmaticlabs/prysm/math" "github.com/prysmaticlabs/prysm/monitoring/tracing" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/bytesutil" - "github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/time/slots" "github.com/prysmaticlabs/prysm/validator/keymanager/remote" @@ -85,7 +85,7 @@ func (v *validator) waitForActivation(ctx context.Context, accountsChangedChan < log.WithError(err).WithField("attempts", attempts). Error("Stream broken while waiting for activation. Reconnecting...") // Reconnection attempt backoff, up to 60s. - time.Sleep(time.Second * time.Duration(mathutil.Min(uint64(attempts), 60))) + time.Sleep(time.Second * time.Duration(math.Min(uint64(attempts), 60))) return v.waitForActivation(incrementRetries(ctx), accountsChangedChan) } @@ -155,7 +155,7 @@ func (v *validator) waitForActivation(ctx context.Context, accountsChangedChan < log.WithError(err).WithField("attempts", attempts). Error("Stream broken while waiting for activation. Reconnecting...") // Reconnection attempt backoff, up to 60s. - time.Sleep(time.Second * time.Duration(mathutil.Min(uint64(attempts), 60))) + time.Sleep(time.Second * time.Duration(math.Min(uint64(attempts), 60))) return v.waitForActivation(incrementRetries(ctx), accountsChangedChan) } diff --git a/validator/db/BUILD.bazel b/validator/db/BUILD.bazel index aa276d651..87b5a04b1 100644 --- a/validator/db/BUILD.bazel +++ b/validator/db/BUILD.bazel @@ -14,9 +14,9 @@ go_library( "//validator:__subpackages__", ], deps = [ + "//io/file:go_default_library", + "//io/prompt:go_default_library", "//shared/cmd:go_default_library", - "//shared/fileutil:go_default_library", - "//shared/promptutil:go_default_library", "//validator/db/iface:go_default_library", "//validator/db/kv:go_default_library", "@com_github_pkg_errors//:go_default_library", diff --git a/validator/db/kv/BUILD.bazel b/validator/db/kv/BUILD.bazel index b05949aab..358d222e6 100644 --- a/validator/db/kv/BUILD.bazel +++ b/validator/db/kv/BUILD.bazel @@ -23,13 +23,13 @@ go_library( deps = [ "//beacon-chain/core:go_default_library", "//config/features:go_default_library", + "//io/file:go_default_library", "//monitoring/progress:go_default_library", "//monitoring/tracing:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//shared/abool:go_default_library", "//shared/bytesutil:go_default_library", "//shared/event:go_default_library", - "//shared/fileutil:go_default_library", "//shared/params:go_default_library", "//shared/slashutil:go_default_library", "@com_github_pkg_errors//:go_default_library", diff --git a/validator/db/kv/backup.go b/validator/db/kv/backup.go index b4391637f..c9b1ccbe6 100644 --- a/validator/db/kv/backup.go +++ b/validator/db/kv/backup.go @@ -6,7 +6,7 @@ import ( "path" "time" - "github.com/prysmaticlabs/prysm/shared/fileutil" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/shared/params" bolt "go.etcd.io/bbolt" "go.opencensus.io/trace" @@ -23,7 +23,7 @@ func (s *Store) Backup(ctx context.Context, outputDir string, permissionOverride var backupsDir string var err error if outputDir != "" { - backupsDir, err = fileutil.ExpandPath(outputDir) + backupsDir, err = file.ExpandPath(outputDir) if err != nil { return err } @@ -31,7 +31,7 @@ func (s *Store) Backup(ctx context.Context, outputDir string, permissionOverride backupsDir = path.Join(s.databasePath, backupsDirectoryName) } // Ensure the backups directory exists. - if err := fileutil.HandleBackupDir(backupsDir, permissionOverride); err != nil { + if err := file.HandleBackupDir(backupsDir, permissionOverride); err != nil { return err } backupPath := path.Join(backupsDir, fmt.Sprintf("prysm_validatordb_%d.backup", time.Now().Unix())) diff --git a/validator/db/kv/db.go b/validator/db/kv/db.go index d22e712eb..1c3d6cf63 100644 --- a/validator/db/kv/db.go +++ b/validator/db/kv/db.go @@ -11,9 +11,9 @@ import ( "github.com/prometheus/client_golang/prometheus" prombolt "github.com/prysmaticlabs/prombbolt" "github.com/prysmaticlabs/prysm/config/features" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/shared/abool" "github.com/prysmaticlabs/prysm/shared/event" - "github.com/prysmaticlabs/prysm/shared/fileutil" "github.com/prysmaticlabs/prysm/shared/params" bolt "go.etcd.io/bbolt" ) @@ -107,12 +107,12 @@ func createBuckets(tx *bolt.Tx, buckets ...[]byte) error { // path specified, creates the kv-buckets based on the schema, and stores // an open connection db object as a property of the Store struct. func NewKVStore(ctx context.Context, dirPath string, config *Config) (*Store, error) { - hasDir, err := fileutil.HasDir(dirPath) + hasDir, err := file.HasDir(dirPath) if err != nil { return nil, err } if !hasDir { - if err := fileutil.MkdirAll(dirPath); err != nil { + if err := file.MkdirAll(dirPath); err != nil { return nil, err } } diff --git a/validator/db/migrate.go b/validator/db/migrate.go index b5f240859..ee29de65f 100644 --- a/validator/db/migrate.go +++ b/validator/db/migrate.go @@ -5,8 +5,8 @@ import ( "path" "github.com/pkg/errors" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/shared/cmd" - "github.com/prysmaticlabs/prysm/shared/fileutil" "github.com/prysmaticlabs/prysm/validator/db/kv" "github.com/urfave/cli/v2" ) @@ -15,7 +15,7 @@ import ( func MigrateUp(cliCtx *cli.Context) error { dataDir := cliCtx.String(cmd.DataDirFlag.Name) - if !fileutil.FileExists(path.Join(dataDir, kv.ProtectionDbFileName)) { + if !file.FileExists(path.Join(dataDir, kv.ProtectionDbFileName)) { return errors.New("No validator db found at path, nothing to migrate") } @@ -33,7 +33,7 @@ func MigrateUp(cliCtx *cli.Context) error { func MigrateDown(cliCtx *cli.Context) error { dataDir := cliCtx.String(cmd.DataDirFlag.Name) - if !fileutil.FileExists(path.Join(dataDir, kv.ProtectionDbFileName)) { + if !file.FileExists(path.Join(dataDir, kv.ProtectionDbFileName)) { return errors.New("No validator db found at path, nothing to rollback") } diff --git a/validator/db/restore.go b/validator/db/restore.go index 98f67e148..f300f23da 100644 --- a/validator/db/restore.go +++ b/validator/db/restore.go @@ -6,9 +6,9 @@ import ( "strings" "github.com/pkg/errors" + "github.com/prysmaticlabs/prysm/io/file" + "github.com/prysmaticlabs/prysm/io/prompt" "github.com/prysmaticlabs/prysm/shared/cmd" - "github.com/prysmaticlabs/prysm/shared/fileutil" - "github.com/prysmaticlabs/prysm/shared/promptutil" "github.com/prysmaticlabs/prysm/validator/db/kv" "github.com/urfave/cli/v2" ) @@ -21,9 +21,9 @@ func Restore(cliCtx *cli.Context) error { sourceFile := cliCtx.String(cmd.RestoreSourceFileFlag.Name) targetDir := cliCtx.String(cmd.RestoreTargetDirFlag.Name) - if fileutil.FileExists(path.Join(targetDir, kv.ProtectionDbFileName)) { - resp, err := promptutil.ValidatePrompt( - os.Stdin, dbExistsYesNoPrompt, promptutil.ValidateYesOrNo, + if file.FileExists(path.Join(targetDir, kv.ProtectionDbFileName)) { + resp, err := prompt.ValidatePrompt( + os.Stdin, dbExistsYesNoPrompt, prompt.ValidateYesOrNo, ) if err != nil { return errors.Wrap(err, "could not validate choice") @@ -33,10 +33,10 @@ func Restore(cliCtx *cli.Context) error { return nil } } - if err := fileutil.MkdirAll(targetDir); err != nil { + if err := file.MkdirAll(targetDir); err != nil { return err } - if err := fileutil.CopyFile(sourceFile, path.Join(targetDir, kv.ProtectionDbFileName)); err != nil { + if err := file.CopyFile(sourceFile, path.Join(targetDir, kv.ProtectionDbFileName)); err != nil { return err } diff --git a/validator/keymanager/derived/BUILD.bazel b/validator/keymanager/derived/BUILD.bazel index fc3e251a8..1fba41b36 100644 --- a/validator/keymanager/derived/BUILD.bazel +++ b/validator/keymanager/derived/BUILD.bazel @@ -15,9 +15,9 @@ go_library( deps = [ "//crypto/bls:go_default_library", "//crypto/rand:go_default_library", + "//io/prompt:go_default_library", "//proto/prysm/v1alpha1/validator-client:go_default_library", "//shared/event:go_default_library", - "//shared/promptutil:go_default_library", "//validator/accounts/iface:go_default_library", "//validator/keymanager:go_default_library", "//validator/keymanager/imported:go_default_library", diff --git a/validator/keymanager/derived/mnemonic.go b/validator/keymanager/derived/mnemonic.go index 870f5d4c2..7e01e2975 100644 --- a/validator/keymanager/derived/mnemonic.go +++ b/validator/keymanager/derived/mnemonic.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/crypto/rand" - "github.com/prysmaticlabs/prysm/shared/promptutil" + "github.com/prysmaticlabs/prysm/io/prompt" "github.com/tyler-smith/go-bip39" ) @@ -65,9 +65,9 @@ func (m *EnglishMnemonicGenerator) ConfirmAcknowledgement(phrase string) error { return nil } // Confirm the user has written down the mnemonic phrase offline. - _, err := promptutil.ValidatePrompt(os.Stdin, confirmationText, promptutil.ValidateConfirmation) + _, err := prompt.ValidatePrompt(os.Stdin, confirmationText, prompt.ValidateConfirmation) if err != nil { - log.Errorf("Could not confirm acknowledgement of prompt, please enter y") + log.Errorf("Could not confirm acknowledgement of userprompt, please enter y") } return nil } diff --git a/validator/keymanager/imported/BUILD.bazel b/validator/keymanager/imported/BUILD.bazel index 6acf9194e..fbbd0d255 100644 --- a/validator/keymanager/imported/BUILD.bazel +++ b/validator/keymanager/imported/BUILD.bazel @@ -19,14 +19,14 @@ go_library( deps = [ "//config/features:go_default_library", "//crypto/bls:go_default_library", + "//io/file:go_default_library", + "//io/prompt:go_default_library", "//proto/prysm/v1alpha1/validator-client:go_default_library", "//shared/asyncutil:go_default_library", "//shared/bytesutil:go_default_library", "//shared/event:go_default_library", - "//shared/fileutil:go_default_library", "//shared/interop:go_default_library", "//shared/petnames:go_default_library", - "//shared/promptutil:go_default_library", "//validator/accounts/iface:go_default_library", "//validator/keymanager:go_default_library", "@com_github_fsnotify_fsnotify//:go_default_library", diff --git a/validator/keymanager/imported/import.go b/validator/keymanager/imported/import.go index d21259b94..939b32d00 100644 --- a/validator/keymanager/imported/import.go +++ b/validator/keymanager/imported/import.go @@ -10,7 +10,7 @@ import ( "github.com/k0kubun/go-ansi" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/crypto/bls" - "github.com/prysmaticlabs/prysm/shared/promptutil" + "github.com/prysmaticlabs/prysm/io/prompt" "github.com/prysmaticlabs/prysm/validator/keymanager" "github.com/schollz/progressbar/v3" keystorev4 "github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4" @@ -87,8 +87,8 @@ func (km *Keymanager) attemptDecryptKeystore( privKeyBytes, err = enc.Decrypt(keystore.Crypto, password) doesNotDecrypt := err != nil && strings.Contains(err.Error(), "invalid checksum") for doesNotDecrypt { - password, err = promptutil.PasswordPrompt( - fmt.Sprintf("Password incorrect for key 0x%s, input correct password", keystore.Pubkey), promptutil.NotEmpty, + password, err = prompt.PasswordPrompt( + fmt.Sprintf("Password incorrect for key 0x%s, input correct password", keystore.Pubkey), prompt.NotEmpty, ) if err != nil { return nil, nil, "", fmt.Errorf("could not read keystore password: %w", err) diff --git a/validator/keymanager/imported/refresh.go b/validator/keymanager/imported/refresh.go index dfe630b8c..902074b7c 100644 --- a/validator/keymanager/imported/refresh.go +++ b/validator/keymanager/imported/refresh.go @@ -10,9 +10,9 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/crypto/bls" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/shared/asyncutil" "github.com/prysmaticlabs/prysm/shared/bytesutil" - "github.com/prysmaticlabs/prysm/shared/fileutil" "github.com/prysmaticlabs/prysm/validator/keymanager" keystorev4 "github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4" ) @@ -24,7 +24,7 @@ import ( func (km *Keymanager) listenForAccountChanges(ctx context.Context) { debounceFileChangesInterval := features.Get().KeystoreImportDebounceInterval accountsFilePath := filepath.Join(km.wallet.AccountsDir(), AccountsPath, AccountsKeystoreFileName) - if !fileutil.FileExists(accountsFilePath) { + if !file.FileExists(accountsFilePath) { return } watcher, err := fsnotify.NewWatcher() diff --git a/validator/node/BUILD.bazel b/validator/node/BUILD.bazel index fd6b413f3..97cd6e66b 100644 --- a/validator/node/BUILD.bazel +++ b/validator/node/BUILD.bazel @@ -31,6 +31,7 @@ go_library( "//api/gateway:go_default_library", "//cmd/validator/flags:go_default_library", "//config/features:go_default_library", + "//io/file:go_default_library", "//monitoring/backup:go_default_library", "//monitoring/prometheus:go_default_library", "//monitoring/tracing:go_default_library", @@ -42,7 +43,6 @@ go_library( "//runtime/version:go_default_library", "//shared/cmd:go_default_library", "//shared/event:go_default_library", - "//shared/fileutil:go_default_library", "//shared/params:go_default_library", "//validator/accounts/iface:go_default_library", "//validator/accounts/wallet:go_default_library", diff --git a/validator/node/node.go b/validator/node/node.go index 073d03383..55585f723 100644 --- a/validator/node/node.go +++ b/validator/node/node.go @@ -19,6 +19,7 @@ import ( "github.com/prysmaticlabs/prysm/api/gateway" "github.com/prysmaticlabs/prysm/cmd/validator/flags" "github.com/prysmaticlabs/prysm/config/features" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/monitoring/backup" "github.com/prysmaticlabs/prysm/monitoring/prometheus" tracing2 "github.com/prysmaticlabs/prysm/monitoring/tracing" @@ -30,7 +31,6 @@ import ( "github.com/prysmaticlabs/prysm/runtime/version" "github.com/prysmaticlabs/prysm/shared/cmd" "github.com/prysmaticlabs/prysm/shared/event" - "github.com/prysmaticlabs/prysm/shared/fileutil" "github.com/prysmaticlabs/prysm/shared/params" accountsiface "github.com/prysmaticlabs/prysm/validator/accounts/iface" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" @@ -226,7 +226,7 @@ func (c *ValidatorClient) initializeFromCLI(cliCtx *cli.Context) error { } } else { dataFile := filepath.Join(dataDir, kv.ProtectionDbFileName) - if !fileutil.FileExists(dataFile) { + if !file.FileExists(dataFile) { log.Warnf("Slashing protection file %s is missing.\n"+ "If you changed your --wallet-dir or --datadir, please copy your previous \"validator.db\" file into your current --datadir.\n"+ "Disregard this warning if this is the first time you are running this set of keys.", dataFile) @@ -572,9 +572,9 @@ func (c *ValidatorClient) registerRPCGatewayService(cliCtx *cli.Context) error { func setWalletPasswordFilePath(cliCtx *cli.Context) error { walletDir := cliCtx.String(flags.WalletDirFlag.Name) defaultWalletPasswordFilePath := filepath.Join(walletDir, wallet.DefaultWalletPasswordFile) - if fileutil.FileExists(defaultWalletPasswordFilePath) { + if file.FileExists(defaultWalletPasswordFilePath) { // Ensure file has proper permissions. - hasPerms, err := fileutil.HasReadWritePermissions(defaultWalletPasswordFilePath) + hasPerms, err := file.HasReadWritePermissions(defaultWalletPasswordFilePath) if err != nil { return err } diff --git a/validator/rpc/BUILD.bazel b/validator/rpc/BUILD.bazel index 5e362bc95..851f85626 100644 --- a/validator/rpc/BUILD.bazel +++ b/validator/rpc/BUILD.bazel @@ -21,16 +21,16 @@ go_library( "//config/features:go_default_library", "//crypto/bls:go_default_library", "//crypto/rand:go_default_library", + "//io/file:go_default_library", + "//io/logs:go_default_library", + "//io/prompt:go_default_library", "//monitoring/tracing:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/validator-client:go_default_library", "//runtime/version:go_default_library", "//shared/cmd:go_default_library", "//shared/event:go_default_library", - "//shared/fileutil:go_default_library", - "//shared/logutil:go_default_library", "//shared/petnames:go_default_library", - "//shared/promptutil:go_default_library", "//time:go_default_library", "//validator/accounts:go_default_library", "//validator/accounts/iface:go_default_library", @@ -81,11 +81,11 @@ go_test( "//cmd/validator/flags:go_default_library", "//config/features:go_default_library", "//crypto/bls:go_default_library", + "//io/file:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/validator-client:go_default_library", "//shared/bytesutil:go_default_library", "//shared/event:go_default_library", - "//shared/fileutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", "//testing/mock:go_default_library", diff --git a/validator/rpc/auth.go b/validator/rpc/auth.go index aa0b32c66..bc1a503da 100644 --- a/validator/rpc/auth.go +++ b/validator/rpc/auth.go @@ -8,9 +8,9 @@ import ( "github.com/golang-jwt/jwt" "github.com/golang/protobuf/ptypes/empty" "github.com/pkg/errors" + "github.com/prysmaticlabs/prysm/io/file" + "github.com/prysmaticlabs/prysm/io/prompt" pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client" - "github.com/prysmaticlabs/prysm/shared/fileutil" - "github.com/prysmaticlabs/prysm/shared/promptutil" prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" "golang.org/x/crypto/bcrypt" @@ -38,20 +38,20 @@ func (s *Server) Signup(ctx context.Context, req *pb.AuthRequest) (*pb.AuthRespo } // First, we check if the validator already has a password. In this case, // the user should be logged in as normal. - if fileutil.FileExists(filepath.Join(walletDir, HashedRPCPassword)) { + if file.FileExists(filepath.Join(walletDir, HashedRPCPassword)) { return s.Login(ctx, req) } // We check the strength of the password to ensure it is high-entropy, // has the required character count, and contains only unicode characters. - if err := promptutil.ValidatePasswordInput(req.Password); err != nil { + if err := prompt.ValidatePasswordInput(req.Password); err != nil { return nil, status.Errorf(codes.InvalidArgument, "Could not validate RPC password input: %v", err) } - hasDir, err := fileutil.HasDir(walletDir) + hasDir, err := file.HasDir(walletDir) if err != nil { return nil, status.Error(codes.FailedPrecondition, "Could not check if wallet directory exists") } if !hasDir { - if err := fileutil.MkdirAll(walletDir); err != nil { + if err := file.MkdirAll(walletDir); err != nil { return nil, status.Errorf(codes.Internal, "could not write directory %s to disk: %v", walletDir, err) } } @@ -67,14 +67,14 @@ func (s *Server) Login(ctx context.Context, req *pb.AuthRequest) (*pb.AuthRespon walletDir := s.walletDir // We check the strength of the password to ensure it is high-entropy, // has the required character count, and contains only unicode characters. - if err := promptutil.ValidatePasswordInput(req.Password); err != nil { + if err := prompt.ValidatePasswordInput(req.Password); err != nil { return nil, status.Errorf(codes.InvalidArgument, "Could not validate RPC password input: %v", err) } hashedPasswordPath := filepath.Join(walletDir, HashedRPCPassword) - if !fileutil.FileExists(hashedPasswordPath) { + if !file.FileExists(hashedPasswordPath) { return nil, status.Error(codes.Internal, "Could not find hashed password on disk") } - hashedPassword, err := fileutil.ReadFileAsBytes(hashedPasswordPath) + hashedPassword, err := file.ReadFileAsBytes(hashedPasswordPath) if err != nil { return nil, status.Error(codes.Internal, "Could not retrieve hashed password from disk") } @@ -93,7 +93,7 @@ func (s *Server) HasUsedWeb(ctx context.Context, _ *empty.Empty) (*pb.HasUsedWeb } hashedPasswordPath := filepath.Join(s.walletDir, HashedRPCPassword) return &pb.HasUsedWebResponse{ - HasSignedUp: fileutil.FileExists(hashedPasswordPath), + HasSignedUp: file.FileExists(hashedPasswordPath), HasWallet: walletExists, }, nil } @@ -128,10 +128,10 @@ func (s *Server) ChangePassword(ctx context.Context, req *pb.ChangePasswordReque return nil, status.Error(codes.InvalidArgument, "Current password cannot be empty") } hashedPasswordPath := filepath.Join(s.walletDir, HashedRPCPassword) - if !fileutil.FileExists(hashedPasswordPath) { + if !file.FileExists(hashedPasswordPath) { return nil, status.Error(codes.FailedPrecondition, "Could not compare password from disk") } - hashedPassword, err := fileutil.ReadFileAsBytes(hashedPasswordPath) + hashedPassword, err := file.ReadFileAsBytes(hashedPasswordPath) if err != nil { return nil, status.Error(codes.FailedPrecondition, "Could not retrieve hashed password from disk") } @@ -141,7 +141,7 @@ func (s *Server) ChangePassword(ctx context.Context, req *pb.ChangePasswordReque if req.Password != req.PasswordConfirmation { return nil, status.Error(codes.InvalidArgument, "Password does not match confirmation") } - if err := promptutil.ValidatePasswordInput(req.Password); err != nil { + if err := prompt.ValidatePasswordInput(req.Password); err != nil { return nil, status.Errorf(codes.InvalidArgument, "Could not validate password input: %v", err) } // Write the new password hash to disk. @@ -158,7 +158,7 @@ func (s *Server) SaveHashedPassword(password string) error { return errors.Wrap(err, "could not generate hashed password") } hashFilePath := filepath.Join(s.walletDir, HashedRPCPassword) - return fileutil.WriteFile(hashFilePath, hashedPassword) + return file.WriteFile(hashFilePath, hashedPassword) } // Interval in which we should check if a user has not yet used the RPC Signup endpoint @@ -171,7 +171,7 @@ func (s *Server) checkUserSignup(ctx context.Context) { select { case <-ticker.C: hashedPasswordPath := filepath.Join(s.walletDir, HashedRPCPassword) - if fileutil.FileExists(hashedPasswordPath) { + if file.FileExists(hashedPasswordPath) { return } log.Warnf( diff --git a/validator/rpc/auth_test.go b/validator/rpc/auth_test.go index 698be1a7f..a1251ab80 100644 --- a/validator/rpc/auth_test.go +++ b/validator/rpc/auth_test.go @@ -8,9 +8,9 @@ import ( "github.com/golang-jwt/jwt" "github.com/golang/protobuf/ptypes/empty" + "github.com/prysmaticlabs/prysm/io/file" pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/shared/event" - "github.com/prysmaticlabs/prysm/shared/fileutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" "github.com/prysmaticlabs/prysm/validator/accounts" @@ -52,7 +52,7 @@ func TestServer_SignupAndLogin_RoundTrip(t *testing.T) { require.NoError(t, err) // Assert we stored the hashed password. - passwordHashExists := fileutil.FileExists(filepath.Join(defaultWalletPath, HashedRPCPassword)) + passwordHashExists := file.FileExists(filepath.Join(defaultWalletPath, HashedRPCPassword)) assert.Equal(t, true, passwordHashExists) // We attempt to create the wallet. diff --git a/validator/rpc/server.go b/validator/rpc/server.go index e6f8bded5..0451e840e 100644 --- a/validator/rpc/server.go +++ b/validator/rpc/server.go @@ -12,12 +12,12 @@ import ( grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing" grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" "github.com/prysmaticlabs/prysm/crypto/rand" + "github.com/prysmaticlabs/prysm/io/logs" "github.com/prysmaticlabs/prysm/monitoring/tracing" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" validatorpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/shared/event" - "github.com/prysmaticlabs/prysm/shared/logutil" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/validator/client" "github.com/prysmaticlabs/prysm/validator/db" @@ -58,7 +58,7 @@ type Config struct { // Server defining a gRPC server for the remote signer API. type Server struct { - logsStreamer logutil.Streamer + logsStreamer logs.Streamer streamLogsBufferSize int beaconChainClient ethpb.BeaconChainClient beaconNodeClient ethpb.NodeClient @@ -102,7 +102,7 @@ func NewServer(ctx context.Context, cfg *Config) *Server { return &Server{ ctx: ctx, cancel: cancel, - logsStreamer: logutil.NewStreamServer(), + logsStreamer: logs.NewStreamServer(), streamLogsBufferSize: 1000, // Enough to handle most bursts of logs in the validator client. host: cfg.Host, port: cfg.Port, diff --git a/validator/rpc/wallet.go b/validator/rpc/wallet.go index e5e1631af..8e4cc312f 100644 --- a/validator/rpc/wallet.go +++ b/validator/rpc/wallet.go @@ -12,9 +12,9 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/crypto/rand" + "github.com/prysmaticlabs/prysm/io/file" + "github.com/prysmaticlabs/prysm/io/prompt" pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client" - "github.com/prysmaticlabs/prysm/shared/fileutil" - "github.com/prysmaticlabs/prysm/shared/promptutil" "github.com/prysmaticlabs/prysm/validator/accounts" "github.com/prysmaticlabs/prysm/validator/accounts/iface" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" @@ -177,7 +177,7 @@ func (s *Server) RecoverWallet(ctx context.Context, req *pb.RecoverWalletRequest // Web UI should check the new and confirmed password are equal. walletPassword := req.WalletPassword - if err := promptutil.ValidatePasswordInput(walletPassword); err != nil { + if err := prompt.ValidatePasswordInput(walletPassword); err != nil { return nil, status.Error(codes.InvalidArgument, "password did not pass validation") } @@ -331,8 +331,8 @@ func writeWalletPasswordToDisk(walletDir, password string) error { return nil } passwordFilePath := filepath.Join(walletDir, wallet.DefaultWalletPasswordFile) - if fileutil.FileExists(passwordFilePath) { + if file.FileExists(passwordFilePath) { return fmt.Errorf("cannot write wallet password file as it already exists %s", passwordFilePath) } - return fileutil.WriteFile(passwordFilePath, []byte(password)) + return file.WriteFile(passwordFilePath, []byte(password)) } diff --git a/validator/rpc/wallet_test.go b/validator/rpc/wallet_test.go index e240b39e5..c3796ac6b 100644 --- a/validator/rpc/wallet_test.go +++ b/validator/rpc/wallet_test.go @@ -12,9 +12,9 @@ import ( "github.com/google/uuid" "github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/crypto/bls" + "github.com/prysmaticlabs/prysm/io/file" pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/shared/event" - "github.com/prysmaticlabs/prysm/shared/fileutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" "github.com/prysmaticlabs/prysm/validator/accounts" @@ -151,7 +151,7 @@ func TestServer_RecoverWallet_Derived(t *testing.T) { // Password File should have been written. passwordFilePath := filepath.Join(localWalletDir, wallet.DefaultWalletPasswordFile) - assert.Equal(t, true, fileutil.FileExists(passwordFilePath)) + assert.Equal(t, true, file.FileExists(passwordFilePath)) // Attempting to write again should trigger an error. err = writeWalletPasswordToDisk(localWalletDir, "somepassword") @@ -334,7 +334,7 @@ func Test_writeWalletPasswordToDisk(t *testing.T) { // Expected a silent failure if the feature flag is not enabled. passwordFilePath := filepath.Join(walletDir, wallet.DefaultWalletPasswordFile) - assert.Equal(t, false, fileutil.FileExists(passwordFilePath)) + assert.Equal(t, false, file.FileExists(passwordFilePath)) resetCfg = features.InitWithReset(&features.Flags{ WriteWalletPasswordOnWebOnboarding: true, }) @@ -343,7 +343,7 @@ func Test_writeWalletPasswordToDisk(t *testing.T) { require.NoError(t, err) // File should have been written. - assert.Equal(t, true, fileutil.FileExists(passwordFilePath)) + assert.Equal(t, true, file.FileExists(passwordFilePath)) // Attempting to write again should trigger an error. err = writeWalletPasswordToDisk(walletDir, "somepassword") diff --git a/validator/slashing-protection/BUILD.bazel b/validator/slashing-protection/BUILD.bazel index 62aa2e118..a1a5e201c 100644 --- a/validator/slashing-protection/BUILD.bazel +++ b/validator/slashing-protection/BUILD.bazel @@ -17,10 +17,10 @@ go_library( deps = [ "//api/grpc:go_default_library", "//cmd/validator/flags:go_default_library", + "//io/file:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//shared/cmd:go_default_library", - "//shared/fileutil:go_default_library", - "//validator/accounts/prompt:go_default_library", + "//validator/accounts/userprompt:go_default_library", "//validator/db/kv:go_default_library", "//validator/slashing-protection/local/standard-protection-format:go_default_library", "@com_github_grpc_ecosystem_go_grpc_middleware//:go_default_library", @@ -47,10 +47,10 @@ go_test( embed = [":go_default_library"], deps = [ "//cmd/validator/flags:go_default_library", + "//io/file:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//shared/bytesutil:go_default_library", "//shared/cmd:go_default_library", - "//shared/fileutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", "//validator/db/kv:go_default_library", diff --git a/validator/slashing-protection/cli_export.go b/validator/slashing-protection/cli_export.go index 37c75014e..430a7ff16 100644 --- a/validator/slashing-protection/cli_export.go +++ b/validator/slashing-protection/cli_export.go @@ -7,9 +7,9 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/cmd/validator/flags" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/shared/cmd" - "github.com/prysmaticlabs/prysm/shared/fileutil" - "github.com/prysmaticlabs/prysm/validator/accounts/prompt" + "github.com/prysmaticlabs/prysm/validator/accounts/userprompt" "github.com/prysmaticlabs/prysm/validator/db/kv" export "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format" "github.com/urfave/cli/v2" @@ -37,13 +37,13 @@ func ExportSlashingProtectionJSONCli(cliCtx *cli.Context) error { var err error dataDir := cliCtx.String(cmd.DataDirFlag.Name) if !cliCtx.IsSet(cmd.DataDirFlag.Name) { - dataDir, err = prompt.InputDirectory(cliCtx, prompt.DataDirDirPromptText, cmd.DataDirFlag) + dataDir, err = userprompt.InputDirectory(cliCtx, userprompt.DataDirDirPromptText, cmd.DataDirFlag) if err != nil { return errors.Wrapf(err, "could not read directory value from input") } } // ensure that the validator.db is found under the specified dir or its subdirectories - found, _, err := fileutil.RecursiveFileFind(kv.ProtectionDbFileName, dataDir) + found, _, err := file.RecursiveFileFind(kv.ProtectionDbFileName, dataDir) if err != nil { return errors.Wrapf(err, "error finding validator database at path %s", dataDir) } @@ -67,7 +67,7 @@ func ExportSlashingProtectionJSONCli(cliCtx *cli.Context) error { if err != nil { return errors.Wrap(err, "could not export slashing protection history") } - outputDir, err := prompt.InputDirectory( + outputDir, err := userprompt.InputDirectory( cliCtx, "Enter your desired output directory for your slashing protection history file", flags.SlashingProtectionExportDirFlag, @@ -78,12 +78,12 @@ func ExportSlashingProtectionJSONCli(cliCtx *cli.Context) error { if outputDir == "" { return errors.New("output directory not specified") } - exists, err := fileutil.HasDir(outputDir) + exists, err := file.HasDir(outputDir) if err != nil { return errors.Wrapf(err, "could not check if output directory %s already exists", outputDir) } if !exists { - if err := fileutil.MkdirAll(outputDir); err != nil { + if err := file.MkdirAll(outputDir); err != nil { return errors.Wrapf(err, "could not create output directory %s", outputDir) } } @@ -93,7 +93,7 @@ func ExportSlashingProtectionJSONCli(cliCtx *cli.Context) error { if err != nil { return errors.Wrap(err, "could not JSON marshal slashing protection history") } - if err := fileutil.WriteFile(outputFilePath, encoded); err != nil { + if err := file.WriteFile(outputFilePath, encoded); err != nil { return errors.Wrapf(err, "could not write file to path %s", outputFilePath) } log.Infof( diff --git a/validator/slashing-protection/cli_import.go b/validator/slashing-protection/cli_import.go index 1498abd84..48bc1b908 100644 --- a/validator/slashing-protection/cli_import.go +++ b/validator/slashing-protection/cli_import.go @@ -6,9 +6,9 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/cmd/validator/flags" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/shared/cmd" - "github.com/prysmaticlabs/prysm/shared/fileutil" - "github.com/prysmaticlabs/prysm/validator/accounts/prompt" + "github.com/prysmaticlabs/prysm/validator/accounts/userprompt" "github.com/prysmaticlabs/prysm/validator/db/kv" slashingProtectionFormat "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format" "github.com/urfave/cli/v2" @@ -27,13 +27,13 @@ func ImportSlashingProtectionCLI(cliCtx *cli.Context) error { var err error dataDir := cliCtx.String(cmd.DataDirFlag.Name) if !cliCtx.IsSet(cmd.DataDirFlag.Name) { - dataDir, err = prompt.InputDirectory(cliCtx, prompt.DataDirDirPromptText, cmd.DataDirFlag) + dataDir, err = userprompt.InputDirectory(cliCtx, userprompt.DataDirDirPromptText, cmd.DataDirFlag) if err != nil { return errors.Wrapf(err, "could not read directory value from input") } } // ensure that the validator.db is found under the specified dir or its subdirectories - found, _, err := fileutil.RecursiveFileFind(kv.ProtectionDbFileName, dataDir) + found, _, err := file.RecursiveFileFind(kv.ProtectionDbFileName, dataDir) if err != nil { return errors.Wrapf(err, "error finding validator database at path %s", dataDir) } @@ -54,7 +54,7 @@ func ImportSlashingProtectionCLI(cliCtx *cli.Context) error { log.WithError(err).Errorf("Could not close validator DB") } }() - protectionFilePath, err := prompt.InputDirectory(cliCtx, prompt.SlashingProtectionJSONPromptText, flags.SlashingProtectionJSONFileFlag) + protectionFilePath, err := userprompt.InputDirectory(cliCtx, userprompt.SlashingProtectionJSONPromptText, flags.SlashingProtectionJSONFileFlag) if err != nil { return errors.Wrap(err, "could not get slashing protection json file") } @@ -65,7 +65,7 @@ func ImportSlashingProtectionCLI(cliCtx *cli.Context) error { flags.SlashingProtectionJSONFileFlag.Name, ) } - enc, err := fileutil.ReadFileAsBytes(protectionFilePath) + enc, err := file.ReadFileAsBytes(protectionFilePath) if err != nil { return err } diff --git a/validator/slashing-protection/cli_import_export_test.go b/validator/slashing-protection/cli_import_export_test.go index fcaa3fefb..85bb630f8 100644 --- a/validator/slashing-protection/cli_import_export_test.go +++ b/validator/slashing-protection/cli_import_export_test.go @@ -8,8 +8,8 @@ import ( "testing" "github.com/prysmaticlabs/prysm/cmd/validator/flags" + "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/shared/cmd" - "github.com/prysmaticlabs/prysm/shared/fileutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" "github.com/prysmaticlabs/prysm/validator/db/kv" @@ -39,7 +39,7 @@ func setupCliCtx( func TestImportExportSlashingProtectionCli_RoundTrip(t *testing.T) { numValidators := 10 outputPath := filepath.Join(os.TempDir(), "slashing-exports") - err := fileutil.MkdirAll(outputPath) + err := file.MkdirAll(outputPath) require.NoError(t, err) protectionFileName := "slashing_history_import.json" @@ -56,7 +56,7 @@ func TestImportExportSlashingProtectionCli_RoundTrip(t *testing.T) { require.NoError(t, err) protectionFilePath := filepath.Join(outputPath, protectionFileName) - err = fileutil.WriteFile(protectionFilePath, encoded) + err = file.WriteFile(protectionFilePath, encoded) require.NoError(t, err) // We create a CLI context with the required values, such as the database datadir and output directory. @@ -74,7 +74,7 @@ func TestImportExportSlashingProtectionCli_RoundTrip(t *testing.T) { require.NoError(t, err) // Attempt to read the exported file from the output directory. - enc, err := fileutil.ReadFileAsBytes(filepath.Join(outputPath, jsonExportFileName)) + enc, err := file.ReadFileAsBytes(filepath.Join(outputPath, jsonExportFileName)) require.NoError(t, err) receivedJSON := &format.EIPSlashingProtectionFormat{} @@ -112,7 +112,7 @@ func TestImportExportSlashingProtectionCli_RoundTrip(t *testing.T) { func TestImportExportSlashingProtectionCli_EmptyData(t *testing.T) { numValidators := 10 outputPath := filepath.Join(os.TempDir(), "slashing-exports") - err := fileutil.MkdirAll(outputPath) + err := file.MkdirAll(outputPath) require.NoError(t, err) protectionFileName := "slashing_history_import.json" @@ -132,7 +132,7 @@ func TestImportExportSlashingProtectionCli_EmptyData(t *testing.T) { require.NoError(t, err) protectionFilePath := filepath.Join(outputPath, protectionFileName) - err = fileutil.WriteFile(protectionFilePath, encoded) + err = file.WriteFile(protectionFilePath, encoded) require.NoError(t, err) // We create a CLI context with the required values, such as the database datadir and output directory. @@ -150,7 +150,7 @@ func TestImportExportSlashingProtectionCli_EmptyData(t *testing.T) { require.NoError(t, err) // Attempt to read the exported file from the output directory. - enc, err := fileutil.ReadFileAsBytes(filepath.Join(outputPath, jsonExportFileName)) + enc, err := file.ReadFileAsBytes(filepath.Join(outputPath, jsonExportFileName)) require.NoError(t, err) receivedJSON := &format.EIPSlashingProtectionFormat{}