From d860daff7516181460b8501278a208e65f4cd013 Mon Sep 17 00:00:00 2001 From: terencechain Date: Mon, 12 Sep 2022 16:03:20 +0200 Subject: [PATCH] clean up: godoc comments, redundant castings and more (#11428) * clean up: Godoc comments, redundant castings and more * Fix assertion check * Update beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go Co-authored-by: Preston Van Loon * Update beacon-chain/forkchoice/protoarray/store.go Co-authored-by: Preston Van Loon Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Preston Van Loon --- beacon-chain/blockchain/process_block_test.go | 2 +- beacon-chain/db/kv/execution_chain.go | 4 ++-- beacon-chain/execution/log_processing.go | 2 +- .../forkchoice/doubly-linked-tree/forkchoice.go | 2 +- .../doubly-linked-tree/proposer_boost_test.go | 2 +- .../forkchoice/protoarray/proposer_boost_test.go | 2 +- beacon-chain/forkchoice/protoarray/store.go | 2 +- beacon-chain/p2p/options.go | 2 +- beacon-chain/p2p/service_test.go | 2 +- proto/engine/v1/json_marshal_unmarshal.go | 4 ++-- proto/prysm/v1alpha1/cloners_test.go | 10 ---------- validator/accounts/wallet_create.go | 2 +- validator/rpc/standard_api_test.go | 10 +++++----- 13 files changed, 18 insertions(+), 28 deletions(-) diff --git a/beacon-chain/blockchain/process_block_test.go b/beacon-chain/blockchain/process_block_test.go index 24f4d455e4..23ce1b0fa8 100644 --- a/beacon-chain/blockchain/process_block_test.go +++ b/beacon-chain/blockchain/process_block_test.go @@ -3411,6 +3411,6 @@ func TestOnBlock_HandleBlockAttestations(t *testing.T) { // Helper function to simulate the block being on time or delayed for proposer // boost. It alters the genesisTime tracked by the store. func driftGenesisTime(s *Service, slot int64, delay int64) { - offset := int64(slot*int64(params.BeaconConfig().SecondsPerSlot) - delay) + offset := slot*int64(params.BeaconConfig().SecondsPerSlot) - delay s.SetGenesisTime(time.Unix(time.Now().Unix()-offset, 0)) } diff --git a/beacon-chain/db/kv/execution_chain.go b/beacon-chain/db/kv/execution_chain.go index cfe1517980..2a49ab8b26 100644 --- a/beacon-chain/db/kv/execution_chain.go +++ b/beacon-chain/db/kv/execution_chain.go @@ -11,7 +11,7 @@ import ( "google.golang.org/protobuf/proto" ) -// SavePowchainData saves the pow chain data. +// SaveExecutionChainData saves the execution chain data. func (s *Store) SaveExecutionChainData(ctx context.Context, data *v2.ETH1ChainData) error { ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveExecutionChainData") defer span.End() @@ -34,7 +34,7 @@ func (s *Store) SaveExecutionChainData(ctx context.Context, data *v2.ETH1ChainDa return err } -// PowchainData retrieves the powchain data. +// ExecutionChainData retrieves the execution chain data. func (s *Store) ExecutionChainData(ctx context.Context) (*v2.ETH1ChainData, error) { ctx, span := trace.StartSpan(ctx, "BeaconDB.ExecutionChainData") defer span.End() diff --git a/beacon-chain/execution/log_processing.go b/beacon-chain/execution/log_processing.go index b4056ddda9..65419ce070 100644 --- a/beacon-chain/execution/log_processing.go +++ b/beacon-chain/execution/log_processing.go @@ -51,7 +51,7 @@ func clientTimedOutError(err error) bool { return strings.Contains(err.Error(), errTimedOut.Error()) } -// Eth2GenesisPowchainInfo retrieves the genesis time and eth1 block number of the beacon chain +// GenesisExecutionChainInfo retrieves the genesis time and execution block number of the beacon chain // from the deposit contract. func (s *Service) GenesisExecutionChainInfo() (uint64, *big.Int) { return s.chainStartData.GenesisTime, big.NewInt(int64(s.chainStartData.GenesisBlock)) diff --git a/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go b/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go index 5f4fd0e48c..e9e6c03b9a 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go @@ -491,7 +491,7 @@ func (f *ForkChoice) UpdateFinalizedCheckpoint(fc *forkchoicetypes.Checkpoint) e return nil } -// CommonAncestorRoot returns the common ancestor root between the two block roots r1 and r2. +// CommonAncestor returns the common ancestor root and slot between the two block roots r1 and r2. func (f *ForkChoice) CommonAncestor(ctx context.Context, r1 [32]byte, r2 [32]byte) ([32]byte, types.Slot, error) { ctx, span := trace.StartSpan(ctx, "doublelinkedtree.CommonAncestorRoot") defer span.End() diff --git a/beacon-chain/forkchoice/doubly-linked-tree/proposer_boost_test.go b/beacon-chain/forkchoice/doubly-linked-tree/proposer_boost_test.go index afb553d382..44e0a765a7 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/proposer_boost_test.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/proposer_boost_test.go @@ -430,7 +430,7 @@ func TestForkChoice_BoostProposerRoot(t *testing.T) { f := setup(0, 0) slot := types.Slot(1) currentSlot := types.Slot(1) - driftGenesisTime(f, currentSlot, uint64(params.BeaconConfig().SecondsPerSlot-1)) + driftGenesisTime(f, currentSlot, params.BeaconConfig().SecondsPerSlot-1) state, blkRoot, err := prepareForkchoiceState(ctx, slot, root, zeroHash, zeroHash, 0, 0) require.NoError(t, err) require.NoError(t, f.InsertNode(ctx, state, blkRoot)) diff --git a/beacon-chain/forkchoice/protoarray/proposer_boost_test.go b/beacon-chain/forkchoice/protoarray/proposer_boost_test.go index c66270fa6a..0f2f71eab3 100644 --- a/beacon-chain/forkchoice/protoarray/proposer_boost_test.go +++ b/beacon-chain/forkchoice/protoarray/proposer_boost_test.go @@ -426,7 +426,7 @@ func TestForkChoice_BoostProposerRoot(t *testing.T) { f := setup(0, 0) slot := types.Slot(1) currentSlot := types.Slot(1) - driftGenesisTime(f, currentSlot, uint64(params.BeaconConfig().SecondsPerSlot-1)) + driftGenesisTime(f, currentSlot, params.BeaconConfig().SecondsPerSlot-1) state, blkRoot, err := prepareForkchoiceState(ctx, slot, root, zeroHash, zeroHash, 0, 0) require.NoError(t, err) require.NoError(t, f.InsertNode(ctx, state, blkRoot)) diff --git a/beacon-chain/forkchoice/protoarray/store.go b/beacon-chain/forkchoice/protoarray/store.go index b47564e965..03453d19e0 100644 --- a/beacon-chain/forkchoice/protoarray/store.go +++ b/beacon-chain/forkchoice/protoarray/store.go @@ -281,7 +281,7 @@ func (f *ForkChoice) AncestorRoot(ctx context.Context, root [32]byte, slot types return f.store.nodes[i].root, nil } -// CommonAncestorRoot returns the common ancestor root between the two block roots r1 and r2. +// CommonAncestor returns the common ancestor root and slot between the two block roots r1 and r2. func (f *ForkChoice) CommonAncestor(ctx context.Context, r1 [32]byte, r2 [32]byte) ([32]byte, types.Slot, error) { ctx, span := trace.StartSpan(ctx, "protoArray.CommonAncestorRoot") defer span.End() diff --git a/beacon-chain/p2p/options.go b/beacon-chain/p2p/options.go index 0fab1e2fe8..701e3b4ada 100644 --- a/beacon-chain/p2p/options.go +++ b/beacon-chain/p2p/options.go @@ -8,7 +8,7 @@ import ( "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p/p2p/muxer/mplex" - noise "github.com/libp2p/go-libp2p/p2p/security/noise" + "github.com/libp2p/go-libp2p/p2p/security/noise" "github.com/libp2p/go-libp2p/p2p/transport/tcp" ma "github.com/multiformats/go-multiaddr" "github.com/pkg/errors" diff --git a/beacon-chain/p2p/service_test.go b/beacon-chain/p2p/service_test.go index caf12f26a4..786f55c08a 100644 --- a/beacon-chain/p2p/service_test.go +++ b/beacon-chain/p2p/service_test.go @@ -13,7 +13,7 @@ import ( "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/peer" - noise "github.com/libp2p/go-libp2p/p2p/security/noise" + "github.com/libp2p/go-libp2p/p2p/security/noise" "github.com/multiformats/go-multiaddr" "github.com/prysmaticlabs/prysm/v3/async/event" mock "github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain/testing" diff --git a/proto/engine/v1/json_marshal_unmarshal.go b/proto/engine/v1/json_marshal_unmarshal.go index aaece6e5a4..a75c2f0089 100644 --- a/proto/engine/v1/json_marshal_unmarshal.go +++ b/proto/engine/v1/json_marshal_unmarshal.go @@ -275,7 +275,7 @@ func (p *PayloadStatus) MarshalJSON() ([]byte, error) { var latestHash *common.Hash if p.LatestValidHash != nil { hash := common.Hash(bytesutil.ToBytes32(p.LatestValidHash)) - latestHash = (*common.Hash)(&hash) + latestHash = &hash } return json.Marshal(payloadStatusJSON{ LatestValidHash: latestHash, @@ -324,7 +324,7 @@ func (t *TransitionConfiguration) MarshalJSON() ([]byte, error) { } return json.Marshal(transitionConfigurationJSON{ TerminalTotalDifficulty: hexNum, - TerminalBlockHash: common.Hash(*(*[32]byte)(t.TerminalBlockHash)), + TerminalBlockHash: *(*[32]byte)(t.TerminalBlockHash), TerminalBlockNumber: hexutil.Uint64(num.Uint64()), }) } diff --git a/proto/prysm/v1alpha1/cloners_test.go b/proto/prysm/v1alpha1/cloners_test.go index afa5582603..b8685a56a3 100644 --- a/proto/prysm/v1alpha1/cloners_test.go +++ b/proto/prysm/v1alpha1/cloners_test.go @@ -682,16 +682,6 @@ func genBlindedBeaconBlockBodyBellatrix() *v1alpha1.BlindedBeaconBlockBodyBellat } } -func genBlindedBeaconBlockBellatrix() *v1alpha1.BlindedBeaconBlockBellatrix { - return &v1alpha1.BlindedBeaconBlockBellatrix{ - Slot: 123455, - ProposerIndex: 55433, - ParentRoot: bytes(), - StateRoot: bytes(), - Body: genBlindedBeaconBlockBodyBellatrix(), - } -} - func genSyncCommitteeMessage() *v1alpha1.SyncCommitteeMessage { return &v1alpha1.SyncCommitteeMessage{ Slot: 424555, diff --git a/validator/accounts/wallet_create.go b/validator/accounts/wallet_create.go index fbb69eede8..9404d6b146 100644 --- a/validator/accounts/wallet_create.go +++ b/validator/accounts/wallet_create.go @@ -13,7 +13,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/validator/keymanager/remote" ) -// CreateWalletWithKeymanager specified by configuration options. +// WalletCreate creates wallet specified by configuration options. func (acm *AccountsCLIManager) WalletCreate(ctx context.Context) (*wallet.Wallet, error) { w := wallet.New(&wallet.Config{ WalletDir: acm.walletDir, diff --git a/validator/rpc/standard_api_test.go b/validator/rpc/standard_api_test.go index 039bff3e7d..cb215564a3 100644 --- a/validator/rpc/standard_api_test.go +++ b/validator/rpc/standard_api_test.go @@ -938,7 +938,7 @@ func TestServer_SetGasLimit(t *testing.T) { }, }, w: []want{ - want{ + { pubkey: pubkey1, gaslimit: 9999, }, @@ -959,11 +959,11 @@ func TestServer_SetGasLimit(t *testing.T) { }, }, w: []want{ - want{ + { pubkey: pubkey1, gaslimit: 123456789, }, - want{ + { pubkey: pubkey2, gaslimit: 8888, }, @@ -979,7 +979,7 @@ func TestServer_SetGasLimit(t *testing.T) { }, }, w: []want{ - want{ + { pubkey: pubkey1, gaslimit: 8888, }, @@ -991,7 +991,7 @@ func TestServer_SetGasLimit(t *testing.T) { newGasLimit: 7777, // proposerSettings is not set - we need to create proposerSettings and set gaslimit properly w: []want{ - want{ + { pubkey: pubkey1, gaslimit: 7777, },