Fix redundant type converstion (#13076)

* Fix redundant type converstion

* Revert generated changes

---------

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
terencechain
2023-10-20 08:07:10 -07:00
committed by GitHub
parent 88e1b9edb3
commit 823f8ee3a2
14 changed files with 21 additions and 23 deletions

View File

@@ -876,7 +876,7 @@ func testSignedBlindedBeaconBlockAndBlobsDeneb(t *testing.T) *eth.SignedBlindedB
},
SyncAggregate: &eth.SyncAggregate{
SyncCommitteeSignature: make([]byte, 96),
SyncCommitteeBits: bitfield.Bitvector512(ezDecode(t, "0x6451e9f951ebf05edc01de67e593484b672877054f055903ff0df1a1a945cf30ca26bb4d4b154f94a1bc776bcf5d0efb3603e1f9b8ee2499ccdcfe2a18cef458")),
SyncCommitteeBits: ezDecode(t, "0x6451e9f951ebf05edc01de67e593484b672877054f055903ff0df1a1a945cf30ca26bb4d4b154f94a1bc776bcf5d0efb3603e1f9b8ee2499ccdcfe2a18cef458"),
},
ExecutionPayloadHeader: &v1.ExecutionPayloadHeaderDeneb{
ParentHash: ezDecode(t, "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"),

View File

@@ -8,7 +8,6 @@ import (
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v4/config/params"
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
ethpbv1 "github.com/prysmaticlabs/prysm/v4/proto/eth/v1"
ethpbv2 "github.com/prysmaticlabs/prysm/v4/proto/eth/v2"
@@ -63,7 +62,7 @@ func NewLightClientOptimisticUpdateFromBeaconState(
attestedState state.BeaconState) (*ethpbv2.LightClientUpdate, error) {
// assert compute_epoch_at_slot(attested_state.slot) >= ALTAIR_FORK_EPOCH
attestedEpoch := slots.ToEpoch(attestedState.Slot())
if attestedEpoch < types.Epoch(params.BeaconConfig().AltairForkEpoch) {
if attestedEpoch < params.BeaconConfig().AltairForkEpoch {
return nil, fmt.Errorf("invalid attested epoch %d", attestedEpoch)
}

View File

@@ -91,7 +91,7 @@ func TestStore_BlobSidecars(t *testing.T) {
db := setupDB(t)
scs := generateBlobSidecars(t, fieldparams.MaxBlobsPerBlock)
require.NoError(t, db.SaveBlobSidecar(ctx, scs))
require.Equal(t, int(fieldparams.MaxBlobsPerBlock), len(scs))
require.Equal(t, fieldparams.MaxBlobsPerBlock, len(scs))
// we'll request indices 0 and 3, so make a slice with those indices for comparison
expect := make([]*ethpb.BlobSidecar, 2)
@@ -108,7 +108,7 @@ func TestStore_BlobSidecars(t *testing.T) {
db := setupDB(t)
scs := generateBlobSidecars(t, fieldparams.MaxBlobsPerBlock)
require.NoError(t, db.SaveBlobSidecar(ctx, scs))
require.Equal(t, int(fieldparams.MaxBlobsPerBlock), len(scs))
require.Equal(t, fieldparams.MaxBlobsPerBlock, len(scs))
got, err := db.BlobSidecarsByRoot(ctx, bytesutil.ToBytes32(scs[0].BlockRoot), uint64(len(scs)))
require.ErrorIs(t, err, ErrNotFound)
@@ -127,7 +127,7 @@ func TestStore_BlobSidecars(t *testing.T) {
db := setupDB(t)
scs := generateBlobSidecars(t, fieldparams.MaxBlobsPerBlock)
require.NoError(t, db.SaveBlobSidecar(ctx, scs))
require.Equal(t, int(fieldparams.MaxBlobsPerBlock), len(scs))
require.Equal(t, fieldparams.MaxBlobsPerBlock, len(scs))
got, err := db.BlobSidecarsBySlot(ctx, scs[0].Slot)
require.NoError(t, err)
require.NoError(t, equalBlobSlices(scs, got))
@@ -147,7 +147,7 @@ func TestStore_BlobSidecars(t *testing.T) {
db := setupDB(t)
scs := generateBlobSidecars(t, fieldparams.MaxBlobsPerBlock)
require.NoError(t, db.SaveBlobSidecar(ctx, scs))
require.Equal(t, int(fieldparams.MaxBlobsPerBlock), len(scs))
require.Equal(t, fieldparams.MaxBlobsPerBlock, len(scs))
// we'll request indices 0 and 3, so make a slice with those indices for comparison
expect := make([]*ethpb.BlobSidecar, 2)
@@ -165,7 +165,7 @@ func TestStore_BlobSidecars(t *testing.T) {
db := setupDB(t)
scs := generateBlobSidecars(t, fieldparams.MaxBlobsPerBlock)
require.NoError(t, db.SaveBlobSidecar(ctx, scs))
require.Equal(t, int(fieldparams.MaxBlobsPerBlock), len(scs))
require.Equal(t, fieldparams.MaxBlobsPerBlock, len(scs))
got, err := db.BlobSidecarsBySlot(ctx, scs[0].Slot, uint64(len(scs)))
require.ErrorIs(t, err, ErrNotFound)
@@ -175,7 +175,7 @@ func TestStore_BlobSidecars(t *testing.T) {
db := setupDB(t)
scs := generateBlobSidecars(t, fieldparams.MaxBlobsPerBlock)
require.NoError(t, db.SaveBlobSidecar(ctx, scs))
require.Equal(t, int(fieldparams.MaxBlobsPerBlock), len(scs))
require.Equal(t, fieldparams.MaxBlobsPerBlock, len(scs))
got, err := db.BlobSidecarsByRoot(ctx, bytesutil.ToBytes32(scs[0].BlockRoot))
require.NoError(t, err)
require.NoError(t, equalBlobSlices(scs, got))

View File

@@ -291,7 +291,7 @@ func (s *Server) streamPayloadAttributes(stream ethpbservice.Events_StreamEvents
return err
}
t, err := slots.ToTime(uint64(headState.GenesisTime()), headState.Slot())
t, err := slots.ToTime(headState.GenesisTime(), headState.Slot())
if err != nil {
return err
}

View File

@@ -3260,5 +3260,5 @@ func sszBytesToUint256String(b []byte) (string, error) {
if !math.IsValidUint256(bi) {
return "", fmt.Errorf("%s is not a valid Uint256", bi.String())
}
return string([]byte(bi.String())), nil
return string(bi.String()), nil
}

View File

@@ -466,7 +466,7 @@ func (s *Server) ProduceSyncCommitteeContribution(w http.ResponseWriter, r *http
http2.HandleError(w, "Invalid Beacon Block Root: "+err.Error(), http.StatusBadRequest)
return
}
contribution, ok := s.produceSyncCommitteeContribution(ctx, w, primitives.Slot(slot), index, []byte(blockRoot))
contribution, ok := s.produceSyncCommitteeContribution(ctx, w, primitives.Slot(slot), index, blockRoot)
if !ok {
return
}

View File

@@ -54,7 +54,7 @@ func (b *BeaconState) AppendCurrentEpochAttestations(val *ethpb.PendingAttestati
}
atts := b.currentEpochAttestations
max := uint64(params.BeaconConfig().CurrentEpochAttestationsLength())
max := params.BeaconConfig().CurrentEpochAttestationsLength()
if uint64(len(atts)) >= max {
return fmt.Errorf("current pending attestation exceeds max length %d", max)
}
@@ -84,7 +84,7 @@ func (b *BeaconState) AppendPreviousEpochAttestations(val *ethpb.PendingAttestat
}
atts := b.previousEpochAttestations
max := uint64(params.BeaconConfig().PreviousEpochAttestationsLength())
max := params.BeaconConfig().PreviousEpochAttestationsLength()
if uint64(len(atts)) >= max {
return fmt.Errorf("previous pending attestation exceeds max length %d", max)
}

View File

@@ -79,7 +79,7 @@ func BenchmarkAppendPreviousEpochAttestations(b *testing.B) {
st, err := InitializeFromProtoPhase0(&ethpb.BeaconState{})
require.NoError(b, err)
max := uint64(params.BeaconConfig().PreviousEpochAttestationsLength())
max := params.BeaconConfig().PreviousEpochAttestationsLength()
if max < 2 {
b.Fatalf("previous epoch attestations length is less than 2: %d", max)
}

View File

@@ -18,7 +18,7 @@ func RootsArrayHashTreeRoot(vals [][]byte, length uint64) ([32]byte, error) {
}
func EpochAttestationsRoot(atts []*ethpb.PendingAttestation) ([32]byte, error) {
max := uint64(params.BeaconConfig().CurrentEpochAttestationsLength())
max := params.BeaconConfig().CurrentEpochAttestationsLength()
if uint64(len(atts)) > max {
return [32]byte{}, fmt.Errorf("epoch attestation exceeds max length %d", max)
}

View File

@@ -41,8 +41,8 @@ func (rt *rpcHandlerTest) testHandler(nh network.StreamHandler, rh rpcHandler, r
defer w.Done()
nh(stream)
}
server.BHost.SetStreamHandler(protocol.ID(rt.topic), h)
stream, err := client.BHost.NewStream(ctx, server.BHost.ID(), protocol.ID(rt.topic))
server.BHost.SetStreamHandler(rt.topic, h)
stream, err := client.BHost.NewStream(ctx, server.BHost.ID(), rt.topic)
require.NoError(rt.t, err)
err = rh(ctx, rhi, stream)

View File

@@ -13,7 +13,6 @@ import (
pubsub "github.com/libp2p/go-libp2p-pubsub"
libp2pcore "github.com/libp2p/go-libp2p/core"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
gcache "github.com/patrickmn/go-cache"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v4/async"
@@ -208,7 +207,7 @@ func (s *Service) Stop() error {
}()
// Removing RPC Stream handlers.
for _, p := range s.cfg.p2p.Host().Mux().Protocols() {
s.cfg.p2p.Host().RemoveStreamHandler(protocol.ID(p))
s.cfg.p2p.Host().RemoveStreamHandler(p)
}
// Deregister Topic Subscribers.
for _, t := range s.cfg.p2p.PubSub().GetTopics() {

View File

@@ -704,7 +704,7 @@ func NewInvalidSignatureSet(t *testing.T, msgBody string, num int, throwErr bool
func messageBytes(message string) [32]byte {
var bytes [32]byte
copy(bytes[:], []byte(message))
copy(bytes[:], message)
return bytes
}

View File

@@ -23,7 +23,7 @@ func (x *SyncCommittee) Equals(other *SyncCommittee) bool {
}
func FloorLog2(x uint64) int {
return bits.Len64(uint64(x - 1))
return bits.Len64(x - 1)
}
func isEmptyWithLength(bb [][]byte, length uint64) bool {

View File

@@ -255,7 +255,7 @@ func (p *Builder) registerValidators(w http.ResponseWriter, req *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
p.validatorMap[string(r.Message.Pubkey)] = msg
p.validatorMap[r.Message.Pubkey] = msg
}
// TODO: Verify Signatures from validators
w.WriteHeader(http.StatusOK)