Skip to content

Commit

Permalink
Revert "Update fastssz (#6760)"
Browse files Browse the repository at this point in the history
This reverts commit 78a25f9.
  • Loading branch information
terencechain authored Aug 24, 2020
1 parent 880298d commit d575658
Show file tree
Hide file tree
Showing 153 changed files with 2,538 additions and 4,292 deletions.
8 changes: 4 additions & 4 deletions .buildkite-bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#
# This config is loaded from https://github.com/bazelbuild/bazel-toolchains/blob/master/bazelrc/latest.bazelrc
build:remote-cache --remote_timeout=3600
#build:remote-cache --spawn_strategy=standalone
#build:remote-cache --strategy=Javac=standalone
#build:remote-cache --strategy=Closure=standalone
#build:remote-cache --strategy=Genrule=standalone
build:remote-cache --spawn_strategy=standalone
build:remote-cache --strategy=Javac=standalone
build:remote-cache --strategy=Closure=standalone
build:remote-cache --strategy=Genrule=standalone

# Prysm specific remote-cache properties.
#build:remote-cache --disk_cache=
Expand Down
11 changes: 4 additions & 7 deletions beacon-chain/blockchain/chain_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import (
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
Expand Down Expand Up @@ -44,7 +42,7 @@ func TestHeadRoot_Nil(t *testing.T) {
func TestFinalizedCheckpt_CanRetrieve(t *testing.T) {
db, sc := testDB.SetupDB(t)

cp := &ethpb.Checkpoint{Epoch: 5, Root: bytesutil.PadTo([]byte("foo"), 32)}
cp := &ethpb.Checkpoint{Epoch: 5, Root: []byte("foo")}
c := setupBeaconChain(t, db, sc)
c.finalizedCheckpt = cp

Expand All @@ -68,7 +66,7 @@ func TestFinalizedCheckpt_GenesisRootOk(t *testing.T) {
func TestCurrentJustifiedCheckpt_CanRetrieve(t *testing.T) {
db, sc := testDB.SetupDB(t)

cp := &ethpb.Checkpoint{Epoch: 6, Root: bytesutil.PadTo([]byte("foo"), 32)}
cp := &ethpb.Checkpoint{Epoch: 6, Root: []byte("foo")}
c := setupBeaconChain(t, db, sc)
c.justifiedCheckpt = cp

Expand All @@ -92,7 +90,7 @@ func TestJustifiedCheckpt_GenesisRootOk(t *testing.T) {
func TestPreviousJustifiedCheckpt_CanRetrieve(t *testing.T) {
db, sc := testDB.SetupDB(t)

cp := &ethpb.Checkpoint{Epoch: 7, Root: bytesutil.PadTo([]byte("foo"), 32)}
cp := &ethpb.Checkpoint{Epoch: 7, Root: []byte("foo")}
c := setupBeaconChain(t, db, sc)
c.prevJustifiedCheckpt = cp

Expand Down Expand Up @@ -130,8 +128,7 @@ func TestHeadRoot_CanRetrieve(t *testing.T) {
}

func TestHeadBlock_CanRetrieve(t *testing.T) {
b := testutil.NewBeaconBlock()
b.Block.Slot = 1
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 1}}
s, err := state.InitializeFromProto(&pb.BeaconState{})
require.NoError(t, err)
c := &Service{}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/checkpoint_info_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestHotStateCache_RoundTrip(t *testing.T) {
func TestHotStateCache_CanPrune(t *testing.T) {
c := newCheckPointInfoCache()
for i := 0; i < maxInfoSize+1; i++ {
cp := &ethpb.Checkpoint{Epoch: uint64(i), Root: make([]byte, 32)}
cp := &ethpb.Checkpoint{Epoch: uint64(i)}
require.NoError(t, c.put(cp, &pb.CheckPtInfo{}))
}
require.Equal(t, len(c.cache.Keys()), maxInfoSize)
Expand Down
15 changes: 8 additions & 7 deletions beacon-chain/blockchain/head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"testing"

ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
Expand Down Expand Up @@ -34,9 +35,8 @@ func TestSaveHead_Different(t *testing.T) {
oldRoot := [32]byte{'A'}
service.head = &head{slot: 0, root: oldRoot}

newHeadSignedBlock := testutil.NewBeaconBlock()
newHeadSignedBlock.Block.Slot = 1
newHeadBlock := newHeadSignedBlock.Block
newHeadBlock := &ethpb.BeaconBlock{Slot: 1}
newHeadSignedBlock := &ethpb.SignedBeaconBlock{Block: newHeadBlock}

require.NoError(t, service.beaconDB.SaveBlock(context.Background(), newHeadSignedBlock))
newRoot, err := stateutil.BlockRoot(newHeadBlock)
Expand Down Expand Up @@ -68,10 +68,11 @@ func TestSaveHead_Different_Reorg(t *testing.T) {
service.head = &head{slot: 0, root: oldRoot}

reorgChainParent := [32]byte{'B'}
newHeadSignedBlock := testutil.NewBeaconBlock()
newHeadSignedBlock.Block.Slot = 1
newHeadSignedBlock.Block.ParentRoot = reorgChainParent[:]
newHeadBlock := newHeadSignedBlock.Block
newHeadBlock := &ethpb.BeaconBlock{
Slot: 1,
ParentRoot: reorgChainParent[:],
}
newHeadSignedBlock := &ethpb.SignedBeaconBlock{Block: newHeadBlock}

require.NoError(t, service.beaconDB.SaveBlock(context.Background(), newHeadSignedBlock))
newRoot, err := stateutil.BlockRoot(newHeadBlock)
Expand Down
98 changes: 45 additions & 53 deletions beacon-chain/blockchain/process_attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
Expand All @@ -36,14 +37,12 @@ func TestStore_OnAttestation(t *testing.T) {
_, err = blockTree1(db, []byte{'g'})
require.NoError(t, err)

BlkWithOutState := testutil.NewBeaconBlock()
BlkWithOutState.Block.Slot = 0
BlkWithOutState := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 0}}
require.NoError(t, db.SaveBlock(ctx, BlkWithOutState))
BlkWithOutStateRoot, err := stateutil.BlockRoot(BlkWithOutState.Block)
require.NoError(t, err)

BlkWithStateBadAtt := testutil.NewBeaconBlock()
BlkWithStateBadAtt.Block.Slot = 1
BlkWithStateBadAtt := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 1}}
require.NoError(t, db.SaveBlock(ctx, BlkWithStateBadAtt))
BlkWithStateBadAttRoot, err := stateutil.BlockRoot(BlkWithStateBadAtt.Block)
require.NoError(t, err)
Expand All @@ -52,8 +51,7 @@ func TestStore_OnAttestation(t *testing.T) {
require.NoError(t, s.SetSlot(100*params.BeaconConfig().SlotsPerEpoch))
require.NoError(t, service.beaconDB.SaveState(ctx, s, BlkWithStateBadAttRoot))

BlkWithValidState := testutil.NewBeaconBlock()
BlkWithValidState.Block.Slot = 2
BlkWithValidState := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 2}}
require.NoError(t, db.SaveBlock(ctx, BlkWithValidState))

BlkWithValidStateRoot, err := stateutil.BlockRoot(BlkWithValidState.Block)
Expand All @@ -71,57 +69,57 @@ func TestStore_OnAttestation(t *testing.T) {
tests := []struct {
name string
a *ethpb.Attestation
s *pb.BeaconState
wantErr bool
wantErrString string
}{
{
name: "attestation's data slot not aligned with target vote",
a: &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: params.BeaconConfig().SlotsPerEpoch, Target: &ethpb.Checkpoint{Root: make([]byte, 32)}}},
a: &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: params.BeaconConfig().SlotsPerEpoch, Target: &ethpb.Checkpoint{}}},
s: &pb.BeaconState{},
wantErr: true,
wantErrString: "data slot is not in the same epoch as target 1 != 0",
},
{
name: "attestation's target root not in db",
a: &ethpb.Attestation{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte{'A'}, 32)}}},
a: &ethpb.Attestation{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{Root: []byte{'A'}}}},
s: &pb.BeaconState{},
wantErr: true,
wantErrString: "target root does not exist in db",
},
{
name: "no pre state for attestations's target block",
a: &ethpb.Attestation{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{Root: BlkWithOutStateRoot[:]}}},
s: &pb.BeaconState{},
wantErr: true,
wantErrString: "could not get pre state for slot 0",
},
{
name: "process attestation doesn't match current epoch",
a: &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 100 * params.BeaconConfig().SlotsPerEpoch, Target: &ethpb.Checkpoint{Epoch: 100,
Root: BlkWithStateBadAttRoot[:]}}},
s: &pb.BeaconState{Slot: 100 * params.BeaconConfig().SlotsPerEpoch},
wantErr: true,
wantErrString: "target epoch 100 does not match current epoch",
},
{
name: "process nil attestation",
name: "process nil field (a.Target) in attestation",
a: nil,
s: &pb.BeaconState{},
wantErr: true,
wantErrString: "nil attestation",
},
{
name: "process nil field (a.Data) in attestation",
a: &ethpb.Attestation{},
s: &pb.BeaconState{},
wantErr: true,
wantErrString: "nil attestation.Data field",
},
{
name: "process nil field (a.Target) in attestation",
a: &ethpb.Attestation{
Data: &ethpb.AttestationData{
BeaconBlockRoot: make([]byte, 32),
Target: nil,
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
},
AggregationBits: make([]byte, 1),
Signature: make([]byte, 96),
},
name: "process nil field (a.Target) in attestation",
a: &ethpb.Attestation{Data: &ethpb.AttestationData{}},
s: &pb.BeaconState{},
wantErr: true,
wantErrString: "nil attestation.Data.Target field",
},
Expand Down Expand Up @@ -152,16 +150,22 @@ func TestStore_SaveCheckpointState(t *testing.T) {
service, err := NewService(ctx, cfg)
require.NoError(t, err)

s := testutil.NewBeaconState()
err = s.SetFinalizedCheckpoint(&ethpb.Checkpoint{Root: bytesutil.PadTo([]byte{'A'}, 32)})
require.NoError(t, err)
val := &ethpb.Validator{
PublicKey: bytesutil.PadTo([]byte("foo"), 48),
WithdrawalCredentials: bytesutil.PadTo([]byte("bar"), 32),
}
err = s.SetValidators([]*ethpb.Validator{val})
require.NoError(t, err)
err = s.SetBalances([]uint64{0})
s, err := stateTrie.InitializeFromProto(&pb.BeaconState{
Fork: &pb.Fork{
Epoch: 0,
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
},
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
StateRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot),
BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot),
LatestBlockHeader: &ethpb.BeaconBlockHeader{},
JustificationBits: []byte{0},
Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector),
FinalizedCheckpoint: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte{'A'}, 32)},
Validators: []*ethpb.Validator{{PublicKey: bytesutil.PadTo([]byte("foo"), 48)}},
Balances: []uint64{0},
})
require.NoError(t, err)
r := [32]byte{'g'}
require.NoError(t, service.beaconDB.SaveState(ctx, s, r))
Expand Down Expand Up @@ -226,7 +230,7 @@ func TestStore_UpdateCheckpointState(t *testing.T) {
epoch := uint64(1)
baseState, _ := testutil.DeterministicGenesisState(t, 1)
require.NoError(t, baseState.SetSlot(epoch*params.BeaconConfig().SlotsPerEpoch))
checkpoint := &ethpb.Checkpoint{Epoch: epoch, Root: bytesutil.PadTo([]byte("hi"), 32)}
checkpoint := &ethpb.Checkpoint{Epoch: epoch}
require.NoError(t, service.beaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(checkpoint.Root)))
returned, err := service.getAttPreState(ctx, checkpoint)
require.NoError(t, err)
Expand All @@ -237,7 +241,7 @@ func TestStore_UpdateCheckpointState(t *testing.T) {
assert.NotNil(t, cached, "State should have been cached")

epoch = uint64(2)
newCheckpoint := &ethpb.Checkpoint{Epoch: epoch, Root: bytesutil.PadTo([]byte("bye"), 32)}
newCheckpoint := &ethpb.Checkpoint{Epoch: epoch}
require.NoError(t, service.beaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(newCheckpoint.Root)))
returned, err = service.getAttPreState(ctx, newCheckpoint)
require.NoError(t, err)
Expand All @@ -264,7 +268,7 @@ func TestAttEpoch_MatchPrevEpoch(t *testing.T) {
ctx,
0,
params.BeaconConfig().SlotsPerEpoch*params.BeaconConfig().SecondsPerSlot,
&ethpb.Checkpoint{Root: make([]byte, 32)}); err != nil {
&ethpb.Checkpoint{}); err != nil {
t.Error(err)
}
}
Expand Down Expand Up @@ -298,7 +302,7 @@ func TestAttEpoch_NotMatch(t *testing.T) {
ctx,
0,
2*params.BeaconConfig().SlotsPerEpoch*params.BeaconConfig().SecondsPerSlot,
&ethpb.Checkpoint{Root: make([]byte, 32)}); !strings.Contains(err.Error(),
&ethpb.Checkpoint{}); !strings.Contains(err.Error(),
"target epoch 0 does not match current epoch 2 or prev epoch 1") {
t.Error("Did not receive wanted error")
}
Expand All @@ -312,12 +316,8 @@ func TestVerifyBeaconBlock_NoBlock(t *testing.T) {
service, err := NewService(ctx, cfg)
require.NoError(t, err)

d := &ethpb.AttestationData{
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}
assert.ErrorContains(t, "beacon block 0x000000000000 does not exist", service.verifyBeaconBlock(ctx, d))
d := &ethpb.AttestationData{}
assert.ErrorContains(t, "beacon block does not exist", service.verifyBeaconBlock(ctx, d))
}

func TestVerifyBeaconBlock_futureBlock(t *testing.T) {
Expand All @@ -328,8 +328,7 @@ func TestVerifyBeaconBlock_futureBlock(t *testing.T) {
service, err := NewService(ctx, cfg)
require.NoError(t, err)

b := testutil.NewBeaconBlock()
b.Block.Slot = 2
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 2}}
require.NoError(t, service.beaconDB.SaveBlock(ctx, b))
r, err := stateutil.BlockRoot(b.Block)
require.NoError(t, err)
Expand All @@ -346,8 +345,7 @@ func TestVerifyBeaconBlock_OK(t *testing.T) {
service, err := NewService(ctx, cfg)
require.NoError(t, err)

b := testutil.NewBeaconBlock()
b.Block.Slot = 2
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 2}}
require.NoError(t, service.beaconDB.SaveBlock(ctx, b))
r, err := stateutil.BlockRoot(b.Block)
require.NoError(t, err)
Expand All @@ -364,14 +362,11 @@ func TestVerifyLMDFFGConsistent_NotOK(t *testing.T) {
service, err := NewService(ctx, cfg)
require.NoError(t, err)

b32 := testutil.NewBeaconBlock()
b32.Block.Slot = 32
b32 := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 32}}
require.NoError(t, service.beaconDB.SaveBlock(ctx, b32))
r32, err := stateutil.BlockRoot(b32.Block)
require.NoError(t, err)
b33 := testutil.NewBeaconBlock()
b33.Block.Slot = 33
b33.Block.ParentRoot = r32[:]
b33 := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 33, ParentRoot: r32[:]}}
require.NoError(t, service.beaconDB.SaveBlock(ctx, b33))
r33, err := stateutil.BlockRoot(b33.Block)
require.NoError(t, err)
Expand All @@ -388,14 +383,11 @@ func TestVerifyLMDFFGConsistent_OK(t *testing.T) {
service, err := NewService(ctx, cfg)
require.NoError(t, err)

b32 := testutil.NewBeaconBlock()
b32.Block.Slot = 32
b32 := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 32}}
require.NoError(t, service.beaconDB.SaveBlock(ctx, b32))
r32, err := stateutil.BlockRoot(b32.Block)
require.NoError(t, err)
b33 := testutil.NewBeaconBlock()
b33.Block.Slot = 33
b33.Block.ParentRoot = r32[:]
b33 := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 33, ParentRoot: r32[:]}}
require.NoError(t, service.beaconDB.SaveBlock(ctx, b33))
r33, err := stateutil.BlockRoot(b33.Block)
require.NoError(t, err)
Expand Down
Loading

0 comments on commit d575658

Please sign in to comment.