mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
Use FastSSZ Everywhere Applicable (#6135)
* use fast ssz anywhere applicable * use fastssz clearly * Merge branch 'master' into use-fastssz * Apply suggestions from code review * imports * Update beacon-chain/p2p/fork.go * Merge branch 'master' into use-fastssz * update go-ssz * update go-ssz * Merge refs/heads/master into use-fastssz * Merge refs/heads/master into use-fastssz
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/shared/params/spectest"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
@@ -25,7 +24,7 @@ func runAttestationTest(t *testing.T, config string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
att := ðpb.Attestation{}
|
||||
if err := ssz.Unmarshal(attestationFile, att); err != nil {
|
||||
if err := att.UnmarshalSSZ(attestationFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/shared/params/spectest"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
@@ -25,7 +24,7 @@ func runAttesterSlashingTest(t *testing.T, config string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
attSlashing := ðpb.AttesterSlashing{}
|
||||
if err := ssz.Unmarshal(attSlashingFile, attSlashing); err != nil {
|
||||
if err := attSlashing.UnmarshalSSZ(attSlashingFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
@@ -31,7 +30,7 @@ func runBlockHeaderTest(t *testing.T, config string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block := ðpb.BeaconBlock{}
|
||||
if err := ssz.Unmarshal(blockFile, block); err != nil {
|
||||
if err := block.UnmarshalSSZ(blockFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
|
||||
@@ -40,7 +39,7 @@ func runBlockHeaderTest(t *testing.T, config string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
preBeaconStateBase := &pb.BeaconState{}
|
||||
if err := ssz.Unmarshal(preBeaconStateFile, preBeaconStateBase); err != nil {
|
||||
if err := preBeaconStateBase.UnmarshalSSZ(preBeaconStateFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
preBeaconState, err := stateTrie.InitializeFromProto(preBeaconStateBase)
|
||||
@@ -70,7 +69,7 @@ func runBlockHeaderTest(t *testing.T, config string) {
|
||||
}
|
||||
|
||||
postBeaconState := &pb.BeaconState{}
|
||||
if err := ssz.Unmarshal(postBeaconStateFile, postBeaconState); err != nil {
|
||||
if err := postBeaconState.UnmarshalSSZ(postBeaconStateFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
if !proto.Equal(beaconState.CloneInnerState(), postBeaconState) {
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
@@ -41,7 +40,7 @@ func runBlockProcessingTest(t *testing.T, config string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconStateBase := &pb.BeaconState{}
|
||||
if err := ssz.Unmarshal(preBeaconStateFile, beaconStateBase); err != nil {
|
||||
if err := beaconStateBase.UnmarshalSSZ(preBeaconStateFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
beaconState, err := stateTrie.InitializeFromProto(beaconStateBase)
|
||||
@@ -67,7 +66,7 @@ func runBlockProcessingTest(t *testing.T, config string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block := ðpb.SignedBeaconBlock{}
|
||||
if err := ssz.Unmarshal(blockFile, block); err != nil {
|
||||
if err := block.UnmarshalSSZ(blockFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
beaconState, transitionError = state.ExecuteStateTransition(context.Background(), beaconState, block)
|
||||
@@ -96,7 +95,7 @@ func runBlockProcessingTest(t *testing.T, config string) {
|
||||
}
|
||||
|
||||
postBeaconState := &pb.BeaconState{}
|
||||
if err := ssz.Unmarshal(postBeaconStateFile, postBeaconState); err != nil {
|
||||
if err := postBeaconState.UnmarshalSSZ(postBeaconStateFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/shared/params/spectest"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
@@ -25,7 +24,7 @@ func runDepositTest(t *testing.T, config string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
deposit := ðpb.Deposit{}
|
||||
if err := ssz.Unmarshal(depositFile, deposit); err != nil {
|
||||
if err := deposit.UnmarshalSSZ(depositFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/shared/params/spectest"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
@@ -25,7 +24,7 @@ func runProposerSlashingTest(t *testing.T, config string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
proposerSlashing := ðpb.ProposerSlashing{}
|
||||
if err := ssz.Unmarshal(proposerSlashingFile, proposerSlashing); err != nil {
|
||||
if err := proposerSlashing.UnmarshalSSZ(proposerSlashingFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/shared/params/spectest"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
@@ -25,7 +24,7 @@ func runVoluntaryExitTest(t *testing.T, config string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
voluntaryExit := ðpb.SignedVoluntaryExit{}
|
||||
if err := ssz.Unmarshal(exitFile, voluntaryExit); err != nil {
|
||||
if err := voluntaryExit.UnmarshalSSZ(exitFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ go_library(
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//shared/featureconfig:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"path"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
)
|
||||
|
||||
@@ -23,7 +22,7 @@ func WriteBlockToDisk(block *ethpb.SignedBeaconBlock, failed bool) {
|
||||
}
|
||||
fp := path.Join(os.TempDir(), filename)
|
||||
log.Warnf("Writing block to disk at %s", fp)
|
||||
enc, err := ssz.Marshal(block)
|
||||
enc, err := block.MarshalSSZ()
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Failed to ssz encode block")
|
||||
return
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
)
|
||||
@@ -18,7 +17,7 @@ func WriteStateToDisk(state *stateTrie.BeaconState) {
|
||||
}
|
||||
fp := path.Join(os.TempDir(), fmt.Sprintf("beacon_state_%d.ssz", state.Slot()))
|
||||
log.Warnf("Writing state to disk at %s", fp)
|
||||
enc, err := ssz.Marshal(state.InnerStateUnsafe())
|
||||
enc, err := state.InnerStateUnsafe().MarshalSSZ()
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Failed to ssz encode state")
|
||||
return
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
@@ -33,7 +32,7 @@ func runSlotProcessingTests(t *testing.T, config string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
base := &pb.BeaconState{}
|
||||
if err := ssz.Unmarshal(preBeaconStateFile, base); err != nil {
|
||||
if err := base.UnmarshalSSZ(preBeaconStateFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
beaconState, err := beaconstate.InitializeFromProto(base)
|
||||
@@ -56,7 +55,7 @@ func runSlotProcessingTests(t *testing.T, config string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
postBeaconState := &pb.BeaconState{}
|
||||
if err := ssz.Unmarshal(postBeaconStateFile, postBeaconState); err != nil {
|
||||
if err := postBeaconState.UnmarshalSSZ(postBeaconStateFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
postState, err := state.ProcessSlots(context.Background(), beaconState, beaconState.Slot()+uint64(slotsCount))
|
||||
|
||||
@@ -20,7 +20,6 @@ go_library(
|
||||
"//shared/interop:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
@@ -72,7 +71,7 @@ func NewColdStartService(ctx context.Context, cfg *Config) *Service {
|
||||
log.Fatalf("Could not read pre-loaded state: %v", err)
|
||||
}
|
||||
genesisState := &pb.BeaconState{}
|
||||
if err := ssz.Unmarshal(data, genesisState); err != nil {
|
||||
if err := genesisState.UnmarshalSSZ(data); err != nil {
|
||||
log.Fatalf("Could not unmarshal pre-loaded state: %v", err)
|
||||
}
|
||||
genesisTrie, err := stateTrie.InitializeFromProto(genesisState)
|
||||
|
||||
@@ -82,7 +82,6 @@ go_library(
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@io_opencensus_go//trace:go_default_library",
|
||||
],
|
||||
@@ -134,7 +133,6 @@ go_test(
|
||||
"@com_github_multiformats_go_multiaddr//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
||||
],
|
||||
|
||||
@@ -15,6 +15,7 @@ go_library(
|
||||
],
|
||||
deps = [
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_golang_snappy//:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
fastssz "github.com/ferranbt/fastssz"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/golang/snappy"
|
||||
"github.com/pkg/errors"
|
||||
@@ -36,6 +37,9 @@ type SszNetworkEncoder struct {
|
||||
}
|
||||
|
||||
func (e SszNetworkEncoder) doEncode(msg interface{}) ([]byte, error) {
|
||||
if v, ok := msg.(fastssz.Marshaler); ok {
|
||||
return v.MarshalSSZ()
|
||||
}
|
||||
return ssz.Marshal(msg)
|
||||
}
|
||||
|
||||
@@ -118,6 +122,9 @@ func (e SszNetworkEncoder) EncodeWithMaxLength(w io.Writer, msg interface{}, max
|
||||
}
|
||||
|
||||
func (e SszNetworkEncoder) doDecode(b []byte, to interface{}) error {
|
||||
if v, ok := to.(fastssz.Unmarshaler); ok {
|
||||
return v.UnmarshalSSZ(b)
|
||||
}
|
||||
return ssz.Unmarshal(b, to)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"github.com/ethereum/go-ethereum/p2p/enr"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/p2putils"
|
||||
@@ -110,7 +109,7 @@ func addForkEntry(
|
||||
NextForkVersion: nextForkVersion,
|
||||
NextForkEpoch: nextForkEpoch,
|
||||
}
|
||||
enc, err := ssz.Marshal(enrForkID)
|
||||
enc, err := enrForkID.MarshalSSZ()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -129,7 +128,7 @@ func retrieveForkEntry(record *enr.Record) (*pb.ENRForkID, error) {
|
||||
return nil, err
|
||||
}
|
||||
forkEntry := &pb.ENRForkID{}
|
||||
if err := ssz.Unmarshal(sszEncodedForkEntry, forkEntry); err != nil {
|
||||
if err := forkEntry.UnmarshalSSZ(sszEncodedForkEntry); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return forkEntry, nil
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"github.com/ethereum/go-ethereum/p2p/enr"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/p2putils"
|
||||
@@ -215,7 +214,7 @@ func TestDiscv5_AddRetrieveForkEntryENR(t *testing.T) {
|
||||
NextForkVersion: nextForkVersion,
|
||||
NextForkEpoch: nextForkEpoch,
|
||||
}
|
||||
enc, err := ssz.Marshal(enrForkID)
|
||||
enc, err := enrForkID.MarshalSSZ()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ go_library(
|
||||
"@com_github_ethereum_go_ethereum//log:go_default_library",
|
||||
"@com_github_gogo_protobuf//types:go_default_library",
|
||||
"@com_github_ipfs_go_log_v2//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@org_golang_google_grpc//codes:go_default_library",
|
||||
"@org_golang_google_grpc//status:go_default_library",
|
||||
@@ -48,6 +47,5 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"@com_github_gogo_protobuf//types:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -3,7 +3,6 @@ package debug
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -23,7 +22,7 @@ func (ds *Server) GetBlock(
|
||||
if signedBlock == nil {
|
||||
return &pbrpc.SSZResponse{Encoded: make([]byte, 0)}, nil
|
||||
}
|
||||
encoded, err := ssz.Marshal(signedBlock)
|
||||
encoded, err := signedBlock.MarshalSSZ()
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not marshal block: %v", err)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
||||
@@ -34,7 +33,7 @@ func TestServer_GetBlock(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wanted, err := ssz.Marshal(b)
|
||||
wanted, err := b.MarshalSSZ()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package debug
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
@@ -38,7 +37,7 @@ func (ds *Server) GetBeaconState(
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not compute state by slot: %v", err)
|
||||
}
|
||||
encoded, err := ssz.Marshal(st.CloneInnerState())
|
||||
encoded, err := st.CloneInnerState().MarshalSSZ()
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not ssz encode beacon state: %v", err)
|
||||
}
|
||||
@@ -50,7 +49,7 @@ func (ds *Server) GetBeaconState(
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not compute state by block root: %v", err)
|
||||
}
|
||||
encoded, err := ssz.Marshal(st.CloneInnerState())
|
||||
encoded, err := st.CloneInnerState().MarshalSSZ()
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not ssz encode beacon state: %v", err)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
@@ -62,7 +61,7 @@ func TestServer_GetBeaconState(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wanted, err := ssz.Marshal(st.CloneInnerState())
|
||||
wanted, err := st.CloneInnerState().MarshalSSZ()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ go_library(
|
||||
"//shared/slotutil:go_default_library",
|
||||
"//shared/traceutil:go_default_library",
|
||||
"//shared/trieutil:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_gogo_protobuf//types:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
@@ -103,6 +104,7 @@ go_test(
|
||||
"//shared/roughtime:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/trieutil:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_gogo_protobuf//types:go_default_library",
|
||||
"@com_github_golang_mock//gomock:go_default_library",
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
fastssz "github.com/ferranbt/fastssz"
|
||||
"github.com/pkg/errors"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
@@ -201,10 +202,8 @@ func (vs *Server) mockETH1DataVote(ctx context.Context, slot uint64) (*ethpb.Eth
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
enc, err := ssz.Marshal(helpers.SlotToEpoch(slot) + slotInVotingPeriod)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var enc []byte
|
||||
enc = fastssz.MarshalUint64(enc, helpers.SlotToEpoch(slot)+slotInVotingPeriod)
|
||||
depRoot := hashutil.Hash(enc)
|
||||
blockHash := hashutil.Hash(depRoot[:])
|
||||
return ðpb.Eth1Data{
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
fastssz "github.com/ferranbt/fastssz"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
@@ -1263,10 +1264,8 @@ func TestEth1Data_MockEnabled(t *testing.T) {
|
||||
period := params.BeaconConfig().EpochsPerEth1VotingPeriod * params.BeaconConfig().SlotsPerEpoch
|
||||
wantedSlot := 100 % period
|
||||
currentEpoch := helpers.SlotToEpoch(100)
|
||||
enc, err := ssz.Marshal(currentEpoch + wantedSlot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var enc []byte
|
||||
enc = fastssz.MarshalUint64(enc, currentEpoch+wantedSlot)
|
||||
depRoot := hashutil.Hash(enc)
|
||||
blockHash := hashutil.Hash(depRoot[:])
|
||||
want := ðpb.Eth1Data{
|
||||
|
||||
8
deps.bzl
8
deps.bzl
@@ -2896,12 +2896,8 @@ def prysm_deps():
|
||||
go_repository(
|
||||
name = "com_github_prysmaticlabs_go_ssz",
|
||||
importpath = "github.com/prysmaticlabs/go-ssz",
|
||||
patch_args = ["-p1"],
|
||||
patches = [
|
||||
"@prysm//third_party:com_github_prysmaticlabs_go_ssz.patch",
|
||||
],
|
||||
sum = "h1:Th5ufPIaL5s/7i3gXHTgiTwfsUhWDP/PwFRiI6qV6v0=",
|
||||
version = "v0.0.0-20200101200214-e24db4d9e963",
|
||||
sum = "h1:V4o7uJqGXAuz6ZpwxhT4cnVjRb/XxpBmTKp/lVVr05k=",
|
||||
version = "v0.0.0-20200605034351-b6a925e519d0",
|
||||
)
|
||||
go_repository(
|
||||
name = "io_k8s_client_go",
|
||||
|
||||
@@ -3,7 +3,6 @@ package fuzz
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
prylabs_testing "github.com/prysmaticlabs/prysm/fuzz/testing"
|
||||
@@ -14,7 +13,7 @@ import (
|
||||
func BeaconFuzzAttestation(b []byte) ([]byte, bool) {
|
||||
params.UseMainnetConfig()
|
||||
input := &InputAttestationWrapper{}
|
||||
if err := ssz.Unmarshal(b, input); err != nil {
|
||||
if err := input.UnmarshalSSZ(b); err != nil {
|
||||
return fail(err)
|
||||
}
|
||||
s, err := prylabs_testing.GetBeaconFuzzState(input.StateID)
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
prylabs_testing "github.com/prysmaticlabs/prysm/fuzz/testing"
|
||||
@@ -15,7 +14,7 @@ import (
|
||||
func BeaconFuzzBlock(b []byte) ([]byte, bool) {
|
||||
params.UseMainnetConfig()
|
||||
input := &InputBlockHeader{}
|
||||
if err := ssz.Unmarshal(b, input); err != nil {
|
||||
if err := input.UnmarshalSSZ(b); err != nil {
|
||||
return fail(err)
|
||||
}
|
||||
s, err := prylabs_testing.GetBeaconFuzzState(input.StateID)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package fuzz
|
||||
|
||||
import (
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
prylabs_testing "github.com/prysmaticlabs/prysm/fuzz/testing"
|
||||
@@ -12,7 +11,7 @@ import (
|
||||
func BeaconFuzzBlockHeader(b []byte) ([]byte, bool) {
|
||||
params.UseMainnetConfig()
|
||||
input := &InputBlockHeader{}
|
||||
if err := ssz.Unmarshal(b, input); err != nil {
|
||||
if err := input.UnmarshalSSZ(b); err != nil {
|
||||
return fail(err)
|
||||
}
|
||||
s, err := prylabs_testing.GetBeaconFuzzState(input.StateID)
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
)
|
||||
@@ -33,7 +32,7 @@ func success(post *stateTrie.BeaconState) ([]byte, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
result, err := ssz.Marshal(post.InnerStateUnsafe())
|
||||
result, err := post.InnerStateUnsafe().MarshalSSZ()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package fuzz
|
||||
|
||||
import (
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
prylabs_testing "github.com/prysmaticlabs/prysm/fuzz/testing"
|
||||
@@ -12,7 +11,7 @@ import (
|
||||
func BeaconFuzzDeposit(b []byte) ([]byte, bool) {
|
||||
params.UseMainnetConfig()
|
||||
input := &InputDepositWrapper{}
|
||||
if err := ssz.Unmarshal(b, input); err != nil {
|
||||
if err := input.UnmarshalSSZ(b); err != nil {
|
||||
return fail(err)
|
||||
}
|
||||
s, err := prylabs_testing.GetBeaconFuzzState(input.StateID)
|
||||
|
||||
2
go.mod
2
go.mod
@@ -85,7 +85,7 @@ require (
|
||||
github.com/protolambda/zssz v0.1.4
|
||||
github.com/prysmaticlabs/ethereumapis v0.0.0-20200604035415-4196125e9fd6
|
||||
github.com/prysmaticlabs/go-bitfield v0.0.0-20200322041314-62c2aee71669
|
||||
github.com/prysmaticlabs/go-ssz v0.0.0-20200101200214-e24db4d9e963
|
||||
github.com/prysmaticlabs/go-ssz v0.0.0-20200605034351-b6a925e519d0
|
||||
github.com/prysmaticlabs/prombbolt v0.0.0-20200324184628-09789ef63796
|
||||
github.com/rs/cors v1.7.0
|
||||
github.com/sirupsen/logrus v1.6.0
|
||||
|
||||
2
go.sum
2
go.sum
@@ -949,6 +949,8 @@ github.com/prysmaticlabs/go-bitfield v0.0.0-20200322041314-62c2aee71669 h1:cX6YR
|
||||
github.com/prysmaticlabs/go-bitfield v0.0.0-20200322041314-62c2aee71669/go.mod h1:hCwmef+4qXWjv0jLDbQdWnL0Ol7cS7/lCSS26WR+u6s=
|
||||
github.com/prysmaticlabs/go-ssz v0.0.0-20200101200214-e24db4d9e963 h1:Th5ufPIaL5s/7i3gXHTgiTwfsUhWDP/PwFRiI6qV6v0=
|
||||
github.com/prysmaticlabs/go-ssz v0.0.0-20200101200214-e24db4d9e963/go.mod h1:VecIJZrewdAuhVckySLFt2wAAHRME934bSDurP8ftkc=
|
||||
github.com/prysmaticlabs/go-ssz v0.0.0-20200605034351-b6a925e519d0 h1:V4o7uJqGXAuz6ZpwxhT4cnVjRb/XxpBmTKp/lVVr05k=
|
||||
github.com/prysmaticlabs/go-ssz v0.0.0-20200605034351-b6a925e519d0/go.mod h1:VecIJZrewdAuhVckySLFt2wAAHRME934bSDurP8ftkc=
|
||||
github.com/prysmaticlabs/prombbolt v0.0.0-20200324184628-09789ef63796 h1:bVD46NhbqEE6bsIqj42TCS3ELUdumti3WfAw9DXNtkg=
|
||||
github.com/prysmaticlabs/prombbolt v0.0.0-20200324184628-09789ef63796/go.mod h1:5JkKm84FcLZQPNuHwjX8Mtd5emni/PH5CylWCNqnKos=
|
||||
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||
|
||||
@@ -88,21 +88,6 @@ func TestBlockHeaderSigningRoot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// See: https://github.com/prysmaticlabs/go-ssz/pull/69
|
||||
func TestBeaconBlock(t *testing.T) {
|
||||
block := ðpb.BeaconBlock{
|
||||
Slot: 55,
|
||||
}
|
||||
enc, err := ssz.Marshal(block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dec := ðpb.BeaconBlock{}
|
||||
if err := ssz.Unmarshal(enc, dec); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func hexDecodeOrDie(t *testing.T, h string) []byte {
|
||||
b, err := hex.DecodeString(h)
|
||||
if err != nil {
|
||||
|
||||
@@ -12,7 +12,6 @@ go_library(
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
@@ -51,7 +50,7 @@ func PreGenState1Epoch() (*beaconstate.BeaconState, error) {
|
||||
return nil, err
|
||||
}
|
||||
beaconState := &pb.BeaconState{}
|
||||
if err := ssz.Unmarshal(beaconBytes, beaconState); err != nil {
|
||||
if err := beaconState.UnmarshalSSZ(beaconBytes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return beaconstate.InitializeFromProto(beaconState)
|
||||
@@ -68,7 +67,7 @@ func PreGenState2FullEpochs() (*beaconstate.BeaconState, error) {
|
||||
return nil, err
|
||||
}
|
||||
beaconState := &pb.BeaconState{}
|
||||
if err := ssz.Unmarshal(beaconBytes, beaconState); err != nil {
|
||||
if err := beaconState.UnmarshalSSZ(beaconBytes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return beaconstate.InitializeFromProto(beaconState)
|
||||
@@ -85,7 +84,7 @@ func PreGenFullBlock() (*ethpb.SignedBeaconBlock, error) {
|
||||
return nil, err
|
||||
}
|
||||
beaconBlock := ðpb.SignedBeaconBlock{}
|
||||
if err := ssz.Unmarshal(blockBytes, beaconBlock); err != nil {
|
||||
if err := beaconBlock.UnmarshalSSZ(blockBytes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return beaconBlock, nil
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
ssz "github.com/ferranbt/fastssz"
|
||||
fastssz "github.com/ferranbt/fastssz"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/minio/highwayhash"
|
||||
"github.com/minio/sha256-simd"
|
||||
@@ -116,7 +116,7 @@ func HashProto(msg proto.Message) (result [32]byte, err error) {
|
||||
return [32]byte{}, ErrNilProto
|
||||
}
|
||||
var data []byte
|
||||
if m, ok := msg.(ssz.Marshaler); ok {
|
||||
if m, ok := msg.(fastssz.Marshaler); ok {
|
||||
data, err = m.MarshalSSZ()
|
||||
} else {
|
||||
data, err = proto.Marshal(msg)
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/gogo/protobuf/proto"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
@@ -95,7 +94,7 @@ func RunBlockOperationTest(
|
||||
t.Fatal(err)
|
||||
}
|
||||
preStateBase := &pb.BeaconState{}
|
||||
if err := ssz.Unmarshal(preBeaconStateFile, preStateBase); err != nil {
|
||||
if err := preStateBase.UnmarshalSSZ(preBeaconStateFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
preState, err := beaconstate.InitializeFromProto(preStateBase)
|
||||
@@ -125,7 +124,7 @@ func RunBlockOperationTest(
|
||||
}
|
||||
|
||||
postBeaconState := &pb.BeaconState{}
|
||||
if err := ssz.Unmarshal(postBeaconStateFile, postBeaconState); err != nil {
|
||||
if err := postBeaconState.UnmarshalSSZ(postBeaconStateFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
|
||||
@@ -157,7 +156,7 @@ func RunEpochOperationTest(
|
||||
t.Fatal(err)
|
||||
}
|
||||
preBeaconStateBase := &pb.BeaconState{}
|
||||
if err := ssz.Unmarshal(preBeaconStateFile, preBeaconStateBase); err != nil {
|
||||
if err := preBeaconStateBase.UnmarshalSSZ(preBeaconStateFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
preBeaconState, err := beaconstate.InitializeFromProto(preBeaconStateBase)
|
||||
@@ -186,7 +185,7 @@ func RunEpochOperationTest(
|
||||
}
|
||||
|
||||
postBeaconState := &pb.BeaconState{}
|
||||
if err := ssz.Unmarshal(postBeaconStateFile, postBeaconState); err != nil {
|
||||
if err := postBeaconState.UnmarshalSSZ(postBeaconStateFile); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,5 @@ go_test(
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
@@ -47,12 +46,12 @@ func TestMarshalDepositWithProof(t *testing.T) {
|
||||
Signature: someSig[:],
|
||||
},
|
||||
}
|
||||
enc, err := ssz.Marshal(dep)
|
||||
enc, err := dep.MarshalSSZ()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dec := ðpb.Deposit{}
|
||||
if err := ssz.Unmarshal(enc, &dec); err != nil {
|
||||
if err := dec.UnmarshalSSZ(enc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(dec, dep) {
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
diff --git a/BUILD.bazel b/BUILD.bazel
|
||||
index e502174..1c29b7a 100644
|
||||
--- a/BUILD.bazel
|
||||
+++ b/BUILD.bazel
|
||||
@@ -61,6 +61,7 @@ go_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//types:go_default_library",
|
||||
+ "@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
],
|
||||
diff --git a/ssz.go b/ssz.go
|
||||
index 61fb9ef..24755fc 100644
|
||||
--- a/ssz.go
|
||||
+++ b/ssz.go
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
+ fssz "github.com/ferranbt/fastssz"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/go-ssz/types"
|
||||
@@ -48,6 +49,11 @@ func Marshal(val interface{}) ([]byte, error) {
|
||||
if val == nil {
|
||||
return nil, errors.New("untyped-value nil cannot be marshaled")
|
||||
}
|
||||
+
|
||||
+ if v, ok := val.(fssz.Marshaler); ok {
|
||||
+ return v.MarshalSSZ()
|
||||
+ }
|
||||
+
|
||||
rval := reflect.ValueOf(val)
|
||||
|
||||
// We pre-allocate a buffer-size depending on the value's calculated total byte size.
|
||||
@@ -87,6 +93,9 @@ func Unmarshal(input []byte, val interface{}) error {
|
||||
if val == nil {
|
||||
return errors.New("cannot unmarshal into untyped, nil value")
|
||||
}
|
||||
+ if v, ok := val.(fssz.Unmarshaler); ok {
|
||||
+ return v.UnmarshalSSZ(input)
|
||||
+ }
|
||||
if len(input) == 0 {
|
||||
return errors.New("no data to unmarshal from, input is an empty byte slice []byte{}")
|
||||
}
|
||||
@@ -18,7 +18,6 @@ go_library(
|
||||
"//shared/testutil:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
@@ -74,7 +73,7 @@ func generateGenesisBeaconState() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
beaconBytes, err := ssz.Marshal(genesisState)
|
||||
beaconBytes, err := genesisState.MarshalSSZ()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -156,7 +155,7 @@ func generateMarshalledFullStateAndBlock() error {
|
||||
return err
|
||||
}
|
||||
|
||||
beaconBytes, err := ssz.Marshal(beaconState.InnerStateUnsafe())
|
||||
beaconBytes, err := beaconState.InnerStateUnsafe().MarshalSSZ()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -170,7 +169,7 @@ func generateMarshalledFullStateAndBlock() error {
|
||||
return err
|
||||
}
|
||||
|
||||
blockBytes, err := ssz.Marshal(block)
|
||||
blockBytes, err := block.MarshalSSZ()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -207,7 +206,7 @@ func generate2FullEpochState() error {
|
||||
}
|
||||
}
|
||||
|
||||
beaconBytes, err := ssz.Marshal(beaconState.InnerStateUnsafe())
|
||||
beaconBytes, err := beaconState.InnerStateUnsafe().MarshalSSZ()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -223,7 +222,7 @@ func genesisBeaconState() (*stateTrie.BeaconState, error) {
|
||||
return nil, errors.Wrap(err, "cannot read genesis state file")
|
||||
}
|
||||
genesisState := &pb.BeaconState{}
|
||||
if err := ssz.Unmarshal(beaconBytes, genesisState); err != nil {
|
||||
if err := genesisState.UnmarshalSSZ(beaconBytes); err != nil {
|
||||
return nil, errors.Wrap(err, "cannot unmarshal genesis state file")
|
||||
}
|
||||
return stateTrie.InitializeFromProtoUnsafe(genesisState)
|
||||
|
||||
@@ -34,7 +34,6 @@ go_library(
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@org_uber_go_automaxprocs//:go_default_library",
|
||||
],
|
||||
|
||||
@@ -39,7 +39,6 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/iputils"
|
||||
@@ -243,7 +242,7 @@ func createLocalNode(privKey *ecdsa.PrivateKey, ipAddr net.IP, port int) (*enode
|
||||
NextForkVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
NextForkEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
}
|
||||
forkEntry, err := ssz.Marshal(forkID)
|
||||
forkEntry, err := forkID.MarshalSSZ()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Could not marshal fork id")
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ go_library(
|
||||
"//shared/interop:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_ghodss_yaml//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/shared/interop"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
)
|
||||
@@ -41,7 +40,7 @@ func main() {
|
||||
log.Fatalf("Could not generate genesis beacon state: %v", err)
|
||||
}
|
||||
if *sszOutputFile != "" {
|
||||
encodedState, err := ssz.Marshal(genesisState)
|
||||
encodedState, err := genesisState.MarshalSSZ()
|
||||
if err != nil {
|
||||
log.Fatalf("Could not ssz marshal the genesis beacon state: %v", err)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ go_library(
|
||||
deps = [
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/db:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
)
|
||||
@@ -38,7 +37,7 @@ func main() {
|
||||
if gs == nil {
|
||||
panic("nil genesis state")
|
||||
}
|
||||
b, err := ssz.Marshal(gs)
|
||||
b, err := gs.InnerStateUnsafe().MarshalSSZ()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func main() {
|
||||
beaconState.GenesisTime = *genesisTime
|
||||
}
|
||||
|
||||
encodedState, err := ssz.Marshal(beaconState)
|
||||
encodedState, err := beaconState.MarshalSSZ()
|
||||
if err != nil {
|
||||
log.Fatalf("Could not ssz marshal the beacon state: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user