Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FastSSZ Marshal/Unmarshal for DB Encodings in v0.11.1 #5351

Merged
merged 39 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
de14890
try
rauljordan Apr 8, 2020
ffa3d66
use marshaler structure for db instead of proto
rauljordan Apr 8, 2020
87db578
Merge branch 'trytry' into eliminate-proto-db
rauljordan Apr 8, 2020
ee09fea
white list types
rauljordan Apr 8, 2020
52663ad
attempt
rauljordan Apr 8, 2020
839980f
revert
rauljordan Apr 8, 2020
2af0e09
testutil.NewBeaconState()
prestonvanloon Apr 8, 2020
4daf1d9
Fully populate fields for round trip ssz marshal
prestonvanloon Apr 8, 2020
61d4200
fix //beacon-chain/db/kv:go_default_test
prestonvanloon Apr 8, 2020
877240a
more passing tests
rauljordan Apr 9, 2020
1b8314d
another test target passed
rauljordan Apr 9, 2020
874179f
fixed stategen
rauljordan Apr 9, 2020
f4b3108
blockchain tests green
rauljordan Apr 9, 2020
8c61be5
passing sync
rauljordan Apr 9, 2020
a4f31ac
more targets fixed
rauljordan Apr 9, 2020
6e8b899
Merge refs/heads/v0.11 into eliminate-proto-db
prylabs-bulldozer[bot] Apr 9, 2020
3399e32
more test fixes in rpc/validator
rauljordan Apr 9, 2020
f5a728b
Merge branch 'eliminate-proto-db' of github.com:prysmaticlabs/prysm i…
rauljordan Apr 9, 2020
0b25048
most rpc val
rauljordan Apr 9, 2020
ff1a7a4
validators test fixes
rauljordan Apr 9, 2020
9f34cc9
Merge branch 'eliminate-proto-db' of github.com:prysmaticlabs/prysm i…
rauljordan Apr 9, 2020
06627aa
skip round robin old
rauljordan Apr 9, 2020
308ab1c
Merge branch 'eliminate-proto-db' of github.com:prysmaticlabs/prysm i…
rauljordan Apr 9, 2020
ec93a03
aggregate test
rauljordan Apr 9, 2020
6370c79
whitelist done
rauljordan Apr 9, 2020
25dc732
Update beacon-chain/rpc/validator/attester_test.go
rauljordan Apr 9, 2020
9d71295
edit baz
rauljordan Apr 9, 2020
ea03bfb
Merge refs/heads/v0.11 into eliminate-proto-db
prylabs-bulldozer[bot] Apr 9, 2020
3968dc0
Fixed tests
terencechain Apr 9, 2020
ec0b5ce
Merge refs/heads/v0.11 into eliminate-proto-db
prylabs-bulldozer[bot] Apr 9, 2020
456d4c7
Merge refs/heads/v0.11 into eliminate-proto-db
prylabs-bulldozer[bot] Apr 9, 2020
297d3ac
Merge refs/heads/v0.11 into eliminate-proto-db
prylabs-bulldozer[bot] Apr 10, 2020
d220334
Fixed getblock test
terencechain Apr 10, 2020
19746a2
Merge branch 'eliminate-proto-db' of github.com:prysmaticlabs/prysm i…
terencechain Apr 10, 2020
c7e0d41
Add back init
terencechain Apr 10, 2020
b0845b7
reduce test size
rauljordan Apr 10, 2020
7b946b9
Merge branch 'eliminate-proto-db' of github.com:prysmaticlabs/prysm i…
rauljordan Apr 10, 2020
e8cc378
fix broken build
rauljordan Apr 10, 2020
9068f99
tests pass
rauljordan Apr 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion beacon-chain/archiver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ go_test(
"//shared/testutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
],
Expand Down
35 changes: 10 additions & 25 deletions beacon-chain/archiver/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-bitfield"
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
Expand All @@ -34,12 +33,8 @@ func TestArchiverService_ReceivesBlockProcessedEvent(t *testing.T) {
hook := logTest.NewGlobal()
svc, beaconDB := setupService(t)
defer dbutil.TeardownDB(t, beaconDB)
st, err := stateTrie.InitializeFromProto(&pb.BeaconState{
Slot: 1,
})
if err != nil {
t.Fatal(err)
}
st := testutil.NewBeaconState()
st.SetSlot(1)
svc.headFetcher = &mock.ChainService{
State: st,
}
Expand All @@ -61,12 +56,8 @@ func TestArchiverService_OnlyArchiveAtEpochEnd(t *testing.T) {
svc, beaconDB := setupService(t)
defer dbutil.TeardownDB(t, beaconDB)
// The head state is NOT an epoch end.
st, err := stateTrie.InitializeFromProto(&pb.BeaconState{
Slot: params.BeaconConfig().SlotsPerEpoch - 2,
})
if err != nil {
t.Fatal(err)
}
st := testutil.NewBeaconState()
st.SetSlot(params.BeaconConfig().SlotsPerEpoch - 2)
svc.headFetcher = &mock.ChainService{
State: st,
}
Expand Down Expand Up @@ -433,18 +424,12 @@ func setupState(validatorCount uint64) (*stateTrie.BeaconState, error) {

// We initialize a head state that has attestations from participated
// validators in a simulated fashion.
return stateTrie.InitializeFromProto(&pb.BeaconState{
Slot: (2 * params.BeaconConfig().SlotsPerEpoch) - 1,
Validators: validators,
Balances: balances,
BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot),
Slashings: []uint64{0, 1e9, 1e9},
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
CurrentEpochAttestations: atts,
FinalizedCheckpoint: &ethpb.Checkpoint{},
JustificationBits: bitfield.Bitvector4{0x00},
CurrentJustifiedCheckpoint: &ethpb.Checkpoint{},
})
st := testutil.NewBeaconState()
st.SetSlot((2 * params.BeaconConfig().SlotsPerEpoch) - 1)
st.SetValidators(validators)
st.SetBalances(balances)
st.SetCurrentEpochAttestations(atts)
return st, nil
}

func setupService(t *testing.T) (*Service, db.Database) {
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/blockchain/head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
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/testutil"
)

func TestSaveHead_Same(t *testing.T) {
Expand Down Expand Up @@ -46,7 +45,8 @@ func TestSaveHead_Different(t *testing.T) {
newHeadSignedBlock := &ethpb.SignedBeaconBlock{Block: newHeadBlock}
service.beaconDB.SaveBlock(context.Background(), newHeadSignedBlock)
newRoot, _ := ssz.HashTreeRoot(newHeadBlock)
headState, _ := state.InitializeFromProto(&pb.BeaconState{Slot: 1})
headState := testutil.NewBeaconState()
headState.SetSlot(1)
service.beaconDB.SaveState(context.Background(), headState, newRoot)
if err := service.saveHead(context.Background(), newRoot); err != nil {
t.Fatal(err)
Expand Down
15 changes: 6 additions & 9 deletions beacon-chain/blockchain/process_attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ 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"
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
Expand Down Expand Up @@ -54,7 +53,7 @@ func TestStore_OnAttestation(t *testing.T) {
}
BlkWithStateBadAttRoot, _ := ssz.HashTreeRoot(BlkWithStateBadAtt.Block)

s, err := beaconstate.InitializeFromProto(&pb.BeaconState{})
s := testutil.NewBeaconState()
if err := s.SetSlot(100 * params.BeaconConfig().SlotsPerEpoch); err != nil {
t.Fatal(err)
}
Expand All @@ -67,13 +66,11 @@ func TestStore_OnAttestation(t *testing.T) {
t.Fatal(err)
}
BlkWithValidStateRoot, _ := ssz.HashTreeRoot(BlkWithValidState.Block)
s, _ = stateTrie.InitializeFromProto(&pb.BeaconState{
Fork: &pb.Fork{
Epoch: 0,
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
},
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
s = testutil.NewBeaconState()
s.SetFork(&pb.Fork{
Epoch: 0,
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
})
if err := service.beaconDB.SaveState(ctx, s, BlkWithValidStateRoot); err != nil {
t.Fatal(err)
Expand Down
38 changes: 16 additions & 22 deletions beacon-chain/blockchain/process_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ func TestStore_OnBlock(t *testing.T) {
if err != nil {
t.Error(err)
}
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
if err != nil {
t.Fatal(err)
}
st := testutil.NewBeaconState()
if err := service.beaconDB.SaveState(ctx, st.Copy(), validGenesisRoot); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -187,7 +184,8 @@ func TestRemoveStateSinceLastFinalized(t *testing.T) {
if err != nil {
t.Fatal(err)
}
s, _ := stateTrie.InitializeFromProto(&pb.BeaconState{Slot: uint64(i)})
s := testutil.NewBeaconState()
s.SetSlot(uint64(i))
if err := service.beaconDB.SaveState(ctx, s, r); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -397,16 +395,17 @@ func TestSaveInitState_CanSaveDelete(t *testing.T) {

for i := uint64(0); i < 64; i++ {
b := &ethpb.BeaconBlock{Slot: i}
s, _ := stateTrie.InitializeFromProto(&pb.BeaconState{Slot: i})
s := testutil.NewBeaconState()
s.SetSlot(i)
r, _ := ssz.HashTreeRoot(b)
service.initSyncState[r] = s
}

// Set finalized root as slot 32
finalizedRoot, _ := ssz.HashTreeRoot(&ethpb.BeaconBlock{Slot: 32})

s, _ := stateTrie.InitializeFromProto(&pb.BeaconState{FinalizedCheckpoint: &ethpb.Checkpoint{
Epoch: 1, Root: finalizedRoot[:]}})
s := testutil.NewBeaconState()
s.SetFinalizedCheckpoint(&ethpb.Checkpoint{
Epoch: 1, Root: finalizedRoot[:]})
if err := service.saveInitState(ctx, s); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -442,17 +441,15 @@ func TestUpdateJustified_CouldUpdateBest(t *testing.T) {
}
service.justifiedCheckpt = &ethpb.Checkpoint{Root: []byte{'A'}}
service.bestJustifiedCheckpt = &ethpb.Checkpoint{Root: []byte{'A'}}
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
if err != nil {
t.Fatal(err)
}
st := testutil.NewBeaconState()
service.initSyncState[r] = st.Copy()
if err := db.SaveState(ctx, st.Copy(), r); err != nil {
t.Fatal(err)
}

// Could update
s, _ := stateTrie.InitializeFromProto(&pb.BeaconState{CurrentJustifiedCheckpoint: &ethpb.Checkpoint{Epoch: 1, Root: r[:]}})
s := testutil.NewBeaconState()
s.SetCurrentJustifiedCheckpoint(&ethpb.Checkpoint{Epoch: 1, Root: r[:]})
if err := service.updateJustified(context.Background(), s); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -487,7 +484,7 @@ func TestFilterBlockRoots_CanFilter(t *testing.T) {
fRoot, _ := ssz.HashTreeRoot(fBlock)
hBlock := &ethpb.BeaconBlock{Slot: 1}
headRoot, _ := ssz.HashTreeRoot(hBlock)
st, _ := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
st := testutil.NewBeaconState()
if err := service.beaconDB.SaveBlock(ctx, &ethpb.SignedBeaconBlock{Block: fBlock}); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -530,7 +527,7 @@ func TestPersistCache_CanSave(t *testing.T) {
if err != nil {
t.Fatal(err)
}
st, _ := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
st := testutil.NewBeaconState()

for i := uint64(0); i < initialSyncCacheSize; i++ {
st.SetSlot(i)
Expand Down Expand Up @@ -582,7 +579,7 @@ func TestFillForkChoiceMissingBlocks_CanSave(t *testing.T) {
if err != nil {
t.Error(err)
}
st, _ := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
st := testutil.NewBeaconState()
if err := service.beaconDB.SaveState(ctx, st.Copy(), validGenesisRoot); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -636,7 +633,7 @@ func TestFillForkChoiceMissingBlocks_FilterFinalized(t *testing.T) {
if err != nil {
t.Error(err)
}
st, _ := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
st := testutil.NewBeaconState()
if err := service.beaconDB.SaveState(ctx, st.Copy(), validGenesisRoot); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -695,10 +692,7 @@ func blockTree1(db db.Database, genesisRoot []byte) ([][]byte, error) {
r7, _ := ssz.HashTreeRoot(b7)
b8 := &ethpb.BeaconBlock{Slot: 8, ParentRoot: r6[:]}
r8, _ := ssz.HashTreeRoot(b8)
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
if err != nil {
return nil, err
}
st := testutil.NewBeaconState()
for _, b := range []*ethpb.BeaconBlock{b0, b1, b3, b4, b5, b6, b7, b8} {
if err := db.SaveBlock(context.Background(), &ethpb.SignedBeaconBlock{Block: b}); err != nil {
return nil, err
Expand Down
23 changes: 8 additions & 15 deletions beacon-chain/blockchain/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,8 @@ func TestChainStartStop_Initialized(t *testing.T) {
if err := db.SaveBlock(ctx, genesisBlk); err != nil {
t.Fatal(err)
}
s, err := beaconstate.InitializeFromProto(&pb.BeaconState{Slot: 1})
if err != nil {
t.Fatal(err)
}
s := testutil.NewBeaconState()
s.SetSlot(1)
if err := db.SaveState(ctx, s, blkRoot); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -348,10 +346,9 @@ func TestChainService_InitializeChainInfo(t *testing.T) {

finalizedSlot := params.BeaconConfig().SlotsPerEpoch*2 + 1
headBlock := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: finalizedSlot, ParentRoot: genesisRoot[:]}}
headState, err := beaconstate.InitializeFromProto(&pb.BeaconState{Slot: finalizedSlot, GenesisValidatorsRoot: params.BeaconConfig().ZeroHash[:]})
if err != nil {
t.Fatal(err)
}
headState := testutil.NewBeaconState()
headState.SetSlot(finalizedSlot)
headState.SetGenesisValidatorRoot(params.BeaconConfig().ZeroHash[:])
headRoot, _ := ssz.HashTreeRoot(headBlock.Block)
if err := db.SaveState(ctx, headState, headRoot); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -414,8 +411,7 @@ func TestChainService_SaveHeadNoDB(t *testing.T) {
}
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 1}}
r, _ := ssz.HashTreeRoot(b)
state := &pb.BeaconState{}
newState, err := beaconstate.InitializeFromProto(state)
newState := testutil.NewBeaconState()
s.stateGen.SaveState(ctx, r, newState)
if err := s.saveHeadNoDB(ctx, b, r); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -447,11 +443,8 @@ func TestChainService_PruneOldStates(t *testing.T) {
if err != nil {
t.Fatal(err)
}
state := &pb.BeaconState{Slot: uint64(i)}
newState, err := beaconstate.InitializeFromProto(state)
if err != nil {
t.Fatal(err)
}
newState := testutil.NewBeaconState()
newState.SetSlot(uint64(i))
if err := s.beaconDB.SaveState(ctx, newState, r); err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/blocks/block_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func VerifyProposerSlashing(
return fmt.Errorf("validator with key %#x is not slashable", proposer.PublicKey)
}
// Using headerEpoch1 here because both of the headers should have the same epoch.
domain, err := helpers.Domain(beaconState.Fork(), helpers.StartSlot(slashing.Header_1.Header.Slot), params.BeaconConfig().DomainBeaconProposer, beaconState.GenesisValidatorRoot())
domain, err := helpers.Domain(beaconState.Fork(), helpers.SlotToEpoch(slashing.Header_1.Header.Slot), params.BeaconConfig().DomainBeaconProposer, beaconState.GenesisValidatorRoot())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion beacon-chain/db/kv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ go_library(
"//shared/traceutil:go_default_library",
"@com_github_dgraph_io_ristretto//:go_default_library",
"@com_github_ethereum_go_ethereum//common: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",
Expand Down Expand Up @@ -80,7 +81,6 @@ go_test(
deps = [
"//beacon-chain/cache:go_default_library",
"//beacon-chain/db/filters:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//proto/testing:go_default_library",
"//shared/bytesutil:go_default_library",
Expand All @@ -91,5 +91,6 @@ go_test(
"@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",
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
],
)
5 changes: 2 additions & 3 deletions beacon-chain/db/kv/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (

eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/testutil"
)

func TestStore_Backup(t *testing.T) {
Expand All @@ -26,7 +25,7 @@ func TestStore_Backup(t *testing.T) {
if err != nil {
t.Fatal(err)
}
st, err := state.InitializeFromProto(&pb.BeaconState{})
st := testutil.NewBeaconState()
if err := db.SaveState(ctx, st, root); err != nil {
t.Fatal(err)
}
Expand Down
16 changes: 6 additions & 10 deletions beacon-chain/db/kv/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import (
"github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
"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/testutil"
)

func TestStore_JustifiedCheckpoint_CanSaveRetrieve(t *testing.T) {
Expand All @@ -22,10 +21,9 @@ func TestStore_JustifiedCheckpoint_CanSaveRetrieve(t *testing.T) {
Epoch: 10,
Root: root[:],
}
st, err := state.InitializeFromProto(&pb.BeaconState{Slot: 1})
if err != nil {
t.Fatal(err)
}
st := testutil.NewBeaconState()
st.SetSlot(1)

if err := db.SaveState(ctx, st, root); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -74,10 +72,8 @@ func TestStore_FinalizedCheckpoint_CanSaveRetrieve(t *testing.T) {
if err := db.SaveBlock(ctx, blk); err != nil {
t.Fatal(err)
}
st, err := state.InitializeFromProto(&pb.BeaconState{Slot: 1})
if err != nil {
t.Fatal(err)
}
st := testutil.NewBeaconState()
st.SetSlot(1)
// a state is required to save checkpoint
if err := db.SaveState(ctx, st, root); err != nil {
t.Fatal(err)
Expand Down
Loading