Clean up state types (#11916)

* Clean up state types

* rename package
This commit is contained in:
Radosław Kapka
2023-01-26 15:40:12 +01:00
committed by GitHub
parent a296a0c783
commit 77d3ccb9ad
555 changed files with 4696 additions and 4958 deletions

View File

@@ -2,32 +2,32 @@ package bytesutil
import (
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
)
// EpochToBytesLittleEndian conversion.
func EpochToBytesLittleEndian(i types.Epoch) []byte {
func EpochToBytesLittleEndian(i primitives.Epoch) []byte {
return Uint64ToBytesLittleEndian(uint64(i))
}
// EpochToBytesBigEndian conversion.
func EpochToBytesBigEndian(i types.Epoch) []byte {
func EpochToBytesBigEndian(i primitives.Epoch) []byte {
return Uint64ToBytesBigEndian(uint64(i))
}
// BytesToEpochBigEndian conversion.
func BytesToEpochBigEndian(b []byte) types.Epoch {
return types.Epoch(BytesToUint64BigEndian(b))
func BytesToEpochBigEndian(b []byte) primitives.Epoch {
return primitives.Epoch(BytesToUint64BigEndian(b))
}
// SlotToBytesBigEndian conversion.
func SlotToBytesBigEndian(i types.Slot) []byte {
func SlotToBytesBigEndian(i primitives.Slot) []byte {
return Uint64ToBytesBigEndian(uint64(i))
}
// BytesToSlotBigEndian conversion.
func BytesToSlotBigEndian(b []byte) types.Slot {
return types.Slot(BytesToUint64BigEndian(b))
func BytesToSlotBigEndian(b []byte) primitives.Slot {
return primitives.Slot(BytesToUint64BigEndian(b))
}
// ZeroRoot returns whether or not a root is of proper length and non-zero hash.

View File

@@ -14,7 +14,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/config/params"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/runtime/version"
"github.com/prysmaticlabs/prysm/v3/time/slots"
@@ -138,12 +138,12 @@ var beaconBlockSlot = fieldSpec{
t: typeUint64,
}
func slotFromBlock(marshaled []byte) (types.Slot, error) {
func slotFromBlock(marshaled []byte) (primitives.Slot, error) {
slot, err := beaconBlockSlot.uint64(marshaled)
if err != nil {
return 0, err
}
return types.Slot(slot), nil
return primitives.Slot(slot), nil
}
var errBlockForkMismatch = errors.New("fork or config detected in unmarshaler is different than block")
@@ -212,7 +212,7 @@ func (cf *VersionedUnmarshaler) UnmarshalBlindedBeaconBlock(marshaled []byte) (i
// Heuristic to make sure block is from the same version as the VersionedUnmarshaler.
// Look up the version for the epoch that the block is from, then ensure that it matches the Version in the
// VersionedUnmarshaler.
func (cf *VersionedUnmarshaler) validateVersion(slot types.Slot) error {
func (cf *VersionedUnmarshaler) validateVersion(slot primitives.Slot) error {
epoch := slots.ToEpoch(slot)
fs := forks.NewOrderedSchedule(cf.Config)
ver, err := fs.VersionForEpoch(epoch)

View File

@@ -15,14 +15,14 @@ import (
"github.com/prysmaticlabs/prysm/v3/testing/util"
"github.com/prysmaticlabs/prysm/v3/time/slots"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/testing/require"
)
func TestSlotFromBlock(t *testing.T) {
b := util.NewBeaconBlock()
var slot types.Slot = 3
var slot primitives.Slot = 3
b.Block.Slot = slot
bb, err := b.MarshalSSZ()
require.NoError(t, err)
@@ -63,7 +63,7 @@ func TestByState(t *testing.T) {
cases := []struct {
name string
version int
slot types.Slot
slot primitives.Slot
forkversion [4]byte
}{
{
@@ -139,7 +139,7 @@ func TestUnmarshalState(t *testing.T) {
cases := []struct {
name string
version int
slot types.Slot
slot primitives.Slot
forkversion [4]byte
}{
{
@@ -208,10 +208,10 @@ func TestUnmarshalBlock(t *testing.T) {
bellaS, err := slots.EpochStart(params.BeaconConfig().BellatrixForkEpoch)
require.NoError(t, err)
cases := []struct {
b func(*testing.T, types.Slot) interfaces.SignedBeaconBlock
b func(*testing.T, primitives.Slot) interfaces.SignedBeaconBlock
name string
version [4]byte
slot types.Slot
slot primitives.Slot
err error
}{
{
@@ -299,10 +299,10 @@ func TestUnmarshalBlindedBlock(t *testing.T) {
bellaS, err := slots.EpochStart(params.BeaconConfig().BellatrixForkEpoch)
require.NoError(t, err)
cases := []struct {
b func(*testing.T, types.Slot) interfaces.SignedBeaconBlock
b func(*testing.T, primitives.Slot) interfaces.SignedBeaconBlock
name string
version [4]byte
slot types.Slot
slot primitives.Slot
err error
}{
{
@@ -377,7 +377,7 @@ func TestUnmarshalBlindedBlock(t *testing.T) {
}
}
func signedTestBlockGenesis(t *testing.T, slot types.Slot) interfaces.SignedBeaconBlock {
func signedTestBlockGenesis(t *testing.T, slot primitives.Slot) interfaces.SignedBeaconBlock {
b := util.NewBeaconBlock()
b.Block.Slot = slot
s, err := blocks.NewSignedBeaconBlock(b)
@@ -385,7 +385,7 @@ func signedTestBlockGenesis(t *testing.T, slot types.Slot) interfaces.SignedBeac
return s
}
func signedTestBlockAltair(t *testing.T, slot types.Slot) interfaces.SignedBeaconBlock {
func signedTestBlockAltair(t *testing.T, slot primitives.Slot) interfaces.SignedBeaconBlock {
b := util.NewBeaconBlockAltair()
b.Block.Slot = slot
s, err := blocks.NewSignedBeaconBlock(b)
@@ -393,7 +393,7 @@ func signedTestBlockAltair(t *testing.T, slot types.Slot) interfaces.SignedBeaco
return s
}
func signedTestBlockBellatrix(t *testing.T, slot types.Slot) interfaces.SignedBeaconBlock {
func signedTestBlockBellatrix(t *testing.T, slot primitives.Slot) interfaces.SignedBeaconBlock {
b := util.NewBeaconBlockBellatrix()
b.Block.Slot = slot
s, err := blocks.NewSignedBeaconBlock(b)
@@ -401,7 +401,7 @@ func signedTestBlockBellatrix(t *testing.T, slot types.Slot) interfaces.SignedBe
return s
}
func signedTestBlindedBlockBellatrix(t *testing.T, slot types.Slot) interfaces.SignedBeaconBlock {
func signedTestBlindedBlockBellatrix(t *testing.T, slot primitives.Slot) interfaces.SignedBeaconBlock {
b := util.NewBlindedBeaconBlockBellatrix()
b.Block.Slot = slot
s, err := blocks.NewSignedBeaconBlock(b)

View File

@@ -4,7 +4,7 @@ import (
"reflect"
"unsafe"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"google.golang.org/protobuf/proto"
)
@@ -223,13 +223,13 @@ func deepValueBaseTypeEqual(v1, v2 reflect.Value) bool {
case reflect.Uint64:
switch v1.Type().Name() {
case "Epoch":
return v1.Interface().(types.Epoch) == v2.Interface().(types.Epoch)
return v1.Interface().(primitives.Epoch) == v2.Interface().(primitives.Epoch)
case "Slot":
return v1.Interface().(types.Slot) == v2.Interface().(types.Slot)
return v1.Interface().(primitives.Slot) == v2.Interface().(primitives.Slot)
case "ValidatorIndex":
return v1.Interface().(types.ValidatorIndex) == v2.Interface().(types.ValidatorIndex)
return v1.Interface().(primitives.ValidatorIndex) == v2.Interface().(primitives.ValidatorIndex)
case "CommitteeIndex":
return v1.Interface().(types.CommitteeIndex) == v2.Interface().(types.CommitteeIndex)
return v1.Interface().(primitives.CommitteeIndex) == v2.Interface().(primitives.CommitteeIndex)
}
return v1.Interface().(uint64) == v2.Interface().(uint64)
case reflect.Uint32: