mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 04:54:05 -05:00
Revert "Update fastssz" (#7100)
* Revert "Update fastssz (#6760)"
This reverts commit 78a25f99c3.
* Merge refs/heads/master into revert-6760-update-fssz
This commit is contained in:
@@ -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=
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
@@ -44,7 +42,7 @@ func TestHeadRoot_Nil(t *testing.T) {
|
||||
func TestFinalizedCheckpt_CanRetrieve(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
|
||||
cp := ðpb.Checkpoint{Epoch: 5, Root: bytesutil.PadTo([]byte("foo"), 32)}
|
||||
cp := ðpb.Checkpoint{Epoch: 5, Root: []byte("foo")}
|
||||
c := setupBeaconChain(t, db, sc)
|
||||
c.finalizedCheckpt = cp
|
||||
|
||||
@@ -68,7 +66,7 @@ func TestFinalizedCheckpt_GenesisRootOk(t *testing.T) {
|
||||
func TestCurrentJustifiedCheckpt_CanRetrieve(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
|
||||
cp := ðpb.Checkpoint{Epoch: 6, Root: bytesutil.PadTo([]byte("foo"), 32)}
|
||||
cp := ðpb.Checkpoint{Epoch: 6, Root: []byte("foo")}
|
||||
c := setupBeaconChain(t, db, sc)
|
||||
c.justifiedCheckpt = cp
|
||||
|
||||
@@ -92,7 +90,7 @@ func TestJustifiedCheckpt_GenesisRootOk(t *testing.T) {
|
||||
func TestPreviousJustifiedCheckpt_CanRetrieve(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
|
||||
cp := ðpb.Checkpoint{Epoch: 7, Root: bytesutil.PadTo([]byte("foo"), 32)}
|
||||
cp := ðpb.Checkpoint{Epoch: 7, Root: []byte("foo")}
|
||||
c := setupBeaconChain(t, db, sc)
|
||||
c.prevJustifiedCheckpt = cp
|
||||
|
||||
@@ -130,8 +128,7 @@ func TestHeadRoot_CanRetrieve(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHeadBlock_CanRetrieve(t *testing.T) {
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 1
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
s, err := state.InitializeFromProto(&pb.BeaconState{})
|
||||
require.NoError(t, err)
|
||||
c := &Service{}
|
||||
|
||||
@@ -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 := ðpb.Checkpoint{Epoch: uint64(i), Root: make([]byte, 32)}
|
||||
cp := ðpb.Checkpoint{Epoch: uint64(i)}
|
||||
require.NoError(t, c.put(cp, &pb.CheckPtInfo{}))
|
||||
}
|
||||
require.Equal(t, len(c.cache.Keys()), maxInfoSize)
|
||||
|
||||
@@ -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"
|
||||
@@ -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 := ðpb.BeaconBlock{Slot: 1}
|
||||
newHeadSignedBlock := ðpb.SignedBeaconBlock{Block: newHeadBlock}
|
||||
|
||||
require.NoError(t, service.beaconDB.SaveBlock(context.Background(), newHeadSignedBlock))
|
||||
newRoot, err := stateutil.BlockRoot(newHeadBlock)
|
||||
@@ -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 := ðpb.BeaconBlock{
|
||||
Slot: 1,
|
||||
ParentRoot: reorgChainParent[:],
|
||||
}
|
||||
newHeadSignedBlock := ðpb.SignedBeaconBlock{Block: newHeadBlock}
|
||||
|
||||
require.NoError(t, service.beaconDB.SaveBlock(context.Background(), newHeadSignedBlock))
|
||||
newRoot, err := stateutil.BlockRoot(newHeadBlock)
|
||||
|
||||
@@ -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"
|
||||
@@ -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 := ðpb.SignedBeaconBlock{Block: ðpb.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 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
require.NoError(t, db.SaveBlock(ctx, BlkWithStateBadAtt))
|
||||
BlkWithStateBadAttRoot, err := stateutil.BlockRoot(BlkWithStateBadAtt.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -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 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 2}}
|
||||
require.NoError(t, db.SaveBlock(ctx, BlkWithValidState))
|
||||
|
||||
BlkWithValidStateRoot, err := stateutil.BlockRoot(BlkWithValidState.Block)
|
||||
@@ -71,24 +69,28 @@ 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: ðpb.Attestation{Data: ðpb.AttestationData{Slot: params.BeaconConfig().SlotsPerEpoch, Target: ðpb.Checkpoint{Root: make([]byte, 32)}}},
|
||||
a: ðpb.Attestation{Data: ðpb.AttestationData{Slot: params.BeaconConfig().SlotsPerEpoch, Target: ðpb.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: ðpb.Attestation{Data: ðpb.AttestationData{Target: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{'A'}, 32)}}},
|
||||
a: ðpb.Attestation{Data: ðpb.AttestationData{Target: ðpb.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: ðpb.Attestation{Data: ðpb.AttestationData{Target: ðpb.Checkpoint{Root: BlkWithOutStateRoot[:]}}},
|
||||
s: &pb.BeaconState{},
|
||||
wantErr: true,
|
||||
wantErrString: "could not get pre state for slot 0",
|
||||
},
|
||||
@@ -96,32 +98,28 @@ func TestStore_OnAttestation(t *testing.T) {
|
||||
name: "process attestation doesn't match current epoch",
|
||||
a: ðpb.Attestation{Data: ðpb.AttestationData{Slot: 100 * params.BeaconConfig().SlotsPerEpoch, Target: ðpb.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: ðpb.Attestation{},
|
||||
s: &pb.BeaconState{},
|
||||
wantErr: true,
|
||||
wantErrString: "nil attestation.Data field",
|
||||
},
|
||||
{
|
||||
name: "process nil field (a.Target) in attestation",
|
||||
a: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: nil,
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
},
|
||||
AggregationBits: make([]byte, 1),
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
name: "process nil field (a.Target) in attestation",
|
||||
a: ðpb.Attestation{Data: ðpb.AttestationData{}},
|
||||
s: &pb.BeaconState{},
|
||||
wantErr: true,
|
||||
wantErrString: "nil attestation.Data.Target field",
|
||||
},
|
||||
@@ -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(ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{'A'}, 32)})
|
||||
require.NoError(t, err)
|
||||
val := ðpb.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: ðpb.BeaconBlockHeader{},
|
||||
JustificationBits: []byte{0},
|
||||
Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector),
|
||||
FinalizedCheckpoint: ðpb.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))
|
||||
@@ -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 := ðpb.Checkpoint{Epoch: epoch, Root: bytesutil.PadTo([]byte("hi"), 32)}
|
||||
checkpoint := ðpb.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)
|
||||
@@ -237,7 +241,7 @@ func TestStore_UpdateCheckpointState(t *testing.T) {
|
||||
assert.NotNil(t, cached, "State should have been cached")
|
||||
|
||||
epoch = uint64(2)
|
||||
newCheckpoint := ðpb.Checkpoint{Epoch: epoch, Root: bytesutil.PadTo([]byte("bye"), 32)}
|
||||
newCheckpoint := ðpb.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)
|
||||
@@ -264,7 +268,7 @@ func TestAttEpoch_MatchPrevEpoch(t *testing.T) {
|
||||
ctx,
|
||||
0,
|
||||
params.BeaconConfig().SlotsPerEpoch*params.BeaconConfig().SecondsPerSlot,
|
||||
ðpb.Checkpoint{Root: make([]byte, 32)}); err != nil {
|
||||
ðpb.Checkpoint{}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@@ -298,7 +302,7 @@ func TestAttEpoch_NotMatch(t *testing.T) {
|
||||
ctx,
|
||||
0,
|
||||
2*params.BeaconConfig().SlotsPerEpoch*params.BeaconConfig().SecondsPerSlot,
|
||||
ðpb.Checkpoint{Root: make([]byte, 32)}); !strings.Contains(err.Error(),
|
||||
ðpb.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")
|
||||
}
|
||||
@@ -312,12 +316,8 @@ func TestVerifyBeaconBlock_NoBlock(t *testing.T) {
|
||||
service, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
d := ðpb.AttestationData{
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
}
|
||||
assert.ErrorContains(t, "beacon block 0x000000000000 does not exist", service.verifyBeaconBlock(ctx, d))
|
||||
d := ðpb.AttestationData{}
|
||||
assert.ErrorContains(t, "beacon block does not exist", service.verifyBeaconBlock(ctx, d))
|
||||
}
|
||||
|
||||
func TestVerifyBeaconBlock_futureBlock(t *testing.T) {
|
||||
@@ -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 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 2}}
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, b))
|
||||
r, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -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 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 2}}
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, b))
|
||||
r, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -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 := ðpb.SignedBeaconBlock{Block: ðpb.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 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 33, ParentRoot: r32[:]}}
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, b33))
|
||||
r33, err := stateutil.BlockRoot(b33.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -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 := ðpb.SignedBeaconBlock{Block: ðpb.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 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 33, ParentRoot: r32[:]}}
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, b33))
|
||||
r33, err := stateutil.BlockRoot(b33.Block)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
@@ -48,9 +48,7 @@ func TestStore_OnBlock(t *testing.T) {
|
||||
require.NoError(t, service.beaconDB.SaveState(ctx, st.Copy(), validGenesisRoot))
|
||||
roots, err := blockTree1(db, validGenesisRoot[:])
|
||||
require.NoError(t, err)
|
||||
random := testutil.NewBeaconBlock()
|
||||
random.Block.Slot = 1
|
||||
random.Block.ParentRoot = validGenesisRoot[:]
|
||||
random := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1, ParentRoot: validGenesisRoot[:]}}
|
||||
assert.NoError(t, db.SaveBlock(ctx, random))
|
||||
randomParentRoot, err := stateutil.BlockRoot(random.Block)
|
||||
assert.NoError(t, err)
|
||||
@@ -62,46 +60,32 @@ func TestStore_OnBlock(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
blk *ethpb.SignedBeaconBlock
|
||||
blk *ethpb.BeaconBlock
|
||||
s *stateTrie.BeaconState
|
||||
time uint64
|
||||
wantErrString string
|
||||
}{
|
||||
{
|
||||
name: "parent block root does not have a state",
|
||||
blk: testutil.NewBeaconBlock(),
|
||||
blk: ðpb.BeaconBlock{},
|
||||
s: st.Copy(),
|
||||
wantErrString: "could not reconstruct parent state",
|
||||
},
|
||||
{
|
||||
name: "block is from the future",
|
||||
blk: func() *ethpb.SignedBeaconBlock {
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.ParentRoot = randomParentRoot[:]
|
||||
b.Block.Slot = params.BeaconConfig().FarFutureEpoch
|
||||
return b
|
||||
}(),
|
||||
name: "block is from the future",
|
||||
blk: ðpb.BeaconBlock{ParentRoot: randomParentRoot[:], Slot: params.BeaconConfig().FarFutureEpoch},
|
||||
s: st.Copy(),
|
||||
wantErrString: "far distant future",
|
||||
},
|
||||
{
|
||||
name: "could not get finalized block",
|
||||
blk: func() *ethpb.SignedBeaconBlock {
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.ParentRoot = randomParentRoot[:]
|
||||
return b
|
||||
}(),
|
||||
name: "could not get finalized block",
|
||||
blk: ðpb.BeaconBlock{ParentRoot: randomParentRoot[:]},
|
||||
s: st.Copy(),
|
||||
wantErrString: "is not a descendent of the current finalized block",
|
||||
},
|
||||
{
|
||||
name: "same slot as finalized block",
|
||||
blk: func() *ethpb.SignedBeaconBlock {
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 0
|
||||
b.Block.ParentRoot = randomParentRoot2
|
||||
return b
|
||||
}(),
|
||||
name: "same slot as finalized block",
|
||||
blk: ðpb.BeaconBlock{Slot: 0, ParentRoot: randomParentRoot2},
|
||||
s: st.Copy(),
|
||||
wantErrString: "block is equal or earlier than finalized block, slot 0 < slot 0",
|
||||
},
|
||||
@@ -115,9 +99,9 @@ func TestStore_OnBlock(t *testing.T) {
|
||||
service.prevFinalizedCheckpt = ðpb.Checkpoint{Root: validGenesisRoot[:]}
|
||||
service.finalizedCheckpt.Root = roots[0]
|
||||
|
||||
root, err := stateutil.BlockRoot(tt.blk.Block)
|
||||
root, err := stateutil.BlockRoot(tt.blk)
|
||||
assert.NoError(t, err)
|
||||
err = service.onBlock(ctx, tt.blk, root)
|
||||
err = service.onBlock(ctx, ðpb.SignedBeaconBlock{Block: tt.blk}, root)
|
||||
assert.ErrorContains(t, tt.wantErrString, err)
|
||||
})
|
||||
}
|
||||
@@ -175,7 +159,7 @@ func TestRemoveStateSinceLastFinalized_EmptyStartSlot(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
service.genesisTime = time.Now()
|
||||
|
||||
update, err := service.shouldUpdateCurrentJustified(ctx, ðpb.Checkpoint{Root: make([]byte, 32)})
|
||||
update, err := service.shouldUpdateCurrentJustified(ctx, ðpb.Checkpoint{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, true, update, "Should be able to update justified")
|
||||
lastJustifiedBlk := testutil.NewBeaconBlock()
|
||||
@@ -244,12 +228,10 @@ func TestCachedPreState_CanGetFromStateSummary(t *testing.T) {
|
||||
s, err := stateTrie.InitializeFromProto(&pb.BeaconState{Slot: 1, GenesisValidatorsRoot: params.BeaconConfig().ZeroHash[:]})
|
||||
require.NoError(t, err)
|
||||
r := [32]byte{'A'}
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 1
|
||||
b.Block.ParentRoot = r[:]
|
||||
b := ðpb.BeaconBlock{Slot: 1, ParentRoot: r[:]}
|
||||
require.NoError(t, service.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{Slot: 1, Root: r[:]}))
|
||||
require.NoError(t, service.stateGen.SaveState(ctx, r, s))
|
||||
require.NoError(t, service.verifyBlkPreState(ctx, b.Block))
|
||||
require.NoError(t, service.verifyBlkPreState(ctx, b))
|
||||
}
|
||||
|
||||
func TestCachedPreState_CanGetFromDB(t *testing.T) {
|
||||
@@ -267,12 +249,10 @@ func TestCachedPreState_CanGetFromDB(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
r := [32]byte{'A'}
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 1
|
||||
b.Block.ParentRoot = r[:]
|
||||
b := ðpb.BeaconBlock{Slot: 1, ParentRoot: r[:]}
|
||||
|
||||
service.finalizedCheckpt = ðpb.Checkpoint{Root: r[:]}
|
||||
err = service.verifyBlkPreState(ctx, b.Block)
|
||||
err = service.verifyBlkPreState(ctx, b)
|
||||
wanted := "could not reconstruct parent state"
|
||||
assert.ErrorContains(t, wanted, err)
|
||||
|
||||
@@ -280,7 +260,7 @@ func TestCachedPreState_CanGetFromDB(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{Slot: 1, Root: r[:]}))
|
||||
require.NoError(t, service.stateGen.SaveState(ctx, r, s))
|
||||
require.NoError(t, service.verifyBlkPreState(ctx, b.Block))
|
||||
require.NoError(t, service.verifyBlkPreState(ctx, b))
|
||||
}
|
||||
|
||||
func TestUpdateJustified_CouldUpdateBest(t *testing.T) {
|
||||
@@ -291,7 +271,7 @@ func TestUpdateJustified_CouldUpdateBest(t *testing.T) {
|
||||
service, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
signedBlock := testutil.NewBeaconBlock()
|
||||
signedBlock := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, signedBlock))
|
||||
r, err := stateutil.BlockRoot(signedBlock.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -323,7 +303,7 @@ func TestFillForkChoiceMissingBlocks_CanSave(t *testing.T) {
|
||||
service, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
service.forkChoiceStore = protoarray.New(0, 0, [32]byte{'A'})
|
||||
service.finalizedCheckpt = ðpb.Checkpoint{Root: make([]byte, 32)}
|
||||
service.finalizedCheckpt = ðpb.Checkpoint{}
|
||||
|
||||
genesisStateRoot := [32]byte{}
|
||||
genesis := blocks.NewGenesisBlock(genesisStateRoot[:])
|
||||
@@ -337,12 +317,10 @@ func TestFillForkChoiceMissingBlocks_CanSave(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.Slot = 9
|
||||
block.Block.ParentRoot = roots[8]
|
||||
block := ðpb.BeaconBlock{Slot: 9, ParentRoot: roots[8], Body: ðpb.BeaconBlockBody{Graffiti: []byte{}}}
|
||||
|
||||
err = service.fillInForkChoiceMissingBlocks(
|
||||
context.Background(), block.Block, beaconState.FinalizedCheckpoint(), beaconState.CurrentJustifiedCheckpoint())
|
||||
context.Background(), block, beaconState.FinalizedCheckpoint(), beaconState.CurrentJustifiedCheckpoint())
|
||||
require.NoError(t, err)
|
||||
|
||||
// 5 nodes from the block tree 1. B0 - B3 - B4 - B6 - B8
|
||||
@@ -373,20 +351,15 @@ func TestFillForkChoiceMissingBlocks_FilterFinalized(t *testing.T) {
|
||||
require.NoError(t, service.beaconDB.SaveState(ctx, st.Copy(), validGenesisRoot))
|
||||
|
||||
// Define a tree branch, slot 63 <- 64 <- 65
|
||||
b63 := testutil.NewBeaconBlock()
|
||||
b63.Block.Slot = 63
|
||||
b63 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 63, Body: ðpb.BeaconBlockBody{}}}
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, b63))
|
||||
r63, err := stateutil.BlockRoot(b63.Block)
|
||||
require.NoError(t, err)
|
||||
b64 := testutil.NewBeaconBlock()
|
||||
b64.Block.Slot = 64
|
||||
b64.Block.ParentRoot = r63[:]
|
||||
b64 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 64, ParentRoot: r63[:], Body: ðpb.BeaconBlockBody{}}}
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, b64))
|
||||
r64, err := stateutil.BlockRoot(b64.Block)
|
||||
require.NoError(t, err)
|
||||
b65 := testutil.NewBeaconBlock()
|
||||
b65.Block.Slot = 65
|
||||
b65.Block.ParentRoot = r64[:]
|
||||
b65 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 65, ParentRoot: r64[:], Body: ðpb.BeaconBlockBody{}}}
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, b65))
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
@@ -407,74 +380,58 @@ func TestFillForkChoiceMissingBlocks_FilterFinalized(t *testing.T) {
|
||||
// \- B3 - B4 - B6 - B8
|
||||
// (B1, and B3 are all from the same slots)
|
||||
func blockTree1(db db.Database, genesisRoot []byte) ([][]byte, error) {
|
||||
genesisRoot = bytesutil.PadTo(genesisRoot, 32)
|
||||
b0 := testutil.NewBeaconBlock()
|
||||
b0.Block.Slot = 0
|
||||
b0.Block.ParentRoot = genesisRoot
|
||||
r0, err := b0.Block.HashTreeRoot()
|
||||
b0 := ðpb.BeaconBlock{Slot: 0, ParentRoot: genesisRoot}
|
||||
r0, err := ssz.HashTreeRoot(b0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b1 := testutil.NewBeaconBlock()
|
||||
b1.Block.Slot = 1
|
||||
b1.Block.ParentRoot = r0[:]
|
||||
r1, err := b1.Block.HashTreeRoot()
|
||||
b1 := ðpb.BeaconBlock{Slot: 1, ParentRoot: r0[:]}
|
||||
r1, err := ssz.HashTreeRoot(b1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b3 := testutil.NewBeaconBlock()
|
||||
b3.Block.Slot = 3
|
||||
b3.Block.ParentRoot = r0[:]
|
||||
r3, err := b3.Block.HashTreeRoot()
|
||||
b3 := ðpb.BeaconBlock{Slot: 3, ParentRoot: r0[:]}
|
||||
r3, err := ssz.HashTreeRoot(b3)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b4 := testutil.NewBeaconBlock()
|
||||
b4.Block.Slot = 4
|
||||
b4.Block.ParentRoot = r3[:]
|
||||
r4, err := b4.Block.HashTreeRoot()
|
||||
b4 := ðpb.BeaconBlock{Slot: 4, ParentRoot: r3[:]}
|
||||
r4, err := ssz.HashTreeRoot(b4)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b5 := testutil.NewBeaconBlock()
|
||||
b5.Block.Slot = 5
|
||||
b5.Block.ParentRoot = r4[:]
|
||||
r5, err := b5.Block.HashTreeRoot()
|
||||
b5 := ðpb.BeaconBlock{Slot: 5, ParentRoot: r4[:]}
|
||||
r5, err := ssz.HashTreeRoot(b5)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b6 := testutil.NewBeaconBlock()
|
||||
b6.Block.Slot = 6
|
||||
b6.Block.ParentRoot = r4[:]
|
||||
r6, err := b6.Block.HashTreeRoot()
|
||||
b6 := ðpb.BeaconBlock{Slot: 6, ParentRoot: r4[:]}
|
||||
r6, err := ssz.HashTreeRoot(b6)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b7 := testutil.NewBeaconBlock()
|
||||
b7.Block.Slot = 7
|
||||
b7.Block.ParentRoot = r5[:]
|
||||
r7, err := b7.Block.HashTreeRoot()
|
||||
b7 := ðpb.BeaconBlock{Slot: 7, ParentRoot: r5[:]}
|
||||
r7, err := ssz.HashTreeRoot(b7)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b8 := testutil.NewBeaconBlock()
|
||||
b8.Block.Slot = 8
|
||||
b8.Block.ParentRoot = r6[:]
|
||||
r8, err := b8.Block.HashTreeRoot()
|
||||
b8 := ðpb.BeaconBlock{Slot: 8, ParentRoot: r6[:]}
|
||||
r8, err := ssz.HashTreeRoot(b8)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
st := testutil.NewBeaconState()
|
||||
|
||||
for _, b := range []*ethpb.SignedBeaconBlock{b0, b1, b3, b4, b5, b6, b7, b8} {
|
||||
for _, b := range []*ethpb.BeaconBlock{b0, b1, b3, b4, b5, b6, b7, b8} {
|
||||
beaconBlock := testutil.NewBeaconBlock()
|
||||
beaconBlock.Block.Slot = b.Block.Slot
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.Block.ParentRoot, 32)
|
||||
beaconBlock.Block.Slot = b.Slot
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.ParentRoot, 32)
|
||||
beaconBlock.Block.Body = ðpb.BeaconBlockBody{}
|
||||
if err := db.SaveBlock(context.Background(), beaconBlock); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.SaveState(context.Background(), st.Copy(), bytesutil.ToBytes32(beaconBlock.Block.ParentRoot)); err != nil {
|
||||
return nil, errors.Wrap(err, "could not save state")
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := db.SaveState(context.Background(), st.Copy(), r1); err != nil {
|
||||
@@ -504,25 +461,20 @@ func TestAncestor_HandleSkipSlot(t *testing.T) {
|
||||
service, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
b1 := testutil.NewBeaconBlock()
|
||||
b1.Block.Slot = 1
|
||||
b1.Block.ParentRoot = bytesutil.PadTo([]byte{'a'}, 32)
|
||||
r1, err := b1.Block.HashTreeRoot()
|
||||
b1 := ðpb.BeaconBlock{Slot: 1, ParentRoot: []byte{'a'}}
|
||||
r1, err := ssz.HashTreeRoot(b1)
|
||||
require.NoError(t, err)
|
||||
b100 := testutil.NewBeaconBlock()
|
||||
b100.Block.Slot = 100
|
||||
b100.Block.ParentRoot = r1[:]
|
||||
r100, err := b100.Block.HashTreeRoot()
|
||||
b100 := ðpb.BeaconBlock{Slot: 100, ParentRoot: r1[:]}
|
||||
r100, err := ssz.HashTreeRoot(b100)
|
||||
require.NoError(t, err)
|
||||
b200 := testutil.NewBeaconBlock()
|
||||
b200.Block.Slot = 200
|
||||
b200.Block.ParentRoot = r100[:]
|
||||
r200, err := b200.Block.HashTreeRoot()
|
||||
b200 := ðpb.BeaconBlock{Slot: 200, ParentRoot: r100[:]}
|
||||
r200, err := ssz.HashTreeRoot(b200)
|
||||
require.NoError(t, err)
|
||||
for _, b := range []*ethpb.SignedBeaconBlock{b1, b100, b200} {
|
||||
for _, b := range []*ethpb.BeaconBlock{b1, b100, b200} {
|
||||
beaconBlock := testutil.NewBeaconBlock()
|
||||
beaconBlock.Block.Slot = b.Block.Slot
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.Block.ParentRoot, 32)
|
||||
beaconBlock.Block.Slot = b.Slot
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.ParentRoot, 32)
|
||||
beaconBlock.Block.Body = ðpb.BeaconBlockBody{}
|
||||
require.NoError(t, db.SaveBlock(context.Background(), beaconBlock))
|
||||
}
|
||||
|
||||
@@ -605,20 +557,16 @@ func TestFinalizedImpliesNewJustified(t *testing.T) {
|
||||
require.NoError(t, service.beaconDB.SaveState(ctx, genesisState, bytesutil.ToBytes32(test.want.Root)))
|
||||
|
||||
if test.args.diffFinalizedCheckPoint {
|
||||
b1 := testutil.NewBeaconBlock()
|
||||
b1.Block.Slot = 1
|
||||
b1.Block.ParentRoot = bytesutil.PadTo([]byte{'a'}, 32)
|
||||
r1, err := b1.Block.HashTreeRoot()
|
||||
b1 := ðpb.BeaconBlock{Slot: 1, ParentRoot: []byte{'a'}}
|
||||
r1, err := ssz.HashTreeRoot(b1)
|
||||
require.NoError(t, err)
|
||||
b100 := testutil.NewBeaconBlock()
|
||||
b100.Block.Slot = 100
|
||||
b100.Block.ParentRoot = r1[:]
|
||||
r100, err := b100.Block.HashTreeRoot()
|
||||
b100 := ðpb.BeaconBlock{Slot: 100, ParentRoot: r1[:]}
|
||||
r100, err := ssz.HashTreeRoot(b100)
|
||||
require.NoError(t, err)
|
||||
for _, b := range []*ethpb.SignedBeaconBlock{b1, b100} {
|
||||
for _, b := range []*ethpb.BeaconBlock{b1, b100} {
|
||||
beaconBlock := testutil.NewBeaconBlock()
|
||||
beaconBlock.Block.Slot = b.Block.Slot
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.Block.ParentRoot, 32)
|
||||
beaconBlock.Block.Slot = b.Slot
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.ParentRoot, 32)
|
||||
require.NoError(t, service.beaconDB.SaveBlock(context.Background(), beaconBlock))
|
||||
}
|
||||
service.finalizedCheckpt = ðpb.Checkpoint{Root: []byte{'c'}, Epoch: 1}
|
||||
@@ -717,7 +665,7 @@ func TestUpdateJustifiedInitSync(t *testing.T) {
|
||||
service, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
gBlk := testutil.NewBeaconBlock()
|
||||
gBlk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
gRoot, err := stateutil.BlockRoot(gBlk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, gBlk))
|
||||
|
||||
@@ -17,6 +17,6 @@ func TestVerifyCheckpointEpoch_Ok(t *testing.T) {
|
||||
chainService := setupBeaconChain(t, db, sc)
|
||||
chainService.genesisTime = time.Now()
|
||||
|
||||
assert.Equal(t, true, chainService.verifyCheckpointEpoch(ðpb.Checkpoint{Root: make([]byte, 32)}))
|
||||
assert.Equal(t, true, chainService.verifyCheckpointEpoch(ðpb.Checkpoint{}))
|
||||
assert.Equal(t, false, chainService.verifyCheckpointEpoch(ðpb.Checkpoint{Epoch: 1}))
|
||||
}
|
||||
|
||||
@@ -322,8 +322,8 @@ func TestService_ReceiveBlockBatch(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
db, stateSummaryCache := testDB.SetupDB(t)
|
||||
genesisBlockRoot, err := genesis.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
genesisBlockRoot := bytesutil.ToBytes32(nil)
|
||||
|
||||
cfg := &Config{
|
||||
BeaconDB: db,
|
||||
ForkChoiceStore: protoarray.New(
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
||||
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
@@ -178,12 +179,11 @@ func TestChainService_InitializeBeaconChain(t *testing.T) {
|
||||
err = genState.SetEth1Data(ðpb.Eth1Data{
|
||||
DepositRoot: hashTreeRoot[:],
|
||||
DepositCount: uint64(len(deposits)),
|
||||
BlockHash: make([]byte, 32),
|
||||
})
|
||||
genState, err = b.ProcessPreGenesisDeposits(ctx, genState, deposits)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = bc.initializeBeaconChain(ctx, time.Unix(0, 0), genState, ðpb.Eth1Data{DepositRoot: hashTreeRoot[:], BlockHash: make([]byte, 32)})
|
||||
_, err = bc.initializeBeaconChain(ctx, time.Unix(0, 0), genState, ðpb.Eth1Data{DepositRoot: hashTreeRoot[:]})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = bc.HeadState(ctx)
|
||||
@@ -275,9 +275,8 @@ func TestChainService_SaveHeadNoDB(t *testing.T) {
|
||||
beaconDB: db,
|
||||
stateGen: stategen.New(db, sc),
|
||||
}
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 1
|
||||
r, err := b.HashTreeRoot()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
r, err := ssz.HashTreeRoot(b)
|
||||
require.NoError(t, err)
|
||||
newState := testutil.NewBeaconState()
|
||||
require.NoError(t, s.stateGen.SaveState(ctx, r, newState))
|
||||
@@ -295,13 +294,13 @@ func TestHasBlock_ForkChoiceAndDB(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
s := &Service{
|
||||
forkChoiceStore: protoarray.New(0, 0, [32]byte{}),
|
||||
finalizedCheckpt: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
finalizedCheckpt: ðpb.Checkpoint{},
|
||||
beaconDB: db,
|
||||
}
|
||||
block := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{}}}
|
||||
r, err := stateutil.BlockRoot(block.Block)
|
||||
require.NoError(t, err)
|
||||
bs := &pb.BeaconState{FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}}
|
||||
bs := &pb.BeaconState{FinalizedCheckpoint: ðpb.Checkpoint{}, CurrentJustifiedCheckpoint: ðpb.Checkpoint{}}
|
||||
state, err := beaconstate.InitializeFromProto(bs)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, s.insertBlockAndAttestationsToForkChoiceStore(ctx, block.Block, r, state))
|
||||
@@ -316,7 +315,7 @@ func BenchmarkHasBlockDB(b *testing.B) {
|
||||
s := &Service{
|
||||
beaconDB: db,
|
||||
}
|
||||
block := testutil.NewBeaconBlock()
|
||||
block := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(b, s.beaconDB.SaveBlock(ctx, block))
|
||||
r, err := stateutil.BlockRoot(block.Block)
|
||||
require.NoError(b, err)
|
||||
@@ -332,13 +331,13 @@ func BenchmarkHasBlockForkChoiceStore(b *testing.B) {
|
||||
db, _ := testDB.SetupDB(b)
|
||||
s := &Service{
|
||||
forkChoiceStore: protoarray.New(0, 0, [32]byte{}),
|
||||
finalizedCheckpt: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
finalizedCheckpt: ðpb.Checkpoint{},
|
||||
beaconDB: db,
|
||||
}
|
||||
block := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{}}}
|
||||
r, err := stateutil.BlockRoot(block.Block)
|
||||
require.NoError(b, err)
|
||||
bs := &pb.BeaconState{FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}}
|
||||
bs := &pb.BeaconState{FinalizedCheckpoint: ðpb.Checkpoint{}, CurrentJustifiedCheckpoint: ðpb.Checkpoint{}}
|
||||
state, err := beaconstate.InitializeFromProto(bs)
|
||||
require.NoError(b, err)
|
||||
require.NoError(b, s.insertBlockAndAttestationsToForkChoiceStore(ctx, block.Block, r, state))
|
||||
|
||||
@@ -233,10 +233,8 @@ func (ms *ChainService) HeadSlot() uint64 {
|
||||
|
||||
// HeadRoot mocks HeadRoot method in chain service.
|
||||
func (ms *ChainService) HeadRoot(ctx context.Context) ([]byte, error) {
|
||||
if len(ms.Root) > 0 {
|
||||
return ms.Root, nil
|
||||
}
|
||||
return make([]byte, 32), nil
|
||||
return ms.Root, nil
|
||||
|
||||
}
|
||||
|
||||
// HeadBlock mocks HeadBlock method in chain service.
|
||||
|
||||
2
beacon-chain/cache/attestation_data_test.go
vendored
2
beacon-chain/cache/attestation_data_test.go
vendored
@@ -26,7 +26,7 @@ func TestAttestationCache_RoundTrip(t *testing.T) {
|
||||
assert.NoError(t, c.MarkInProgress(req))
|
||||
|
||||
res := ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Epoch: 5, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 5},
|
||||
}
|
||||
|
||||
assert.NoError(t, c.Put(ctx, req, res))
|
||||
|
||||
2
beacon-chain/cache/checkpoint_state_test.go
vendored
2
beacon-chain/cache/checkpoint_state_test.go
vendored
@@ -61,7 +61,7 @@ func TestCheckpointStateCache_MaxSize(t *testing.T) {
|
||||
|
||||
for i := uint64(0); i < uint64(maxCheckpointStateSize+100); i++ {
|
||||
require.NoError(t, st.SetSlot(i))
|
||||
require.NoError(t, c.AddCheckpointState(ðpb.Checkpoint{Epoch: i, Root: make([]byte, 32)}, st))
|
||||
require.NoError(t, c.AddCheckpointState(ðpb.Checkpoint{Epoch: i}, st))
|
||||
}
|
||||
|
||||
assert.Equal(t, maxCheckpointStateSize, len(c.cache.Keys()))
|
||||
|
||||
2
beacon-chain/cache/depositcache/BUILD.bazel
vendored
2
beacon-chain/cache/depositcache/BUILD.bazel
vendored
@@ -18,6 +18,7 @@ go_library(
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto: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",
|
||||
"@io_opencensus_go//trace:go_default_library",
|
||||
],
|
||||
@@ -39,6 +40,7 @@ go_test(
|
||||
"//shared/trieutil:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
dbpb "github.com/prysmaticlabs/prysm/proto/beacon/db"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
@@ -127,7 +128,7 @@ func (dc *DepositCache) InsertFinalizedDeposits(ctx context.Context, eth1Deposit
|
||||
if d.Index > eth1DepositIndex {
|
||||
break
|
||||
}
|
||||
depHash, err := d.Deposit.Data.HashTreeRoot()
|
||||
depHash, err := ssz.HashTreeRoot(d.Deposit.Data)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not hash deposit data. Finalized deposit cache not updated.")
|
||||
return
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
dbpb "github.com/prysmaticlabs/prysm/proto/beacon/db"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
@@ -161,74 +162,32 @@ func TestDepositsNumberAndRootAtHeight_ReturnsAppropriateCountAndRoot(t *testing
|
||||
dc.deposits = []*dbpb.DepositContainer{
|
||||
{
|
||||
Eth1BlockHeight: 10,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
},
|
||||
Deposit: ðpb.Deposit{},
|
||||
},
|
||||
{
|
||||
Eth1BlockHeight: 10,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
},
|
||||
Deposit: ðpb.Deposit{},
|
||||
},
|
||||
{
|
||||
Eth1BlockHeight: 10,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
},
|
||||
Deposit: ðpb.Deposit{},
|
||||
},
|
||||
{
|
||||
Eth1BlockHeight: 10,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
},
|
||||
Deposit: ðpb.Deposit{},
|
||||
},
|
||||
{
|
||||
Eth1BlockHeight: 11,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
},
|
||||
DepositRoot: bytesutil.PadTo([]byte("root"), 32),
|
||||
Deposit: ðpb.Deposit{},
|
||||
DepositRoot: []byte("root"),
|
||||
},
|
||||
{
|
||||
Eth1BlockHeight: 12,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
},
|
||||
Deposit: ðpb.Deposit{},
|
||||
},
|
||||
{
|
||||
Eth1BlockHeight: 12,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
},
|
||||
Deposit: ðpb.Deposit{},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -244,25 +203,13 @@ func TestDepositsNumberAndRootAtHeight_ReturnsEmptyTrieIfBlockHeightLessThanOlde
|
||||
dc.deposits = []*dbpb.DepositContainer{
|
||||
{
|
||||
Eth1BlockHeight: 10,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
},
|
||||
DepositRoot: bytesutil.PadTo([]byte("root"), 32),
|
||||
Deposit: ðpb.Deposit{},
|
||||
DepositRoot: []byte("root"),
|
||||
},
|
||||
{
|
||||
Eth1BlockHeight: 11,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
},
|
||||
DepositRoot: bytesutil.PadTo([]byte("root"), 32),
|
||||
Deposit: ðpb.Deposit{},
|
||||
DepositRoot: []byte("root"),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -280,9 +227,7 @@ func TestDepositByPubkey_ReturnsFirstMatchingDeposit(t *testing.T) {
|
||||
Eth1BlockHeight: 9,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("pk0"), 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte("pk0"),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -290,9 +235,7 @@ func TestDepositByPubkey_ReturnsFirstMatchingDeposit(t *testing.T) {
|
||||
Eth1BlockHeight: 10,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("pk1"), 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte("pk1"),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -300,9 +243,7 @@ func TestDepositByPubkey_ReturnsFirstMatchingDeposit(t *testing.T) {
|
||||
Eth1BlockHeight: 11,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("pk1"), 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte("pk1"),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -310,18 +251,15 @@ func TestDepositByPubkey_ReturnsFirstMatchingDeposit(t *testing.T) {
|
||||
Eth1BlockHeight: 12,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("pk2"), 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte("pk2"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
pk1 := bytesutil.PadTo([]byte("pk1"), 48)
|
||||
dep, blkNum := dc.DepositByPubkey(context.Background(), pk1)
|
||||
dep, blkNum := dc.DepositByPubkey(context.Background(), []byte("pk1"))
|
||||
|
||||
if dep == nil || !bytes.Equal(dep.Data.PublicKey, pk1) {
|
||||
if !bytes.Equal(dep.Data.PublicKey, []byte("pk1")) {
|
||||
t.Error("Returned wrong deposit")
|
||||
}
|
||||
assert.Equal(t, 0, blkNum.Cmp(big.NewInt(10)),
|
||||
@@ -336,9 +274,7 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
|
||||
{
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{0}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{0},
|
||||
},
|
||||
},
|
||||
Index: 0,
|
||||
@@ -346,9 +282,7 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
|
||||
{
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{1}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{1},
|
||||
},
|
||||
},
|
||||
Index: 1,
|
||||
@@ -356,9 +290,7 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
|
||||
{
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{2}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{2},
|
||||
},
|
||||
},
|
||||
Index: 2,
|
||||
@@ -367,9 +299,7 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
|
||||
dc.deposits = append(finalizedDeposits, &dbpb.DepositContainer{
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{3}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{3},
|
||||
},
|
||||
},
|
||||
Index: 3,
|
||||
@@ -383,7 +313,7 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
|
||||
|
||||
var deps [][]byte
|
||||
for _, d := range finalizedDeposits {
|
||||
hash, err := d.Deposit.Data.HashTreeRoot()
|
||||
hash, err := ssz.HashTreeRoot(d.Deposit.Data)
|
||||
require.NoError(t, err, "Could not hash deposit data")
|
||||
deps = append(deps, hash[:])
|
||||
}
|
||||
@@ -400,9 +330,7 @@ func TestFinalizedDeposits_UtilizesPreviouslyCachedDeposits(t *testing.T) {
|
||||
{
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{0}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{0},
|
||||
},
|
||||
},
|
||||
Index: 0,
|
||||
@@ -410,9 +338,7 @@ func TestFinalizedDeposits_UtilizesPreviouslyCachedDeposits(t *testing.T) {
|
||||
{
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{1}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{1},
|
||||
},
|
||||
},
|
||||
Index: 1,
|
||||
@@ -421,9 +347,7 @@ func TestFinalizedDeposits_UtilizesPreviouslyCachedDeposits(t *testing.T) {
|
||||
newFinalizedDeposit := dbpb.DepositContainer{
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{2}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{2},
|
||||
},
|
||||
},
|
||||
Index: 2,
|
||||
@@ -441,7 +365,7 @@ func TestFinalizedDeposits_UtilizesPreviouslyCachedDeposits(t *testing.T) {
|
||||
|
||||
var deps [][]byte
|
||||
for _, d := range append(oldFinalizedDeposits, &newFinalizedDeposit) {
|
||||
hash, err := d.Deposit.Data.HashTreeRoot()
|
||||
hash, err := ssz.HashTreeRoot(d.Deposit.Data)
|
||||
require.NoError(t, err, "Could not hash deposit data")
|
||||
deps = append(deps, hash[:])
|
||||
}
|
||||
@@ -469,9 +393,7 @@ func TestNonFinalizedDeposits_ReturnsAllNonFinalizedDeposits(t *testing.T) {
|
||||
Eth1BlockHeight: 10,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{0}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{0},
|
||||
},
|
||||
},
|
||||
Index: 0,
|
||||
@@ -480,9 +402,7 @@ func TestNonFinalizedDeposits_ReturnsAllNonFinalizedDeposits(t *testing.T) {
|
||||
Eth1BlockHeight: 10,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{1}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{1},
|
||||
},
|
||||
},
|
||||
Index: 1,
|
||||
@@ -493,9 +413,7 @@ func TestNonFinalizedDeposits_ReturnsAllNonFinalizedDeposits(t *testing.T) {
|
||||
Eth1BlockHeight: 10,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{2}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{2},
|
||||
},
|
||||
},
|
||||
Index: 2,
|
||||
@@ -504,9 +422,7 @@ func TestNonFinalizedDeposits_ReturnsAllNonFinalizedDeposits(t *testing.T) {
|
||||
Eth1BlockHeight: 11,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{3}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{3},
|
||||
},
|
||||
},
|
||||
Index: 3,
|
||||
@@ -526,9 +442,7 @@ func TestNonFinalizedDeposits_ReturnsNonFinalizedDepositsUpToBlockNumber(t *test
|
||||
Eth1BlockHeight: 10,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{0}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{0},
|
||||
},
|
||||
},
|
||||
Index: 0,
|
||||
@@ -537,9 +451,7 @@ func TestNonFinalizedDeposits_ReturnsNonFinalizedDepositsUpToBlockNumber(t *test
|
||||
Eth1BlockHeight: 10,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{1}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{1},
|
||||
},
|
||||
},
|
||||
Index: 1,
|
||||
@@ -550,9 +462,7 @@ func TestNonFinalizedDeposits_ReturnsNonFinalizedDepositsUpToBlockNumber(t *test
|
||||
Eth1BlockHeight: 10,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{2}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{2},
|
||||
},
|
||||
},
|
||||
Index: 2,
|
||||
@@ -561,9 +471,7 @@ func TestNonFinalizedDeposits_ReturnsNonFinalizedDepositsUpToBlockNumber(t *test
|
||||
Eth1BlockHeight: 11,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{3}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{3},
|
||||
},
|
||||
},
|
||||
Index: 3,
|
||||
|
||||
@@ -29,28 +29,14 @@ func TestInsertPendingDeposit_ignoresNilDeposit(t *testing.T) {
|
||||
assert.Equal(t, 0, len(dc.pendingDeposits))
|
||||
}
|
||||
|
||||
func makeDepositProof() [][]byte {
|
||||
proof := make([][]byte, int(params.BeaconConfig().DepositContractTreeDepth)+1)
|
||||
for i := range proof {
|
||||
proof[i] = make([]byte, 32)
|
||||
}
|
||||
return proof
|
||||
}
|
||||
|
||||
func TestRemovePendingDeposit_OK(t *testing.T) {
|
||||
db := DepositCache{}
|
||||
proof1 := makeDepositProof()
|
||||
proof1 := make([][]byte, int(params.BeaconConfig().DepositContractTreeDepth)+1)
|
||||
proof1[0] = bytesutil.PadTo([]byte{'A'}, 32)
|
||||
proof2 := makeDepositProof()
|
||||
proof2 := make([][]byte, int(params.BeaconConfig().DepositContractTreeDepth)+1)
|
||||
proof2[0] = bytesutil.PadTo([]byte{'A'}, 32)
|
||||
data := ðpb.Deposit_Data{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Amount: 0,
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
depToRemove := ðpb.Deposit{Proof: proof1, Data: data}
|
||||
otherDep := ðpb.Deposit{Proof: proof2, Data: data}
|
||||
depToRemove := ðpb.Deposit{Proof: proof1}
|
||||
otherDep := ðpb.Deposit{Proof: proof2}
|
||||
db.pendingDeposits = []*dbpb.DepositContainer{
|
||||
{Deposit: depToRemove, Index: 1},
|
||||
{Deposit: otherDep, Index: 5},
|
||||
@@ -71,15 +57,9 @@ func TestRemovePendingDeposit_IgnoresNilDeposit(t *testing.T) {
|
||||
|
||||
func TestPendingDeposit_RoundTrip(t *testing.T) {
|
||||
dc := DepositCache{}
|
||||
proof := makeDepositProof()
|
||||
proof := make([][]byte, int(params.BeaconConfig().DepositContractTreeDepth)+1)
|
||||
proof[0] = bytesutil.PadTo([]byte{'A'}, 32)
|
||||
data := ðpb.Deposit_Data{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Amount: 0,
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
dep := ðpb.Deposit{Proof: proof, Data: data}
|
||||
dep := ðpb.Deposit{Proof: proof}
|
||||
dc.InsertPendingDeposit(context.Background(), dep, 111, 100, [32]byte{})
|
||||
dc.RemovePendingDeposit(context.Background(), dep)
|
||||
assert.Equal(t, 0, len(dc.pendingDeposits), "Failed to insert & delete a pending deposit")
|
||||
|
||||
@@ -63,7 +63,6 @@ go_test(
|
||||
"randao_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
shard_count = 2,
|
||||
deps = [
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
@@ -83,6 +82,7 @@ go_test(
|
||||
"@com_github_google_gofuzz//: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",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
attaggregation "github.com/prysmaticlabs/prysm/shared/aggregation/attestations"
|
||||
"github.com/prysmaticlabs/prysm/shared/attestationutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"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"
|
||||
@@ -26,7 +25,7 @@ func TestProcessAttestations_InclusionDelayFailure(t *testing.T) {
|
||||
attestations := []*ethpb.Attestation{
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
Slot: 5,
|
||||
},
|
||||
},
|
||||
@@ -82,8 +81,8 @@ func TestProcessAttestations_CurrentEpochFFGDataMismatches(t *testing.T) {
|
||||
attestations := []*ethpb.Attestation{
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
Source: ðpb.Checkpoint{Epoch: 1},
|
||||
},
|
||||
AggregationBits: aggBits,
|
||||
},
|
||||
@@ -128,8 +127,8 @@ func TestProcessAttestations_PrevEpochFFGDataMismatches(t *testing.T) {
|
||||
attestations := []*ethpb.Attestation{
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Epoch: 1},
|
||||
Target: ðpb.Checkpoint{Epoch: 1},
|
||||
Slot: params.BeaconConfig().SlotsPerEpoch,
|
||||
},
|
||||
AggregationBits: aggBits,
|
||||
@@ -208,12 +207,10 @@ func TestProcessAttestations_OK(t *testing.T) {
|
||||
copy(mockRoot[:], "hello-world")
|
||||
att := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
|
||||
},
|
||||
AggregationBits: aggBits,
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
|
||||
cfc := beaconState.CurrentJustifiedCheckpoint()
|
||||
@@ -235,21 +232,23 @@ func TestProcessAttestations_OK(t *testing.T) {
|
||||
}
|
||||
att.Signature = bls.AggregateSignatures(sigs).Marshal()[:]
|
||||
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.Body.Attestations = []*ethpb.Attestation{att}
|
||||
block := ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
Attestations: []*ethpb.Attestation{att},
|
||||
},
|
||||
}
|
||||
|
||||
err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
require.NoError(t, err)
|
||||
_, err = blocks.ProcessAttestations(context.Background(), beaconState, block.Block.Body)
|
||||
_, err = blocks.ProcessAttestations(context.Background(), beaconState, block.Body)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestProcessAggregatedAttestation_OverlappingBits(t *testing.T) {
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, 100)
|
||||
data := ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: bytesutil.PadTo([]byte("hello-world"), 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: bytesutil.PadTo([]byte("hello-world"), 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: []byte("hello-world")},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: []byte("hello-world")},
|
||||
}
|
||||
aggBits1 := bitfield.NewBitlist(4)
|
||||
aggBits1.SetBitAt(0, true)
|
||||
@@ -261,7 +260,7 @@ func TestProcessAggregatedAttestation_OverlappingBits(t *testing.T) {
|
||||
}
|
||||
|
||||
cfc := beaconState.CurrentJustifiedCheckpoint()
|
||||
cfc.Root = bytesutil.PadTo([]byte("hello-world"), 32)
|
||||
cfc.Root = []byte("hello-world")
|
||||
require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(cfc))
|
||||
require.NoError(t, beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}))
|
||||
|
||||
@@ -312,9 +311,8 @@ func TestProcessAggregatedAttestation_NoOverlappingBits(t *testing.T) {
|
||||
var mockRoot [32]byte
|
||||
copy(mockRoot[:], "hello-world")
|
||||
data := ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
|
||||
}
|
||||
aggBits1 := bitfield.NewBitlist(9)
|
||||
aggBits1.SetBitAt(0, true)
|
||||
@@ -322,7 +320,6 @@ func TestProcessAggregatedAttestation_NoOverlappingBits(t *testing.T) {
|
||||
att1 := ðpb.Attestation{
|
||||
Data: data,
|
||||
AggregationBits: aggBits1,
|
||||
Signature: make([]byte, 32),
|
||||
}
|
||||
|
||||
cfc := beaconState.CurrentJustifiedCheckpoint()
|
||||
@@ -350,7 +347,6 @@ func TestProcessAggregatedAttestation_NoOverlappingBits(t *testing.T) {
|
||||
att2 := ðpb.Attestation{
|
||||
Data: data,
|
||||
AggregationBits: aggBits2,
|
||||
Signature: make([]byte, 32),
|
||||
}
|
||||
|
||||
committee, err = helpers.BeaconCommitteeFromState(beaconState, att2.Data.Slot, att2.Data.CommitteeIndex)
|
||||
@@ -369,13 +365,16 @@ func TestProcessAggregatedAttestation_NoOverlappingBits(t *testing.T) {
|
||||
|
||||
aggregatedAtt, err := attaggregation.AggregatePair(att1, att2)
|
||||
require.NoError(t, err)
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.Body.Attestations = []*ethpb.Attestation{aggregatedAtt}
|
||||
block := ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
Attestations: []*ethpb.Attestation{aggregatedAtt},
|
||||
},
|
||||
}
|
||||
|
||||
err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = blocks.ProcessAttestations(context.Background(), beaconState, block.Block.Body)
|
||||
_, err = blocks.ProcessAttestations(context.Background(), beaconState, block.Body)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -385,7 +384,7 @@ func TestProcessAttestationsNoVerify_IncorrectSlotTargetEpoch(t *testing.T) {
|
||||
att := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: params.BeaconConfig().SlotsPerEpoch,
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{},
|
||||
},
|
||||
}
|
||||
wanted := fmt.Sprintf("data slot is not in the same epoch as target %d != %d", helpers.SlotToEpoch(att.Data.Slot), att.Data.Target.Epoch)
|
||||
@@ -405,7 +404,7 @@ func TestProcessAttestationsNoVerify_OK(t *testing.T) {
|
||||
att := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
AggregationBits: aggBits,
|
||||
}
|
||||
@@ -434,7 +433,7 @@ func TestProcessAttestationsNoVerify_BadAttIdx(t *testing.T) {
|
||||
Data: ðpb.AttestationData{
|
||||
CommitteeIndex: 100,
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
AggregationBits: aggBits,
|
||||
}
|
||||
@@ -487,8 +486,8 @@ func TestConvertToIndexed_OK(t *testing.T) {
|
||||
attestation := ðpb.Attestation{
|
||||
Signature: sig[:],
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Epoch: 0},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -513,9 +512,8 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: keys[i].PublicKey().Marshal(),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: keys[i].PublicKey().Marshal(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,57 +535,33 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) {
|
||||
Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 2,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Source: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
},
|
||||
AttestingIndices: []uint64{1},
|
||||
Signature: make([]byte, 96),
|
||||
}},
|
||||
{attestation: ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 1,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Source: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
},
|
||||
AttestingIndices: []uint64{47, 99, 101},
|
||||
Signature: make([]byte, 96),
|
||||
}},
|
||||
{attestation: ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 4,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Source: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
},
|
||||
AttestingIndices: []uint64{21, 72},
|
||||
Signature: make([]byte, 96),
|
||||
}},
|
||||
{attestation: ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 7,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Source: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
},
|
||||
AttestingIndices: []uint64{100, 121, 122},
|
||||
Signature: make([]byte, 96),
|
||||
}},
|
||||
}
|
||||
|
||||
@@ -679,28 +653,32 @@ func TestVerifyAttestations_VerifiesMultipleAttestations(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: keys[i].PublicKey().Marshal(),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: keys[i].PublicKey().Marshal(),
|
||||
}
|
||||
}
|
||||
|
||||
st := testutil.NewBeaconState()
|
||||
require.NoError(t, st.SetSlot(5))
|
||||
require.NoError(t, st.SetValidators(validators))
|
||||
st, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Slot: 5,
|
||||
Validators: validators,
|
||||
Fork: &pb.Fork{
|
||||
Epoch: 0,
|
||||
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
},
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
|
||||
comm1, err := helpers.BeaconCommitteeFromState(st, 1 /*slot*/, 0 /*committeeIndex*/)
|
||||
require.NoError(t, err)
|
||||
att1 := ðpb.Attestation{
|
||||
AggregationBits: bitfield.NewBitlist(uint64(len(comm1))),
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
CommitteeIndex: 0,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
CommitteeIndex: 0,
|
||||
Target: new(ethpb.Checkpoint),
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
Signature: nil,
|
||||
}
|
||||
domain, err := helpers.Domain(st.Fork(), st.Fork().Epoch, params.BeaconConfig().DomainBeaconAttester, st.GenesisValidatorRoot())
|
||||
require.NoError(t, err)
|
||||
@@ -718,13 +696,11 @@ func TestVerifyAttestations_VerifiesMultipleAttestations(t *testing.T) {
|
||||
att2 := ðpb.Attestation{
|
||||
AggregationBits: bitfield.NewBitlist(uint64(len(comm2))),
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
CommitteeIndex: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
CommitteeIndex: 1,
|
||||
Target: new(ethpb.Checkpoint),
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
Signature: nil,
|
||||
}
|
||||
root, err = helpers.ComputeSigningRoot(att2.Data, domain)
|
||||
require.NoError(t, err)
|
||||
@@ -747,33 +723,32 @@ func TestVerifyAttestations_HandlesPlannedFork(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: keys[i].PublicKey().Marshal(),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: keys[i].PublicKey().Marshal(),
|
||||
}
|
||||
}
|
||||
|
||||
st := testutil.NewBeaconState()
|
||||
require.NoError(t, st.SetSlot(35))
|
||||
require.NoError(t, st.SetValidators(validators))
|
||||
require.NoError(t, st.SetFork(&pb.Fork{
|
||||
Epoch: 1,
|
||||
CurrentVersion: []byte{0, 1, 2, 3},
|
||||
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
}))
|
||||
st, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Slot: 35,
|
||||
Validators: validators,
|
||||
Fork: &pb.Fork{
|
||||
Epoch: 1,
|
||||
CurrentVersion: []byte{0, 1, 2, 3},
|
||||
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
},
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
|
||||
comm1, err := helpers.BeaconCommitteeFromState(st, 1 /*slot*/, 0 /*committeeIndex*/)
|
||||
require.NoError(t, err)
|
||||
att1 := ðpb.Attestation{
|
||||
AggregationBits: bitfield.NewBitlist(uint64(len(comm1))),
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
CommitteeIndex: 0,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
CommitteeIndex: 0,
|
||||
Target: new(ethpb.Checkpoint),
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
Signature: nil,
|
||||
}
|
||||
prevDomain, err := helpers.Domain(st.Fork(), st.Fork().Epoch-1, params.BeaconConfig().DomainBeaconAttester, st.GenesisValidatorRoot())
|
||||
require.NoError(t, err)
|
||||
@@ -791,13 +766,11 @@ func TestVerifyAttestations_HandlesPlannedFork(t *testing.T) {
|
||||
att2 := ðpb.Attestation{
|
||||
AggregationBits: bitfield.NewBitlist(uint64(len(comm2))),
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1*params.BeaconConfig().SlotsPerEpoch + 1,
|
||||
CommitteeIndex: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1*params.BeaconConfig().SlotsPerEpoch + 1,
|
||||
CommitteeIndex: 1,
|
||||
Target: new(ethpb.Checkpoint),
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
Signature: nil,
|
||||
}
|
||||
currDomain, err := helpers.Domain(st.Fork(), st.Fork().Epoch, params.BeaconConfig().DomainBeaconAttester, st.GenesisValidatorRoot())
|
||||
root, err = helpers.ComputeSigningRoot(att2.Data, currDomain)
|
||||
@@ -820,28 +793,32 @@ func TestRetrieveAttestationSignatureSet_VerifiesMultipleAttestations(t *testing
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: keys[i].PublicKey().Marshal(),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: keys[i].PublicKey().Marshal(),
|
||||
}
|
||||
}
|
||||
|
||||
st := testutil.NewBeaconState()
|
||||
require.NoError(t, st.SetSlot(5))
|
||||
require.NoError(t, st.SetValidators(validators))
|
||||
st, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Slot: 5,
|
||||
Validators: validators,
|
||||
Fork: &pb.Fork{
|
||||
Epoch: 0,
|
||||
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
},
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
|
||||
comm1, err := helpers.BeaconCommitteeFromState(st, 1 /*slot*/, 0 /*committeeIndex*/)
|
||||
require.NoError(t, err)
|
||||
att1 := ðpb.Attestation{
|
||||
AggregationBits: bitfield.NewBitlist(uint64(len(comm1))),
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
CommitteeIndex: 0,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
CommitteeIndex: 0,
|
||||
Target: new(ethpb.Checkpoint),
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
Signature: nil,
|
||||
}
|
||||
domain, err := helpers.Domain(st.Fork(), st.Fork().Epoch, params.BeaconConfig().DomainBeaconAttester, st.GenesisValidatorRoot())
|
||||
require.NoError(t, err)
|
||||
@@ -859,13 +836,11 @@ func TestRetrieveAttestationSignatureSet_VerifiesMultipleAttestations(t *testing
|
||||
att2 := ðpb.Attestation{
|
||||
AggregationBits: bitfield.NewBitlist(uint64(len(comm2))),
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
CommitteeIndex: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
CommitteeIndex: 1,
|
||||
Target: new(ethpb.Checkpoint),
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
Signature: nil,
|
||||
}
|
||||
root, err = helpers.ComputeSigningRoot(att2.Data, domain)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"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"
|
||||
@@ -20,14 +19,12 @@ import (
|
||||
|
||||
func TestSlashableAttestationData_CanSlash(t *testing.T) {
|
||||
att1 := ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{'A'}, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Epoch: 1},
|
||||
Source: ðpb.Checkpoint{Root: []byte{'A'}},
|
||||
}
|
||||
att2 := ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{'B'}, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Epoch: 1},
|
||||
Source: ðpb.Checkpoint{Root: []byte{'B'}},
|
||||
}
|
||||
assert.Equal(t, true, blocks.IsSlashableAttestationData(att1, att2), "Atts should have been slashable")
|
||||
att1.Target.Epoch = 4
|
||||
@@ -41,19 +38,15 @@ func TestProcessAttesterSlashings_DataNotSlashable(t *testing.T) {
|
||||
{
|
||||
Attestation_1: ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Epoch: 0},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
Attestation_2: ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Epoch: 1},
|
||||
Target: ðpb.Checkpoint{Epoch: 1},
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -89,21 +82,17 @@ func TestProcessAttesterSlashings_IndexedAttestationFailedToVerify(t *testing.T)
|
||||
{
|
||||
Attestation_1: ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Epoch: 1},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
AttestingIndices: make([]uint64, params.BeaconConfig().MaxValidatorsPerCommittee+1),
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
Attestation_2: ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Epoch: 0},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
AttestingIndices: make([]uint64, params.BeaconConfig().MaxValidatorsPerCommittee+1),
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -127,9 +116,8 @@ func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) {
|
||||
|
||||
att1 := ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Epoch: 1},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
AttestingIndices: []uint64{0, 1},
|
||||
}
|
||||
@@ -144,9 +132,8 @@ func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) {
|
||||
|
||||
att2 := ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Epoch: 0},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
AttestingIndices: []uint64{0, 1},
|
||||
}
|
||||
|
||||
@@ -39,12 +39,10 @@ func TestProcessAttesterSlashings_RegressionSlashableIndices(t *testing.T) {
|
||||
root1 := [32]byte{'d', 'o', 'u', 'b', 'l', 'e', '1'}
|
||||
att1 := ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: root1[:]},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Epoch: 0},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: root1[:]},
|
||||
},
|
||||
AttestingIndices: setA,
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
domain, err := helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, beaconState.GenesisValidatorRoot())
|
||||
require.NoError(t, err)
|
||||
@@ -61,12 +59,10 @@ func TestProcessAttesterSlashings_RegressionSlashableIndices(t *testing.T) {
|
||||
root2 := [32]byte{'d', 'o', 'u', 'b', 'l', 'e', '2'}
|
||||
att2 := ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: root2[:]},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Epoch: 0},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: root2[:]},
|
||||
},
|
||||
AttestingIndices: setB,
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
signingRoot, err = helpers.ComputeSigningRoot(att2.Data, domain)
|
||||
assert.NoError(t, err, "Could not get signing root of beacon block header")
|
||||
|
||||
@@ -197,7 +197,7 @@ func verifyDeposit(beaconState *stateTrie.BeaconState, deposit *ethpb.Deposit) e
|
||||
}
|
||||
|
||||
receiptRoot := eth1Data.DepositRoot
|
||||
leaf, err := deposit.Data.HashTreeRoot()
|
||||
leaf, err := ssz.HashTreeRoot(deposit.Data)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not tree hash deposit data")
|
||||
}
|
||||
@@ -253,7 +253,7 @@ func verifyDepositDataWithDomain(ctx context.Context, deps []*ethpb.Deposit, dom
|
||||
ObjectRoot: root[:],
|
||||
Domain: domain,
|
||||
}
|
||||
ctrRoot, err := signingData.HashTreeRoot()
|
||||
ctrRoot, err := ssz.HashTreeRoot(signingData)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not get container root")
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ 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/beacon-chain/core/helpers"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
@@ -57,12 +58,11 @@ func TestProcessDeposits_SameValidatorMultipleDepositsSameBlock(t *testing.T) {
|
||||
func TestProcessDeposits_MerkleBranchFailsVerification(t *testing.T) {
|
||||
deposit := ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{1, 2, 3}, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: []byte{1, 2, 3},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
}
|
||||
leaf, err := deposit.Data.HashTreeRoot()
|
||||
leaf, err := ssz.HashTreeRoot(deposit.Data)
|
||||
require.NoError(t, err)
|
||||
|
||||
// We then create a merkle branch for the test.
|
||||
@@ -132,17 +132,15 @@ func TestProcessDeposits_RepeatedDeposit_IncreasesValidatorBalance(t *testing.T)
|
||||
sk := bls.RandKey()
|
||||
deposit := ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: sk.PublicKey().Marshal(),
|
||||
Amount: 1000,
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
Signature: make([]byte, 96),
|
||||
PublicKey: sk.PublicKey().Marshal(),
|
||||
Amount: 1000,
|
||||
},
|
||||
}
|
||||
sr, err := helpers.ComputeSigningRoot(deposit.Data, bytesutil.ToBytes(3, 32))
|
||||
sr, err := helpers.ComputeSigningRoot(deposit.Data, bytesutil.ToBytes(3, 8))
|
||||
require.NoError(t, err)
|
||||
sig := sk.Sign(sr[:])
|
||||
deposit.Data.Signature = sig.Marshal()
|
||||
leaf, err := deposit.Data.HashTreeRoot()
|
||||
leaf, err := ssz.HashTreeRoot(deposit.Data)
|
||||
require.NoError(t, err)
|
||||
|
||||
// We then create a merkle branch for the test.
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
beaconstate "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/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
@@ -20,7 +19,7 @@ func FakeDeposits(n uint64) []*ethpb.Eth1Data {
|
||||
for i := uint64(0); i < n; i++ {
|
||||
deposits[i] = ðpb.Eth1Data{
|
||||
DepositCount: 1,
|
||||
DepositRoot: bytesutil.PadTo([]byte("root"), 32),
|
||||
DepositRoot: []byte("root"),
|
||||
}
|
||||
}
|
||||
return deposits
|
||||
@@ -37,7 +36,7 @@ func TestEth1DataHasEnoughSupport(t *testing.T) {
|
||||
stateVotes: FakeDeposits(4 * params.BeaconConfig().SlotsPerEpoch),
|
||||
data: ðpb.Eth1Data{
|
||||
DepositCount: 1,
|
||||
DepositRoot: bytesutil.PadTo([]byte("root"), 32),
|
||||
DepositRoot: []byte("root"),
|
||||
},
|
||||
hasSupport: true,
|
||||
votingPeriodLength: 7,
|
||||
@@ -45,7 +44,7 @@ func TestEth1DataHasEnoughSupport(t *testing.T) {
|
||||
stateVotes: FakeDeposits(4 * params.BeaconConfig().SlotsPerEpoch),
|
||||
data: ðpb.Eth1Data{
|
||||
DepositCount: 1,
|
||||
DepositRoot: bytesutil.PadTo([]byte("root"), 32),
|
||||
DepositRoot: []byte("root"),
|
||||
},
|
||||
hasSupport: false,
|
||||
votingPeriodLength: 8,
|
||||
@@ -53,7 +52,7 @@ func TestEth1DataHasEnoughSupport(t *testing.T) {
|
||||
stateVotes: FakeDeposits(4 * params.BeaconConfig().SlotsPerEpoch),
|
||||
data: ðpb.Eth1Data{
|
||||
DepositCount: 1,
|
||||
DepositRoot: bytesutil.PadTo([]byte("root"), 32),
|
||||
DepositRoot: []byte("root"),
|
||||
},
|
||||
hasSupport: false,
|
||||
votingPeriodLength: 10,
|
||||
|
||||
@@ -10,20 +10,13 @@ import (
|
||||
// NewGenesisBlock returns the canonical, genesis block for the beacon chain protocol.
|
||||
func NewGenesisBlock(stateRoot []byte) *ethpb.SignedBeaconBlock {
|
||||
zeroHash := params.BeaconConfig().ZeroHash[:]
|
||||
block := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
ParentRoot: zeroHash,
|
||||
StateRoot: stateRoot,
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
RandaoReveal: make([]byte, 96),
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: make([]byte, 32),
|
||||
},
|
||||
Graffiti: make([]byte, 32),
|
||||
},
|
||||
},
|
||||
genBlock := ðpb.BeaconBlock{
|
||||
ParentRoot: zeroHash,
|
||||
StateRoot: stateRoot,
|
||||
Body: ðpb.BeaconBlockBody{},
|
||||
}
|
||||
return ðpb.SignedBeaconBlock{
|
||||
Block: genBlock,
|
||||
Signature: params.BeaconConfig().EmptySignature[:],
|
||||
}
|
||||
return block
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ import (
|
||||
|
||||
"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"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"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"
|
||||
@@ -28,22 +28,22 @@ func TestProcessBlockHeader_ImproperBlockSlot(t *testing.T) {
|
||||
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
PublicKey: make([]byte, 32),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
Slashed: true,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
Slashed: true,
|
||||
}
|
||||
}
|
||||
|
||||
state := testutil.NewBeaconState()
|
||||
require.NoError(t, state.SetSlot(10))
|
||||
require.NoError(t, state.SetValidators(validators))
|
||||
require.NoError(t, state.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
Slot: 10, // Must be less than block.Slot
|
||||
ParentRoot: make([]byte, 32),
|
||||
StateRoot: make([]byte, 32),
|
||||
BodyRoot: make([]byte, 32),
|
||||
}))
|
||||
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: 10,
|
||||
LatestBlockHeader: ðpb.BeaconBlockHeader{Slot: 10}, // Must be less than block.Slot
|
||||
Fork: &pb.Fork{
|
||||
PreviousVersion: []byte{0, 0, 0, 0},
|
||||
CurrentVersion: []byte{0, 0, 0, 0},
|
||||
},
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
latestBlockSignedRoot, err := stateutil.BlockHeaderRoot(state.LatestBlockHeader())
|
||||
require.NoError(t, err)
|
||||
@@ -52,11 +52,16 @@ func TestProcessBlockHeader_ImproperBlockSlot(t *testing.T) {
|
||||
priv := bls.RandKey()
|
||||
pID, err := helpers.BeaconProposerIndex(state)
|
||||
require.NoError(t, err)
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.ProposerIndex = pID
|
||||
block.Block.Slot = 10
|
||||
block.Block.Body.RandaoReveal = bytesutil.PadTo([]byte{'A', 'B', 'C'}, 96)
|
||||
block.Block.ParentRoot = latestBlockSignedRoot[:]
|
||||
block := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
ProposerIndex: pID,
|
||||
Slot: 10,
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
RandaoReveal: []byte{'A', 'B', 'C'},
|
||||
},
|
||||
ParentRoot: latestBlockSignedRoot[:],
|
||||
},
|
||||
}
|
||||
block.Signature, err = helpers.ComputeDomainAndSign(state, currentEpoch, block.Block, params.BeaconConfig().DomainBeaconProposer, priv)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -74,12 +79,7 @@ func TestProcessBlockHeader_ImproperBlockSlot(t *testing.T) {
|
||||
func TestProcessBlockHeader_WrongProposerSig(t *testing.T) {
|
||||
testutil.ResetCache()
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, 100)
|
||||
require.NoError(t, beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
Slot: 9,
|
||||
ParentRoot: make([]byte, 32),
|
||||
StateRoot: make([]byte, 32),
|
||||
BodyRoot: make([]byte, 32),
|
||||
}))
|
||||
require.NoError(t, beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{Slot: 9}))
|
||||
require.NoError(t, beaconState.SetSlot(10))
|
||||
|
||||
lbhdr, err := stateutil.BlockHeaderRoot(beaconState.LatestBlockHeader())
|
||||
@@ -88,11 +88,16 @@ func TestProcessBlockHeader_WrongProposerSig(t *testing.T) {
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
|
||||
require.NoError(t, err)
|
||||
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.ProposerIndex = proposerIdx
|
||||
block.Block.Slot = 10
|
||||
block.Block.Body.RandaoReveal = bytesutil.PadTo([]byte{'A', 'B', 'C'}, 96)
|
||||
block.Block.ParentRoot = lbhdr[:]
|
||||
block := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
ProposerIndex: proposerIdx,
|
||||
Slot: 10,
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
RandaoReveal: []byte{'A', 'B', 'C'},
|
||||
},
|
||||
ParentRoot: lbhdr[:],
|
||||
},
|
||||
}
|
||||
block.Signature, err = helpers.ComputeDomainAndSign(beaconState, 0, block.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx+1])
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -105,25 +110,24 @@ func TestProcessBlockHeader_DifferentSlots(t *testing.T) {
|
||||
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
PublicKey: make([]byte, 32),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
Slashed: true,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
Slashed: true,
|
||||
}
|
||||
}
|
||||
|
||||
state := testutil.NewBeaconState()
|
||||
require.NoError(t, state.SetValidators(validators))
|
||||
require.NoError(t, state.SetSlot(10))
|
||||
require.NoError(t, state.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
Slot: 9,
|
||||
ProposerIndex: 0,
|
||||
ParentRoot: make([]byte, 32),
|
||||
StateRoot: make([]byte, 32),
|
||||
BodyRoot: make([]byte, 32),
|
||||
}))
|
||||
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: 10,
|
||||
LatestBlockHeader: ðpb.BeaconBlockHeader{Slot: 9},
|
||||
Fork: &pb.Fork{
|
||||
PreviousVersion: []byte{0, 0, 0, 0},
|
||||
CurrentVersion: []byte{0, 0, 0, 0},
|
||||
},
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
lbhsr, err := state.LatestBlockHeader().HashTreeRoot()
|
||||
lbhsr, err := ssz.HashTreeRoot(state.LatestBlockHeader())
|
||||
require.NoError(t, err)
|
||||
currentEpoch := helpers.CurrentEpoch(state)
|
||||
|
||||
@@ -151,10 +155,8 @@ func TestProcessBlockHeader_PreviousBlockRootNotSignedRoot(t *testing.T) {
|
||||
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
PublicKey: make([]byte, 32),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
Slashed: true,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
Slashed: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,10 +200,8 @@ func TestProcessBlockHeader_SlashedProposer(t *testing.T) {
|
||||
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
PublicKey: make([]byte, 32),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
Slashed: true,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
Slashed: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,23 +248,22 @@ func TestProcessBlockHeader_OK(t *testing.T) {
|
||||
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
PublicKey: make([]byte, 32),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
Slashed: true,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
Slashed: true,
|
||||
}
|
||||
}
|
||||
|
||||
state := testutil.NewBeaconState()
|
||||
require.NoError(t, state.SetValidators(validators))
|
||||
require.NoError(t, state.SetSlot(10))
|
||||
require.NoError(t, state.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
Slot: 9,
|
||||
ProposerIndex: 0,
|
||||
ParentRoot: make([]byte, 32),
|
||||
StateRoot: make([]byte, 32),
|
||||
BodyRoot: make([]byte, 32),
|
||||
}))
|
||||
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: 10,
|
||||
LatestBlockHeader: ðpb.BeaconBlockHeader{Slot: 9},
|
||||
Fork: &pb.Fork{
|
||||
PreviousVersion: []byte{0, 0, 0, 0},
|
||||
CurrentVersion: []byte{0, 0, 0, 0},
|
||||
},
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
latestBlockSignedRoot, err := stateutil.BlockHeaderRoot(state.LatestBlockHeader())
|
||||
require.NoError(t, err)
|
||||
@@ -273,11 +272,16 @@ func TestProcessBlockHeader_OK(t *testing.T) {
|
||||
priv := bls.RandKey()
|
||||
pID, err := helpers.BeaconProposerIndex(state)
|
||||
require.NoError(t, err)
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.ProposerIndex = pID
|
||||
block.Block.Slot = 10
|
||||
block.Block.Body.RandaoReveal = bytesutil.PadTo([]byte{'A', 'B', 'C'}, 96)
|
||||
block.Block.ParentRoot = latestBlockSignedRoot[:]
|
||||
block := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
ProposerIndex: pID,
|
||||
Slot: 10,
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
RandaoReveal: []byte{'A', 'B', 'C'},
|
||||
},
|
||||
ParentRoot: latestBlockSignedRoot[:],
|
||||
},
|
||||
}
|
||||
block.Signature, err = helpers.ComputeDomainAndSign(state, currentEpoch, block.Block, params.BeaconConfig().DomainBeaconProposer, priv)
|
||||
require.NoError(t, err)
|
||||
bodyRoot, err := stateutil.BlockBodyRoot(block.Block.Body)
|
||||
@@ -308,23 +312,22 @@ func TestBlockSignatureSet_OK(t *testing.T) {
|
||||
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
PublicKey: make([]byte, 32),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
Slashed: true,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
Slashed: true,
|
||||
}
|
||||
}
|
||||
|
||||
state := testutil.NewBeaconState()
|
||||
require.NoError(t, state.SetValidators(validators))
|
||||
require.NoError(t, state.SetSlot(10))
|
||||
require.NoError(t, state.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
Slot: 9,
|
||||
ProposerIndex: 0,
|
||||
ParentRoot: make([]byte, 32),
|
||||
StateRoot: make([]byte, 32),
|
||||
BodyRoot: make([]byte, 32),
|
||||
}))
|
||||
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: 10,
|
||||
LatestBlockHeader: ðpb.BeaconBlockHeader{Slot: 9},
|
||||
Fork: &pb.Fork{
|
||||
PreviousVersion: []byte{0, 0, 0, 0},
|
||||
CurrentVersion: []byte{0, 0, 0, 0},
|
||||
},
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
latestBlockSignedRoot, err := stateutil.BlockHeaderRoot(state.LatestBlockHeader())
|
||||
require.NoError(t, err)
|
||||
@@ -333,11 +336,16 @@ func TestBlockSignatureSet_OK(t *testing.T) {
|
||||
priv := bls.RandKey()
|
||||
pID, err := helpers.BeaconProposerIndex(state)
|
||||
require.NoError(t, err)
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.Slot = 10
|
||||
block.Block.ProposerIndex = pID
|
||||
block.Block.Body.RandaoReveal = bytesutil.PadTo([]byte{'A', 'B', 'C'}, 96)
|
||||
block.Block.ParentRoot = latestBlockSignedRoot[:]
|
||||
block := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
ProposerIndex: pID,
|
||||
Slot: 10,
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
RandaoReveal: []byte{'A', 'B', 'C'},
|
||||
},
|
||||
ParentRoot: latestBlockSignedRoot[:],
|
||||
},
|
||||
}
|
||||
block.Signature, err = helpers.ComputeDomainAndSign(state, currentEpoch, block.Block, params.BeaconConfig().DomainBeaconProposer, priv)
|
||||
require.NoError(t, err)
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(state)
|
||||
|
||||
@@ -98,14 +98,14 @@ func TestProcessProposerSlashings_ValidatorNotSlashable(t *testing.T) {
|
||||
ProposerIndex: 0,
|
||||
Slot: 0,
|
||||
},
|
||||
Signature: bytesutil.PadTo([]byte("A"), 96),
|
||||
Signature: []byte("A"),
|
||||
},
|
||||
Header_2: ðpb.SignedBeaconBlockHeader{
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
ProposerIndex: 0,
|
||||
Slot: 0,
|
||||
},
|
||||
Signature: bytesutil.PadTo([]byte("B"), 96),
|
||||
Signature: []byte("B"),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -138,9 +138,7 @@ func TestProcessProposerSlashings_AppliesCorrectStatus(t *testing.T) {
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
ProposerIndex: proposerIdx,
|
||||
Slot: 0,
|
||||
ParentRoot: make([]byte, 32),
|
||||
BodyRoot: make([]byte, 32),
|
||||
StateRoot: bytesutil.PadTo([]byte("A"), 32),
|
||||
StateRoot: []byte("A"),
|
||||
},
|
||||
}
|
||||
var err error
|
||||
@@ -151,9 +149,7 @@ func TestProcessProposerSlashings_AppliesCorrectStatus(t *testing.T) {
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
ProposerIndex: proposerIdx,
|
||||
Slot: 0,
|
||||
ParentRoot: make([]byte, 32),
|
||||
BodyRoot: make([]byte, 32),
|
||||
StateRoot: bytesutil.PadTo([]byte("B"), 32),
|
||||
StateRoot: []byte("B"),
|
||||
},
|
||||
}
|
||||
header2.Signature, err = helpers.ComputeDomainAndSign(beaconState, 0, header2.Header, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
|
||||
@@ -166,10 +162,13 @@ func TestProcessProposerSlashings_AppliesCorrectStatus(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.Body.ProposerSlashings = slashings
|
||||
block := ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
ProposerSlashings: slashings,
|
||||
},
|
||||
}
|
||||
|
||||
newState, err := blocks.ProcessProposerSlashings(context.Background(), beaconState, block.Block.Body)
|
||||
newState, err := blocks.ProcessProposerSlashings(context.Background(), beaconState, block.Body)
|
||||
require.NoError(t, err)
|
||||
|
||||
newStateVals := newState.Validators()
|
||||
|
||||
@@ -6,6 +6,7 @@ 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/beacon-chain/core/helpers"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
@@ -25,7 +26,7 @@ func TestProcessRandao_IncorrectProposerFailsVerification(t *testing.T) {
|
||||
binary.LittleEndian.PutUint64(buf, epoch)
|
||||
domain, err := helpers.Domain(beaconState.Fork(), epoch, params.BeaconConfig().DomainRandao, beaconState.GenesisValidatorRoot())
|
||||
require.NoError(t, err)
|
||||
root, err := (&pb.SigningData{ObjectRoot: buf, Domain: domain}).HashTreeRoot()
|
||||
root, err := ssz.HashTreeRoot(&pb.SigningData{ObjectRoot: buf, Domain: domain})
|
||||
require.NoError(t, err)
|
||||
// We make the previous validator's index sign the message instead of the proposer.
|
||||
epochSignature := privKeys[proposerIdx-1].Sign(root[:])
|
||||
|
||||
@@ -6,6 +6,7 @@ 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"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
@@ -28,7 +29,7 @@ func retrieveSignatureSet(signedData []byte, pub []byte, signature []byte, domai
|
||||
ObjectRoot: signedData,
|
||||
Domain: domain,
|
||||
}
|
||||
root, err := signingData.HashTreeRoot()
|
||||
root, err := ssz.HashTreeRoot(signingData)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not hash container")
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ go_library(
|
||||
"//shared/params: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",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -32,7 +33,6 @@ go_test(
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
|
||||
@@ -10,6 +10,7 @@ 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/validators"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
@@ -45,7 +46,7 @@ func (s sortableIndices) Less(i, j int) bool {
|
||||
// def get_attesting_balance(state: BeaconState, attestations: List[PendingAttestation]) -> Gwei:
|
||||
// return get_total_balance(state, get_unslashed_attesting_indices(state, attestations))
|
||||
func AttestingBalance(state *stateTrie.BeaconState, atts []*pb.PendingAttestation) (uint64, error) {
|
||||
indices, err := UnslashedAttestingIndices(state, atts)
|
||||
indices, err := unslashedAttestingIndices(state, atts)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "could not get attesting indices")
|
||||
}
|
||||
@@ -310,7 +311,7 @@ func ProcessFinalUpdates(state *stateTrie.BeaconState) (*stateTrie.BeaconState,
|
||||
BlockRoots: state.BlockRoots(),
|
||||
StateRoots: state.StateRoots(),
|
||||
}
|
||||
batchRoot, err := historicalBatch.HashTreeRoot()
|
||||
batchRoot, err := ssz.HashTreeRoot(historicalBatch)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not hash historical batch")
|
||||
}
|
||||
@@ -329,7 +330,7 @@ func ProcessFinalUpdates(state *stateTrie.BeaconState) (*stateTrie.BeaconState,
|
||||
return state, nil
|
||||
}
|
||||
|
||||
// UnslashedAttestingIndices returns all the attesting indices from a list of attestations,
|
||||
// unslashedAttestingIndices returns all the attesting indices from a list of attestations,
|
||||
// it sorts the indices and filters out the slashed ones.
|
||||
//
|
||||
// Spec pseudocode definition:
|
||||
@@ -339,7 +340,7 @@ func ProcessFinalUpdates(state *stateTrie.BeaconState) (*stateTrie.BeaconState,
|
||||
// for a in attestations:
|
||||
// output = output.union(get_attesting_indices(state, a.data, a.aggregation_bits))
|
||||
// return set(filter(lambda index: not state.validators[index].slashed, output))
|
||||
func UnslashedAttestingIndices(state *stateTrie.BeaconState, atts []*pb.PendingAttestation) ([]uint64, error) {
|
||||
func unslashedAttestingIndices(state *stateTrie.BeaconState, atts []*pb.PendingAttestation) ([]uint64, error) {
|
||||
var setIndices []uint64
|
||||
seen := make(map[uint64]bool)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package epoch_test
|
||||
package epoch
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -7,12 +7,10 @@ import (
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"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"
|
||||
)
|
||||
@@ -22,8 +20,8 @@ func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) {
|
||||
atts := make([]*pb.PendingAttestation, 2)
|
||||
for i := 0; i < len(atts); i++ {
|
||||
atts[i] = &pb.PendingAttestation{
|
||||
Data: ðpb.AttestationData{Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Data: ðpb.AttestationData{Source: ðpb.Checkpoint{},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF},
|
||||
}
|
||||
@@ -44,7 +42,7 @@ func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) {
|
||||
state, err := state.InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
|
||||
indices, err := epoch.UnslashedAttestingIndices(state, atts)
|
||||
indices, err := unslashedAttestingIndices(state, atts)
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < len(indices)-1; i++ {
|
||||
if indices[i] >= indices[i+1] {
|
||||
@@ -57,7 +55,7 @@ func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) {
|
||||
validators = state.Validators()
|
||||
validators[slashedValidator].Slashed = true
|
||||
require.NoError(t, state.SetValidators(validators))
|
||||
indices, err = epoch.UnslashedAttestingIndices(state, atts)
|
||||
indices, err = unslashedAttestingIndices(state, atts)
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < len(indices); i++ {
|
||||
assert.NotEqual(t, slashedValidator, indices[i], "Slashed validator %d is not filtered", slashedValidator)
|
||||
@@ -69,7 +67,7 @@ func TestUnslashedAttestingIndices_DuplicatedAttestations(t *testing.T) {
|
||||
atts := make([]*pb.PendingAttestation, 5)
|
||||
for i := 0; i < len(atts); i++ {
|
||||
atts[i] = &pb.PendingAttestation{
|
||||
Data: ðpb.AttestationData{Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Data: ðpb.AttestationData{Source: ðpb.Checkpoint{},
|
||||
Target: ðpb.Checkpoint{Epoch: 0}},
|
||||
AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF},
|
||||
}
|
||||
@@ -90,7 +88,7 @@ func TestUnslashedAttestingIndices_DuplicatedAttestations(t *testing.T) {
|
||||
state, err := state.InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
|
||||
indices, err := epoch.UnslashedAttestingIndices(state, atts)
|
||||
indices, err := unslashedAttestingIndices(state, atts)
|
||||
require.NoError(t, err)
|
||||
|
||||
for i := 0; i < len(indices)-1; i++ {
|
||||
@@ -107,8 +105,8 @@ func TestAttestingBalance_CorrectBalance(t *testing.T) {
|
||||
for i := 0; i < len(atts); i++ {
|
||||
atts[i] = &pb.PendingAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{},
|
||||
Source: ðpb.Checkpoint{},
|
||||
Slot: uint64(i),
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
@@ -136,7 +134,7 @@ func TestAttestingBalance_CorrectBalance(t *testing.T) {
|
||||
state, err := state.InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
|
||||
balance, err := epoch.AttestingBalance(state, atts)
|
||||
balance, err := AttestingBalance(state, atts)
|
||||
require.NoError(t, err)
|
||||
wanted := 256 * params.BeaconConfig().MaxEffectiveBalance
|
||||
assert.Equal(t, wanted, balance)
|
||||
@@ -161,9 +159,9 @@ func TestBaseReward_AccurateRewards(t *testing.T) {
|
||||
}
|
||||
state, err := state.InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
c, err := epoch.BaseReward(state, 0)
|
||||
c, err := BaseReward(state, 0)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.c, c, "epoch.BaseReward(%d)", tt.a)
|
||||
assert.Equal(t, tt.c, c, "BaseReward(%d)", tt.a)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +174,7 @@ func TestProcessSlashings_NotSlashed(t *testing.T) {
|
||||
}
|
||||
s, err := state.InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
newState, err := epoch.ProcessSlashings(s)
|
||||
newState, err := ProcessSlashings(s)
|
||||
require.NoError(t, err)
|
||||
wanted := params.BeaconConfig().MaxEffectiveBalance
|
||||
assert.Equal(t, wanted, newState.Balances()[0], "Unexpected slashed balance")
|
||||
@@ -254,7 +252,7 @@ func TestProcessSlashings_SlashedLess(t *testing.T) {
|
||||
original := proto.Clone(tt.state)
|
||||
s, err := state.InitializeFromProto(tt.state)
|
||||
require.NoError(t, err)
|
||||
newState, err := epoch.ProcessSlashings(s)
|
||||
newState, err := ProcessSlashings(s)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.want, newState.Balances()[0], "ProcessSlashings({%v}) = newState; newState.Balances[0] = %d", original, newState.Balances()[0])
|
||||
})
|
||||
@@ -262,7 +260,7 @@ func TestProcessSlashings_SlashedLess(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcessFinalUpdates_CanProcess(t *testing.T) {
|
||||
s := buildState(t, params.BeaconConfig().SlotsPerHistoricalRoot-1, params.BeaconConfig().SlotsPerEpoch)
|
||||
s := buildState(params.BeaconConfig().SlotsPerHistoricalRoot-1, params.BeaconConfig().SlotsPerEpoch)
|
||||
ce := helpers.CurrentEpoch(s)
|
||||
ne := ce + 1
|
||||
require.NoError(t, s.SetEth1DataVotes([]*ethpb.Eth1Data{}))
|
||||
@@ -277,7 +275,7 @@ func TestProcessFinalUpdates_CanProcess(t *testing.T) {
|
||||
mixes := s.RandaoMixes()
|
||||
mixes[ce] = []byte{'A'}
|
||||
require.NoError(t, s.SetRandaoMixes(mixes))
|
||||
newS, err := epoch.ProcessFinalUpdates(s)
|
||||
newS, err := ProcessFinalUpdates(s)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify effective balance is correctly updated.
|
||||
@@ -308,11 +306,11 @@ func TestProcessRegistryUpdates_NoRotation(t *testing.T) {
|
||||
params.BeaconConfig().MaxEffectiveBalance,
|
||||
params.BeaconConfig().MaxEffectiveBalance,
|
||||
},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{},
|
||||
}
|
||||
state, err := state.InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
newState, err := epoch.ProcessRegistryUpdates(state)
|
||||
newState, err := ProcessRegistryUpdates(state)
|
||||
require.NoError(t, err)
|
||||
for i, validator := range newState.Validators() {
|
||||
assert.Equal(t, params.BeaconConfig().MaxSeedLookahead, validator.ExitEpoch, "Could not update registry %d", i)
|
||||
@@ -322,7 +320,7 @@ func TestProcessRegistryUpdates_NoRotation(t *testing.T) {
|
||||
func TestProcessRegistryUpdates_EligibleToActivate(t *testing.T) {
|
||||
base := &pb.BeaconState{
|
||||
Slot: 5 * params.BeaconConfig().SlotsPerEpoch,
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{Epoch: 6, Root: make([]byte, 32)},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{Epoch: 6},
|
||||
}
|
||||
limit, err := helpers.ValidatorChurnLimit(0)
|
||||
require.NoError(t, err)
|
||||
@@ -335,7 +333,7 @@ func TestProcessRegistryUpdates_EligibleToActivate(t *testing.T) {
|
||||
}
|
||||
state, err := state.InitializeFromProto(base)
|
||||
currentEpoch := helpers.CurrentEpoch(state)
|
||||
newState, err := epoch.ProcessRegistryUpdates(state)
|
||||
newState, err := ProcessRegistryUpdates(state)
|
||||
require.NoError(t, err)
|
||||
for i, validator := range newState.Validators() {
|
||||
assert.Equal(t, currentEpoch+1, validator.ActivationEligibilityEpoch, "Could not update registry %d, unexpected activation eligibility epoch", i)
|
||||
@@ -359,11 +357,11 @@ func TestProcessRegistryUpdates_ActivationCompletes(t *testing.T) {
|
||||
{ExitEpoch: params.BeaconConfig().MaxSeedLookahead,
|
||||
ActivationEpoch: 5 + params.BeaconConfig().MaxSeedLookahead + 1},
|
||||
},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{},
|
||||
}
|
||||
state, err := state.InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
newState, err := epoch.ProcessRegistryUpdates(state)
|
||||
newState, err := ProcessRegistryUpdates(state)
|
||||
require.NoError(t, err)
|
||||
for i, validator := range newState.Validators() {
|
||||
assert.Equal(t, params.BeaconConfig().MaxSeedLookahead, validator.ExitEpoch, "Could not update registry %d, unexpected exit slot", i)
|
||||
@@ -383,11 +381,11 @@ func TestProcessRegistryUpdates_ValidatorsEjected(t *testing.T) {
|
||||
EffectiveBalance: params.BeaconConfig().EjectionBalance - 1,
|
||||
},
|
||||
},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{},
|
||||
}
|
||||
state, err := state.InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
newState, err := epoch.ProcessRegistryUpdates(state)
|
||||
newState, err := ProcessRegistryUpdates(state)
|
||||
require.NoError(t, err)
|
||||
for i, validator := range newState.Validators() {
|
||||
assert.Equal(t, params.BeaconConfig().MaxSeedLookahead+1, validator.ExitEpoch, "Could not update registry %d, unexpected exit slot", i)
|
||||
@@ -395,11 +393,11 @@ func TestProcessRegistryUpdates_ValidatorsEjected(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcessRegistryUpdates_CanExits(t *testing.T) {
|
||||
e := uint64(5)
|
||||
exitEpoch := helpers.ActivationExitEpoch(e)
|
||||
epoch := uint64(5)
|
||||
exitEpoch := helpers.ActivationExitEpoch(epoch)
|
||||
minWithdrawalDelay := params.BeaconConfig().MinValidatorWithdrawabilityDelay
|
||||
base := &pb.BeaconState{
|
||||
Slot: e * params.BeaconConfig().SlotsPerEpoch,
|
||||
Slot: epoch * params.BeaconConfig().SlotsPerEpoch,
|
||||
Validators: []*ethpb.Validator{
|
||||
{
|
||||
ExitEpoch: exitEpoch,
|
||||
@@ -408,18 +406,18 @@ func TestProcessRegistryUpdates_CanExits(t *testing.T) {
|
||||
ExitEpoch: exitEpoch,
|
||||
WithdrawableEpoch: exitEpoch + minWithdrawalDelay},
|
||||
},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{},
|
||||
}
|
||||
state, err := state.InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
newState, err := epoch.ProcessRegistryUpdates(state)
|
||||
newState, err := ProcessRegistryUpdates(state)
|
||||
require.NoError(t, err)
|
||||
for i, validator := range newState.Validators() {
|
||||
assert.Equal(t, exitEpoch, validator.ExitEpoch, "Could not update registry %d, unexpected exit slot", i)
|
||||
}
|
||||
}
|
||||
|
||||
func buildState(t testing.TB, slot uint64, validatorCount uint64) *state.BeaconState {
|
||||
func buildState(slot uint64, validatorCount uint64) *state.BeaconState {
|
||||
validators := make([]*ethpb.Validator, validatorCount)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
@@ -445,15 +443,19 @@ func buildState(t testing.TB, slot uint64, validatorCount uint64) *state.BeaconS
|
||||
for i := 0; i < len(latestRandaoMixes); i++ {
|
||||
latestRandaoMixes[i] = params.BeaconConfig().ZeroHash[:]
|
||||
}
|
||||
s := testutil.NewBeaconState()
|
||||
if err := s.SetSlot(slot); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := s.SetBalances(validatorBalances); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := s.SetValidators(validators); err != nil {
|
||||
t.Error(err)
|
||||
s, err := state.InitializeFromProto(&pb.BeaconState{
|
||||
Slot: slot,
|
||||
Balances: validatorBalances,
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector),
|
||||
BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerEpoch*10),
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{},
|
||||
PreviousJustifiedCheckpoint: ðpb.Checkpoint{},
|
||||
CurrentJustifiedCheckpoint: ðpb.Checkpoint{},
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestProcessJustificationAndFinalizationPreCompute_ConsecutiveEpochs(t *test
|
||||
Epoch: 0,
|
||||
Root: params.BeaconConfig().ZeroHash[:],
|
||||
},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{},
|
||||
JustificationBits: bitfield.Bitvector4{0x0F}, // 0b1111
|
||||
Validators: []*ethpb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}},
|
||||
Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000
|
||||
@@ -67,7 +67,7 @@ func TestProcessJustificationAndFinalizationPreCompute_JustifyCurrentEpoch(t *te
|
||||
Epoch: 0,
|
||||
Root: params.BeaconConfig().ZeroHash[:],
|
||||
},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{},
|
||||
JustificationBits: bitfield.Bitvector4{0x03}, // 0b0011
|
||||
Validators: []*ethpb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}},
|
||||
Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000
|
||||
@@ -107,7 +107,7 @@ func TestProcessJustificationAndFinalizationPreCompute_JustifyPrevEpoch(t *testi
|
||||
JustificationBits: bitfield.Bitvector4{0x03}, // 0b0011
|
||||
Validators: []*ethpb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}},
|
||||
Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000
|
||||
BlockRoots: blockRoots, FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
BlockRoots: blockRoots, FinalizedCheckpoint: ðpb.Checkpoint{},
|
||||
}
|
||||
state, err := beaconstate.InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -24,8 +24,8 @@ func TestProcessRewardsAndPenaltiesPrecompute(t *testing.T) {
|
||||
for i := 0; i < len(atts); i++ {
|
||||
atts[i] = &pb.PendingAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{},
|
||||
Source: ðpb.Checkpoint{},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0xC0, 0xC0, 0xC0, 0xC0, 0x01},
|
||||
InclusionDelay: 1,
|
||||
@@ -214,8 +214,8 @@ func TestProcessRewardsAndPenaltiesPrecompute_SlashedInactivePenalty(t *testing.
|
||||
for i := 0; i < len(atts); i++ {
|
||||
atts[i] = &pb.PendingAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{},
|
||||
Source: ðpb.Checkpoint{},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0xC0, 0xC0, 0xC0, 0xC0, 0x01},
|
||||
InclusionDelay: 1,
|
||||
@@ -287,9 +287,9 @@ func buildState(slot uint64, validatorCount uint64) *pb.BeaconState {
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector),
|
||||
BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerEpoch*10),
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
PreviousJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{},
|
||||
PreviousJustifiedCheckpoint: ðpb.Checkpoint{},
|
||||
CurrentJustifiedCheckpoint: ðpb.Checkpoint{},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ type SyncedData struct {
|
||||
type InitializedData struct {
|
||||
// StartTime is the time at which the chain started.
|
||||
StartTime time.Time
|
||||
// GenesisValidatorsRoot represents state.validators.HashTreeRoot().
|
||||
// GenesisValidatorsRoot represents ssz.HashTreeRoot(state.validators).
|
||||
GenesisValidatorsRoot []byte
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ go_library(
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/roughtime:go_default_library",
|
||||
"//shared/sliceutil:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
@@ -67,6 +66,7 @@ go_test(
|
||||
deps = [
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//beacon-chain/state/stateutil:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/bls:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
|
||||
@@ -263,7 +263,7 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) {
|
||||
AggregationBits: bitfield.Bitlist{0x05},
|
||||
Data: ðpb.AttestationData{
|
||||
CommitteeIndex: 5,
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{},
|
||||
},
|
||||
},
|
||||
stateSlot: 5,
|
||||
@@ -274,7 +274,7 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) {
|
||||
AggregationBits: bitfield.Bitlist{0x06},
|
||||
Data: ðpb.AttestationData{
|
||||
CommitteeIndex: 10,
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{},
|
||||
},
|
||||
},
|
||||
stateSlot: 10,
|
||||
@@ -284,7 +284,7 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) {
|
||||
AggregationBits: bitfield.Bitlist{0x06},
|
||||
Data: ðpb.AttestationData{
|
||||
CommitteeIndex: 20,
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{},
|
||||
},
|
||||
},
|
||||
stateSlot: 20,
|
||||
@@ -294,7 +294,7 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) {
|
||||
AggregationBits: bitfield.Bitlist{0x06},
|
||||
Data: ðpb.AttestationData{
|
||||
CommitteeIndex: 20,
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{},
|
||||
},
|
||||
},
|
||||
stateSlot: 20,
|
||||
@@ -304,7 +304,7 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) {
|
||||
AggregationBits: bitfield.Bitlist{0xFF, 0xC0, 0x01},
|
||||
Data: ðpb.AttestationData{
|
||||
CommitteeIndex: 5,
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{},
|
||||
},
|
||||
},
|
||||
stateSlot: 5,
|
||||
@@ -315,7 +315,7 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) {
|
||||
AggregationBits: bitfield.Bitlist{0xFF, 0x01},
|
||||
Data: ðpb.AttestationData{
|
||||
CommitteeIndex: 20,
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{},
|
||||
},
|
||||
},
|
||||
stateSlot: 20,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
fssz "github.com/ferranbt/fastssz"
|
||||
"github.com/pkg/errors"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
@@ -49,14 +48,16 @@ func ComputeDomainAndSign(state *state.BeaconState, epoch uint64, obj interface{
|
||||
// domain=domain,
|
||||
// ))
|
||||
func ComputeSigningRoot(object interface{}, domain []byte) ([32]byte, error) {
|
||||
if object == nil {
|
||||
return [32]byte{}, errors.New("cannot compute signing root of nil")
|
||||
}
|
||||
return signingData(func() ([32]byte, error) {
|
||||
if v, ok := object.(fssz.HashRoot); ok {
|
||||
return v.HashTreeRoot()
|
||||
switch t := object.(type) {
|
||||
case *ethpb.BeaconBlock:
|
||||
return stateutil.BlockRoot(t)
|
||||
case *ethpb.AttestationData:
|
||||
return stateutil.AttestationDataRoot(t)
|
||||
default:
|
||||
// utilise generic ssz library
|
||||
return ssz.HashTreeRoot(object)
|
||||
}
|
||||
return ssz.HashTreeRoot(object)
|
||||
}, domain)
|
||||
}
|
||||
|
||||
@@ -71,7 +72,7 @@ func signingData(rootFunc func() ([32]byte, error), domain []byte) ([32]byte, er
|
||||
ObjectRoot: objRoot[:],
|
||||
Domain: domain,
|
||||
}
|
||||
return container.HashTreeRoot()
|
||||
return ssz.HashTreeRoot(container)
|
||||
}
|
||||
|
||||
// ComputeDomainVerifySigningRoot computes domain and verifies signing root of an object given the beacon state, validator index and signature.
|
||||
@@ -224,10 +225,10 @@ func domain(domainType [DomainByteLength]byte, forkDataRoot []byte) []byte {
|
||||
// genesis_validators_root=genesis_validators_root,
|
||||
// ))
|
||||
func computeForkDataRoot(version []byte, root []byte) ([32]byte, error) {
|
||||
r, err := (&pb.ForkData{
|
||||
r, err := ssz.HashTreeRoot(&pb.ForkData{
|
||||
CurrentVersion: version,
|
||||
GenesisValidatorsRoot: root,
|
||||
}).HashTreeRoot()
|
||||
})
|
||||
if err != nil {
|
||||
return [32]byte{}, err
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package helpers_test
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
fuzz "github.com/google/gofuzz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
ethereum_beacon_p2p_v1 "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
|
||||
func TestSigningRoot_ComputeOK(t *testing.T) {
|
||||
emptyBlock := testutil.NewBeaconBlock()
|
||||
_, err := helpers.ComputeSigningRoot(emptyBlock, bytesutil.PadTo([]byte{'T', 'E', 'S', 'T'}, 32))
|
||||
emptyBlock := ðpb.BeaconBlock{}
|
||||
_, err := ComputeSigningRoot(emptyBlock, []byte{'T', 'E', 'S', 'T'})
|
||||
assert.NoError(t, err, "Could not compute signing root of block")
|
||||
}
|
||||
|
||||
@@ -25,21 +25,38 @@ func TestComputeDomain_OK(t *testing.T) {
|
||||
domainType [4]byte
|
||||
domain []byte
|
||||
}{
|
||||
{epoch: 1, domainType: [4]byte{4, 0, 0, 0}, domain: []byte{4, 0, 0, 0, 245, 165, 253, 66, 209, 106, 32, 48, 39, 152, 239, 110, 211, 9, 151, 155, 67, 0, 61, 35, 32, 217, 240, 232, 234, 152, 49, 169}},
|
||||
{epoch: 2, domainType: [4]byte{4, 0, 0, 0}, domain: []byte{4, 0, 0, 0, 245, 165, 253, 66, 209, 106, 32, 48, 39, 152, 239, 110, 211, 9, 151, 155, 67, 0, 61, 35, 32, 217, 240, 232, 234, 152, 49, 169}},
|
||||
{epoch: 2, domainType: [4]byte{5, 0, 0, 0}, domain: []byte{5, 0, 0, 0, 245, 165, 253, 66, 209, 106, 32, 48, 39, 152, 239, 110, 211, 9, 151, 155, 67, 0, 61, 35, 32, 217, 240, 232, 234, 152, 49, 169}},
|
||||
{epoch: 3, domainType: [4]byte{4, 0, 0, 0}, domain: []byte{4, 0, 0, 0, 245, 165, 253, 66, 209, 106, 32, 48, 39, 152, 239, 110, 211, 9, 151, 155, 67, 0, 61, 35, 32, 217, 240, 232, 234, 152, 49, 169}},
|
||||
{epoch: 3, domainType: [4]byte{5, 0, 0, 0}, domain: []byte{5, 0, 0, 0, 245, 165, 253, 66, 209, 106, 32, 48, 39, 152, 239, 110, 211, 9, 151, 155, 67, 0, 61, 35, 32, 217, 240, 232, 234, 152, 49, 169}},
|
||||
{epoch: 1, domainType: [4]byte{4, 0, 0, 0}, domain: []byte{4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
|
||||
{epoch: 2, domainType: [4]byte{4, 0, 0, 0}, domain: []byte{4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
|
||||
{epoch: 2, domainType: [4]byte{5, 0, 0, 0}, domain: []byte{5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
|
||||
{epoch: 3, domainType: [4]byte{4, 0, 0, 0}, domain: []byte{4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
|
||||
{epoch: 3, domainType: [4]byte{5, 0, 0, 0}, domain: []byte{5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got, err := helpers.ComputeDomain(tt.domainType, nil, nil); !bytes.Equal(got, tt.domain) {
|
||||
t.Errorf("wanted domain version: %d, got: %d", tt.domain, got)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
if !bytes.Equal(domain(tt.domainType, params.BeaconConfig().ZeroHash[:]), tt.domain) {
|
||||
t.Errorf("wanted domain version: %d, got: %d", tt.domain, domain(tt.domainType, params.BeaconConfig().ZeroHash[:]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSigningRoot_Compatibility(t *testing.T) {
|
||||
parRoot := [32]byte{'A'}
|
||||
stateRoot := [32]byte{'B'}
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: 20,
|
||||
ProposerIndex: 20,
|
||||
ParentRoot: parRoot[:],
|
||||
StateRoot: stateRoot[:],
|
||||
Body: ðpb.BeaconBlockBody{},
|
||||
}
|
||||
root, err := ComputeSigningRoot(blk, params.BeaconConfig().DomainBeaconProposer[:])
|
||||
require.NoError(t, err)
|
||||
newRoot, err := signingData(func() ([32]byte, error) {
|
||||
return stateutil.BlockRoot(blk)
|
||||
}, params.BeaconConfig().DomainBeaconProposer[:])
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, root, newRoot, "Wanted root of %#x but got %#x", root, newRoot)
|
||||
}
|
||||
|
||||
func TestComputeForkDigest_OK(t *testing.T) {
|
||||
tests := []struct {
|
||||
version []byte
|
||||
@@ -51,7 +68,7 @@ func TestComputeForkDigest_OK(t *testing.T) {
|
||||
{version: []byte{'b', 'w', 'r', 't'}, root: [32]byte{'r', 'd', 'c'}, result: [4]byte{0x83, 0x34, 0x38, 0x88}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
digest, err := helpers.ComputeForkDigest(tt.version, tt.root[:])
|
||||
digest, err := ComputeForkDigest(tt.version, tt.root[:])
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.result, digest, "Wanted domain version: %#x, got: %#x", digest, tt.result)
|
||||
}
|
||||
@@ -75,8 +92,8 @@ func TestFuzzverifySigningRoot_10000(t *testing.T) {
|
||||
fuzzer.Fuzz(&p)
|
||||
fuzzer.Fuzz(&s)
|
||||
fuzzer.Fuzz(&d)
|
||||
err := helpers.VerifySigningRoot(state, pubkey[:], sig[:], domain[:])
|
||||
err = helpers.VerifySigningRoot(state, p, s, d)
|
||||
err := VerifySigningRoot(state, pubkey[:], sig[:], domain[:])
|
||||
err = VerifySigningRoot(state, p, s, d)
|
||||
_ = err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -731,7 +731,7 @@ func TestIsIsEligibleForActivation(t *testing.T) {
|
||||
true},
|
||||
{"Not yet finalized",
|
||||
ðpb.Validator{ActivationEligibilityEpoch: 1, ActivationEpoch: params.BeaconConfig().FarFutureEpoch},
|
||||
&pb.BeaconState{FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}},
|
||||
&pb.BeaconState{FinalizedCheckpoint: ðpb.Checkpoint{}},
|
||||
false},
|
||||
{"Incorrect activation epoch",
|
||||
ðpb.Validator{ActivationEligibilityEpoch: 1},
|
||||
|
||||
@@ -38,6 +38,7 @@ go_library(
|
||||
"//shared/trieutil: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",
|
||||
"@io_opencensus_go//trace:go_default_library",
|
||||
],
|
||||
@@ -69,7 +70,6 @@ go_test(
|
||||
"//shared/attestationutil:go_default_library",
|
||||
"//shared/benchutil:go_default_library",
|
||||
"//shared/bls:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
@@ -100,7 +101,7 @@ func BenchmarkHashTreeRoot_FullState(b *testing.B) {
|
||||
b.N = 50
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := beaconState.HashTreeRoot(context.Background()); err != nil {
|
||||
if _, err := ssz.HashTreeRoot(beaconState); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
@@ -69,7 +70,7 @@ func GenesisBeaconState(deposits []*ethpb.Deposit, genesisTime uint64, eth1Data
|
||||
if deposit == nil || deposit.Data == nil {
|
||||
return nil, fmt.Errorf("nil deposit or deposit with nil data cannot be processed: %v", deposit)
|
||||
}
|
||||
hash, err := deposit.Data.HashTreeRoot()
|
||||
hash, err := ssz.HashTreeRoot(deposit.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
@@ -17,7 +18,6 @@ import (
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/attestationutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
@@ -52,8 +52,7 @@ func TestExecuteStateTransition_FullProcess(t *testing.T) {
|
||||
|
||||
eth1Data := ðpb.Eth1Data{
|
||||
DepositCount: 100,
|
||||
DepositRoot: bytesutil.PadTo([]byte{2}, 32),
|
||||
BlockHash: make([]byte, 32),
|
||||
DepositRoot: []byte{2},
|
||||
}
|
||||
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch-1))
|
||||
e := beaconState.Eth1Data()
|
||||
@@ -77,12 +76,17 @@ func TestExecuteStateTransition_FullProcess(t *testing.T) {
|
||||
require.NoError(t, nextSlotState.SetSlot(beaconState.Slot()+1))
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(nextSlotState)
|
||||
require.NoError(t, err)
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.ProposerIndex = proposerIdx
|
||||
block.Block.Slot = beaconState.Slot() + 1
|
||||
block.Block.ParentRoot = parentRoot[:]
|
||||
block.Block.Body.RandaoReveal = randaoReveal
|
||||
block.Block.Body.Eth1Data = eth1Data
|
||||
block := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
ProposerIndex: proposerIdx,
|
||||
Slot: beaconState.Slot() + 1,
|
||||
ParentRoot: parentRoot[:],
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
RandaoReveal: randaoReveal,
|
||||
Eth1Data: eth1Data,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
stateRoot, err := state.CalculateStateRoot(context.Background(), beaconState, block)
|
||||
require.NoError(t, err)
|
||||
@@ -110,8 +114,7 @@ func TestExecuteStateTransitionNoVerify_FullProcess(t *testing.T) {
|
||||
|
||||
eth1Data := ðpb.Eth1Data{
|
||||
DepositCount: 100,
|
||||
DepositRoot: bytesutil.PadTo([]byte{2}, 32),
|
||||
BlockHash: make([]byte, 32),
|
||||
DepositRoot: []byte{2},
|
||||
}
|
||||
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch-1))
|
||||
e := beaconState.Eth1Data()
|
||||
@@ -132,12 +135,17 @@ func TestExecuteStateTransitionNoVerify_FullProcess(t *testing.T) {
|
||||
require.NoError(t, nextSlotState.SetSlot(beaconState.Slot()+1))
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(nextSlotState)
|
||||
require.NoError(t, err)
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.ProposerIndex = proposerIdx
|
||||
block.Block.Slot = beaconState.Slot() + 1
|
||||
block.Block.ParentRoot = parentRoot[:]
|
||||
block.Block.Body.RandaoReveal = randaoReveal
|
||||
block.Block.Body.Eth1Data = eth1Data
|
||||
block := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
ProposerIndex: proposerIdx,
|
||||
Slot: beaconState.Slot() + 1,
|
||||
ParentRoot: parentRoot[:],
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
RandaoReveal: randaoReveal,
|
||||
Eth1Data: eth1Data,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
stateRoot, err := state.CalculateStateRoot(context.Background(), beaconState, block)
|
||||
require.NoError(t, err)
|
||||
@@ -161,24 +169,8 @@ func TestProcessBlock_IncorrectProposerSlashing(t *testing.T) {
|
||||
block, err := testutil.GenerateFullBlock(beaconState, privKeys, nil, 1)
|
||||
require.NoError(t, err)
|
||||
slashing := ðpb.ProposerSlashing{
|
||||
Header_1: ðpb.SignedBeaconBlockHeader{
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
Slot: params.BeaconConfig().SlotsPerEpoch,
|
||||
ParentRoot: make([]byte, 32),
|
||||
StateRoot: make([]byte, 32),
|
||||
BodyRoot: make([]byte, 32),
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
Header_2: ðpb.SignedBeaconBlockHeader{
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
Slot: params.BeaconConfig().SlotsPerEpoch * 2,
|
||||
ParentRoot: make([]byte, 32),
|
||||
StateRoot: make([]byte, 32),
|
||||
BodyRoot: make([]byte, 32),
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
Header_1: ðpb.SignedBeaconBlockHeader{Header: ðpb.BeaconBlockHeader{Slot: params.BeaconConfig().SlotsPerEpoch}},
|
||||
Header_2: ðpb.SignedBeaconBlockHeader{Header: ðpb.BeaconBlockHeader{Slot: params.BeaconConfig().SlotsPerEpoch * 2}},
|
||||
}
|
||||
block.Block.Body.ProposerSlashings = []*ethpb.ProposerSlashing{slashing}
|
||||
|
||||
@@ -201,12 +193,10 @@ func TestProcessBlock_IncorrectProcessBlockAttestations(t *testing.T) {
|
||||
|
||||
att := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
Source: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
AggregationBits: bitfield.NewBitlist(3),
|
||||
Signature: bls.RandKey().Sign([]byte("foo")).Marshal(),
|
||||
}
|
||||
|
||||
block, err := testutil.GenerateFullBlock(beaconState, privKeys, nil, 1)
|
||||
@@ -222,7 +212,7 @@ func TestProcessBlock_IncorrectProcessBlockAttestations(t *testing.T) {
|
||||
beaconState, err = state.ProcessSlots(context.Background(), beaconState, 1)
|
||||
require.NoError(t, err)
|
||||
|
||||
want := "could not verify attestations"
|
||||
want := "could not process block attestations"
|
||||
_, err = state.ProcessBlock(context.Background(), beaconState, block)
|
||||
assert.ErrorContains(t, want, err)
|
||||
}
|
||||
@@ -236,21 +226,15 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
ProposerIndex: 3,
|
||||
Slot: 1,
|
||||
ParentRoot: make([]byte, 32),
|
||||
StateRoot: make([]byte, 32),
|
||||
BodyRoot: make([]byte, 32),
|
||||
},
|
||||
Signature: bytesutil.PadTo([]byte("A"), 96),
|
||||
Signature: []byte("A"),
|
||||
},
|
||||
Header_2: ðpb.SignedBeaconBlockHeader{
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
ProposerIndex: 3,
|
||||
Slot: 1,
|
||||
ParentRoot: make([]byte, 32),
|
||||
StateRoot: make([]byte, 32),
|
||||
BodyRoot: make([]byte, 32),
|
||||
},
|
||||
Signature: bytesutil.PadTo([]byte("B"), 96),
|
||||
Signature: []byte("B"),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -258,19 +242,17 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
|
||||
{
|
||||
Attestation_1: ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Epoch: 0},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
AttestingIndices: []uint64{0, 1},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
Attestation_2: ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Epoch: 1},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
AttestingIndices: []uint64{0, 1},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -281,7 +263,7 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
|
||||
require.NoError(t, beaconState.SetBlockRoots(blockRoots))
|
||||
blockAtt := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Epoch: 0},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: []byte("hello-world")},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0xC0, 0xC0, 0xC0, 0xC0, 0x01},
|
||||
@@ -298,24 +280,23 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
|
||||
Slot: genesisBlock.Block.Slot,
|
||||
ParentRoot: genesisBlock.Block.ParentRoot,
|
||||
BodyRoot: bodyRoot[:],
|
||||
StateRoot: make([]byte, 32),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
parentRoot, err := beaconState.LatestBlockHeader().HashTreeRoot()
|
||||
parentRoot, err := ssz.HashTreeRoot(beaconState.LatestBlockHeader())
|
||||
require.NoError(t, err)
|
||||
block := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
ParentRoot: parentRoot[:],
|
||||
Slot: 1,
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
RandaoReveal: make([]byte, 96),
|
||||
RandaoReveal: []byte{},
|
||||
ProposerSlashings: proposerSlashings,
|
||||
AttesterSlashings: attesterSlashings,
|
||||
Attestations: attestations,
|
||||
VoluntaryExits: exits,
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: bytesutil.PadTo([]byte{2}, 32),
|
||||
BlockHash: bytesutil.PadTo([]byte{3}, 32),
|
||||
DepositRoot: []byte{2},
|
||||
BlockHash: []byte{3},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -362,9 +343,7 @@ func createFullBlockWithOperations(t *testing.T) (*beaconstate.BeaconState,
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
ProposerIndex: proposerSlashIdx,
|
||||
Slot: 1,
|
||||
StateRoot: bytesutil.PadTo([]byte("A"), 32),
|
||||
ParentRoot: make([]byte, 32),
|
||||
BodyRoot: make([]byte, 32),
|
||||
StateRoot: []byte("A"),
|
||||
},
|
||||
}
|
||||
header1.Signature, err = helpers.ComputeDomainAndSign(beaconState, currentEpoch, header1.Header, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerSlashIdx])
|
||||
@@ -374,9 +353,7 @@ func createFullBlockWithOperations(t *testing.T) (*beaconstate.BeaconState,
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
ProposerIndex: proposerSlashIdx,
|
||||
Slot: 1,
|
||||
StateRoot: bytesutil.PadTo([]byte("B"), 32),
|
||||
ParentRoot: make([]byte, 32),
|
||||
BodyRoot: make([]byte, 32),
|
||||
StateRoot: []byte("B"),
|
||||
},
|
||||
}
|
||||
header2.Signature, err = helpers.ComputeDomainAndSign(beaconState, helpers.CurrentEpoch(beaconState), header2.Header, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerSlashIdx])
|
||||
@@ -395,12 +372,9 @@ func createFullBlockWithOperations(t *testing.T) (*beaconstate.BeaconState,
|
||||
mockRoot2 := [32]byte{'A'}
|
||||
att1 := ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot2[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
},
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot2[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0}},
|
||||
AttestingIndices: []uint64{0, 1},
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
domain, err := helpers.Domain(beaconState.Fork(), currentEpoch, params.BeaconConfig().DomainBeaconAttester, beaconState.GenesisValidatorRoot())
|
||||
require.NoError(t, err)
|
||||
@@ -414,12 +388,9 @@ func createFullBlockWithOperations(t *testing.T) (*beaconstate.BeaconState,
|
||||
mockRoot3 := [32]byte{'B'}
|
||||
att2 := ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot3[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
},
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot3[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0}},
|
||||
AttestingIndices: []uint64{0, 1},
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
|
||||
hashTreeRoot, err = helpers.ComputeSigningRoot(att2.Data, domain)
|
||||
@@ -446,15 +417,13 @@ func createFullBlockWithOperations(t *testing.T) (*beaconstate.BeaconState,
|
||||
aggBits.SetBitAt(0, true)
|
||||
blockAtt := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: beaconState.Slot(),
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Epoch: helpers.CurrentEpoch(beaconState), Root: make([]byte, 32)},
|
||||
Slot: beaconState.Slot(),
|
||||
Target: ðpb.Checkpoint{Epoch: helpers.CurrentEpoch(beaconState)},
|
||||
Source: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: mockRoot[:],
|
||||
}},
|
||||
AggregationBits: aggBits,
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
|
||||
committee, err := helpers.BeaconCommitteeFromState(beaconState, blockAtt.Data.Slot, blockAtt.Data.CommitteeIndex)
|
||||
@@ -498,15 +467,14 @@ func createFullBlockWithOperations(t *testing.T) (*beaconstate.BeaconState,
|
||||
Slot: beaconState.Slot() + 1,
|
||||
ProposerIndex: proposerIndex,
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
Graffiti: make([]byte, 32),
|
||||
RandaoReveal: randaoReveal,
|
||||
ProposerSlashings: proposerSlashings,
|
||||
AttesterSlashings: attesterSlashings,
|
||||
Attestations: []*ethpb.Attestation{blockAtt},
|
||||
VoluntaryExits: []*ethpb.SignedVoluntaryExit{exit},
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: bytesutil.PadTo([]byte{2}, 32),
|
||||
BlockHash: bytesutil.PadTo([]byte{3}, 32),
|
||||
DepositRoot: []byte{2},
|
||||
BlockHash: []byte{3},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -554,7 +522,7 @@ func TestProcessBlockNoVerify_PassesProcessingConditions(t *testing.T) {
|
||||
func TestProcessEpochPrecompute_CanProcess(t *testing.T) {
|
||||
epoch := uint64(1)
|
||||
|
||||
atts := []*pb.PendingAttestation{{Data: ðpb.AttestationData{Target: ðpb.Checkpoint{Root: make([]byte, 32)}}, InclusionDelay: 1}}
|
||||
atts := []*pb.PendingAttestation{{Data: ðpb.AttestationData{Target: ðpb.Checkpoint{}}, InclusionDelay: 1}}
|
||||
slashing := make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector)
|
||||
base := &pb.BeaconState{
|
||||
Slot: epoch*params.BeaconConfig().SlotsPerEpoch + 1,
|
||||
@@ -562,9 +530,9 @@ func TestProcessEpochPrecompute_CanProcess(t *testing.T) {
|
||||
Slashings: slashing,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
CurrentEpochAttestations: atts,
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{},
|
||||
JustificationBits: bitfield.Bitvector4{0x00},
|
||||
CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
CurrentJustifiedCheckpoint: ðpb.Checkpoint{},
|
||||
Validators: []*ethpb.Validator{},
|
||||
}
|
||||
s, err := beaconstate.InitializeFromProto(base)
|
||||
@@ -624,14 +592,14 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
|
||||
ProposerIndex: 1,
|
||||
Slot: 0,
|
||||
},
|
||||
Signature: bytesutil.PadTo([]byte("A"), 96),
|
||||
Signature: []byte("A"),
|
||||
},
|
||||
Header_2: ðpb.SignedBeaconBlockHeader{
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
ProposerIndex: 1,
|
||||
Slot: 0,
|
||||
},
|
||||
Signature: bytesutil.PadTo([]byte("B"), 96),
|
||||
Signature: []byte("B"),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -640,19 +608,11 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
|
||||
attesterSlashings := []*ethpb.AttesterSlashing{
|
||||
{
|
||||
Attestation_1: ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
},
|
||||
Data: ðpb.AttestationData{},
|
||||
AttestingIndices: []uint64{2, 3},
|
||||
},
|
||||
Attestation_2: ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
},
|
||||
Data: ðpb.AttestationData{},
|
||||
AttestingIndices: []uint64{2, 3},
|
||||
},
|
||||
},
|
||||
@@ -665,7 +625,7 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
|
||||
Amount: params.BeaconConfig().MaxEffectiveBalance,
|
||||
},
|
||||
}
|
||||
leaf, err := deposit.Data.HashTreeRoot()
|
||||
leaf, err := ssz.HashTreeRoot(deposit.Data)
|
||||
require.NoError(b, err)
|
||||
depositTrie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, int(params.BeaconConfig().DepositContractTreeDepth))
|
||||
require.NoError(b, err, "Could not generate trie")
|
||||
@@ -688,7 +648,7 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
|
||||
ObjectRoot: buf,
|
||||
Domain: domain,
|
||||
}
|
||||
root, err = ctr.HashTreeRoot()
|
||||
root, err = ssz.HashTreeRoot(ctr)
|
||||
require.NoError(b, err)
|
||||
epochSignature := priv.Sign(root[:])
|
||||
|
||||
@@ -765,13 +725,10 @@ func TestProcessBlk_AttsBasedOnValidatorCount(t *testing.T) {
|
||||
for i := 0; i < len(atts); i++ {
|
||||
att := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
},
|
||||
Slot: 1,
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0}},
|
||||
AggregationBits: aggBits,
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
|
||||
committee, err := helpers.BeaconCommitteeFromState(s, att.Data.Slot, att.Data.CommitteeIndex)
|
||||
@@ -807,12 +764,18 @@ func TestProcessBlk_AttsBasedOnValidatorCount(t *testing.T) {
|
||||
require.NoError(t, nextSlotState.SetSlot(s.Slot()+1))
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(nextSlotState)
|
||||
require.NoError(t, err)
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.ProposerIndex = proposerIdx
|
||||
blk.Block.Slot = s.Slot() + 1
|
||||
blk.Block.ParentRoot = parentRoot[:]
|
||||
blk.Block.Body.RandaoReveal = epochSignature
|
||||
blk.Block.Body.Attestations = atts
|
||||
blk := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
ProposerIndex: proposerIdx,
|
||||
Slot: s.Slot() + 1,
|
||||
ParentRoot: parentRoot[:],
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
Eth1Data: ðpb.Eth1Data{},
|
||||
RandaoReveal: epochSignature,
|
||||
Attestations: atts,
|
||||
},
|
||||
},
|
||||
}
|
||||
sig, err := testutil.BlockSignature(s, blk.Block, privKeys)
|
||||
require.NoError(t, err)
|
||||
blk.Signature = sig.Marshal()
|
||||
|
||||
@@ -18,7 +18,6 @@ go_library(
|
||||
"//shared/featureconfig:go_default_library",
|
||||
"//shared/traceutil:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_golang_protobuf//jsonpb:go_default_library_gen",
|
||||
"@com_github_golang_protobuf//proto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
|
||||
fssz "github.com/ferranbt/fastssz"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
@@ -56,13 +55,7 @@ func (e Exporter) publish(ctx context.Context, topic string, msg proto.Message)
|
||||
return err
|
||||
}
|
||||
|
||||
var key [32]byte
|
||||
var err error
|
||||
if v, ok := msg.(fssz.HashRoot); ok {
|
||||
key, err = v.HashTreeRoot()
|
||||
} else {
|
||||
key, err = ssz.HashTreeRoot(msg)
|
||||
}
|
||||
key, err := ssz.HashTreeRoot(msg)
|
||||
if err != nil {
|
||||
traceutil.AnnotateError(span, err)
|
||||
return err
|
||||
|
||||
@@ -50,6 +50,7 @@ go_library(
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_prysmaticlabs_prombbolt//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@io_etcd_go_bbolt//:go_default_library",
|
||||
@@ -93,6 +94,7 @@ go_test(
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
|
||||
"@io_etcd_go_bbolt//:go_default_library",
|
||||
],
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
@@ -15,8 +16,7 @@ func TestStore_Backup(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
head := testutil.NewBeaconBlock()
|
||||
head.Block.Slot = 5000
|
||||
head := ð.SignedBeaconBlock{Block: ð.BeaconBlock{Slot: 5000}}
|
||||
|
||||
require.NoError(t, db.SaveBlock(ctx, head))
|
||||
root, err := stateutil.BlockRoot(head.Block)
|
||||
|
||||
@@ -22,14 +22,19 @@ func TestStore_SaveBlock_NoDuplicates(t *testing.T) {
|
||||
slot := uint64(20)
|
||||
ctx := context.Background()
|
||||
// First we save a previous block to ensure the cache max size is reached.
|
||||
prevBlock := testutil.NewBeaconBlock()
|
||||
prevBlock.Block.Slot = slot - 1
|
||||
prevBlock.Block.ParentRoot = bytesutil.PadTo([]byte{1, 2, 3}, 32)
|
||||
prevBlock := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
Slot: slot - 1,
|
||||
ParentRoot: bytesutil.PadTo([]byte{1, 2, 3}, 32),
|
||||
},
|
||||
}
|
||||
require.NoError(t, db.SaveBlock(ctx, prevBlock))
|
||||
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.Slot = slot
|
||||
block.Block.ParentRoot = bytesutil.PadTo([]byte{1, 2, 3}, 32)
|
||||
block := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
Slot: slot,
|
||||
ParentRoot: bytesutil.PadTo([]byte{1, 2, 3}, 32),
|
||||
},
|
||||
}
|
||||
// Even with a full cache, saving new blocks should not cause
|
||||
// duplicated blocks in the DB.
|
||||
for i := 0; i < 100; i++ {
|
||||
@@ -46,11 +51,12 @@ func TestStore_SaveBlock_NoDuplicates(t *testing.T) {
|
||||
func TestStore_BlocksCRUD(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.Slot = 20
|
||||
block.Block.ParentRoot = bytesutil.PadTo([]byte{1, 2, 3}, 32)
|
||||
|
||||
block := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
Slot: 20,
|
||||
ParentRoot: bytesutil.PadTo([]byte{1, 2, 3}, 32),
|
||||
},
|
||||
}
|
||||
blockRoot, err := stateutil.BlockRoot(block.Block)
|
||||
require.NoError(t, err)
|
||||
retrievedBlock, err := db.Block(ctx, blockRoot)
|
||||
@@ -366,10 +372,12 @@ func TestStore_SaveBlocks_HasCachedBlocks(t *testing.T) {
|
||||
|
||||
b := make([]*ethpb.SignedBeaconBlock, 500)
|
||||
for i := 0; i < 500; i++ {
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.ParentRoot = bytesutil.PadTo([]byte("parent"), 32)
|
||||
blk.Block.Slot = uint64(i)
|
||||
b[i] = blk
|
||||
b[i] = ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
ParentRoot: bytesutil.PadTo([]byte("parent"), 32),
|
||||
Slot: uint64(i),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
require.NoError(t, db.SaveBlock(ctx, b[0]))
|
||||
|
||||
@@ -39,9 +39,12 @@ func TestStore_FinalizedCheckpoint_CanSaveRetrieve(t *testing.T) {
|
||||
genesis := bytesutil.ToBytes32([]byte{'G', 'E', 'N', 'E', 'S', 'I', 'S'})
|
||||
require.NoError(t, db.SaveGenesisBlockRoot(ctx, genesis))
|
||||
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.ParentRoot = genesis[:]
|
||||
blk.Block.Slot = 40
|
||||
blk := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
ParentRoot: genesis[:],
|
||||
Slot: 40,
|
||||
},
|
||||
}
|
||||
|
||||
root, err := stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -55,8 +55,7 @@ func TestStore_IsFinalizedBlockGenesis(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.Slot = 0
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 0}}
|
||||
root, err := stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveBlock(ctx, blk))
|
||||
@@ -140,9 +139,12 @@ func makeBlocks(t *testing.T, i, n uint64, previousRoot [32]byte) []*ethpb.Signe
|
||||
for j := i; j < n+i; j++ {
|
||||
parentRoot := make([]byte, 32)
|
||||
copy(parentRoot, previousRoot[:])
|
||||
blocks[j-i] = testutil.NewBeaconBlock()
|
||||
blocks[j-i].Block.Slot = j + 1
|
||||
blocks[j-i].Block.ParentRoot = parentRoot
|
||||
blocks[j-i] = ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
Slot: j + 1,
|
||||
ParentRoot: parentRoot,
|
||||
},
|
||||
}
|
||||
var err error
|
||||
previousRoot, err = stateutil.BlockRoot(blocks[j-i].Block)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
@@ -53,9 +53,8 @@ func Test_migrateArchivedIndex(t *testing.T) {
|
||||
if err := tx.Bucket(archivedRootBucket).Put(bytesutil.Uint64ToBytesLittleEndian(2048), []byte("foo")); err != nil {
|
||||
return err
|
||||
}
|
||||
sb := testutil.NewBeaconBlock()
|
||||
sb.Block.Slot = 2048
|
||||
b, err := encode(context.Background(), sb)
|
||||
|
||||
b, err := encode(context.Background(), ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 2048}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
@@ -41,7 +42,7 @@ func (kv *Store) HasVoluntaryExit(ctx context.Context, exitRoot [32]byte) bool {
|
||||
func (kv *Store) SaveVoluntaryExit(ctx context.Context, exit *ethpb.VoluntaryExit) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveVoluntaryExit")
|
||||
defer span.End()
|
||||
exitRoot, err := exit.HashTreeRoot()
|
||||
exitRoot, err := ssz.HashTreeRoot(exit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
@@ -16,7 +17,7 @@ func TestStore_VoluntaryExits_CRUD(t *testing.T) {
|
||||
exit := ðpb.VoluntaryExit{
|
||||
Epoch: 5,
|
||||
}
|
||||
exitRoot, err := exit.HashTreeRoot()
|
||||
exitRoot, err := ssz.HashTreeRoot(exit)
|
||||
require.NoError(t, err)
|
||||
retrieved, err := db.VoluntaryExit(ctx, exitRoot)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
@@ -41,7 +42,7 @@ func (kv *Store) HasProposerSlashing(ctx context.Context, slashingRoot [32]byte)
|
||||
func (kv *Store) SaveProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveProposerSlashing")
|
||||
defer span.End()
|
||||
slashingRoot, err := slashing.HashTreeRoot()
|
||||
slashingRoot, err := ssz.HashTreeRoot(slashing)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -110,7 +111,7 @@ func (kv *Store) HasAttesterSlashing(ctx context.Context, slashingRoot [32]byte)
|
||||
func (kv *Store) SaveAttesterSlashing(ctx context.Context, slashing *ethpb.AttesterSlashing) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveAttesterSlashing")
|
||||
defer span.End()
|
||||
slashingRoot, err := slashing.HashTreeRoot()
|
||||
slashingRoot, err := ssz.HashTreeRoot(slashing)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
@@ -33,7 +34,7 @@ func TestStore_ProposerSlashing_CRUD(t *testing.T) {
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
}
|
||||
slashingRoot, err := prop.HashTreeRoot()
|
||||
slashingRoot, err := ssz.HashTreeRoot(prop)
|
||||
require.NoError(t, err)
|
||||
retrieved, err := db.ProposerSlashing(ctx, slashingRoot)
|
||||
require.NoError(t, err)
|
||||
@@ -82,7 +83,7 @@ func TestStore_AttesterSlashing_CRUD(t *testing.T) {
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
}
|
||||
slashingRoot, err := att.HashTreeRoot()
|
||||
slashingRoot, err := ssz.HashTreeRoot(att)
|
||||
require.NoError(t, err)
|
||||
retrieved, err := db.AttesterSlashing(ctx, slashingRoot)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -132,10 +132,12 @@ func TestStore_DeleteFinalizedState(t *testing.T) {
|
||||
genesis := bytesutil.ToBytes32([]byte{'G', 'E', 'N', 'E', 'S', 'I', 'S'})
|
||||
require.NoError(t, db.SaveGenesisBlockRoot(ctx, genesis))
|
||||
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.ParentRoot = genesis[:]
|
||||
blk.Block.Slot = 100
|
||||
|
||||
blk := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
ParentRoot: genesis[:],
|
||||
Slot: 100,
|
||||
},
|
||||
}
|
||||
require.NoError(t, db.SaveBlock(ctx, blk))
|
||||
|
||||
finalizedBlockRoot, err := stateutil.BlockRoot(blk.Block)
|
||||
@@ -157,9 +159,12 @@ func TestStore_DeleteHeadState(t *testing.T) {
|
||||
genesis := bytesutil.ToBytes32([]byte{'G', 'E', 'N', 'E', 'S', 'I', 'S'})
|
||||
require.NoError(t, db.SaveGenesisBlockRoot(ctx, genesis))
|
||||
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.ParentRoot = genesis[:]
|
||||
blk.Block.Slot = 100
|
||||
blk := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
ParentRoot: genesis[:],
|
||||
Slot: 100,
|
||||
},
|
||||
}
|
||||
require.NoError(t, db.SaveBlock(ctx, blk))
|
||||
|
||||
headBlockRoot, err := stateutil.BlockRoot(blk.Block)
|
||||
@@ -175,8 +180,7 @@ func TestStore_DeleteHeadState(t *testing.T) {
|
||||
func TestStore_SaveDeleteState_CanGetHighestBelow(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 1
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
r, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveBlock(context.Background(), b))
|
||||
@@ -185,7 +189,7 @@ func TestStore_SaveDeleteState_CanGetHighestBelow(t *testing.T) {
|
||||
s0 := st.InnerStateUnsafe()
|
||||
require.NoError(t, db.SaveState(context.Background(), st, r))
|
||||
|
||||
b.Block.Slot = 100
|
||||
b = ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 100}}
|
||||
r1, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveBlock(context.Background(), b))
|
||||
@@ -194,7 +198,7 @@ func TestStore_SaveDeleteState_CanGetHighestBelow(t *testing.T) {
|
||||
s1 := st.InnerStateUnsafe()
|
||||
require.NoError(t, db.SaveState(context.Background(), st, r1))
|
||||
|
||||
b.Block.Slot = 1000
|
||||
b = ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1000}}
|
||||
r2, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveBlock(context.Background(), b))
|
||||
@@ -225,8 +229,7 @@ func TestStore_GenesisState_CanGetHighestBelow(t *testing.T) {
|
||||
require.NoError(t, db.SaveGenesisBlockRoot(context.Background(), genesisRoot))
|
||||
require.NoError(t, db.SaveState(context.Background(), genesisState, genesisRoot))
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 1
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
r, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveBlock(context.Background(), b))
|
||||
|
||||
@@ -42,7 +42,6 @@ go_test(
|
||||
"//shared/bls:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_patrickmn_go_cache//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
fssz "github.com/ferranbt/fastssz"
|
||||
c "github.com/patrickmn/go-cache"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
@@ -19,14 +18,14 @@ func TestKV_Aggregated_AggregateUnaggregatedAttestations(t *testing.T) {
|
||||
priv := bls.RandKey()
|
||||
sig1 := priv.Sign([]byte{'a'})
|
||||
sig2 := priv.Sign([]byte{'b'})
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig1.Marshal()}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1010}, Signature: sig1.Marshal()}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1100}, Signature: sig1.Marshal()}
|
||||
att4 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig2.Marshal()}
|
||||
att5 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig1.Marshal()}
|
||||
att6 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1010}, Signature: sig1.Marshal()}
|
||||
att7 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1100}, Signature: sig1.Marshal()}
|
||||
att8 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig2.Marshal()}
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig1.Marshal()}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1010}, Signature: sig1.Marshal()}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1100}, Signature: sig1.Marshal()}
|
||||
att4 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig2.Marshal()}
|
||||
att5 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig1.Marshal()}
|
||||
att6 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1010}, Signature: sig1.Marshal()}
|
||||
att7 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1100}, Signature: sig1.Marshal()}
|
||||
att8 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig2.Marshal()}
|
||||
atts := []*ethpb.Attestation{att1, att2, att3, att4, att5, att6, att7, att8}
|
||||
if err := cache.SaveUnaggregatedAttestations(atts); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -61,11 +60,7 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) {
|
||||
{
|
||||
name: "not aggregated",
|
||||
att: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
}, AggregationBits: bitfield.Bitlist{0b10100}},
|
||||
Data: ðpb.AttestationData{}, AggregationBits: bitfield.Bitlist{0b10100}},
|
||||
wantErrString: "attestation is not aggregated",
|
||||
},
|
||||
{
|
||||
@@ -76,19 +71,15 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) {
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b10111},
|
||||
},
|
||||
wantErrString: "could not tree hash attestation: " + fssz.ErrBytesLength.Error(),
|
||||
wantErrString: "could not tree hash attestation: incorrect fixed bytes marshalling",
|
||||
},
|
||||
{
|
||||
name: "already seen",
|
||||
att: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 100,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 100,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b11101001},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
count: 0,
|
||||
},
|
||||
@@ -96,22 +87,15 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) {
|
||||
name: "normal save",
|
||||
att: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1101},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
count: 1,
|
||||
},
|
||||
}
|
||||
r, err := hashFn(ðpb.AttestationData{
|
||||
Slot: 100,
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Slot: 100,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -152,9 +136,9 @@ func TestKV_Aggregated_SaveAggregatedAttestations(t *testing.T) {
|
||||
{
|
||||
name: "no duplicates",
|
||||
atts: []*ethpb.Attestation{
|
||||
{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}},
|
||||
{Data: ðpb.AttestationData{Slot: 1},
|
||||
AggregationBits: bitfield.Bitlist{0b1101}},
|
||||
{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}},
|
||||
{Data: ðpb.AttestationData{Slot: 1},
|
||||
AggregationBits: bitfield.Bitlist{0b1101}},
|
||||
},
|
||||
count: 1,
|
||||
@@ -185,9 +169,9 @@ func TestKV_Aggregated_SaveAggregatedAttestations(t *testing.T) {
|
||||
func TestKV_Aggregated_AggregatedAttestations(t *testing.T) {
|
||||
cache := NewAttCaches()
|
||||
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
atts := []*ethpb.Attestation{att1, att2, att3}
|
||||
|
||||
for _, att := range atts {
|
||||
@@ -209,7 +193,7 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) {
|
||||
if err := cache.DeleteAggregatedAttestation(nil); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
att := ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10101}, Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}}
|
||||
att := ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10101}}
|
||||
if err := cache.DeleteAggregatedAttestation(att); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -217,7 +201,7 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) {
|
||||
|
||||
t.Run("non aggregated attestation", func(t *testing.T) {
|
||||
cache := NewAttCaches()
|
||||
att := ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1001}, Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}}
|
||||
att := ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1001}, Data: ðpb.AttestationData{Slot: 2}}
|
||||
err := cache.DeleteAggregatedAttestation(att)
|
||||
wantErr := "attestation is not aggregated"
|
||||
if err == nil || err.Error() != wantErr {
|
||||
@@ -230,11 +214,12 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) {
|
||||
att := ðpb.Attestation{
|
||||
AggregationBits: bitfield.Bitlist{0b1111},
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 2,
|
||||
Slot: 2,
|
||||
BeaconBlockRoot: []byte{0b0},
|
||||
},
|
||||
}
|
||||
err := cache.DeleteAggregatedAttestation(att)
|
||||
wantErr := "could not tree hash attestation data: " + fssz.ErrBytesLength.Error()
|
||||
wantErr := "could not tree hash attestation data: incorrect fixed bytes marshalling"
|
||||
if err == nil || err.Error() != wantErr {
|
||||
t.Errorf("Did not receive wanted error, want: %q, got: %v", wantErr, err)
|
||||
}
|
||||
@@ -242,7 +227,7 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) {
|
||||
|
||||
t.Run("nonexistent attestation", func(t *testing.T) {
|
||||
cache := NewAttCaches()
|
||||
att := ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1111}, Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}}
|
||||
att := ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1111}, Data: ðpb.AttestationData{Slot: 2}}
|
||||
if err := cache.DeleteAggregatedAttestation(att); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -250,10 +235,10 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) {
|
||||
|
||||
t.Run("non-filtered deletion", func(t *testing.T) {
|
||||
cache := NewAttCaches()
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att4 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b10101}}
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att4 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b10101}}
|
||||
atts := []*ethpb.Attestation{att1, att2, att3, att4}
|
||||
if err := cache.SaveAggregatedAttestations(atts); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -273,10 +258,10 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) {
|
||||
|
||||
t.Run("filtered deletion", func(t *testing.T) {
|
||||
cache := NewAttCaches()
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110111}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110100}}
|
||||
att4 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110101}}
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b110101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110111}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110100}}
|
||||
att4 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110101}}
|
||||
atts := []*ethpb.Attestation{att1, att2, att3, att4}
|
||||
if err := cache.SaveAggregatedAttestations(atts); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -313,23 +298,14 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
|
||||
{
|
||||
name: "nil attestation data",
|
||||
input: ðpb.Attestation{
|
||||
AggregationBits: bitfield.Bitlist{0b1111},
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1111}},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "empty cache aggregated",
|
||||
input: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1111}},
|
||||
want: false,
|
||||
@@ -338,10 +314,7 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
|
||||
name: "empty cache unaggregated",
|
||||
input: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1001}},
|
||||
want: false,
|
||||
@@ -350,19 +323,13 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
|
||||
name: "single attestation in cache with exact match",
|
||||
existing: []*ethpb.Attestation{{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1111}},
|
||||
},
|
||||
input: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1111}},
|
||||
want: true,
|
||||
@@ -371,19 +338,13 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
|
||||
name: "single attestation in cache with subset aggregation",
|
||||
existing: []*ethpb.Attestation{{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1111}},
|
||||
},
|
||||
input: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1110}},
|
||||
want: true,
|
||||
@@ -392,19 +353,13 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
|
||||
name: "single attestation in cache with superset aggregation",
|
||||
existing: []*ethpb.Attestation{{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1110}},
|
||||
},
|
||||
input: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1111}},
|
||||
want: false,
|
||||
@@ -414,29 +369,20 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
|
||||
existing: []*ethpb.Attestation{
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1111000},
|
||||
},
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1100111},
|
||||
},
|
||||
},
|
||||
input: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1100000}},
|
||||
want: true,
|
||||
@@ -446,29 +392,20 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
|
||||
existing: []*ethpb.Attestation{
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1111000},
|
||||
},
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1100111},
|
||||
},
|
||||
},
|
||||
input: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1111111}},
|
||||
want: false,
|
||||
@@ -478,29 +415,20 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
|
||||
existing: []*ethpb.Attestation{
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 2,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 2,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1111000},
|
||||
},
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 3,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 3,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1100111},
|
||||
},
|
||||
},
|
||||
input: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1111111}},
|
||||
want: false,
|
||||
@@ -510,20 +438,14 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
|
||||
existing: []*ethpb.Attestation{
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 2,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 2,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1111000},
|
||||
},
|
||||
},
|
||||
input: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 2,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 2,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1111},
|
||||
},
|
||||
@@ -538,10 +460,6 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if tt.input != nil && tt.input.Signature == nil {
|
||||
tt.input.Signature = make([]byte, 96)
|
||||
}
|
||||
|
||||
result, err := cache.HasAggregatedAttestation(tt.input)
|
||||
require.NoError(t, err)
|
||||
if result != tt.want {
|
||||
@@ -566,8 +484,8 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
|
||||
func TestKV_Aggregated_DuplicateAggregatedAttestations(t *testing.T) {
|
||||
cache := NewAttCaches()
|
||||
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1111}}
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1111}}
|
||||
atts := []*ethpb.Attestation{att1, att2}
|
||||
|
||||
for _, att := range atts {
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
func TestKV_BlockAttestation_CanSaveRetrieve(t *testing.T) {
|
||||
cache := NewAttCaches()
|
||||
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
atts := []*ethpb.Attestation{att1, att2, att3}
|
||||
|
||||
for _, att := range atts {
|
||||
@@ -35,9 +35,9 @@ func TestKV_BlockAttestation_CanSaveRetrieve(t *testing.T) {
|
||||
func TestKV_BlockAttestation_CanDelete(t *testing.T) {
|
||||
cache := NewAttCaches()
|
||||
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
atts := []*ethpb.Attestation{att1, att2, att3}
|
||||
|
||||
for _, att := range atts {
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
func TestKV_Forkchoice_CanSaveRetrieve(t *testing.T) {
|
||||
cache := NewAttCaches()
|
||||
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}, Signature: make([]byte, 96)}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}, Signature: make([]byte, 96)}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}, Signature: make([]byte, 96)}
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
atts := []*ethpb.Attestation{att1, att2, att3}
|
||||
|
||||
for _, att := range atts {
|
||||
@@ -35,9 +35,9 @@ func TestKV_Forkchoice_CanSaveRetrieve(t *testing.T) {
|
||||
func TestKV_Forkchoice_CanDelete(t *testing.T) {
|
||||
cache := NewAttCaches()
|
||||
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}, Signature: make([]byte, 96)}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}, Signature: make([]byte, 96)}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}, Signature: make([]byte, 96)}
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
atts := []*ethpb.Attestation{att1, att2, att3}
|
||||
|
||||
for _, att := range atts {
|
||||
|
||||
@@ -10,25 +10,21 @@ import (
|
||||
|
||||
func TestAttCaches_hasSeenBit(t *testing.T) {
|
||||
c := NewAttCaches()
|
||||
d := ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
}
|
||||
seenA1 := ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000011}, Signature: make([]byte, 96)}
|
||||
seenA2 := ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11100000}, Signature: make([]byte, 96)}
|
||||
d := ðpb.AttestationData{}
|
||||
seenA1 := ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000011}}
|
||||
seenA2 := ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11100000}}
|
||||
require.NoError(t, c.insertSeenBit(seenA1))
|
||||
require.NoError(t, c.insertSeenBit(seenA2))
|
||||
tests := []struct {
|
||||
att *ethpb.Attestation
|
||||
want bool
|
||||
}{
|
||||
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000000}, Signature: make([]byte, 96)}, want: true},
|
||||
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000001}, Signature: make([]byte, 96)}, want: true},
|
||||
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11100000}, Signature: make([]byte, 96)}, want: true},
|
||||
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000011}, Signature: make([]byte, 96)}, want: true},
|
||||
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b00001000}, Signature: make([]byte, 96)}, want: false},
|
||||
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11110111}, Signature: make([]byte, 96)}, want: false},
|
||||
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000000}}, want: true},
|
||||
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000001}}, want: true},
|
||||
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11100000}}, want: true},
|
||||
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000011}}, want: true},
|
||||
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b00001000}}, want: false},
|
||||
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11110111}}, want: false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
got, err := c.hasSeenBit(tt.att)
|
||||
|
||||
@@ -3,7 +3,6 @@ package kv
|
||||
import (
|
||||
"testing"
|
||||
|
||||
fssz "github.com/ferranbt/fastssz"
|
||||
c "github.com/patrickmn/go-cache"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
@@ -24,7 +23,7 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "already aggregated",
|
||||
att: ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10101}, Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}},
|
||||
att: ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10101}},
|
||||
wantErrString: "attestation is aggregated",
|
||||
},
|
||||
{
|
||||
@@ -34,33 +33,31 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) {
|
||||
BeaconBlockRoot: []byte{0b0},
|
||||
},
|
||||
},
|
||||
wantErrString: fssz.ErrBytesLength.Error(),
|
||||
wantErrString: "incorrect fixed bytes marshalling",
|
||||
},
|
||||
{
|
||||
name: "normal save",
|
||||
att: ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b0001}, Data: ðpb.AttestationData{BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}},
|
||||
name: "normal save",
|
||||
att: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 100,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b0001},
|
||||
},
|
||||
count: 1,
|
||||
},
|
||||
{
|
||||
name: "already seen",
|
||||
att: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 100,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slot: 100,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b10000001},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
count: 0,
|
||||
},
|
||||
}
|
||||
r, err := hashFn(ðpb.AttestationData{
|
||||
Slot: 100,
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Slot: 100,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -72,10 +69,6 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) {
|
||||
t.Errorf("Invalid start pool, atts: %d", len(cache.unAggregatedAtt))
|
||||
}
|
||||
|
||||
if tt.att != nil && tt.att.Signature == nil {
|
||||
tt.att.Signature = make([]byte, 96)
|
||||
}
|
||||
|
||||
err := cache.SaveUnaggregatedAttestation(tt.att)
|
||||
if tt.wantErrString != "" && (err == nil || err.Error() != tt.wantErrString) {
|
||||
t.Errorf("Did not receive wanted error, want: %q, got: %v", tt.wantErrString, err)
|
||||
@@ -105,18 +98,18 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestations(t *testing.T) {
|
||||
{
|
||||
name: "unaggregated only",
|
||||
atts: []*ethpb.Attestation{
|
||||
{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, Signature: make([]byte, 96)},
|
||||
{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, Signature: make([]byte, 96)},
|
||||
{Data: ðpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, Signature: make([]byte, 96)},
|
||||
{Data: ðpb.AttestationData{Slot: 1}},
|
||||
{Data: ðpb.AttestationData{Slot: 2}},
|
||||
{Data: ðpb.AttestationData{Slot: 3}},
|
||||
},
|
||||
count: 3,
|
||||
},
|
||||
{
|
||||
name: "has aggregated",
|
||||
atts: []*ethpb.Attestation{
|
||||
{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, Signature: make([]byte, 96)},
|
||||
{AggregationBits: bitfield.Bitlist{0b1111}, Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, Signature: make([]byte, 96)},
|
||||
{Data: ðpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, Signature: make([]byte, 96)},
|
||||
{Data: ðpb.AttestationData{Slot: 1}},
|
||||
{AggregationBits: bitfield.Bitlist{0b1111}, Data: ðpb.AttestationData{Slot: 2}},
|
||||
{Data: ðpb.AttestationData{Slot: 3}},
|
||||
},
|
||||
wantErrString: "attestation is aggregated",
|
||||
count: 1,
|
||||
@@ -157,7 +150,7 @@ func TestKV_Unaggregated_DeleteUnaggregatedAttestation(t *testing.T) {
|
||||
|
||||
t.Run("aggregated attestation", func(t *testing.T) {
|
||||
cache := NewAttCaches()
|
||||
att := ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1111}, Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, Signature: make([]byte, 96)}
|
||||
att := ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1111}, Data: ðpb.AttestationData{Slot: 2}}
|
||||
err := cache.DeleteUnaggregatedAttestation(att)
|
||||
wantErr := "attestation is aggregated"
|
||||
if err == nil || err.Error() != wantErr {
|
||||
@@ -167,9 +160,9 @@ func TestKV_Unaggregated_DeleteUnaggregatedAttestation(t *testing.T) {
|
||||
|
||||
t.Run("successful deletion", func(t *testing.T) {
|
||||
cache := NewAttCaches()
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b101}, Signature: make([]byte, 96)}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110}, Signature: make([]byte, 96)}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110}, Signature: make([]byte, 96)}
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b110}}
|
||||
atts := []*ethpb.Attestation{att1, att2, att3}
|
||||
if err := cache.SaveUnaggregatedAttestations(atts); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -188,9 +181,9 @@ func TestKV_Unaggregated_DeleteUnaggregatedAttestation(t *testing.T) {
|
||||
func TestKV_Unaggregated_UnaggregatedAttestationsBySlotIndex(t *testing.T) {
|
||||
cache := NewAttCaches()
|
||||
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, CommitteeIndex: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b101}, Signature: make([]byte, 96)}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, CommitteeIndex: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110}, Signature: make([]byte, 96)}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, CommitteeIndex: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110}, Signature: make([]byte, 96)}
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, CommitteeIndex: 1}, AggregationBits: bitfield.Bitlist{0b101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, CommitteeIndex: 2}, AggregationBits: bitfield.Bitlist{0b110}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, CommitteeIndex: 1}, AggregationBits: bitfield.Bitlist{0b110}}
|
||||
atts := []*ethpb.Attestation{att1, att2, att3}
|
||||
|
||||
for _, att := range atts {
|
||||
|
||||
@@ -2,7 +2,6 @@ package attestations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
@@ -263,34 +262,21 @@ func TestSeenAttestations_PresentInCache(t *testing.T) {
|
||||
s, err := NewService(context.Background(), &Config{Pool: NewPool()})
|
||||
require.NoError(t, err)
|
||||
|
||||
ad1 := ðpb.AttestationData{
|
||||
Slot: 0,
|
||||
CommitteeIndex: 0,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
}
|
||||
att1 := ðpb.Attestation{Data: ad1, Signature: []byte{'A'}, AggregationBits: bitfield.Bitlist{0x13} /* 0b00010011 */}
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{}, Signature: []byte{'A'}, AggregationBits: bitfield.Bitlist{0x13} /* 0b00010011 */}
|
||||
got, err := s.seen(att1)
|
||||
require.NoError(t, err)
|
||||
if got {
|
||||
t.Error("Wanted false, got true")
|
||||
}
|
||||
|
||||
att2 := ðpb.Attestation{Data: ad1, Signature: []byte{'A'}, AggregationBits: bitfield.Bitlist{0x17} /* 0b00010111 */}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{}, Signature: []byte{'A'}, AggregationBits: bitfield.Bitlist{0x17} /* 0b00010111 */}
|
||||
got, err = s.seen(att2)
|
||||
require.NoError(t, err)
|
||||
if got {
|
||||
t.Error("Wanted false, got true")
|
||||
}
|
||||
|
||||
att3 := ðpb.Attestation{Data: ad1, Signature: []byte{'A'}, AggregationBits: bitfield.Bitlist{0x17} /* 0b00010111 */}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{}, Signature: []byte{'A'}, AggregationBits: bitfield.Bitlist{0x17} /* 0b00010111 */}
|
||||
got, err = s.seen(att3)
|
||||
require.NoError(t, err)
|
||||
if !got {
|
||||
@@ -299,34 +285,6 @@ func TestSeenAttestations_PresentInCache(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestService_seen(t *testing.T) {
|
||||
ad1 := ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
CommitteeIndex: 0,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
}
|
||||
|
||||
ad2 := ðpb.AttestationData{
|
||||
Slot: 2,
|
||||
CommitteeIndex: 0,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
}
|
||||
|
||||
// Attestation are checked in order of this list.
|
||||
tests := []struct {
|
||||
att *ethpb.Attestation
|
||||
@@ -335,42 +293,42 @@ func TestService_seen(t *testing.T) {
|
||||
{
|
||||
att: ðpb.Attestation{
|
||||
AggregationBits: bitfield.Bitlist{0b11011},
|
||||
Data: ad1,
|
||||
Data: ðpb.AttestationData{Slot: 1},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
att: ðpb.Attestation{
|
||||
AggregationBits: bitfield.Bitlist{0b11011},
|
||||
Data: ad1,
|
||||
Data: ðpb.AttestationData{Slot: 1},
|
||||
},
|
||||
want: true, // Exact same attestation should return true
|
||||
},
|
||||
{
|
||||
att: ðpb.Attestation{
|
||||
AggregationBits: bitfield.Bitlist{0b10101},
|
||||
Data: ad1,
|
||||
Data: ðpb.AttestationData{Slot: 1},
|
||||
},
|
||||
want: false, // Haven't seen the bit at index 2 yet.
|
||||
},
|
||||
{
|
||||
att: ðpb.Attestation{
|
||||
AggregationBits: bitfield.Bitlist{0b11111},
|
||||
Data: ad1,
|
||||
Data: ðpb.AttestationData{Slot: 1},
|
||||
},
|
||||
want: true, // We've full committee at this point.
|
||||
},
|
||||
{
|
||||
att: ðpb.Attestation{
|
||||
AggregationBits: bitfield.Bitlist{0b11111},
|
||||
Data: ad2,
|
||||
Data: ðpb.AttestationData{Slot: 2},
|
||||
},
|
||||
want: false, // Different root is different bitlist.
|
||||
},
|
||||
{
|
||||
att: ðpb.Attestation{
|
||||
AggregationBits: bitfield.Bitlist{0b11111001},
|
||||
Data: ad1,
|
||||
Data: ðpb.AttestationData{Slot: 1},
|
||||
},
|
||||
want: false, // Sanity test that an attestation of different lengths does not panic.
|
||||
},
|
||||
@@ -379,11 +337,9 @@ func TestService_seen(t *testing.T) {
|
||||
s, err := NewService(context.Background(), &Config{Pool: NewPool()})
|
||||
require.NoError(t, err)
|
||||
|
||||
for i, tt := range tests {
|
||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||
got, err := s.seen(tt.att)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
for _, tt := range tests {
|
||||
got, err := s.seen(tt.att)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.want, got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,37 +24,9 @@ func TestPruneExpired_Ticker(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
ad1 := ðpb.AttestationData{
|
||||
Slot: 0,
|
||||
CommitteeIndex: 0,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
}
|
||||
|
||||
ad2 := ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
CommitteeIndex: 0,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
}
|
||||
|
||||
atts := []*ethpb.Attestation{
|
||||
{Data: ad1, AggregationBits: bitfield.Bitlist{0b1000, 0b1}, Signature: make([]byte, 96)},
|
||||
{Data: ad2, AggregationBits: bitfield.Bitlist{0b1000, 0b1}, Signature: make([]byte, 96)},
|
||||
{Data: ðpb.AttestationData{Slot: 0}, AggregationBits: bitfield.Bitlist{0b1000, 0b1}},
|
||||
{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1000, 0b1}},
|
||||
}
|
||||
if err := s.pool.SaveUnaggregatedAttestations(atts); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -63,8 +35,8 @@ func TestPruneExpired_Ticker(t *testing.T) {
|
||||
t.Fatalf("Unexpected number of attestations: %d", s.pool.UnaggregatedAttestationCount())
|
||||
}
|
||||
atts = []*ethpb.Attestation{
|
||||
{Data: ad1, AggregationBits: bitfield.Bitlist{0b1101, 0b1}, Signature: make([]byte, 96)},
|
||||
{Data: ad2, AggregationBits: bitfield.Bitlist{0b1101, 0b1}, Signature: make([]byte, 96)},
|
||||
{Data: ðpb.AttestationData{Slot: 0}, AggregationBits: bitfield.Bitlist{0b1101, 0b1}},
|
||||
{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101, 0b1}},
|
||||
}
|
||||
if err := s.pool.SaveAggregatedAttestations(atts); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -115,38 +87,10 @@ func TestPruneExpired_PruneExpiredAtts(t *testing.T) {
|
||||
s, err := NewService(context.Background(), &Config{Pool: NewPool()})
|
||||
require.NoError(t, err)
|
||||
|
||||
ad1 := ðpb.AttestationData{
|
||||
Slot: 0,
|
||||
CommitteeIndex: 0,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
}
|
||||
|
||||
ad2 := ðpb.AttestationData{
|
||||
Slot: 0,
|
||||
CommitteeIndex: 0,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
}
|
||||
|
||||
att1 := ðpb.Attestation{Data: ad1, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att2 := ðpb.Attestation{Data: ad1, AggregationBits: bitfield.Bitlist{0b1111}}
|
||||
att3 := ðpb.Attestation{Data: ad2, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att4 := ðpb.Attestation{Data: ad2, AggregationBits: bitfield.Bitlist{0b1110}}
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 0}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 0}, AggregationBits: bitfield.Bitlist{0b1111}}
|
||||
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}
|
||||
att4 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1110}}
|
||||
atts := []*ethpb.Attestation{att1, att2, att3, att4}
|
||||
if err := s.pool.SaveAggregatedAttestations(atts); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -118,7 +118,6 @@ go_test(
|
||||
"//beacon-chain/p2p/testing:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//proto/testing:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/featureconfig:go_default_library",
|
||||
"//shared/iputils:go_default_library",
|
||||
"//shared/p2putils:go_default_library",
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
||||
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/iputils"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
@@ -218,7 +217,7 @@ func TestHostIsResolved(t *testing.T) {
|
||||
HostDNS: exampleHost,
|
||||
},
|
||||
genesisTime: time.Now(),
|
||||
genesisValidatorsRoot: bytesutil.PadTo([]byte{'A'}, 32),
|
||||
genesisValidatorsRoot: []byte{'A'},
|
||||
}
|
||||
ip, key := createAddrAndPrivKey(t)
|
||||
list, err := s.createListener(ip, key)
|
||||
|
||||
@@ -115,9 +115,7 @@ func TestStartDiscV5_DiscoverPeersWithSubnets(t *testing.T) {
|
||||
// Update ENR of a peer.
|
||||
testService := &Service{
|
||||
dv5Listener: listeners[0],
|
||||
metaData: &pb.MetaData{
|
||||
Attnets: bitfield.NewBitvector64(),
|
||||
},
|
||||
metaData: &pb.MetaData{},
|
||||
}
|
||||
cache.SubnetIDs.AddAttesterSubnetID(0, 10)
|
||||
testService.RefreshENR()
|
||||
|
||||
@@ -42,6 +42,7 @@ go_library(
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto: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",
|
||||
"@io_k8s_client_go//tools/cache:go_default_library",
|
||||
"@io_opencensus_go//trace:go_default_library",
|
||||
@@ -84,6 +85,7 @@ go_test(
|
||||
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//core/types: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",
|
||||
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
||||
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"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"
|
||||
@@ -81,9 +81,9 @@ func TestProcessDeposit_InvalidPublicKey(t *testing.T) {
|
||||
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
require.NoError(t, err)
|
||||
deposits[0].Data.PublicKey = bytesutil.PadTo([]byte("junk"), 48)
|
||||
deposits[0].Data.PublicKey = []byte("junk")
|
||||
|
||||
leaf, err := deposits[0].Data.HashTreeRoot()
|
||||
leaf, err := ssz.HashTreeRoot(deposits[0].Data)
|
||||
require.NoError(t, err, "Could not hash deposit")
|
||||
|
||||
trie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, int(params.BeaconConfig().DepositContractTreeDepth))
|
||||
@@ -121,7 +121,7 @@ func TestProcessDeposit_InvalidSignature(t *testing.T) {
|
||||
copy(fakeSig[:], []byte{'F', 'A', 'K', 'E'})
|
||||
deposits[0].Data.Signature = fakeSig[:]
|
||||
|
||||
leaf, err := deposits[0].Data.HashTreeRoot()
|
||||
leaf, err := ssz.HashTreeRoot(deposits[0].Data)
|
||||
require.NoError(t, err, "Could not hash deposit")
|
||||
|
||||
trie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, int(params.BeaconConfig().DepositContractTreeDepth))
|
||||
@@ -186,8 +186,7 @@ func TestProcessDeposit_IncompleteDeposit(t *testing.T) {
|
||||
deposit := ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
Amount: params.BeaconConfig().EffectiveBalanceIncrement, // incomplete deposit
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("testing"), 32),
|
||||
Signature: bytesutil.PadTo([]byte("test"), 96),
|
||||
WithdrawalCredentials: []byte("testing"),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -210,7 +209,7 @@ func TestProcessDeposit_IncompleteDeposit(t *testing.T) {
|
||||
}
|
||||
proof, err := trie.MerkleProof(0)
|
||||
require.NoError(t, err)
|
||||
dataRoot, err := deposit.Data.HashTreeRoot()
|
||||
dataRoot, err := ssz.HashTreeRoot(deposit.Data)
|
||||
require.NoError(t, err)
|
||||
deposit.Proof = proof
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
gethTypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/pkg/errors"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
||||
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
@@ -134,7 +135,7 @@ func (s *Service) ProcessDepositLog(ctx context.Context, depositLog gethTypes.Lo
|
||||
WithdrawalCredentials: withdrawalCredentials,
|
||||
}
|
||||
|
||||
depositHash, err := depositData.HashTreeRoot()
|
||||
depositHash, err := ssz.HashTreeRoot(depositData)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Unable to determine hashed value of deposit")
|
||||
}
|
||||
|
||||
@@ -111,6 +111,7 @@ go_test(
|
||||
"@com_github_golang_mock//gomock: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",
|
||||
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
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/core/helpers"
|
||||
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
@@ -54,7 +55,7 @@ func TestServer_ListAssignments_NoResults(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
st := testutil.NewBeaconState()
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -95,7 +96,7 @@ func TestServer_ListAssignments_Pagination_InputOutOfRange(t *testing.T) {
|
||||
headState, err := db.HeadState(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -140,30 +141,29 @@ func TestServer_ListAssignments_Pagination_DefaultPageSize_NoArchive(t *testing.
|
||||
validators := make([]*ethpb.Validator, 0, count)
|
||||
for i := 0; i < count; i++ {
|
||||
pubKey := make([]byte, params.BeaconConfig().BLSPubkeyLength)
|
||||
withdrawalCred := make([]byte, 32)
|
||||
binary.LittleEndian.PutUint64(pubKey, uint64(i))
|
||||
// Mark the validators with index divisible by 3 inactive.
|
||||
if i%3 == 0 {
|
||||
validators = append(validators, ðpb.Validator{
|
||||
PublicKey: pubKey,
|
||||
WithdrawalCredentials: withdrawalCred,
|
||||
ExitEpoch: 0,
|
||||
ActivationEpoch: 0,
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
PublicKey: pubKey,
|
||||
ExitEpoch: 0,
|
||||
ActivationEpoch: 0,
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
})
|
||||
} else {
|
||||
validators = append(validators, ðpb.Validator{
|
||||
PublicKey: pubKey,
|
||||
WithdrawalCredentials: withdrawalCred,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
ActivationEpoch: 0,
|
||||
PublicKey: pubKey,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
ActivationEpoch: 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
blk := testutil.NewBeaconBlock().Block
|
||||
blockRoot, err := blk.HashTreeRoot()
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: 0,
|
||||
}
|
||||
blockRoot, err := ssz.HashTreeRoot(blk)
|
||||
require.NoError(t, err)
|
||||
|
||||
s := testutil.NewBeaconState()
|
||||
@@ -221,20 +221,16 @@ func TestServer_ListAssignments_FilterPubkeysIndices_NoPagination(t *testing.T)
|
||||
ctx := context.Background()
|
||||
count := 100
|
||||
validators := make([]*ethpb.Validator, 0, count)
|
||||
withdrawCreds := make([]byte, 32)
|
||||
for i := 0; i < count; i++ {
|
||||
pubKey := make([]byte, params.BeaconConfig().BLSPubkeyLength)
|
||||
binary.LittleEndian.PutUint64(pubKey, uint64(i))
|
||||
val := ðpb.Validator{
|
||||
PublicKey: pubKey,
|
||||
WithdrawalCredentials: withdrawCreds,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
}
|
||||
validators = append(validators, val)
|
||||
validators = append(validators, ðpb.Validator{PublicKey: pubKey, ExitEpoch: params.BeaconConfig().FarFutureEpoch})
|
||||
}
|
||||
|
||||
blk := testutil.NewBeaconBlock().Block
|
||||
blockRoot, err := blk.HashTreeRoot()
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: 0,
|
||||
}
|
||||
blockRoot, err := ssz.HashTreeRoot(blk)
|
||||
require.NoError(t, err)
|
||||
s := testutil.NewBeaconState()
|
||||
require.NoError(t, s.SetValidators(validators))
|
||||
@@ -289,20 +285,16 @@ func TestServer_ListAssignments_CanFilterPubkeysIndices_WithPagination(t *testin
|
||||
ctx := context.Background()
|
||||
count := 100
|
||||
validators := make([]*ethpb.Validator, 0, count)
|
||||
withdrawCred := make([]byte, 32)
|
||||
for i := 0; i < count; i++ {
|
||||
pubKey := make([]byte, params.BeaconConfig().BLSPubkeyLength)
|
||||
binary.LittleEndian.PutUint64(pubKey, uint64(i))
|
||||
val := ðpb.Validator{
|
||||
PublicKey: pubKey,
|
||||
WithdrawalCredentials: withdrawCred,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
}
|
||||
validators = append(validators, val)
|
||||
validators = append(validators, ðpb.Validator{PublicKey: pubKey, ExitEpoch: params.BeaconConfig().FarFutureEpoch})
|
||||
}
|
||||
|
||||
blk := testutil.NewBeaconBlock().Block
|
||||
blockRoot, err := blk.HashTreeRoot()
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: 0,
|
||||
}
|
||||
blockRoot, err := ssz.HashTreeRoot(blk)
|
||||
require.NoError(t, err)
|
||||
s := testutil.NewBeaconState()
|
||||
require.NoError(t, s.SetValidators(validators))
|
||||
|
||||
@@ -88,8 +88,7 @@ func TestServer_ListAttestations_Genesis(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
att := ðpb.Attestation{
|
||||
AggregationBits: bitfield.NewBitlist(0),
|
||||
Signature: make([]byte, 96),
|
||||
Signature: make([]byte, 96),
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 2,
|
||||
CommitteeIndex: 1,
|
||||
@@ -100,12 +99,17 @@ func TestServer_ListAttestations_Genesis(t *testing.T) {
|
||||
}
|
||||
|
||||
parentRoot := [32]byte{1, 2, 3}
|
||||
signedBlock := testutil.NewBeaconBlock()
|
||||
signedBlock.Block.ParentRoot = bytesutil.PadTo(parentRoot[:], 32)
|
||||
signedBlock.Block.Body.Attestations = []*ethpb.Attestation{att}
|
||||
root, err := stateutil.BlockRoot(signedBlock.Block)
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{
|
||||
Slot: 0,
|
||||
ParentRoot: parentRoot[:],
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
Attestations: []*ethpb.Attestation{att},
|
||||
},
|
||||
},
|
||||
}
|
||||
root, err := stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveBlock(ctx, signedBlock))
|
||||
require.NoError(t, db.SaveBlock(ctx, blk))
|
||||
require.NoError(t, db.SaveGenesisBlockRoot(ctx, root))
|
||||
wanted := ðpb.ListAttestationsResponse{
|
||||
Attestations: []*ethpb.Attestation{att},
|
||||
@@ -125,7 +129,7 @@ func TestServer_ListAttestations_Genesis(t *testing.T) {
|
||||
|
||||
// Should throw an error if there is more than 1 block
|
||||
// for the genesis slot.
|
||||
require.NoError(t, db.SaveBlock(ctx, signedBlock))
|
||||
require.NoError(t, db.SaveBlock(ctx, blk))
|
||||
if _, err := bs.ListAttestations(ctx, ðpb.ListAttestationsRequest{
|
||||
QueryFilter: ðpb.ListAttestationsRequest_GenesisEpoch{
|
||||
GenesisEpoch: true,
|
||||
@@ -142,17 +146,23 @@ func TestServer_ListAttestations_NoPagination(t *testing.T) {
|
||||
count := uint64(8)
|
||||
atts := make([]*ethpb.Attestation, 0, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
blockExample := testutil.NewBeaconBlock()
|
||||
blockExample.Block.Body.Attestations = []*ethpb.Attestation{
|
||||
{
|
||||
Signature: make([]byte, 96),
|
||||
Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("root"), 32)},
|
||||
Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("root"), 32)},
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32),
|
||||
Slot: i,
|
||||
blockExample := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
Slot: i,
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
Attestations: []*ethpb.Attestation{
|
||||
{
|
||||
Signature: make([]byte, 96),
|
||||
Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("root"), 32)},
|
||||
Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("root"), 32)},
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32),
|
||||
Slot: i,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
},
|
||||
},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
},
|
||||
}
|
||||
require.NoError(t, db.SaveBlock(ctx, blockExample))
|
||||
@@ -206,14 +216,8 @@ func TestServer_ListAttestations_FiltersCorrectly(t *testing.T) {
|
||||
Slot: 3,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
Signature: bytesutil.PadTo([]byte("sig"), 96),
|
||||
},
|
||||
},
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: make([]byte, 32),
|
||||
},
|
||||
Graffiti: make([]byte, 32),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -240,14 +244,8 @@ func TestServer_ListAttestations_FiltersCorrectly(t *testing.T) {
|
||||
Slot: 4 + params.BeaconConfig().SlotsPerEpoch,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
Signature: bytesutil.PadTo([]byte("sig"), 96),
|
||||
},
|
||||
},
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: make([]byte, 32),
|
||||
},
|
||||
Graffiti: make([]byte, 32),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -274,14 +272,8 @@ func TestServer_ListAttestations_FiltersCorrectly(t *testing.T) {
|
||||
Slot: 4,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
Signature: bytesutil.PadTo([]byte("sig"), 96),
|
||||
},
|
||||
},
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: make([]byte, 32),
|
||||
},
|
||||
Graffiti: make([]byte, 32),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -313,19 +305,24 @@ func TestServer_ListAttestations_Pagination_CustomPageParameters(t *testing.T) {
|
||||
atts := make([]*ethpb.Attestation, 0, count)
|
||||
for i := uint64(0); i < params.BeaconConfig().SlotsPerEpoch; i++ {
|
||||
for s := uint64(0); s < 4; s++ {
|
||||
blockExample := testutil.NewBeaconBlock()
|
||||
blockExample.Block.Slot = i
|
||||
blockExample.Block.Body.Attestations = []*ethpb.Attestation{
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
CommitteeIndex: s,
|
||||
Slot: i,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
blockExample := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
Slot: i,
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
Attestations: []*ethpb.Attestation{
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
CommitteeIndex: s,
|
||||
Slot: i,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
}
|
||||
require.NoError(t, db.SaveBlock(ctx, blockExample))
|
||||
@@ -427,24 +424,17 @@ func TestServer_ListAttestations_Pagination_OutOfRange(t *testing.T) {
|
||||
ParentRoot: make([]byte, 32),
|
||||
StateRoot: make([]byte, 32),
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
Graffiti: make([]byte, 32),
|
||||
RandaoReveal: make([]byte, 96),
|
||||
Attestations: []*ethpb.Attestation{
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32),
|
||||
Slot: i,
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
},
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: make([]byte, 32),
|
||||
},
|
||||
Graffiti: make([]byte, 32),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -486,17 +476,26 @@ func TestServer_ListAttestations_Pagination_DefaultPageSize(t *testing.T) {
|
||||
count := uint64(params.BeaconConfig().DefaultPageSize)
|
||||
atts := make([]*ethpb.Attestation, 0, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
blockExample := testutil.NewBeaconBlock()
|
||||
blockExample.Block.Body.Attestations = []*ethpb.Attestation{
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32),
|
||||
Target: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("root"), 32)},
|
||||
Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("root"), 32)},
|
||||
Slot: i,
|
||||
blockExample := ðpb.SignedBeaconBlock{
|
||||
Signature: make([]byte, 96),
|
||||
Block: ðpb.BeaconBlock{
|
||||
ParentRoot: make([]byte, 32),
|
||||
StateRoot: make([]byte, 32),
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
RandaoReveal: make([]byte, 96),
|
||||
Attestations: []*ethpb.Attestation{
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32),
|
||||
Target: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("root"), 32)},
|
||||
Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("root"), 32)},
|
||||
Slot: i,
|
||||
},
|
||||
Signature: bytesutil.PadTo([]byte("root"), 96),
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
},
|
||||
},
|
||||
},
|
||||
Signature: bytesutil.PadTo([]byte("root"), 96),
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
},
|
||||
}
|
||||
require.NoError(t, db.SaveBlock(ctx, blockExample))
|
||||
@@ -570,22 +569,27 @@ func TestServer_ListIndexedAttestations_GenesisEpoch(t *testing.T) {
|
||||
} else {
|
||||
targetRoot = targetRoot2
|
||||
}
|
||||
blockExample := testutil.NewBeaconBlock()
|
||||
blockExample.Block.Body.Attestations = []*ethpb.Attestation{
|
||||
{
|
||||
Signature: make([]byte, 96),
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{
|
||||
Root: targetRoot[:],
|
||||
blockExample := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
Attestations: []*ethpb.Attestation{
|
||||
{
|
||||
Signature: make([]byte, 96),
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Target: ðpb.Checkpoint{
|
||||
Root: targetRoot[:],
|
||||
},
|
||||
Source: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Slot: i,
|
||||
CommitteeIndex: 0,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
},
|
||||
},
|
||||
Source: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Slot: i,
|
||||
CommitteeIndex: 0,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
},
|
||||
}
|
||||
require.NoError(t, db.SaveBlock(ctx, blockExample))
|
||||
@@ -753,36 +757,9 @@ func TestServer_AttestationPool_Pagination_OutOfRange(t *testing.T) {
|
||||
}
|
||||
|
||||
atts := []*ethpb.Attestation{
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte{1}, 32),
|
||||
Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{1}, 32)},
|
||||
Target: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{1}, 32)},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1101},
|
||||
Signature: bytesutil.PadTo([]byte{1}, 96),
|
||||
},
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 2,
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte{2}, 32),
|
||||
Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{2}, 32)},
|
||||
Target: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{2}, 32)},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1101},
|
||||
Signature: bytesutil.PadTo([]byte{2}, 96),
|
||||
},
|
||||
{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 3,
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte{3}, 32),
|
||||
Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{3}, 32)},
|
||||
Target: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{3}, 32)},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b1101},
|
||||
Signature: bytesutil.PadTo([]byte{3}, 96),
|
||||
},
|
||||
{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}},
|
||||
{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}},
|
||||
{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}},
|
||||
}
|
||||
require.NoError(t, bs.AttestationsPool.SaveAggregatedAttestations(atts))
|
||||
|
||||
@@ -803,9 +780,10 @@ func TestServer_AttestationPool_Pagination_DefaultPageSize(t *testing.T) {
|
||||
|
||||
atts := make([]*ethpb.Attestation, params.BeaconConfig().DefaultPageSize+1)
|
||||
for i := 0; i < len(atts); i++ {
|
||||
att := testutil.NewAttestation()
|
||||
att.Data.Slot = uint64(i)
|
||||
atts[i] = att
|
||||
atts[i] = ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{Slot: uint64(i)},
|
||||
AggregationBits: bitfield.Bitlist{0b1101},
|
||||
}
|
||||
}
|
||||
require.NoError(t, bs.AttestationsPool.SaveAggregatedAttestations(atts))
|
||||
|
||||
@@ -825,9 +803,10 @@ func TestServer_AttestationPool_Pagination_CustomPageSize(t *testing.T) {
|
||||
numAtts := 100
|
||||
atts := make([]*ethpb.Attestation, numAtts)
|
||||
for i := 0; i < len(atts); i++ {
|
||||
att := testutil.NewAttestation()
|
||||
att.Data.Slot = uint64(i)
|
||||
atts[i] = att
|
||||
atts[i] = ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{Slot: uint64(i)},
|
||||
AggregationBits: bitfield.Bitlist{0b1101},
|
||||
}
|
||||
}
|
||||
require.NoError(t, bs.AttestationsPool.SaveAggregatedAttestations(atts))
|
||||
tests := []struct {
|
||||
@@ -914,7 +893,7 @@ func TestServer_StreamIndexedAttestations_OK(t *testing.T) {
|
||||
|
||||
numValidators := 64
|
||||
headState, privKeys := testutil.DeterministicGenesisState(t, uint64(numValidators))
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -957,10 +936,6 @@ func TestServer_StreamIndexedAttestations_OK(t *testing.T) {
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32),
|
||||
Slot: i,
|
||||
Source: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: gRoot[:],
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: gRoot[:],
|
||||
@@ -1084,9 +1059,9 @@ func TestServer_StreamAttestations_OnSlotTick(t *testing.T) {
|
||||
}
|
||||
|
||||
atts := []*ethpb.Attestation{
|
||||
{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}},
|
||||
{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}},
|
||||
{Data: ðpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}},
|
||||
{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}},
|
||||
{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}},
|
||||
{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}},
|
||||
}
|
||||
|
||||
mockStream := mock.NewMockBeaconChain_StreamAttestationsServer(ctrl)
|
||||
|
||||
@@ -123,8 +123,12 @@ func TestServer_ListBlocks_Genesis_MultiBlocks(t *testing.T) {
|
||||
}
|
||||
// Should return the proper genesis block if it exists.
|
||||
parentRoot := [32]byte{1, 2, 3}
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.ParentRoot = parentRoot[:]
|
||||
blk := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
Slot: 0,
|
||||
ParentRoot: parentRoot[:],
|
||||
},
|
||||
}
|
||||
root, err := stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveBlock(ctx, blk))
|
||||
@@ -134,8 +138,11 @@ func TestServer_ListBlocks_Genesis_MultiBlocks(t *testing.T) {
|
||||
blks := make([]*ethpb.SignedBeaconBlock, count)
|
||||
blkContainers := make([]*ethpb.BeaconBlockContainer, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = i
|
||||
b := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
Slot: i,
|
||||
},
|
||||
}
|
||||
root, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
blks[i] = b
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestServer_ListBeaconCommittees_CurrentEpoch(t *testing.T) {
|
||||
GenesisTimeFetcher: m,
|
||||
StateGen: stategen.New(db, sc),
|
||||
}
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -89,7 +89,7 @@ func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) {
|
||||
require.NoError(t, headState.SetRandaoMixes(mixes))
|
||||
require.NoError(t, headState.SetSlot(params.BeaconConfig().SlotsPerEpoch*2))
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -159,7 +159,7 @@ func TestRetrieveCommitteesForRoot(t *testing.T) {
|
||||
GenesisTimeFetcher: m,
|
||||
StateGen: stategen.New(db, sc),
|
||||
}
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
ptypes "github.com/gogo/protobuf/types"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
|
||||
@@ -102,7 +103,7 @@ func TestServer_ListValidatorBalances_NoResults(t *testing.T) {
|
||||
}
|
||||
|
||||
headState := testutil.NewBeaconState()
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -152,7 +153,7 @@ func TestServer_ListValidatorBalances_DefaultResponse_NoArchive(t *testing.T) {
|
||||
require.NoError(t, st.SetSlot(0))
|
||||
require.NoError(t, st.SetValidators(validators))
|
||||
require.NoError(t, st.SetBalances(balances))
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -180,7 +181,7 @@ func TestServer_ListValidatorBalances_PaginationOutOfRange(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
setupValidators(t, db, 3)
|
||||
st := testutil.NewBeaconState()
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -229,7 +230,7 @@ func TestServer_ListValidatorBalances_Pagination_Default(t *testing.T) {
|
||||
setupValidators(t, db, 100)
|
||||
headState, err := db.HeadState(context.Background())
|
||||
require.NoError(t, err)
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
|
||||
@@ -314,7 +315,7 @@ func TestServer_ListValidatorBalances_Pagination_CustomPageSizes(t *testing.T) {
|
||||
setupValidators(t, db, count)
|
||||
headState, err := db.HeadState(context.Background())
|
||||
require.NoError(t, err)
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
|
||||
@@ -385,7 +386,7 @@ func TestServer_ListValidatorBalances_OutOfRange(t *testing.T) {
|
||||
|
||||
headState, err := db.HeadState(context.Background())
|
||||
require.NoError(t, err)
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
|
||||
@@ -524,7 +525,7 @@ func TestServer_ListValidators_OnlyActiveValidators(t *testing.T) {
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
}
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -895,7 +896,7 @@ func TestServer_ListValidators_FromOldEpoch(t *testing.T) {
|
||||
st := testutil.NewBeaconState()
|
||||
require.NoError(t, st.SetSlot(helpers.StartSlot(30)))
|
||||
require.NoError(t, st.SetValidators(validators))
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -961,7 +962,7 @@ func TestServer_ListValidators_ProcessHeadStateSlots(t *testing.T) {
|
||||
require.NoError(t, st.SetSlot(headSlot))
|
||||
require.NoError(t, st.SetValidators(validators))
|
||||
require.NoError(t, st.SetBalances(balances))
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -1123,7 +1124,7 @@ func TestServer_GetValidatorActiveSetChanges(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
@@ -1133,7 +1134,7 @@ func TestServer_GetValidatorActiveSetChanges(t *testing.T) {
|
||||
|
||||
bs := &Server{
|
||||
FinalizationFetcher: &mock.ChainService{
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
@@ -1233,19 +1234,19 @@ func TestServer_GetValidatorQueue_ExitedValidatorLeavesQueue(t *testing.T) {
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: bytesutil.PadTo([]byte("1"), 48),
|
||||
PublicKey: []byte("1"),
|
||||
},
|
||||
{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: 4,
|
||||
WithdrawableEpoch: 6,
|
||||
PublicKey: bytesutil.PadTo([]byte("2"), 48),
|
||||
PublicKey: []byte("2"),
|
||||
},
|
||||
}
|
||||
|
||||
headState := testutil.NewBeaconState()
|
||||
require.NoError(t, headState.SetValidators(validators))
|
||||
require.NoError(t, headState.SetFinalizedCheckpoint(ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)}))
|
||||
require.NoError(t, headState.SetFinalizedCheckpoint(ðpb.Checkpoint{Epoch: 0}))
|
||||
bs := &Server{
|
||||
HeadFetcher: &mock.ChainService{
|
||||
State: headState,
|
||||
@@ -1256,7 +1257,7 @@ func TestServer_GetValidatorQueue_ExitedValidatorLeavesQueue(t *testing.T) {
|
||||
res, err := bs.GetValidatorQueue(context.Background(), &ptypes.Empty{})
|
||||
require.NoError(t, err)
|
||||
wanted := [][]byte{
|
||||
bytesutil.PadTo([]byte("2"), 48),
|
||||
[]byte("2"),
|
||||
}
|
||||
activeValidatorCount, err := helpers.ActiveValidatorCount(headState, helpers.CurrentEpoch(headState))
|
||||
require.NoError(t, err)
|
||||
@@ -1368,35 +1369,20 @@ func TestServer_GetValidatorParticipation_PrevEpoch(t *testing.T) {
|
||||
balances := make([]uint64, validatorCount)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
PublicKey: bytesutil.ToBytes(uint64(i), 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
}
|
||||
balances[i] = params.BeaconConfig().MaxEffectiveBalance
|
||||
}
|
||||
|
||||
atts := []*pbp2p.PendingAttestation{{
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
},
|
||||
InclusionDelay: 1,
|
||||
AggregationBits: bitfield.NewBitlist(2),
|
||||
}}
|
||||
atts := []*pbp2p.PendingAttestation{{Data: ðpb.AttestationData{Target: ðpb.Checkpoint{}}, InclusionDelay: 1}}
|
||||
headState := testutil.NewBeaconState()
|
||||
require.NoError(t, headState.SetSlot(params.BeaconConfig().SlotsPerEpoch))
|
||||
require.NoError(t, headState.SetValidators(validators))
|
||||
require.NoError(t, headState.SetBalances(balances))
|
||||
require.NoError(t, headState.SetPreviousEpochAttestations(atts))
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = params.BeaconConfig().SlotsPerEpoch
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: params.BeaconConfig().SlotsPerEpoch}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
bRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -1426,8 +1412,7 @@ func TestServer_GetValidatorParticipation_DoesntExist(t *testing.T) {
|
||||
headState := testutil.NewBeaconState()
|
||||
require.NoError(t, headState.SetSlot(params.BeaconConfig().SlotsPerEpoch))
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = params.BeaconConfig().SlotsPerEpoch
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: params.BeaconConfig().SlotsPerEpoch}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
bRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -1471,8 +1456,8 @@ func TestGetValidatorPerformance_OK(t *testing.T) {
|
||||
for i := 0; i < len(atts); i++ {
|
||||
atts[i] = &pb.PendingAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{},
|
||||
Source: ðpb.Checkpoint{},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0xC0, 0xC0, 0xC0, 0xC0, 0x01},
|
||||
InclusionDelay: 1,
|
||||
@@ -1716,8 +1701,10 @@ func setupValidators(t testing.TB, db db.Database, count int) ([]*ethpb.Validato
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
})
|
||||
}
|
||||
blk := testutil.NewBeaconBlock().Block
|
||||
blockRoot, err := blk.HashTreeRoot()
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: 0,
|
||||
}
|
||||
blockRoot, err := ssz.HashTreeRoot(blk)
|
||||
require.NoError(t, err)
|
||||
s := testutil.NewBeaconState()
|
||||
require.NoError(t, s.SetValidators(validators))
|
||||
@@ -1830,10 +1817,12 @@ func TestServer_GetIndividualVotes_Working(t *testing.T) {
|
||||
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch))
|
||||
|
||||
bf := []byte{0xff}
|
||||
att1 := testutil.NewAttestation()
|
||||
att1.AggregationBits = bf
|
||||
att2 := testutil.NewAttestation()
|
||||
att2.AggregationBits = bf
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Epoch: 0}},
|
||||
AggregationBits: bf}
|
||||
att2 := ðpb.Attestation{Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Epoch: 0}},
|
||||
AggregationBits: bf}
|
||||
rt := [32]byte{'A'}
|
||||
att1.Data.Target.Root = rt[:]
|
||||
att1.Data.BeaconBlockRoot = rt[:]
|
||||
|
||||
@@ -22,9 +22,9 @@ import (
|
||||
func TestServer_GetBlock(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 100
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{
|
||||
Slot: 100,
|
||||
}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
blockRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -66,17 +66,19 @@ func TestServer_GetAttestationInclusionSlot(t *testing.T) {
|
||||
|
||||
a := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Root: tr[:]},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Slot: 1,
|
||||
Target: ðpb.Checkpoint{Root: tr[:]},
|
||||
Slot: 1,
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 2
|
||||
b.Block.Body.Attestations = []*ethpb.Attestation{a}
|
||||
b := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
Slot: 2,
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
Attestations: []*ethpb.Attestation{a},
|
||||
},
|
||||
},
|
||||
}
|
||||
require.NoError(t, bs.BeaconDB.SaveBlock(ctx, b))
|
||||
res, err := bs.GetInclusionSlot(ctx, &pbrpc.InclusionSlotRequest{Slot: 1, Id: c[0]})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
|
||||
@@ -24,8 +25,9 @@ func TestServer_GetBeaconState(t *testing.T) {
|
||||
st := testutil.NewBeaconState()
|
||||
slot := uint64(100)
|
||||
require.NoError(t, st.SetSlot(slot))
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = slot
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{
|
||||
Slot: slot,
|
||||
}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -54,6 +54,7 @@ go_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",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@io_opencensus_go//trace:go_default_library",
|
||||
"@org_golang_google_grpc//codes:go_default_library",
|
||||
@@ -116,6 +117,7 @@ go_test(
|
||||
"@com_github_golang_mock//gomock: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",
|
||||
],
|
||||
|
||||
@@ -218,13 +218,11 @@ func generateAtt(state *beaconstate.BeaconState, index uint64, privKeys []bls.Se
|
||||
aggBits.SetBitAt(index+1, true)
|
||||
att := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
CommitteeIndex: 1,
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
CommitteeIndex: 1,
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
AggregationBits: aggBits,
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
committee, err := helpers.BeaconCommitteeFromState(state, att.Data.Slot, att.Data.CommitteeIndex)
|
||||
if err != nil {
|
||||
@@ -258,13 +256,11 @@ func generateUnaggregatedAtt(state *beaconstate.BeaconState, index uint64, privK
|
||||
aggBits.SetBitAt(index, true)
|
||||
att := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
CommitteeIndex: 1,
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
CommitteeIndex: 1,
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0},
|
||||
},
|
||||
AggregationBits: aggBits,
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
committee, err := helpers.BeaconCommitteeFromState(state, att.Data.Slot, att.Data.CommitteeIndex)
|
||||
if err != nil {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
||||
@@ -265,7 +266,7 @@ func TestStreamDuties_OK(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
bs, err := state.GenesisBeaconState(deposits, 0, eth1Data)
|
||||
require.NoError(t, err, "Could not setup genesis bs")
|
||||
genesisRoot, err := genesis.Block.HashTreeRoot()
|
||||
genesisRoot, err := ssz.HashTreeRoot(genesis.Block)
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
|
||||
pubKeys := make([][]byte, len(deposits))
|
||||
@@ -324,7 +325,7 @@ func TestStreamDuties_OK_ChainReorg(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
bs, err := state.GenesisBeaconState(deposits, 0, eth1Data)
|
||||
require.NoError(t, err, "Could not setup genesis bs")
|
||||
genesisRoot, err := genesis.Block.HashTreeRoot()
|
||||
genesisRoot, err := ssz.HashTreeRoot(genesis.Block)
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
|
||||
pubKeys := make([][]byte, len(deposits))
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
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"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
@@ -51,10 +52,8 @@ func TestProposeAttestation_OK(t *testing.T) {
|
||||
validators := make([]*ethpb.Validator, 64)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,8 +69,8 @@ func TestProposeAttestation_OK(t *testing.T) {
|
||||
Signature: sig.Marshal(),
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: root[:],
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{},
|
||||
Target: ðpb.Checkpoint{},
|
||||
},
|
||||
}
|
||||
_, err = attesterServer.ProposeAttestation(context.Background(), req)
|
||||
@@ -92,11 +91,9 @@ func TestProposeAttestation_IncorrectSignature(t *testing.T) {
|
||||
|
||||
req := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{},
|
||||
Target: ðpb.Checkpoint{},
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
wanted := "Incorrect attestation signature"
|
||||
_, err := attesterServer.ProposeAttestation(context.Background(), req)
|
||||
@@ -107,17 +104,20 @@ func TestGetAttestationData_OK(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.Slot = 3*params.BeaconConfig().SlotsPerEpoch + 1
|
||||
targetBlock := testutil.NewBeaconBlock()
|
||||
targetBlock.Block.Slot = 1 * params.BeaconConfig().SlotsPerEpoch
|
||||
justifiedBlock := testutil.NewBeaconBlock()
|
||||
justifiedBlock.Block.Slot = 2 * params.BeaconConfig().SlotsPerEpoch
|
||||
blockRoot, err := stateutil.BlockRoot(block.Block)
|
||||
block := ðpb.BeaconBlock{
|
||||
Slot: 3*params.BeaconConfig().SlotsPerEpoch + 1,
|
||||
}
|
||||
targetBlock := ðpb.BeaconBlock{
|
||||
Slot: 1 * params.BeaconConfig().SlotsPerEpoch,
|
||||
}
|
||||
justifiedBlock := ðpb.BeaconBlock{
|
||||
Slot: 2 * params.BeaconConfig().SlotsPerEpoch,
|
||||
}
|
||||
blockRoot, err := stateutil.BlockRoot(block)
|
||||
require.NoError(t, err, "Could not hash beacon block")
|
||||
justifiedRoot, err := stateutil.BlockRoot(justifiedBlock.Block)
|
||||
justifiedRoot, err := stateutil.BlockRoot(justifiedBlock)
|
||||
require.NoError(t, err, "Could not get signing root for justified block")
|
||||
targetRoot, err := stateutil.BlockRoot(targetBlock.Block)
|
||||
targetRoot, err := stateutil.BlockRoot(targetBlock)
|
||||
require.NoError(t, err, "Could not get signing root for target block")
|
||||
slot := 3*params.BeaconConfig().SlotsPerEpoch + 1
|
||||
beaconState := testutil.NewBeaconState()
|
||||
@@ -153,7 +153,7 @@ func TestGetAttestationData_OK(t *testing.T) {
|
||||
StateNotifier: chainService.StateNotifier(),
|
||||
}
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, blockRoot))
|
||||
require.NoError(t, db.SaveBlock(ctx, block))
|
||||
require.NoError(t, db.SaveBlock(ctx, ðpb.SignedBeaconBlock{Block: block}))
|
||||
require.NoError(t, db.SaveHeadBlockRoot(ctx, blockRoot))
|
||||
|
||||
req := ðpb.AttestationDataRequest{
|
||||
@@ -206,17 +206,20 @@ func TestAttestationDataAtSlot_HandlesFarAwayJustifiedEpoch(t *testing.T) {
|
||||
cfg.HistoricalRootsLimit = 8192
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.Slot = 10000
|
||||
epochBoundaryBlock := testutil.NewBeaconBlock()
|
||||
epochBoundaryBlock.Block.Slot = helpers.StartSlot(helpers.SlotToEpoch(10000))
|
||||
justifiedBlock := testutil.NewBeaconBlock()
|
||||
justifiedBlock.Block.Slot = helpers.StartSlot(helpers.SlotToEpoch(1500)) - 2 // Imagine two skip block
|
||||
blockRoot, err := stateutil.BlockRoot(block.Block)
|
||||
block := ðpb.BeaconBlock{
|
||||
Slot: 10000,
|
||||
}
|
||||
epochBoundaryBlock := ðpb.BeaconBlock{
|
||||
Slot: helpers.StartSlot(helpers.SlotToEpoch(10000)),
|
||||
}
|
||||
justifiedBlock := ðpb.BeaconBlock{
|
||||
Slot: helpers.StartSlot(helpers.SlotToEpoch(1500)) - 2, // Imagine two skip block
|
||||
}
|
||||
blockRoot, err := stateutil.BlockRoot(block)
|
||||
require.NoError(t, err, "Could not hash beacon block")
|
||||
justifiedBlockRoot, err := stateutil.BlockRoot(justifiedBlock.Block)
|
||||
justifiedBlockRoot, err := stateutil.BlockRoot(justifiedBlock)
|
||||
require.NoError(t, err, "Could not hash justified block")
|
||||
epochBoundaryRoot, err := stateutil.BlockRoot(epochBoundaryBlock.Block)
|
||||
epochBoundaryRoot, err := stateutil.BlockRoot(epochBoundaryBlock)
|
||||
require.NoError(t, err, "Could not hash justified block")
|
||||
slot := uint64(10000)
|
||||
|
||||
@@ -248,7 +251,7 @@ func TestAttestationDataAtSlot_HandlesFarAwayJustifiedEpoch(t *testing.T) {
|
||||
StateNotifier: chainService.StateNotifier(),
|
||||
}
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, blockRoot))
|
||||
require.NoError(t, db.SaveBlock(ctx, block))
|
||||
require.NoError(t, db.SaveBlock(ctx, ðpb.SignedBeaconBlock{Block: block}))
|
||||
require.NoError(t, db.SaveHeadBlockRoot(ctx, blockRoot))
|
||||
|
||||
req := ðpb.AttestationDataRequest{
|
||||
@@ -299,7 +302,7 @@ func TestAttestationDataSlot_handlesInProgressRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
res := ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Epoch: 55, Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{Epoch: 55},
|
||||
}
|
||||
|
||||
require.NoError(t, server.AttestationCache.MarkInProgress(req))
|
||||
@@ -352,22 +355,24 @@ func TestServer_GetAttestationData_HeadStateSlotGreaterThanRequestSlot(t *testin
|
||||
db, sc := dbutil.SetupDB(t)
|
||||
|
||||
slot := 3*params.BeaconConfig().SlotsPerEpoch + 1
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.Slot = slot
|
||||
block2 := testutil.NewBeaconBlock()
|
||||
block2.Block.Slot = slot - 1
|
||||
targetBlock := testutil.NewBeaconBlock()
|
||||
targetBlock.Block.Slot = 1 * params.BeaconConfig().SlotsPerEpoch
|
||||
justifiedBlock := testutil.NewBeaconBlock()
|
||||
justifiedBlock.Block.Slot = 2 * params.BeaconConfig().SlotsPerEpoch
|
||||
blockRoot, err := stateutil.BlockRoot(block.Block)
|
||||
block := ðpb.BeaconBlock{
|
||||
Slot: slot,
|
||||
}
|
||||
block2 := ðpb.BeaconBlock{Slot: slot - 1}
|
||||
targetBlock := ðpb.BeaconBlock{
|
||||
Slot: 1 * params.BeaconConfig().SlotsPerEpoch,
|
||||
}
|
||||
justifiedBlock := ðpb.BeaconBlock{
|
||||
Slot: 2 * params.BeaconConfig().SlotsPerEpoch,
|
||||
}
|
||||
blockRoot, err := stateutil.BlockRoot(block)
|
||||
require.NoError(t, err, "Could not hash beacon block")
|
||||
blockRoot2, err := block2.HashTreeRoot()
|
||||
blockRoot2, err := ssz.HashTreeRoot(block2)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveBlock(ctx, block2))
|
||||
justifiedRoot, err := stateutil.BlockRoot(justifiedBlock.Block)
|
||||
require.NoError(t, db.SaveBlock(ctx, ðpb.SignedBeaconBlock{Block: block2}))
|
||||
justifiedRoot, err := stateutil.BlockRoot(justifiedBlock)
|
||||
require.NoError(t, err, "Could not get signing root for justified block")
|
||||
targetRoot, err := stateutil.BlockRoot(targetBlock.Block)
|
||||
targetRoot, err := stateutil.BlockRoot(targetBlock)
|
||||
require.NoError(t, err, "Could not get signing root for target block")
|
||||
|
||||
beaconState := testutil.NewBeaconState()
|
||||
@@ -409,7 +414,7 @@ func TestServer_GetAttestationData_HeadStateSlotGreaterThanRequestSlot(t *testin
|
||||
StateGen: stategen.New(db, sc),
|
||||
}
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, blockRoot))
|
||||
require.NoError(t, db.SaveBlock(ctx, block))
|
||||
require.NoError(t, db.SaveBlock(ctx, ðpb.SignedBeaconBlock{Block: block}))
|
||||
require.NoError(t, db.SaveHeadBlockRoot(ctx, blockRoot))
|
||||
|
||||
req := ðpb.AttestationDataRequest{
|
||||
@@ -442,17 +447,20 @@ func TestGetAttestationData_SucceedsInFirstEpoch(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
|
||||
slot := uint64(5)
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.Slot = slot
|
||||
targetBlock := testutil.NewBeaconBlock()
|
||||
targetBlock.Block.Slot = 0
|
||||
justifiedBlock := testutil.NewBeaconBlock()
|
||||
justifiedBlock.Block.Slot = 0
|
||||
blockRoot, err := stateutil.BlockRoot(block.Block)
|
||||
block := ðpb.BeaconBlock{
|
||||
Slot: slot,
|
||||
}
|
||||
targetBlock := ðpb.BeaconBlock{
|
||||
Slot: 0,
|
||||
}
|
||||
justifiedBlock := ðpb.BeaconBlock{
|
||||
Slot: 0,
|
||||
}
|
||||
blockRoot, err := stateutil.BlockRoot(block)
|
||||
require.NoError(t, err, "Could not hash beacon block")
|
||||
justifiedRoot, err := stateutil.BlockRoot(justifiedBlock.Block)
|
||||
justifiedRoot, err := stateutil.BlockRoot(justifiedBlock)
|
||||
require.NoError(t, err, "Could not get signing root for justified block")
|
||||
targetRoot, err := stateutil.BlockRoot(targetBlock.Block)
|
||||
targetRoot, err := stateutil.BlockRoot(targetBlock)
|
||||
require.NoError(t, err, "Could not get signing root for target block")
|
||||
|
||||
beaconState := testutil.NewBeaconState()
|
||||
@@ -485,7 +493,7 @@ func TestGetAttestationData_SucceedsInFirstEpoch(t *testing.T) {
|
||||
StateNotifier: chainService.StateNotifier(),
|
||||
}
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, blockRoot))
|
||||
require.NoError(t, db.SaveBlock(ctx, block))
|
||||
require.NoError(t, db.SaveBlock(ctx, ðpb.SignedBeaconBlock{Block: block}))
|
||||
require.NoError(t, db.SaveHeadBlockRoot(ctx, blockRoot))
|
||||
|
||||
req := ðpb.AttestationDataRequest{
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
fastssz "github.com/ferranbt/fastssz"
|
||||
"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/core/feed"
|
||||
@@ -540,7 +541,7 @@ func (vs *Server) depositTrie(ctx context.Context, canonicalEth1DataHeight *big.
|
||||
insertIndex := finalizedDeposits.MerkleTrieIndex + 1
|
||||
|
||||
for _, dep := range upToEth1DataDeposits {
|
||||
depHash, err := dep.Data.HashTreeRoot()
|
||||
depHash, err := ssz.HashTreeRoot(dep.Data)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not hash deposit data")
|
||||
}
|
||||
@@ -554,7 +555,7 @@ func (vs *Server) depositTrie(ctx context.Context, canonicalEth1DataHeight *big.
|
||||
upToEth1DataDeposits := vs.DepositFetcher.AllDeposits(ctx, canonicalEth1DataHeight)
|
||||
depositData := [][]byte{}
|
||||
for _, dep := range upToEth1DataDeposits {
|
||||
depHash, err := dep.Data.HashTreeRoot()
|
||||
depHash, err := ssz.HashTreeRoot(dep.Data)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not hash deposit data")
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
||||
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
@@ -276,10 +277,19 @@ func TestComputeStateRoot_OK(t *testing.T) {
|
||||
Eth1BlockFetcher: &mockPOW.POWChain{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
}
|
||||
req := testutil.NewBeaconBlock()
|
||||
req.Block.ProposerIndex = 21
|
||||
req.Block.ParentRoot = parentRoot[:]
|
||||
req.Block.Slot = 1
|
||||
req := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
ProposerIndex: 21,
|
||||
ParentRoot: parentRoot[:],
|
||||
Slot: 1,
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
RandaoReveal: nil,
|
||||
ProposerSlashings: nil,
|
||||
AttesterSlashings: nil,
|
||||
Eth1Data: ðpb.Eth1Data{},
|
||||
},
|
||||
},
|
||||
}
|
||||
require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1))
|
||||
randaoReveal, err := testutil.RandaoReveal(beaconState, 0, privKeys)
|
||||
require.NoError(t, err)
|
||||
@@ -324,17 +334,22 @@ func TestPendingDeposits_Eth1DataVoteOK(t *testing.T) {
|
||||
|
||||
blockHash = make([]byte, 32)
|
||||
copy(blockHash, "0x0")
|
||||
beaconState := testutil.NewBeaconState()
|
||||
require.NoError(t, beaconState.SetEth1DepositIndex(2))
|
||||
require.NoError(t, beaconState.SetEth1Data(ðpb.Eth1Data{
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: blockHash,
|
||||
DepositCount: 2,
|
||||
}))
|
||||
require.NoError(t, beaconState.SetEth1DataVotes(votes))
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: blockHash,
|
||||
DepositCount: 2,
|
||||
},
|
||||
Eth1DepositIndex: 2,
|
||||
Eth1DataVotes: votes,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blkRoot, err := blk.Block.HashTreeRoot()
|
||||
blk := ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{Eth1Data: ðpb.Eth1Data{}},
|
||||
}
|
||||
|
||||
blkRoot, err := ssz.HashTreeRoot(blk)
|
||||
require.NoError(t, err)
|
||||
|
||||
bs := &Server{
|
||||
@@ -352,7 +367,7 @@ func TestPendingDeposits_Eth1DataVoteOK(t *testing.T) {
|
||||
|
||||
assert.Equal(t, 0, eth1Height.Cmp(height))
|
||||
|
||||
newState, err := b.ProcessEth1DataInBlock(beaconState, blk.Block)
|
||||
newState, err := b.ProcessEth1DataInBlock(beaconState, blk)
|
||||
require.NoError(t, err)
|
||||
|
||||
if proto.Equal(newState.Eth1Data(), vote) {
|
||||
@@ -360,13 +375,15 @@ func TestPendingDeposits_Eth1DataVoteOK(t *testing.T) {
|
||||
"have majority: Got %v", vote)
|
||||
}
|
||||
|
||||
blk.Block.Body.Eth1Data = vote
|
||||
blk = ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{Eth1Data: vote},
|
||||
}
|
||||
|
||||
_, eth1Height, err = bs.canonicalEth1Data(ctx, beaconState, vote)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 0, eth1Height.Cmp(newHeight))
|
||||
|
||||
newState, err = b.ProcessEth1DataInBlock(beaconState, blk.Block)
|
||||
newState, err = b.ProcessEth1DataInBlock(beaconState, blk)
|
||||
require.NoError(t, err)
|
||||
|
||||
if !proto.Equal(newState.Eth1Data(), vote) {
|
||||
@@ -387,8 +404,7 @@ func TestPendingDeposits_OutsideEth1FollowWindow(t *testing.T) {
|
||||
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: bytesutil.PadTo([]byte("0x0"), 32),
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: []byte("0x0"),
|
||||
},
|
||||
Eth1DepositIndex: 2,
|
||||
})
|
||||
@@ -404,7 +420,7 @@ func TestPendingDeposits_OutsideEth1FollowWindow(t *testing.T) {
|
||||
Eth1BlockHeight: 2,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -414,7 +430,7 @@ func TestPendingDeposits_OutsideEth1FollowWindow(t *testing.T) {
|
||||
Eth1BlockHeight: 8,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("b"), 48),
|
||||
PublicKey: []byte("b"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -427,7 +443,7 @@ func TestPendingDeposits_OutsideEth1FollowWindow(t *testing.T) {
|
||||
Eth1BlockHeight: 400,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("c"), 48),
|
||||
PublicKey: []byte("c"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -437,7 +453,7 @@ func TestPendingDeposits_OutsideEth1FollowWindow(t *testing.T) {
|
||||
Eth1BlockHeight: 600,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("d"), 48),
|
||||
PublicKey: []byte("d"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -450,7 +466,7 @@ func TestPendingDeposits_OutsideEth1FollowWindow(t *testing.T) {
|
||||
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
|
||||
require.NoError(t, err, "Could not setup deposit trie")
|
||||
for _, dp := range append(readyDeposits, recentDeposits...) {
|
||||
depositHash, err := dp.Deposit.Data.HashTreeRoot()
|
||||
depositHash, err := ssz.HashTreeRoot(dp.Deposit.Data)
|
||||
require.NoError(t, err, "Unable to determine hashed value of deposit")
|
||||
|
||||
depositTrie.Insert(depositHash[:], int(dp.Index))
|
||||
@@ -460,10 +476,11 @@ func TestPendingDeposits_OutsideEth1FollowWindow(t *testing.T) {
|
||||
depositCache.InsertPendingDeposit(ctx, dp.Deposit, dp.Eth1BlockHeight, dp.Index, depositTrie.Root())
|
||||
}
|
||||
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.Slot = beaconState.Slot()
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: beaconState.Slot(),
|
||||
}
|
||||
|
||||
blkRoot, err := blk.HashTreeRoot()
|
||||
blkRoot, err := ssz.HashTreeRoot(blk)
|
||||
require.NoError(t, err)
|
||||
|
||||
bs := &Server{
|
||||
@@ -504,8 +521,7 @@ func TestPendingDeposits_FollowsCorrectEth1Block(t *testing.T) {
|
||||
var votes []*ethpb.Eth1Data
|
||||
|
||||
vote := ðpb.Eth1Data{
|
||||
BlockHash: bytesutil.PadTo([]byte("0x1"), 32),
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: []byte("0x1"),
|
||||
DepositCount: 7,
|
||||
}
|
||||
period := params.BeaconConfig().EpochsPerEth1VotingPeriod * params.BeaconConfig().SlotsPerEpoch
|
||||
@@ -516,17 +532,17 @@ func TestPendingDeposits_FollowsCorrectEth1Block(t *testing.T) {
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositRoot: make([]byte, 32),
|
||||
DepositCount: 5,
|
||||
},
|
||||
Eth1DepositIndex: 1,
|
||||
Eth1DataVotes: votes,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.Slot = beaconState.Slot()
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: beaconState.Slot(),
|
||||
}
|
||||
|
||||
blkRoot, err := blk.HashTreeRoot()
|
||||
blkRoot, err := ssz.HashTreeRoot(blk)
|
||||
require.NoError(t, err)
|
||||
|
||||
var mockSig [96]byte
|
||||
@@ -539,7 +555,7 @@ func TestPendingDeposits_FollowsCorrectEth1Block(t *testing.T) {
|
||||
Eth1BlockHeight: 8,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -549,7 +565,7 @@ func TestPendingDeposits_FollowsCorrectEth1Block(t *testing.T) {
|
||||
Eth1BlockHeight: 14,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("b"), 48),
|
||||
PublicKey: []byte("b"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -562,7 +578,7 @@ func TestPendingDeposits_FollowsCorrectEth1Block(t *testing.T) {
|
||||
Eth1BlockHeight: 5000,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("c"), 48),
|
||||
PublicKey: []byte("c"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -572,7 +588,7 @@ func TestPendingDeposits_FollowsCorrectEth1Block(t *testing.T) {
|
||||
Eth1BlockHeight: 6000,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("d"), 48),
|
||||
PublicKey: []byte("d"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -585,7 +601,7 @@ func TestPendingDeposits_FollowsCorrectEth1Block(t *testing.T) {
|
||||
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
|
||||
require.NoError(t, err, "Could not setup deposit trie")
|
||||
for _, dp := range append(readyDeposits, recentDeposits...) {
|
||||
depositHash, err := dp.Deposit.Data.HashTreeRoot()
|
||||
depositHash, err := ssz.HashTreeRoot(dp.Deposit.Data)
|
||||
require.NoError(t, err, "Unable to determine hashed value of deposit")
|
||||
|
||||
depositTrie.Insert(depositHash[:], int(dp.Index))
|
||||
@@ -628,16 +644,18 @@ func TestPendingDeposits_CantReturnBelowStateEth1DepositIndex(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
beaconState := testutil.NewBeaconState()
|
||||
require.NoError(t, beaconState.SetEth1Data(ðpb.Eth1Data{
|
||||
BlockHash: bytesutil.PadTo([]byte("0x0"), 32),
|
||||
DepositRoot: make([]byte, 32),
|
||||
DepositCount: 100,
|
||||
}))
|
||||
require.NoError(t, beaconState.SetEth1DepositIndex(10))
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.Slot = beaconState.Slot()
|
||||
blkRoot, err := blk.HashTreeRoot()
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositCount: 100,
|
||||
},
|
||||
Eth1DepositIndex: 10,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: beaconState.Slot(),
|
||||
}
|
||||
blkRoot, err := ssz.HashTreeRoot(blk)
|
||||
require.NoError(t, err)
|
||||
|
||||
var mockSig [96]byte
|
||||
@@ -648,7 +666,7 @@ func TestPendingDeposits_CantReturnBelowStateEth1DepositIndex(t *testing.T) {
|
||||
Index: 0,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -657,7 +675,7 @@ func TestPendingDeposits_CantReturnBelowStateEth1DepositIndex(t *testing.T) {
|
||||
Index: 1,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("b"), 48),
|
||||
PublicKey: []byte("b"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -670,7 +688,7 @@ func TestPendingDeposits_CantReturnBelowStateEth1DepositIndex(t *testing.T) {
|
||||
Index: i,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{byte(i)}, 48),
|
||||
PublicKey: []byte{byte(i)},
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -683,7 +701,7 @@ func TestPendingDeposits_CantReturnBelowStateEth1DepositIndex(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, dp := range append(readyDeposits, recentDeposits...) {
|
||||
depositHash, err := dp.Deposit.Data.HashTreeRoot()
|
||||
depositHash, err := ssz.HashTreeRoot(dp.Deposit.Data)
|
||||
require.NoError(t, err, "Unable to determine hashed value of deposit")
|
||||
|
||||
depositTrie.Insert(depositHash[:], int(dp.Index))
|
||||
@@ -725,16 +743,16 @@ func TestPendingDeposits_CantReturnMoreThanMax(t *testing.T) {
|
||||
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: bytesutil.PadTo([]byte("0x0"), 32),
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositCount: 100,
|
||||
},
|
||||
Eth1DepositIndex: 2,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.Slot = beaconState.Slot()
|
||||
blkRoot, err := blk.HashTreeRoot()
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: beaconState.Slot(),
|
||||
}
|
||||
blkRoot, err := ssz.HashTreeRoot(blk)
|
||||
require.NoError(t, err)
|
||||
var mockSig [96]byte
|
||||
var mockCreds [32]byte
|
||||
@@ -744,7 +762,7 @@ func TestPendingDeposits_CantReturnMoreThanMax(t *testing.T) {
|
||||
Index: 0,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -753,7 +771,7 @@ func TestPendingDeposits_CantReturnMoreThanMax(t *testing.T) {
|
||||
Index: 1,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("b"), 48),
|
||||
PublicKey: []byte("b"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -766,7 +784,7 @@ func TestPendingDeposits_CantReturnMoreThanMax(t *testing.T) {
|
||||
Index: i,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{byte(i)}, 48),
|
||||
PublicKey: []byte{byte(i)},
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -779,7 +797,7 @@ func TestPendingDeposits_CantReturnMoreThanMax(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, dp := range append(readyDeposits, recentDeposits...) {
|
||||
depositHash, err := dp.Deposit.Data.HashTreeRoot()
|
||||
depositHash, err := ssz.HashTreeRoot(dp.Deposit.Data)
|
||||
require.NoError(t, err, "Unable to determine hashed value of deposit")
|
||||
|
||||
depositTrie.Insert(depositHash[:], int(dp.Index))
|
||||
@@ -819,16 +837,16 @@ func TestPendingDeposits_CantReturnMoreThanDepositCount(t *testing.T) {
|
||||
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: bytesutil.PadTo([]byte("0x0"), 32),
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositCount: 5,
|
||||
},
|
||||
Eth1DepositIndex: 2,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.Slot = beaconState.Slot()
|
||||
blkRoot, err := blk.HashTreeRoot()
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: beaconState.Slot(),
|
||||
}
|
||||
blkRoot, err := ssz.HashTreeRoot(blk)
|
||||
require.NoError(t, err)
|
||||
var mockSig [96]byte
|
||||
var mockCreds [32]byte
|
||||
@@ -838,7 +856,7 @@ func TestPendingDeposits_CantReturnMoreThanDepositCount(t *testing.T) {
|
||||
Index: 0,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -847,7 +865,7 @@ func TestPendingDeposits_CantReturnMoreThanDepositCount(t *testing.T) {
|
||||
Index: 1,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("b"), 48),
|
||||
PublicKey: []byte("b"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -860,7 +878,7 @@ func TestPendingDeposits_CantReturnMoreThanDepositCount(t *testing.T) {
|
||||
Index: i,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{byte(i)}, 48),
|
||||
PublicKey: []byte{byte(i)},
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -873,7 +891,7 @@ func TestPendingDeposits_CantReturnMoreThanDepositCount(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, dp := range append(readyDeposits, recentDeposits...) {
|
||||
depositHash, err := dp.Deposit.Data.HashTreeRoot()
|
||||
depositHash, err := ssz.HashTreeRoot(dp.Deposit.Data)
|
||||
require.NoError(t, err, "Unable to determine hashed value of deposit")
|
||||
|
||||
depositTrie.Insert(depositHash[:], int(dp.Index))
|
||||
@@ -915,17 +933,17 @@ func TestDepositTrie_UtilizesCachedFinalizedDeposits(t *testing.T) {
|
||||
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: bytesutil.PadTo([]byte("0x0"), 32),
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositCount: 4,
|
||||
},
|
||||
Eth1DepositIndex: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.Slot = beaconState.Slot()
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: beaconState.Slot(),
|
||||
}
|
||||
|
||||
blkRoot, err := blk.Block.HashTreeRoot()
|
||||
blkRoot, err := ssz.HashTreeRoot(blk)
|
||||
require.NoError(t, err)
|
||||
|
||||
var mockSig [96]byte
|
||||
@@ -938,7 +956,7 @@ func TestDepositTrie_UtilizesCachedFinalizedDeposits(t *testing.T) {
|
||||
Eth1BlockHeight: 10,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -948,7 +966,7 @@ func TestDepositTrie_UtilizesCachedFinalizedDeposits(t *testing.T) {
|
||||
Eth1BlockHeight: 10,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("b"), 48),
|
||||
PublicKey: []byte("b"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -961,7 +979,7 @@ func TestDepositTrie_UtilizesCachedFinalizedDeposits(t *testing.T) {
|
||||
Eth1BlockHeight: 11,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("c"), 48),
|
||||
PublicKey: []byte("c"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -971,7 +989,7 @@ func TestDepositTrie_UtilizesCachedFinalizedDeposits(t *testing.T) {
|
||||
Eth1BlockHeight: 11,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("d"), 48),
|
||||
PublicKey: []byte("d"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -984,7 +1002,7 @@ func TestDepositTrie_UtilizesCachedFinalizedDeposits(t *testing.T) {
|
||||
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
|
||||
require.NoError(t, err, "Could not setup deposit trie")
|
||||
for _, dp := range append(finalizedDeposits, recentDeposits...) {
|
||||
depositHash, err := dp.Deposit.Data.HashTreeRoot()
|
||||
depositHash, err := ssz.HashTreeRoot(dp.Deposit.Data)
|
||||
require.NoError(t, err, "Unable to determine hashed value of deposit")
|
||||
|
||||
depositTrie.Insert(depositHash[:], int(dp.Index))
|
||||
@@ -1045,7 +1063,7 @@ func TestDefaultEth1Data_NoBlockExists(t *testing.T) {
|
||||
Eth1BlockHeight: 8,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: make([]byte, 96),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
}},
|
||||
@@ -1055,7 +1073,7 @@ func TestDefaultEth1Data_NoBlockExists(t *testing.T) {
|
||||
Eth1BlockHeight: 14,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("b"), 48),
|
||||
PublicKey: []byte("b"),
|
||||
Signature: make([]byte, 96),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
}},
|
||||
@@ -1144,7 +1162,7 @@ func TestEth1Data_SmallerDepositCount(t *testing.T) {
|
||||
Eth1BlockHeight: 8,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: make([]byte, 96),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
}},
|
||||
@@ -1154,7 +1172,7 @@ func TestEth1Data_SmallerDepositCount(t *testing.T) {
|
||||
Eth1BlockHeight: 14,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("b"), 48),
|
||||
PublicKey: []byte("b"),
|
||||
Signature: make([]byte, 96),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
}},
|
||||
@@ -1259,7 +1277,7 @@ func TestEth1DataMajorityVote_ChooseHighestCount(t *testing.T) {
|
||||
Eth1BlockHeight: 0,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: make([]byte, 96),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
}},
|
||||
@@ -1320,7 +1338,7 @@ func TestEth1DataMajorityVote_HighestCountBeforeRange_ChooseHighestCountWithinRa
|
||||
Eth1BlockHeight: 0,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: make([]byte, 96),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
}},
|
||||
@@ -1380,7 +1398,7 @@ func TestEth1DataMajorityVote_HighestCountAfterRange_ChooseHighestCountWithinRan
|
||||
Eth1BlockHeight: 0,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: make([]byte, 96),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
}},
|
||||
@@ -1440,7 +1458,7 @@ func TestEth1DataMajorityVote_HighestCountOnUnknownBlock_ChooseKnownBlockWithHig
|
||||
Eth1BlockHeight: 0,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: make([]byte, 96),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
}},
|
||||
@@ -1502,7 +1520,7 @@ func TestEth1DataMajorityVote_NoVotesInRange_ChooseDefault(t *testing.T) {
|
||||
Eth1BlockHeight: 0,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: make([]byte, 96),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
}},
|
||||
@@ -1562,7 +1580,7 @@ func TestEth1DataMajorityVote_NoVotes_ChooseDefault(t *testing.T) {
|
||||
Eth1BlockHeight: 0,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: make([]byte, 96),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
}},
|
||||
@@ -1617,7 +1635,7 @@ func TestEth1DataMajorityVote_SameCount_ChooseMoreRecentBlock(t *testing.T) {
|
||||
Eth1BlockHeight: 0,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: make([]byte, 96),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
}},
|
||||
@@ -1684,14 +1702,9 @@ func TestFilterAttestation_OK(t *testing.T) {
|
||||
|
||||
atts := make([]*ethpb.Attestation, 10)
|
||||
for i := 0; i < len(atts); i++ {
|
||||
atts[i] = ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
CommitteeIndex: uint64(i),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
atts[i] = ðpb.Attestation{Data: ðpb.AttestationData{
|
||||
CommitteeIndex: uint64(i),
|
||||
Target: ðpb.Checkpoint{}},
|
||||
}
|
||||
}
|
||||
received, err := proposerServer.filterAttestationsForBlockInclusion(context.Background(), state, atts)
|
||||
@@ -1703,15 +1716,11 @@ func TestFilterAttestation_OK(t *testing.T) {
|
||||
for i := 0; i < len(atts); i++ {
|
||||
aggBits := bitfield.NewBitlist(2)
|
||||
aggBits.SetBitAt(0, true)
|
||||
atts[i] = ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
CommitteeIndex: uint64(i),
|
||||
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Source: ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]},
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
},
|
||||
atts[i] = ðpb.Attestation{Data: ðpb.AttestationData{
|
||||
CommitteeIndex: uint64(i),
|
||||
Target: ðpb.Checkpoint{},
|
||||
Source: ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}},
|
||||
AggregationBits: aggBits,
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
committee, err := helpers.BeaconCommitteeFromState(state, atts[i].Data.Slot, atts[i].Data.CommitteeIndex)
|
||||
assert.NoError(t, err)
|
||||
@@ -1756,7 +1765,7 @@ func Benchmark_Eth1Data(b *testing.B) {
|
||||
Index: 0,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -1765,7 +1774,7 @@ func Benchmark_Eth1Data(b *testing.B) {
|
||||
Index: 1,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("b"), 48),
|
||||
PublicKey: []byte("b"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -1793,9 +1802,10 @@ func Benchmark_Eth1Data(b *testing.B) {
|
||||
}
|
||||
hashesByHeight[numOfVotes+1] = []byte("stub")
|
||||
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.Slot = beaconState.Slot()
|
||||
blkRoot, err := blk.HashTreeRoot()
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: beaconState.Slot(),
|
||||
}
|
||||
blkRoot, err := ssz.HashTreeRoot(blk)
|
||||
require.NoError(b, err)
|
||||
|
||||
currentHeight := params.BeaconConfig().Eth1FollowDistance + 5
|
||||
@@ -1833,15 +1843,15 @@ func TestDeposits_ReturnsEmptyList_IfLatestEth1DataEqGenesisEth1Block(t *testing
|
||||
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: bytesutil.PadTo([]byte("0x0"), 32),
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: []byte("0x0"),
|
||||
},
|
||||
Eth1DepositIndex: 2,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.Slot = beaconState.Slot()
|
||||
blkRoot, err := blk.Block.HashTreeRoot()
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: beaconState.Slot(),
|
||||
}
|
||||
blkRoot, err := ssz.HashTreeRoot(blk)
|
||||
require.NoError(t, err)
|
||||
|
||||
var mockSig [96]byte
|
||||
@@ -1852,7 +1862,7 @@ func TestDeposits_ReturnsEmptyList_IfLatestEth1DataEqGenesisEth1Block(t *testing
|
||||
Index: 0,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("a"), 48),
|
||||
PublicKey: []byte("a"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -1861,7 +1871,7 @@ func TestDeposits_ReturnsEmptyList_IfLatestEth1DataEqGenesisEth1Block(t *testing
|
||||
Index: 1,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte("b"), 48),
|
||||
PublicKey: []byte("b"),
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -1874,7 +1884,7 @@ func TestDeposits_ReturnsEmptyList_IfLatestEth1DataEqGenesisEth1Block(t *testing
|
||||
Index: i,
|
||||
Deposit: ðpb.Deposit{
|
||||
Data: ðpb.Deposit_Data{
|
||||
PublicKey: bytesutil.PadTo([]byte{byte(i)}, 48),
|
||||
PublicKey: []byte{byte(i)},
|
||||
Signature: mockSig[:],
|
||||
WithdrawalCredentials: mockCreds[:],
|
||||
}},
|
||||
@@ -1887,7 +1897,7 @@ func TestDeposits_ReturnsEmptyList_IfLatestEth1DataEqGenesisEth1Block(t *testing
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, dp := range append(readyDeposits, recentDeposits...) {
|
||||
depositHash, err := dp.Deposit.Data.HashTreeRoot()
|
||||
depositHash, err := ssz.HashTreeRoot(dp.Deposit.Data)
|
||||
require.NoError(t, err, "Unable to determine hashed value of deposit")
|
||||
|
||||
depositTrie.Insert(depositHash[:], int(dp.Index))
|
||||
@@ -1920,8 +1930,9 @@ func TestDeleteAttsInPool_Aggregated(t *testing.T) {
|
||||
}
|
||||
|
||||
sig := bls.RandKey().Sign([]byte("foo")).Marshal()
|
||||
aggregatedAtts := []*ethpb.Attestation{{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b10101}, Signature: sig}, {Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b11010}, Signature: sig}}
|
||||
unaggregatedAtts := []*ethpb.Attestation{{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig}, {Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b0001}, Signature: sig}}
|
||||
d := ðpb.AttestationData{}
|
||||
aggregatedAtts := []*ethpb.Attestation{{Data: d, AggregationBits: bitfield.Bitlist{0b10101}, Signature: sig}, {Data: d, AggregationBits: bitfield.Bitlist{0b11010}, Signature: sig}}
|
||||
unaggregatedAtts := []*ethpb.Attestation{{Data: d, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig}, {Data: d, AggregationBits: bitfield.Bitlist{0b0001}, Signature: sig}}
|
||||
|
||||
require.NoError(t, s.AttPool.SaveAggregatedAttestations(aggregatedAtts))
|
||||
require.NoError(t, s.AttPool.SaveUnaggregatedAttestations(unaggregatedAtts))
|
||||
@@ -1937,21 +1948,21 @@ func TestDeleteAttsInPool_Aggregated(t *testing.T) {
|
||||
|
||||
func TestSortProfitableAtts(t *testing.T) {
|
||||
atts := []*ethpb.Attestation{
|
||||
{Data: ðpb.AttestationData{Slot: 4, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b11100000}},
|
||||
{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b11000000}},
|
||||
{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b11100000}},
|
||||
{Data: ðpb.AttestationData{Slot: 4, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b11110000}},
|
||||
{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b11100000}},
|
||||
{Data: ðpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b11000000}},
|
||||
{Data: ðpb.AttestationData{Slot: 4}, AggregationBits: bitfield.Bitlist{0b11100000}},
|
||||
{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11000000}},
|
||||
{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b11100000}},
|
||||
{Data: ðpb.AttestationData{Slot: 4}, AggregationBits: bitfield.Bitlist{0b11110000}},
|
||||
{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11100000}},
|
||||
{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b11000000}},
|
||||
}
|
||||
sort.Sort(profitableAtts{atts: atts})
|
||||
want := []*ethpb.Attestation{
|
||||
{Data: ðpb.AttestationData{Slot: 4, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b11110000}},
|
||||
{Data: ðpb.AttestationData{Slot: 4, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b11100000}},
|
||||
{Data: ðpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b11000000}},
|
||||
{Data: ðpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b11100000}},
|
||||
{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b11100000}},
|
||||
{Data: ðpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: ðpb.Checkpoint{Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b11000000}},
|
||||
{Data: ðpb.AttestationData{Slot: 4}, AggregationBits: bitfield.Bitlist{0b11110000}},
|
||||
{Data: ðpb.AttestationData{Slot: 4}, AggregationBits: bitfield.Bitlist{0b11100000}},
|
||||
{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b11000000}},
|
||||
{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b11100000}},
|
||||
{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11100000}},
|
||||
{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11000000}},
|
||||
}
|
||||
require.DeepEqual(t, want, atts)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
||||
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/event"
|
||||
"github.com/prysmaticlabs/prysm/shared/mock"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
@@ -119,10 +118,9 @@ func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) {
|
||||
Slot: 4000,
|
||||
Validators: []*ethpb.Validator{
|
||||
{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: pubKey1,
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: pubKey1,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -131,8 +129,7 @@ func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) {
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey1,
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("hey"), 32),
|
||||
Signature: make([]byte, 96),
|
||||
WithdrawalCredentials: []byte("hey"),
|
||||
}
|
||||
domain, err := helpers.ComputeDomain(params.BeaconConfig().DomainDeposit, nil, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
||||
pbp2p "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"
|
||||
@@ -72,8 +71,8 @@ func TestValidatorStatus_Deposited(t *testing.T) {
|
||||
pubKey1 := pubKey(1)
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey1,
|
||||
Signature: bytesutil.PadTo([]byte("hi"), 96),
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("hey"), 32),
|
||||
Signature: []byte("hi"),
|
||||
WithdrawalCredentials: []byte("hey"),
|
||||
}
|
||||
deposit := ðpb.Deposit{
|
||||
Data: depData,
|
||||
@@ -130,11 +129,10 @@ func TestValidatorStatus_Pending(t *testing.T) {
|
||||
require.NoError(t, state.SetSlot(5000))
|
||||
err = state.SetValidators([]*ethpb.Validator{
|
||||
{
|
||||
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: pubKey,
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: pubKey,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -143,8 +141,8 @@ func TestValidatorStatus_Pending(t *testing.T) {
|
||||
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey,
|
||||
Signature: bytesutil.PadTo([]byte("hi"), 96),
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("hey"), 32),
|
||||
Signature: []byte("hi"),
|
||||
WithdrawalCredentials: []byte("hey"),
|
||||
}
|
||||
|
||||
deposit := ðpb.Deposit{
|
||||
@@ -190,8 +188,8 @@ func TestValidatorStatus_Active(t *testing.T) {
|
||||
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey,
|
||||
Signature: bytesutil.PadTo([]byte("hi"), 96),
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("hey"), 32),
|
||||
Signature: []byte("hi"),
|
||||
WithdrawalCredentials: []byte("hey"),
|
||||
}
|
||||
|
||||
deposit := ðpb.Deposit{
|
||||
@@ -281,8 +279,8 @@ func TestValidatorStatus_Exiting(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey,
|
||||
Signature: bytesutil.PadTo([]byte("hi"), 96),
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("hey"), 32),
|
||||
Signature: []byte("hi"),
|
||||
WithdrawalCredentials: []byte("hey"),
|
||||
}
|
||||
|
||||
deposit := ðpb.Deposit{
|
||||
@@ -341,8 +339,8 @@ func TestValidatorStatus_Slashing(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey,
|
||||
Signature: bytesutil.PadTo([]byte("hi"), 96),
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("hey"), 32),
|
||||
Signature: []byte("hi"),
|
||||
WithdrawalCredentials: []byte("hey"),
|
||||
}
|
||||
|
||||
deposit := ðpb.Deposit{
|
||||
@@ -398,15 +396,14 @@ func TestValidatorStatus_Exited(t *testing.T) {
|
||||
state := testutil.NewBeaconState()
|
||||
require.NoError(t, state.SetSlot(slot))
|
||||
err = state.SetValidators([]*ethpb.Validator{{
|
||||
PublicKey: pubKey,
|
||||
WithdrawableEpoch: epoch + 1,
|
||||
WithdrawalCredentials: make([]byte, 32)},
|
||||
PublicKey: pubKey,
|
||||
WithdrawableEpoch: epoch + 1},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey,
|
||||
Signature: bytesutil.PadTo([]byte("hi"), 96),
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("hey"), 32),
|
||||
Signature: []byte("hi"),
|
||||
WithdrawalCredentials: []byte("hey"),
|
||||
}
|
||||
|
||||
deposit := ðpb.Deposit{
|
||||
@@ -566,46 +563,40 @@ func TestValidatorStatus_CorrectActivationQueue(t *testing.T) {
|
||||
// Pending active because activation epoch is still defaulted at far future slot.
|
||||
validators := []*ethpb.Validator{
|
||||
{
|
||||
ActivationEpoch: 0,
|
||||
PublicKey: pubKey(0),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
ActivationEpoch: 0,
|
||||
PublicKey: pubKey(0),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
{
|
||||
ActivationEpoch: 0,
|
||||
PublicKey: pubKey(1),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
ActivationEpoch: 0,
|
||||
PublicKey: pubKey(1),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
{
|
||||
ActivationEpoch: 0,
|
||||
PublicKey: pubKey(2),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
ActivationEpoch: 0,
|
||||
PublicKey: pubKey(2),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
{
|
||||
ActivationEpoch: 0,
|
||||
PublicKey: pubKey(3),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
ActivationEpoch: 0,
|
||||
PublicKey: pubKey(3),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
{
|
||||
ActivationEpoch: currentSlot/params.BeaconConfig().SlotsPerEpoch + 1,
|
||||
PublicKey: pbKey,
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
ActivationEpoch: currentSlot/params.BeaconConfig().SlotsPerEpoch + 1,
|
||||
PublicKey: pbKey,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
{
|
||||
ActivationEpoch: currentSlot/params.BeaconConfig().SlotsPerEpoch + 4,
|
||||
PublicKey: pubKey(5),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
ActivationEpoch: currentSlot/params.BeaconConfig().SlotsPerEpoch + 4,
|
||||
PublicKey: pubKey(5),
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
}
|
||||
state := testutil.NewBeaconState()
|
||||
@@ -622,8 +613,8 @@ func TestValidatorStatus_CorrectActivationQueue(t *testing.T) {
|
||||
for i := 0; i < 6; i++ {
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey(uint64(i)),
|
||||
Signature: bytesutil.PadTo([]byte("hi"), 96),
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("hey"), 32),
|
||||
Signature: []byte("hi"),
|
||||
WithdrawalCredentials: []byte("hey"),
|
||||
}
|
||||
|
||||
deposit := ðpb.Deposit{
|
||||
@@ -664,8 +655,8 @@ func TestDepositBlockSlotAfterGenesisTime(t *testing.T) {
|
||||
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey,
|
||||
Signature: bytesutil.PadTo([]byte("hi"), 96),
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("hey"), 32),
|
||||
Signature: []byte("hi"),
|
||||
WithdrawalCredentials: []byte("hey"),
|
||||
}
|
||||
|
||||
deposit := ðpb.Deposit{
|
||||
@@ -727,8 +718,8 @@ func TestDepositBlockSlotBeforeGenesisTime(t *testing.T) {
|
||||
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey,
|
||||
Signature: bytesutil.PadTo([]byte("hi"), 96),
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("hey"), 32),
|
||||
Signature: []byte("hi"),
|
||||
WithdrawalCredentials: []byte("hey"),
|
||||
}
|
||||
|
||||
deposit := ðpb.Deposit{
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
@@ -159,7 +160,7 @@ func TestBeaconState_HashTreeRoot(t *testing.T) {
|
||||
if err == nil && tt.error != "" {
|
||||
t.Errorf("Expected error, expected %v, recevied %v", tt.error, err)
|
||||
}
|
||||
genericHTR, err := testState.InnerStateUnsafe().HashTreeRoot()
|
||||
genericHTR, err := ssz.HashTreeRoot(testState.InnerStateUnsafe())
|
||||
if err == nil && tt.error != "" {
|
||||
t.Errorf("Expected error, expected %v, recevied %v", tt.error, err)
|
||||
}
|
||||
@@ -230,7 +231,7 @@ func TestBeaconState_HashTreeRoot_FieldTrie(t *testing.T) {
|
||||
if err == nil && tt.error != "" {
|
||||
t.Errorf("Expected error, expected %v, recevied %v", tt.error, err)
|
||||
}
|
||||
genericHTR, err := testState.InnerStateUnsafe().HashTreeRoot()
|
||||
genericHTR, err := ssz.HashTreeRoot(testState.InnerStateUnsafe())
|
||||
if err == nil && tt.error != "" {
|
||||
t.Errorf("Expected error, expected %v, recevied %v", tt.error, err)
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ go_test(
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
@@ -57,7 +58,7 @@ func TestLoadStateByRoot_CanGet(t *testing.T) {
|
||||
service.slotsPerArchivedPoint = 1
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
blkRoot, err := stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.beaconDB.SaveGenesisBlockRoot(ctx, blkRoot))
|
||||
@@ -83,7 +84,7 @@ func TestLoadColdStateBySlot_CanGet(t *testing.T) {
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
blkRoot, err := stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.beaconDB.SaveGenesisBlockRoot(ctx, blkRoot))
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
@@ -23,8 +24,7 @@ func TestStateByRoot_ColdState(t *testing.T) {
|
||||
service.finalizedInfo.slot = 2
|
||||
service.slotsPerArchivedPoint = 1
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 1
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
bRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -55,7 +55,7 @@ func TestStateByRoot_HotStateUsingEpochBoundaryCacheNoReplay(t *testing.T) {
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
require.NoError(t, beaconState.SetSlot(10))
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
blkRoot, err := stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{Root: blkRoot[:]}))
|
||||
@@ -72,15 +72,12 @@ func TestStateByRoot_HotStateUsingEpochBoundaryCacheWithReplay(t *testing.T) {
|
||||
service := New(db, ssc)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
blkRoot, err := stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.epochBoundaryStateCache.put(blkRoot, beaconState))
|
||||
targetSlot := uint64(10)
|
||||
targetBlock := testutil.NewBeaconBlock()
|
||||
targetBlock.Block.Slot = 11
|
||||
targetBlock.Block.ParentRoot = blkRoot[:]
|
||||
targetBlock.Block.ProposerIndex = 8
|
||||
targetBlock := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 11, ParentRoot: blkRoot[:], ProposerIndex: 8}}
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, targetBlock))
|
||||
targetRoot, err := stateutil.BlockRoot(targetBlock.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -122,7 +119,7 @@ func TestStateByRootInitialSync_UseEpochStateCache(t *testing.T) {
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
targetSlot := uint64(10)
|
||||
require.NoError(t, beaconState.SetSlot(targetSlot))
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
blkRoot, err := stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.epochBoundaryStateCache.put(blkRoot, beaconState))
|
||||
@@ -158,14 +155,12 @@ func TestStateByRootInitialSync_CanProcessUpTo(t *testing.T) {
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
blkRoot, err := stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.epochBoundaryStateCache.put(blkRoot, beaconState))
|
||||
targetSlot := uint64(10)
|
||||
targetBlk := testutil.NewBeaconBlock()
|
||||
targetBlk.Block.Slot = 11
|
||||
targetBlk.Block.ParentRoot = blkRoot[:]
|
||||
targetBlk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 11, ParentRoot: blkRoot[:]}}
|
||||
targetRoot, err := stateutil.BlockRoot(targetBlk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, targetBlk))
|
||||
@@ -191,8 +186,7 @@ func TestStateBySlot_ColdState(t *testing.T) {
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
require.NoError(t, beaconState.SetSlot(1))
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 1
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
bRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -220,7 +214,7 @@ func TestStateBySlot_HotStateDB(t *testing.T) {
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
bRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
@@ -64,7 +66,7 @@ func TestSaveHotState_NoSaveNotEpochBoundary(t *testing.T) {
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch-1))
|
||||
r := [32]byte{'A'}
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -101,15 +103,12 @@ func TestLoadHoteStateByRoot_EpochBoundaryStateCanProcess(t *testing.T) {
|
||||
service := New(db, ssc)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
gBlk := testutil.NewBeaconBlock()
|
||||
gBlk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
gBlkRoot, err := stateutil.BlockRoot(gBlk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.epochBoundaryStateCache.put(gBlkRoot, beaconState))
|
||||
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.Slot = 11
|
||||
blk.Block.ProposerIndex = 8
|
||||
blk.Block.ParentRoot = gBlkRoot[:]
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 11, ParentRoot: gBlkRoot[:], ProposerIndex: 8}}
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, blk))
|
||||
blkRoot, err := stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -132,7 +131,7 @@ func TestLoadHoteStateByRoot_FromDBBoundaryCase(t *testing.T) {
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
blkRoot, err := stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.epochBoundaryStateCache.put(blkRoot, beaconState))
|
||||
@@ -156,7 +155,7 @@ func TestLoadHoteStateBySlot_CanAdvanceSlotUsingDB(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
b := testutil.NewBeaconBlock()
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, b))
|
||||
gRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -176,22 +175,22 @@ func TestLastAncestorState_CanGetUsingDB(t *testing.T) {
|
||||
|
||||
b0 := testutil.NewBeaconBlock()
|
||||
b0.Block.ParentRoot = bytesutil.PadTo([]byte{'a'}, 32)
|
||||
r0, err := b0.Block.HashTreeRoot()
|
||||
r0, err := ssz.HashTreeRoot(b0.Block)
|
||||
require.NoError(t, err)
|
||||
b1 := testutil.NewBeaconBlock()
|
||||
b1.Block.Slot = 1
|
||||
b1.Block.ParentRoot = bytesutil.PadTo(r0[:], 32)
|
||||
r1, err := b1.Block.HashTreeRoot()
|
||||
r1, err := ssz.HashTreeRoot(b1.Block)
|
||||
require.NoError(t, err)
|
||||
b2 := testutil.NewBeaconBlock()
|
||||
b2.Block.Slot = 2
|
||||
b2.Block.ParentRoot = bytesutil.PadTo(r1[:], 32)
|
||||
r2, err := b2.Block.HashTreeRoot()
|
||||
r2, err := ssz.HashTreeRoot(b2.Block)
|
||||
require.NoError(t, err)
|
||||
b3 := testutil.NewBeaconBlock()
|
||||
b3.Block.Slot = 3
|
||||
b3.Block.ParentRoot = bytesutil.PadTo(r2[:], 32)
|
||||
r3, err := b3.Block.HashTreeRoot()
|
||||
r3, err := ssz.HashTreeRoot(b3.Block)
|
||||
require.NoError(t, err)
|
||||
|
||||
b1State := testutil.NewBeaconState()
|
||||
@@ -215,22 +214,22 @@ func TestLastAncestorState_CanGetUsingHotCache(t *testing.T) {
|
||||
|
||||
b0 := testutil.NewBeaconBlock()
|
||||
b0.Block.ParentRoot = bytesutil.PadTo([]byte{'a'}, 32)
|
||||
r0, err := b0.Block.HashTreeRoot()
|
||||
r0, err := ssz.HashTreeRoot(b0.Block)
|
||||
require.NoError(t, err)
|
||||
b1 := testutil.NewBeaconBlock()
|
||||
b1.Block.Slot = 1
|
||||
b1.Block.ParentRoot = bytesutil.PadTo(r0[:], 32)
|
||||
r1, err := b1.Block.HashTreeRoot()
|
||||
r1, err := ssz.HashTreeRoot(b1.Block)
|
||||
require.NoError(t, err)
|
||||
b2 := testutil.NewBeaconBlock()
|
||||
b2.Block.Slot = 2
|
||||
b2.Block.ParentRoot = bytesutil.PadTo(r1[:], 32)
|
||||
r2, err := b2.Block.HashTreeRoot()
|
||||
r2, err := ssz.HashTreeRoot(b2.Block)
|
||||
require.NoError(t, err)
|
||||
b3 := testutil.NewBeaconBlock()
|
||||
b3.Block.Slot = 3
|
||||
b3.Block.ParentRoot = bytesutil.PadTo(r2[:], 32)
|
||||
r3, err := b3.Block.HashTreeRoot()
|
||||
r3, err := ssz.HashTreeRoot(b3.Block)
|
||||
require.NoError(t, err)
|
||||
|
||||
b1State := testutil.NewBeaconState()
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
@@ -19,8 +20,7 @@ func TestMigrateToCold_CanSaveFinalizedInfo(t *testing.T) {
|
||||
db, c := testDB.SetupDB(t)
|
||||
service := New(db, c)
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 1
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
br, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, b))
|
||||
@@ -41,8 +41,7 @@ func TestMigrateToCold_HappyPath(t *testing.T) {
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
stateSlot := uint64(1)
|
||||
require.NoError(t, beaconState.SetSlot(stateSlot))
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 2
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 2}}
|
||||
fRoot, err := stateutil.BlockRoot(b.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, b))
|
||||
@@ -71,8 +70,7 @@ func TestMigrateToCold_RegeneratePath(t *testing.T) {
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
stateSlot := uint64(1)
|
||||
require.NoError(t, beaconState.SetSlot(stateSlot))
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.Slot = 2
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 2}}
|
||||
fRoot, err := stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, blk))
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
@@ -25,7 +26,7 @@ func TestComputeStateUpToSlot_GenesisState(t *testing.T) {
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
|
||||
gBlk := testutil.NewBeaconBlock()
|
||||
gBlk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
gRoot, err := stateutil.BlockRoot(gBlk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, gBlk))
|
||||
@@ -47,7 +48,7 @@ func TestComputeStateUpToSlot_CanProcessUpTo(t *testing.T) {
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
|
||||
gBlk := testutil.NewBeaconBlock()
|
||||
gBlk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
gRoot, err := stateutil.BlockRoot(gBlk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, gBlk))
|
||||
@@ -155,7 +156,7 @@ func TestLoadBlocks_SecondBranch(t *testing.T) {
|
||||
beaconDB: db,
|
||||
}
|
||||
|
||||
roots, savedBlocks, err := tree1(db, bytesutil.PadTo([]byte{'A'}, 32))
|
||||
roots, savedBlocks, err := tree1(db, []byte{'A'})
|
||||
require.NoError(t, err)
|
||||
|
||||
filteredBlocks, err := s.LoadBlocks(ctx, 0, 5, roots[5])
|
||||
@@ -182,7 +183,7 @@ func TestLoadBlocks_ThirdBranch(t *testing.T) {
|
||||
beaconDB: db,
|
||||
}
|
||||
|
||||
roots, savedBlocks, err := tree1(db, bytesutil.PadTo([]byte{'A'}, 32))
|
||||
roots, savedBlocks, err := tree1(db, []byte{'A'})
|
||||
require.NoError(t, err)
|
||||
|
||||
filteredBlocks, err := s.LoadBlocks(ctx, 0, 7, roots[7])
|
||||
@@ -211,7 +212,7 @@ func TestLoadBlocks_SameSlots(t *testing.T) {
|
||||
beaconDB: db,
|
||||
}
|
||||
|
||||
roots, savedBlocks, err := tree2(db, bytesutil.PadTo([]byte{'A'}, 32))
|
||||
roots, savedBlocks, err := tree2(db, []byte{'A'})
|
||||
require.NoError(t, err)
|
||||
|
||||
filteredBlocks, err := s.LoadBlocks(ctx, 0, 3, roots[6])
|
||||
@@ -303,7 +304,7 @@ func TestLastSavedBlock_Genesis(t *testing.T) {
|
||||
finalizedInfo: &finalizedInfo{slot: 128},
|
||||
}
|
||||
|
||||
gBlk := testutil.NewBeaconBlock()
|
||||
gBlk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
gRoot, err := stateutil.BlockRoot(gBlk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, s.beaconDB.SaveBlock(ctx, gBlk))
|
||||
@@ -323,14 +324,11 @@ func TestLastSavedBlock_CanGet(t *testing.T) {
|
||||
finalizedInfo: &finalizedInfo{slot: 128},
|
||||
}
|
||||
|
||||
b1 := testutil.NewBeaconBlock()
|
||||
b1.Block.Slot = s.finalizedInfo.slot + 5
|
||||
b1 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: s.finalizedInfo.slot + 5}}
|
||||
require.NoError(t, s.beaconDB.SaveBlock(ctx, b1))
|
||||
b2 := testutil.NewBeaconBlock()
|
||||
b2.Block.Slot = s.finalizedInfo.slot + 10
|
||||
b2 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: s.finalizedInfo.slot + 10}}
|
||||
require.NoError(t, s.beaconDB.SaveBlock(ctx, b2))
|
||||
b3 := testutil.NewBeaconBlock()
|
||||
b3.Block.Slot = s.finalizedInfo.slot + 20
|
||||
b3 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: s.finalizedInfo.slot + 20}}
|
||||
require.NoError(t, s.beaconDB.SaveBlock(ctx, b3))
|
||||
|
||||
savedRoot, savedSlot, err := s.lastSavedBlock(ctx, s.finalizedInfo.slot+100)
|
||||
@@ -364,7 +362,7 @@ func TestLastSavedState_Genesis(t *testing.T) {
|
||||
finalizedInfo: &finalizedInfo{slot: 128},
|
||||
}
|
||||
|
||||
gBlk := testutil.NewBeaconBlock()
|
||||
gBlk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
gState := testutil.NewBeaconState()
|
||||
gRoot, err := stateutil.BlockRoot(gBlk.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -385,11 +383,9 @@ func TestLastSavedState_CanGet(t *testing.T) {
|
||||
finalizedInfo: &finalizedInfo{slot: 128},
|
||||
}
|
||||
|
||||
b1 := testutil.NewBeaconBlock()
|
||||
b1.Block.Slot = s.finalizedInfo.slot + 5
|
||||
b1 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: s.finalizedInfo.slot + 5}}
|
||||
require.NoError(t, s.beaconDB.SaveBlock(ctx, b1))
|
||||
b2 := testutil.NewBeaconBlock()
|
||||
b2.Block.Slot = s.finalizedInfo.slot + 10
|
||||
b2 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: s.finalizedInfo.slot + 10}}
|
||||
require.NoError(t, s.beaconDB.SaveBlock(ctx, b2))
|
||||
b2Root, err := stateutil.BlockRoot(b2.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -397,8 +393,7 @@ func TestLastSavedState_CanGet(t *testing.T) {
|
||||
require.NoError(t, st.SetSlot(s.finalizedInfo.slot+10))
|
||||
|
||||
require.NoError(t, s.beaconDB.SaveState(ctx, st, b2Root))
|
||||
b3 := testutil.NewBeaconBlock()
|
||||
b3.Block.Slot = s.finalizedInfo.slot + 20
|
||||
b3 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: s.finalizedInfo.slot + 20}}
|
||||
require.NoError(t, s.beaconDB.SaveBlock(ctx, b3))
|
||||
|
||||
savedState, err := s.lastSavedState(ctx, s.finalizedInfo.slot+100)
|
||||
@@ -416,8 +411,7 @@ func TestLastSavedState_NoSavedBlockState(t *testing.T) {
|
||||
finalizedInfo: &finalizedInfo{slot: 128},
|
||||
}
|
||||
|
||||
b1 := testutil.NewBeaconBlock()
|
||||
b1.Block.Slot = 127
|
||||
b1 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 127}}
|
||||
require.NoError(t, s.beaconDB.SaveBlock(ctx, b1))
|
||||
|
||||
_, err := s.lastSavedState(ctx, s.finalizedInfo.slot+1)
|
||||
@@ -471,76 +465,58 @@ func TestProcessStateUpToSlot_CanProcess(t *testing.T) {
|
||||
// \- B2 -- B4 -- B6 ----- B8
|
||||
// \- B7
|
||||
func tree1(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.SignedBeaconBlock, error) {
|
||||
b0 := testutil.NewBeaconBlock()
|
||||
b0.Block.Slot = 0
|
||||
b0.Block.ParentRoot = genesisRoot
|
||||
r0, err := b0.Block.HashTreeRoot()
|
||||
b0 := ðpb.BeaconBlock{Slot: 0, ParentRoot: genesisRoot}
|
||||
r0, err := ssz.HashTreeRoot(b0)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b1 := testutil.NewBeaconBlock()
|
||||
b1.Block.Slot = 1
|
||||
b1.Block.ParentRoot = r0[:]
|
||||
r1, err := b1.Block.HashTreeRoot()
|
||||
b1 := ðpb.BeaconBlock{Slot: 1, ParentRoot: r0[:]}
|
||||
r1, err := ssz.HashTreeRoot(b1)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b2 := testutil.NewBeaconBlock()
|
||||
b2.Block.Slot = 2
|
||||
b2.Block.ParentRoot = r1[:]
|
||||
r2, err := b2.Block.HashTreeRoot()
|
||||
b2 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:]}
|
||||
r2, err := ssz.HashTreeRoot(b2)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b3 := testutil.NewBeaconBlock()
|
||||
b3.Block.Slot = 3
|
||||
b3.Block.ParentRoot = r1[:]
|
||||
r3, err := b3.Block.HashTreeRoot()
|
||||
b3 := ðpb.BeaconBlock{Slot: 3, ParentRoot: r1[:]}
|
||||
r3, err := ssz.HashTreeRoot(b3)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b4 := testutil.NewBeaconBlock()
|
||||
b4.Block.Slot = 4
|
||||
b4.Block.ParentRoot = r2[:]
|
||||
r4, err := b4.Block.HashTreeRoot()
|
||||
b4 := ðpb.BeaconBlock{Slot: 4, ParentRoot: r2[:]}
|
||||
r4, err := ssz.HashTreeRoot(b4)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b5 := testutil.NewBeaconBlock()
|
||||
b5.Block.Slot = 5
|
||||
b5.Block.ParentRoot = r3[:]
|
||||
r5, err := b5.Block.HashTreeRoot()
|
||||
b5 := ðpb.BeaconBlock{Slot: 5, ParentRoot: r3[:]}
|
||||
r5, err := ssz.HashTreeRoot(b5)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b6 := testutil.NewBeaconBlock()
|
||||
b6.Block.Slot = 6
|
||||
b6.Block.ParentRoot = r4[:]
|
||||
r6, err := b6.Block.HashTreeRoot()
|
||||
b6 := ðpb.BeaconBlock{Slot: 6, ParentRoot: r4[:]}
|
||||
r6, err := ssz.HashTreeRoot(b6)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b7 := testutil.NewBeaconBlock()
|
||||
b7.Block.Slot = 7
|
||||
b7.Block.ParentRoot = r6[:]
|
||||
r7, err := b7.Block.HashTreeRoot()
|
||||
b7 := ðpb.BeaconBlock{Slot: 7, ParentRoot: r6[:]}
|
||||
r7, err := ssz.HashTreeRoot(b7)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b8 := testutil.NewBeaconBlock()
|
||||
b8.Block.Slot = 8
|
||||
b8.Block.ParentRoot = r6[:]
|
||||
r8, err := b8.Block.HashTreeRoot()
|
||||
b8 := ðpb.BeaconBlock{Slot: 8, ParentRoot: r6[:]}
|
||||
r8, err := ssz.HashTreeRoot(b8)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
st := testutil.NewBeaconState()
|
||||
|
||||
returnedBlocks := make([]*ethpb.SignedBeaconBlock, 0)
|
||||
for _, b := range []*ethpb.SignedBeaconBlock{b0, b1, b2, b3, b4, b5, b6, b7, b8} {
|
||||
for _, b := range []*ethpb.BeaconBlock{b0, b1, b2, b3, b4, b5, b6, b7, b8} {
|
||||
beaconBlock := testutil.NewBeaconBlock()
|
||||
beaconBlock.Block.Slot = b.Block.Slot
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.Block.ParentRoot, 32)
|
||||
beaconBlock.Block.Slot = b.Slot
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.ParentRoot, 32)
|
||||
if err := db.SaveBlock(context.Background(), beaconBlock); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -559,67 +535,49 @@ func tree1(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.SignedBeaco
|
||||
// \- B2
|
||||
// \- B2 -- B3
|
||||
func tree2(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.SignedBeaconBlock, error) {
|
||||
b0 := testutil.NewBeaconBlock()
|
||||
b0.Block.Slot = 0
|
||||
b0.Block.ParentRoot = genesisRoot
|
||||
r0, err := b0.Block.HashTreeRoot()
|
||||
b0 := ðpb.BeaconBlock{Slot: 0, ParentRoot: genesisRoot}
|
||||
r0, err := ssz.HashTreeRoot(b0)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b1 := testutil.NewBeaconBlock()
|
||||
b1.Block.Slot = 1
|
||||
b1.Block.ParentRoot = r0[:]
|
||||
r1, err := b1.Block.HashTreeRoot()
|
||||
b1 := ðpb.BeaconBlock{Slot: 1, ParentRoot: r0[:]}
|
||||
r1, err := ssz.HashTreeRoot(b1)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b21 := testutil.NewBeaconBlock()
|
||||
b21.Block.Slot = 2
|
||||
b21.Block.ParentRoot = r1[:]
|
||||
b21.Block.StateRoot = bytesutil.PadTo([]byte{'A'}, 32)
|
||||
r21, err := b21.Block.HashTreeRoot()
|
||||
b21 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'A'}}
|
||||
r21, err := ssz.HashTreeRoot(b21)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b22 := testutil.NewBeaconBlock()
|
||||
b22.Block.Slot = 2
|
||||
b22.Block.ParentRoot = r1[:]
|
||||
b22.Block.StateRoot = bytesutil.PadTo([]byte{'B'}, 32)
|
||||
r22, err := b22.Block.HashTreeRoot()
|
||||
b22 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'B'}}
|
||||
r22, err := ssz.HashTreeRoot(b22)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b23 := testutil.NewBeaconBlock()
|
||||
b23.Block.Slot = 2
|
||||
b23.Block.ParentRoot = r1[:]
|
||||
b23.Block.StateRoot = bytesutil.PadTo([]byte{'C'}, 32)
|
||||
r23, err := b23.Block.HashTreeRoot()
|
||||
b23 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'C'}}
|
||||
r23, err := ssz.HashTreeRoot(b23)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b24 := testutil.NewBeaconBlock()
|
||||
b24.Block.Slot = 2
|
||||
b24.Block.ParentRoot = r1[:]
|
||||
b24.Block.StateRoot = bytesutil.PadTo([]byte{'D'}, 32)
|
||||
r24, err := b24.Block.HashTreeRoot()
|
||||
b24 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'D'}}
|
||||
r24, err := ssz.HashTreeRoot(b24)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b3 := testutil.NewBeaconBlock()
|
||||
b3.Block.Slot = 3
|
||||
b3.Block.ParentRoot = r24[:]
|
||||
r3, err := b3.Block.HashTreeRoot()
|
||||
b3 := ðpb.BeaconBlock{Slot: 3, ParentRoot: r24[:]}
|
||||
r3, err := ssz.HashTreeRoot(b3)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
st := testutil.NewBeaconState()
|
||||
|
||||
returnedBlocks := make([]*ethpb.SignedBeaconBlock, 0)
|
||||
for _, b := range []*ethpb.SignedBeaconBlock{b0, b1, b21, b22, b23, b24, b3} {
|
||||
for _, b := range []*ethpb.BeaconBlock{b0, b1, b21, b22, b23, b24, b3} {
|
||||
beaconBlock := testutil.NewBeaconBlock()
|
||||
beaconBlock.Block.Slot = b.Block.Slot
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.Block.ParentRoot, 32)
|
||||
beaconBlock.Block.StateRoot = bytesutil.PadTo(b.Block.StateRoot, 32)
|
||||
beaconBlock.Block.Slot = b.Slot
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.ParentRoot, 32)
|
||||
beaconBlock.Block.StateRoot = bytesutil.PadTo(b.StateRoot, 32)
|
||||
if err := db.SaveBlock(context.Background(), beaconBlock); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -638,60 +596,44 @@ func tree2(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.SignedBeaco
|
||||
// \- B2
|
||||
// \- B2
|
||||
func tree3(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.SignedBeaconBlock, error) {
|
||||
b0 := testutil.NewBeaconBlock()
|
||||
b0.Block.Slot = 0
|
||||
b0.Block.ParentRoot = genesisRoot
|
||||
r0, err := b0.Block.HashTreeRoot()
|
||||
b0 := ðpb.BeaconBlock{Slot: 0, ParentRoot: genesisRoot}
|
||||
r0, err := ssz.HashTreeRoot(b0)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b1 := testutil.NewBeaconBlock()
|
||||
b1.Block.Slot = 1
|
||||
b1.Block.ParentRoot = r0[:]
|
||||
r1, err := b1.Block.HashTreeRoot()
|
||||
b1 := ðpb.BeaconBlock{Slot: 1, ParentRoot: r0[:]}
|
||||
r1, err := ssz.HashTreeRoot(b1)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b21 := testutil.NewBeaconBlock()
|
||||
b21.Block.Slot = 2
|
||||
b21.Block.ParentRoot = r1[:]
|
||||
b21.Block.StateRoot = bytesutil.PadTo([]byte{'A'}, 32)
|
||||
r21, err := b21.Block.HashTreeRoot()
|
||||
b21 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'A'}}
|
||||
r21, err := ssz.HashTreeRoot(b21)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b22 := testutil.NewBeaconBlock()
|
||||
b22.Block.Slot = 2
|
||||
b22.Block.ParentRoot = r1[:]
|
||||
b22.Block.StateRoot = bytesutil.PadTo([]byte{'B'}, 32)
|
||||
r22, err := b22.Block.HashTreeRoot()
|
||||
b22 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'B'}}
|
||||
r22, err := ssz.HashTreeRoot(b22)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b23 := testutil.NewBeaconBlock()
|
||||
b23.Block.Slot = 2
|
||||
b23.Block.ParentRoot = r1[:]
|
||||
b23.Block.StateRoot = bytesutil.PadTo([]byte{'C'}, 32)
|
||||
r23, err := b23.Block.HashTreeRoot()
|
||||
b23 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'C'}}
|
||||
r23, err := ssz.HashTreeRoot(b23)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b24 := testutil.NewBeaconBlock()
|
||||
b24.Block.Slot = 2
|
||||
b24.Block.ParentRoot = r1[:]
|
||||
b24.Block.StateRoot = bytesutil.PadTo([]byte{'D'}, 32)
|
||||
r24, err := b24.Block.HashTreeRoot()
|
||||
b24 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'D'}}
|
||||
r24, err := ssz.HashTreeRoot(b24)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
st := testutil.NewBeaconState()
|
||||
|
||||
returnedBlocks := make([]*ethpb.SignedBeaconBlock, 0)
|
||||
for _, b := range []*ethpb.SignedBeaconBlock{b0, b1, b21, b22, b23, b24} {
|
||||
for _, b := range []*ethpb.BeaconBlock{b0, b1, b21, b22, b23, b24} {
|
||||
beaconBlock := testutil.NewBeaconBlock()
|
||||
beaconBlock.Block.Slot = b.Block.Slot
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.Block.ParentRoot, 32)
|
||||
beaconBlock.Block.StateRoot = bytesutil.PadTo(b.Block.StateRoot, 32)
|
||||
beaconBlock.Block.Slot = b.Slot
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.ParentRoot, 32)
|
||||
beaconBlock.Block.StateRoot = bytesutil.PadTo(b.StateRoot, 32)
|
||||
if err := db.SaveBlock(context.Background(), beaconBlock); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -711,53 +653,39 @@ func tree3(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.SignedBeaco
|
||||
// \- B2
|
||||
// \- B2
|
||||
func tree4(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.SignedBeaconBlock, error) {
|
||||
b0 := testutil.NewBeaconBlock()
|
||||
b0.Block.Slot = 0
|
||||
b0.Block.ParentRoot = genesisRoot
|
||||
r0, err := b0.Block.HashTreeRoot()
|
||||
b0 := ðpb.BeaconBlock{Slot: 0, ParentRoot: genesisRoot}
|
||||
r0, err := ssz.HashTreeRoot(b0)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b21 := testutil.NewBeaconBlock()
|
||||
b21.Block.Slot = 2
|
||||
b21.Block.ParentRoot = r0[:]
|
||||
b21.Block.StateRoot = bytesutil.PadTo([]byte{'A'}, 32)
|
||||
r21, err := b21.Block.HashTreeRoot()
|
||||
b21 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r0[:], StateRoot: []byte{'A'}}
|
||||
r21, err := ssz.HashTreeRoot(b21)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b22 := testutil.NewBeaconBlock()
|
||||
b22.Block.Slot = 2
|
||||
b22.Block.ParentRoot = r0[:]
|
||||
b22.Block.StateRoot = bytesutil.PadTo([]byte{'B'}, 32)
|
||||
r22, err := b22.Block.HashTreeRoot()
|
||||
b22 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r0[:], StateRoot: []byte{'B'}}
|
||||
r22, err := ssz.HashTreeRoot(b22)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b23 := testutil.NewBeaconBlock()
|
||||
b23.Block.Slot = 2
|
||||
b23.Block.ParentRoot = r0[:]
|
||||
b23.Block.StateRoot = bytesutil.PadTo([]byte{'C'}, 32)
|
||||
r23, err := b23.Block.HashTreeRoot()
|
||||
b23 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r0[:], StateRoot: []byte{'C'}}
|
||||
r23, err := ssz.HashTreeRoot(b23)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b24 := testutil.NewBeaconBlock()
|
||||
b24.Block.Slot = 2
|
||||
b24.Block.ParentRoot = r0[:]
|
||||
b24.Block.StateRoot = bytesutil.PadTo([]byte{'D'}, 32)
|
||||
r24, err := b24.Block.HashTreeRoot()
|
||||
b24 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r0[:], StateRoot: []byte{'D'}}
|
||||
r24, err := ssz.HashTreeRoot(b24)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
st := testutil.NewBeaconState()
|
||||
|
||||
returnedBlocks := make([]*ethpb.SignedBeaconBlock, 0)
|
||||
for _, b := range []*ethpb.SignedBeaconBlock{b0, b21, b22, b23, b24} {
|
||||
for _, b := range []*ethpb.BeaconBlock{b0, b21, b22, b23, b24} {
|
||||
beaconBlock := testutil.NewBeaconBlock()
|
||||
beaconBlock.Block.Slot = b.Block.Slot
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.Block.ParentRoot, 32)
|
||||
beaconBlock.Block.StateRoot = bytesutil.PadTo(b.Block.StateRoot, 32)
|
||||
beaconBlock.Block.Slot = b.Slot
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.ParentRoot, 32)
|
||||
beaconBlock.Block.StateRoot = bytesutil.PadTo(b.StateRoot, 32)
|
||||
if err := db.SaveBlock(context.Background(), beaconBlock); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -776,11 +704,10 @@ func TestLoadFinalizedBlocks(t *testing.T) {
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
}
|
||||
gBlock := testutil.NewBeaconBlock()
|
||||
gBlock := ðpb.SignedBeaconBlock{}
|
||||
gRoot, err := stateutil.BlockRoot(gBlock.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveBlock(ctx, gBlock))
|
||||
require.NoError(t, db.SaveGenesisBlockRoot(ctx, [32]byte{}))
|
||||
roots, _, err := tree1(db, gRoot[:])
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ go_test(
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
@@ -23,7 +24,7 @@ func TestAttestationDataRoot_EqualGeneric(t *testing.T) {
|
||||
Epoch: 9,
|
||||
},
|
||||
}
|
||||
genericHtr, err := attData.HashTreeRoot()
|
||||
genericHtr, err := ssz.HashTreeRoot(attData)
|
||||
require.NoError(t, err)
|
||||
dataHtr, err := AttestationDataRoot(attData)
|
||||
require.NoError(t, err)
|
||||
@@ -49,7 +50,7 @@ func BenchmarkAttestationDataRoot(b *testing.B) {
|
||||
}
|
||||
b.Run("generic", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := attData.HashTreeRoot()
|
||||
_, err := ssz.HashTreeRoot(attData)
|
||||
require.NoError(b, err)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
@@ -14,14 +15,14 @@ func TestBlockRoot(t *testing.T) {
|
||||
genState, keys := testutil.DeterministicGenesisState(t, 100)
|
||||
blk, err := testutil.GenerateFullBlock(genState, keys, testutil.DefaultBlockGenConfig(), 10)
|
||||
require.NoError(t, err)
|
||||
expectedRoot, err := blk.Block.HashTreeRoot()
|
||||
expectedRoot, err := ssz.HashTreeRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
receivedRoot, err := stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedRoot, receivedRoot)
|
||||
blk, err = testutil.GenerateFullBlock(genState, keys, testutil.DefaultBlockGenConfig(), 100)
|
||||
require.NoError(t, err)
|
||||
expectedRoot, err = blk.Block.HashTreeRoot()
|
||||
expectedRoot, err = ssz.HashTreeRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
receivedRoot, err = stateutil.BlockRoot(blk.Block)
|
||||
require.NoError(t, err)
|
||||
@@ -29,15 +30,7 @@ func TestBlockRoot(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBlockBodyRoot_NilIsSameAsEmpty(t *testing.T) {
|
||||
a, err := (ðpb.BeaconBlockBody{
|
||||
RandaoReveal: make([]byte, 96),
|
||||
Graffiti: make([]byte, 32),
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: make([]byte, 32),
|
||||
DepositCount: 0,
|
||||
DepositRoot: make([]byte, 32),
|
||||
},
|
||||
}).HashTreeRoot()
|
||||
a, err := ssz.HashTreeRoot(ðpb.BeaconBlockBody{})
|
||||
require.NoError(t, err)
|
||||
b, err := stateutil.BlockBodyRoot(nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/interop"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
@@ -32,7 +33,7 @@ func BenchmarkHashTreeRoot_Generic_512(b *testing.B) {
|
||||
genesisState := setupGenesisState(b, 512)
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := genesisState.HashTreeRoot()
|
||||
_, err := ssz.HashTreeRoot(genesisState)
|
||||
require.NoError(b, err)
|
||||
}
|
||||
}
|
||||
@@ -42,7 +43,7 @@ func BenchmarkHashTreeRoot_Generic_16384(b *testing.B) {
|
||||
genesisState := setupGenesisState(b, 16384)
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := genesisState.HashTreeRoot()
|
||||
_, err := ssz.HashTreeRoot(genesisState)
|
||||
require.NoError(b, err)
|
||||
}
|
||||
}
|
||||
@@ -52,7 +53,7 @@ func BenchmarkHashTreeRoot_Generic_300000(b *testing.B) {
|
||||
genesisState := setupGenesisState(b, 300000)
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := genesisState.HashTreeRoot()
|
||||
_, err := ssz.HashTreeRoot(genesisState)
|
||||
require.NoError(b, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ go_test(
|
||||
"//beacon-chain/p2p:go_default_library",
|
||||
"//beacon-chain/p2p/peers:go_default_library",
|
||||
"//beacon-chain/p2p/testing:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//beacon-chain/state/stateutil:go_default_library",
|
||||
"//beacon-chain/sync:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
@@ -121,7 +122,6 @@ go_test(
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/roughtime:go_default_library",
|
||||
"//shared/sliceutil:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//p2p/enr:go_default_library",
|
||||
|
||||
@@ -21,11 +21,11 @@ import (
|
||||
p2pm "github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers"
|
||||
p2pt "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
p2ppb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/roughtime"
|
||||
"github.com/prysmaticlabs/prysm/shared/sliceutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -256,10 +256,11 @@ func TestBlocksFetcher_RoundRobin(t *testing.T) {
|
||||
genesisRoot := cache.rootCache[0]
|
||||
cache.RUnlock()
|
||||
|
||||
err := beaconDB.SaveBlock(context.Background(), testutil.NewBeaconBlock())
|
||||
err := beaconDB.SaveBlock(context.Background(), ð.SignedBeaconBlock{Block: ð.BeaconBlock{Slot: 0}})
|
||||
require.NoError(t, err)
|
||||
|
||||
st := testutil.NewBeaconState()
|
||||
st, err := stateTrie.InitializeFromProto(&p2ppb.BeaconState{})
|
||||
require.NoError(t, err)
|
||||
|
||||
mc := &mock.ChainService{
|
||||
State: st,
|
||||
|
||||
@@ -20,16 +20,15 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers"
|
||||
p2pt "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
beaconsync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
|
||||
p2ppb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/roughtime"
|
||||
"github.com/prysmaticlabs/prysm/shared/sliceutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -83,10 +82,11 @@ func initializeTestServices(t *testing.T, blocks []uint64, peers []*peerData) (*
|
||||
genesisRoot := cache.rootCache[0]
|
||||
cache.RUnlock()
|
||||
|
||||
err := beaconDB.SaveBlock(context.Background(), testutil.NewBeaconBlock())
|
||||
err := beaconDB.SaveBlock(context.Background(), ð.SignedBeaconBlock{Block: ð.BeaconBlock{Slot: 0}})
|
||||
require.NoError(t, err)
|
||||
|
||||
st := testutil.NewBeaconState()
|
||||
st, err := stateTrie.InitializeFromProto(&p2ppb.BeaconState{})
|
||||
require.NoError(t, err)
|
||||
|
||||
return &mock.ChainService{
|
||||
State: st,
|
||||
@@ -202,9 +202,12 @@ func connectPeer(t *testing.T, host *p2pt.TestP2P, datum *peerData, peerStatus *
|
||||
cache.RLock()
|
||||
parentRoot := cache.rootCache[cache.parentSlotCache[slot]]
|
||||
cache.RUnlock()
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.Slot = slot
|
||||
blk.Block.ParentRoot = parentRoot[:]
|
||||
blk := ð.SignedBeaconBlock{
|
||||
Block: ð.BeaconBlock{
|
||||
Slot: slot,
|
||||
ParentRoot: parentRoot[:],
|
||||
},
|
||||
}
|
||||
// If forked peer, give a different parent root.
|
||||
if datum.forkedPeer {
|
||||
newRoot := hashutil.Hash(parentRoot[:])
|
||||
@@ -233,7 +236,7 @@ func connectPeer(t *testing.T, host *p2pt.TestP2P, datum *peerData, peerStatus *
|
||||
ForkDigest: params.BeaconConfig().GenesisForkVersion,
|
||||
FinalizedRoot: []byte(fmt.Sprintf("finalized_root %d", datum.finalizedEpoch)),
|
||||
FinalizedEpoch: datum.finalizedEpoch,
|
||||
HeadRoot: bytesutil.PadTo([]byte("head_root"), 32),
|
||||
HeadRoot: []byte("head_root"),
|
||||
HeadSlot: datum.headSlot,
|
||||
})
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user