Update fastssz: Attempt 2 (#7115)

* Revert "Revert "Update fastssz" (#7100)"

This reverts commit b954db9704.
* Preston's patch
* Merge branch 'master' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Update fssz, add regression test case
* more HTR with fssz
* fix some tests
* only one test left
* Make it so that HTR will work
* gofmt, imports
* gofmt, imports
* fix
* Merge branch 'master' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* fix
* Merge branch 'master' into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
* gaz
* Merge branch 'revert-7100-revert-6760-update-fssz' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
* fix test
* Merge branch 'revert-7100-revert-6760-update-fssz' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
This commit is contained in:
Preston Van Loon
2020-08-27 11:13:32 -07:00
committed by GitHub
parent 7d28146e1e
commit b7175b3482
194 changed files with 4696 additions and 3029 deletions

View File

@@ -3,10 +3,10 @@
# #
# This config is loaded from https://github.com/bazelbuild/bazel-toolchains/blob/master/bazelrc/latest.bazelrc # 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 --remote_timeout=3600
build:remote-cache --spawn_strategy=standalone #build:remote-cache --spawn_strategy=standalone
build:remote-cache --strategy=Javac=standalone #build:remote-cache --strategy=Javac=standalone
build:remote-cache --strategy=Closure=standalone #build:remote-cache --strategy=Closure=standalone
build:remote-cache --strategy=Genrule=standalone #build:remote-cache --strategy=Genrule=standalone
# Prysm specific remote-cache properties. # Prysm specific remote-cache properties.
#build:remote-cache --disk_cache= #build:remote-cache --disk_cache=

View File

@@ -41,7 +41,6 @@ go_library(
"//beacon-chain/powchain:go_default_library", "//beacon-chain/powchain:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library", "//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
"//shared/attestationutil:go_default_library", "//shared/attestationutil:go_default_library",
"//shared/bls:go_default_library", "//shared/bls:go_default_library",

View File

@@ -5,14 +5,14 @@ import (
"time" "time"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"go.opencensus.io/trace"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray" "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
"go.opencensus.io/trace"
) )
// ChainInfoFetcher defines a common interface for methods in blockchain service which // ChainInfoFetcher defines a common interface for methods in blockchain service which
@@ -119,7 +119,7 @@ func (s *Service) HeadRoot(ctx context.Context) ([]byte, error) {
return params.BeaconConfig().ZeroHash[:], nil return params.BeaconConfig().ZeroHash[:], nil
} }
r, err := stateutil.BlockRoot(b.Block) r, err := b.Block.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -10,7 +10,9 @@ import (
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" 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/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require" "github.com/prysmaticlabs/prysm/shared/testutil/require"
) )
@@ -37,7 +39,7 @@ func TestHeadRoot_Nil(t *testing.T) {
func TestFinalizedCheckpt_CanRetrieve(t *testing.T) { func TestFinalizedCheckpt_CanRetrieve(t *testing.T) {
db, sc := testDB.SetupDB(t) db, sc := testDB.SetupDB(t)
cp := &ethpb.Checkpoint{Epoch: 5, Root: []byte("foo")} cp := &ethpb.Checkpoint{Epoch: 5, Root: bytesutil.PadTo([]byte("foo"), 32)}
c := setupBeaconChain(t, db, sc) c := setupBeaconChain(t, db, sc)
c.finalizedCheckpt = cp c.finalizedCheckpt = cp
@@ -58,7 +60,7 @@ func TestFinalizedCheckpt_GenesisRootOk(t *testing.T) {
func TestCurrentJustifiedCheckpt_CanRetrieve(t *testing.T) { func TestCurrentJustifiedCheckpt_CanRetrieve(t *testing.T) {
db, sc := testDB.SetupDB(t) db, sc := testDB.SetupDB(t)
cp := &ethpb.Checkpoint{Epoch: 6, Root: []byte("foo")} cp := &ethpb.Checkpoint{Epoch: 6, Root: bytesutil.PadTo([]byte("foo"), 32)}
c := setupBeaconChain(t, db, sc) c := setupBeaconChain(t, db, sc)
c.justifiedCheckpt = cp c.justifiedCheckpt = cp
@@ -79,7 +81,7 @@ func TestJustifiedCheckpt_GenesisRootOk(t *testing.T) {
func TestPreviousJustifiedCheckpt_CanRetrieve(t *testing.T) { func TestPreviousJustifiedCheckpt_CanRetrieve(t *testing.T) {
db, sc := testDB.SetupDB(t) db, sc := testDB.SetupDB(t)
cp := &ethpb.Checkpoint{Epoch: 7, Root: []byte("foo")} cp := &ethpb.Checkpoint{Epoch: 7, Root: bytesutil.PadTo([]byte("foo"), 32)}
c := setupBeaconChain(t, db, sc) c := setupBeaconChain(t, db, sc)
c.prevJustifiedCheckpt = cp c.prevJustifiedCheckpt = cp
assert.Equal(t, cp.Epoch, c.PreviousJustifiedCheckpt().Epoch, "Unexpected previous justified epoch") assert.Equal(t, cp.Epoch, c.PreviousJustifiedCheckpt().Epoch, "Unexpected previous justified epoch")
@@ -111,7 +113,8 @@ func TestHeadRoot_CanRetrieve(t *testing.T) {
} }
func TestHeadBlock_CanRetrieve(t *testing.T) { func TestHeadBlock_CanRetrieve(t *testing.T) {
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 1}} b := testutil.NewBeaconBlock()
b.Block.Slot = 1
s, err := state.InitializeFromProto(&pb.BeaconState{}) s, err := state.InitializeFromProto(&pb.BeaconState{})
require.NoError(t, err) require.NoError(t, err)
c := &Service{} c := &Service{}

View File

@@ -34,7 +34,7 @@ func TestHotStateCache_RoundTrip(t *testing.T) {
func TestHotStateCache_CanPrune(t *testing.T) { func TestHotStateCache_CanPrune(t *testing.T) {
c := newCheckPointInfoCache() c := newCheckPointInfoCache()
for i := 0; i < maxInfoSize+1; i++ { for i := 0; i < maxInfoSize+1; i++ {
cp := &ethpb.Checkpoint{Epoch: uint64(i)} cp := &ethpb.Checkpoint{Epoch: uint64(i), Root: make([]byte, 32)}
require.NoError(t, c.put(cp, &pb.CheckPtInfo{})) require.NoError(t, c.put(cp, &pb.CheckPtInfo{}))
} }
require.Equal(t, len(c.cache.Keys()), maxInfoSize) require.Equal(t, len(c.cache.Keys()), maxInfoSize)

View File

@@ -5,9 +5,7 @@ import (
"context" "context"
"testing" "testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" 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" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/assert"
@@ -35,11 +33,12 @@ func TestSaveHead_Different(t *testing.T) {
oldRoot := [32]byte{'A'} oldRoot := [32]byte{'A'}
service.head = &head{slot: 0, root: oldRoot} service.head = &head{slot: 0, root: oldRoot}
newHeadBlock := &ethpb.BeaconBlock{Slot: 1} newHeadSignedBlock := testutil.NewBeaconBlock()
newHeadSignedBlock := &ethpb.SignedBeaconBlock{Block: newHeadBlock} newHeadSignedBlock.Block.Slot = 1
newHeadBlock := newHeadSignedBlock.Block
require.NoError(t, service.beaconDB.SaveBlock(context.Background(), newHeadSignedBlock)) require.NoError(t, service.beaconDB.SaveBlock(context.Background(), newHeadSignedBlock))
newRoot, err := stateutil.BlockRoot(newHeadBlock) newRoot, err := newHeadBlock.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
headState := testutil.NewBeaconState() headState := testutil.NewBeaconState()
require.NoError(t, headState.SetSlot(1)) require.NoError(t, headState.SetSlot(1))
@@ -68,14 +67,13 @@ func TestSaveHead_Different_Reorg(t *testing.T) {
service.head = &head{slot: 0, root: oldRoot} service.head = &head{slot: 0, root: oldRoot}
reorgChainParent := [32]byte{'B'} reorgChainParent := [32]byte{'B'}
newHeadBlock := &ethpb.BeaconBlock{ newHeadSignedBlock := testutil.NewBeaconBlock()
Slot: 1, newHeadSignedBlock.Block.Slot = 1
ParentRoot: reorgChainParent[:], newHeadSignedBlock.Block.ParentRoot = reorgChainParent[:]
} newHeadBlock := newHeadSignedBlock.Block
newHeadSignedBlock := &ethpb.SignedBeaconBlock{Block: newHeadBlock}
require.NoError(t, service.beaconDB.SaveBlock(context.Background(), newHeadSignedBlock)) require.NoError(t, service.beaconDB.SaveBlock(context.Background(), newHeadSignedBlock))
newRoot, err := stateutil.BlockRoot(newHeadBlock) newRoot, err := newHeadBlock.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
headState := testutil.NewBeaconState() headState := testutil.NewBeaconState()
require.NoError(t, headState.SetSlot(1)) require.NoError(t, headState.SetSlot(1))

View File

@@ -12,9 +12,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray" "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/stategen"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/featureconfig"
@@ -39,24 +37,27 @@ func TestStore_OnAttestation(t *testing.T) {
_, err = blockTree1(db, []byte{'g'}) _, err = blockTree1(db, []byte{'g'})
require.NoError(t, err) require.NoError(t, err)
BlkWithOutState := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 0}} BlkWithOutState := testutil.NewBeaconBlock()
BlkWithOutState.Block.Slot = 0
require.NoError(t, db.SaveBlock(ctx, BlkWithOutState)) require.NoError(t, db.SaveBlock(ctx, BlkWithOutState))
BlkWithOutStateRoot, err := stateutil.BlockRoot(BlkWithOutState.Block) BlkWithOutStateRoot, err := BlkWithOutState.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
BlkWithStateBadAtt := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 1}} BlkWithStateBadAtt := testutil.NewBeaconBlock()
BlkWithStateBadAtt.Block.Slot = 1
require.NoError(t, db.SaveBlock(ctx, BlkWithStateBadAtt)) require.NoError(t, db.SaveBlock(ctx, BlkWithStateBadAtt))
BlkWithStateBadAttRoot, err := stateutil.BlockRoot(BlkWithStateBadAtt.Block) BlkWithStateBadAttRoot, err := BlkWithStateBadAtt.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
s := testutil.NewBeaconState() s := testutil.NewBeaconState()
require.NoError(t, s.SetSlot(100*params.BeaconConfig().SlotsPerEpoch)) require.NoError(t, s.SetSlot(100*params.BeaconConfig().SlotsPerEpoch))
require.NoError(t, service.beaconDB.SaveState(ctx, s, BlkWithStateBadAttRoot)) require.NoError(t, service.beaconDB.SaveState(ctx, s, BlkWithStateBadAttRoot))
BlkWithValidState := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 2}} BlkWithValidState := testutil.NewBeaconBlock()
BlkWithValidState.Block.Slot = 2
require.NoError(t, db.SaveBlock(ctx, BlkWithValidState)) require.NoError(t, db.SaveBlock(ctx, BlkWithValidState))
BlkWithValidStateRoot, err := stateutil.BlockRoot(BlkWithValidState.Block) BlkWithValidStateRoot, err := BlkWithValidState.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
s = testutil.NewBeaconState() s = testutil.NewBeaconState()
err = s.SetFork(&pb.Fork{ err = s.SetFork(&pb.Fork{
@@ -70,28 +71,24 @@ func TestStore_OnAttestation(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
a *ethpb.Attestation a *ethpb.Attestation
s *pb.BeaconState
wantErr bool wantErr bool
wantErrString string wantErrString string
}{ }{
{ {
name: "attestation's data slot not aligned with target vote", name: "attestation's data slot not aligned with target vote",
a: &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: params.BeaconConfig().SlotsPerEpoch, Target: &ethpb.Checkpoint{}}}, a: &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: params.BeaconConfig().SlotsPerEpoch, Target: &ethpb.Checkpoint{Root: make([]byte, 32)}}},
s: &pb.BeaconState{},
wantErr: true, wantErr: true,
wantErrString: "data slot is not in the same epoch as target 1 != 0", wantErrString: "data slot is not in the same epoch as target 1 != 0",
}, },
{ {
name: "attestation's target root not in db", name: "attestation's target root not in db",
a: &ethpb.Attestation{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{Root: []byte{'A'}}}}, a: &ethpb.Attestation{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte{'A'}, 32)}}},
s: &pb.BeaconState{},
wantErr: true, wantErr: true,
wantErrString: "target root does not exist in db", wantErrString: "target root does not exist in db",
}, },
{ {
name: "no pre state for attestations's target block", name: "no pre state for attestations's target block",
a: &ethpb.Attestation{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{Root: BlkWithOutStateRoot[:]}}}, a: &ethpb.Attestation{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{Root: BlkWithOutStateRoot[:]}}},
s: &pb.BeaconState{},
wantErr: true, wantErr: true,
wantErrString: "could not get pre state for slot 0", wantErrString: "could not get pre state for slot 0",
}, },
@@ -99,28 +96,32 @@ func TestStore_OnAttestation(t *testing.T) {
name: "process attestation doesn't match current epoch", name: "process attestation doesn't match current epoch",
a: &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 100 * params.BeaconConfig().SlotsPerEpoch, Target: &ethpb.Checkpoint{Epoch: 100, a: &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 100 * params.BeaconConfig().SlotsPerEpoch, Target: &ethpb.Checkpoint{Epoch: 100,
Root: BlkWithStateBadAttRoot[:]}}}, Root: BlkWithStateBadAttRoot[:]}}},
s: &pb.BeaconState{Slot: 100 * params.BeaconConfig().SlotsPerEpoch},
wantErr: true, wantErr: true,
wantErrString: "target epoch 100 does not match current epoch", wantErrString: "target epoch 100 does not match current epoch",
}, },
{ {
name: "process nil field (a.Target) in attestation", name: "process nil attestation",
a: nil, a: nil,
s: &pb.BeaconState{},
wantErr: true, wantErr: true,
wantErrString: "nil attestation", wantErrString: "nil attestation",
}, },
{ {
name: "process nil field (a.Data) in attestation", name: "process nil field (a.Data) in attestation",
a: &ethpb.Attestation{}, a: &ethpb.Attestation{},
s: &pb.BeaconState{},
wantErr: true, wantErr: true,
wantErrString: "nil attestation.Data field", wantErrString: "nil attestation.Data field",
}, },
{ {
name: "process nil field (a.Target) in attestation", name: "process nil field (a.Target) in attestation",
a: &ethpb.Attestation{Data: &ethpb.AttestationData{}}, a: &ethpb.Attestation{
s: &pb.BeaconState{}, Data: &ethpb.AttestationData{
BeaconBlockRoot: make([]byte, 32),
Target: nil,
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
},
AggregationBits: make([]byte, 1),
Signature: make([]byte, 96),
},
wantErr: true, wantErr: true,
wantErrString: "nil attestation.Data.Target field", wantErrString: "nil attestation.Data.Target field",
}, },
@@ -161,13 +162,13 @@ func TestStore_OnAttestationUsingCheckptCache(t *testing.T) {
BlkWithOutState := testutil.NewBeaconBlock() BlkWithOutState := testutil.NewBeaconBlock()
BlkWithOutState.Block.Slot = 0 BlkWithOutState.Block.Slot = 0
require.NoError(t, db.SaveBlock(ctx, BlkWithOutState)) require.NoError(t, db.SaveBlock(ctx, BlkWithOutState))
BlkWithOutStateRoot, err := stateutil.BlockRoot(BlkWithOutState.Block) BlkWithOutStateRoot, err := BlkWithOutState.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
BlkWithStateBadAtt := testutil.NewBeaconBlock() BlkWithStateBadAtt := testutil.NewBeaconBlock()
BlkWithStateBadAtt.Block.Slot = 1 BlkWithStateBadAtt.Block.Slot = 1
require.NoError(t, db.SaveBlock(ctx, BlkWithStateBadAtt)) require.NoError(t, db.SaveBlock(ctx, BlkWithStateBadAtt))
BlkWithStateBadAttRoot, err := stateutil.BlockRoot(BlkWithStateBadAtt.Block) BlkWithStateBadAttRoot, err := BlkWithStateBadAtt.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
s := testutil.NewBeaconState() s := testutil.NewBeaconState()
@@ -178,7 +179,7 @@ func TestStore_OnAttestationUsingCheckptCache(t *testing.T) {
BlkWithValidState.Block.Slot = 2 BlkWithValidState.Block.Slot = 2
require.NoError(t, db.SaveBlock(ctx, BlkWithValidState)) require.NoError(t, db.SaveBlock(ctx, BlkWithValidState))
BlkWithValidStateRoot, err := stateutil.BlockRoot(BlkWithValidState.Block) BlkWithValidStateRoot, err := BlkWithValidState.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
s = testutil.NewBeaconState() s = testutil.NewBeaconState()
err = s.SetFork(&pb.Fork{ err = s.SetFork(&pb.Fork{
@@ -273,22 +274,16 @@ func TestStore_SaveCheckpointState(t *testing.T) {
service, err := NewService(ctx, cfg) service, err := NewService(ctx, cfg)
require.NoError(t, err) require.NoError(t, err)
s, err := stateTrie.InitializeFromProto(&pb.BeaconState{ s := testutil.NewBeaconState()
Fork: &pb.Fork{ err = s.SetFinalizedCheckpoint(&ethpb.Checkpoint{Root: bytesutil.PadTo([]byte{'A'}, 32)})
Epoch: 0, require.NoError(t, err)
CurrentVersion: params.BeaconConfig().GenesisForkVersion, val := &ethpb.Validator{
PreviousVersion: params.BeaconConfig().GenesisForkVersion, PublicKey: bytesutil.PadTo([]byte("foo"), 48),
}, WithdrawalCredentials: bytesutil.PadTo([]byte("bar"), 32),
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }
StateRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot), err = s.SetValidators([]*ethpb.Validator{val})
BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot), require.NoError(t, err)
LatestBlockHeader: &ethpb.BeaconBlockHeader{}, err = s.SetBalances([]uint64{0})
JustificationBits: []byte{0},
Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector),
FinalizedCheckpoint: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte{'A'}, 32)},
Validators: []*ethpb.Validator{{PublicKey: bytesutil.PadTo([]byte("foo"), 48)}},
Balances: []uint64{0},
})
require.NoError(t, err) require.NoError(t, err)
r := [32]byte{'g'} r := [32]byte{'g'}
require.NoError(t, service.beaconDB.SaveState(ctx, s, r)) require.NoError(t, service.beaconDB.SaveState(ctx, s, r))
@@ -353,7 +348,7 @@ func TestStore_UpdateCheckpointState(t *testing.T) {
epoch := uint64(1) epoch := uint64(1)
baseState, _ := testutil.DeterministicGenesisState(t, 1) baseState, _ := testutil.DeterministicGenesisState(t, 1)
require.NoError(t, baseState.SetSlot(epoch*params.BeaconConfig().SlotsPerEpoch)) require.NoError(t, baseState.SetSlot(epoch*params.BeaconConfig().SlotsPerEpoch))
checkpoint := &ethpb.Checkpoint{Epoch: epoch} checkpoint := &ethpb.Checkpoint{Epoch: epoch, Root: bytesutil.PadTo([]byte("hi"), 32)}
require.NoError(t, service.beaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(checkpoint.Root))) require.NoError(t, service.beaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(checkpoint.Root)))
returned, err := service.getAttPreState(ctx, checkpoint) returned, err := service.getAttPreState(ctx, checkpoint)
require.NoError(t, err) require.NoError(t, err)
@@ -364,7 +359,7 @@ func TestStore_UpdateCheckpointState(t *testing.T) {
assert.NotNil(t, cached, "State should have been cached") assert.NotNil(t, cached, "State should have been cached")
epoch = uint64(2) epoch = uint64(2)
newCheckpoint := &ethpb.Checkpoint{Epoch: epoch} newCheckpoint := &ethpb.Checkpoint{Epoch: epoch, Root: bytesutil.PadTo([]byte("bye"), 32)}
require.NoError(t, service.beaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(newCheckpoint.Root))) require.NoError(t, service.beaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(newCheckpoint.Root)))
returned, err = service.getAttPreState(ctx, newCheckpoint) returned, err = service.getAttPreState(ctx, newCheckpoint)
require.NoError(t, err) require.NoError(t, err)
@@ -388,7 +383,7 @@ func TestAttEpoch_MatchPrevEpoch(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
nowTime := params.BeaconConfig().SlotsPerEpoch * params.BeaconConfig().SecondsPerSlot nowTime := params.BeaconConfig().SlotsPerEpoch * params.BeaconConfig().SecondsPerSlot
require.NoError(t, service.verifyAttTargetEpoch(ctx, 0, nowTime, &ethpb.Checkpoint{})) require.NoError(t, service.verifyAttTargetEpoch(ctx, 0, nowTime, &ethpb.Checkpoint{Root: make([]byte, 32)}))
} }
func TestAttEpoch_MatchCurrentEpoch(t *testing.T) { func TestAttEpoch_MatchCurrentEpoch(t *testing.T) {
@@ -412,7 +407,7 @@ func TestAttEpoch_NotMatch(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
nowTime := 2 * params.BeaconConfig().SlotsPerEpoch * params.BeaconConfig().SecondsPerSlot nowTime := 2 * params.BeaconConfig().SlotsPerEpoch * params.BeaconConfig().SecondsPerSlot
err = service.verifyAttTargetEpoch(ctx, 0, nowTime, &ethpb.Checkpoint{}) err = service.verifyAttTargetEpoch(ctx, 0, nowTime, &ethpb.Checkpoint{Root: make([]byte, 32)})
assert.ErrorContains(t, "target epoch 0 does not match current epoch 2 or prev epoch 1", err) assert.ErrorContains(t, "target epoch 0 does not match current epoch 2 or prev epoch 1", err)
} }
@@ -424,8 +419,12 @@ func TestVerifyBeaconBlock_NoBlock(t *testing.T) {
service, err := NewService(ctx, cfg) service, err := NewService(ctx, cfg)
require.NoError(t, err) require.NoError(t, err)
d := &ethpb.AttestationData{} d := &ethpb.AttestationData{
assert.ErrorContains(t, "beacon block does not exist", service.verifyBeaconBlock(ctx, d)) BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}
assert.ErrorContains(t, "beacon block 0x000000000000 does not exist", service.verifyBeaconBlock(ctx, d))
} }
func TestVerifyBeaconBlock_futureBlock(t *testing.T) { func TestVerifyBeaconBlock_futureBlock(t *testing.T) {
@@ -436,9 +435,10 @@ func TestVerifyBeaconBlock_futureBlock(t *testing.T) {
service, err := NewService(ctx, cfg) service, err := NewService(ctx, cfg)
require.NoError(t, err) require.NoError(t, err)
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 2}} b := testutil.NewBeaconBlock()
b.Block.Slot = 2
require.NoError(t, service.beaconDB.SaveBlock(ctx, b)) require.NoError(t, service.beaconDB.SaveBlock(ctx, b))
r, err := stateutil.BlockRoot(b.Block) r, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
d := &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: r[:]} d := &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: r[:]}
@@ -453,9 +453,10 @@ func TestVerifyBeaconBlock_OK(t *testing.T) {
service, err := NewService(ctx, cfg) service, err := NewService(ctx, cfg)
require.NoError(t, err) require.NoError(t, err)
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 2}} b := testutil.NewBeaconBlock()
b.Block.Slot = 2
require.NoError(t, service.beaconDB.SaveBlock(ctx, b)) require.NoError(t, service.beaconDB.SaveBlock(ctx, b))
r, err := stateutil.BlockRoot(b.Block) r, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
d := &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: r[:]} d := &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: r[:]}
@@ -470,13 +471,16 @@ func TestVerifyLMDFFGConsistent_NotOK(t *testing.T) {
service, err := NewService(ctx, cfg) service, err := NewService(ctx, cfg)
require.NoError(t, err) require.NoError(t, err)
b32 := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 32}} b32 := testutil.NewBeaconBlock()
b32.Block.Slot = 32
require.NoError(t, service.beaconDB.SaveBlock(ctx, b32)) require.NoError(t, service.beaconDB.SaveBlock(ctx, b32))
r32, err := stateutil.BlockRoot(b32.Block) r32, err := b32.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
b33 := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 33, ParentRoot: r32[:]}} b33 := testutil.NewBeaconBlock()
b33.Block.Slot = 33
b33.Block.ParentRoot = r32[:]
require.NoError(t, service.beaconDB.SaveBlock(ctx, b33)) require.NoError(t, service.beaconDB.SaveBlock(ctx, b33))
r33, err := stateutil.BlockRoot(b33.Block) r33, err := b33.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
wanted := "FFG and LMD votes are not consistent" wanted := "FFG and LMD votes are not consistent"
@@ -491,13 +495,16 @@ func TestVerifyLMDFFGConsistent_OK(t *testing.T) {
service, err := NewService(ctx, cfg) service, err := NewService(ctx, cfg)
require.NoError(t, err) require.NoError(t, err)
b32 := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 32}} b32 := testutil.NewBeaconBlock()
b32.Block.Slot = 32
require.NoError(t, service.beaconDB.SaveBlock(ctx, b32)) require.NoError(t, service.beaconDB.SaveBlock(ctx, b32))
r32, err := stateutil.BlockRoot(b32.Block) r32, err := b32.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
b33 := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 33, ParentRoot: r32[:]}} b33 := testutil.NewBeaconBlock()
b33.Block.Slot = 33
b33.Block.ParentRoot = r32[:]
require.NoError(t, service.beaconDB.SaveBlock(ctx, b33)) require.NoError(t, service.beaconDB.SaveBlock(ctx, b33))
r33, err := stateutil.BlockRoot(b33.Block) r33, err := b33.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
err = service.verifyLMDFFGConsistent(context.Background(), 1, r32[:], r33[:]) err = service.verifyLMDFFGConsistent(context.Background(), 1, r32[:], r33[:])
@@ -513,7 +520,7 @@ func TestGetAttCheckptInfo(t *testing.T) {
baseState, _ := testutil.DeterministicGenesisState(t, 128) baseState, _ := testutil.DeterministicGenesisState(t, 128)
b := testutil.NewBeaconBlock() b := testutil.NewBeaconBlock()
r, err := stateutil.BlockRoot(b.Block) r, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, service.beaconDB.SaveState(ctx, baseState, r)) require.NoError(t, service.beaconDB.SaveState(ctx, baseState, r))
require.NoError(t, service.beaconDB.SaveBlock(ctx, b)) require.NoError(t, service.beaconDB.SaveBlock(ctx, b))

View File

@@ -9,7 +9,6 @@ import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/attestationutil" "github.com/prysmaticlabs/prysm/shared/attestationutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
@@ -360,7 +359,7 @@ func (s *Service) fillInForkChoiceMissingBlocks(ctx context.Context, blk *ethpb.
// Lower slots should be at the end of the list. // Lower slots should be at the end of the list.
for i := len(pendingNodes) - 1; i >= 0; i-- { for i := len(pendingNodes) - 1; i >= 0; i-- {
b := pendingNodes[i] b := pendingNodes[i]
r, err := stateutil.BlockRoot(b) r, err := b.HashTreeRoot()
if err != nil { if err != nil {
return err return err
} }

View File

@@ -6,8 +6,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" 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"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
@@ -16,7 +16,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray" "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "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" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/attestationutil" "github.com/prysmaticlabs/prysm/shared/attestationutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
@@ -42,15 +41,17 @@ func TestStore_OnBlock(t *testing.T) {
genesisStateRoot := [32]byte{} genesisStateRoot := [32]byte{}
genesis := blocks.NewGenesisBlock(genesisStateRoot[:]) genesis := blocks.NewGenesisBlock(genesisStateRoot[:])
assert.NoError(t, db.SaveBlock(ctx, genesis)) assert.NoError(t, db.SaveBlock(ctx, genesis))
validGenesisRoot, err := stateutil.BlockRoot(genesis.Block) validGenesisRoot, err := genesis.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
st := testutil.NewBeaconState() st := testutil.NewBeaconState()
require.NoError(t, service.beaconDB.SaveState(ctx, st.Copy(), validGenesisRoot)) require.NoError(t, service.beaconDB.SaveState(ctx, st.Copy(), validGenesisRoot))
roots, err := blockTree1(db, validGenesisRoot[:]) roots, err := blockTree1(db, validGenesisRoot[:])
require.NoError(t, err) require.NoError(t, err)
random := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 1, ParentRoot: validGenesisRoot[:]}} random := testutil.NewBeaconBlock()
random.Block.Slot = 1
random.Block.ParentRoot = validGenesisRoot[:]
assert.NoError(t, db.SaveBlock(ctx, random)) assert.NoError(t, db.SaveBlock(ctx, random))
randomParentRoot, err := stateutil.BlockRoot(random.Block) randomParentRoot, err := random.Block.HashTreeRoot()
assert.NoError(t, err) assert.NoError(t, err)
require.NoError(t, service.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{Slot: st.Slot(), Root: randomParentRoot[:]})) require.NoError(t, service.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{Slot: st.Slot(), Root: randomParentRoot[:]}))
require.NoError(t, service.beaconDB.SaveState(ctx, st.Copy(), randomParentRoot)) require.NoError(t, service.beaconDB.SaveState(ctx, st.Copy(), randomParentRoot))
@@ -60,32 +61,46 @@ func TestStore_OnBlock(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
blk *ethpb.BeaconBlock blk *ethpb.SignedBeaconBlock
s *stateTrie.BeaconState s *stateTrie.BeaconState
time uint64 time uint64
wantErrString string wantErrString string
}{ }{
{ {
name: "parent block root does not have a state", name: "parent block root does not have a state",
blk: &ethpb.BeaconBlock{}, blk: testutil.NewBeaconBlock(),
s: st.Copy(), s: st.Copy(),
wantErrString: "could not reconstruct parent state", wantErrString: "could not reconstruct parent state",
}, },
{ {
name: "block is from the future", name: "block is from the future",
blk: &ethpb.BeaconBlock{ParentRoot: randomParentRoot[:], Slot: params.BeaconConfig().FarFutureEpoch}, blk: func() *ethpb.SignedBeaconBlock {
b := testutil.NewBeaconBlock()
b.Block.ParentRoot = randomParentRoot[:]
b.Block.Slot = params.BeaconConfig().FarFutureEpoch
return b
}(),
s: st.Copy(), s: st.Copy(),
wantErrString: "far distant future", wantErrString: "far distant future",
}, },
{ {
name: "could not get finalized block", name: "could not get finalized block",
blk: &ethpb.BeaconBlock{ParentRoot: randomParentRoot[:]}, blk: func() *ethpb.SignedBeaconBlock {
b := testutil.NewBeaconBlock()
b.Block.ParentRoot = randomParentRoot[:]
return b
}(),
s: st.Copy(), s: st.Copy(),
wantErrString: "is not a descendent of the current finalized block", wantErrString: "is not a descendent of the current finalized block",
}, },
{ {
name: "same slot as finalized block", name: "same slot as finalized block",
blk: &ethpb.BeaconBlock{Slot: 0, ParentRoot: randomParentRoot2}, blk: func() *ethpb.SignedBeaconBlock {
b := testutil.NewBeaconBlock()
b.Block.Slot = 0
b.Block.ParentRoot = randomParentRoot2
return b
}(),
s: st.Copy(), s: st.Copy(),
wantErrString: "block is equal or earlier than finalized block, slot 0 < slot 0", wantErrString: "block is equal or earlier than finalized block, slot 0 < slot 0",
}, },
@@ -99,9 +114,9 @@ func TestStore_OnBlock(t *testing.T) {
service.prevFinalizedCheckpt = &ethpb.Checkpoint{Root: validGenesisRoot[:]} service.prevFinalizedCheckpt = &ethpb.Checkpoint{Root: validGenesisRoot[:]}
service.finalizedCheckpt.Root = roots[0] service.finalizedCheckpt.Root = roots[0]
root, err := stateutil.BlockRoot(tt.blk) root, err := tt.blk.Block.HashTreeRoot()
assert.NoError(t, err) assert.NoError(t, err)
err = service.onBlock(ctx, &ethpb.SignedBeaconBlock{Block: tt.blk}, root) err = service.onBlock(ctx, tt.blk, root)
assert.ErrorContains(t, tt.wantErrString, err) assert.ErrorContains(t, tt.wantErrString, err)
}) })
} }
@@ -137,7 +152,7 @@ func TestStore_OnBlockBatch(t *testing.T) {
if i == 1 { if i == 1 {
firstState = bState.Copy() firstState = bState.Copy()
} }
root, err := stateutil.BlockRoot(b.Block) root, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
blks = append(blks, b) blks = append(blks, b)
blkRoots = append(blkRoots, root) blkRoots = append(blkRoots, root)
@@ -159,17 +174,17 @@ func TestRemoveStateSinceLastFinalized_EmptyStartSlot(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
service.genesisTime = time.Now() service.genesisTime = time.Now()
update, err := service.shouldUpdateCurrentJustified(ctx, &ethpb.Checkpoint{}) update, err := service.shouldUpdateCurrentJustified(ctx, &ethpb.Checkpoint{Root: make([]byte, 32)})
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, true, update, "Should be able to update justified") assert.Equal(t, true, update, "Should be able to update justified")
lastJustifiedBlk := testutil.NewBeaconBlock() lastJustifiedBlk := testutil.NewBeaconBlock()
lastJustifiedBlk.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32) lastJustifiedBlk.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32)
lastJustifiedRoot, err := stateutil.BlockRoot(lastJustifiedBlk.Block) lastJustifiedRoot, err := lastJustifiedBlk.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
newJustifiedBlk := testutil.NewBeaconBlock() newJustifiedBlk := testutil.NewBeaconBlock()
newJustifiedBlk.Block.Slot = 1 newJustifiedBlk.Block.Slot = 1
newJustifiedBlk.Block.ParentRoot = bytesutil.PadTo(lastJustifiedRoot[:], 32) newJustifiedBlk.Block.ParentRoot = bytesutil.PadTo(lastJustifiedRoot[:], 32)
newJustifiedRoot, err := stateutil.BlockRoot(newJustifiedBlk.Block) newJustifiedRoot, err := newJustifiedBlk.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, service.beaconDB.SaveBlock(ctx, newJustifiedBlk)) require.NoError(t, service.beaconDB.SaveBlock(ctx, newJustifiedBlk))
require.NoError(t, service.beaconDB.SaveBlock(ctx, lastJustifiedBlk)) require.NoError(t, service.beaconDB.SaveBlock(ctx, lastJustifiedBlk))
@@ -193,11 +208,11 @@ func TestShouldUpdateJustified_ReturnFalse(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
lastJustifiedBlk := testutil.NewBeaconBlock() lastJustifiedBlk := testutil.NewBeaconBlock()
lastJustifiedBlk.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32) lastJustifiedBlk.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32)
lastJustifiedRoot, err := stateutil.BlockRoot(lastJustifiedBlk.Block) lastJustifiedRoot, err := lastJustifiedBlk.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
newJustifiedBlk := testutil.NewBeaconBlock() newJustifiedBlk := testutil.NewBeaconBlock()
newJustifiedBlk.Block.ParentRoot = bytesutil.PadTo(lastJustifiedRoot[:], 32) newJustifiedBlk.Block.ParentRoot = bytesutil.PadTo(lastJustifiedRoot[:], 32)
newJustifiedRoot, err := stateutil.BlockRoot(newJustifiedBlk.Block) newJustifiedRoot, err := newJustifiedBlk.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, service.beaconDB.SaveBlock(ctx, newJustifiedBlk)) require.NoError(t, service.beaconDB.SaveBlock(ctx, newJustifiedBlk))
require.NoError(t, service.beaconDB.SaveBlock(ctx, lastJustifiedBlk)) require.NoError(t, service.beaconDB.SaveBlock(ctx, lastJustifiedBlk))
@@ -228,10 +243,12 @@ func TestCachedPreState_CanGetFromStateSummary(t *testing.T) {
s, err := stateTrie.InitializeFromProto(&pb.BeaconState{Slot: 1, GenesisValidatorsRoot: params.BeaconConfig().ZeroHash[:]}) s, err := stateTrie.InitializeFromProto(&pb.BeaconState{Slot: 1, GenesisValidatorsRoot: params.BeaconConfig().ZeroHash[:]})
require.NoError(t, err) require.NoError(t, err)
r := [32]byte{'A'} r := [32]byte{'A'}
b := &ethpb.BeaconBlock{Slot: 1, ParentRoot: r[:]} b := testutil.NewBeaconBlock()
b.Block.Slot = 1
b.Block.ParentRoot = r[:]
require.NoError(t, service.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{Slot: 1, Root: 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.stateGen.SaveState(ctx, r, s))
require.NoError(t, service.verifyBlkPreState(ctx, b)) require.NoError(t, service.verifyBlkPreState(ctx, b.Block))
} }
func TestCachedPreState_CanGetFromDB(t *testing.T) { func TestCachedPreState_CanGetFromDB(t *testing.T) {
@@ -249,10 +266,12 @@ func TestCachedPreState_CanGetFromDB(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
r := [32]byte{'A'} r := [32]byte{'A'}
b := &ethpb.BeaconBlock{Slot: 1, ParentRoot: r[:]} b := testutil.NewBeaconBlock()
b.Block.Slot = 1
b.Block.ParentRoot = r[:]
service.finalizedCheckpt = &ethpb.Checkpoint{Root: r[:]} service.finalizedCheckpt = &ethpb.Checkpoint{Root: r[:]}
err = service.verifyBlkPreState(ctx, b) err = service.verifyBlkPreState(ctx, b.Block)
wanted := "could not reconstruct parent state" wanted := "could not reconstruct parent state"
assert.ErrorContains(t, wanted, err) assert.ErrorContains(t, wanted, err)
@@ -260,7 +279,7 @@ func TestCachedPreState_CanGetFromDB(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, service.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{Slot: 1, Root: 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.stateGen.SaveState(ctx, r, s))
require.NoError(t, service.verifyBlkPreState(ctx, b)) require.NoError(t, service.verifyBlkPreState(ctx, b.Block))
} }
func TestUpdateJustified_CouldUpdateBest(t *testing.T) { func TestUpdateJustified_CouldUpdateBest(t *testing.T) {
@@ -271,9 +290,9 @@ func TestUpdateJustified_CouldUpdateBest(t *testing.T) {
service, err := NewService(ctx, cfg) service, err := NewService(ctx, cfg)
require.NoError(t, err) require.NoError(t, err)
signedBlock := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} signedBlock := testutil.NewBeaconBlock()
require.NoError(t, db.SaveBlock(ctx, signedBlock)) require.NoError(t, db.SaveBlock(ctx, signedBlock))
r, err := stateutil.BlockRoot(signedBlock.Block) r, err := signedBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
service.justifiedCheckpt = &ethpb.Checkpoint{Root: []byte{'A'}} service.justifiedCheckpt = &ethpb.Checkpoint{Root: []byte{'A'}}
service.bestJustifiedCheckpt = &ethpb.Checkpoint{Root: []byte{'A'}} service.bestJustifiedCheckpt = &ethpb.Checkpoint{Root: []byte{'A'}}
@@ -303,12 +322,12 @@ func TestFillForkChoiceMissingBlocks_CanSave(t *testing.T) {
service, err := NewService(ctx, cfg) service, err := NewService(ctx, cfg)
require.NoError(t, err) require.NoError(t, err)
service.forkChoiceStore = protoarray.New(0, 0, [32]byte{'A'}) service.forkChoiceStore = protoarray.New(0, 0, [32]byte{'A'})
service.finalizedCheckpt = &ethpb.Checkpoint{} service.finalizedCheckpt = &ethpb.Checkpoint{Root: make([]byte, 32)}
genesisStateRoot := [32]byte{} genesisStateRoot := [32]byte{}
genesis := blocks.NewGenesisBlock(genesisStateRoot[:]) genesis := blocks.NewGenesisBlock(genesisStateRoot[:])
require.NoError(t, db.SaveBlock(ctx, genesis)) require.NoError(t, db.SaveBlock(ctx, genesis))
validGenesisRoot, err := stateutil.BlockRoot(genesis.Block) validGenesisRoot, err := genesis.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
st := testutil.NewBeaconState() st := testutil.NewBeaconState()
@@ -317,10 +336,12 @@ func TestFillForkChoiceMissingBlocks_CanSave(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
beaconState, _ := testutil.DeterministicGenesisState(t, 32) beaconState, _ := testutil.DeterministicGenesisState(t, 32)
block := &ethpb.BeaconBlock{Slot: 9, ParentRoot: roots[8], Body: &ethpb.BeaconBlockBody{Graffiti: []byte{}}} block := testutil.NewBeaconBlock()
block.Block.Slot = 9
block.Block.ParentRoot = roots[8]
err = service.fillInForkChoiceMissingBlocks( err = service.fillInForkChoiceMissingBlocks(
context.Background(), block, beaconState.FinalizedCheckpoint(), beaconState.CurrentJustifiedCheckpoint()) context.Background(), block.Block, beaconState.FinalizedCheckpoint(), beaconState.CurrentJustifiedCheckpoint())
require.NoError(t, err) require.NoError(t, err)
// 5 nodes from the block tree 1. B0 - B3 - B4 - B6 - B8 // 5 nodes from the block tree 1. B0 - B3 - B4 - B6 - B8
@@ -344,22 +365,27 @@ func TestFillForkChoiceMissingBlocks_FilterFinalized(t *testing.T) {
genesisStateRoot := [32]byte{} genesisStateRoot := [32]byte{}
genesis := blocks.NewGenesisBlock(genesisStateRoot[:]) genesis := blocks.NewGenesisBlock(genesisStateRoot[:])
assert.NoError(t, db.SaveBlock(ctx, genesis)) assert.NoError(t, db.SaveBlock(ctx, genesis))
validGenesisRoot, err := stateutil.BlockRoot(genesis.Block) validGenesisRoot, err := genesis.Block.HashTreeRoot()
assert.NoError(t, err) assert.NoError(t, err)
st := testutil.NewBeaconState() st := testutil.NewBeaconState()
require.NoError(t, service.beaconDB.SaveState(ctx, st.Copy(), validGenesisRoot)) require.NoError(t, service.beaconDB.SaveState(ctx, st.Copy(), validGenesisRoot))
// Define a tree branch, slot 63 <- 64 <- 65 // Define a tree branch, slot 63 <- 64 <- 65
b63 := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 63, Body: &ethpb.BeaconBlockBody{}}} b63 := testutil.NewBeaconBlock()
b63.Block.Slot = 63
require.NoError(t, service.beaconDB.SaveBlock(ctx, b63)) require.NoError(t, service.beaconDB.SaveBlock(ctx, b63))
r63, err := stateutil.BlockRoot(b63.Block) r63, err := b63.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
b64 := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 64, ParentRoot: r63[:], Body: &ethpb.BeaconBlockBody{}}} b64 := testutil.NewBeaconBlock()
b64.Block.Slot = 64
b64.Block.ParentRoot = r63[:]
require.NoError(t, service.beaconDB.SaveBlock(ctx, b64)) require.NoError(t, service.beaconDB.SaveBlock(ctx, b64))
r64, err := stateutil.BlockRoot(b64.Block) r64, err := b64.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
b65 := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 65, ParentRoot: r64[:], Body: &ethpb.BeaconBlockBody{}}} b65 := testutil.NewBeaconBlock()
b65.Block.Slot = 65
b65.Block.ParentRoot = r64[:]
require.NoError(t, service.beaconDB.SaveBlock(ctx, b65)) require.NoError(t, service.beaconDB.SaveBlock(ctx, b65))
beaconState, _ := testutil.DeterministicGenesisState(t, 32) beaconState, _ := testutil.DeterministicGenesisState(t, 32)
@@ -380,58 +406,74 @@ func TestFillForkChoiceMissingBlocks_FilterFinalized(t *testing.T) {
// \- B3 - B4 - B6 - B8 // \- B3 - B4 - B6 - B8
// (B1, and B3 are all from the same slots) // (B1, and B3 are all from the same slots)
func blockTree1(db db.Database, genesisRoot []byte) ([][]byte, error) { func blockTree1(db db.Database, genesisRoot []byte) ([][]byte, error) {
b0 := &ethpb.BeaconBlock{Slot: 0, ParentRoot: genesisRoot} genesisRoot = bytesutil.PadTo(genesisRoot, 32)
r0, err := ssz.HashTreeRoot(b0) b0 := testutil.NewBeaconBlock()
b0.Block.Slot = 0
b0.Block.ParentRoot = genesisRoot
r0, err := b0.Block.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
b1 := &ethpb.BeaconBlock{Slot: 1, ParentRoot: r0[:]} b1 := testutil.NewBeaconBlock()
r1, err := ssz.HashTreeRoot(b1) b1.Block.Slot = 1
b1.Block.ParentRoot = r0[:]
r1, err := b1.Block.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
b3 := &ethpb.BeaconBlock{Slot: 3, ParentRoot: r0[:]} b3 := testutil.NewBeaconBlock()
r3, err := ssz.HashTreeRoot(b3) b3.Block.Slot = 3
b3.Block.ParentRoot = r0[:]
r3, err := b3.Block.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
b4 := &ethpb.BeaconBlock{Slot: 4, ParentRoot: r3[:]} b4 := testutil.NewBeaconBlock()
r4, err := ssz.HashTreeRoot(b4) b4.Block.Slot = 4
b4.Block.ParentRoot = r3[:]
r4, err := b4.Block.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
b5 := &ethpb.BeaconBlock{Slot: 5, ParentRoot: r4[:]} b5 := testutil.NewBeaconBlock()
r5, err := ssz.HashTreeRoot(b5) b5.Block.Slot = 5
b5.Block.ParentRoot = r4[:]
r5, err := b5.Block.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
b6 := &ethpb.BeaconBlock{Slot: 6, ParentRoot: r4[:]} b6 := testutil.NewBeaconBlock()
r6, err := ssz.HashTreeRoot(b6) b6.Block.Slot = 6
b6.Block.ParentRoot = r4[:]
r6, err := b6.Block.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
b7 := &ethpb.BeaconBlock{Slot: 7, ParentRoot: r5[:]} b7 := testutil.NewBeaconBlock()
r7, err := ssz.HashTreeRoot(b7) b7.Block.Slot = 7
b7.Block.ParentRoot = r5[:]
r7, err := b7.Block.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
b8 := &ethpb.BeaconBlock{Slot: 8, ParentRoot: r6[:]} b8 := testutil.NewBeaconBlock()
r8, err := ssz.HashTreeRoot(b8) b8.Block.Slot = 8
b8.Block.ParentRoot = r6[:]
r8, err := b8.Block.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
st := testutil.NewBeaconState() st := testutil.NewBeaconState()
for _, b := range []*ethpb.BeaconBlock{b0, b1, b3, b4, b5, b6, b7, b8} { for _, b := range []*ethpb.SignedBeaconBlock{b0, b1, b3, b4, b5, b6, b7, b8} {
beaconBlock := testutil.NewBeaconBlock() beaconBlock := testutil.NewBeaconBlock()
beaconBlock.Block.Slot = b.Slot beaconBlock.Block.Slot = b.Block.Slot
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.ParentRoot, 32) beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.Block.ParentRoot, 32)
beaconBlock.Block.Body = &ethpb.BeaconBlockBody{}
if err := db.SaveBlock(context.Background(), beaconBlock); err != nil { if err := db.SaveBlock(context.Background(), beaconBlock); err != nil {
return nil, err return nil, err
} }
if err := db.SaveState(context.Background(), st.Copy(), bytesutil.ToBytes32(beaconBlock.Block.ParentRoot)); err != nil { if err := db.SaveState(context.Background(), st.Copy(), bytesutil.ToBytes32(beaconBlock.Block.ParentRoot)); err != nil {
return nil, err return nil, errors.Wrap(err, "could not save state")
} }
} }
if err := db.SaveState(context.Background(), st.Copy(), r1); err != nil { if err := db.SaveState(context.Background(), st.Copy(), r1); err != nil {
@@ -461,20 +503,25 @@ func TestAncestor_HandleSkipSlot(t *testing.T) {
service, err := NewService(ctx, cfg) service, err := NewService(ctx, cfg)
require.NoError(t, err) require.NoError(t, err)
b1 := &ethpb.BeaconBlock{Slot: 1, ParentRoot: []byte{'a'}} b1 := testutil.NewBeaconBlock()
r1, err := ssz.HashTreeRoot(b1) b1.Block.Slot = 1
b1.Block.ParentRoot = bytesutil.PadTo([]byte{'a'}, 32)
r1, err := b1.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
b100 := &ethpb.BeaconBlock{Slot: 100, ParentRoot: r1[:]} b100 := testutil.NewBeaconBlock()
r100, err := ssz.HashTreeRoot(b100) b100.Block.Slot = 100
b100.Block.ParentRoot = r1[:]
r100, err := b100.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
b200 := &ethpb.BeaconBlock{Slot: 200, ParentRoot: r100[:]} b200 := testutil.NewBeaconBlock()
r200, err := ssz.HashTreeRoot(b200) b200.Block.Slot = 200
b200.Block.ParentRoot = r100[:]
r200, err := b200.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
for _, b := range []*ethpb.BeaconBlock{b1, b100, b200} { for _, b := range []*ethpb.SignedBeaconBlock{b1, b100, b200} {
beaconBlock := testutil.NewBeaconBlock() beaconBlock := testutil.NewBeaconBlock()
beaconBlock.Block.Slot = b.Slot beaconBlock.Block.Slot = b.Block.Slot
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.ParentRoot, 32) beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.Block.ParentRoot, 32)
beaconBlock.Block.Body = &ethpb.BeaconBlockBody{}
require.NoError(t, db.SaveBlock(context.Background(), beaconBlock)) require.NoError(t, db.SaveBlock(context.Background(), beaconBlock))
} }
@@ -557,16 +604,20 @@ func TestFinalizedImpliesNewJustified(t *testing.T) {
require.NoError(t, service.beaconDB.SaveState(ctx, genesisState, bytesutil.ToBytes32(test.want.Root))) require.NoError(t, service.beaconDB.SaveState(ctx, genesisState, bytesutil.ToBytes32(test.want.Root)))
if test.args.diffFinalizedCheckPoint { if test.args.diffFinalizedCheckPoint {
b1 := &ethpb.BeaconBlock{Slot: 1, ParentRoot: []byte{'a'}} b1 := testutil.NewBeaconBlock()
r1, err := ssz.HashTreeRoot(b1) b1.Block.Slot = 1
b1.Block.ParentRoot = bytesutil.PadTo([]byte{'a'}, 32)
r1, err := b1.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
b100 := &ethpb.BeaconBlock{Slot: 100, ParentRoot: r1[:]} b100 := testutil.NewBeaconBlock()
r100, err := ssz.HashTreeRoot(b100) b100.Block.Slot = 100
b100.Block.ParentRoot = r1[:]
r100, err := b100.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
for _, b := range []*ethpb.BeaconBlock{b1, b100} { for _, b := range []*ethpb.SignedBeaconBlock{b1, b100} {
beaconBlock := testutil.NewBeaconBlock() beaconBlock := testutil.NewBeaconBlock()
beaconBlock.Block.Slot = b.Slot beaconBlock.Block.Slot = b.Block.Slot
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.ParentRoot, 32) beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.Block.ParentRoot, 32)
require.NoError(t, service.beaconDB.SaveBlock(context.Background(), beaconBlock)) require.NoError(t, service.beaconDB.SaveBlock(context.Background(), beaconBlock))
} }
service.finalizedCheckpt = &ethpb.Checkpoint{Root: []byte{'c'}, Epoch: 1} service.finalizedCheckpt = &ethpb.Checkpoint{Root: []byte{'c'}, Epoch: 1}
@@ -584,14 +635,14 @@ func TestVerifyBlkDescendant(t *testing.T) {
b := testutil.NewBeaconBlock() b := testutil.NewBeaconBlock()
b.Block.Slot = 1 b.Block.Slot = 1
r, err := stateutil.BlockRoot(b.Block) r, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
b1 := testutil.NewBeaconBlock() b1 := testutil.NewBeaconBlock()
b1.Block.Slot = 1 b1.Block.Slot = 1
b1.Block.Body.Graffiti = bytesutil.PadTo([]byte{'a'}, 32) b1.Block.Body.Graffiti = bytesutil.PadTo([]byte{'a'}, 32)
r1, err := stateutil.BlockRoot(b1.Block) r1, err := b1.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveBlock(ctx, b1)) require.NoError(t, db.SaveBlock(ctx, b1))
@@ -665,8 +716,8 @@ func TestUpdateJustifiedInitSync(t *testing.T) {
service, err := NewService(ctx, cfg) service, err := NewService(ctx, cfg)
require.NoError(t, err) require.NoError(t, err)
gBlk := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} gBlk := testutil.NewBeaconBlock()
gRoot, err := stateutil.BlockRoot(gBlk.Block) gRoot, err := gBlk.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, service.beaconDB.SaveBlock(ctx, gBlk)) require.NoError(t, service.beaconDB.SaveBlock(ctx, gBlk))
require.NoError(t, service.beaconDB.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, service.beaconDB.SaveGenesisBlockRoot(ctx, gRoot))

View File

@@ -17,6 +17,6 @@ func TestVerifyCheckpointEpoch_Ok(t *testing.T) {
chainService := setupBeaconChain(t, db, sc) chainService := setupBeaconChain(t, db, sc)
chainService.genesisTime = time.Now() chainService.genesisTime = time.Now()
assert.Equal(t, true, chainService.verifyCheckpointEpoch(&ethpb.Checkpoint{})) assert.Equal(t, true, chainService.verifyCheckpointEpoch(&ethpb.Checkpoint{Root: make([]byte, 32)}))
assert.Equal(t, false, chainService.verifyCheckpointEpoch(&ethpb.Checkpoint{Epoch: 1})) assert.Equal(t, false, chainService.verifyCheckpointEpoch(&ethpb.Checkpoint{Epoch: 1}))
} }

View File

@@ -12,7 +12,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations" "github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
"github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits" "github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil"
@@ -139,9 +138,9 @@ func TestService_ReceiveBlock(t *testing.T) {
require.NoError(t, s.saveGenesisData(ctx, genesis)) require.NoError(t, s.saveGenesisData(ctx, genesis))
gBlk, err := s.beaconDB.GenesisBlock(ctx) gBlk, err := s.beaconDB.GenesisBlock(ctx)
require.NoError(t, err) require.NoError(t, err)
gRoot, err := stateutil.BlockRoot(gBlk.Block) gRoot, err := gBlk.Block.HashTreeRoot()
s.finalizedCheckpt = &ethpb.Checkpoint{Root: gRoot[:]} s.finalizedCheckpt = &ethpb.Checkpoint{Root: gRoot[:]}
root, err := stateutil.BlockRoot(tt.args.block.Block) root, err := tt.args.block.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
err = s.ReceiveBlock(ctx, tt.args.block, root) err = s.ReceiveBlock(ctx, tt.args.block, root)
if tt.wantedErr != "" { if tt.wantedErr != "" {
@@ -179,9 +178,9 @@ func TestService_ReceiveBlockUpdateHead(t *testing.T) {
require.NoError(t, s.saveGenesisData(ctx, genesis)) require.NoError(t, s.saveGenesisData(ctx, genesis))
gBlk, err := s.beaconDB.GenesisBlock(ctx) gBlk, err := s.beaconDB.GenesisBlock(ctx)
require.NoError(t, err) require.NoError(t, err)
gRoot, err := stateutil.BlockRoot(gBlk.Block) gRoot, err := gBlk.Block.HashTreeRoot()
s.finalizedCheckpt = &ethpb.Checkpoint{Root: gRoot[:]} s.finalizedCheckpt = &ethpb.Checkpoint{Root: gRoot[:]}
root, err := stateutil.BlockRoot(b.Block) root, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
wg.Add(1) wg.Add(1)
@@ -261,9 +260,9 @@ func TestService_ReceiveBlockInitialSync(t *testing.T) {
gBlk, err := s.beaconDB.GenesisBlock(ctx) gBlk, err := s.beaconDB.GenesisBlock(ctx)
require.NoError(t, err) require.NoError(t, err)
gRoot, err := stateutil.BlockRoot(gBlk.Block) gRoot, err := gBlk.Block.HashTreeRoot()
s.finalizedCheckpt = &ethpb.Checkpoint{Root: gRoot[:]} s.finalizedCheckpt = &ethpb.Checkpoint{Root: gRoot[:]}
root, err := stateutil.BlockRoot(tt.args.block.Block) root, err := tt.args.block.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
err = s.ReceiveBlockInitialSync(ctx, tt.args.block, root) err = s.ReceiveBlockInitialSync(ctx, tt.args.block, root)
@@ -322,8 +321,8 @@ func TestService_ReceiveBlockBatch(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
db, stateSummaryCache := testDB.SetupDB(t) db, stateSummaryCache := testDB.SetupDB(t)
genesisBlockRoot := bytesutil.ToBytes32(nil) genesisBlockRoot, err := genesis.HashTreeRoot(ctx)
require.NoError(t, err)
cfg := &Config{ cfg := &Config{
BeaconDB: db, BeaconDB: db,
ForkChoiceStore: protoarray.New( ForkChoiceStore: protoarray.New(
@@ -341,9 +340,9 @@ func TestService_ReceiveBlockBatch(t *testing.T) {
gBlk, err := s.beaconDB.GenesisBlock(ctx) gBlk, err := s.beaconDB.GenesisBlock(ctx)
require.NoError(t, err) require.NoError(t, err)
gRoot, err := stateutil.BlockRoot(gBlk.Block) gRoot, err := gBlk.Block.HashTreeRoot()
s.finalizedCheckpt = &ethpb.Checkpoint{Root: gRoot[:]} s.finalizedCheckpt = &ethpb.Checkpoint{Root: gRoot[:]}
root, err := stateutil.BlockRoot(tt.args.block.Block) root, err := tt.args.block.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
blks := []*ethpb.SignedBeaconBlock{tt.args.block} blks := []*ethpb.SignedBeaconBlock{tt.args.block}
roots := [][32]byte{root} roots := [][32]byte{root}

View File

@@ -30,7 +30,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/powchain" "github.com/prysmaticlabs/prysm/beacon-chain/powchain"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "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" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
@@ -324,7 +323,7 @@ func (s *Service) saveGenesisData(ctx context.Context, genesisState *stateTrie.B
return err return err
} }
genesisBlk := blocks.NewGenesisBlock(stateRoot[:]) genesisBlk := blocks.NewGenesisBlock(stateRoot[:])
genesisBlkRoot, err := stateutil.BlockRoot(genesisBlk.Block) genesisBlkRoot, err := genesisBlk.Block.HashTreeRoot()
if err != nil { if err != nil {
return errors.Wrap(err, "could not get genesis block root") return errors.Wrap(err, "could not get genesis block root")
} }
@@ -388,7 +387,7 @@ func (s *Service) initializeChainInfo(ctx context.Context) error {
if genesisBlock == nil { if genesisBlock == nil {
return errors.New("no genesis block in db") return errors.New("no genesis block in db")
} }
genesisBlkRoot, err := stateutil.BlockRoot(genesisBlock.Block) genesisBlkRoot, err := genesisBlock.Block.HashTreeRoot()
if err != nil { if err != nil {
return errors.Wrap(err, "could not get signing root of genesis block") return errors.Wrap(err, "could not get signing root of genesis block")
} }
@@ -399,7 +398,7 @@ func (s *Service) initializeChainInfo(ctx context.Context) error {
if err != nil { if err != nil {
return errors.Wrap(err, "could not retrieve head block") return errors.Wrap(err, "could not retrieve head block")
} }
headRoot, err := stateutil.BlockRoot(headBlock.Block) headRoot, err := headBlock.Block.HashTreeRoot()
if err != nil { if err != nil {
return errors.Wrap(err, "could not hash head block") return errors.Wrap(err, "could not hash head block")
} }

View File

@@ -11,7 +11,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" 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"
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache" "github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
@@ -25,7 +24,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/powchain" "github.com/prysmaticlabs/prysm/beacon-chain/powchain"
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state" beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
protodb "github.com/prysmaticlabs/prysm/proto/beacon/db" protodb "github.com/prysmaticlabs/prysm/proto/beacon/db"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
@@ -137,7 +135,7 @@ func TestChainStartStop_Initialized(t *testing.T) {
chainService := setupBeaconChain(t, db, sc) chainService := setupBeaconChain(t, db, sc)
genesisBlk := testutil.NewBeaconBlock() genesisBlk := testutil.NewBeaconBlock()
blkRoot, err := stateutil.BlockRoot(genesisBlk.Block) blkRoot, err := genesisBlk.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveBlock(ctx, genesisBlk)) require.NoError(t, db.SaveBlock(ctx, genesisBlk))
s := testutil.NewBeaconState() s := testutil.NewBeaconState()
@@ -177,11 +175,12 @@ func TestChainService_InitializeBeaconChain(t *testing.T) {
err = genState.SetEth1Data(&ethpb.Eth1Data{ err = genState.SetEth1Data(&ethpb.Eth1Data{
DepositRoot: hashTreeRoot[:], DepositRoot: hashTreeRoot[:],
DepositCount: uint64(len(deposits)), DepositCount: uint64(len(deposits)),
BlockHash: make([]byte, 32),
}) })
genState, err = b.ProcessPreGenesisDeposits(ctx, genState, deposits) genState, err = b.ProcessPreGenesisDeposits(ctx, genState, deposits)
require.NoError(t, err) require.NoError(t, err)
_, err = bc.initializeBeaconChain(ctx, time.Unix(0, 0), genState, &ethpb.Eth1Data{DepositRoot: hashTreeRoot[:]}) _, err = bc.initializeBeaconChain(ctx, time.Unix(0, 0), genState, &ethpb.Eth1Data{DepositRoot: hashTreeRoot[:], BlockHash: make([]byte, 32)})
require.NoError(t, err) require.NoError(t, err)
_, err = bc.HeadState(ctx) _, err = bc.HeadState(ctx)
@@ -203,7 +202,7 @@ func TestChainService_CorrectGenesisRoots(t *testing.T) {
chainService := setupBeaconChain(t, db, sc) chainService := setupBeaconChain(t, db, sc)
genesisBlk := testutil.NewBeaconBlock() genesisBlk := testutil.NewBeaconBlock()
blkRoot, err := stateutil.BlockRoot(genesisBlk.Block) blkRoot, err := genesisBlk.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveBlock(ctx, genesisBlk)) require.NoError(t, db.SaveBlock(ctx, genesisBlk))
s := testutil.NewBeaconState() s := testutil.NewBeaconState()
@@ -226,7 +225,7 @@ func TestChainService_InitializeChainInfo(t *testing.T) {
ctx := context.Background() ctx := context.Background()
genesis := testutil.NewBeaconBlock() genesis := testutil.NewBeaconBlock()
genesisRoot, err := stateutil.BlockRoot(genesis.Block) genesisRoot, err := genesis.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, genesisRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, genesisRoot))
require.NoError(t, db.SaveBlock(ctx, genesis)) require.NoError(t, db.SaveBlock(ctx, genesis))
@@ -238,7 +237,7 @@ func TestChainService_InitializeChainInfo(t *testing.T) {
headState := testutil.NewBeaconState() headState := testutil.NewBeaconState()
require.NoError(t, headState.SetSlot(finalizedSlot)) require.NoError(t, headState.SetSlot(finalizedSlot))
require.NoError(t, headState.SetGenesisValidatorRoot(params.BeaconConfig().ZeroHash[:])) require.NoError(t, headState.SetGenesisValidatorRoot(params.BeaconConfig().ZeroHash[:]))
headRoot, err := stateutil.BlockRoot(headBlock.Block) headRoot, err := headBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveState(ctx, headState, headRoot)) require.NoError(t, db.SaveState(ctx, headState, headRoot))
require.NoError(t, db.SaveState(ctx, headState, genesisRoot)) require.NoError(t, db.SaveState(ctx, headState, genesisRoot))
@@ -268,8 +267,9 @@ func TestChainService_SaveHeadNoDB(t *testing.T) {
beaconDB: db, beaconDB: db,
stateGen: stategen.New(db, sc), stateGen: stategen.New(db, sc),
} }
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 1}} b := testutil.NewBeaconBlock()
r, err := ssz.HashTreeRoot(b) b.Block.Slot = 1
r, err := b.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
newState := testutil.NewBeaconState() newState := testutil.NewBeaconState()
require.NoError(t, s.stateGen.SaveState(ctx, r, newState)) require.NoError(t, s.stateGen.SaveState(ctx, r, newState))
@@ -287,15 +287,13 @@ func TestHasBlock_ForkChoiceAndDB(t *testing.T) {
db, _ := testDB.SetupDB(t) db, _ := testDB.SetupDB(t)
s := &Service{ s := &Service{
forkChoiceStore: protoarray.New(0, 0, [32]byte{}), forkChoiceStore: protoarray.New(0, 0, [32]byte{}),
finalizedCheckpt: &ethpb.Checkpoint{}, finalizedCheckpt: &ethpb.Checkpoint{Root: make([]byte, 32)},
beaconDB: db, beaconDB: db,
} }
block := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Body: &ethpb.BeaconBlockBody{}}} block := testutil.NewBeaconBlock()
r, err := stateutil.BlockRoot(block.Block) r, err := block.Block.HashTreeRoot()
require.NoError(t, err)
bs := &pb.BeaconState{FinalizedCheckpoint: &ethpb.Checkpoint{}, CurrentJustifiedCheckpoint: &ethpb.Checkpoint{}}
state, err := beaconstate.InitializeFromProto(bs)
require.NoError(t, err) require.NoError(t, err)
state := testutil.NewBeaconState()
require.NoError(t, s.insertBlockAndAttestationsToForkChoiceStore(ctx, block.Block, r, state)) require.NoError(t, s.insertBlockAndAttestationsToForkChoiceStore(ctx, block.Block, r, state))
assert.Equal(t, false, s.hasBlock(ctx, [32]byte{}), "Should not have block") assert.Equal(t, false, s.hasBlock(ctx, [32]byte{}), "Should not have block")
@@ -308,9 +306,9 @@ func BenchmarkHasBlockDB(b *testing.B) {
s := &Service{ s := &Service{
beaconDB: db, beaconDB: db,
} }
block := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} block := testutil.NewBeaconBlock()
require.NoError(b, s.beaconDB.SaveBlock(ctx, block)) require.NoError(b, s.beaconDB.SaveBlock(ctx, block))
r, err := stateutil.BlockRoot(block.Block) r, err := block.Block.HashTreeRoot()
require.NoError(b, err) require.NoError(b, err)
b.ResetTimer() b.ResetTimer()
@@ -324,13 +322,13 @@ func BenchmarkHasBlockForkChoiceStore(b *testing.B) {
db, _ := testDB.SetupDB(b) db, _ := testDB.SetupDB(b)
s := &Service{ s := &Service{
forkChoiceStore: protoarray.New(0, 0, [32]byte{}), forkChoiceStore: protoarray.New(0, 0, [32]byte{}),
finalizedCheckpt: &ethpb.Checkpoint{}, finalizedCheckpt: &ethpb.Checkpoint{Root: make([]byte, 32)},
beaconDB: db, beaconDB: db,
} }
block := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Body: &ethpb.BeaconBlockBody{}}} block := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Body: &ethpb.BeaconBlockBody{}}}
r, err := stateutil.BlockRoot(block.Block) r, err := block.Block.HashTreeRoot()
require.NoError(b, err) require.NoError(b, err)
bs := &pb.BeaconState{FinalizedCheckpoint: &ethpb.Checkpoint{}, CurrentJustifiedCheckpoint: &ethpb.Checkpoint{}} bs := &pb.BeaconState{FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)}, CurrentJustifiedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)}}
state, err := beaconstate.InitializeFromProto(bs) state, err := beaconstate.InitializeFromProto(bs)
require.NoError(b, err) require.NoError(b, err)
require.NoError(b, s.insertBlockAndAttestationsToForkChoiceStore(ctx, block.Block, r, state)) require.NoError(b, s.insertBlockAndAttestationsToForkChoiceStore(ctx, block.Block, r, state))

View File

@@ -19,7 +19,6 @@ go_library(
"//beacon-chain/db:go_default_library", "//beacon-chain/db:go_default_library",
"//beacon-chain/forkchoice/protoarray:go_default_library", "//beacon-chain/forkchoice/protoarray:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
"//shared/bytesutil:go_default_library", "//shared/bytesutil:go_default_library",
"//shared/event:go_default_library", "//shared/event:go_default_library",

View File

@@ -19,7 +19,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray" "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" 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" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event" "github.com/prysmaticlabs/prysm/shared/event"
@@ -153,7 +152,7 @@ func (ms *ChainService) ReceiveBlockInitialSync(ctx context.Context, block *ethp
return err return err
} }
ms.BlocksReceived = append(ms.BlocksReceived, block) ms.BlocksReceived = append(ms.BlocksReceived, block)
signingRoot, err := stateutil.BlockRoot(block.Block) signingRoot, err := block.Block.HashTreeRoot()
if err != nil { if err != nil {
return err return err
} }
@@ -181,7 +180,7 @@ func (ms *ChainService) ReceiveBlockBatch(ctx context.Context, blks []*ethpb.Sig
return err return err
} }
ms.BlocksReceived = append(ms.BlocksReceived, block) ms.BlocksReceived = append(ms.BlocksReceived, block)
signingRoot, err := stateutil.BlockRoot(block.Block) signingRoot, err := block.Block.HashTreeRoot()
if err != nil { if err != nil {
return err return err
} }
@@ -209,7 +208,7 @@ func (ms *ChainService) ReceiveBlock(ctx context.Context, block *ethpb.SignedBea
return err return err
} }
ms.BlocksReceived = append(ms.BlocksReceived, block) ms.BlocksReceived = append(ms.BlocksReceived, block)
signingRoot, err := stateutil.BlockRoot(block.Block) signingRoot, err := block.Block.HashTreeRoot()
if err != nil { if err != nil {
return err return err
} }
@@ -234,8 +233,10 @@ func (ms *ChainService) HeadSlot() uint64 {
// HeadRoot mocks HeadRoot method in chain service. // HeadRoot mocks HeadRoot method in chain service.
func (ms *ChainService) HeadRoot(ctx context.Context) ([]byte, error) { func (ms *ChainService) HeadRoot(ctx context.Context) ([]byte, error) {
return ms.Root, nil if len(ms.Root) > 0 {
return ms.Root, nil
}
return make([]byte, 32), nil
} }
// HeadBlock mocks HeadBlock method in chain service. // HeadBlock mocks HeadBlock method in chain service.

View File

@@ -26,7 +26,7 @@ func TestAttestationCache_RoundTrip(t *testing.T) {
assert.NoError(t, c.MarkInProgress(req)) assert.NoError(t, c.MarkInProgress(req))
res := &ethpb.AttestationData{ res := &ethpb.AttestationData{
Target: &ethpb.Checkpoint{Epoch: 5}, Target: &ethpb.Checkpoint{Epoch: 5, Root: make([]byte, 32)},
} }
assert.NoError(t, c.Put(ctx, req, res)) assert.NoError(t, c.Put(ctx, req, res))

View File

@@ -61,7 +61,7 @@ func TestCheckpointStateCache_MaxSize(t *testing.T) {
for i := uint64(0); i < uint64(maxCheckpointStateSize+100); i++ { for i := uint64(0); i < uint64(maxCheckpointStateSize+100); i++ {
require.NoError(t, st.SetSlot(i)) require.NoError(t, st.SetSlot(i))
require.NoError(t, c.AddCheckpointState(&ethpb.Checkpoint{Epoch: i}, st)) require.NoError(t, c.AddCheckpointState(&ethpb.Checkpoint{Epoch: i, Root: make([]byte, 32)}, st))
} }
assert.Equal(t, maxCheckpointStateSize, len(c.cache.Keys())) assert.Equal(t, maxCheckpointStateSize, len(c.cache.Keys()))

View File

@@ -18,7 +18,6 @@ go_library(
"@com_github_prometheus_client_golang//prometheus:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto: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_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//:go_default_library",
"@io_opencensus_go//trace:go_default_library", "@io_opencensus_go//trace:go_default_library",
], ],
@@ -40,7 +39,6 @@ go_test(
"//shared/trieutil:go_default_library", "//shared/trieutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1: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", "@com_github_sirupsen_logrus//hooks/test:go_default_library",
], ],
) )

View File

@@ -15,7 +15,6 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promauto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
dbpb "github.com/prysmaticlabs/prysm/proto/beacon/db" dbpb "github.com/prysmaticlabs/prysm/proto/beacon/db"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
@@ -128,7 +127,7 @@ func (dc *DepositCache) InsertFinalizedDeposits(ctx context.Context, eth1Deposit
if d.Index > eth1DepositIndex { if d.Index > eth1DepositIndex {
break break
} }
depHash, err := ssz.HashTreeRoot(d.Deposit.Data) depHash, err := d.Deposit.Data.HashTreeRoot()
if err != nil { if err != nil {
log.WithError(err).Error("Could not hash deposit data. Finalized deposit cache not updated.") log.WithError(err).Error("Could not hash deposit data. Finalized deposit cache not updated.")
return return

View File

@@ -8,7 +8,6 @@ import (
"testing" "testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
dbpb "github.com/prysmaticlabs/prysm/proto/beacon/db" dbpb "github.com/prysmaticlabs/prysm/proto/beacon/db"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
@@ -162,32 +161,74 @@ func TestDepositsNumberAndRootAtHeight_ReturnsAppropriateCountAndRoot(t *testing
dc.deposits = []*dbpb.DepositContainer{ dc.deposits = []*dbpb.DepositContainer{
{ {
Eth1BlockHeight: 10, Eth1BlockHeight: 10,
Deposit: &ethpb.Deposit{}, Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{
PublicKey: make([]byte, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
},
},
}, },
{ {
Eth1BlockHeight: 10, Eth1BlockHeight: 10,
Deposit: &ethpb.Deposit{}, Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{
PublicKey: make([]byte, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
},
},
}, },
{ {
Eth1BlockHeight: 10, Eth1BlockHeight: 10,
Deposit: &ethpb.Deposit{}, Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{
PublicKey: make([]byte, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
},
},
}, },
{ {
Eth1BlockHeight: 10, Eth1BlockHeight: 10,
Deposit: &ethpb.Deposit{}, Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{
PublicKey: make([]byte, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
},
},
}, },
{ {
Eth1BlockHeight: 11, Eth1BlockHeight: 11,
Deposit: &ethpb.Deposit{}, Deposit: &ethpb.Deposit{
DepositRoot: []byte("root"), Data: &ethpb.Deposit_Data{
PublicKey: make([]byte, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
},
},
DepositRoot: bytesutil.PadTo([]byte("root"), 32),
}, },
{ {
Eth1BlockHeight: 12, Eth1BlockHeight: 12,
Deposit: &ethpb.Deposit{}, Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{
PublicKey: make([]byte, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
},
},
}, },
{ {
Eth1BlockHeight: 12, Eth1BlockHeight: 12,
Deposit: &ethpb.Deposit{}, Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{
PublicKey: make([]byte, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
},
},
}, },
} }
@@ -203,13 +244,25 @@ func TestDepositsNumberAndRootAtHeight_ReturnsEmptyTrieIfBlockHeightLessThanOlde
dc.deposits = []*dbpb.DepositContainer{ dc.deposits = []*dbpb.DepositContainer{
{ {
Eth1BlockHeight: 10, Eth1BlockHeight: 10,
Deposit: &ethpb.Deposit{}, Deposit: &ethpb.Deposit{
DepositRoot: []byte("root"), Data: &ethpb.Deposit_Data{
PublicKey: make([]byte, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
},
},
DepositRoot: bytesutil.PadTo([]byte("root"), 32),
}, },
{ {
Eth1BlockHeight: 11, Eth1BlockHeight: 11,
Deposit: &ethpb.Deposit{}, Deposit: &ethpb.Deposit{
DepositRoot: []byte("root"), Data: &ethpb.Deposit_Data{
PublicKey: make([]byte, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
},
},
DepositRoot: bytesutil.PadTo([]byte("root"), 32),
}, },
} }
@@ -227,7 +280,9 @@ func TestDepositByPubkey_ReturnsFirstMatchingDeposit(t *testing.T) {
Eth1BlockHeight: 9, Eth1BlockHeight: 9,
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte("pk0"), PublicKey: bytesutil.PadTo([]byte("pk0"), 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
}, },
@@ -235,7 +290,9 @@ func TestDepositByPubkey_ReturnsFirstMatchingDeposit(t *testing.T) {
Eth1BlockHeight: 10, Eth1BlockHeight: 10,
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte("pk1"), PublicKey: bytesutil.PadTo([]byte("pk1"), 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
}, },
@@ -243,7 +300,9 @@ func TestDepositByPubkey_ReturnsFirstMatchingDeposit(t *testing.T) {
Eth1BlockHeight: 11, Eth1BlockHeight: 11,
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte("pk1"), PublicKey: bytesutil.PadTo([]byte("pk1"), 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
}, },
@@ -251,15 +310,18 @@ func TestDepositByPubkey_ReturnsFirstMatchingDeposit(t *testing.T) {
Eth1BlockHeight: 12, Eth1BlockHeight: 12,
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte("pk2"), PublicKey: bytesutil.PadTo([]byte("pk2"), 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
}, },
} }
dep, blkNum := dc.DepositByPubkey(context.Background(), []byte("pk1")) pk1 := bytesutil.PadTo([]byte("pk1"), 48)
dep, blkNum := dc.DepositByPubkey(context.Background(), pk1)
if !bytes.Equal(dep.Data.PublicKey, []byte("pk1")) { if dep == nil || !bytes.Equal(dep.Data.PublicKey, pk1) {
t.Error("Returned wrong deposit") t.Error("Returned wrong deposit")
} }
assert.Equal(t, 0, blkNum.Cmp(big.NewInt(10)), assert.Equal(t, 0, blkNum.Cmp(big.NewInt(10)),
@@ -274,7 +336,9 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
{ {
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{0}, PublicKey: bytesutil.PadTo([]byte{0}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 0, Index: 0,
@@ -282,7 +346,9 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
{ {
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{1}, PublicKey: bytesutil.PadTo([]byte{1}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 1, Index: 1,
@@ -290,7 +356,9 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
{ {
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{2}, PublicKey: bytesutil.PadTo([]byte{2}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 2, Index: 2,
@@ -299,7 +367,9 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
dc.deposits = append(finalizedDeposits, &dbpb.DepositContainer{ dc.deposits = append(finalizedDeposits, &dbpb.DepositContainer{
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{3}, PublicKey: bytesutil.PadTo([]byte{3}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 3, Index: 3,
@@ -313,7 +383,7 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
var deps [][]byte var deps [][]byte
for _, d := range finalizedDeposits { for _, d := range finalizedDeposits {
hash, err := ssz.HashTreeRoot(d.Deposit.Data) hash, err := d.Deposit.Data.HashTreeRoot()
require.NoError(t, err, "Could not hash deposit data") require.NoError(t, err, "Could not hash deposit data")
deps = append(deps, hash[:]) deps = append(deps, hash[:])
} }
@@ -330,7 +400,9 @@ func TestFinalizedDeposits_UtilizesPreviouslyCachedDeposits(t *testing.T) {
{ {
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{0}, PublicKey: bytesutil.PadTo([]byte{0}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 0, Index: 0,
@@ -338,7 +410,9 @@ func TestFinalizedDeposits_UtilizesPreviouslyCachedDeposits(t *testing.T) {
{ {
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{1}, PublicKey: bytesutil.PadTo([]byte{1}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 1, Index: 1,
@@ -347,7 +421,9 @@ func TestFinalizedDeposits_UtilizesPreviouslyCachedDeposits(t *testing.T) {
newFinalizedDeposit := dbpb.DepositContainer{ newFinalizedDeposit := dbpb.DepositContainer{
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{2}, PublicKey: bytesutil.PadTo([]byte{2}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 2, Index: 2,
@@ -365,7 +441,7 @@ func TestFinalizedDeposits_UtilizesPreviouslyCachedDeposits(t *testing.T) {
var deps [][]byte var deps [][]byte
for _, d := range append(oldFinalizedDeposits, &newFinalizedDeposit) { for _, d := range append(oldFinalizedDeposits, &newFinalizedDeposit) {
hash, err := ssz.HashTreeRoot(d.Deposit.Data) hash, err := d.Deposit.Data.HashTreeRoot()
require.NoError(t, err, "Could not hash deposit data") require.NoError(t, err, "Could not hash deposit data")
deps = append(deps, hash[:]) deps = append(deps, hash[:])
} }
@@ -393,7 +469,9 @@ func TestNonFinalizedDeposits_ReturnsAllNonFinalizedDeposits(t *testing.T) {
Eth1BlockHeight: 10, Eth1BlockHeight: 10,
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{0}, PublicKey: bytesutil.PadTo([]byte{0}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 0, Index: 0,
@@ -402,7 +480,9 @@ func TestNonFinalizedDeposits_ReturnsAllNonFinalizedDeposits(t *testing.T) {
Eth1BlockHeight: 10, Eth1BlockHeight: 10,
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{1}, PublicKey: bytesutil.PadTo([]byte{1}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 1, Index: 1,
@@ -413,7 +493,9 @@ func TestNonFinalizedDeposits_ReturnsAllNonFinalizedDeposits(t *testing.T) {
Eth1BlockHeight: 10, Eth1BlockHeight: 10,
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{2}, PublicKey: bytesutil.PadTo([]byte{2}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 2, Index: 2,
@@ -422,7 +504,9 @@ func TestNonFinalizedDeposits_ReturnsAllNonFinalizedDeposits(t *testing.T) {
Eth1BlockHeight: 11, Eth1BlockHeight: 11,
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{3}, PublicKey: bytesutil.PadTo([]byte{3}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 3, Index: 3,
@@ -442,7 +526,9 @@ func TestNonFinalizedDeposits_ReturnsNonFinalizedDepositsUpToBlockNumber(t *test
Eth1BlockHeight: 10, Eth1BlockHeight: 10,
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{0}, PublicKey: bytesutil.PadTo([]byte{0}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 0, Index: 0,
@@ -451,7 +537,9 @@ func TestNonFinalizedDeposits_ReturnsNonFinalizedDepositsUpToBlockNumber(t *test
Eth1BlockHeight: 10, Eth1BlockHeight: 10,
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{1}, PublicKey: bytesutil.PadTo([]byte{1}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 1, Index: 1,
@@ -462,7 +550,9 @@ func TestNonFinalizedDeposits_ReturnsNonFinalizedDepositsUpToBlockNumber(t *test
Eth1BlockHeight: 10, Eth1BlockHeight: 10,
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{2}, PublicKey: bytesutil.PadTo([]byte{2}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 2, Index: 2,
@@ -471,7 +561,9 @@ func TestNonFinalizedDeposits_ReturnsNonFinalizedDepositsUpToBlockNumber(t *test
Eth1BlockHeight: 11, Eth1BlockHeight: 11,
Deposit: &ethpb.Deposit{ Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{3}, PublicKey: bytesutil.PadTo([]byte{3}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
}, },
Index: 3, Index: 3,

View File

@@ -29,14 +29,28 @@ func TestInsertPendingDeposit_ignoresNilDeposit(t *testing.T) {
assert.Equal(t, 0, len(dc.pendingDeposits)) 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) { func TestRemovePendingDeposit_OK(t *testing.T) {
db := DepositCache{} db := DepositCache{}
proof1 := make([][]byte, int(params.BeaconConfig().DepositContractTreeDepth)+1) proof1 := makeDepositProof()
proof1[0] = bytesutil.PadTo([]byte{'A'}, 32) proof1[0] = bytesutil.PadTo([]byte{'A'}, 32)
proof2 := make([][]byte, int(params.BeaconConfig().DepositContractTreeDepth)+1) proof2 := makeDepositProof()
proof2[0] = bytesutil.PadTo([]byte{'A'}, 32) proof2[0] = bytesutil.PadTo([]byte{'A'}, 32)
depToRemove := &ethpb.Deposit{Proof: proof1} data := &ethpb.Deposit_Data{
otherDep := &ethpb.Deposit{Proof: proof2} PublicKey: make([]byte, 48),
WithdrawalCredentials: make([]byte, 32),
Amount: 0,
Signature: make([]byte, 96),
}
depToRemove := &ethpb.Deposit{Proof: proof1, Data: data}
otherDep := &ethpb.Deposit{Proof: proof2, Data: data}
db.pendingDeposits = []*dbpb.DepositContainer{ db.pendingDeposits = []*dbpb.DepositContainer{
{Deposit: depToRemove, Index: 1}, {Deposit: depToRemove, Index: 1},
{Deposit: otherDep, Index: 5}, {Deposit: otherDep, Index: 5},
@@ -57,9 +71,15 @@ func TestRemovePendingDeposit_IgnoresNilDeposit(t *testing.T) {
func TestPendingDeposit_RoundTrip(t *testing.T) { func TestPendingDeposit_RoundTrip(t *testing.T) {
dc := DepositCache{} dc := DepositCache{}
proof := make([][]byte, int(params.BeaconConfig().DepositContractTreeDepth)+1) proof := makeDepositProof()
proof[0] = bytesutil.PadTo([]byte{'A'}, 32) proof[0] = bytesutil.PadTo([]byte{'A'}, 32)
dep := &ethpb.Deposit{Proof: proof} data := &ethpb.Deposit_Data{
PublicKey: make([]byte, 48),
WithdrawalCredentials: make([]byte, 32),
Amount: 0,
Signature: make([]byte, 96),
}
dep := &ethpb.Deposit{Proof: proof, Data: data}
dc.InsertPendingDeposit(context.Background(), dep, 111, 100, [32]byte{}) dc.InsertPendingDeposit(context.Background(), dep, 111, 100, [32]byte{})
dc.RemovePendingDeposit(context.Background(), dep) dc.RemovePendingDeposit(context.Background(), dep)
assert.Equal(t, 0, len(dc.pendingDeposits), "Failed to insert & delete a pending deposit") assert.Equal(t, 0, len(dc.pendingDeposits), "Failed to insert & delete a pending deposit")

View File

@@ -26,7 +26,6 @@ go_library(
"//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/validators:go_default_library", "//beacon-chain/core/validators:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
"//shared/attestationutil:go_default_library", "//shared/attestationutil:go_default_library",
"//shared/bls:go_default_library", "//shared/bls:go_default_library",
@@ -63,10 +62,10 @@ go_test(
"randao_test.go", "randao_test.go",
], ],
embed = [":go_default_library"], embed = [":go_default_library"],
shard_count = 2,
deps = [ deps = [
"//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
"//shared/aggregation:go_default_library", "//shared/aggregation:go_default_library",
"//shared/aggregation/attestations:go_default_library", "//shared/aggregation/attestations:go_default_library",
@@ -82,7 +81,6 @@ go_test(
"@com_github_google_gofuzz//:go_default_library", "@com_github_google_gofuzz//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//: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//:go_default_library",
], ],
) )

View File

@@ -15,6 +15,7 @@ import (
attaggregation "github.com/prysmaticlabs/prysm/shared/aggregation/attestations" attaggregation "github.com/prysmaticlabs/prysm/shared/aggregation/attestations"
"github.com/prysmaticlabs/prysm/shared/attestationutil" "github.com/prysmaticlabs/prysm/shared/attestationutil"
"github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/assert"
@@ -25,7 +26,7 @@ func TestProcessAttestations_InclusionDelayFailure(t *testing.T) {
attestations := []*ethpb.Attestation{ attestations := []*ethpb.Attestation{
{ {
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
Slot: 5, Slot: 5,
}, },
}, },
@@ -81,8 +82,8 @@ func TestProcessAttestations_CurrentEpochFFGDataMismatches(t *testing.T) {
attestations := []*ethpb.Attestation{ attestations := []*ethpb.Attestation{
{ {
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Epoch: 1}, Source: &ethpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
}, },
AggregationBits: aggBits, AggregationBits: aggBits,
}, },
@@ -127,8 +128,8 @@ func TestProcessAttestations_PrevEpochFFGDataMismatches(t *testing.T) {
attestations := []*ethpb.Attestation{ attestations := []*ethpb.Attestation{
{ {
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 1}, Source: &ethpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 1}, Target: &ethpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
Slot: params.BeaconConfig().SlotsPerEpoch, Slot: params.BeaconConfig().SlotsPerEpoch,
}, },
AggregationBits: aggBits, AggregationBits: aggBits,
@@ -207,10 +208,12 @@ func TestProcessAttestations_OK(t *testing.T) {
copy(mockRoot[:], "hello-world") copy(mockRoot[:], "hello-world")
att := &ethpb.Attestation{ att := &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot[:]}, Source: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
Target: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot[:]}, Target: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
BeaconBlockRoot: make([]byte, 32),
}, },
AggregationBits: aggBits, AggregationBits: aggBits,
Signature: make([]byte, 96),
} }
cfc := beaconState.CurrentJustifiedCheckpoint() cfc := beaconState.CurrentJustifiedCheckpoint()
@@ -232,23 +235,21 @@ func TestProcessAttestations_OK(t *testing.T) {
} }
att.Signature = bls.AggregateSignatures(sigs).Marshal()[:] att.Signature = bls.AggregateSignatures(sigs).Marshal()[:]
block := &ethpb.BeaconBlock{ block := testutil.NewBeaconBlock()
Body: &ethpb.BeaconBlockBody{ block.Block.Body.Attestations = []*ethpb.Attestation{att}
Attestations: []*ethpb.Attestation{att},
},
}
err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay) err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
require.NoError(t, err) require.NoError(t, err)
_, err = blocks.ProcessAttestations(context.Background(), beaconState, block.Body) _, err = blocks.ProcessAttestations(context.Background(), beaconState, block.Block.Body)
assert.NoError(t, err) assert.NoError(t, err)
} }
func TestProcessAggregatedAttestation_OverlappingBits(t *testing.T) { func TestProcessAggregatedAttestation_OverlappingBits(t *testing.T) {
beaconState, privKeys := testutil.DeterministicGenesisState(t, 100) beaconState, privKeys := testutil.DeterministicGenesisState(t, 100)
data := &ethpb.AttestationData{ data := &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0, Root: []byte("hello-world")}, Source: &ethpb.Checkpoint{Epoch: 0, Root: bytesutil.PadTo([]byte("hello-world"), 32)},
Target: &ethpb.Checkpoint{Epoch: 0, Root: []byte("hello-world")}, Target: &ethpb.Checkpoint{Epoch: 0, Root: bytesutil.PadTo([]byte("hello-world"), 32)},
BeaconBlockRoot: make([]byte, 32),
} }
aggBits1 := bitfield.NewBitlist(4) aggBits1 := bitfield.NewBitlist(4)
aggBits1.SetBitAt(0, true) aggBits1.SetBitAt(0, true)
@@ -260,7 +261,7 @@ func TestProcessAggregatedAttestation_OverlappingBits(t *testing.T) {
} }
cfc := beaconState.CurrentJustifiedCheckpoint() cfc := beaconState.CurrentJustifiedCheckpoint()
cfc.Root = []byte("hello-world") cfc.Root = bytesutil.PadTo([]byte("hello-world"), 32)
require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(cfc)) require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(cfc))
require.NoError(t, beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{})) require.NoError(t, beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}))
@@ -311,8 +312,9 @@ func TestProcessAggregatedAttestation_NoOverlappingBits(t *testing.T) {
var mockRoot [32]byte var mockRoot [32]byte
copy(mockRoot[:], "hello-world") copy(mockRoot[:], "hello-world")
data := &ethpb.AttestationData{ data := &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot[:]}, Source: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
Target: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot[:]}, Target: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
BeaconBlockRoot: make([]byte, 32),
} }
aggBits1 := bitfield.NewBitlist(9) aggBits1 := bitfield.NewBitlist(9)
aggBits1.SetBitAt(0, true) aggBits1.SetBitAt(0, true)
@@ -320,6 +322,7 @@ func TestProcessAggregatedAttestation_NoOverlappingBits(t *testing.T) {
att1 := &ethpb.Attestation{ att1 := &ethpb.Attestation{
Data: data, Data: data,
AggregationBits: aggBits1, AggregationBits: aggBits1,
Signature: make([]byte, 32),
} }
cfc := beaconState.CurrentJustifiedCheckpoint() cfc := beaconState.CurrentJustifiedCheckpoint()
@@ -347,6 +350,7 @@ func TestProcessAggregatedAttestation_NoOverlappingBits(t *testing.T) {
att2 := &ethpb.Attestation{ att2 := &ethpb.Attestation{
Data: data, Data: data,
AggregationBits: aggBits2, AggregationBits: aggBits2,
Signature: make([]byte, 32),
} }
committee, err = helpers.BeaconCommitteeFromState(beaconState, att2.Data.Slot, att2.Data.CommitteeIndex) committee, err = helpers.BeaconCommitteeFromState(beaconState, att2.Data.Slot, att2.Data.CommitteeIndex)
@@ -365,16 +369,13 @@ func TestProcessAggregatedAttestation_NoOverlappingBits(t *testing.T) {
aggregatedAtt, err := attaggregation.AggregatePair(att1, att2) aggregatedAtt, err := attaggregation.AggregatePair(att1, att2)
require.NoError(t, err) require.NoError(t, err)
block := &ethpb.BeaconBlock{ block := testutil.NewBeaconBlock()
Body: &ethpb.BeaconBlockBody{ block.Block.Body.Attestations = []*ethpb.Attestation{aggregatedAtt}
Attestations: []*ethpb.Attestation{aggregatedAtt},
},
}
err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay) err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
require.NoError(t, err) require.NoError(t, err)
_, err = blocks.ProcessAttestations(context.Background(), beaconState, block.Body) _, err = blocks.ProcessAttestations(context.Background(), beaconState, block.Block.Body)
assert.NoError(t, err) assert.NoError(t, err)
} }
@@ -384,7 +385,7 @@ func TestProcessAttestationsNoVerify_IncorrectSlotTargetEpoch(t *testing.T) {
att := &ethpb.Attestation{ att := &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: params.BeaconConfig().SlotsPerEpoch, Slot: params.BeaconConfig().SlotsPerEpoch,
Target: &ethpb.Checkpoint{}, Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
} }
wanted := fmt.Sprintf("data slot is not in the same epoch as target %d != %d", helpers.SlotToEpoch(att.Data.Slot), att.Data.Target.Epoch) wanted := fmt.Sprintf("data slot is not in the same epoch as target %d != %d", helpers.SlotToEpoch(att.Data.Slot), att.Data.Target.Epoch)
@@ -404,7 +405,7 @@ func TestProcessAttestationsNoVerify_OK(t *testing.T) {
att := &ethpb.Attestation{ att := &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot[:]}, Source: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
}, },
AggregationBits: aggBits, AggregationBits: aggBits,
} }
@@ -433,7 +434,7 @@ func TestProcessAttestationsNoVerify_BadAttIdx(t *testing.T) {
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
CommitteeIndex: 100, CommitteeIndex: 100,
Source: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot[:]}, Source: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
}, },
AggregationBits: aggBits, AggregationBits: aggBits,
} }
@@ -486,8 +487,8 @@ func TestConvertToIndexed_OK(t *testing.T) {
attestation := &ethpb.Attestation{ attestation := &ethpb.Attestation{
Signature: sig[:], Signature: sig[:],
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0}, Source: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
}, },
} }
for _, tt := range tests { for _, tt := range tests {
@@ -512,8 +513,9 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
for i := 0; i < len(validators); i++ { for i := 0; i < len(validators); i++ {
validators[i] = &ethpb.Validator{ validators[i] = &ethpb.Validator{
ExitEpoch: params.BeaconConfig().FarFutureEpoch, ExitEpoch: params.BeaconConfig().FarFutureEpoch,
PublicKey: keys[i].PublicKey().Marshal(), PublicKey: keys[i].PublicKey().Marshal(),
WithdrawalCredentials: make([]byte, 32),
} }
} }
@@ -535,33 +537,57 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) {
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{ Target: &ethpb.Checkpoint{
Epoch: 2, Epoch: 2,
Root: make([]byte, 32),
}, },
Source: &ethpb.Checkpoint{
Root: make([]byte, 32),
},
BeaconBlockRoot: make([]byte, 32),
}, },
AttestingIndices: []uint64{1}, AttestingIndices: []uint64{1},
Signature: make([]byte, 96),
}}, }},
{attestation: &ethpb.IndexedAttestation{ {attestation: &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{ Target: &ethpb.Checkpoint{
Epoch: 1, Epoch: 1,
Root: make([]byte, 32),
}, },
Source: &ethpb.Checkpoint{
Root: make([]byte, 32),
},
BeaconBlockRoot: make([]byte, 32),
}, },
AttestingIndices: []uint64{47, 99, 101}, AttestingIndices: []uint64{47, 99, 101},
Signature: make([]byte, 96),
}}, }},
{attestation: &ethpb.IndexedAttestation{ {attestation: &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{ Target: &ethpb.Checkpoint{
Epoch: 4, Epoch: 4,
Root: make([]byte, 32),
}, },
Source: &ethpb.Checkpoint{
Root: make([]byte, 32),
},
BeaconBlockRoot: make([]byte, 32),
}, },
AttestingIndices: []uint64{21, 72}, AttestingIndices: []uint64{21, 72},
Signature: make([]byte, 96),
}}, }},
{attestation: &ethpb.IndexedAttestation{ {attestation: &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{ Target: &ethpb.Checkpoint{
Epoch: 7, Epoch: 7,
Root: make([]byte, 32),
}, },
Source: &ethpb.Checkpoint{
Root: make([]byte, 32),
},
BeaconBlockRoot: make([]byte, 32),
}, },
AttestingIndices: []uint64{100, 121, 122}, AttestingIndices: []uint64{100, 121, 122},
Signature: make([]byte, 96),
}}, }},
} }
@@ -653,32 +679,28 @@ func TestVerifyAttestations_VerifiesMultipleAttestations(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
for i := 0; i < len(validators); i++ { for i := 0; i < len(validators); i++ {
validators[i] = &ethpb.Validator{ validators[i] = &ethpb.Validator{
ExitEpoch: params.BeaconConfig().FarFutureEpoch, ExitEpoch: params.BeaconConfig().FarFutureEpoch,
PublicKey: keys[i].PublicKey().Marshal(), PublicKey: keys[i].PublicKey().Marshal(),
WithdrawalCredentials: make([]byte, 32),
} }
} }
st, err := stateTrie.InitializeFromProto(&pb.BeaconState{ st := testutil.NewBeaconState()
Slot: 5, require.NoError(t, st.SetSlot(5))
Validators: validators, require.NoError(t, st.SetValidators(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*/) comm1, err := helpers.BeaconCommitteeFromState(st, 1 /*slot*/, 0 /*committeeIndex*/)
require.NoError(t, err) require.NoError(t, err)
att1 := &ethpb.Attestation{ att1 := &ethpb.Attestation{
AggregationBits: bitfield.NewBitlist(uint64(len(comm1))), AggregationBits: bitfield.NewBitlist(uint64(len(comm1))),
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
CommitteeIndex: 0, CommitteeIndex: 0,
Target: new(ethpb.Checkpoint), BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
Signature: nil, Signature: make([]byte, 96),
} }
domain, err := helpers.Domain(st.Fork(), st.Fork().Epoch, params.BeaconConfig().DomainBeaconAttester, st.GenesisValidatorRoot()) domain, err := helpers.Domain(st.Fork(), st.Fork().Epoch, params.BeaconConfig().DomainBeaconAttester, st.GenesisValidatorRoot())
require.NoError(t, err) require.NoError(t, err)
@@ -696,11 +718,13 @@ func TestVerifyAttestations_VerifiesMultipleAttestations(t *testing.T) {
att2 := &ethpb.Attestation{ att2 := &ethpb.Attestation{
AggregationBits: bitfield.NewBitlist(uint64(len(comm2))), AggregationBits: bitfield.NewBitlist(uint64(len(comm2))),
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
CommitteeIndex: 1, CommitteeIndex: 1,
Target: new(ethpb.Checkpoint), BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
Signature: nil, Signature: make([]byte, 96),
} }
root, err = helpers.ComputeSigningRoot(att2.Data, domain) root, err = helpers.ComputeSigningRoot(att2.Data, domain)
require.NoError(t, err) require.NoError(t, err)
@@ -723,32 +747,33 @@ func TestVerifyAttestations_HandlesPlannedFork(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
for i := 0; i < len(validators); i++ { for i := 0; i < len(validators); i++ {
validators[i] = &ethpb.Validator{ validators[i] = &ethpb.Validator{
ExitEpoch: params.BeaconConfig().FarFutureEpoch, ExitEpoch: params.BeaconConfig().FarFutureEpoch,
PublicKey: keys[i].PublicKey().Marshal(), PublicKey: keys[i].PublicKey().Marshal(),
WithdrawalCredentials: make([]byte, 32),
} }
} }
st, err := stateTrie.InitializeFromProto(&pb.BeaconState{ st := testutil.NewBeaconState()
Slot: 35, require.NoError(t, st.SetSlot(35))
Validators: validators, require.NoError(t, st.SetValidators(validators))
Fork: &pb.Fork{ require.NoError(t, st.SetFork(&pb.Fork{
Epoch: 1, Epoch: 1,
CurrentVersion: []byte{0, 1, 2, 3}, CurrentVersion: []byte{0, 1, 2, 3},
PreviousVersion: params.BeaconConfig().GenesisForkVersion, PreviousVersion: params.BeaconConfig().GenesisForkVersion,
}, }))
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
})
comm1, err := helpers.BeaconCommitteeFromState(st, 1 /*slot*/, 0 /*committeeIndex*/) comm1, err := helpers.BeaconCommitteeFromState(st, 1 /*slot*/, 0 /*committeeIndex*/)
require.NoError(t, err) require.NoError(t, err)
att1 := &ethpb.Attestation{ att1 := &ethpb.Attestation{
AggregationBits: bitfield.NewBitlist(uint64(len(comm1))), AggregationBits: bitfield.NewBitlist(uint64(len(comm1))),
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
CommitteeIndex: 0, CommitteeIndex: 0,
Target: new(ethpb.Checkpoint), BeaconBlockRoot: make([]byte, 32),
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
Signature: nil, Signature: make([]byte, 96),
} }
prevDomain, err := helpers.Domain(st.Fork(), st.Fork().Epoch-1, params.BeaconConfig().DomainBeaconAttester, st.GenesisValidatorRoot()) prevDomain, err := helpers.Domain(st.Fork(), st.Fork().Epoch-1, params.BeaconConfig().DomainBeaconAttester, st.GenesisValidatorRoot())
require.NoError(t, err) require.NoError(t, err)
@@ -766,11 +791,13 @@ func TestVerifyAttestations_HandlesPlannedFork(t *testing.T) {
att2 := &ethpb.Attestation{ att2 := &ethpb.Attestation{
AggregationBits: bitfield.NewBitlist(uint64(len(comm2))), AggregationBits: bitfield.NewBitlist(uint64(len(comm2))),
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1*params.BeaconConfig().SlotsPerEpoch + 1, Slot: 1*params.BeaconConfig().SlotsPerEpoch + 1,
CommitteeIndex: 1, CommitteeIndex: 1,
Target: new(ethpb.Checkpoint), BeaconBlockRoot: make([]byte, 32),
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
Signature: nil, Signature: make([]byte, 96),
} }
currDomain, err := helpers.Domain(st.Fork(), st.Fork().Epoch, params.BeaconConfig().DomainBeaconAttester, st.GenesisValidatorRoot()) currDomain, err := helpers.Domain(st.Fork(), st.Fork().Epoch, params.BeaconConfig().DomainBeaconAttester, st.GenesisValidatorRoot())
root, err = helpers.ComputeSigningRoot(att2.Data, currDomain) root, err = helpers.ComputeSigningRoot(att2.Data, currDomain)
@@ -793,32 +820,28 @@ func TestRetrieveAttestationSignatureSet_VerifiesMultipleAttestations(t *testing
require.NoError(t, err) require.NoError(t, err)
for i := 0; i < len(validators); i++ { for i := 0; i < len(validators); i++ {
validators[i] = &ethpb.Validator{ validators[i] = &ethpb.Validator{
ExitEpoch: params.BeaconConfig().FarFutureEpoch, ExitEpoch: params.BeaconConfig().FarFutureEpoch,
PublicKey: keys[i].PublicKey().Marshal(), PublicKey: keys[i].PublicKey().Marshal(),
WithdrawalCredentials: make([]byte, 32),
} }
} }
st, err := stateTrie.InitializeFromProto(&pb.BeaconState{ st := testutil.NewBeaconState()
Slot: 5, require.NoError(t, st.SetSlot(5))
Validators: validators, require.NoError(t, st.SetValidators(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*/) comm1, err := helpers.BeaconCommitteeFromState(st, 1 /*slot*/, 0 /*committeeIndex*/)
require.NoError(t, err) require.NoError(t, err)
att1 := &ethpb.Attestation{ att1 := &ethpb.Attestation{
AggregationBits: bitfield.NewBitlist(uint64(len(comm1))), AggregationBits: bitfield.NewBitlist(uint64(len(comm1))),
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
CommitteeIndex: 0, CommitteeIndex: 0,
Target: new(ethpb.Checkpoint), BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
Signature: nil, Signature: make([]byte, 96),
} }
domain, err := helpers.Domain(st.Fork(), st.Fork().Epoch, params.BeaconConfig().DomainBeaconAttester, st.GenesisValidatorRoot()) domain, err := helpers.Domain(st.Fork(), st.Fork().Epoch, params.BeaconConfig().DomainBeaconAttester, st.GenesisValidatorRoot())
require.NoError(t, err) require.NoError(t, err)
@@ -836,11 +859,13 @@ func TestRetrieveAttestationSignatureSet_VerifiesMultipleAttestations(t *testing
att2 := &ethpb.Attestation{ att2 := &ethpb.Attestation{
AggregationBits: bitfield.NewBitlist(uint64(len(comm2))), AggregationBits: bitfield.NewBitlist(uint64(len(comm2))),
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
CommitteeIndex: 1, CommitteeIndex: 1,
Target: new(ethpb.Checkpoint), BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
Signature: nil, Signature: make([]byte, 96),
} }
root, err = helpers.ComputeSigningRoot(att2.Data, domain) root, err = helpers.ComputeSigningRoot(att2.Data, domain)
require.NoError(t, err) require.NoError(t, err)

View File

@@ -11,6 +11,7 @@ import (
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/assert"
@@ -19,12 +20,14 @@ import (
func TestSlashableAttestationData_CanSlash(t *testing.T) { func TestSlashableAttestationData_CanSlash(t *testing.T) {
att1 := &ethpb.AttestationData{ att1 := &ethpb.AttestationData{
Target: &ethpb.Checkpoint{Epoch: 1}, Target: &ethpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: []byte{'A'}}, Source: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte{'A'}, 32)},
BeaconBlockRoot: make([]byte, 32),
} }
att2 := &ethpb.AttestationData{ att2 := &ethpb.AttestationData{
Target: &ethpb.Checkpoint{Epoch: 1}, Target: &ethpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: []byte{'B'}}, Source: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte{'B'}, 32)},
BeaconBlockRoot: make([]byte, 32),
} }
assert.Equal(t, true, blocks.IsSlashableAttestationData(att1, att2), "Atts should have been slashable") assert.Equal(t, true, blocks.IsSlashableAttestationData(att1, att2), "Atts should have been slashable")
att1.Target.Epoch = 4 att1.Target.Epoch = 4
@@ -38,15 +41,19 @@ func TestProcessAttesterSlashings_DataNotSlashable(t *testing.T) {
{ {
Attestation_1: &ethpb.IndexedAttestation{ Attestation_1: &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0}, Source: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
}, },
Signature: make([]byte, 96),
}, },
Attestation_2: &ethpb.IndexedAttestation{ Attestation_2: &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 1}, Source: &ethpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 1}, Target: &ethpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
}, },
Signature: make([]byte, 96),
}, },
}, },
} }
@@ -82,17 +89,21 @@ func TestProcessAttesterSlashings_IndexedAttestationFailedToVerify(t *testing.T)
{ {
Attestation_1: &ethpb.IndexedAttestation{ Attestation_1: &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 1}, Source: &ethpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
}, },
AttestingIndices: make([]uint64, params.BeaconConfig().MaxValidatorsPerCommittee+1), AttestingIndices: make([]uint64, params.BeaconConfig().MaxValidatorsPerCommittee+1),
Signature: make([]byte, 96),
}, },
Attestation_2: &ethpb.IndexedAttestation{ Attestation_2: &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0}, Source: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
}, },
AttestingIndices: make([]uint64, params.BeaconConfig().MaxValidatorsPerCommittee+1), AttestingIndices: make([]uint64, params.BeaconConfig().MaxValidatorsPerCommittee+1),
Signature: make([]byte, 96),
}, },
}, },
} }
@@ -116,8 +127,9 @@ func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) {
att1 := &ethpb.IndexedAttestation{ att1 := &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 1}, Source: &ethpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
}, },
AttestingIndices: []uint64{0, 1}, AttestingIndices: []uint64{0, 1},
} }
@@ -132,8 +144,9 @@ func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) {
att2 := &ethpb.IndexedAttestation{ att2 := &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0}, Source: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
}, },
AttestingIndices: []uint64{0, 1}, AttestingIndices: []uint64{0, 1},
} }

View File

@@ -39,10 +39,12 @@ func TestProcessAttesterSlashings_RegressionSlashableIndices(t *testing.T) {
root1 := [32]byte{'d', 'o', 'u', 'b', 'l', 'e', '1'} root1 := [32]byte{'d', 'o', 'u', 'b', 'l', 'e', '1'}
att1 := &ethpb.IndexedAttestation{ att1 := &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0}, Source: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 0, Root: root1[:]}, Target: &ethpb.Checkpoint{Epoch: 0, Root: root1[:]},
BeaconBlockRoot: make([]byte, 32),
}, },
AttestingIndices: setA, AttestingIndices: setA,
Signature: make([]byte, 96),
} }
domain, err := helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, beaconState.GenesisValidatorRoot()) domain, err := helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, beaconState.GenesisValidatorRoot())
require.NoError(t, err) require.NoError(t, err)
@@ -59,10 +61,12 @@ func TestProcessAttesterSlashings_RegressionSlashableIndices(t *testing.T) {
root2 := [32]byte{'d', 'o', 'u', 'b', 'l', 'e', '2'} root2 := [32]byte{'d', 'o', 'u', 'b', 'l', 'e', '2'}
att2 := &ethpb.IndexedAttestation{ att2 := &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0}, Source: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 0, Root: root2[:]}, Target: &ethpb.Checkpoint{Epoch: 0, Root: root2[:]},
BeaconBlockRoot: make([]byte, 32),
}, },
AttestingIndices: setB, AttestingIndices: setB,
Signature: make([]byte, 96),
} }
signingRoot, err = helpers.ComputeSigningRoot(att2.Data, domain) signingRoot, err = helpers.ComputeSigningRoot(att2.Data, domain)
assert.NoError(t, err, "Could not get signing root of beacon block header") assert.NoError(t, err, "Could not get signing root of beacon block header")

View File

@@ -197,7 +197,7 @@ func verifyDeposit(beaconState *stateTrie.BeaconState, deposit *ethpb.Deposit) e
} }
receiptRoot := eth1Data.DepositRoot receiptRoot := eth1Data.DepositRoot
leaf, err := ssz.HashTreeRoot(deposit.Data) leaf, err := deposit.Data.HashTreeRoot()
if err != nil { if err != nil {
return errors.Wrap(err, "could not tree hash deposit data") return errors.Wrap(err, "could not tree hash deposit data")
} }
@@ -255,7 +255,7 @@ func verifyDepositDataWithDomain(ctx context.Context, deps []*ethpb.Deposit, dom
ObjectRoot: root[:], ObjectRoot: root[:],
Domain: domain, Domain: domain,
} }
ctrRoot, err := ssz.HashTreeRoot(signingData) ctrRoot, err := signingData.HashTreeRoot()
if err != nil { if err != nil {
return errors.Wrap(err, "could not get container root") return errors.Wrap(err, "could not get container root")
} }

View File

@@ -5,7 +5,6 @@ import (
"testing" "testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" 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/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
@@ -58,11 +57,12 @@ func TestProcessDeposits_SameValidatorMultipleDepositsSameBlock(t *testing.T) {
func TestProcessDeposits_MerkleBranchFailsVerification(t *testing.T) { func TestProcessDeposits_MerkleBranchFailsVerification(t *testing.T) {
deposit := &ethpb.Deposit{ deposit := &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: []byte{1, 2, 3}, PublicKey: bytesutil.PadTo([]byte{1, 2, 3}, 48),
Signature: make([]byte, 96), WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
} }
leaf, err := ssz.HashTreeRoot(deposit.Data) leaf, err := deposit.Data.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
// We then create a merkle branch for the test. // We then create a merkle branch for the test.
@@ -132,15 +132,17 @@ func TestProcessDeposits_RepeatedDeposit_IncreasesValidatorBalance(t *testing.T)
sk := bls.RandKey() sk := bls.RandKey()
deposit := &ethpb.Deposit{ deposit := &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
PublicKey: sk.PublicKey().Marshal(), PublicKey: sk.PublicKey().Marshal(),
Amount: 1000, Amount: 1000,
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}, },
} }
sr, err := helpers.ComputeSigningRoot(deposit.Data, bytesutil.ToBytes(3, 8)) sr, err := helpers.ComputeSigningRoot(deposit.Data, bytesutil.ToBytes(3, 32))
require.NoError(t, err) require.NoError(t, err)
sig := sk.Sign(sr[:]) sig := sk.Sign(sr[:])
deposit.Data.Signature = sig.Marshal() deposit.Data.Signature = sig.Marshal()
leaf, err := ssz.HashTreeRoot(deposit.Data) leaf, err := deposit.Data.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
// We then create a merkle branch for the test. // We then create a merkle branch for the test.

View File

@@ -9,6 +9,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state" beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" 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/params"
"github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require" "github.com/prysmaticlabs/prysm/shared/testutil/require"
@@ -19,7 +20,7 @@ func FakeDeposits(n uint64) []*ethpb.Eth1Data {
for i := uint64(0); i < n; i++ { for i := uint64(0); i < n; i++ {
deposits[i] = &ethpb.Eth1Data{ deposits[i] = &ethpb.Eth1Data{
DepositCount: 1, DepositCount: 1,
DepositRoot: []byte("root"), DepositRoot: bytesutil.PadTo([]byte("root"), 32),
} }
} }
return deposits return deposits
@@ -36,7 +37,7 @@ func TestEth1DataHasEnoughSupport(t *testing.T) {
stateVotes: FakeDeposits(4 * params.BeaconConfig().SlotsPerEpoch), stateVotes: FakeDeposits(4 * params.BeaconConfig().SlotsPerEpoch),
data: &ethpb.Eth1Data{ data: &ethpb.Eth1Data{
DepositCount: 1, DepositCount: 1,
DepositRoot: []byte("root"), DepositRoot: bytesutil.PadTo([]byte("root"), 32),
}, },
hasSupport: true, hasSupport: true,
votingPeriodLength: 7, votingPeriodLength: 7,
@@ -44,7 +45,7 @@ func TestEth1DataHasEnoughSupport(t *testing.T) {
stateVotes: FakeDeposits(4 * params.BeaconConfig().SlotsPerEpoch), stateVotes: FakeDeposits(4 * params.BeaconConfig().SlotsPerEpoch),
data: &ethpb.Eth1Data{ data: &ethpb.Eth1Data{
DepositCount: 1, DepositCount: 1,
DepositRoot: []byte("root"), DepositRoot: bytesutil.PadTo([]byte("root"), 32),
}, },
hasSupport: false, hasSupport: false,
votingPeriodLength: 8, votingPeriodLength: 8,
@@ -52,7 +53,7 @@ func TestEth1DataHasEnoughSupport(t *testing.T) {
stateVotes: FakeDeposits(4 * params.BeaconConfig().SlotsPerEpoch), stateVotes: FakeDeposits(4 * params.BeaconConfig().SlotsPerEpoch),
data: &ethpb.Eth1Data{ data: &ethpb.Eth1Data{
DepositCount: 1, DepositCount: 1,
DepositRoot: []byte("root"), DepositRoot: bytesutil.PadTo([]byte("root"), 32),
}, },
hasSupport: false, hasSupport: false,
votingPeriodLength: 10, votingPeriodLength: 10,

View File

@@ -4,19 +4,27 @@ package blocks
import ( import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
) )
// NewGenesisBlock returns the canonical, genesis block for the beacon chain protocol. // NewGenesisBlock returns the canonical, genesis block for the beacon chain protocol.
func NewGenesisBlock(stateRoot []byte) *ethpb.SignedBeaconBlock { func NewGenesisBlock(stateRoot []byte) *ethpb.SignedBeaconBlock {
zeroHash := params.BeaconConfig().ZeroHash[:] zeroHash := params.BeaconConfig().ZeroHash[:]
genBlock := &ethpb.BeaconBlock{ block := &ethpb.SignedBeaconBlock{
ParentRoot: zeroHash, Block: &ethpb.BeaconBlock{
StateRoot: stateRoot, ParentRoot: zeroHash,
Body: &ethpb.BeaconBlockBody{}, StateRoot: bytesutil.PadTo(stateRoot, 32),
} Body: &ethpb.BeaconBlockBody{
return &ethpb.SignedBeaconBlock{ RandaoReveal: make([]byte, 96),
Block: genBlock, Eth1Data: &ethpb.Eth1Data{
DepositRoot: make([]byte, 32),
BlockHash: make([]byte, 32),
},
Graffiti: make([]byte, 32),
},
},
Signature: params.BeaconConfig().EmptySignature[:], Signature: params.BeaconConfig().EmptySignature[:],
} }
return block
} }

View File

@@ -4,11 +4,12 @@ import (
"testing" "testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/assert"
) )
func TestGenesisBlock_InitializedCorrectly(t *testing.T) { func TestGenesisBlock_InitializedCorrectly(t *testing.T) {
stateHash := []byte{0} stateHash := bytesutil.PadTo([]byte{0}, 32)
b1 := blocks.NewGenesisBlock(stateHash) b1 := blocks.NewGenesisBlock(stateHash)
assert.NotNil(t, b1.Block.ParentRoot, "Genesis block missing ParentHash field") assert.NotNil(t, b1.Block.ParentRoot, "Genesis block missing ParentHash field")

View File

@@ -8,7 +8,6 @@ import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
) )
@@ -99,7 +98,7 @@ func ProcessBlockHeaderNoVerify(
if parentHeader.Slot >= block.Slot { if parentHeader.Slot >= block.Slot {
return nil, fmt.Errorf("block.Slot %d must be greater than state.LatestBlockHeader.Slot %d", block.Slot, parentHeader.Slot) return nil, fmt.Errorf("block.Slot %d must be greater than state.LatestBlockHeader.Slot %d", block.Slot, parentHeader.Slot)
} }
parentRoot, err := stateutil.BlockHeaderRoot(parentHeader) parentRoot, err := parentHeader.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -118,7 +117,7 @@ func ProcessBlockHeaderNoVerify(
return nil, fmt.Errorf("proposer at index %d was previously slashed", idx) return nil, fmt.Errorf("proposer at index %d was previously slashed", idx)
} }
bodyRoot, err := stateutil.BlockBodyRoot(block.Body) bodyRoot, err := block.Body.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -6,18 +6,16 @@ import (
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz" "github.com/sirupsen/logrus"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "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/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require" "github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/sirupsen/logrus"
) )
func init() { func init() {
@@ -28,40 +26,35 @@ func TestProcessBlockHeader_ImproperBlockSlot(t *testing.T) {
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount) validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
for i := 0; i < len(validators); i++ { for i := 0; i < len(validators); i++ {
validators[i] = &ethpb.Validator{ validators[i] = &ethpb.Validator{
ExitEpoch: params.BeaconConfig().FarFutureEpoch, PublicKey: make([]byte, 32),
Slashed: true, WithdrawalCredentials: make([]byte, 32),
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
Slashed: true,
} }
} }
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{ state := testutil.NewBeaconState()
Validators: validators, require.NoError(t, state.SetSlot(10))
Slot: 10, require.NoError(t, state.SetValidators(validators))
LatestBlockHeader: &ethpb.BeaconBlockHeader{Slot: 10}, // Must be less than block.Slot require.NoError(t, state.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{
Fork: &pb.Fork{ Slot: 10, // Must be less than block.Slot
PreviousVersion: []byte{0, 0, 0, 0}, ParentRoot: make([]byte, 32),
CurrentVersion: []byte{0, 0, 0, 0}, StateRoot: make([]byte, 32),
}, BodyRoot: make([]byte, 32),
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }))
})
require.NoError(t, err)
latestBlockSignedRoot, err := stateutil.BlockHeaderRoot(state.LatestBlockHeader()) latestBlockSignedRoot, err := state.LatestBlockHeader().HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
currentEpoch := helpers.CurrentEpoch(state) currentEpoch := helpers.CurrentEpoch(state)
priv := bls.RandKey() priv := bls.RandKey()
pID, err := helpers.BeaconProposerIndex(state) pID, err := helpers.BeaconProposerIndex(state)
require.NoError(t, err) require.NoError(t, err)
block := &ethpb.SignedBeaconBlock{ block := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ block.Block.ProposerIndex = pID
ProposerIndex: pID, block.Block.Slot = 10
Slot: 10, block.Block.Body.RandaoReveal = bytesutil.PadTo([]byte{'A', 'B', 'C'}, 96)
Body: &ethpb.BeaconBlockBody{ block.Block.ParentRoot = latestBlockSignedRoot[:]
RandaoReveal: []byte{'A', 'B', 'C'},
},
ParentRoot: latestBlockSignedRoot[:],
},
}
block.Signature, err = helpers.ComputeDomainAndSign(state, currentEpoch, block.Block, params.BeaconConfig().DomainBeaconProposer, priv) block.Signature, err = helpers.ComputeDomainAndSign(state, currentEpoch, block.Block, params.BeaconConfig().DomainBeaconProposer, priv)
require.NoError(t, err) require.NoError(t, err)
@@ -79,25 +72,25 @@ func TestProcessBlockHeader_ImproperBlockSlot(t *testing.T) {
func TestProcessBlockHeader_WrongProposerSig(t *testing.T) { func TestProcessBlockHeader_WrongProposerSig(t *testing.T) {
testutil.ResetCache() testutil.ResetCache()
beaconState, privKeys := testutil.DeterministicGenesisState(t, 100) beaconState, privKeys := testutil.DeterministicGenesisState(t, 100)
require.NoError(t, beaconState.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{Slot: 9})) require.NoError(t, beaconState.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{
Slot: 9,
ParentRoot: make([]byte, 32),
StateRoot: make([]byte, 32),
BodyRoot: make([]byte, 32),
}))
require.NoError(t, beaconState.SetSlot(10)) require.NoError(t, beaconState.SetSlot(10))
lbhdr, err := stateutil.BlockHeaderRoot(beaconState.LatestBlockHeader()) lbhdr, err := beaconState.LatestBlockHeader().HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
proposerIdx, err := helpers.BeaconProposerIndex(beaconState) proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
require.NoError(t, err) require.NoError(t, err)
block := &ethpb.SignedBeaconBlock{ block := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ block.Block.ProposerIndex = proposerIdx
ProposerIndex: proposerIdx, block.Block.Slot = 10
Slot: 10, block.Block.Body.RandaoReveal = bytesutil.PadTo([]byte{'A', 'B', 'C'}, 96)
Body: &ethpb.BeaconBlockBody{ block.Block.ParentRoot = lbhdr[:]
RandaoReveal: []byte{'A', 'B', 'C'},
},
ParentRoot: lbhdr[:],
},
}
block.Signature, err = helpers.ComputeDomainAndSign(beaconState, 0, block.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx+1]) block.Signature, err = helpers.ComputeDomainAndSign(beaconState, 0, block.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx+1])
require.NoError(t, err) require.NoError(t, err)
@@ -110,24 +103,25 @@ func TestProcessBlockHeader_DifferentSlots(t *testing.T) {
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount) validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
for i := 0; i < len(validators); i++ { for i := 0; i < len(validators); i++ {
validators[i] = &ethpb.Validator{ validators[i] = &ethpb.Validator{
ExitEpoch: params.BeaconConfig().FarFutureEpoch, PublicKey: make([]byte, 32),
Slashed: true, WithdrawalCredentials: make([]byte, 32),
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
Slashed: true,
} }
} }
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{ state := testutil.NewBeaconState()
Validators: validators, require.NoError(t, state.SetValidators(validators))
Slot: 10, require.NoError(t, state.SetSlot(10))
LatestBlockHeader: &ethpb.BeaconBlockHeader{Slot: 9}, require.NoError(t, state.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{
Fork: &pb.Fork{ Slot: 9,
PreviousVersion: []byte{0, 0, 0, 0}, ProposerIndex: 0,
CurrentVersion: []byte{0, 0, 0, 0}, ParentRoot: make([]byte, 32),
}, StateRoot: make([]byte, 32),
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), BodyRoot: make([]byte, 32),
}) }))
require.NoError(t, err)
lbhsr, err := ssz.HashTreeRoot(state.LatestBlockHeader()) lbhsr, err := state.LatestBlockHeader().HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
currentEpoch := helpers.CurrentEpoch(state) currentEpoch := helpers.CurrentEpoch(state)
@@ -155,23 +149,19 @@ func TestProcessBlockHeader_PreviousBlockRootNotSignedRoot(t *testing.T) {
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount) validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
for i := 0; i < len(validators); i++ { for i := 0; i < len(validators); i++ {
validators[i] = &ethpb.Validator{ validators[i] = &ethpb.Validator{
ExitEpoch: params.BeaconConfig().FarFutureEpoch, PublicKey: make([]byte, 48),
Slashed: true, WithdrawalCredentials: make([]byte, 32),
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
Slashed: true,
} }
} }
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{ state := testutil.NewBeaconState()
Validators: validators, require.NoError(t, state.SetValidators(validators))
Slot: 10, require.NoError(t, state.SetSlot(10))
LatestBlockHeader: &ethpb.BeaconBlockHeader{Slot: 9}, bh := state.LatestBlockHeader()
Fork: &pb.Fork{ bh.Slot = 9
PreviousVersion: []byte{0, 0, 0, 0}, require.NoError(t, state.SetLatestBlockHeader(bh))
CurrentVersion: []byte{0, 0, 0, 0},
},
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
})
require.NoError(t, err)
currentEpoch := helpers.CurrentEpoch(state) currentEpoch := helpers.CurrentEpoch(state)
priv := bls.RandKey() priv := bls.RandKey()
blockSig, err := helpers.ComputeDomainAndSign(state, currentEpoch, []byte("hello"), params.BeaconConfig().DomainBeaconProposer, priv) blockSig, err := helpers.ComputeDomainAndSign(state, currentEpoch, []byte("hello"), params.BeaconConfig().DomainBeaconProposer, priv)
@@ -179,17 +169,12 @@ func TestProcessBlockHeader_PreviousBlockRootNotSignedRoot(t *testing.T) {
validators[5896].PublicKey = priv.PublicKey().Marshal() validators[5896].PublicKey = priv.PublicKey().Marshal()
pID, err := helpers.BeaconProposerIndex(state) pID, err := helpers.BeaconProposerIndex(state)
require.NoError(t, err) require.NoError(t, err)
block := &ethpb.SignedBeaconBlock{ block := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ block.Block.Slot = 10
ProposerIndex: pID, block.Block.ProposerIndex = pID
Slot: 10, block.Block.Body.RandaoReveal = bytesutil.PadTo([]byte{'A', 'B', 'C'}, 96)
Body: &ethpb.BeaconBlockBody{ block.Block.ParentRoot = bytesutil.PadTo([]byte{'A'}, 32)
RandaoReveal: []byte{'A', 'B', 'C'}, block.Signature = blockSig
},
ParentRoot: []byte{'A'},
},
Signature: blockSig,
}
_, err = blocks.ProcessBlockHeader(state, block) _, err = blocks.ProcessBlockHeader(state, block)
want := "does not match" want := "does not match"
@@ -200,24 +185,20 @@ func TestProcessBlockHeader_SlashedProposer(t *testing.T) {
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount) validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
for i := 0; i < len(validators); i++ { for i := 0; i < len(validators); i++ {
validators[i] = &ethpb.Validator{ validators[i] = &ethpb.Validator{
ExitEpoch: params.BeaconConfig().FarFutureEpoch, PublicKey: make([]byte, 48),
Slashed: true, WithdrawalCredentials: make([]byte, 32),
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
Slashed: true,
} }
} }
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{ state := testutil.NewBeaconState()
Validators: validators, require.NoError(t, state.SetValidators(validators))
Slot: 10, require.NoError(t, state.SetSlot(10))
LatestBlockHeader: &ethpb.BeaconBlockHeader{Slot: 9}, bh := state.LatestBlockHeader()
Fork: &pb.Fork{ bh.Slot = 9
PreviousVersion: []byte{0, 0, 0, 0}, require.NoError(t, state.SetLatestBlockHeader(bh))
CurrentVersion: []byte{0, 0, 0, 0}, parentRoot, err := state.LatestBlockHeader().HashTreeRoot()
},
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
})
require.NoError(t, err)
parentRoot, err := stateutil.BlockHeaderRoot(state.LatestBlockHeader())
require.NoError(t, err) require.NoError(t, err)
currentEpoch := helpers.CurrentEpoch(state) currentEpoch := helpers.CurrentEpoch(state)
priv := bls.RandKey() priv := bls.RandKey()
@@ -227,17 +208,12 @@ func TestProcessBlockHeader_SlashedProposer(t *testing.T) {
validators[12683].PublicKey = priv.PublicKey().Marshal() validators[12683].PublicKey = priv.PublicKey().Marshal()
pID, err := helpers.BeaconProposerIndex(state) pID, err := helpers.BeaconProposerIndex(state)
require.NoError(t, err) require.NoError(t, err)
block := &ethpb.SignedBeaconBlock{ block := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ block.Block.Slot = 10
ProposerIndex: pID, block.Block.ProposerIndex = pID
Slot: 10, block.Block.Body.RandaoReveal = bytesutil.PadTo([]byte{'A', 'B', 'C'}, 96)
Body: &ethpb.BeaconBlockBody{ block.Block.ParentRoot = parentRoot[:]
RandaoReveal: []byte{'A', 'B', 'C'}, block.Signature = blockSig
},
ParentRoot: parentRoot[:],
},
Signature: blockSig,
}
_, err = blocks.ProcessBlockHeader(state, block) _, err = blocks.ProcessBlockHeader(state, block)
want := "was previously slashed" want := "was previously slashed"
@@ -248,43 +224,39 @@ func TestProcessBlockHeader_OK(t *testing.T) {
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount) validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
for i := 0; i < len(validators); i++ { for i := 0; i < len(validators); i++ {
validators[i] = &ethpb.Validator{ validators[i] = &ethpb.Validator{
ExitEpoch: params.BeaconConfig().FarFutureEpoch, PublicKey: make([]byte, 32),
Slashed: true, WithdrawalCredentials: make([]byte, 32),
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
Slashed: true,
} }
} }
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{ state := testutil.NewBeaconState()
Validators: validators, require.NoError(t, state.SetValidators(validators))
Slot: 10, require.NoError(t, state.SetSlot(10))
LatestBlockHeader: &ethpb.BeaconBlockHeader{Slot: 9}, require.NoError(t, state.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{
Fork: &pb.Fork{ Slot: 9,
PreviousVersion: []byte{0, 0, 0, 0}, ProposerIndex: 0,
CurrentVersion: []byte{0, 0, 0, 0}, ParentRoot: make([]byte, 32),
}, StateRoot: make([]byte, 32),
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), BodyRoot: make([]byte, 32),
}) }))
require.NoError(t, err)
latestBlockSignedRoot, err := stateutil.BlockHeaderRoot(state.LatestBlockHeader()) latestBlockSignedRoot, err := state.LatestBlockHeader().HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
currentEpoch := helpers.CurrentEpoch(state) currentEpoch := helpers.CurrentEpoch(state)
priv := bls.RandKey() priv := bls.RandKey()
pID, err := helpers.BeaconProposerIndex(state) pID, err := helpers.BeaconProposerIndex(state)
require.NoError(t, err) require.NoError(t, err)
block := &ethpb.SignedBeaconBlock{ block := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ block.Block.ProposerIndex = pID
ProposerIndex: pID, block.Block.Slot = 10
Slot: 10, block.Block.Body.RandaoReveal = bytesutil.PadTo([]byte{'A', 'B', 'C'}, 96)
Body: &ethpb.BeaconBlockBody{ block.Block.ParentRoot = latestBlockSignedRoot[:]
RandaoReveal: []byte{'A', 'B', 'C'},
},
ParentRoot: latestBlockSignedRoot[:],
},
}
block.Signature, err = helpers.ComputeDomainAndSign(state, currentEpoch, block.Block, params.BeaconConfig().DomainBeaconProposer, priv) block.Signature, err = helpers.ComputeDomainAndSign(state, currentEpoch, block.Block, params.BeaconConfig().DomainBeaconProposer, priv)
require.NoError(t, err) require.NoError(t, err)
bodyRoot, err := stateutil.BlockBodyRoot(block.Block.Body) bodyRoot, err := block.Block.Body.HashTreeRoot()
require.NoError(t, err, "Failed to hash block bytes got") require.NoError(t, err, "Failed to hash block bytes got")
proposerIdx, err := helpers.BeaconProposerIndex(state) proposerIdx, err := helpers.BeaconProposerIndex(state)
@@ -312,40 +284,36 @@ func TestBlockSignatureSet_OK(t *testing.T) {
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount) validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
for i := 0; i < len(validators); i++ { for i := 0; i < len(validators); i++ {
validators[i] = &ethpb.Validator{ validators[i] = &ethpb.Validator{
ExitEpoch: params.BeaconConfig().FarFutureEpoch, PublicKey: make([]byte, 32),
Slashed: true, WithdrawalCredentials: make([]byte, 32),
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
Slashed: true,
} }
} }
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{ state := testutil.NewBeaconState()
Validators: validators, require.NoError(t, state.SetValidators(validators))
Slot: 10, require.NoError(t, state.SetSlot(10))
LatestBlockHeader: &ethpb.BeaconBlockHeader{Slot: 9}, require.NoError(t, state.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{
Fork: &pb.Fork{ Slot: 9,
PreviousVersion: []byte{0, 0, 0, 0}, ProposerIndex: 0,
CurrentVersion: []byte{0, 0, 0, 0}, ParentRoot: make([]byte, 32),
}, StateRoot: make([]byte, 32),
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), BodyRoot: make([]byte, 32),
}) }))
require.NoError(t, err)
latestBlockSignedRoot, err := stateutil.BlockHeaderRoot(state.LatestBlockHeader()) latestBlockSignedRoot, err := state.LatestBlockHeader().HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
currentEpoch := helpers.CurrentEpoch(state) currentEpoch := helpers.CurrentEpoch(state)
priv := bls.RandKey() priv := bls.RandKey()
pID, err := helpers.BeaconProposerIndex(state) pID, err := helpers.BeaconProposerIndex(state)
require.NoError(t, err) require.NoError(t, err)
block := &ethpb.SignedBeaconBlock{ block := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ block.Block.Slot = 10
ProposerIndex: pID, block.Block.ProposerIndex = pID
Slot: 10, block.Block.Body.RandaoReveal = bytesutil.PadTo([]byte{'A', 'B', 'C'}, 96)
Body: &ethpb.BeaconBlockBody{ block.Block.ParentRoot = latestBlockSignedRoot[:]
RandaoReveal: []byte{'A', 'B', 'C'},
},
ParentRoot: latestBlockSignedRoot[:],
},
}
block.Signature, err = helpers.ComputeDomainAndSign(state, currentEpoch, block.Block, params.BeaconConfig().DomainBeaconProposer, priv) block.Signature, err = helpers.ComputeDomainAndSign(state, currentEpoch, block.Block, params.BeaconConfig().DomainBeaconProposer, priv)
require.NoError(t, err) require.NoError(t, err)
proposerIdx, err := helpers.BeaconProposerIndex(state) proposerIdx, err := helpers.BeaconProposerIndex(state)

View File

@@ -98,14 +98,14 @@ func TestProcessProposerSlashings_ValidatorNotSlashable(t *testing.T) {
ProposerIndex: 0, ProposerIndex: 0,
Slot: 0, Slot: 0,
}, },
Signature: []byte("A"), Signature: bytesutil.PadTo([]byte("A"), 96),
}, },
Header_2: &ethpb.SignedBeaconBlockHeader{ Header_2: &ethpb.SignedBeaconBlockHeader{
Header: &ethpb.BeaconBlockHeader{ Header: &ethpb.BeaconBlockHeader{
ProposerIndex: 0, ProposerIndex: 0,
Slot: 0, Slot: 0,
}, },
Signature: []byte("B"), Signature: bytesutil.PadTo([]byte("B"), 96),
}, },
}, },
} }
@@ -138,7 +138,9 @@ func TestProcessProposerSlashings_AppliesCorrectStatus(t *testing.T) {
Header: &ethpb.BeaconBlockHeader{ Header: &ethpb.BeaconBlockHeader{
ProposerIndex: proposerIdx, ProposerIndex: proposerIdx,
Slot: 0, Slot: 0,
StateRoot: []byte("A"), ParentRoot: make([]byte, 32),
BodyRoot: make([]byte, 32),
StateRoot: bytesutil.PadTo([]byte("A"), 32),
}, },
} }
var err error var err error
@@ -149,7 +151,9 @@ func TestProcessProposerSlashings_AppliesCorrectStatus(t *testing.T) {
Header: &ethpb.BeaconBlockHeader{ Header: &ethpb.BeaconBlockHeader{
ProposerIndex: proposerIdx, ProposerIndex: proposerIdx,
Slot: 0, Slot: 0,
StateRoot: []byte("B"), ParentRoot: make([]byte, 32),
BodyRoot: make([]byte, 32),
StateRoot: bytesutil.PadTo([]byte("B"), 32),
}, },
} }
header2.Signature, err = helpers.ComputeDomainAndSign(beaconState, 0, header2.Header, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx]) header2.Signature, err = helpers.ComputeDomainAndSign(beaconState, 0, header2.Header, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
@@ -162,13 +166,10 @@ func TestProcessProposerSlashings_AppliesCorrectStatus(t *testing.T) {
}, },
} }
block := &ethpb.BeaconBlock{ block := testutil.NewBeaconBlock()
Body: &ethpb.BeaconBlockBody{ block.Block.Body.ProposerSlashings = slashings
ProposerSlashings: slashings,
},
}
newState, err := blocks.ProcessProposerSlashings(context.Background(), beaconState, block.Body) newState, err := blocks.ProcessProposerSlashings(context.Background(), beaconState, block.Block.Body)
require.NoError(t, err) require.NoError(t, err)
newStateVals := newState.Validators() newStateVals := newState.Validators()

View File

@@ -6,7 +6,6 @@ import (
"testing" "testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" 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/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
@@ -26,7 +25,7 @@ func TestProcessRandao_IncorrectProposerFailsVerification(t *testing.T) {
binary.LittleEndian.PutUint64(buf, epoch) binary.LittleEndian.PutUint64(buf, epoch)
domain, err := helpers.Domain(beaconState.Fork(), epoch, params.BeaconConfig().DomainRandao, beaconState.GenesisValidatorRoot()) domain, err := helpers.Domain(beaconState.Fork(), epoch, params.BeaconConfig().DomainRandao, beaconState.GenesisValidatorRoot())
require.NoError(t, err) require.NoError(t, err)
root, err := ssz.HashTreeRoot(&pb.SigningData{ObjectRoot: buf, Domain: domain}) root, err := (&pb.SigningData{ObjectRoot: buf, Domain: domain}).HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
// We make the previous validator's index sign the message instead of the proposer. // We make the previous validator's index sign the message instead of the proposer.
epochSignature := privKeys[proposerIdx-1].Sign(root[:]) epochSignature := privKeys[proposerIdx-1].Sign(root[:])

View File

@@ -6,7 +6,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" 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/helpers"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
@@ -29,7 +28,7 @@ func retrieveSignatureSet(signedData []byte, pub []byte, signature []byte, domai
ObjectRoot: signedData, ObjectRoot: signedData,
Domain: domain, Domain: domain,
} }
root, err := ssz.HashTreeRoot(signingData) root, err := signingData.HashTreeRoot()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not hash container") return nil, errors.Wrap(err, "could not hash container")
} }

View File

@@ -16,7 +16,6 @@ go_library(
"//shared/params:go_default_library", "//shared/params:go_default_library",
"@com_github_pkg_errors//:go_default_library", "@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
], ],
) )
@@ -33,6 +32,7 @@ go_test(
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
"//shared/params:go_default_library", "//shared/params:go_default_library",
"//shared/testutil:go_default_library",
"//shared/testutil/assert:go_default_library", "//shared/testutil/assert:go_default_library",
"//shared/testutil/require:go_default_library", "//shared/testutil/require:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library",

View File

@@ -10,7 +10,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" 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/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/validators" "github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
@@ -46,7 +45,7 @@ func (s sortableIndices) Less(i, j int) bool {
// def get_attesting_balance(state: BeaconState, attestations: List[PendingAttestation]) -> Gwei: // def get_attesting_balance(state: BeaconState, attestations: List[PendingAttestation]) -> Gwei:
// return get_total_balance(state, get_unslashed_attesting_indices(state, attestations)) // return get_total_balance(state, get_unslashed_attesting_indices(state, attestations))
func AttestingBalance(state *stateTrie.BeaconState, atts []*pb.PendingAttestation) (uint64, error) { func AttestingBalance(state *stateTrie.BeaconState, atts []*pb.PendingAttestation) (uint64, error) {
indices, err := unslashedAttestingIndices(state, atts) indices, err := UnslashedAttestingIndices(state, atts)
if err != nil { if err != nil {
return 0, errors.Wrap(err, "could not get attesting indices") return 0, errors.Wrap(err, "could not get attesting indices")
} }
@@ -311,7 +310,7 @@ func ProcessFinalUpdates(state *stateTrie.BeaconState) (*stateTrie.BeaconState,
BlockRoots: state.BlockRoots(), BlockRoots: state.BlockRoots(),
StateRoots: state.StateRoots(), StateRoots: state.StateRoots(),
} }
batchRoot, err := ssz.HashTreeRoot(historicalBatch) batchRoot, err := historicalBatch.HashTreeRoot()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not hash historical batch") return nil, errors.Wrap(err, "could not hash historical batch")
} }
@@ -330,7 +329,7 @@ func ProcessFinalUpdates(state *stateTrie.BeaconState) (*stateTrie.BeaconState,
return state, nil 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. // it sorts the indices and filters out the slashed ones.
// //
// Spec pseudocode definition: // Spec pseudocode definition:
@@ -340,7 +339,7 @@ func ProcessFinalUpdates(state *stateTrie.BeaconState) (*stateTrie.BeaconState,
// for a in attestations: // for a in attestations:
// output = output.union(get_attesting_indices(state, a.data, a.aggregation_bits)) // output = output.union(get_attesting_indices(state, a.data, a.aggregation_bits))
// return set(filter(lambda index: not state.validators[index].slashed, output)) // 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 var setIndices []uint64
seen := make(map[uint64]bool) seen := make(map[uint64]bool)

View File

@@ -1,4 +1,4 @@
package epoch package epoch_test
import ( import (
"testing" "testing"
@@ -6,10 +6,12 @@ import (
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-bitfield" "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/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/params" "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/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require" "github.com/prysmaticlabs/prysm/shared/testutil/require"
) )
@@ -19,8 +21,8 @@ func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) {
atts := make([]*pb.PendingAttestation, 2) atts := make([]*pb.PendingAttestation, 2)
for i := 0; i < len(atts); i++ { for i := 0; i < len(atts); i++ {
atts[i] = &pb.PendingAttestation{ atts[i] = &pb.PendingAttestation{
Data: &ethpb.AttestationData{Source: &ethpb.Checkpoint{}, Data: &ethpb.AttestationData{Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF}, AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF},
} }
@@ -41,7 +43,7 @@ func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) {
state, err := state.InitializeFromProto(base) state, err := state.InitializeFromProto(base)
require.NoError(t, err) require.NoError(t, err)
indices, err := unslashedAttestingIndices(state, atts) indices, err := epoch.UnslashedAttestingIndices(state, atts)
require.NoError(t, err) require.NoError(t, err)
for i := 0; i < len(indices)-1; i++ { for i := 0; i < len(indices)-1; i++ {
if indices[i] >= indices[i+1] { if indices[i] >= indices[i+1] {
@@ -54,7 +56,7 @@ func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) {
validators = state.Validators() validators = state.Validators()
validators[slashedValidator].Slashed = true validators[slashedValidator].Slashed = true
require.NoError(t, state.SetValidators(validators)) require.NoError(t, state.SetValidators(validators))
indices, err = unslashedAttestingIndices(state, atts) indices, err = epoch.UnslashedAttestingIndices(state, atts)
require.NoError(t, err) require.NoError(t, err)
for i := 0; i < len(indices); i++ { for i := 0; i < len(indices); i++ {
assert.NotEqual(t, slashedValidator, indices[i], "Slashed validator %d is not filtered", slashedValidator) assert.NotEqual(t, slashedValidator, indices[i], "Slashed validator %d is not filtered", slashedValidator)
@@ -66,7 +68,7 @@ func TestUnslashedAttestingIndices_DuplicatedAttestations(t *testing.T) {
atts := make([]*pb.PendingAttestation, 5) atts := make([]*pb.PendingAttestation, 5)
for i := 0; i < len(atts); i++ { for i := 0; i < len(atts); i++ {
atts[i] = &pb.PendingAttestation{ atts[i] = &pb.PendingAttestation{
Data: &ethpb.AttestationData{Source: &ethpb.Checkpoint{}, Data: &ethpb.AttestationData{Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 0}}, Target: &ethpb.Checkpoint{Epoch: 0}},
AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF}, AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF},
} }
@@ -87,7 +89,7 @@ func TestUnslashedAttestingIndices_DuplicatedAttestations(t *testing.T) {
state, err := state.InitializeFromProto(base) state, err := state.InitializeFromProto(base)
require.NoError(t, err) require.NoError(t, err)
indices, err := unslashedAttestingIndices(state, atts) indices, err := epoch.UnslashedAttestingIndices(state, atts)
require.NoError(t, err) require.NoError(t, err)
for i := 0; i < len(indices)-1; i++ { for i := 0; i < len(indices)-1; i++ {
@@ -104,8 +106,8 @@ func TestAttestingBalance_CorrectBalance(t *testing.T) {
for i := 0; i < len(atts); i++ { for i := 0; i < len(atts); i++ {
atts[i] = &pb.PendingAttestation{ atts[i] = &pb.PendingAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{}, Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
Slot: uint64(i), Slot: uint64(i),
}, },
AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
@@ -133,7 +135,7 @@ func TestAttestingBalance_CorrectBalance(t *testing.T) {
state, err := state.InitializeFromProto(base) state, err := state.InitializeFromProto(base)
require.NoError(t, err) require.NoError(t, err)
balance, err := AttestingBalance(state, atts) balance, err := epoch.AttestingBalance(state, atts)
require.NoError(t, err) require.NoError(t, err)
wanted := 256 * params.BeaconConfig().MaxEffectiveBalance wanted := 256 * params.BeaconConfig().MaxEffectiveBalance
assert.Equal(t, wanted, balance) assert.Equal(t, wanted, balance)
@@ -158,9 +160,9 @@ func TestBaseReward_AccurateRewards(t *testing.T) {
} }
state, err := state.InitializeFromProto(base) state, err := state.InitializeFromProto(base)
require.NoError(t, err) require.NoError(t, err)
c, err := BaseReward(state, 0) c, err := epoch.BaseReward(state, 0)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, tt.c, c, "BaseReward(%d)", tt.a) assert.Equal(t, tt.c, c, "epoch.BaseReward(%d)", tt.a)
} }
} }
@@ -173,7 +175,7 @@ func TestProcessSlashings_NotSlashed(t *testing.T) {
} }
s, err := state.InitializeFromProto(base) s, err := state.InitializeFromProto(base)
require.NoError(t, err) require.NoError(t, err)
newState, err := ProcessSlashings(s) newState, err := epoch.ProcessSlashings(s)
require.NoError(t, err) require.NoError(t, err)
wanted := params.BeaconConfig().MaxEffectiveBalance wanted := params.BeaconConfig().MaxEffectiveBalance
assert.Equal(t, wanted, newState.Balances()[0], "Unexpected slashed balance") assert.Equal(t, wanted, newState.Balances()[0], "Unexpected slashed balance")
@@ -251,7 +253,7 @@ func TestProcessSlashings_SlashedLess(t *testing.T) {
original := proto.Clone(tt.state) original := proto.Clone(tt.state)
s, err := state.InitializeFromProto(tt.state) s, err := state.InitializeFromProto(tt.state)
require.NoError(t, err) require.NoError(t, err)
newState, err := ProcessSlashings(s) newState, err := epoch.ProcessSlashings(s)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, tt.want, newState.Balances()[0], "ProcessSlashings({%v}) = newState; newState.Balances[0] = %d", original, newState.Balances()[0]) assert.Equal(t, tt.want, newState.Balances()[0], "ProcessSlashings({%v}) = newState; newState.Balances[0] = %d", original, newState.Balances()[0])
}) })
@@ -259,7 +261,7 @@ func TestProcessSlashings_SlashedLess(t *testing.T) {
} }
func TestProcessFinalUpdates_CanProcess(t *testing.T) { func TestProcessFinalUpdates_CanProcess(t *testing.T) {
s := buildState(params.BeaconConfig().SlotsPerHistoricalRoot-1, params.BeaconConfig().SlotsPerEpoch) s := buildState(t, params.BeaconConfig().SlotsPerHistoricalRoot-1, params.BeaconConfig().SlotsPerEpoch)
ce := helpers.CurrentEpoch(s) ce := helpers.CurrentEpoch(s)
ne := ce + 1 ne := ce + 1
require.NoError(t, s.SetEth1DataVotes([]*ethpb.Eth1Data{})) require.NoError(t, s.SetEth1DataVotes([]*ethpb.Eth1Data{}))
@@ -274,7 +276,7 @@ func TestProcessFinalUpdates_CanProcess(t *testing.T) {
mixes := s.RandaoMixes() mixes := s.RandaoMixes()
mixes[ce] = []byte{'A'} mixes[ce] = []byte{'A'}
require.NoError(t, s.SetRandaoMixes(mixes)) require.NoError(t, s.SetRandaoMixes(mixes))
newS, err := ProcessFinalUpdates(s) newS, err := epoch.ProcessFinalUpdates(s)
require.NoError(t, err) require.NoError(t, err)
// Verify effective balance is correctly updated. // Verify effective balance is correctly updated.
@@ -305,11 +307,11 @@ func TestProcessRegistryUpdates_NoRotation(t *testing.T) {
params.BeaconConfig().MaxEffectiveBalance, params.BeaconConfig().MaxEffectiveBalance,
params.BeaconConfig().MaxEffectiveBalance, params.BeaconConfig().MaxEffectiveBalance,
}, },
FinalizedCheckpoint: &ethpb.Checkpoint{}, FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
} }
state, err := state.InitializeFromProto(base) state, err := state.InitializeFromProto(base)
require.NoError(t, err) require.NoError(t, err)
newState, err := ProcessRegistryUpdates(state) newState, err := epoch.ProcessRegistryUpdates(state)
require.NoError(t, err) require.NoError(t, err)
for i, validator := range newState.Validators() { for i, validator := range newState.Validators() {
assert.Equal(t, params.BeaconConfig().MaxSeedLookahead, validator.ExitEpoch, "Could not update registry %d", i) assert.Equal(t, params.BeaconConfig().MaxSeedLookahead, validator.ExitEpoch, "Could not update registry %d", i)
@@ -319,7 +321,7 @@ func TestProcessRegistryUpdates_NoRotation(t *testing.T) {
func TestProcessRegistryUpdates_EligibleToActivate(t *testing.T) { func TestProcessRegistryUpdates_EligibleToActivate(t *testing.T) {
base := &pb.BeaconState{ base := &pb.BeaconState{
Slot: 5 * params.BeaconConfig().SlotsPerEpoch, Slot: 5 * params.BeaconConfig().SlotsPerEpoch,
FinalizedCheckpoint: &ethpb.Checkpoint{Epoch: 6}, FinalizedCheckpoint: &ethpb.Checkpoint{Epoch: 6, Root: make([]byte, 32)},
} }
limit, err := helpers.ValidatorChurnLimit(0) limit, err := helpers.ValidatorChurnLimit(0)
require.NoError(t, err) require.NoError(t, err)
@@ -332,7 +334,7 @@ func TestProcessRegistryUpdates_EligibleToActivate(t *testing.T) {
} }
state, err := state.InitializeFromProto(base) state, err := state.InitializeFromProto(base)
currentEpoch := helpers.CurrentEpoch(state) currentEpoch := helpers.CurrentEpoch(state)
newState, err := ProcessRegistryUpdates(state) newState, err := epoch.ProcessRegistryUpdates(state)
require.NoError(t, err) require.NoError(t, err)
for i, validator := range newState.Validators() { for i, validator := range newState.Validators() {
assert.Equal(t, currentEpoch+1, validator.ActivationEligibilityEpoch, "Could not update registry %d, unexpected activation eligibility epoch", i) assert.Equal(t, currentEpoch+1, validator.ActivationEligibilityEpoch, "Could not update registry %d, unexpected activation eligibility epoch", i)
@@ -356,11 +358,11 @@ func TestProcessRegistryUpdates_ActivationCompletes(t *testing.T) {
{ExitEpoch: params.BeaconConfig().MaxSeedLookahead, {ExitEpoch: params.BeaconConfig().MaxSeedLookahead,
ActivationEpoch: 5 + params.BeaconConfig().MaxSeedLookahead + 1}, ActivationEpoch: 5 + params.BeaconConfig().MaxSeedLookahead + 1},
}, },
FinalizedCheckpoint: &ethpb.Checkpoint{}, FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
} }
state, err := state.InitializeFromProto(base) state, err := state.InitializeFromProto(base)
require.NoError(t, err) require.NoError(t, err)
newState, err := ProcessRegistryUpdates(state) newState, err := epoch.ProcessRegistryUpdates(state)
require.NoError(t, err) require.NoError(t, err)
for i, validator := range newState.Validators() { for i, validator := range newState.Validators() {
assert.Equal(t, params.BeaconConfig().MaxSeedLookahead, validator.ExitEpoch, "Could not update registry %d, unexpected exit slot", i) assert.Equal(t, params.BeaconConfig().MaxSeedLookahead, validator.ExitEpoch, "Could not update registry %d, unexpected exit slot", i)
@@ -380,11 +382,11 @@ func TestProcessRegistryUpdates_ValidatorsEjected(t *testing.T) {
EffectiveBalance: params.BeaconConfig().EjectionBalance - 1, EffectiveBalance: params.BeaconConfig().EjectionBalance - 1,
}, },
}, },
FinalizedCheckpoint: &ethpb.Checkpoint{}, FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
} }
state, err := state.InitializeFromProto(base) state, err := state.InitializeFromProto(base)
require.NoError(t, err) require.NoError(t, err)
newState, err := ProcessRegistryUpdates(state) newState, err := epoch.ProcessRegistryUpdates(state)
require.NoError(t, err) require.NoError(t, err)
for i, validator := range newState.Validators() { for i, validator := range newState.Validators() {
assert.Equal(t, params.BeaconConfig().MaxSeedLookahead+1, validator.ExitEpoch, "Could not update registry %d, unexpected exit slot", i) assert.Equal(t, params.BeaconConfig().MaxSeedLookahead+1, validator.ExitEpoch, "Could not update registry %d, unexpected exit slot", i)
@@ -392,11 +394,11 @@ func TestProcessRegistryUpdates_ValidatorsEjected(t *testing.T) {
} }
func TestProcessRegistryUpdates_CanExits(t *testing.T) { func TestProcessRegistryUpdates_CanExits(t *testing.T) {
epoch := uint64(5) e := uint64(5)
exitEpoch := helpers.ActivationExitEpoch(epoch) exitEpoch := helpers.ActivationExitEpoch(e)
minWithdrawalDelay := params.BeaconConfig().MinValidatorWithdrawabilityDelay minWithdrawalDelay := params.BeaconConfig().MinValidatorWithdrawabilityDelay
base := &pb.BeaconState{ base := &pb.BeaconState{
Slot: epoch * params.BeaconConfig().SlotsPerEpoch, Slot: e * params.BeaconConfig().SlotsPerEpoch,
Validators: []*ethpb.Validator{ Validators: []*ethpb.Validator{
{ {
ExitEpoch: exitEpoch, ExitEpoch: exitEpoch,
@@ -405,18 +407,18 @@ func TestProcessRegistryUpdates_CanExits(t *testing.T) {
ExitEpoch: exitEpoch, ExitEpoch: exitEpoch,
WithdrawableEpoch: exitEpoch + minWithdrawalDelay}, WithdrawableEpoch: exitEpoch + minWithdrawalDelay},
}, },
FinalizedCheckpoint: &ethpb.Checkpoint{}, FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
} }
state, err := state.InitializeFromProto(base) state, err := state.InitializeFromProto(base)
require.NoError(t, err) require.NoError(t, err)
newState, err := ProcessRegistryUpdates(state) newState, err := epoch.ProcessRegistryUpdates(state)
require.NoError(t, err) require.NoError(t, err)
for i, validator := range newState.Validators() { for i, validator := range newState.Validators() {
assert.Equal(t, exitEpoch, validator.ExitEpoch, "Could not update registry %d, unexpected exit slot", i) assert.Equal(t, exitEpoch, validator.ExitEpoch, "Could not update registry %d, unexpected exit slot", i)
} }
} }
func buildState(slot uint64, validatorCount uint64) *state.BeaconState { func buildState(t testing.TB, slot uint64, validatorCount uint64) *state.BeaconState {
validators := make([]*ethpb.Validator, validatorCount) validators := make([]*ethpb.Validator, validatorCount)
for i := 0; i < len(validators); i++ { for i := 0; i < len(validators); i++ {
validators[i] = &ethpb.Validator{ validators[i] = &ethpb.Validator{
@@ -442,19 +444,15 @@ func buildState(slot uint64, validatorCount uint64) *state.BeaconState {
for i := 0; i < len(latestRandaoMixes); i++ { for i := 0; i < len(latestRandaoMixes); i++ {
latestRandaoMixes[i] = params.BeaconConfig().ZeroHash[:] latestRandaoMixes[i] = params.BeaconConfig().ZeroHash[:]
} }
s, err := state.InitializeFromProto(&pb.BeaconState{ s := testutil.NewBeaconState()
Slot: slot, if err := s.SetSlot(slot); err != nil {
Balances: validatorBalances, t.Error(err)
Validators: validators, }
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), if err := s.SetBalances(validatorBalances); err != nil {
Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector), t.Error(err)
BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerEpoch*10), }
FinalizedCheckpoint: &ethpb.Checkpoint{}, if err := s.SetValidators(validators); err != nil {
PreviousJustifiedCheckpoint: &ethpb.Checkpoint{}, t.Error(err)
CurrentJustifiedCheckpoint: &ethpb.Checkpoint{},
})
if err != nil {
panic(err)
} }
return s return s
} }

View File

@@ -30,7 +30,7 @@ func TestProcessJustificationAndFinalizationPreCompute_ConsecutiveEpochs(t *test
Epoch: 0, Epoch: 0,
Root: params.BeaconConfig().ZeroHash[:], Root: params.BeaconConfig().ZeroHash[:],
}, },
FinalizedCheckpoint: &ethpb.Checkpoint{}, FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
JustificationBits: bitfield.Bitvector4{0x0F}, // 0b1111 JustificationBits: bitfield.Bitvector4{0x0F}, // 0b1111
Validators: []*ethpb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}}, Validators: []*ethpb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}},
Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000 Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000
@@ -67,7 +67,7 @@ func TestProcessJustificationAndFinalizationPreCompute_JustifyCurrentEpoch(t *te
Epoch: 0, Epoch: 0,
Root: params.BeaconConfig().ZeroHash[:], Root: params.BeaconConfig().ZeroHash[:],
}, },
FinalizedCheckpoint: &ethpb.Checkpoint{}, FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
JustificationBits: bitfield.Bitvector4{0x03}, // 0b0011 JustificationBits: bitfield.Bitvector4{0x03}, // 0b0011
Validators: []*ethpb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}}, Validators: []*ethpb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}},
Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000 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 JustificationBits: bitfield.Bitvector4{0x03}, // 0b0011
Validators: []*ethpb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}}, Validators: []*ethpb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}},
Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000 Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000
BlockRoots: blockRoots, FinalizedCheckpoint: &ethpb.Checkpoint{}, BlockRoots: blockRoots, FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
} }
state, err := beaconstate.InitializeFromProto(base) state, err := beaconstate.InitializeFromProto(base)
require.NoError(t, err) require.NoError(t, err)

View File

@@ -24,8 +24,8 @@ func TestProcessRewardsAndPenaltiesPrecompute(t *testing.T) {
for i := 0; i < len(atts); i++ { for i := 0; i < len(atts); i++ {
atts[i] = &pb.PendingAttestation{ atts[i] = &pb.PendingAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{}, Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0xC0, 0xC0, 0xC0, 0xC0, 0x01}, AggregationBits: bitfield.Bitlist{0xC0, 0xC0, 0xC0, 0xC0, 0x01},
InclusionDelay: 1, InclusionDelay: 1,
@@ -214,8 +214,8 @@ func TestProcessRewardsAndPenaltiesPrecompute_SlashedInactivePenalty(t *testing.
for i := 0; i < len(atts); i++ { for i := 0; i < len(atts); i++ {
atts[i] = &pb.PendingAttestation{ atts[i] = &pb.PendingAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{}, Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0xC0, 0xC0, 0xC0, 0xC0, 0x01}, AggregationBits: bitfield.Bitlist{0xC0, 0xC0, 0xC0, 0xC0, 0x01},
InclusionDelay: 1, InclusionDelay: 1,
@@ -287,9 +287,9 @@ func buildState(slot uint64, validatorCount uint64) *pb.BeaconState {
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector), Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector),
BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerEpoch*10), BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerEpoch*10),
FinalizedCheckpoint: &ethpb.Checkpoint{}, FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
PreviousJustifiedCheckpoint: &ethpb.Checkpoint{}, PreviousJustifiedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
CurrentJustifiedCheckpoint: &ethpb.Checkpoint{}, CurrentJustifiedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
} }
} }

View File

@@ -45,7 +45,7 @@ type SyncedData struct {
type InitializedData struct { type InitializedData struct {
// StartTime is the time at which the chain started. // StartTime is the time at which the chain started.
StartTime time.Time StartTime time.Time
// GenesisValidatorsRoot represents ssz.HashTreeRoot(state.validators). // GenesisValidatorsRoot represents state.validators.HashTreeRoot().
GenesisValidatorsRoot []byte GenesisValidatorsRoot []byte
} }

View File

@@ -32,7 +32,6 @@ go_library(
deps = [ deps = [
"//beacon-chain/cache:go_default_library", "//beacon-chain/cache:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
"//shared/bls:go_default_library", "//shared/bls:go_default_library",
"//shared/bytesutil:go_default_library", "//shared/bytesutil:go_default_library",
@@ -41,6 +40,7 @@ go_library(
"//shared/params:go_default_library", "//shared/params:go_default_library",
"//shared/roughtime:go_default_library", "//shared/roughtime:go_default_library",
"//shared/sliceutil:go_default_library", "//shared/sliceutil:go_default_library",
"@com_github_ferranbt_fastssz//:go_default_library",
"@com_github_pkg_errors//:go_default_library", "@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library",
@@ -67,7 +67,6 @@ go_test(
deps = [ deps = [
"//beacon-chain/cache:go_default_library", "//beacon-chain/cache:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
"//shared/bls:go_default_library", "//shared/bls:go_default_library",
"//shared/bytesutil:go_default_library", "//shared/bytesutil:go_default_library",

View File

@@ -263,7 +263,7 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) {
AggregationBits: bitfield.Bitlist{0x05}, AggregationBits: bitfield.Bitlist{0x05},
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
CommitteeIndex: 5, CommitteeIndex: 5,
Target: &ethpb.Checkpoint{}, Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
}, },
stateSlot: 5, stateSlot: 5,
@@ -274,7 +274,7 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) {
AggregationBits: bitfield.Bitlist{0x06}, AggregationBits: bitfield.Bitlist{0x06},
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
CommitteeIndex: 10, CommitteeIndex: 10,
Target: &ethpb.Checkpoint{}, Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
}, },
stateSlot: 10, stateSlot: 10,
@@ -284,7 +284,7 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) {
AggregationBits: bitfield.Bitlist{0x06}, AggregationBits: bitfield.Bitlist{0x06},
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
CommitteeIndex: 20, CommitteeIndex: 20,
Target: &ethpb.Checkpoint{}, Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
}, },
stateSlot: 20, stateSlot: 20,
@@ -294,7 +294,7 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) {
AggregationBits: bitfield.Bitlist{0x06}, AggregationBits: bitfield.Bitlist{0x06},
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
CommitteeIndex: 20, CommitteeIndex: 20,
Target: &ethpb.Checkpoint{}, Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
}, },
stateSlot: 20, stateSlot: 20,
@@ -304,7 +304,7 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) {
AggregationBits: bitfield.Bitlist{0xFF, 0xC0, 0x01}, AggregationBits: bitfield.Bitlist{0xFF, 0xC0, 0x01},
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
CommitteeIndex: 5, CommitteeIndex: 5,
Target: &ethpb.Checkpoint{}, Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
}, },
stateSlot: 5, stateSlot: 5,
@@ -315,7 +315,7 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) {
AggregationBits: bitfield.Bitlist{0xFF, 0x01}, AggregationBits: bitfield.Bitlist{0xFF, 0x01},
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
CommitteeIndex: 20, CommitteeIndex: 20,
Target: &ethpb.Checkpoint{}, Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
}, },
stateSlot: 20, stateSlot: 20,

View File

@@ -1,11 +1,11 @@
package helpers package helpers
import ( import (
fssz "github.com/ferranbt/fastssz"
"github.com/pkg/errors" "github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz" "github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
p2ppb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" p2ppb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/bls"
@@ -48,16 +48,14 @@ func ComputeDomainAndSign(state *state.BeaconState, epoch uint64, obj interface{
// domain=domain, // domain=domain,
// )) // ))
func ComputeSigningRoot(object interface{}, domain []byte) ([32]byte, error) { 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) { return signingData(func() ([32]byte, error) {
switch t := object.(type) { if v, ok := object.(fssz.HashRoot); ok {
case *ethpb.BeaconBlock: return v.HashTreeRoot()
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) }, domain)
} }
@@ -72,7 +70,7 @@ func signingData(rootFunc func() ([32]byte, error), domain []byte) ([32]byte, er
ObjectRoot: objRoot[:], ObjectRoot: objRoot[:],
Domain: domain, Domain: domain,
} }
return ssz.HashTreeRoot(container) return container.HashTreeRoot()
} }
// ComputeDomainVerifySigningRoot computes domain and verifies signing root of an object given the beacon state, validator index and signature. // ComputeDomainVerifySigningRoot computes domain and verifies signing root of an object given the beacon state, validator index and signature.
@@ -138,7 +136,7 @@ func RetrieveBlockSignatureSet(blk *ethpb.BeaconBlock, pub []byte, signature []b
} }
root, err := signingData(func() ([32]byte, error) { root, err := signingData(func() ([32]byte, error) {
// utilize custom block hashing function // utilize custom block hashing function
return stateutil.BlockRoot(blk) return blk.HashTreeRoot()
}, domain) }, domain)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not compute signing root") return nil, errors.Wrap(err, "could not compute signing root")
@@ -161,7 +159,7 @@ func VerifyBlockHeaderSigningRoot(blkHdr *ethpb.BeaconBlockHeader, pub []byte, s
return errors.Wrap(err, "could not convert bytes to signature") return errors.Wrap(err, "could not convert bytes to signature")
} }
root, err := signingData(func() ([32]byte, error) { root, err := signingData(func() ([32]byte, error) {
return stateutil.BlockHeaderRoot(blkHdr) return blkHdr.HashTreeRoot()
}, domain) }, domain)
if err != nil { if err != nil {
return errors.Wrap(err, "could not compute signing root") return errors.Wrap(err, "could not compute signing root")
@@ -225,10 +223,10 @@ func domain(domainType [DomainByteLength]byte, forkDataRoot []byte) []byte {
// genesis_validators_root=genesis_validators_root, // genesis_validators_root=genesis_validators_root,
// )) // ))
func computeForkDataRoot(version []byte, root []byte) ([32]byte, error) { func computeForkDataRoot(version []byte, root []byte) ([32]byte, error) {
r, err := ssz.HashTreeRoot(&pb.ForkData{ r, err := (&pb.ForkData{
CurrentVersion: version, CurrentVersion: version,
GenesisValidatorsRoot: root, GenesisValidatorsRoot: root,
}) }).HashTreeRoot()
if err != nil { if err != nil {
return [32]byte{}, err return [32]byte{}, err
} }

View File

@@ -1,21 +1,21 @@
package helpers package helpers_test
import ( import (
"bytes" "bytes"
"testing" "testing"
fuzz "github.com/google/gofuzz" fuzz "github.com/google/gofuzz"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
ethereum_beacon_p2p_v1 "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" ethereum_beacon_p2p_v1 "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require" "github.com/prysmaticlabs/prysm/shared/testutil/require"
) )
func TestSigningRoot_ComputeOK(t *testing.T) { func TestSigningRoot_ComputeOK(t *testing.T) {
emptyBlock := &ethpb.BeaconBlock{} emptyBlock := testutil.NewBeaconBlock()
_, err := ComputeSigningRoot(emptyBlock, []byte{'T', 'E', 'S', 'T'}) _, err := helpers.ComputeSigningRoot(emptyBlock, bytesutil.PadTo([]byte{'T', 'E', 'S', 'T'}, 32))
assert.NoError(t, err, "Could not compute signing root of block") assert.NoError(t, err, "Could not compute signing root of block")
} }
@@ -25,38 +25,21 @@ func TestComputeDomain_OK(t *testing.T) {
domainType [4]byte domainType [4]byte
domain []byte domain []byte
}{ }{
{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: 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, 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, 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, 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, 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, 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, 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, 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, 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}},
} }
for _, tt := range tests { for _, tt := range tests {
if !bytes.Equal(domain(tt.domainType, params.BeaconConfig().ZeroHash[:]), tt.domain) { if got, err := helpers.ComputeDomain(tt.domainType, nil, nil); !bytes.Equal(got, tt.domain) {
t.Errorf("wanted domain version: %d, got: %d", tt.domain, domain(tt.domainType, params.BeaconConfig().ZeroHash[:])) t.Errorf("wanted domain version: %d, got: %d", tt.domain, got)
} else {
require.NoError(t, err)
} }
} }
} }
func TestSigningRoot_Compatibility(t *testing.T) {
parRoot := [32]byte{'A'}
stateRoot := [32]byte{'B'}
blk := &ethpb.BeaconBlock{
Slot: 20,
ProposerIndex: 20,
ParentRoot: parRoot[:],
StateRoot: stateRoot[:],
Body: &ethpb.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) { func TestComputeForkDigest_OK(t *testing.T) {
tests := []struct { tests := []struct {
version []byte version []byte
@@ -68,7 +51,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}}, {version: []byte{'b', 'w', 'r', 't'}, root: [32]byte{'r', 'd', 'c'}, result: [4]byte{0x83, 0x34, 0x38, 0x88}},
} }
for _, tt := range tests { for _, tt := range tests {
digest, err := ComputeForkDigest(tt.version, tt.root[:]) digest, err := helpers.ComputeForkDigest(tt.version, tt.root[:])
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, tt.result, digest, "Wanted domain version: %#x, got: %#x", digest, tt.result) assert.Equal(t, tt.result, digest, "Wanted domain version: %#x, got: %#x", digest, tt.result)
} }
@@ -92,8 +75,8 @@ func TestFuzzverifySigningRoot_10000(t *testing.T) {
fuzzer.Fuzz(&p) fuzzer.Fuzz(&p)
fuzzer.Fuzz(&s) fuzzer.Fuzz(&s)
fuzzer.Fuzz(&d) fuzzer.Fuzz(&d)
err := VerifySigningRoot(state, pubkey[:], sig[:], domain[:]) err := helpers.VerifySigningRoot(state, pubkey[:], sig[:], domain[:])
err = VerifySigningRoot(state, p, s, d) err = helpers.VerifySigningRoot(state, p, s, d)
_ = err _ = err
} }
} }

View File

@@ -728,7 +728,7 @@ func TestIsIsEligibleForActivation(t *testing.T) {
true}, true},
{"Not yet finalized", {"Not yet finalized",
&ethpb.Validator{ActivationEligibilityEpoch: 1, ActivationEpoch: params.BeaconConfig().FarFutureEpoch}, &ethpb.Validator{ActivationEligibilityEpoch: 1, ActivationEpoch: params.BeaconConfig().FarFutureEpoch},
&pb.BeaconState{FinalizedCheckpoint: &ethpb.Checkpoint{}}, &pb.BeaconState{FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)}},
false}, false},
{"Incorrect activation epoch", {"Incorrect activation epoch",
&ethpb.Validator{ActivationEligibilityEpoch: 1}, &ethpb.Validator{ActivationEligibilityEpoch: 1},

View File

@@ -38,7 +38,6 @@ go_library(
"//shared/trieutil:go_default_library", "//shared/trieutil:go_default_library",
"@com_github_pkg_errors//:go_default_library", "@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1: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//:go_default_library",
"@io_opencensus_go//trace:go_default_library", "@io_opencensus_go//trace:go_default_library",
], ],
@@ -65,11 +64,11 @@ go_test(
"//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/blocks:go_default_library",
"//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
"//shared/attestationutil:go_default_library", "//shared/attestationutil:go_default_library",
"//shared/benchutil:go_default_library", "//shared/benchutil:go_default_library",
"//shared/bls:go_default_library", "//shared/bls:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/hashutil:go_default_library", "//shared/hashutil:go_default_library",
"//shared/params:go_default_library", "//shared/params:go_default_library",
"//shared/testutil:go_default_library", "//shared/testutil:go_default_library",

View File

@@ -5,7 +5,6 @@ import (
"testing" "testing"
"github.com/gogo/protobuf/proto" "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/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state" beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
@@ -101,7 +100,7 @@ func BenchmarkHashTreeRoot_FullState(b *testing.B) {
b.N = 50 b.N = 50
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_, err := ssz.HashTreeRoot(beaconState) _, err := beaconState.HashTreeRoot(context.Background())
require.NoError(b, err) require.NoError(b, err)
} }
} }

View File

@@ -9,7 +9,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil" "github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
@@ -70,7 +69,7 @@ func GenesisBeaconState(deposits []*ethpb.Deposit, genesisTime uint64, eth1Data
if deposit == nil || deposit.Data == nil { if deposit == nil || deposit.Data == nil {
return nil, fmt.Errorf("nil deposit or deposit with nil data cannot be processed: %v", deposit) return nil, fmt.Errorf("nil deposit or deposit with nil data cannot be processed: %v", deposit)
} }
hash, err := ssz.HashTreeRoot(deposit.Data) hash, err := deposit.Data.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -189,7 +188,14 @@ func OptimizedGenesisBeaconState(genesisTime uint64, preState *stateTrie.BeaconS
Eth1DepositIndex: preState.Eth1DepositIndex(), Eth1DepositIndex: preState.Eth1DepositIndex(),
} }
bodyRoot, err := stateutil.BlockBodyRoot(&ethpb.BeaconBlockBody{}) bodyRoot, err := (&ethpb.BeaconBlockBody{
RandaoReveal: make([]byte, 96),
Eth1Data: &ethpb.Eth1Data{
DepositRoot: make([]byte, 32),
BlockHash: make([]byte, 32),
},
Graffiti: make([]byte, 32),
}).HashTreeRoot()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not hash tree root empty block body") return nil, errors.Wrap(err, "could not hash tree root empty block body")
} }

View File

@@ -17,7 +17,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state/interop" "github.com/prysmaticlabs/prysm/beacon-chain/core/state/interop"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/mathutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
@@ -269,7 +268,7 @@ func ProcessSlot(ctx context.Context, state *stateTrie.BeaconState) (*stateTrie.
return nil, err return nil, err
} }
} }
prevBlockRoot, err := stateutil.BlockHeaderRoot(state.LatestBlockHeader()) prevBlockRoot, err := state.LatestBlockHeader().HashTreeRoot()
if err != nil { if err != nil {
traceutil.AnnotateError(span, err) traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not determine prev block root") return nil, errors.Wrap(err, "could not determine prev block root")

View File

@@ -9,15 +9,14 @@ import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-bitfield" "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/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state" beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/attestationutil" "github.com/prysmaticlabs/prysm/shared/attestationutil"
"github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil"
@@ -52,19 +51,20 @@ func TestExecuteStateTransition_FullProcess(t *testing.T) {
eth1Data := &ethpb.Eth1Data{ eth1Data := &ethpb.Eth1Data{
DepositCount: 100, DepositCount: 100,
DepositRoot: []byte{2}, DepositRoot: bytesutil.PadTo([]byte{2}, 32),
BlockHash: make([]byte, 32),
} }
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch-1)) require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch-1))
e := beaconState.Eth1Data() e := beaconState.Eth1Data()
e.DepositCount = 100 e.DepositCount = 100
require.NoError(t, beaconState.SetEth1Data(e)) require.NoError(t, beaconState.SetEth1Data(e))
require.NoError(t, beaconState.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{Slot: beaconState.Slot()})) bh := beaconState.LatestBlockHeader()
bh.Slot = beaconState.Slot()
require.NoError(t, beaconState.SetLatestBlockHeader(bh))
require.NoError(t, beaconState.SetEth1DataVotes([]*ethpb.Eth1Data{eth1Data})) require.NoError(t, beaconState.SetEth1DataVotes([]*ethpb.Eth1Data{eth1Data}))
oldMix, err := beaconState.RandaoMixAtIndex(1) oldMix, err := beaconState.RandaoMixAtIndex(1)
require.NoError(t, err) require.NoError(t, err)
parentRoot, err := stateutil.BlockHeaderRoot(beaconState.LatestBlockHeader())
require.NoError(t, err)
require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1)) require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1))
epoch := helpers.CurrentEpoch(beaconState) epoch := helpers.CurrentEpoch(beaconState)
@@ -72,21 +72,18 @@ func TestExecuteStateTransition_FullProcess(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, beaconState.SetSlot(beaconState.Slot()-1)) require.NoError(t, beaconState.SetSlot(beaconState.Slot()-1))
nextSlotState := beaconState.Copy() nextSlotState, err := state.ProcessSlots(context.Background(), beaconState.Copy(), beaconState.Slot()+1)
require.NoError(t, nextSlotState.SetSlot(beaconState.Slot()+1)) require.NoError(t, err)
parentRoot, err := nextSlotState.LatestBlockHeader().HashTreeRoot()
require.NoError(t, err)
proposerIdx, err := helpers.BeaconProposerIndex(nextSlotState) proposerIdx, err := helpers.BeaconProposerIndex(nextSlotState)
require.NoError(t, err) require.NoError(t, err)
block := &ethpb.SignedBeaconBlock{ block := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ block.Block.ProposerIndex = proposerIdx
ProposerIndex: proposerIdx, block.Block.Slot = beaconState.Slot() + 1
Slot: beaconState.Slot() + 1, block.Block.ParentRoot = parentRoot[:]
ParentRoot: parentRoot[:], block.Block.Body.RandaoReveal = randaoReveal
Body: &ethpb.BeaconBlockBody{ block.Block.Body.Eth1Data = eth1Data
RandaoReveal: randaoReveal,
Eth1Data: eth1Data,
},
},
}
stateRoot, err := state.CalculateStateRoot(context.Background(), beaconState, block) stateRoot, err := state.CalculateStateRoot(context.Background(), beaconState, block)
require.NoError(t, err) require.NoError(t, err)
@@ -114,16 +111,17 @@ func TestExecuteStateTransitionNoVerify_FullProcess(t *testing.T) {
eth1Data := &ethpb.Eth1Data{ eth1Data := &ethpb.Eth1Data{
DepositCount: 100, DepositCount: 100,
DepositRoot: []byte{2}, DepositRoot: bytesutil.PadTo([]byte{2}, 32),
BlockHash: make([]byte, 32),
} }
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch-1)) require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch-1))
e := beaconState.Eth1Data() e := beaconState.Eth1Data()
e.DepositCount = 100 e.DepositCount = 100
require.NoError(t, beaconState.SetEth1Data(e)) require.NoError(t, beaconState.SetEth1Data(e))
require.NoError(t, beaconState.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{Slot: beaconState.Slot()})) bh := beaconState.LatestBlockHeader()
bh.Slot = beaconState.Slot()
require.NoError(t, beaconState.SetLatestBlockHeader(bh))
require.NoError(t, beaconState.SetEth1DataVotes([]*ethpb.Eth1Data{eth1Data})) require.NoError(t, beaconState.SetEth1DataVotes([]*ethpb.Eth1Data{eth1Data}))
parentRoot, err := stateutil.BlockHeaderRoot(beaconState.LatestBlockHeader())
require.NoError(t, err)
require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1)) require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1))
epoch := helpers.CurrentEpoch(beaconState) epoch := helpers.CurrentEpoch(beaconState)
@@ -131,21 +129,18 @@ func TestExecuteStateTransitionNoVerify_FullProcess(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, beaconState.SetSlot(beaconState.Slot()-1)) require.NoError(t, beaconState.SetSlot(beaconState.Slot()-1))
nextSlotState := beaconState.Copy() nextSlotState, err := state.ProcessSlots(context.Background(), beaconState.Copy(), beaconState.Slot()+1)
require.NoError(t, nextSlotState.SetSlot(beaconState.Slot()+1)) require.NoError(t, err)
parentRoot, err := nextSlotState.LatestBlockHeader().HashTreeRoot()
require.NoError(t, err)
proposerIdx, err := helpers.BeaconProposerIndex(nextSlotState) proposerIdx, err := helpers.BeaconProposerIndex(nextSlotState)
require.NoError(t, err) require.NoError(t, err)
block := &ethpb.SignedBeaconBlock{ block := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ block.Block.ProposerIndex = proposerIdx
ProposerIndex: proposerIdx, block.Block.Slot = beaconState.Slot() + 1
Slot: beaconState.Slot() + 1, block.Block.ParentRoot = parentRoot[:]
ParentRoot: parentRoot[:], block.Block.Body.RandaoReveal = randaoReveal
Body: &ethpb.BeaconBlockBody{ block.Block.Body.Eth1Data = eth1Data
RandaoReveal: randaoReveal,
Eth1Data: eth1Data,
},
},
}
stateRoot, err := state.CalculateStateRoot(context.Background(), beaconState, block) stateRoot, err := state.CalculateStateRoot(context.Background(), beaconState, block)
require.NoError(t, err) require.NoError(t, err)
@@ -169,8 +164,24 @@ func TestProcessBlock_IncorrectProposerSlashing(t *testing.T) {
block, err := testutil.GenerateFullBlock(beaconState, privKeys, nil, 1) block, err := testutil.GenerateFullBlock(beaconState, privKeys, nil, 1)
require.NoError(t, err) require.NoError(t, err)
slashing := &ethpb.ProposerSlashing{ slashing := &ethpb.ProposerSlashing{
Header_1: &ethpb.SignedBeaconBlockHeader{Header: &ethpb.BeaconBlockHeader{Slot: params.BeaconConfig().SlotsPerEpoch}}, Header_1: &ethpb.SignedBeaconBlockHeader{
Header_2: &ethpb.SignedBeaconBlockHeader{Header: &ethpb.BeaconBlockHeader{Slot: params.BeaconConfig().SlotsPerEpoch * 2}}, Header: &ethpb.BeaconBlockHeader{
Slot: params.BeaconConfig().SlotsPerEpoch,
ParentRoot: make([]byte, 32),
StateRoot: make([]byte, 32),
BodyRoot: make([]byte, 32),
},
Signature: make([]byte, 96),
},
Header_2: &ethpb.SignedBeaconBlockHeader{
Header: &ethpb.BeaconBlockHeader{
Slot: params.BeaconConfig().SlotsPerEpoch * 2,
ParentRoot: make([]byte, 32),
StateRoot: make([]byte, 32),
BodyRoot: make([]byte, 32),
},
Signature: make([]byte, 96),
},
} }
block.Block.Body.ProposerSlashings = []*ethpb.ProposerSlashing{slashing} block.Block.Body.ProposerSlashings = []*ethpb.ProposerSlashing{slashing}
@@ -193,10 +204,12 @@ func TestProcessBlock_IncorrectProcessBlockAttestations(t *testing.T) {
att := &ethpb.Attestation{ att := &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Epoch: 0}, Source: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
}, },
AggregationBits: bitfield.NewBitlist(3), AggregationBits: bitfield.NewBitlist(3),
Signature: bls.RandKey().Sign([]byte("foo")).Marshal(),
} }
block, err := testutil.GenerateFullBlock(beaconState, privKeys, nil, 1) block, err := testutil.GenerateFullBlock(beaconState, privKeys, nil, 1)
@@ -212,7 +225,7 @@ func TestProcessBlock_IncorrectProcessBlockAttestations(t *testing.T) {
beaconState, err = state.ProcessSlots(context.Background(), beaconState, 1) beaconState, err = state.ProcessSlots(context.Background(), beaconState, 1)
require.NoError(t, err) require.NoError(t, err)
want := "could not process block attestations" want := "could not verify attestations"
_, err = state.ProcessBlock(context.Background(), beaconState, block) _, err = state.ProcessBlock(context.Background(), beaconState, block)
assert.ErrorContains(t, want, err) assert.ErrorContains(t, want, err)
} }
@@ -226,15 +239,21 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
Header: &ethpb.BeaconBlockHeader{ Header: &ethpb.BeaconBlockHeader{
ProposerIndex: 3, ProposerIndex: 3,
Slot: 1, Slot: 1,
ParentRoot: make([]byte, 32),
StateRoot: make([]byte, 32),
BodyRoot: make([]byte, 32),
}, },
Signature: []byte("A"), Signature: bytesutil.PadTo([]byte("A"), 96),
}, },
Header_2: &ethpb.SignedBeaconBlockHeader{ Header_2: &ethpb.SignedBeaconBlockHeader{
Header: &ethpb.BeaconBlockHeader{ Header: &ethpb.BeaconBlockHeader{
ProposerIndex: 3, ProposerIndex: 3,
Slot: 1, Slot: 1,
ParentRoot: make([]byte, 32),
StateRoot: make([]byte, 32),
BodyRoot: make([]byte, 32),
}, },
Signature: []byte("B"), Signature: bytesutil.PadTo([]byte("B"), 96),
}, },
}, },
} }
@@ -242,17 +261,19 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
{ {
Attestation_1: &ethpb.IndexedAttestation{ Attestation_1: &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0}, Source: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
}, },
AttestingIndices: []uint64{0, 1}, AttestingIndices: []uint64{0, 1},
Signature: make([]byte, 96),
}, },
Attestation_2: &ethpb.IndexedAttestation{ Attestation_2: &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 1}, Source: &ethpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
}, },
AttestingIndices: []uint64{0, 1}, AttestingIndices: []uint64{0, 1},
Signature: make([]byte, 96),
}, },
}, },
} }
@@ -263,10 +284,12 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
require.NoError(t, beaconState.SetBlockRoots(blockRoots)) require.NoError(t, beaconState.SetBlockRoots(blockRoots))
blockAtt := &ethpb.Attestation{ blockAtt := &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0}, Source: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Epoch: 0, Root: []byte("hello-world")}, Target: &ethpb.Checkpoint{Epoch: 0, Root: bytesutil.PadTo([]byte("hello-world"), 32)},
BeaconBlockRoot: make([]byte, 32),
}, },
AggregationBits: bitfield.Bitlist{0xC0, 0xC0, 0xC0, 0xC0, 0x01}, AggregationBits: bitfield.Bitlist{0xC0, 0xC0, 0xC0, 0xC0, 0x01},
Signature: make([]byte, 96),
} }
attestations := []*ethpb.Attestation{blockAtt} attestations := []*ethpb.Attestation{blockAtt}
var exits []*ethpb.SignedVoluntaryExit var exits []*ethpb.SignedVoluntaryExit
@@ -274,33 +297,26 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
exits = append(exits, &ethpb.SignedVoluntaryExit{}) exits = append(exits, &ethpb.SignedVoluntaryExit{})
} }
genesisBlock := blocks.NewGenesisBlock([]byte{}) genesisBlock := blocks.NewGenesisBlock([]byte{})
bodyRoot, err := stateutil.BlockRoot(genesisBlock.Block) bodyRoot, err := genesisBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
err = beaconState.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{ err = beaconState.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{
Slot: genesisBlock.Block.Slot, Slot: genesisBlock.Block.Slot,
ParentRoot: genesisBlock.Block.ParentRoot, ParentRoot: genesisBlock.Block.ParentRoot,
BodyRoot: bodyRoot[:], BodyRoot: bodyRoot[:],
StateRoot: make([]byte, 32),
}) })
require.NoError(t, err) require.NoError(t, err)
parentRoot, err := ssz.HashTreeRoot(beaconState.LatestBlockHeader()) parentRoot, err := beaconState.LatestBlockHeader().HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
block := &ethpb.SignedBeaconBlock{ block := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ block.Block.Slot = 1
ParentRoot: parentRoot[:], block.Block.ParentRoot = parentRoot[:]
Slot: 1, block.Block.Body.ProposerSlashings = proposerSlashings
Body: &ethpb.BeaconBlockBody{ block.Block.Body.Attestations = attestations
RandaoReveal: []byte{}, block.Block.Body.AttesterSlashings = attesterSlashings
ProposerSlashings: proposerSlashings, block.Block.Body.VoluntaryExits = exits
AttesterSlashings: attesterSlashings, block.Block.Body.Eth1Data.DepositRoot = bytesutil.PadTo([]byte{2}, 32)
Attestations: attestations, block.Block.Body.Eth1Data.BlockHash = bytesutil.PadTo([]byte{3}, 32)
VoluntaryExits: exits,
Eth1Data: &ethpb.Eth1Data{
DepositRoot: []byte{2},
BlockHash: []byte{3},
},
},
},
}
err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay) err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
require.NoError(t, err) require.NoError(t, err)
cp := beaconState.CurrentJustifiedCheckpoint() cp := beaconState.CurrentJustifiedCheckpoint()
@@ -315,7 +331,7 @@ func createFullBlockWithOperations(t *testing.T) (*beaconstate.BeaconState,
*ethpb.SignedBeaconBlock, []*ethpb.Attestation, []*ethpb.ProposerSlashing, []*ethpb.SignedVoluntaryExit) { *ethpb.SignedBeaconBlock, []*ethpb.Attestation, []*ethpb.ProposerSlashing, []*ethpb.SignedVoluntaryExit) {
beaconState, privKeys := testutil.DeterministicGenesisState(t, 32) beaconState, privKeys := testutil.DeterministicGenesisState(t, 32)
genesisBlock := blocks.NewGenesisBlock([]byte{}) genesisBlock := blocks.NewGenesisBlock([]byte{})
bodyRoot, err := stateutil.BlockRoot(genesisBlock.Block) bodyRoot, err := genesisBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
err = beaconState.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{ err = beaconState.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{
Slot: genesisBlock.Block.Slot, Slot: genesisBlock.Block.Slot,
@@ -343,7 +359,9 @@ func createFullBlockWithOperations(t *testing.T) (*beaconstate.BeaconState,
Header: &ethpb.BeaconBlockHeader{ Header: &ethpb.BeaconBlockHeader{
ProposerIndex: proposerSlashIdx, ProposerIndex: proposerSlashIdx,
Slot: 1, Slot: 1,
StateRoot: []byte("A"), StateRoot: bytesutil.PadTo([]byte("A"), 32),
ParentRoot: make([]byte, 32),
BodyRoot: make([]byte, 32),
}, },
} }
header1.Signature, err = helpers.ComputeDomainAndSign(beaconState, currentEpoch, header1.Header, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerSlashIdx]) header1.Signature, err = helpers.ComputeDomainAndSign(beaconState, currentEpoch, header1.Header, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerSlashIdx])
@@ -353,7 +371,9 @@ func createFullBlockWithOperations(t *testing.T) (*beaconstate.BeaconState,
Header: &ethpb.BeaconBlockHeader{ Header: &ethpb.BeaconBlockHeader{
ProposerIndex: proposerSlashIdx, ProposerIndex: proposerSlashIdx,
Slot: 1, Slot: 1,
StateRoot: []byte("B"), StateRoot: bytesutil.PadTo([]byte("B"), 32),
ParentRoot: make([]byte, 32),
BodyRoot: make([]byte, 32),
}, },
} }
header2.Signature, err = helpers.ComputeDomainAndSign(beaconState, helpers.CurrentEpoch(beaconState), header2.Header, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerSlashIdx]) header2.Signature, err = helpers.ComputeDomainAndSign(beaconState, helpers.CurrentEpoch(beaconState), header2.Header, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerSlashIdx])
@@ -372,9 +392,12 @@ func createFullBlockWithOperations(t *testing.T) (*beaconstate.BeaconState,
mockRoot2 := [32]byte{'A'} mockRoot2 := [32]byte{'A'}
att1 := &ethpb.IndexedAttestation{ att1 := &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot2[:]}, Source: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot2[:]},
Target: &ethpb.Checkpoint{Epoch: 0}}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
},
AttestingIndices: []uint64{0, 1}, AttestingIndices: []uint64{0, 1},
Signature: make([]byte, 96),
} }
domain, err := helpers.Domain(beaconState.Fork(), currentEpoch, params.BeaconConfig().DomainBeaconAttester, beaconState.GenesisValidatorRoot()) domain, err := helpers.Domain(beaconState.Fork(), currentEpoch, params.BeaconConfig().DomainBeaconAttester, beaconState.GenesisValidatorRoot())
require.NoError(t, err) require.NoError(t, err)
@@ -388,9 +411,12 @@ func createFullBlockWithOperations(t *testing.T) (*beaconstate.BeaconState,
mockRoot3 := [32]byte{'B'} mockRoot3 := [32]byte{'B'}
att2 := &ethpb.IndexedAttestation{ att2 := &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot3[:]}, Source: &ethpb.Checkpoint{Epoch: 0, Root: mockRoot3[:]},
Target: &ethpb.Checkpoint{Epoch: 0}}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
},
AttestingIndices: []uint64{0, 1}, AttestingIndices: []uint64{0, 1},
Signature: make([]byte, 96),
} }
hashTreeRoot, err = helpers.ComputeSigningRoot(att2.Data, domain) hashTreeRoot, err = helpers.ComputeSigningRoot(att2.Data, domain)
@@ -417,13 +443,15 @@ func createFullBlockWithOperations(t *testing.T) (*beaconstate.BeaconState,
aggBits.SetBitAt(0, true) aggBits.SetBitAt(0, true)
blockAtt := &ethpb.Attestation{ blockAtt := &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: beaconState.Slot(), Slot: beaconState.Slot(),
Target: &ethpb.Checkpoint{Epoch: helpers.CurrentEpoch(beaconState)}, BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Epoch: helpers.CurrentEpoch(beaconState), Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{ Source: &ethpb.Checkpoint{
Epoch: 0, Epoch: 0,
Root: mockRoot[:], Root: mockRoot[:],
}}, }},
AggregationBits: aggBits, AggregationBits: aggBits,
Signature: make([]byte, 96),
} }
committee, err := helpers.BeaconCommitteeFromState(beaconState, blockAtt.Data.Slot, blockAtt.Data.CommitteeIndex) committee, err := helpers.BeaconCommitteeFromState(beaconState, blockAtt.Data.Slot, blockAtt.Data.CommitteeIndex)
@@ -453,7 +481,7 @@ func createFullBlockWithOperations(t *testing.T) (*beaconstate.BeaconState,
require.NoError(t, err) require.NoError(t, err)
header.StateRoot = prevStateRoot[:] header.StateRoot = prevStateRoot[:]
require.NoError(t, beaconState.SetLatestBlockHeader(header)) require.NoError(t, beaconState.SetLatestBlockHeader(header))
parentRoot, err := stateutil.BlockHeaderRoot(beaconState.LatestBlockHeader()) parentRoot, err := beaconState.LatestBlockHeader().HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
copied := beaconState.Copy() copied := beaconState.Copy()
require.NoError(t, copied.SetSlot(beaconState.Slot()+1)) require.NoError(t, copied.SetSlot(beaconState.Slot()+1))
@@ -467,14 +495,15 @@ func createFullBlockWithOperations(t *testing.T) (*beaconstate.BeaconState,
Slot: beaconState.Slot() + 1, Slot: beaconState.Slot() + 1,
ProposerIndex: proposerIndex, ProposerIndex: proposerIndex,
Body: &ethpb.BeaconBlockBody{ Body: &ethpb.BeaconBlockBody{
Graffiti: make([]byte, 32),
RandaoReveal: randaoReveal, RandaoReveal: randaoReveal,
ProposerSlashings: proposerSlashings, ProposerSlashings: proposerSlashings,
AttesterSlashings: attesterSlashings, AttesterSlashings: attesterSlashings,
Attestations: []*ethpb.Attestation{blockAtt}, Attestations: []*ethpb.Attestation{blockAtt},
VoluntaryExits: []*ethpb.SignedVoluntaryExit{exit}, VoluntaryExits: []*ethpb.SignedVoluntaryExit{exit},
Eth1Data: &ethpb.Eth1Data{ Eth1Data: &ethpb.Eth1Data{
DepositRoot: []byte{2}, DepositRoot: bytesutil.PadTo([]byte{2}, 32),
BlockHash: []byte{3}, BlockHash: bytesutil.PadTo([]byte{3}, 32),
}, },
}, },
}, },
@@ -522,7 +551,7 @@ func TestProcessBlockNoVerify_PassesProcessingConditions(t *testing.T) {
func TestProcessEpochPrecompute_CanProcess(t *testing.T) { func TestProcessEpochPrecompute_CanProcess(t *testing.T) {
epoch := uint64(1) epoch := uint64(1)
atts := []*pb.PendingAttestation{{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{}}, InclusionDelay: 1}} atts := []*pb.PendingAttestation{{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{Root: make([]byte, 32)}}, InclusionDelay: 1}}
slashing := make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector) slashing := make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector)
base := &pb.BeaconState{ base := &pb.BeaconState{
Slot: epoch*params.BeaconConfig().SlotsPerEpoch + 1, Slot: epoch*params.BeaconConfig().SlotsPerEpoch + 1,
@@ -530,9 +559,9 @@ func TestProcessEpochPrecompute_CanProcess(t *testing.T) {
Slashings: slashing, Slashings: slashing,
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
CurrentEpochAttestations: atts, CurrentEpochAttestations: atts,
FinalizedCheckpoint: &ethpb.Checkpoint{}, FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
JustificationBits: bitfield.Bitvector4{0x00}, JustificationBits: bitfield.Bitvector4{0x00},
CurrentJustifiedCheckpoint: &ethpb.Checkpoint{}, CurrentJustifiedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
Validators: []*ethpb.Validator{}, Validators: []*ethpb.Validator{},
} }
s, err := beaconstate.InitializeFromProto(base) s, err := beaconstate.InitializeFromProto(base)
@@ -592,14 +621,14 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
ProposerIndex: 1, ProposerIndex: 1,
Slot: 0, Slot: 0,
}, },
Signature: []byte("A"), Signature: bytesutil.PadTo([]byte("A"), 96),
}, },
Header_2: &ethpb.SignedBeaconBlockHeader{ Header_2: &ethpb.SignedBeaconBlockHeader{
Header: &ethpb.BeaconBlockHeader{ Header: &ethpb.BeaconBlockHeader{
ProposerIndex: 1, ProposerIndex: 1,
Slot: 0, Slot: 0,
}, },
Signature: []byte("B"), Signature: bytesutil.PadTo([]byte("B"), 96),
}, },
}, },
} }
@@ -608,11 +637,19 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
attesterSlashings := []*ethpb.AttesterSlashing{ attesterSlashings := []*ethpb.AttesterSlashing{
{ {
Attestation_1: &ethpb.IndexedAttestation{ Attestation_1: &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{}, Data: &ethpb.AttestationData{
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
},
AttestingIndices: []uint64{2, 3}, AttestingIndices: []uint64{2, 3},
}, },
Attestation_2: &ethpb.IndexedAttestation{ Attestation_2: &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{}, Data: &ethpb.AttestationData{
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
},
AttestingIndices: []uint64{2, 3}, AttestingIndices: []uint64{2, 3},
}, },
}, },
@@ -625,7 +662,7 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
Amount: params.BeaconConfig().MaxEffectiveBalance, Amount: params.BeaconConfig().MaxEffectiveBalance,
}, },
} }
leaf, err := ssz.HashTreeRoot(deposit.Data) leaf, err := deposit.Data.HashTreeRoot()
require.NoError(b, err) require.NoError(b, err)
depositTrie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, int(params.BeaconConfig().DepositContractTreeDepth)) depositTrie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, int(params.BeaconConfig().DepositContractTreeDepth))
require.NoError(b, err, "Could not generate trie") require.NoError(b, err, "Could not generate trie")
@@ -648,7 +685,7 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
ObjectRoot: buf, ObjectRoot: buf,
Domain: domain, Domain: domain,
} }
root, err = ssz.HashTreeRoot(ctr) root, err = ctr.HashTreeRoot()
require.NoError(b, err) require.NoError(b, err)
epochSignature := priv.Sign(root[:]) epochSignature := priv.Sign(root[:])
@@ -725,10 +762,13 @@ func TestProcessBlk_AttsBasedOnValidatorCount(t *testing.T) {
for i := 0; i < len(atts); i++ { for i := 0; i < len(atts); i++ {
att := &ethpb.Attestation{ att := &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
Source: &ethpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]}, Source: &ethpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
Target: &ethpb.Checkpoint{Epoch: 0}}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
},
AggregationBits: aggBits, AggregationBits: aggBits,
Signature: make([]byte, 96),
} }
committee, err := helpers.BeaconCommitteeFromState(s, att.Data.Slot, att.Data.CommitteeIndex) committee, err := helpers.BeaconCommitteeFromState(s, att.Data.Slot, att.Data.CommitteeIndex)
@@ -757,25 +797,19 @@ func TestProcessBlk_AttsBasedOnValidatorCount(t *testing.T) {
header.StateRoot = prevStateRoot[:] header.StateRoot = prevStateRoot[:]
require.NoError(t, s.SetLatestBlockHeader(header)) require.NoError(t, s.SetLatestBlockHeader(header))
parentRoot, err := stateutil.BlockHeaderRoot(s.LatestBlockHeader()) parentRoot, err := s.LatestBlockHeader().HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
nextSlotState := s.Copy() nextSlotState := s.Copy()
require.NoError(t, nextSlotState.SetSlot(s.Slot()+1)) require.NoError(t, nextSlotState.SetSlot(s.Slot()+1))
proposerIdx, err := helpers.BeaconProposerIndex(nextSlotState) proposerIdx, err := helpers.BeaconProposerIndex(nextSlotState)
require.NoError(t, err) require.NoError(t, err)
blk := &ethpb.SignedBeaconBlock{ blk := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ blk.Block.ProposerIndex = proposerIdx
ProposerIndex: proposerIdx, blk.Block.Slot = s.Slot() + 1
Slot: s.Slot() + 1, blk.Block.ParentRoot = parentRoot[:]
ParentRoot: parentRoot[:], blk.Block.Body.RandaoReveal = epochSignature
Body: &ethpb.BeaconBlockBody{ blk.Block.Body.Attestations = atts
Eth1Data: &ethpb.Eth1Data{},
RandaoReveal: epochSignature,
Attestations: atts,
},
},
}
sig, err := testutil.BlockSignature(s, blk.Block, privKeys) sig, err := testutil.BlockSignature(s, blk.Block, privKeys)
require.NoError(t, err) require.NoError(t, err)
blk.Signature = sig.Marshal() blk.Signature = sig.Marshal()

View File

@@ -18,6 +18,7 @@ go_library(
"//shared/featureconfig:go_default_library", "//shared/featureconfig:go_default_library",
"//shared/traceutil:go_default_library", "//shared/traceutil:go_default_library",
"@com_github_ethereum_go_ethereum//common: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//jsonpb:go_default_library_gen",
"@com_github_golang_protobuf//proto:go_default_library", "@com_github_golang_protobuf//proto:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",

View File

@@ -6,6 +6,7 @@ import (
"bytes" "bytes"
"context" "context"
fssz "github.com/ferranbt/fastssz"
"github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
@@ -55,7 +56,13 @@ func (e Exporter) publish(ctx context.Context, topic string, msg proto.Message)
return err return err
} }
key, err := ssz.HashTreeRoot(msg) var key [32]byte
var err error
if v, ok := msg.(fssz.HashRoot); ok {
key, err = v.HashTreeRoot()
} else {
key, err = ssz.HashTreeRoot(msg)
}
if err != nil { if err != nil {
traceutil.AnnotateError(span, err) traceutil.AnnotateError(span, err)
return err return err

View File

@@ -34,7 +34,6 @@ go_library(
"//beacon-chain/db/filters:go_default_library", "//beacon-chain/db/filters:go_default_library",
"//beacon-chain/db/iface:go_default_library", "//beacon-chain/db/iface:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//proto/beacon/db:go_default_library", "//proto/beacon/db:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
"//shared/bytesutil:go_default_library", "//shared/bytesutil:go_default_library",
@@ -50,7 +49,6 @@ go_library(
"@com_github_pkg_errors//:go_default_library", "@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1: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_prysmaticlabs_prombbolt//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library",
"@io_etcd_go_bbolt//:go_default_library", "@io_etcd_go_bbolt//:go_default_library",
@@ -83,7 +81,6 @@ go_test(
"//beacon-chain/cache:go_default_library", "//beacon-chain/cache:go_default_library",
"//beacon-chain/db/filters:go_default_library", "//beacon-chain/db/filters:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
"//proto/testing:go_default_library", "//proto/testing:go_default_library",
"//shared/bytesutil:go_default_library", "//shared/bytesutil:go_default_library",
@@ -94,7 +91,6 @@ go_test(
"@com_github_ethereum_go_ethereum//common:go_default_library", "@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1: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", "@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
"@io_etcd_go_bbolt//:go_default_library", "@io_etcd_go_bbolt//:go_default_library",
], ],

View File

@@ -6,8 +6,6 @@ import (
"path" "path"
"testing" "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"
"github.com/prysmaticlabs/prysm/shared/testutil/require" "github.com/prysmaticlabs/prysm/shared/testutil/require"
) )
@@ -16,10 +14,11 @@ func TestStore_Backup(t *testing.T) {
db := setupDB(t) db := setupDB(t)
ctx := context.Background() ctx := context.Background()
head := &eth.SignedBeaconBlock{Block: &eth.BeaconBlock{Slot: 5000}} head := testutil.NewBeaconBlock()
head.Block.Slot = 5000
require.NoError(t, db.SaveBlock(ctx, head)) require.NoError(t, db.SaveBlock(ctx, head))
root, err := stateutil.BlockRoot(head.Block) root, err := head.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
st := testutil.NewBeaconState() st := testutil.NewBeaconState()
require.NoError(t, db.SaveState(ctx, st, root)) require.NoError(t, db.SaveState(ctx, st, root))

View File

@@ -9,7 +9,6 @@ import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/sliceutil" "github.com/prysmaticlabs/prysm/shared/sliceutil"
@@ -181,7 +180,7 @@ func (kv *Store) deleteBlocks(ctx context.Context, blockRoots [][32]byte) error
func (kv *Store) SaveBlock(ctx context.Context, signed *ethpb.SignedBeaconBlock) error { func (kv *Store) SaveBlock(ctx context.Context, signed *ethpb.SignedBeaconBlock) error {
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveBlock") ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveBlock")
defer span.End() defer span.End()
blockRoot, err := stateutil.BlockRoot(signed.Block) blockRoot, err := signed.Block.HashTreeRoot()
if err != nil { if err != nil {
return err return err
} }
@@ -200,7 +199,7 @@ func (kv *Store) SaveBlocks(ctx context.Context, blocks []*ethpb.SignedBeaconBlo
return kv.db.Update(func(tx *bolt.Tx) error { return kv.db.Update(func(tx *bolt.Tx) error {
bkt := tx.Bucket(blocksBucket) bkt := tx.Bucket(blocksBucket)
for _, block := range blocks { for _, block := range blocks {
blockRoot, err := stateutil.BlockRoot(block.Block) blockRoot, err := block.Block.HashTreeRoot()
if err != nil { if err != nil {
return err return err
} }

View File

@@ -8,7 +8,6 @@ import (
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil"
@@ -22,19 +21,14 @@ func TestStore_SaveBlock_NoDuplicates(t *testing.T) {
slot := uint64(20) slot := uint64(20)
ctx := context.Background() ctx := context.Background()
// First we save a previous block to ensure the cache max size is reached. // First we save a previous block to ensure the cache max size is reached.
prevBlock := &ethpb.SignedBeaconBlock{ prevBlock := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ prevBlock.Block.Slot = slot - 1
Slot: slot - 1, prevBlock.Block.ParentRoot = bytesutil.PadTo([]byte{1, 2, 3}, 32)
ParentRoot: bytesutil.PadTo([]byte{1, 2, 3}, 32),
},
}
require.NoError(t, db.SaveBlock(ctx, prevBlock)) require.NoError(t, db.SaveBlock(ctx, prevBlock))
block := &ethpb.SignedBeaconBlock{
Block: &ethpb.BeaconBlock{ block := testutil.NewBeaconBlock()
Slot: slot, block.Block.Slot = slot
ParentRoot: bytesutil.PadTo([]byte{1, 2, 3}, 32), block.Block.ParentRoot = bytesutil.PadTo([]byte{1, 2, 3}, 32)
},
}
// Even with a full cache, saving new blocks should not cause // Even with a full cache, saving new blocks should not cause
// duplicated blocks in the DB. // duplicated blocks in the DB.
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
@@ -51,13 +45,12 @@ func TestStore_SaveBlock_NoDuplicates(t *testing.T) {
func TestStore_BlocksCRUD(t *testing.T) { func TestStore_BlocksCRUD(t *testing.T) {
db := setupDB(t) db := setupDB(t)
ctx := context.Background() ctx := context.Background()
block := &ethpb.SignedBeaconBlock{
Block: &ethpb.BeaconBlock{ block := testutil.NewBeaconBlock()
Slot: 20, block.Block.Slot = 20
ParentRoot: bytesutil.PadTo([]byte{1, 2, 3}, 32), block.Block.ParentRoot = bytesutil.PadTo([]byte{1, 2, 3}, 32)
},
} blockRoot, err := block.Block.HashTreeRoot()
blockRoot, err := stateutil.BlockRoot(block.Block)
require.NoError(t, err) require.NoError(t, err)
retrievedBlock, err := db.Block(ctx, blockRoot) retrievedBlock, err := db.Block(ctx, blockRoot)
require.NoError(t, err) require.NoError(t, err)
@@ -84,7 +77,7 @@ func TestStore_BlocksBatchDelete(t *testing.T) {
b.Block.ParentRoot = bytesutil.PadTo([]byte("parent"), 32) b.Block.ParentRoot = bytesutil.PadTo([]byte("parent"), 32)
totalBlocks[i] = b totalBlocks[i] = b
if i%2 == 0 { if i%2 == 0 {
r, err := stateutil.BlockRoot(totalBlocks[i].Block) r, err := totalBlocks[i].Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
blockRoots = append(blockRoots, r) blockRoots = append(blockRoots, r)
} else { } else {
@@ -113,7 +106,7 @@ func TestStore_GenesisBlock(t *testing.T) {
ctx := context.Background() ctx := context.Background()
genesisBlock := testutil.NewBeaconBlock() genesisBlock := testutil.NewBeaconBlock()
genesisBlock.Block.ParentRoot = bytesutil.PadTo([]byte{1, 2, 3}, 32) genesisBlock.Block.ParentRoot = bytesutil.PadTo([]byte{1, 2, 3}, 32)
blockRoot, err := stateutil.BlockRoot(genesisBlock.Block) blockRoot, err := genesisBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, blockRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, blockRoot))
require.NoError(t, db.SaveBlock(ctx, genesisBlock)) require.NoError(t, db.SaveBlock(ctx, genesisBlock))
@@ -128,7 +121,7 @@ func TestStore_BlocksCRUD_NoCache(t *testing.T) {
block := testutil.NewBeaconBlock() block := testutil.NewBeaconBlock()
block.Block.Slot = 20 block.Block.Slot = 20
block.Block.ParentRoot = bytesutil.PadTo([]byte{1, 2, 3}, 32) block.Block.ParentRoot = bytesutil.PadTo([]byte{1, 2, 3}, 32)
blockRoot, err := stateutil.BlockRoot(block.Block) blockRoot, err := block.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
retrievedBlock, err := db.Block(ctx, blockRoot) retrievedBlock, err := db.Block(ctx, blockRoot)
require.NoError(t, err) require.NoError(t, err)
@@ -231,11 +224,11 @@ func TestStore_Blocks_VerifyBlockRoots(t *testing.T) {
db := setupDB(t) db := setupDB(t)
b1 := testutil.NewBeaconBlock() b1 := testutil.NewBeaconBlock()
b1.Block.Slot = 1 b1.Block.Slot = 1
r1, err := stateutil.BlockRoot(b1.Block) r1, err := b1.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
b2 := testutil.NewBeaconBlock() b2 := testutil.NewBeaconBlock()
b2.Block.Slot = 2 b2.Block.Slot = 2
r2, err := stateutil.BlockRoot(b2.Block) r2, err := b2.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveBlock(ctx, b1)) require.NoError(t, db.SaveBlock(ctx, b1))
@@ -333,7 +326,7 @@ func TestStore_SaveBlock_CanGetHighestAt(t *testing.T) {
assert.Equal(t, false, len(highestAt) <= 0, "Got empty highest at slice") assert.Equal(t, false, len(highestAt) <= 0, "Got empty highest at slice")
assert.Equal(t, true, proto.Equal(block3, highestAt[0]), "Wanted: %v, received: %v", block3, highestAt[0]) assert.Equal(t, true, proto.Equal(block3, highestAt[0]), "Wanted: %v, received: %v", block3, highestAt[0])
r3, err := stateutil.BlockRoot(block3.Block) r3, err := block3.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.deleteBlock(ctx, r3)) require.NoError(t, db.deleteBlock(ctx, r3))
@@ -347,7 +340,7 @@ func TestStore_GenesisBlock_CanGetHighestAt(t *testing.T) {
ctx := context.Background() ctx := context.Background()
genesisBlock := testutil.NewBeaconBlock() genesisBlock := testutil.NewBeaconBlock()
genesisRoot, err := stateutil.BlockRoot(genesisBlock.Block) genesisRoot, err := genesisBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, genesisRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, genesisRoot))
require.NoError(t, db.SaveBlock(ctx, genesisBlock)) require.NoError(t, db.SaveBlock(ctx, genesisBlock))
@@ -372,12 +365,10 @@ func TestStore_SaveBlocks_HasCachedBlocks(t *testing.T) {
b := make([]*ethpb.SignedBeaconBlock, 500) b := make([]*ethpb.SignedBeaconBlock, 500)
for i := 0; i < 500; i++ { for i := 0; i < 500; i++ {
b[i] = &ethpb.SignedBeaconBlock{ blk := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ blk.Block.ParentRoot = bytesutil.PadTo([]byte("parent"), 32)
ParentRoot: bytesutil.PadTo([]byte("parent"), 32), blk.Block.Slot = uint64(i)
Slot: uint64(i), b[i] = blk
},
}
} }
require.NoError(t, db.SaveBlock(ctx, b[0])) require.NoError(t, db.SaveBlock(ctx, b[0]))

View File

@@ -6,7 +6,6 @@ import (
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil"
@@ -39,14 +38,11 @@ func TestStore_FinalizedCheckpoint_CanSaveRetrieve(t *testing.T) {
genesis := bytesutil.ToBytes32([]byte{'G', 'E', 'N', 'E', 'S', 'I', 'S'}) genesis := bytesutil.ToBytes32([]byte{'G', 'E', 'N', 'E', 'S', 'I', 'S'})
require.NoError(t, db.SaveGenesisBlockRoot(ctx, genesis)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, genesis))
blk := &ethpb.SignedBeaconBlock{ blk := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ blk.Block.ParentRoot = genesis[:]
ParentRoot: genesis[:], blk.Block.Slot = 40
Slot: 40,
},
}
root, err := stateutil.BlockRoot(blk.Block) root, err := blk.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
cp := &ethpb.Checkpoint{ cp := &ethpb.Checkpoint{

View File

@@ -5,7 +5,6 @@ import (
"testing" "testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil"
@@ -25,7 +24,7 @@ func TestStore_IsFinalizedBlock(t *testing.T) {
blks := makeBlocks(t, 0, slotsPerEpoch*3, genesisBlockRoot) blks := makeBlocks(t, 0, slotsPerEpoch*3, genesisBlockRoot)
require.NoError(t, db.SaveBlocks(ctx, blks)) require.NoError(t, db.SaveBlocks(ctx, blks))
root, err := stateutil.BlockRoot(blks[slotsPerEpoch].Block) root, err := blks[slotsPerEpoch].Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
cp := &ethpb.Checkpoint{ cp := &ethpb.Checkpoint{
@@ -40,12 +39,12 @@ func TestStore_IsFinalizedBlock(t *testing.T) {
// All blocks up to slotsPerEpoch*2 should be in the finalized index. // All blocks up to slotsPerEpoch*2 should be in the finalized index.
for i := uint64(0); i < slotsPerEpoch*2; i++ { for i := uint64(0); i < slotsPerEpoch*2; i++ {
root, err := stateutil.BlockRoot(blks[i].Block) root, err := blks[i].Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, true, db.IsFinalizedBlock(ctx, root), "Block at index %d was not considered finalized in the index", i) assert.Equal(t, true, db.IsFinalizedBlock(ctx, root), "Block at index %d was not considered finalized in the index", i)
} }
for i := slotsPerEpoch * 3; i < uint64(len(blks)); i++ { for i := slotsPerEpoch * 3; i < uint64(len(blks)); i++ {
root, err := stateutil.BlockRoot(blks[i].Block) root, err := blks[i].Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, false, db.IsFinalizedBlock(ctx, root), "Block at index %d was considered finalized in the index, but should not have", i) assert.Equal(t, false, db.IsFinalizedBlock(ctx, root), "Block at index %d was considered finalized in the index, but should not have", i)
} }
@@ -55,8 +54,9 @@ func TestStore_IsFinalizedBlockGenesis(t *testing.T) {
db := setupDB(t) db := setupDB(t)
ctx := context.Background() ctx := context.Background()
blk := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 0}} blk := testutil.NewBeaconBlock()
root, err := stateutil.BlockRoot(blk.Block) blk.Block.Slot = 0
root, err := blk.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveBlock(ctx, blk)) require.NoError(t, db.SaveBlock(ctx, blk))
require.NoError(t, db.SaveGenesisBlockRoot(ctx, root)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, root))
@@ -129,7 +129,7 @@ func TestStore_IsFinalized_ForkEdgeCase(t *testing.T) {
} }
func sszRootOrDie(t *testing.T, block *ethpb.SignedBeaconBlock) []byte { func sszRootOrDie(t *testing.T, block *ethpb.SignedBeaconBlock) []byte {
root, err := stateutil.BlockRoot(block.Block) root, err := block.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
return root[:] return root[:]
} }
@@ -139,14 +139,11 @@ func makeBlocks(t *testing.T, i, n uint64, previousRoot [32]byte) []*ethpb.Signe
for j := i; j < n+i; j++ { for j := i; j < n+i; j++ {
parentRoot := make([]byte, 32) parentRoot := make([]byte, 32)
copy(parentRoot, previousRoot[:]) copy(parentRoot, previousRoot[:])
blocks[j-i] = &ethpb.SignedBeaconBlock{ blocks[j-i] = testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ blocks[j-i].Block.Slot = j + 1
Slot: j + 1, blocks[j-i].Block.ParentRoot = parentRoot
ParentRoot: parentRoot,
},
}
var err error var err error
previousRoot, err = stateutil.BlockRoot(blocks[j-i].Block) previousRoot, err = blocks[j-i].Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
} }
return blocks return blocks

View File

@@ -6,8 +6,8 @@ import (
"fmt" "fmt"
"testing" "testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/assert"
"go.etcd.io/bbolt" "go.etcd.io/bbolt"
) )
@@ -53,8 +53,9 @@ func Test_migrateArchivedIndex(t *testing.T) {
if err := tx.Bucket(archivedRootBucket).Put(bytesutil.Uint64ToBytesLittleEndian(2048), []byte("foo")); err != nil { if err := tx.Bucket(archivedRootBucket).Put(bytesutil.Uint64ToBytesLittleEndian(2048), []byte("foo")); err != nil {
return err return err
} }
sb := testutil.NewBeaconBlock()
b, err := encode(context.Background(), &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 2048}}) sb.Block.Slot = 2048
b, err := encode(context.Background(), sb)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -4,7 +4,6 @@ import (
"context" "context"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
bolt "go.etcd.io/bbolt" bolt "go.etcd.io/bbolt"
"go.opencensus.io/trace" "go.opencensus.io/trace"
) )
@@ -42,7 +41,7 @@ func (kv *Store) HasVoluntaryExit(ctx context.Context, exitRoot [32]byte) bool {
func (kv *Store) SaveVoluntaryExit(ctx context.Context, exit *ethpb.VoluntaryExit) error { func (kv *Store) SaveVoluntaryExit(ctx context.Context, exit *ethpb.VoluntaryExit) error {
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveVoluntaryExit") ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveVoluntaryExit")
defer span.End() defer span.End()
exitRoot, err := ssz.HashTreeRoot(exit) exitRoot, err := exit.HashTreeRoot()
if err != nil { if err != nil {
return err return err
} }

View File

@@ -6,7 +6,6 @@ import (
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" 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/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require" "github.com/prysmaticlabs/prysm/shared/testutil/require"
) )
@@ -17,7 +16,7 @@ func TestStore_VoluntaryExits_CRUD(t *testing.T) {
exit := &ethpb.VoluntaryExit{ exit := &ethpb.VoluntaryExit{
Epoch: 5, Epoch: 5,
} }
exitRoot, err := ssz.HashTreeRoot(exit) exitRoot, err := exit.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
retrieved, err := db.VoluntaryExit(ctx, exitRoot) retrieved, err := db.VoluntaryExit(ctx, exitRoot)
require.NoError(t, err) require.NoError(t, err)

View File

@@ -11,7 +11,6 @@ import (
transition "github.com/prysmaticlabs/prysm/beacon-chain/core/state" transition "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@@ -99,7 +98,7 @@ func (kv *Store) regenHistoricalStates(ctx context.Context) error {
return errors.Wrap(err, "could not regenerate historical state transition") return errors.Wrap(err, "could not regenerate historical state transition")
} }
r, err := stateutil.BlockRoot(blocks[i].Block) r, err := blocks[i].Block.HashTreeRoot()
if err != nil { if err != nil {
return err return err
} }
@@ -227,7 +226,7 @@ func (kv *Store) saveArchivedInfo(ctx context.Context,
return errors.New("no blocks provided") return errors.New("no blocks provided")
} }
lastBlocksRoot, err := stateutil.BlockRoot(blocks[len(blocks)-1].Block) lastBlocksRoot, err := blocks[len(blocks)-1].Block.HashTreeRoot()
if err != nil { if err != nil {
return nil return nil
} }

View File

@@ -4,7 +4,6 @@ import (
"context" "context"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
bolt "go.etcd.io/bbolt" bolt "go.etcd.io/bbolt"
"go.opencensus.io/trace" "go.opencensus.io/trace"
) )
@@ -42,7 +41,7 @@ func (kv *Store) HasProposerSlashing(ctx context.Context, slashingRoot [32]byte)
func (kv *Store) SaveProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error { func (kv *Store) SaveProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error {
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveProposerSlashing") ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveProposerSlashing")
defer span.End() defer span.End()
slashingRoot, err := ssz.HashTreeRoot(slashing) slashingRoot, err := slashing.HashTreeRoot()
if err != nil { if err != nil {
return err return err
} }
@@ -111,7 +110,7 @@ func (kv *Store) HasAttesterSlashing(ctx context.Context, slashingRoot [32]byte)
func (kv *Store) SaveAttesterSlashing(ctx context.Context, slashing *ethpb.AttesterSlashing) error { func (kv *Store) SaveAttesterSlashing(ctx context.Context, slashing *ethpb.AttesterSlashing) error {
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveAttesterSlashing") ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveAttesterSlashing")
defer span.End() defer span.End()
slashingRoot, err := ssz.HashTreeRoot(slashing) slashingRoot, err := slashing.HashTreeRoot()
if err != nil { if err != nil {
return err return err
} }

View File

@@ -6,7 +6,6 @@ import (
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" 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/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require" "github.com/prysmaticlabs/prysm/shared/testutil/require"
) )
@@ -34,7 +33,7 @@ func TestStore_ProposerSlashing_CRUD(t *testing.T) {
Signature: make([]byte, 96), Signature: make([]byte, 96),
}, },
} }
slashingRoot, err := ssz.HashTreeRoot(prop) slashingRoot, err := prop.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
retrieved, err := db.ProposerSlashing(ctx, slashingRoot) retrieved, err := db.ProposerSlashing(ctx, slashingRoot)
require.NoError(t, err) require.NoError(t, err)
@@ -83,7 +82,7 @@ func TestStore_AttesterSlashing_CRUD(t *testing.T) {
Signature: make([]byte, 96), Signature: make([]byte, 96),
}, },
} }
slashingRoot, err := ssz.HashTreeRoot(att) slashingRoot, err := att.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
retrieved, err := db.AttesterSlashing(ctx, slashingRoot) retrieved, err := db.AttesterSlashing(ctx, slashingRoot)
require.NoError(t, err) require.NoError(t, err)

View File

@@ -8,7 +8,6 @@ import (
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/assert"
@@ -88,7 +87,7 @@ func TestStore_StatesBatchDelete(t *testing.T) {
b := testutil.NewBeaconBlock() b := testutil.NewBeaconBlock()
b.Block.Slot = uint64(i) b.Block.Slot = uint64(i)
totalBlocks[i] = b totalBlocks[i] = b
r, err := stateutil.BlockRoot(totalBlocks[i].Block) r, err := totalBlocks[i].Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
st := testutil.NewBeaconState() st := testutil.NewBeaconState()
require.NoError(t, st.SetSlot(uint64(i))) require.NoError(t, st.SetSlot(uint64(i)))
@@ -132,15 +131,13 @@ func TestStore_DeleteFinalizedState(t *testing.T) {
genesis := bytesutil.ToBytes32([]byte{'G', 'E', 'N', 'E', 'S', 'I', 'S'}) genesis := bytesutil.ToBytes32([]byte{'G', 'E', 'N', 'E', 'S', 'I', 'S'})
require.NoError(t, db.SaveGenesisBlockRoot(ctx, genesis)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, genesis))
blk := &ethpb.SignedBeaconBlock{ blk := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ blk.Block.ParentRoot = genesis[:]
ParentRoot: genesis[:], blk.Block.Slot = 100
Slot: 100,
},
}
require.NoError(t, db.SaveBlock(ctx, blk)) require.NoError(t, db.SaveBlock(ctx, blk))
finalizedBlockRoot, err := stateutil.BlockRoot(blk.Block) finalizedBlockRoot, err := blk.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
finalizedState := testutil.NewBeaconState() finalizedState := testutil.NewBeaconState()
@@ -159,15 +156,12 @@ func TestStore_DeleteHeadState(t *testing.T) {
genesis := bytesutil.ToBytes32([]byte{'G', 'E', 'N', 'E', 'S', 'I', 'S'}) genesis := bytesutil.ToBytes32([]byte{'G', 'E', 'N', 'E', 'S', 'I', 'S'})
require.NoError(t, db.SaveGenesisBlockRoot(ctx, genesis)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, genesis))
blk := &ethpb.SignedBeaconBlock{ blk := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ blk.Block.ParentRoot = genesis[:]
ParentRoot: genesis[:], blk.Block.Slot = 100
Slot: 100,
},
}
require.NoError(t, db.SaveBlock(ctx, blk)) require.NoError(t, db.SaveBlock(ctx, blk))
headBlockRoot, err := stateutil.BlockRoot(blk.Block) headBlockRoot, err := blk.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
st := testutil.NewBeaconState() st := testutil.NewBeaconState()
require.NoError(t, st.SetSlot(100)) require.NoError(t, st.SetSlot(100))
@@ -180,8 +174,9 @@ func TestStore_DeleteHeadState(t *testing.T) {
func TestStore_SaveDeleteState_CanGetHighestBelow(t *testing.T) { func TestStore_SaveDeleteState_CanGetHighestBelow(t *testing.T) {
db := setupDB(t) db := setupDB(t)
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 1}} b := testutil.NewBeaconBlock()
r, err := stateutil.BlockRoot(b.Block) b.Block.Slot = 1
r, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveBlock(context.Background(), b)) require.NoError(t, db.SaveBlock(context.Background(), b))
st := testutil.NewBeaconState() st := testutil.NewBeaconState()
@@ -189,8 +184,8 @@ func TestStore_SaveDeleteState_CanGetHighestBelow(t *testing.T) {
s0 := st.InnerStateUnsafe() s0 := st.InnerStateUnsafe()
require.NoError(t, db.SaveState(context.Background(), st, r)) require.NoError(t, db.SaveState(context.Background(), st, r))
b = &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 100}} b.Block.Slot = 100
r1, err := stateutil.BlockRoot(b.Block) r1, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveBlock(context.Background(), b)) require.NoError(t, db.SaveBlock(context.Background(), b))
st = testutil.NewBeaconState() st = testutil.NewBeaconState()
@@ -198,8 +193,8 @@ func TestStore_SaveDeleteState_CanGetHighestBelow(t *testing.T) {
s1 := st.InnerStateUnsafe() s1 := st.InnerStateUnsafe()
require.NoError(t, db.SaveState(context.Background(), st, r1)) require.NoError(t, db.SaveState(context.Background(), st, r1))
b = &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 1000}} b.Block.Slot = 1000
r2, err := stateutil.BlockRoot(b.Block) r2, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveBlock(context.Background(), b)) require.NoError(t, db.SaveBlock(context.Background(), b))
st = testutil.NewBeaconState() st = testutil.NewBeaconState()
@@ -229,8 +224,9 @@ func TestStore_GenesisState_CanGetHighestBelow(t *testing.T) {
require.NoError(t, db.SaveGenesisBlockRoot(context.Background(), genesisRoot)) require.NoError(t, db.SaveGenesisBlockRoot(context.Background(), genesisRoot))
require.NoError(t, db.SaveState(context.Background(), genesisState, genesisRoot)) require.NoError(t, db.SaveState(context.Background(), genesisState, genesisRoot))
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 1}} b := testutil.NewBeaconBlock()
r, err := stateutil.BlockRoot(b.Block) b.Block.Slot = 1
r, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveBlock(context.Background(), b)) require.NoError(t, db.SaveBlock(context.Background(), b))

View File

@@ -14,7 +14,6 @@ go_library(
"//beacon-chain/db:go_default_library", "//beacon-chain/db:go_default_library",
"//beacon-chain/powchain:go_default_library", "//beacon-chain/powchain:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
"//shared:go_default_library", "//shared:go_default_library",
"//shared/interop:go_default_library", "//shared/interop:go_default_library",

View File

@@ -16,7 +16,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/powchain" "github.com/prysmaticlabs/prysm/beacon-chain/powchain"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" 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" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared" "github.com/prysmaticlabs/prysm/shared"
"github.com/prysmaticlabs/prysm/shared/interop" "github.com/prysmaticlabs/prysm/shared/interop"
@@ -173,7 +172,7 @@ func (s *Service) saveGenesisState(ctx context.Context, genesisState *stateTrie.
return err return err
} }
genesisBlk := blocks.NewGenesisBlock(stateRoot[:]) genesisBlk := blocks.NewGenesisBlock(stateRoot[:])
genesisBlkRoot, err := stateutil.BlockRoot(genesisBlk.Block) genesisBlkRoot, err := genesisBlk.Block.HashTreeRoot()
if err != nil { if err != nil {
return errors.Wrap(err, "could not get genesis block root") return errors.Wrap(err, "could not get genesis block root")
} }

View File

@@ -16,7 +16,6 @@ go_library(
deps = [ deps = [
"//beacon-chain/operations/attestations/kv:go_default_library", "//beacon-chain/operations/attestations/kv:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//shared/aggregation/attestations:go_default_library", "//shared/aggregation/attestations:go_default_library",
"//shared/hashutil:go_default_library", "//shared/hashutil:go_default_library",
"//shared/params:go_default_library", "//shared/params:go_default_library",

View File

@@ -16,7 +16,6 @@ go_library(
deps = [ deps = [
"//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//shared/aggregation/attestations:go_default_library", "//shared/aggregation/attestations:go_default_library",
"//shared/hashutil:go_default_library", "//shared/hashutil:go_default_library",
"//shared/params:go_default_library", "//shared/params:go_default_library",
@@ -42,6 +41,7 @@ go_test(
"//shared/bls:go_default_library", "//shared/bls:go_default_library",
"//shared/testutil/assert:go_default_library", "//shared/testutil/assert:go_default_library",
"//shared/testutil/require: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_patrickmn_go_cache//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library",

View File

@@ -5,7 +5,6 @@ import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
attaggregation "github.com/prysmaticlabs/prysm/shared/aggregation/attestations" attaggregation "github.com/prysmaticlabs/prysm/shared/aggregation/attestations"
) )
@@ -20,7 +19,7 @@ func (p *AttCaches) AggregateUnaggregatedAttestations() error {
} }
attsByDataRoot := make(map[[32]byte][]*ethpb.Attestation, len(unaggregatedAtts)) attsByDataRoot := make(map[[32]byte][]*ethpb.Attestation, len(unaggregatedAtts))
for _, att := range unaggregatedAtts { for _, att := range unaggregatedAtts {
attDataRoot, err := stateutil.AttestationDataRoot(att.Data) attDataRoot, err := att.Data.HashTreeRoot()
if err != nil { if err != nil {
return err return err
} }

View File

@@ -4,6 +4,7 @@ import (
"sort" "sort"
"testing" "testing"
fssz "github.com/ferranbt/fastssz"
c "github.com/patrickmn/go-cache" c "github.com/patrickmn/go-cache"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/go-bitfield"
@@ -17,14 +18,14 @@ func TestKV_Aggregated_AggregateUnaggregatedAttestations(t *testing.T) {
priv := bls.RandKey() priv := bls.RandKey()
sig1 := priv.Sign([]byte{'a'}) sig1 := priv.Sign([]byte{'a'})
sig2 := priv.Sign([]byte{'b'}) sig2 := priv.Sign([]byte{'b'})
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig1.Marshal()} att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig1.Marshal()}
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1010}, Signature: sig1.Marshal()} att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1010}, Signature: sig1.Marshal()}
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1100}, Signature: sig1.Marshal()} att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1100}, Signature: sig1.Marshal()}
att4 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig2.Marshal()} att4 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig2.Marshal()}
att5 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig1.Marshal()} att5 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig1.Marshal()}
att6 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1010}, Signature: sig1.Marshal()} att6 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1010}, Signature: sig1.Marshal()}
att7 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1100}, Signature: sig1.Marshal()} att7 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1100}, Signature: sig1.Marshal()}
att8 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig2.Marshal()} att8 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig2.Marshal()}
atts := []*ethpb.Attestation{att1, att2, att3, att4, att5, att6, att7, att8} atts := []*ethpb.Attestation{att1, att2, att3, att4, att5, att6, att7, att8}
require.NoError(t, cache.SaveUnaggregatedAttestations(atts)) require.NoError(t, cache.SaveUnaggregatedAttestations(atts))
require.NoError(t, cache.AggregateUnaggregatedAttestations()) require.NoError(t, cache.AggregateUnaggregatedAttestations())
@@ -51,7 +52,11 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) {
{ {
name: "not aggregated", name: "not aggregated",
att: &ethpb.Attestation{ att: &ethpb.Attestation{
Data: &ethpb.AttestationData{}, AggregationBits: bitfield.Bitlist{0b10100}}, Data: &ethpb.AttestationData{
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, AggregationBits: bitfield.Bitlist{0b10100}},
wantErrString: "attestation is not aggregated", wantErrString: "attestation is not aggregated",
}, },
{ {
@@ -62,15 +67,19 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) {
}, },
AggregationBits: bitfield.Bitlist{0b10111}, AggregationBits: bitfield.Bitlist{0b10111},
}, },
wantErrString: "could not tree hash attestation: incorrect fixed bytes marshalling", wantErrString: "could not tree hash attestation: " + fssz.ErrBytesLength.Error(),
}, },
{ {
name: "already seen", name: "already seen",
att: &ethpb.Attestation{ att: &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 100, Slot: 100,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b11101001}, AggregationBits: bitfield.Bitlist{0b11101001},
Signature: make([]byte, 96),
}, },
count: 0, count: 0,
}, },
@@ -78,15 +87,22 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) {
name: "normal save", name: "normal save",
att: &ethpb.Attestation{ att: &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1101}, AggregationBits: bitfield.Bitlist{0b1101},
Signature: make([]byte, 96),
}, },
count: 1, count: 1,
}, },
} }
r, err := hashFn(&ethpb.AttestationData{ r, err := hashFn(&ethpb.AttestationData{
Slot: 100, Slot: 100,
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
}) })
require.NoError(t, err) require.NoError(t, err)
@@ -118,9 +134,9 @@ func TestKV_Aggregated_SaveAggregatedAttestations(t *testing.T) {
{ {
name: "no duplicates", name: "no duplicates",
atts: []*ethpb.Attestation{ atts: []*ethpb.Attestation{
{Data: &ethpb.AttestationData{Slot: 1}, {Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}},
AggregationBits: bitfield.Bitlist{0b1101}}, AggregationBits: bitfield.Bitlist{0b1101}},
{Data: &ethpb.AttestationData{Slot: 1}, {Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}},
AggregationBits: bitfield.Bitlist{0b1101}}, AggregationBits: bitfield.Bitlist{0b1101}},
}, },
count: 1, count: 1,
@@ -146,9 +162,9 @@ func TestKV_Aggregated_SaveAggregatedAttestations(t *testing.T) {
func TestKV_Aggregated_AggregatedAttestations(t *testing.T) { func TestKV_Aggregated_AggregatedAttestations(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}} att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}} att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}} att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
atts := []*ethpb.Attestation{att1, att2, att3} atts := []*ethpb.Attestation{att1, att2, att3}
for _, att := range atts { for _, att := range atts {
@@ -166,13 +182,13 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) {
t.Run("nil attestation", func(t *testing.T) { t.Run("nil attestation", func(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
assert.NoError(t, cache.DeleteAggregatedAttestation(nil)) assert.NoError(t, cache.DeleteAggregatedAttestation(nil))
att := &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0b10101}} att := &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0b10101}, Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}}
assert.NoError(t, cache.DeleteAggregatedAttestation(att)) assert.NoError(t, cache.DeleteAggregatedAttestation(att))
}) })
t.Run("non aggregated attestation", func(t *testing.T) { t.Run("non aggregated attestation", func(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
att := &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0b1001}, Data: &ethpb.AttestationData{Slot: 2}} att := &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0b1001}, Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}}
err := cache.DeleteAggregatedAttestation(att) err := cache.DeleteAggregatedAttestation(att)
assert.ErrorContains(t, "attestation is not aggregated", err) assert.ErrorContains(t, "attestation is not aggregated", err)
}) })
@@ -182,27 +198,26 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) {
att := &ethpb.Attestation{ att := &ethpb.Attestation{
AggregationBits: bitfield.Bitlist{0b1111}, AggregationBits: bitfield.Bitlist{0b1111},
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 2, Slot: 2,
BeaconBlockRoot: []byte{0b0},
}, },
} }
err := cache.DeleteAggregatedAttestation(att) err := cache.DeleteAggregatedAttestation(att)
wantErr := "could not tree hash attestation data: incorrect fixed bytes marshalling" wantErr := "could not tree hash attestation data: " + fssz.ErrBytesLength.Error()
assert.ErrorContains(t, wantErr, err) assert.ErrorContains(t, wantErr, err)
}) })
t.Run("nonexistent attestation", func(t *testing.T) { t.Run("nonexistent attestation", func(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
att := &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0b1111}, Data: &ethpb.AttestationData{Slot: 2}} att := &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0b1111}, Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}}
assert.NoError(t, cache.DeleteAggregatedAttestation(att)) assert.NoError(t, cache.DeleteAggregatedAttestation(att))
}) })
t.Run("non-filtered deletion", func(t *testing.T) { t.Run("non-filtered deletion", func(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}} att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}} att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}} att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
att4 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b10101}} att4 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b10101}}
atts := []*ethpb.Attestation{att1, att2, att3, att4} atts := []*ethpb.Attestation{att1, att2, att3, att4}
require.NoError(t, cache.SaveAggregatedAttestations(atts)) require.NoError(t, cache.SaveAggregatedAttestations(atts))
require.NoError(t, cache.DeleteAggregatedAttestation(att1)) require.NoError(t, cache.DeleteAggregatedAttestation(att1))
@@ -215,10 +230,10 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) {
t.Run("filtered deletion", func(t *testing.T) { t.Run("filtered deletion", func(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b110101}} att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110101}}
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110111}} att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110111}}
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110100}} att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110100}}
att4 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110101}} att4 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110101}}
atts := []*ethpb.Attestation{att1, att2, att3, att4} atts := []*ethpb.Attestation{att1, att2, att3, att4}
require.NoError(t, cache.SaveAggregatedAttestations(atts)) require.NoError(t, cache.SaveAggregatedAttestations(atts))
@@ -249,14 +264,23 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
{ {
name: "nil attestation data", name: "nil attestation data",
input: &ethpb.Attestation{ input: &ethpb.Attestation{
AggregationBits: bitfield.Bitlist{0b1111}}, AggregationBits: bitfield.Bitlist{0b1111},
Data: &ethpb.AttestationData{
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
},
},
want: false, want: false,
}, },
{ {
name: "empty cache aggregated", name: "empty cache aggregated",
input: &ethpb.Attestation{ input: &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1111}}, AggregationBits: bitfield.Bitlist{0b1111}},
want: false, want: false,
@@ -265,7 +289,10 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
name: "empty cache unaggregated", name: "empty cache unaggregated",
input: &ethpb.Attestation{ input: &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1001}}, AggregationBits: bitfield.Bitlist{0b1001}},
want: false, want: false,
@@ -274,13 +301,19 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
name: "single attestation in cache with exact match", name: "single attestation in cache with exact match",
existing: []*ethpb.Attestation{{ existing: []*ethpb.Attestation{{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1111}}, AggregationBits: bitfield.Bitlist{0b1111}},
}, },
input: &ethpb.Attestation{ input: &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1111}}, AggregationBits: bitfield.Bitlist{0b1111}},
want: true, want: true,
@@ -289,13 +322,19 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
name: "single attestation in cache with subset aggregation", name: "single attestation in cache with subset aggregation",
existing: []*ethpb.Attestation{{ existing: []*ethpb.Attestation{{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1111}}, AggregationBits: bitfield.Bitlist{0b1111}},
}, },
input: &ethpb.Attestation{ input: &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1110}}, AggregationBits: bitfield.Bitlist{0b1110}},
want: true, want: true,
@@ -304,13 +343,19 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
name: "single attestation in cache with superset aggregation", name: "single attestation in cache with superset aggregation",
existing: []*ethpb.Attestation{{ existing: []*ethpb.Attestation{{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1110}}, AggregationBits: bitfield.Bitlist{0b1110}},
}, },
input: &ethpb.Attestation{ input: &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1111}}, AggregationBits: bitfield.Bitlist{0b1111}},
want: false, want: false,
@@ -320,20 +365,29 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
existing: []*ethpb.Attestation{ existing: []*ethpb.Attestation{
{ {
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1111000}, AggregationBits: bitfield.Bitlist{0b1111000},
}, },
{ {
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1100111}, AggregationBits: bitfield.Bitlist{0b1100111},
}, },
}, },
input: &ethpb.Attestation{ input: &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1100000}}, AggregationBits: bitfield.Bitlist{0b1100000}},
want: true, want: true,
@@ -343,20 +397,29 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
existing: []*ethpb.Attestation{ existing: []*ethpb.Attestation{
{ {
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1111000}, AggregationBits: bitfield.Bitlist{0b1111000},
}, },
{ {
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1100111}, AggregationBits: bitfield.Bitlist{0b1100111},
}, },
}, },
input: &ethpb.Attestation{ input: &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1111111}}, AggregationBits: bitfield.Bitlist{0b1111111}},
want: false, want: false,
@@ -366,20 +429,29 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
existing: []*ethpb.Attestation{ existing: []*ethpb.Attestation{
{ {
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 2, Slot: 2,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1111000}, AggregationBits: bitfield.Bitlist{0b1111000},
}, },
{ {
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 3, Slot: 3,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1100111}, AggregationBits: bitfield.Bitlist{0b1100111},
}, },
}, },
input: &ethpb.Attestation{ input: &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 1, Slot: 1,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1111111}}, AggregationBits: bitfield.Bitlist{0b1111111}},
want: false, want: false,
@@ -389,14 +461,20 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
existing: []*ethpb.Attestation{ existing: []*ethpb.Attestation{
{ {
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 2, Slot: 2,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1111000}, AggregationBits: bitfield.Bitlist{0b1111000},
}, },
}, },
input: &ethpb.Attestation{ input: &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 2, Slot: 2,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b1111}, AggregationBits: bitfield.Bitlist{0b1111},
}, },
@@ -409,6 +487,10 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
require.NoError(t, cache.SaveAggregatedAttestations(tt.existing)) require.NoError(t, cache.SaveAggregatedAttestations(tt.existing))
if tt.input != nil && tt.input.Signature == nil {
tt.input.Signature = make([]byte, 96)
}
result, err := cache.HasAggregatedAttestation(tt.input) result, err := cache.HasAggregatedAttestation(tt.input)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, tt.want, result) assert.Equal(t, tt.want, result)
@@ -427,8 +509,8 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) {
func TestKV_Aggregated_DuplicateAggregatedAttestations(t *testing.T) { func TestKV_Aggregated_DuplicateAggregatedAttestations(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}} att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1111}} att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1111}}
atts := []*ethpb.Attestation{att1, att2} atts := []*ethpb.Attestation{att1, att2}
for _, att := range atts { for _, att := range atts {

View File

@@ -13,9 +13,9 @@ import (
func TestKV_BlockAttestation_CanSaveRetrieve(t *testing.T) { func TestKV_BlockAttestation_CanSaveRetrieve(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}} att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}} att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}} att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
atts := []*ethpb.Attestation{att1, att2, att3} atts := []*ethpb.Attestation{att1, att2, att3}
for _, att := range atts { for _, att := range atts {
@@ -34,9 +34,9 @@ func TestKV_BlockAttestation_CanSaveRetrieve(t *testing.T) {
func TestKV_BlockAttestation_CanDelete(t *testing.T) { func TestKV_BlockAttestation_CanDelete(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}} att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}} att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}} att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
atts := []*ethpb.Attestation{att1, att2, att3} atts := []*ethpb.Attestation{att1, att2, att3}
for _, att := range atts { for _, att := range atts {

View File

@@ -13,9 +13,9 @@ import (
func TestKV_Forkchoice_CanSaveRetrieve(t *testing.T) { func TestKV_Forkchoice_CanSaveRetrieve(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}} att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}, Signature: make([]byte, 96)}
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}} att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}, Signature: make([]byte, 96)}
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}} att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}, Signature: make([]byte, 96)}
atts := []*ethpb.Attestation{att1, att2, att3} atts := []*ethpb.Attestation{att1, att2, att3}
for _, att := range atts { for _, att := range atts {
@@ -34,9 +34,9 @@ func TestKV_Forkchoice_CanSaveRetrieve(t *testing.T) {
func TestKV_Forkchoice_CanDelete(t *testing.T) { func TestKV_Forkchoice_CanDelete(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}} att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}, Signature: make([]byte, 96)}
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}} att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}, Signature: make([]byte, 96)}
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}} att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}, Signature: make([]byte, 96)}
atts := []*ethpb.Attestation{att1, att2, att3} atts := []*ethpb.Attestation{att1, att2, att3}
for _, att := range atts { for _, att := range atts {

View File

@@ -10,21 +10,25 @@ import (
func TestAttCaches_hasSeenBit(t *testing.T) { func TestAttCaches_hasSeenBit(t *testing.T) {
c := NewAttCaches() c := NewAttCaches()
d := &ethpb.AttestationData{} d := &ethpb.AttestationData{
seenA1 := &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000011}} Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
seenA2 := &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11100000}} Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
}
seenA1 := &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000011}, Signature: make([]byte, 96)}
seenA2 := &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11100000}, Signature: make([]byte, 96)}
require.NoError(t, c.insertSeenBit(seenA1)) require.NoError(t, c.insertSeenBit(seenA1))
require.NoError(t, c.insertSeenBit(seenA2)) require.NoError(t, c.insertSeenBit(seenA2))
tests := []struct { tests := []struct {
att *ethpb.Attestation att *ethpb.Attestation
want bool want bool
}{ }{
{att: &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000000}}, want: true}, {att: &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000000}, Signature: make([]byte, 96)}, want: true},
{att: &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000001}}, want: true}, {att: &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000001}, Signature: make([]byte, 96)}, want: true},
{att: &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11100000}}, want: true}, {att: &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11100000}, Signature: make([]byte, 96)}, want: true},
{att: &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000011}}, want: true}, {att: &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000011}, Signature: make([]byte, 96)}, want: true},
{att: &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b00001000}}, want: false}, {att: &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b00001000}, Signature: make([]byte, 96)}, want: false},
{att: &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11110111}}, want: false}, {att: &ethpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11110111}, Signature: make([]byte, 96)}, want: false},
} }
for _, tt := range tests { for _, tt := range tests {
got, err := c.hasSeenBit(tt.att) got, err := c.hasSeenBit(tt.att)

View File

@@ -3,6 +3,7 @@ package kv
import ( import (
"testing" "testing"
fssz "github.com/ferranbt/fastssz"
c "github.com/patrickmn/go-cache" c "github.com/patrickmn/go-cache"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/go-bitfield"
@@ -23,7 +24,7 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) {
}, },
{ {
name: "already aggregated", name: "already aggregated",
att: &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0b10101}}, att: &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0b10101}, Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}},
wantErrString: "attestation is aggregated", wantErrString: "attestation is aggregated",
}, },
{ {
@@ -33,31 +34,33 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) {
BeaconBlockRoot: []byte{0b0}, BeaconBlockRoot: []byte{0b0},
}, },
}, },
wantErrString: "incorrect fixed bytes marshalling", wantErrString: fssz.ErrBytesLength.Error(),
}, },
{ {
name: "normal save", name: "normal save",
att: &ethpb.Attestation{ att: &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0b0001}, Data: &ethpb.AttestationData{BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}},
Data: &ethpb.AttestationData{
Slot: 100,
},
AggregationBits: bitfield.Bitlist{0b0001},
},
count: 1, count: 1,
}, },
{ {
name: "already seen", name: "already seen",
att: &ethpb.Attestation{ att: &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 100, Slot: 100,
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b10000001}, AggregationBits: bitfield.Bitlist{0b10000001},
Signature: make([]byte, 96),
}, },
count: 0, count: 0,
}, },
} }
r, err := hashFn(&ethpb.AttestationData{ r, err := hashFn(&ethpb.AttestationData{
Slot: 100, Slot: 100,
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
}) })
require.NoError(t, err) require.NoError(t, err)
@@ -67,6 +70,10 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) {
cache.seenAtt.Set(string(r[:]), []bitfield.Bitlist{{0xff}}, c.DefaultExpiration) cache.seenAtt.Set(string(r[:]), []bitfield.Bitlist{{0xff}}, c.DefaultExpiration)
assert.Equal(t, 0, len(cache.unAggregatedAtt), "Invalid start pool, atts: %d", len(cache.unAggregatedAtt)) assert.Equal(t, 0, len(cache.unAggregatedAtt), "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) err := cache.SaveUnaggregatedAttestation(tt.att)
if tt.wantErrString != "" { if tt.wantErrString != "" {
assert.ErrorContains(t, tt.wantErrString, err) assert.ErrorContains(t, tt.wantErrString, err)
@@ -89,18 +96,18 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestations(t *testing.T) {
{ {
name: "unaggregated only", name: "unaggregated only",
atts: []*ethpb.Attestation{ atts: []*ethpb.Attestation{
{Data: &ethpb.AttestationData{Slot: 1}}, {Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, Signature: make([]byte, 96)},
{Data: &ethpb.AttestationData{Slot: 2}}, {Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, Signature: make([]byte, 96)},
{Data: &ethpb.AttestationData{Slot: 3}}, {Data: &ethpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, Signature: make([]byte, 96)},
}, },
count: 3, count: 3,
}, },
{ {
name: "has aggregated", name: "has aggregated",
atts: []*ethpb.Attestation{ atts: []*ethpb.Attestation{
{Data: &ethpb.AttestationData{Slot: 1}}, {Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, Signature: make([]byte, 96)},
{AggregationBits: bitfield.Bitlist{0b1111}, Data: &ethpb.AttestationData{Slot: 2}}, {AggregationBits: bitfield.Bitlist{0b1111}, Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, Signature: make([]byte, 96)},
{Data: &ethpb.AttestationData{Slot: 3}}, {Data: &ethpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, Signature: make([]byte, 96)},
}, },
wantErrString: "attestation is aggregated", wantErrString: "attestation is aggregated",
count: 1, count: 1,
@@ -132,16 +139,16 @@ func TestKV_Unaggregated_DeleteUnaggregatedAttestation(t *testing.T) {
t.Run("aggregated attestation", func(t *testing.T) { t.Run("aggregated attestation", func(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
att := &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0b1111}, Data: &ethpb.AttestationData{Slot: 2}} att := &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0b1111}, Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, Signature: make([]byte, 96)}
err := cache.DeleteUnaggregatedAttestation(att) err := cache.DeleteUnaggregatedAttestation(att)
assert.ErrorContains(t, "attestation is aggregated", err) assert.ErrorContains(t, "attestation is aggregated", err)
}) })
t.Run("successful deletion", func(t *testing.T) { t.Run("successful deletion", func(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b101}} att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b101}, Signature: make([]byte, 96)}
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110}} att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110}, Signature: make([]byte, 96)}
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b110}} att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110}, Signature: make([]byte, 96)}
atts := []*ethpb.Attestation{att1, att2, att3} atts := []*ethpb.Attestation{att1, att2, att3}
require.NoError(t, cache.SaveUnaggregatedAttestations(atts)) require.NoError(t, cache.SaveUnaggregatedAttestations(atts))
for _, att := range atts { for _, att := range atts {
@@ -156,9 +163,9 @@ func TestKV_Unaggregated_DeleteUnaggregatedAttestation(t *testing.T) {
func TestKV_Unaggregated_UnaggregatedAttestationsBySlotIndex(t *testing.T) { func TestKV_Unaggregated_UnaggregatedAttestationsBySlotIndex(t *testing.T) {
cache := NewAttCaches() cache := NewAttCaches()
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, CommitteeIndex: 1}, AggregationBits: bitfield.Bitlist{0b101}} att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, CommitteeIndex: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b101}, Signature: make([]byte, 96)}
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, CommitteeIndex: 2}, AggregationBits: bitfield.Bitlist{0b110}} att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, CommitteeIndex: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110}, Signature: make([]byte, 96)}
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, CommitteeIndex: 1}, AggregationBits: bitfield.Bitlist{0b110}} att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, CommitteeIndex: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b110}, Signature: make([]byte, 96)}
atts := []*ethpb.Attestation{att1, att2, att3} atts := []*ethpb.Attestation{att1, att2, att3}
for _, att := range atts { for _, att := range atts {

View File

@@ -9,7 +9,6 @@ import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/go-bitfield"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
attaggregation "github.com/prysmaticlabs/prysm/shared/aggregation/attestations" attaggregation "github.com/prysmaticlabs/prysm/shared/aggregation/attestations"
"github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/slotutil" "github.com/prysmaticlabs/prysm/shared/slotutil"
@@ -62,7 +61,7 @@ func (s *Service) batchForkChoiceAtts(ctx context.Context) error {
continue continue
} }
attDataRoot, err := stateutil.AttestationDataRoot(att.Data) attDataRoot, err := att.Data.HashTreeRoot()
if err != nil { if err != nil {
return err return err
} }

View File

@@ -2,6 +2,7 @@ package attestations
import ( import (
"context" "context"
"fmt"
"sort" "sort"
"testing" "testing"
@@ -228,23 +229,64 @@ func TestSeenAttestations_PresentInCache(t *testing.T) {
s, err := NewService(context.Background(), &Config{Pool: NewPool()}) s, err := NewService(context.Background(), &Config{Pool: NewPool()})
require.NoError(t, err) require.NoError(t, err)
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{}, Signature: []byte{'A'}, AggregationBits: bitfield.Bitlist{0x13} /* 0b00010011 */} ad1 := &ethpb.AttestationData{
Slot: 0,
CommitteeIndex: 0,
BeaconBlockRoot: make([]byte, 32),
Source: &ethpb.Checkpoint{
Epoch: 0,
Root: make([]byte, 32),
},
Target: &ethpb.Checkpoint{
Epoch: 0,
Root: make([]byte, 32),
},
}
att1 := &ethpb.Attestation{Data: ad1, Signature: []byte{'A'}, AggregationBits: bitfield.Bitlist{0x13} /* 0b00010011 */}
got, err := s.seen(att1) got, err := s.seen(att1)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, false, got) assert.Equal(t, false, got)
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{}, Signature: []byte{'A'}, AggregationBits: bitfield.Bitlist{0x17} /* 0b00010111 */} att2 := &ethpb.Attestation{Data: ad1, Signature: []byte{'A'}, AggregationBits: bitfield.Bitlist{0x17} /* 0b00010111 */}
got, err = s.seen(att2) got, err = s.seen(att2)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, false, got) assert.Equal(t, false, got)
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{}, Signature: []byte{'A'}, AggregationBits: bitfield.Bitlist{0x17} /* 0b00010111 */} att3 := &ethpb.Attestation{Data: ad1, Signature: []byte{'A'}, AggregationBits: bitfield.Bitlist{0x17} /* 0b00010111 */}
got, err = s.seen(att3) got, err = s.seen(att3)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, true, got) assert.Equal(t, true, got)
} }
func TestService_seen(t *testing.T) { func TestService_seen(t *testing.T) {
ad1 := &ethpb.AttestationData{
Slot: 1,
CommitteeIndex: 0,
BeaconBlockRoot: make([]byte, 32),
Source: &ethpb.Checkpoint{
Epoch: 0,
Root: make([]byte, 32),
},
Target: &ethpb.Checkpoint{
Epoch: 0,
Root: make([]byte, 32),
},
}
ad2 := &ethpb.AttestationData{
Slot: 2,
CommitteeIndex: 0,
BeaconBlockRoot: make([]byte, 32),
Source: &ethpb.Checkpoint{
Epoch: 0,
Root: make([]byte, 32),
},
Target: &ethpb.Checkpoint{
Epoch: 0,
Root: make([]byte, 32),
},
}
// Attestation are checked in order of this list. // Attestation are checked in order of this list.
tests := []struct { tests := []struct {
att *ethpb.Attestation att *ethpb.Attestation
@@ -253,42 +295,42 @@ func TestService_seen(t *testing.T) {
{ {
att: &ethpb.Attestation{ att: &ethpb.Attestation{
AggregationBits: bitfield.Bitlist{0b11011}, AggregationBits: bitfield.Bitlist{0b11011},
Data: &ethpb.AttestationData{Slot: 1}, Data: ad1,
}, },
want: false, want: false,
}, },
{ {
att: &ethpb.Attestation{ att: &ethpb.Attestation{
AggregationBits: bitfield.Bitlist{0b11011}, AggregationBits: bitfield.Bitlist{0b11011},
Data: &ethpb.AttestationData{Slot: 1}, Data: ad1,
}, },
want: true, // Exact same attestation should return true want: true, // Exact same attestation should return true
}, },
{ {
att: &ethpb.Attestation{ att: &ethpb.Attestation{
AggregationBits: bitfield.Bitlist{0b10101}, AggregationBits: bitfield.Bitlist{0b10101},
Data: &ethpb.AttestationData{Slot: 1}, Data: ad1,
}, },
want: false, // Haven't seen the bit at index 2 yet. want: false, // Haven't seen the bit at index 2 yet.
}, },
{ {
att: &ethpb.Attestation{ att: &ethpb.Attestation{
AggregationBits: bitfield.Bitlist{0b11111}, AggregationBits: bitfield.Bitlist{0b11111},
Data: &ethpb.AttestationData{Slot: 1}, Data: ad1,
}, },
want: true, // We've full committee at this point. want: true, // We've full committee at this point.
}, },
{ {
att: &ethpb.Attestation{ att: &ethpb.Attestation{
AggregationBits: bitfield.Bitlist{0b11111}, AggregationBits: bitfield.Bitlist{0b11111},
Data: &ethpb.AttestationData{Slot: 2}, Data: ad2,
}, },
want: false, // Different root is different bitlist. want: false, // Different root is different bitlist.
}, },
{ {
att: &ethpb.Attestation{ att: &ethpb.Attestation{
AggregationBits: bitfield.Bitlist{0b11111001}, AggregationBits: bitfield.Bitlist{0b11111001},
Data: &ethpb.AttestationData{Slot: 1}, Data: ad1,
}, },
want: false, // Sanity test that an attestation of different lengths does not panic. want: false, // Sanity test that an attestation of different lengths does not panic.
}, },
@@ -297,9 +339,11 @@ func TestService_seen(t *testing.T) {
s, err := NewService(context.Background(), &Config{Pool: NewPool()}) s, err := NewService(context.Background(), &Config{Pool: NewPool()})
require.NoError(t, err) require.NoError(t, err)
for _, tt := range tests { for i, tt := range tests {
got, err := s.seen(tt.att) t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
require.NoError(t, err) got, err := s.seen(tt.att)
assert.Equal(t, tt.want, got) require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
} }
} }

View File

@@ -24,15 +24,43 @@ func TestPruneExpired_Ticker(t *testing.T) {
}) })
require.NoError(t, err) require.NoError(t, err)
ad1 := &ethpb.AttestationData{
Slot: 0,
CommitteeIndex: 0,
BeaconBlockRoot: make([]byte, 32),
Source: &ethpb.Checkpoint{
Epoch: 0,
Root: make([]byte, 32),
},
Target: &ethpb.Checkpoint{
Epoch: 0,
Root: make([]byte, 32),
},
}
ad2 := &ethpb.AttestationData{
Slot: 1,
CommitteeIndex: 0,
BeaconBlockRoot: make([]byte, 32),
Source: &ethpb.Checkpoint{
Epoch: 0,
Root: make([]byte, 32),
},
Target: &ethpb.Checkpoint{
Epoch: 0,
Root: make([]byte, 32),
},
}
atts := []*ethpb.Attestation{ atts := []*ethpb.Attestation{
{Data: &ethpb.AttestationData{Slot: 0}, AggregationBits: bitfield.Bitlist{0b1000, 0b1}}, {Data: ad1, AggregationBits: bitfield.Bitlist{0b1000, 0b1}, Signature: make([]byte, 96)},
{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1000, 0b1}}, {Data: ad2, AggregationBits: bitfield.Bitlist{0b1000, 0b1}, Signature: make([]byte, 96)},
} }
require.NoError(t, s.pool.SaveUnaggregatedAttestations(atts)) require.NoError(t, s.pool.SaveUnaggregatedAttestations(atts))
require.Equal(t, 2, s.pool.UnaggregatedAttestationCount(), "Unexpected number of attestations") require.Equal(t, 2, s.pool.UnaggregatedAttestationCount(), "Unexpected number of attestations")
atts = []*ethpb.Attestation{ atts = []*ethpb.Attestation{
{Data: &ethpb.AttestationData{Slot: 0}, AggregationBits: bitfield.Bitlist{0b1101, 0b1}}, {Data: ad1, AggregationBits: bitfield.Bitlist{0b1101, 0b1}, Signature: make([]byte, 96)},
{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101, 0b1}}, {Data: ad2, AggregationBits: bitfield.Bitlist{0b1101, 0b1}, Signature: make([]byte, 96)},
} }
require.NoError(t, s.pool.SaveAggregatedAttestations(atts)) require.NoError(t, s.pool.SaveAggregatedAttestations(atts))
assert.Equal(t, 2, s.pool.AggregatedAttestationCount()) assert.Equal(t, 2, s.pool.AggregatedAttestationCount())
@@ -79,10 +107,38 @@ func TestPruneExpired_PruneExpiredAtts(t *testing.T) {
s, err := NewService(context.Background(), &Config{Pool: NewPool()}) s, err := NewService(context.Background(), &Config{Pool: NewPool()})
require.NoError(t, err) require.NoError(t, err)
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 0}, AggregationBits: bitfield.Bitlist{0b1101}} ad1 := &ethpb.AttestationData{
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 0}, AggregationBits: bitfield.Bitlist{0b1111}} Slot: 0,
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}} CommitteeIndex: 0,
att4 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1110}} BeaconBlockRoot: make([]byte, 32),
Source: &ethpb.Checkpoint{
Epoch: 0,
Root: make([]byte, 32),
},
Target: &ethpb.Checkpoint{
Epoch: 0,
Root: make([]byte, 32),
},
}
ad2 := &ethpb.AttestationData{
Slot: 0,
CommitteeIndex: 0,
BeaconBlockRoot: make([]byte, 32),
Source: &ethpb.Checkpoint{
Epoch: 0,
Root: make([]byte, 32),
},
Target: &ethpb.Checkpoint{
Epoch: 0,
Root: make([]byte, 32),
},
}
att1 := &ethpb.Attestation{Data: ad1, AggregationBits: bitfield.Bitlist{0b1101}}
att2 := &ethpb.Attestation{Data: ad1, AggregationBits: bitfield.Bitlist{0b1111}}
att3 := &ethpb.Attestation{Data: ad2, AggregationBits: bitfield.Bitlist{0b1101}}
att4 := &ethpb.Attestation{Data: ad2, AggregationBits: bitfield.Bitlist{0b1110}}
atts := []*ethpb.Attestation{att1, att2, att3, att4} atts := []*ethpb.Attestation{att1, att2, att3, att4}
require.NoError(t, s.pool.SaveAggregatedAttestations(atts)) require.NoError(t, s.pool.SaveAggregatedAttestations(atts))
require.NoError(t, s.pool.SaveBlockAttestations(atts)) require.NoError(t, s.pool.SaveBlockAttestations(atts))

View File

@@ -118,6 +118,7 @@ go_test(
"//beacon-chain/p2p/testing:go_default_library", "//beacon-chain/p2p/testing:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
"//proto/testing:go_default_library", "//proto/testing:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/featureconfig:go_default_library", "//shared/featureconfig:go_default_library",
"//shared/iputils:go_default_library", "//shared/iputils:go_default_library",
"//shared/p2putils:go_default_library", "//shared/p2putils:go_default_library",

View File

@@ -17,6 +17,7 @@ import (
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" 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/iputils"
"github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/assert"
@@ -215,7 +216,7 @@ func TestHostIsResolved(t *testing.T) {
HostDNS: exampleHost, HostDNS: exampleHost,
}, },
genesisTime: time.Now(), genesisTime: time.Now(),
genesisValidatorsRoot: []byte{'A'}, genesisValidatorsRoot: bytesutil.PadTo([]byte{'A'}, 32),
} }
ip, key := createAddrAndPrivKey(t) ip, key := createAddrAndPrivKey(t)
list, err := s.createListener(ip, key) list, err := s.createListener(ip, key)

View File

@@ -115,7 +115,9 @@ func TestStartDiscV5_DiscoverPeersWithSubnets(t *testing.T) {
// Update ENR of a peer. // Update ENR of a peer.
testService := &Service{ testService := &Service{
dv5Listener: listeners[0], dv5Listener: listeners[0],
metaData: &pb.MetaData{}, metaData: &pb.MetaData{
Attnets: bitfield.NewBitvector64(),
},
} }
cache.SubnetIDs.AddAttesterSubnetID(0, 10) cache.SubnetIDs.AddAttesterSubnetID(0, 10)
testService.RefreshENR() testService.RefreshENR()

View File

@@ -42,7 +42,6 @@ go_library(
"@com_github_prometheus_client_golang//prometheus:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto: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_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//:go_default_library",
"@io_k8s_client_go//tools/cache:go_default_library", "@io_k8s_client_go//tools/cache:go_default_library",
"@io_opencensus_go//trace:go_default_library", "@io_opencensus_go//trace:go_default_library",
@@ -85,7 +84,6 @@ go_test(
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library", "@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_ethereum_go_ethereum//core/types: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_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//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library", "@com_github_sirupsen_logrus//hooks/test:go_default_library",
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library", "@in_gopkg_d4l3k_messagediff_v1//:go_default_library",

View File

@@ -6,10 +6,10 @@ import (
"testing" "testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" 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/helpers"
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/assert"
@@ -81,9 +81,9 @@ func TestProcessDeposit_InvalidPublicKey(t *testing.T) {
deposits, _, err := testutil.DeterministicDepositsAndKeys(1) deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
require.NoError(t, err) require.NoError(t, err)
deposits[0].Data.PublicKey = []byte("junk") deposits[0].Data.PublicKey = bytesutil.PadTo([]byte("junk"), 48)
leaf, err := ssz.HashTreeRoot(deposits[0].Data) leaf, err := deposits[0].Data.HashTreeRoot()
require.NoError(t, err, "Could not hash deposit") require.NoError(t, err, "Could not hash deposit")
trie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, int(params.BeaconConfig().DepositContractTreeDepth)) 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'}) copy(fakeSig[:], []byte{'F', 'A', 'K', 'E'})
deposits[0].Data.Signature = fakeSig[:] deposits[0].Data.Signature = fakeSig[:]
leaf, err := ssz.HashTreeRoot(deposits[0].Data) leaf, err := deposits[0].Data.HashTreeRoot()
require.NoError(t, err, "Could not hash deposit") require.NoError(t, err, "Could not hash deposit")
trie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, int(params.BeaconConfig().DepositContractTreeDepth)) trie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, int(params.BeaconConfig().DepositContractTreeDepth))
@@ -186,7 +186,8 @@ func TestProcessDeposit_IncompleteDeposit(t *testing.T) {
deposit := &ethpb.Deposit{ deposit := &ethpb.Deposit{
Data: &ethpb.Deposit_Data{ Data: &ethpb.Deposit_Data{
Amount: params.BeaconConfig().EffectiveBalanceIncrement, // incomplete deposit Amount: params.BeaconConfig().EffectiveBalanceIncrement, // incomplete deposit
WithdrawalCredentials: []byte("testing"), WithdrawalCredentials: bytesutil.PadTo([]byte("testing"), 32),
Signature: bytesutil.PadTo([]byte("test"), 96),
}, },
} }
@@ -209,7 +210,7 @@ func TestProcessDeposit_IncompleteDeposit(t *testing.T) {
} }
proof, err := trie.MerkleProof(0) proof, err := trie.MerkleProof(0)
require.NoError(t, err) require.NoError(t, err)
dataRoot, err := ssz.HashTreeRoot(deposit.Data) dataRoot, err := deposit.Data.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
deposit.Proof = proof deposit.Proof = proof

View File

@@ -13,7 +13,6 @@ import (
gethTypes "github.com/ethereum/go-ethereum/core/types" gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/pkg/errors" "github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
@@ -135,7 +134,7 @@ func (s *Service) ProcessDepositLog(ctx context.Context, depositLog gethTypes.Lo
WithdrawalCredentials: withdrawalCredentials, WithdrawalCredentials: withdrawalCredentials,
} }
depositHash, err := ssz.HashTreeRoot(depositData) depositHash, err := depositData.HashTreeRoot()
if err != nil { if err != nil {
return errors.Wrap(err, "Unable to determine hashed value of deposit") return errors.Wrap(err, "Unable to determine hashed value of deposit")
} }

View File

@@ -92,7 +92,6 @@ go_test(
"//beacon-chain/p2p/testing:go_default_library", "//beacon-chain/p2p/testing:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library", "//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//beacon-chain/sync/initial-sync/testing:go_default_library", "//beacon-chain/sync/initial-sync/testing:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
"//shared/aggregation/attestations:go_default_library", "//shared/aggregation/attestations:go_default_library",
@@ -111,7 +110,6 @@ go_test(
"@com_github_golang_mock//gomock:go_default_library", "@com_github_golang_mock//gomock:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//: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", "@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
], ],
) )

View File

@@ -10,12 +10,10 @@ import (
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/cmd" "github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
@@ -55,9 +53,9 @@ func TestServer_ListAssignments_NoResults(t *testing.T) {
ctx := context.Background() ctx := context.Background()
st := testutil.NewBeaconState() st := testutil.NewBeaconState()
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
require.NoError(t, db.SaveState(ctx, st, gRoot)) require.NoError(t, db.SaveState(ctx, st, gRoot))
@@ -96,9 +94,9 @@ func TestServer_ListAssignments_Pagination_InputOutOfRange(t *testing.T) {
headState, err := db.HeadState(ctx) headState, err := db.HeadState(ctx)
require.NoError(t, err) require.NoError(t, err)
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
require.NoError(t, db.SaveState(ctx, headState, gRoot)) require.NoError(t, db.SaveState(ctx, headState, gRoot))
@@ -141,29 +139,30 @@ func TestServer_ListAssignments_Pagination_DefaultPageSize_NoArchive(t *testing.
validators := make([]*ethpb.Validator, 0, count) validators := make([]*ethpb.Validator, 0, count)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
pubKey := make([]byte, params.BeaconConfig().BLSPubkeyLength) pubKey := make([]byte, params.BeaconConfig().BLSPubkeyLength)
withdrawalCred := make([]byte, 32)
binary.LittleEndian.PutUint64(pubKey, uint64(i)) binary.LittleEndian.PutUint64(pubKey, uint64(i))
// Mark the validators with index divisible by 3 inactive. // Mark the validators with index divisible by 3 inactive.
if i%3 == 0 { if i%3 == 0 {
validators = append(validators, &ethpb.Validator{ validators = append(validators, &ethpb.Validator{
PublicKey: pubKey, PublicKey: pubKey,
ExitEpoch: 0, WithdrawalCredentials: withdrawalCred,
ActivationEpoch: 0, ExitEpoch: 0,
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance, ActivationEpoch: 0,
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
}) })
} else { } else {
validators = append(validators, &ethpb.Validator{ validators = append(validators, &ethpb.Validator{
PublicKey: pubKey, PublicKey: pubKey,
ExitEpoch: params.BeaconConfig().FarFutureEpoch, WithdrawalCredentials: withdrawalCred,
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance, ExitEpoch: params.BeaconConfig().FarFutureEpoch,
ActivationEpoch: 0, EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
ActivationEpoch: 0,
}) })
} }
} }
blk := &ethpb.BeaconBlock{ blk := testutil.NewBeaconBlock().Block
Slot: 0, blockRoot, err := blk.HashTreeRoot()
}
blockRoot, err := ssz.HashTreeRoot(blk)
require.NoError(t, err) require.NoError(t, err)
s := testutil.NewBeaconState() s := testutil.NewBeaconState()
@@ -221,16 +220,20 @@ func TestServer_ListAssignments_FilterPubkeysIndices_NoPagination(t *testing.T)
ctx := context.Background() ctx := context.Background()
count := 100 count := 100
validators := make([]*ethpb.Validator, 0, count) validators := make([]*ethpb.Validator, 0, count)
withdrawCreds := make([]byte, 32)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
pubKey := make([]byte, params.BeaconConfig().BLSPubkeyLength) pubKey := make([]byte, params.BeaconConfig().BLSPubkeyLength)
binary.LittleEndian.PutUint64(pubKey, uint64(i)) binary.LittleEndian.PutUint64(pubKey, uint64(i))
validators = append(validators, &ethpb.Validator{PublicKey: pubKey, ExitEpoch: params.BeaconConfig().FarFutureEpoch}) val := &ethpb.Validator{
PublicKey: pubKey,
WithdrawalCredentials: withdrawCreds,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
}
validators = append(validators, val)
} }
blk := &ethpb.BeaconBlock{ blk := testutil.NewBeaconBlock().Block
Slot: 0, blockRoot, err := blk.HashTreeRoot()
}
blockRoot, err := ssz.HashTreeRoot(blk)
require.NoError(t, err) require.NoError(t, err)
s := testutil.NewBeaconState() s := testutil.NewBeaconState()
require.NoError(t, s.SetValidators(validators)) require.NoError(t, s.SetValidators(validators))
@@ -285,16 +288,20 @@ func TestServer_ListAssignments_CanFilterPubkeysIndices_WithPagination(t *testin
ctx := context.Background() ctx := context.Background()
count := 100 count := 100
validators := make([]*ethpb.Validator, 0, count) validators := make([]*ethpb.Validator, 0, count)
withdrawCred := make([]byte, 32)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
pubKey := make([]byte, params.BeaconConfig().BLSPubkeyLength) pubKey := make([]byte, params.BeaconConfig().BLSPubkeyLength)
binary.LittleEndian.PutUint64(pubKey, uint64(i)) binary.LittleEndian.PutUint64(pubKey, uint64(i))
validators = append(validators, &ethpb.Validator{PublicKey: pubKey, ExitEpoch: params.BeaconConfig().FarFutureEpoch}) val := &ethpb.Validator{
PublicKey: pubKey,
WithdrawalCredentials: withdrawCred,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
}
validators = append(validators, val)
} }
blk := &ethpb.BeaconBlock{ blk := testutil.NewBeaconBlock().Block
Slot: 0, blockRoot, err := blk.HashTreeRoot()
}
blockRoot, err := ssz.HashTreeRoot(blk)
require.NoError(t, err) require.NoError(t, err)
s := testutil.NewBeaconState() s := testutil.NewBeaconState()
require.NoError(t, s.SetValidators(validators)) require.NoError(t, s.SetValidators(validators))

View File

@@ -12,7 +12,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed/operation" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/operation"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
attaggregation "github.com/prysmaticlabs/prysm/shared/aggregation/attestations" attaggregation "github.com/prysmaticlabs/prysm/shared/aggregation/attestations"
"github.com/prysmaticlabs/prysm/shared/attestationutil" "github.com/prysmaticlabs/prysm/shared/attestationutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
@@ -351,7 +350,7 @@ func (bs *Server) collectReceivedAttestations(ctx context.Context) {
bs.CollectedAttestationsBuffer <- atts bs.CollectedAttestationsBuffer <- atts
} }
case att := <-bs.ReceivedAttestationsBuffer: case att := <-bs.ReceivedAttestationsBuffer:
attDataRoot, err := stateutil.AttestationDataRoot(att.Data) attDataRoot, err := att.Data.HashTreeRoot()
if err != nil { if err != nil {
log.Errorf("Could not hash tree root data: %v", err) log.Errorf("Could not hash tree root data: %v", err)
continue continue

View File

@@ -22,7 +22,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations" "github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
attaggregation "github.com/prysmaticlabs/prysm/shared/aggregation/attestations" attaggregation "github.com/prysmaticlabs/prysm/shared/aggregation/attestations"
"github.com/prysmaticlabs/prysm/shared/attestationutil" "github.com/prysmaticlabs/prysm/shared/attestationutil"
@@ -88,7 +87,8 @@ func TestServer_ListAttestations_Genesis(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
att := &ethpb.Attestation{ att := &ethpb.Attestation{
Signature: make([]byte, 96), AggregationBits: bitfield.NewBitlist(0),
Signature: make([]byte, 96),
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Slot: 2, Slot: 2,
CommitteeIndex: 1, CommitteeIndex: 1,
@@ -99,17 +99,12 @@ func TestServer_ListAttestations_Genesis(t *testing.T) {
} }
parentRoot := [32]byte{1, 2, 3} parentRoot := [32]byte{1, 2, 3}
blk := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{ signedBlock := testutil.NewBeaconBlock()
Slot: 0, signedBlock.Block.ParentRoot = bytesutil.PadTo(parentRoot[:], 32)
ParentRoot: parentRoot[:], signedBlock.Block.Body.Attestations = []*ethpb.Attestation{att}
Body: &ethpb.BeaconBlockBody{ root, err := signedBlock.Block.HashTreeRoot()
Attestations: []*ethpb.Attestation{att},
},
},
}
root, err := stateutil.BlockRoot(blk.Block)
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveBlock(ctx, blk)) require.NoError(t, db.SaveBlock(ctx, signedBlock))
require.NoError(t, db.SaveGenesisBlockRoot(ctx, root)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, root))
wanted := &ethpb.ListAttestationsResponse{ wanted := &ethpb.ListAttestationsResponse{
Attestations: []*ethpb.Attestation{att}, Attestations: []*ethpb.Attestation{att},
@@ -127,7 +122,7 @@ func TestServer_ListAttestations_Genesis(t *testing.T) {
// Should throw an error if there is more than 1 block // Should throw an error if there is more than 1 block
// for the genesis slot. // for the genesis slot.
require.NoError(t, db.SaveBlock(ctx, blk)) require.NoError(t, db.SaveBlock(ctx, signedBlock))
if _, err := bs.ListAttestations(ctx, &ethpb.ListAttestationsRequest{ if _, err := bs.ListAttestations(ctx, &ethpb.ListAttestationsRequest{
QueryFilter: &ethpb.ListAttestationsRequest_GenesisEpoch{ QueryFilter: &ethpb.ListAttestationsRequest_GenesisEpoch{
GenesisEpoch: true, GenesisEpoch: true,
@@ -144,23 +139,17 @@ func TestServer_ListAttestations_NoPagination(t *testing.T) {
count := uint64(8) count := uint64(8)
atts := make([]*ethpb.Attestation, 0, count) atts := make([]*ethpb.Attestation, 0, count)
for i := uint64(0); i < count; i++ { for i := uint64(0); i < count; i++ {
blockExample := &ethpb.SignedBeaconBlock{ blockExample := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ blockExample.Block.Body.Attestations = []*ethpb.Attestation{
Slot: i, {
Body: &ethpb.BeaconBlockBody{ Signature: make([]byte, 96),
Attestations: []*ethpb.Attestation{ Data: &ethpb.AttestationData{
{ Target: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte("root"), 32)},
Signature: make([]byte, 96), Source: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte("root"), 32)},
Data: &ethpb.AttestationData{ BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32),
Target: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte("root"), 32)}, Slot: i,
Source: &ethpb.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)) require.NoError(t, db.SaveBlock(ctx, blockExample))
@@ -214,8 +203,14 @@ func TestServer_ListAttestations_FiltersCorrectly(t *testing.T) {
Slot: 3, Slot: 3,
}, },
AggregationBits: bitfield.Bitlist{0b11}, AggregationBits: bitfield.Bitlist{0b11},
Signature: bytesutil.PadTo([]byte("sig"), 96),
}, },
}, },
Eth1Data: &ethpb.Eth1Data{
DepositRoot: make([]byte, 32),
BlockHash: make([]byte, 32),
},
Graffiti: make([]byte, 32),
}, },
}, },
}, },
@@ -242,8 +237,14 @@ func TestServer_ListAttestations_FiltersCorrectly(t *testing.T) {
Slot: 4 + params.BeaconConfig().SlotsPerEpoch, Slot: 4 + params.BeaconConfig().SlotsPerEpoch,
}, },
AggregationBits: bitfield.Bitlist{0b11}, AggregationBits: bitfield.Bitlist{0b11},
Signature: bytesutil.PadTo([]byte("sig"), 96),
}, },
}, },
Eth1Data: &ethpb.Eth1Data{
DepositRoot: make([]byte, 32),
BlockHash: make([]byte, 32),
},
Graffiti: make([]byte, 32),
}, },
}, },
}, },
@@ -270,8 +271,14 @@ func TestServer_ListAttestations_FiltersCorrectly(t *testing.T) {
Slot: 4, Slot: 4,
}, },
AggregationBits: bitfield.Bitlist{0b11}, AggregationBits: bitfield.Bitlist{0b11},
Signature: bytesutil.PadTo([]byte("sig"), 96),
}, },
}, },
Eth1Data: &ethpb.Eth1Data{
DepositRoot: make([]byte, 32),
BlockHash: make([]byte, 32),
},
Graffiti: make([]byte, 32),
}, },
}, },
}, },
@@ -303,24 +310,19 @@ func TestServer_ListAttestations_Pagination_CustomPageParameters(t *testing.T) {
atts := make([]*ethpb.Attestation, 0, count) atts := make([]*ethpb.Attestation, 0, count)
for i := uint64(0); i < params.BeaconConfig().SlotsPerEpoch; i++ { for i := uint64(0); i < params.BeaconConfig().SlotsPerEpoch; i++ {
for s := uint64(0); s < 4; s++ { for s := uint64(0); s < 4; s++ {
blockExample := &ethpb.SignedBeaconBlock{ blockExample := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ blockExample.Block.Slot = i
Slot: i, blockExample.Block.Body.Attestations = []*ethpb.Attestation{
Body: &ethpb.BeaconBlockBody{ {
Attestations: []*ethpb.Attestation{ Data: &ethpb.AttestationData{
{ CommitteeIndex: s,
Data: &ethpb.AttestationData{ Slot: i,
CommitteeIndex: s, BeaconBlockRoot: make([]byte, 32),
Slot: i, Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
Target: &ethpb.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)) require.NoError(t, db.SaveBlock(ctx, blockExample))
@@ -422,17 +424,24 @@ func TestServer_ListAttestations_Pagination_OutOfRange(t *testing.T) {
ParentRoot: make([]byte, 32), ParentRoot: make([]byte, 32),
StateRoot: make([]byte, 32), StateRoot: make([]byte, 32),
Body: &ethpb.BeaconBlockBody{ Body: &ethpb.BeaconBlockBody{
Graffiti: make([]byte, 32),
RandaoReveal: make([]byte, 96), RandaoReveal: make([]byte, 96),
Attestations: []*ethpb.Attestation{ Attestations: []*ethpb.Attestation{
{ {
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32), BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32),
Slot: i, Slot: i,
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0b11}, AggregationBits: bitfield.Bitlist{0b11},
Signature: make([]byte, 96),
}, },
}, },
Eth1Data: &ethpb.Eth1Data{
DepositRoot: make([]byte, 32),
BlockHash: make([]byte, 32),
},
Graffiti: make([]byte, 32),
}, },
}, },
} }
@@ -474,26 +483,17 @@ func TestServer_ListAttestations_Pagination_DefaultPageSize(t *testing.T) {
count := uint64(params.BeaconConfig().DefaultPageSize) count := uint64(params.BeaconConfig().DefaultPageSize)
atts := make([]*ethpb.Attestation, 0, count) atts := make([]*ethpb.Attestation, 0, count)
for i := uint64(0); i < count; i++ { for i := uint64(0); i < count; i++ {
blockExample := &ethpb.SignedBeaconBlock{ blockExample := testutil.NewBeaconBlock()
Signature: make([]byte, 96), blockExample.Block.Body.Attestations = []*ethpb.Attestation{
Block: &ethpb.BeaconBlock{ {
ParentRoot: make([]byte, 32), Data: &ethpb.AttestationData{
StateRoot: make([]byte, 32), BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32),
Body: &ethpb.BeaconBlockBody{ Target: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte("root"), 32)},
RandaoReveal: make([]byte, 96), Source: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte("root"), 32)},
Attestations: []*ethpb.Attestation{ Slot: i,
{
Data: &ethpb.AttestationData{
BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32),
Target: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte("root"), 32)},
Source: &ethpb.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)) require.NoError(t, db.SaveBlock(ctx, blockExample))
@@ -567,27 +567,22 @@ func TestServer_ListIndexedAttestations_GenesisEpoch(t *testing.T) {
} else { } else {
targetRoot = targetRoot2 targetRoot = targetRoot2
} }
blockExample := &ethpb.SignedBeaconBlock{ blockExample := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ blockExample.Block.Body.Attestations = []*ethpb.Attestation{
Body: &ethpb.BeaconBlockBody{ {
Attestations: []*ethpb.Attestation{ Signature: make([]byte, 96),
{ Data: &ethpb.AttestationData{
Signature: make([]byte, 96), BeaconBlockRoot: make([]byte, 32),
Data: &ethpb.AttestationData{ Target: &ethpb.Checkpoint{
BeaconBlockRoot: make([]byte, 32), Root: targetRoot[:],
Target: &ethpb.Checkpoint{
Root: targetRoot[:],
},
Source: &ethpb.Checkpoint{
Root: make([]byte, 32),
},
Slot: i,
CommitteeIndex: 0,
},
AggregationBits: bitfield.Bitlist{0b11},
},
}, },
Source: &ethpb.Checkpoint{
Root: make([]byte, 32),
},
Slot: i,
CommitteeIndex: 0,
}, },
AggregationBits: bitfield.Bitlist{0b11},
}, },
} }
require.NoError(t, db.SaveBlock(ctx, blockExample)) require.NoError(t, db.SaveBlock(ctx, blockExample))
@@ -755,9 +750,36 @@ func TestServer_AttestationPool_Pagination_OutOfRange(t *testing.T) {
} }
atts := []*ethpb.Attestation{ atts := []*ethpb.Attestation{
{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}, {
{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}, Data: &ethpb.AttestationData{
{Data: &ethpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}, Slot: 1,
BeaconBlockRoot: bytesutil.PadTo([]byte{1}, 32),
Source: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte{1}, 32)},
Target: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte{1}, 32)},
},
AggregationBits: bitfield.Bitlist{0b1101},
Signature: bytesutil.PadTo([]byte{1}, 96),
},
{
Data: &ethpb.AttestationData{
Slot: 2,
BeaconBlockRoot: bytesutil.PadTo([]byte{2}, 32),
Source: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte{2}, 32)},
Target: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte{2}, 32)},
},
AggregationBits: bitfield.Bitlist{0b1101},
Signature: bytesutil.PadTo([]byte{2}, 96),
},
{
Data: &ethpb.AttestationData{
Slot: 3,
BeaconBlockRoot: bytesutil.PadTo([]byte{3}, 32),
Source: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte{3}, 32)},
Target: &ethpb.Checkpoint{Root: bytesutil.PadTo([]byte{3}, 32)},
},
AggregationBits: bitfield.Bitlist{0b1101},
Signature: bytesutil.PadTo([]byte{3}, 96),
},
} }
require.NoError(t, bs.AttestationsPool.SaveAggregatedAttestations(atts)) require.NoError(t, bs.AttestationsPool.SaveAggregatedAttestations(atts))
@@ -778,10 +800,9 @@ func TestServer_AttestationPool_Pagination_DefaultPageSize(t *testing.T) {
atts := make([]*ethpb.Attestation, params.BeaconConfig().DefaultPageSize+1) atts := make([]*ethpb.Attestation, params.BeaconConfig().DefaultPageSize+1)
for i := 0; i < len(atts); i++ { for i := 0; i < len(atts); i++ {
atts[i] = &ethpb.Attestation{ att := testutil.NewAttestation()
Data: &ethpb.AttestationData{Slot: uint64(i)}, att.Data.Slot = uint64(i)
AggregationBits: bitfield.Bitlist{0b1101}, atts[i] = att
}
} }
require.NoError(t, bs.AttestationsPool.SaveAggregatedAttestations(atts)) require.NoError(t, bs.AttestationsPool.SaveAggregatedAttestations(atts))
@@ -801,10 +822,9 @@ func TestServer_AttestationPool_Pagination_CustomPageSize(t *testing.T) {
numAtts := 100 numAtts := 100
atts := make([]*ethpb.Attestation, numAtts) atts := make([]*ethpb.Attestation, numAtts)
for i := 0; i < len(atts); i++ { for i := 0; i < len(atts); i++ {
atts[i] = &ethpb.Attestation{ att := testutil.NewAttestation()
Data: &ethpb.AttestationData{Slot: uint64(i)}, att.Data.Slot = uint64(i)
AggregationBits: bitfield.Bitlist{0b1101}, atts[i] = att
}
} }
require.NoError(t, bs.AttestationsPool.SaveAggregatedAttestations(atts)) require.NoError(t, bs.AttestationsPool.SaveAggregatedAttestations(atts))
tests := []struct { tests := []struct {
@@ -887,9 +907,9 @@ func TestServer_StreamIndexedAttestations_OK(t *testing.T) {
numValidators := 64 numValidators := 64
headState, privKeys := testutil.DeterministicGenesisState(t, uint64(numValidators)) headState, privKeys := testutil.DeterministicGenesisState(t, uint64(numValidators))
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
require.NoError(t, db.SaveState(ctx, headState, gRoot)) require.NoError(t, db.SaveState(ctx, headState, gRoot))
@@ -930,6 +950,10 @@ func TestServer_StreamIndexedAttestations_OK(t *testing.T) {
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32), BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32),
Slot: i, Slot: i,
Source: &ethpb.Checkpoint{
Epoch: 0,
Root: gRoot[:],
},
Target: &ethpb.Checkpoint{ Target: &ethpb.Checkpoint{
Epoch: 0, Epoch: 0,
Root: gRoot[:], Root: gRoot[:],
@@ -1053,9 +1077,9 @@ func TestServer_StreamAttestations_OnSlotTick(t *testing.T) {
} }
atts := []*ethpb.Attestation{ atts := []*ethpb.Attestation{
{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}, {Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}},
{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}, {Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}},
{Data: &ethpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}, {Data: &ethpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}},
} }
mockStream := mock.NewMockBeaconChain_StreamAttestationsServer(ctrl) mockStream := mock.NewMockBeaconChain_StreamAttestationsServer(ctrl)

View File

@@ -12,7 +12,6 @@ import (
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/cmd" "github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/pagination" "github.com/prysmaticlabs/prysm/shared/pagination"
@@ -59,7 +58,7 @@ func (bs *Server) ListBlocks(
returnedBlks := blks[start:end] returnedBlks := blks[start:end]
containers := make([]*ethpb.BeaconBlockContainer, len(returnedBlks)) containers := make([]*ethpb.BeaconBlockContainer, len(returnedBlks))
for i, b := range returnedBlks { for i, b := range returnedBlks {
root, err := stateutil.BlockRoot(b.Block) root, err := b.Block.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -86,7 +85,7 @@ func (bs *Server) ListBlocks(
NextPageToken: strconv.Itoa(0), NextPageToken: strconv.Itoa(0),
}, nil }, nil
} }
root, err := stateutil.BlockRoot(blk.Block) root, err := blk.Block.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -122,7 +121,7 @@ func (bs *Server) ListBlocks(
returnedBlks := blks[start:end] returnedBlks := blks[start:end]
containers := make([]*ethpb.BeaconBlockContainer, len(returnedBlks)) containers := make([]*ethpb.BeaconBlockContainer, len(returnedBlks))
for i, b := range returnedBlks { for i, b := range returnedBlks {
root, err := stateutil.BlockRoot(b.Block) root, err := b.Block.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -145,7 +144,7 @@ func (bs *Server) ListBlocks(
if genBlk == nil { if genBlk == nil {
return nil, status.Error(codes.Internal, "Could not find genesis block") return nil, status.Error(codes.Internal, "Could not find genesis block")
} }
root, err := stateutil.BlockRoot(genBlk.Block) root, err := genBlk.Block.HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -250,10 +249,10 @@ func (bs *Server) chainHeadRetrieval(ctx context.Context) (*ethpb.ChainHead, err
if err != nil { if err != nil {
return nil, status.Error(codes.Internal, "Could not get head block") return nil, status.Error(codes.Internal, "Could not get head block")
} }
if headBlock == nil { if headBlock == nil || headBlock.Block == nil {
return nil, status.Error(codes.Internal, "Head block of chain was nil") return nil, status.Error(codes.Internal, "Head block of chain was nil")
} }
headBlockRoot, err := stateutil.BlockRoot(headBlock.Block) headBlockRoot, err := headBlock.Block.HashTreeRoot()
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "Could not get head block root: %v", err) return nil, status.Errorf(codes.Internal, "Could not get head block root: %v", err)
} }

View File

@@ -17,7 +17,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/cmd" "github.com/prysmaticlabs/prysm/shared/cmd"
@@ -89,7 +88,7 @@ func TestServer_ListBlocks_Genesis(t *testing.T) {
parentRoot := [32]byte{'a'} parentRoot := [32]byte{'a'}
blk := testutil.NewBeaconBlock() blk := testutil.NewBeaconBlock()
blk.Block.ParentRoot = parentRoot[:] blk.Block.ParentRoot = parentRoot[:]
root, err := stateutil.BlockRoot(blk.Block) root, err := blk.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveBlock(ctx, blk)) require.NoError(t, db.SaveBlock(ctx, blk))
require.NoError(t, db.SaveGenesisBlockRoot(ctx, root)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, root))
@@ -123,13 +122,9 @@ func TestServer_ListBlocks_Genesis_MultiBlocks(t *testing.T) {
} }
// Should return the proper genesis block if it exists. // Should return the proper genesis block if it exists.
parentRoot := [32]byte{1, 2, 3} parentRoot := [32]byte{1, 2, 3}
blk := &ethpb.SignedBeaconBlock{ blk := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ blk.Block.ParentRoot = parentRoot[:]
Slot: 0, root, err := blk.Block.HashTreeRoot()
ParentRoot: parentRoot[:],
},
}
root, err := stateutil.BlockRoot(blk.Block)
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveBlock(ctx, blk)) require.NoError(t, db.SaveBlock(ctx, blk))
require.NoError(t, db.SaveGenesisBlockRoot(ctx, root)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, root))
@@ -138,12 +133,9 @@ func TestServer_ListBlocks_Genesis_MultiBlocks(t *testing.T) {
blks := make([]*ethpb.SignedBeaconBlock, count) blks := make([]*ethpb.SignedBeaconBlock, count)
blkContainers := make([]*ethpb.BeaconBlockContainer, count) blkContainers := make([]*ethpb.BeaconBlockContainer, count)
for i := uint64(0); i < count; i++ { for i := uint64(0); i < count; i++ {
b := &ethpb.SignedBeaconBlock{ b := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ b.Block.Slot = i
Slot: i, root, err := b.Block.HashTreeRoot()
},
}
root, err := stateutil.BlockRoot(b.Block)
require.NoError(t, err) require.NoError(t, err)
blks[i] = b blks[i] = b
blkContainers[i] = &ethpb.BeaconBlockContainer{Block: b, BlockRoot: root[:]} blkContainers[i] = &ethpb.BeaconBlockContainer{Block: b, BlockRoot: root[:]}
@@ -169,7 +161,7 @@ func TestServer_ListBlocks_Pagination(t *testing.T) {
for i := uint64(0); i < count; i++ { for i := uint64(0); i < count; i++ {
b := testutil.NewBeaconBlock() b := testutil.NewBeaconBlock()
b.Block.Slot = i b.Block.Slot = i
root, err := stateutil.BlockRoot(b.Block) root, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
blks[i] = b blks[i] = b
blkContainers[i] = &ethpb.BeaconBlockContainer{Block: b, BlockRoot: root[:]} blkContainers[i] = &ethpb.BeaconBlockContainer{Block: b, BlockRoot: root[:]}
@@ -180,7 +172,7 @@ func TestServer_ListBlocks_Pagination(t *testing.T) {
BeaconDB: db, BeaconDB: db,
} }
root6, err := stateutil.BlockRoot(blks[6].Block) root6, err := blks[6].Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
tests := []struct { tests := []struct {
@@ -338,24 +330,22 @@ func TestServer_ListBlocks_Errors(t *testing.T) {
func TestServer_GetChainHead_NoFinalizedBlock(t *testing.T) { func TestServer_GetChainHead_NoFinalizedBlock(t *testing.T) {
db, _ := dbTest.SetupDB(t) db, _ := dbTest.SetupDB(t)
s, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{ s := testutil.NewBeaconState()
Slot: 1, require.NoError(t, s.SetSlot(1))
PreviousJustifiedCheckpoint: &ethpb.Checkpoint{Epoch: 3, Root: []byte{'A'}}, require.NoError(t, s.SetPreviousJustifiedCheckpoint(&ethpb.Checkpoint{Epoch: 3, Root: bytesutil.PadTo([]byte{'A'}, 32)}))
CurrentJustifiedCheckpoint: &ethpb.Checkpoint{Epoch: 2, Root: []byte{'B'}}, require.NoError(t, s.SetCurrentJustifiedCheckpoint(&ethpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'B'}, 32)}))
FinalizedCheckpoint: &ethpb.Checkpoint{Epoch: 1, Root: []byte{'C'}}, require.NoError(t, s.SetFinalizedCheckpoint(&ethpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'C'}, 32)}))
})
require.NoError(t, err)
genBlock := testutil.NewBeaconBlock() genBlock := testutil.NewBeaconBlock()
genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32) genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32)
require.NoError(t, db.SaveBlock(context.Background(), genBlock)) require.NoError(t, db.SaveBlock(context.Background(), genBlock))
gRoot, err := stateutil.BlockRoot(genBlock.Block) gRoot, err := genBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(context.Background(), gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(context.Background(), gRoot))
bs := &Server{ bs := &Server{
BeaconDB: db, BeaconDB: db,
HeadFetcher: &chainMock.ChainService{Block: &ethpb.SignedBeaconBlock{}, State: s}, HeadFetcher: &chainMock.ChainService{Block: genBlock, State: s},
FinalizationFetcher: &chainMock.ChainService{ FinalizationFetcher: &chainMock.ChainService{
FinalizedCheckPoint: s.FinalizedCheckpoint(), FinalizedCheckPoint: s.FinalizedCheckpoint(),
CurrentJustifiedCheckPoint: s.CurrentJustifiedCheckpoint(), CurrentJustifiedCheckPoint: s.CurrentJustifiedCheckpoint(),
@@ -380,7 +370,7 @@ func TestServer_GetChainHead(t *testing.T) {
genBlock := testutil.NewBeaconBlock() genBlock := testutil.NewBeaconBlock()
genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32) genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32)
require.NoError(t, db.SaveBlock(context.Background(), genBlock)) require.NoError(t, db.SaveBlock(context.Background(), genBlock))
gRoot, err := stateutil.BlockRoot(genBlock.Block) gRoot, err := genBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(context.Background(), gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(context.Background(), gRoot))
@@ -388,21 +378,21 @@ func TestServer_GetChainHead(t *testing.T) {
finalizedBlock.Block.Slot = 1 finalizedBlock.Block.Slot = 1
finalizedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'A'}, 32) finalizedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'A'}, 32)
require.NoError(t, db.SaveBlock(context.Background(), finalizedBlock)) require.NoError(t, db.SaveBlock(context.Background(), finalizedBlock))
fRoot, err := stateutil.BlockRoot(finalizedBlock.Block) fRoot, err := finalizedBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
justifiedBlock := testutil.NewBeaconBlock() justifiedBlock := testutil.NewBeaconBlock()
justifiedBlock.Block.Slot = 2 justifiedBlock.Block.Slot = 2
justifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'B'}, 32) justifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'B'}, 32)
require.NoError(t, db.SaveBlock(context.Background(), justifiedBlock)) require.NoError(t, db.SaveBlock(context.Background(), justifiedBlock))
jRoot, err := stateutil.BlockRoot(justifiedBlock.Block) jRoot, err := justifiedBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
prevJustifiedBlock := testutil.NewBeaconBlock() prevJustifiedBlock := testutil.NewBeaconBlock()
prevJustifiedBlock.Block.Slot = 3 prevJustifiedBlock.Block.Slot = 3
prevJustifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'C'}, 32) prevJustifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'C'}, 32)
require.NoError(t, db.SaveBlock(context.Background(), prevJustifiedBlock)) require.NoError(t, db.SaveBlock(context.Background(), prevJustifiedBlock))
pjRoot, err := stateutil.BlockRoot(prevJustifiedBlock.Block) pjRoot, err := prevJustifiedBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
s, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{ s, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
@@ -413,7 +403,8 @@ func TestServer_GetChainHead(t *testing.T) {
}) })
require.NoError(t, err) require.NoError(t, err)
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: s.PreviousJustifiedCheckpoint().Epoch*params.BeaconConfig().SlotsPerEpoch + 1}} b := testutil.NewBeaconBlock()
b.Block.Slot = helpers.StartSlot(s.PreviousJustifiedCheckpoint().Epoch) + 1
bs := &Server{ bs := &Server{
BeaconDB: db, BeaconDB: db,
HeadFetcher: &chainMock.ChainService{Block: b, State: s}, HeadFetcher: &chainMock.ChainService{Block: b, State: s},
@@ -467,7 +458,7 @@ func TestServer_StreamChainHead_OnHeadUpdated(t *testing.T) {
genBlock := testutil.NewBeaconBlock() genBlock := testutil.NewBeaconBlock()
genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32) genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32)
require.NoError(t, db.SaveBlock(context.Background(), genBlock)) require.NoError(t, db.SaveBlock(context.Background(), genBlock))
gRoot, err := stateutil.BlockRoot(genBlock.Block) gRoot, err := genBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(context.Background(), gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(context.Background(), gRoot))
@@ -475,21 +466,21 @@ func TestServer_StreamChainHead_OnHeadUpdated(t *testing.T) {
finalizedBlock.Block.Slot = 32 finalizedBlock.Block.Slot = 32
finalizedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'A'}, 32) finalizedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'A'}, 32)
require.NoError(t, db.SaveBlock(context.Background(), finalizedBlock)) require.NoError(t, db.SaveBlock(context.Background(), finalizedBlock))
fRoot, err := stateutil.BlockRoot(finalizedBlock.Block) fRoot, err := finalizedBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
justifiedBlock := testutil.NewBeaconBlock() justifiedBlock := testutil.NewBeaconBlock()
justifiedBlock.Block.Slot = 64 justifiedBlock.Block.Slot = 64
justifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'B'}, 32) justifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'B'}, 32)
require.NoError(t, db.SaveBlock(context.Background(), justifiedBlock)) require.NoError(t, db.SaveBlock(context.Background(), justifiedBlock))
jRoot, err := stateutil.BlockRoot(justifiedBlock.Block) jRoot, err := justifiedBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
prevJustifiedBlock := testutil.NewBeaconBlock() prevJustifiedBlock := testutil.NewBeaconBlock()
prevJustifiedBlock.Block.Slot = 96 prevJustifiedBlock.Block.Slot = 96
prevJustifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'C'}, 32) prevJustifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'C'}, 32)
require.NoError(t, db.SaveBlock(context.Background(), prevJustifiedBlock)) require.NoError(t, db.SaveBlock(context.Background(), prevJustifiedBlock))
pjRoot, err := stateutil.BlockRoot(prevJustifiedBlock.Block) pjRoot, err := prevJustifiedBlock.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
s, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{ s, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
@@ -500,8 +491,9 @@ func TestServer_StreamChainHead_OnHeadUpdated(t *testing.T) {
}) })
require.NoError(t, err) require.NoError(t, err)
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: s.PreviousJustifiedCheckpoint().Epoch*params.BeaconConfig().SlotsPerEpoch + 1}} b := testutil.NewBeaconBlock()
hRoot, err := stateutil.BlockRoot(b.Block) b.Block.Slot = helpers.StartSlot(s.PreviousJustifiedCheckpoint().Epoch) + 1
hRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
chainService := &chainMock.ChainService{} chainService := &chainMock.ChainService{}

View File

@@ -15,7 +15,6 @@ import (
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
@@ -44,9 +43,9 @@ func TestServer_ListBeaconCommittees_CurrentEpoch(t *testing.T) {
GenesisTimeFetcher: m, GenesisTimeFetcher: m,
StateGen: stategen.New(db, sc), StateGen: stategen.New(db, sc),
} }
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
require.NoError(t, db.SaveState(ctx, headState, gRoot)) require.NoError(t, db.SaveState(ctx, headState, gRoot))
@@ -89,9 +88,9 @@ func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) {
require.NoError(t, headState.SetRandaoMixes(mixes)) require.NoError(t, headState.SetRandaoMixes(mixes))
require.NoError(t, headState.SetSlot(params.BeaconConfig().SlotsPerEpoch*2)) require.NoError(t, headState.SetSlot(params.BeaconConfig().SlotsPerEpoch*2))
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveState(ctx, headState, gRoot)) require.NoError(t, db.SaveState(ctx, headState, gRoot))
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
@@ -159,9 +158,9 @@ func TestRetrieveCommitteesForRoot(t *testing.T) {
GenesisTimeFetcher: m, GenesisTimeFetcher: m,
StateGen: stategen.New(db, sc), StateGen: stategen.New(db, sc),
} }
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
require.NoError(t, db.SaveState(ctx, headState, gRoot)) require.NoError(t, db.SaveState(ctx, headState, gRoot))

View File

@@ -14,7 +14,6 @@ import (
ptypes "github.com/gogo/protobuf/types" ptypes "github.com/gogo/protobuf/types"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/go-ssz"
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/cache" "github.com/prysmaticlabs/prysm/beacon-chain/cache"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute" "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
@@ -23,7 +22,6 @@ import (
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing" mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
@@ -101,9 +99,9 @@ func TestServer_ListValidatorBalances_NoResults(t *testing.T) {
} }
headState := testutil.NewBeaconState() headState := testutil.NewBeaconState()
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
require.NoError(t, db.SaveState(ctx, headState, gRoot)) require.NoError(t, db.SaveState(ctx, headState, gRoot))
@@ -151,9 +149,9 @@ func TestServer_ListValidatorBalances_DefaultResponse_NoArchive(t *testing.T) {
require.NoError(t, st.SetSlot(0)) require.NoError(t, st.SetSlot(0))
require.NoError(t, st.SetValidators(validators)) require.NoError(t, st.SetValidators(validators))
require.NoError(t, st.SetBalances(balances)) require.NoError(t, st.SetBalances(balances))
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
require.NoError(t, db.SaveState(ctx, st, gRoot)) require.NoError(t, db.SaveState(ctx, st, gRoot))
@@ -179,9 +177,9 @@ func TestServer_ListValidatorBalances_PaginationOutOfRange(t *testing.T) {
ctx := context.Background() ctx := context.Background()
setupValidators(t, db, 3) setupValidators(t, db, 3)
st := testutil.NewBeaconState() st := testutil.NewBeaconState()
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
require.NoError(t, db.SaveState(ctx, st, gRoot)) require.NoError(t, db.SaveState(ctx, st, gRoot))
@@ -228,8 +226,8 @@ func TestServer_ListValidatorBalances_Pagination_Default(t *testing.T) {
setupValidators(t, db, 100) setupValidators(t, db, 100)
headState, err := db.HeadState(context.Background()) headState, err := db.HeadState(context.Background())
require.NoError(t, err) require.NoError(t, err)
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
require.NoError(t, db.SaveState(ctx, headState, gRoot)) require.NoError(t, db.SaveState(ctx, headState, gRoot))
@@ -313,8 +311,8 @@ func TestServer_ListValidatorBalances_Pagination_CustomPageSizes(t *testing.T) {
setupValidators(t, db, count) setupValidators(t, db, count)
headState, err := db.HeadState(context.Background()) headState, err := db.HeadState(context.Background())
require.NoError(t, err) require.NoError(t, err)
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
require.NoError(t, db.SaveState(ctx, headState, gRoot)) require.NoError(t, db.SaveState(ctx, headState, gRoot))
@@ -384,8 +382,8 @@ func TestServer_ListValidatorBalances_OutOfRange(t *testing.T) {
headState, err := db.HeadState(context.Background()) headState, err := db.HeadState(context.Background())
require.NoError(t, err) require.NoError(t, err)
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
require.NoError(t, db.SaveState(ctx, headState, gRoot)) require.NoError(t, db.SaveState(ctx, headState, gRoot))
@@ -523,9 +521,9 @@ func TestServer_ListValidators_OnlyActiveValidators(t *testing.T) {
StateGen: stategen.New(db, cache.NewStateSummaryCache()), StateGen: stategen.New(db, cache.NewStateSummaryCache()),
} }
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
require.NoError(t, db.SaveState(ctx, st, gRoot)) require.NoError(t, db.SaveState(ctx, st, gRoot))
@@ -894,9 +892,9 @@ func TestServer_ListValidators_FromOldEpoch(t *testing.T) {
st := testutil.NewBeaconState() st := testutil.NewBeaconState()
require.NoError(t, st.SetSlot(helpers.StartSlot(30))) require.NoError(t, st.SetSlot(helpers.StartSlot(30)))
require.NoError(t, st.SetValidators(validators)) require.NoError(t, st.SetValidators(validators))
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveState(ctx, st, gRoot)) require.NoError(t, db.SaveState(ctx, st, gRoot))
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
@@ -960,9 +958,9 @@ func TestServer_ListValidators_ProcessHeadStateSlots(t *testing.T) {
require.NoError(t, st.SetSlot(headSlot)) require.NoError(t, st.SetSlot(headSlot))
require.NoError(t, st.SetValidators(validators)) require.NoError(t, st.SetValidators(validators))
require.NoError(t, st.SetBalances(balances)) require.NoError(t, st.SetBalances(balances))
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveState(ctx, st, gRoot)) require.NoError(t, db.SaveState(ctx, st, gRoot))
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
@@ -1114,17 +1112,17 @@ func TestServer_GetValidatorActiveSetChanges(t *testing.T) {
}) })
require.NoError(t, err) require.NoError(t, err)
} }
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{}} b := testutil.NewBeaconBlock()
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
require.NoError(t, db.SaveState(ctx, headState, gRoot)) require.NoError(t, db.SaveState(ctx, headState, gRoot))
bs := &Server{ bs := &Server{
FinalizationFetcher: &mock.ChainService{ FinalizationFetcher: &mock.ChainService{
FinalizedCheckPoint: &ethpb.Checkpoint{Epoch: 0}, FinalizedCheckPoint: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
}, },
GenesisTimeFetcher: &mock.ChainService{}, GenesisTimeFetcher: &mock.ChainService{},
StateGen: stategen.New(db, sc), StateGen: stategen.New(db, sc),
@@ -1224,19 +1222,19 @@ func TestServer_GetValidatorQueue_ExitedValidatorLeavesQueue(t *testing.T) {
ActivationEpoch: 0, ActivationEpoch: 0,
ExitEpoch: params.BeaconConfig().FarFutureEpoch, ExitEpoch: params.BeaconConfig().FarFutureEpoch,
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch, WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
PublicKey: []byte("1"), PublicKey: bytesutil.PadTo([]byte("1"), 48),
}, },
{ {
ActivationEpoch: 0, ActivationEpoch: 0,
ExitEpoch: 4, ExitEpoch: 4,
WithdrawableEpoch: 6, WithdrawableEpoch: 6,
PublicKey: []byte("2"), PublicKey: bytesutil.PadTo([]byte("2"), 48),
}, },
} }
headState := testutil.NewBeaconState() headState := testutil.NewBeaconState()
require.NoError(t, headState.SetValidators(validators)) require.NoError(t, headState.SetValidators(validators))
require.NoError(t, headState.SetFinalizedCheckpoint(&ethpb.Checkpoint{Epoch: 0})) require.NoError(t, headState.SetFinalizedCheckpoint(&ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)}))
bs := &Server{ bs := &Server{
HeadFetcher: &mock.ChainService{ HeadFetcher: &mock.ChainService{
State: headState, State: headState,
@@ -1247,7 +1245,7 @@ func TestServer_GetValidatorQueue_ExitedValidatorLeavesQueue(t *testing.T) {
res, err := bs.GetValidatorQueue(context.Background(), &ptypes.Empty{}) res, err := bs.GetValidatorQueue(context.Background(), &ptypes.Empty{})
require.NoError(t, err) require.NoError(t, err)
wanted := [][]byte{ wanted := [][]byte{
[]byte("2"), bytesutil.PadTo([]byte("2"), 48),
} }
activeValidatorCount, err := helpers.ActiveValidatorCount(headState, helpers.CurrentEpoch(headState)) activeValidatorCount, err := helpers.ActiveValidatorCount(headState, helpers.CurrentEpoch(headState))
require.NoError(t, err) require.NoError(t, err)
@@ -1359,22 +1357,37 @@ func TestServer_GetValidatorParticipation_PrevEpoch(t *testing.T) {
balances := make([]uint64, validatorCount) balances := make([]uint64, validatorCount)
for i := 0; i < len(validators); i++ { for i := 0; i < len(validators); i++ {
validators[i] = &ethpb.Validator{ validators[i] = &ethpb.Validator{
ExitEpoch: params.BeaconConfig().FarFutureEpoch, PublicKey: bytesutil.ToBytes(uint64(i), 48),
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance, WithdrawalCredentials: make([]byte, 32),
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
} }
balances[i] = params.BeaconConfig().MaxEffectiveBalance balances[i] = params.BeaconConfig().MaxEffectiveBalance
} }
atts := []*pbp2p.PendingAttestation{{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{}}, InclusionDelay: 1}} atts := []*pbp2p.PendingAttestation{{
Data: &ethpb.AttestationData{
BeaconBlockRoot: make([]byte, 32),
Source: &ethpb.Checkpoint{
Root: make([]byte, 32),
},
Target: &ethpb.Checkpoint{
Root: make([]byte, 32),
},
},
InclusionDelay: 1,
AggregationBits: bitfield.NewBitlist(2),
}}
headState := testutil.NewBeaconState() headState := testutil.NewBeaconState()
require.NoError(t, headState.SetSlot(params.BeaconConfig().SlotsPerEpoch*2-1)) require.NoError(t, headState.SetSlot(params.BeaconConfig().SlotsPerEpoch*2-1))
require.NoError(t, headState.SetValidators(validators)) require.NoError(t, headState.SetValidators(validators))
require.NoError(t, headState.SetBalances(balances)) require.NoError(t, headState.SetBalances(balances))
require.NoError(t, headState.SetPreviousEpochAttestations(atts)) require.NoError(t, headState.SetPreviousEpochAttestations(atts))
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: params.BeaconConfig().SlotsPerEpoch}} b := testutil.NewBeaconBlock()
b.Block.Slot = params.BeaconConfig().SlotsPerEpoch
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
bRoot, err := stateutil.BlockRoot(b.Block) bRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveState(ctx, headState, bRoot)) require.NoError(t, db.SaveState(ctx, headState, bRoot))
@@ -1402,9 +1415,10 @@ func TestServer_GetValidatorParticipation_DoesntExist(t *testing.T) {
headState := testutil.NewBeaconState() headState := testutil.NewBeaconState()
require.NoError(t, headState.SetSlot(params.BeaconConfig().SlotsPerEpoch*2-1)) require.NoError(t, headState.SetSlot(params.BeaconConfig().SlotsPerEpoch*2-1))
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: params.BeaconConfig().SlotsPerEpoch}} b := testutil.NewBeaconBlock()
b.Block.Slot = params.BeaconConfig().SlotsPerEpoch
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
bRoot, err := stateutil.BlockRoot(b.Block) bRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.SaveState(ctx, headState, bRoot)) require.NoError(t, db.SaveState(ctx, headState, bRoot))
@@ -1446,8 +1460,8 @@ func TestGetValidatorPerformance_OK(t *testing.T) {
for i := 0; i < len(atts); i++ { for i := 0; i < len(atts); i++ {
atts[i] = &pb.PendingAttestation{ atts[i] = &pb.PendingAttestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{}, Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
}, },
AggregationBits: bitfield.Bitlist{0xC0, 0xC0, 0xC0, 0xC0, 0x01}, AggregationBits: bitfield.Bitlist{0xC0, 0xC0, 0xC0, 0xC0, 0x01},
InclusionDelay: 1, InclusionDelay: 1,
@@ -1691,10 +1705,8 @@ func setupValidators(t testing.TB, db db.Database, count int) ([]*ethpb.Validato
WithdrawalCredentials: make([]byte, 32), WithdrawalCredentials: make([]byte, 32),
}) })
} }
blk := &ethpb.BeaconBlock{ blk := testutil.NewBeaconBlock().Block
Slot: 0, blockRoot, err := blk.HashTreeRoot()
}
blockRoot, err := ssz.HashTreeRoot(blk)
require.NoError(t, err) require.NoError(t, err)
s := testutil.NewBeaconState() s := testutil.NewBeaconState()
require.NoError(t, s.SetValidators(validators)) require.NoError(t, s.SetValidators(validators))
@@ -1735,7 +1747,7 @@ func TestServer_GetIndividualVotes_ValidatorsDontExist(t *testing.T) {
b := testutil.NewBeaconBlock() b := testutil.NewBeaconBlock()
b.Block.Slot = params.BeaconConfig().SlotsPerEpoch b.Block.Slot = params.BeaconConfig().SlotsPerEpoch
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
gen := stategen.New(db, sc) gen := stategen.New(db, sc)
require.NoError(t, gen.SaveState(ctx, gRoot, beaconState)) require.NoError(t, gen.SaveState(ctx, gRoot, beaconState))
@@ -1807,12 +1819,10 @@ func TestServer_GetIndividualVotes_Working(t *testing.T) {
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch)) require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch))
bf := []byte{0xff} bf := []byte{0xff}
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{ att1 := testutil.NewAttestation()
Target: &ethpb.Checkpoint{Epoch: 0}}, att1.AggregationBits = bf
AggregationBits: bf} att2 := testutil.NewAttestation()
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{ att2.AggregationBits = bf
Target: &ethpb.Checkpoint{Epoch: 0}},
AggregationBits: bf}
rt := [32]byte{'A'} rt := [32]byte{'A'}
att1.Data.Target.Root = rt[:] att1.Data.Target.Root = rt[:]
att1.Data.BeaconBlockRoot = rt[:] att1.Data.BeaconBlockRoot = rt[:]
@@ -1834,7 +1844,7 @@ func TestServer_GetIndividualVotes_Working(t *testing.T) {
b := testutil.NewBeaconBlock() b := testutil.NewBeaconBlock()
b.Block.Slot = params.BeaconConfig().SlotsPerEpoch b.Block.Slot = params.BeaconConfig().SlotsPerEpoch
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
gen := stategen.New(db, sc) gen := stategen.New(db, sc)
require.NoError(t, gen.SaveState(ctx, gRoot, beaconState)) require.NoError(t, gen.SaveState(ctx, gRoot, beaconState))
@@ -1870,10 +1880,12 @@ func TestServer_appendNonFinalizedBlockAttsToState(t *testing.T) {
e := uint64(1) e := uint64(1)
b1 := testutil.NewBeaconBlock() b1 := testutil.NewBeaconBlock()
b1.Block.Slot = e * params.BeaconConfig().SlotsPerEpoch b1.Block.Slot = e * params.BeaconConfig().SlotsPerEpoch
b1.Block.Body.Attestations = []*ethpb.Attestation{{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{Epoch: 1}}}} a1 := testutil.NewAttestation()
a1.Data.Target.Epoch = 1
b1.Block.Body.Attestations = []*ethpb.Attestation{a1}
b2 := testutil.NewBeaconBlock() b2 := testutil.NewBeaconBlock()
b2.Block.Slot = e*params.BeaconConfig().SlotsPerEpoch + 1 b2.Block.Slot = e*params.BeaconConfig().SlotsPerEpoch + 1
b2.Block.Body.Attestations = []*ethpb.Attestation{{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{Epoch: 1}}}} b2.Block.Body.Attestations = []*ethpb.Attestation{a1}
require.NoError(t, db.SaveBlock(ctx, b1)) require.NoError(t, db.SaveBlock(ctx, b1))
require.NoError(t, db.SaveBlock(ctx, b2)) require.NoError(t, db.SaveBlock(ctx, b2))
s := testutil.NewBeaconState() s := testutil.NewBeaconState()

View File

@@ -52,7 +52,6 @@ go_test(
"//beacon-chain/forkchoice/protoarray:go_default_library", "//beacon-chain/forkchoice/protoarray:go_default_library",
"//beacon-chain/p2p/testing:go_default_library", "//beacon-chain/p2p/testing:go_default_library",
"//beacon-chain/state/stategen:go_default_library", "//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//proto/beacon/rpc/v1:go_default_library", "//proto/beacon/rpc/v1:go_default_library",
"//shared/featureconfig:go_default_library", "//shared/featureconfig:go_default_library",
"//shared/params:go_default_library", "//shared/params:go_default_library",

View File

@@ -11,7 +11,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1" pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil"
@@ -22,11 +21,11 @@ import (
func TestServer_GetBlock(t *testing.T) { func TestServer_GetBlock(t *testing.T) {
db, _ := dbTest.SetupDB(t) db, _ := dbTest.SetupDB(t)
ctx := context.Background() ctx := context.Background()
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{
Slot: 100, b := testutil.NewBeaconBlock()
}} b.Block.Slot = 100
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
blockRoot, err := stateutil.BlockRoot(b.Block) blockRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
bs := &Server{ bs := &Server{
BeaconDB: db, BeaconDB: db,
@@ -66,19 +65,17 @@ func TestServer_GetAttestationInclusionSlot(t *testing.T) {
a := &ethpb.Attestation{ a := &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{Root: tr[:]}, Target: &ethpb.Checkpoint{Root: tr[:]},
Slot: 1, Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
Slot: 1,
}, },
AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
Signature: make([]byte, 96),
} }
b := &ethpb.SignedBeaconBlock{ b := testutil.NewBeaconBlock()
Block: &ethpb.BeaconBlock{ b.Block.Slot = 2
Slot: 2, b.Block.Body.Attestations = []*ethpb.Attestation{a}
Body: &ethpb.BeaconBlockBody{
Attestations: []*ethpb.Attestation{a},
},
},
}
require.NoError(t, bs.BeaconDB.SaveBlock(ctx, b)) require.NoError(t, bs.BeaconDB.SaveBlock(ctx, b))
res, err := bs.GetInclusionSlot(ctx, &pbrpc.InclusionSlotRequest{Slot: 1, Id: c[0]}) res, err := bs.GetInclusionSlot(ctx, &pbrpc.InclusionSlotRequest{Slot: 1, Id: c[0]})
require.NoError(t, err) require.NoError(t, err)

View File

@@ -4,11 +4,9 @@ import (
"context" "context"
"testing" "testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1" pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
"github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil"
@@ -25,11 +23,10 @@ func TestServer_GetBeaconState(t *testing.T) {
st := testutil.NewBeaconState() st := testutil.NewBeaconState()
slot := uint64(100) slot := uint64(100)
require.NoError(t, st.SetSlot(slot)) require.NoError(t, st.SetSlot(slot))
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{ b := testutil.NewBeaconBlock()
Slot: slot, b.Block.Slot = slot
}}
require.NoError(t, db.SaveBlock(ctx, b)) require.NoError(t, db.SaveBlock(ctx, b))
gRoot, err := stateutil.BlockRoot(b.Block) gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
gen := stategen.New(db, sc) gen := stategen.New(db, sc)
require.NoError(t, gen.SaveState(ctx, gRoot, st)) require.NoError(t, gen.SaveState(ctx, gRoot, st))

View File

@@ -34,7 +34,6 @@ go_library(
"//beacon-chain/powchain:go_default_library", "//beacon-chain/powchain:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library", "//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//beacon-chain/sync:go_default_library", "//beacon-chain/sync:go_default_library",
"//proto/beacon/db:go_default_library", "//proto/beacon/db:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
@@ -54,7 +53,6 @@ go_library(
"@com_github_gogo_protobuf//types:go_default_library", "@com_github_gogo_protobuf//types:go_default_library",
"@com_github_pkg_errors//:go_default_library", "@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1: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//:go_default_library",
"@io_opencensus_go//trace:go_default_library", "@io_opencensus_go//trace:go_default_library",
"@org_golang_google_grpc//codes:go_default_library", "@org_golang_google_grpc//codes:go_default_library",
@@ -93,7 +91,6 @@ go_test(
"//beacon-chain/powchain/testing:go_default_library", "//beacon-chain/powchain/testing:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library", "//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//beacon-chain/sync/initial-sync/testing:go_default_library", "//beacon-chain/sync/initial-sync/testing:go_default_library",
"//proto/beacon/db:go_default_library", "//proto/beacon/db:go_default_library",
"//proto/beacon/p2p/v1:go_default_library", "//proto/beacon/p2p/v1:go_default_library",
@@ -117,7 +114,6 @@ go_test(
"@com_github_golang_mock//gomock:go_default_library", "@com_github_golang_mock//gomock:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//: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//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library", "@com_github_sirupsen_logrus//hooks/test:go_default_library",
], ],

View File

@@ -218,11 +218,13 @@ func generateAtt(state *beaconstate.BeaconState, index uint64, privKeys []bls.Se
aggBits.SetBitAt(index+1, true) aggBits.SetBitAt(index+1, true)
att := &ethpb.Attestation{ att := &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
CommitteeIndex: 1, CommitteeIndex: 1,
Source: &ethpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]}, Source: &ethpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
}, },
AggregationBits: aggBits, AggregationBits: aggBits,
Signature: make([]byte, 96),
} }
committee, err := helpers.BeaconCommitteeFromState(state, att.Data.Slot, att.Data.CommitteeIndex) committee, err := helpers.BeaconCommitteeFromState(state, att.Data.Slot, att.Data.CommitteeIndex)
if err != nil { if err != nil {
@@ -256,11 +258,13 @@ func generateUnaggregatedAtt(state *beaconstate.BeaconState, index uint64, privK
aggBits.SetBitAt(index, true) aggBits.SetBitAt(index, true)
att := &ethpb.Attestation{ att := &ethpb.Attestation{
Data: &ethpb.AttestationData{ Data: &ethpb.AttestationData{
CommitteeIndex: 1, CommitteeIndex: 1,
Source: &ethpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]}, Source: &ethpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
Target: &ethpb.Checkpoint{Epoch: 0}, Target: &ethpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
}, },
AggregationBits: aggBits, AggregationBits: aggBits,
Signature: make([]byte, 96),
} }
committee, err := helpers.BeaconCommitteeFromState(state, att.Data.Slot, att.Data.CommitteeIndex) committee, err := helpers.BeaconCommitteeFromState(state, att.Data.Slot, att.Data.CommitteeIndex)
if err != nil { if err != nil {

View File

@@ -9,7 +9,6 @@ import (
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/cache" "github.com/prysmaticlabs/prysm/beacon-chain/cache"
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache" "github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
@@ -19,7 +18,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
dbutil "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" dbutil "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
mockPOW "github.com/prysmaticlabs/prysm/beacon-chain/powchain/testing" mockPOW "github.com/prysmaticlabs/prysm/beacon-chain/powchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing" mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/mock" "github.com/prysmaticlabs/prysm/shared/mock"
@@ -41,7 +39,7 @@ func TestGetDuties_NextEpoch_CantFindValidatorIdx(t *testing.T) {
beaconState, _ := testutil.DeterministicGenesisState(t, 10) beaconState, _ := testutil.DeterministicGenesisState(t, 10)
genesis := testutil.NewBeaconBlock() genesis := testutil.NewBeaconBlock()
genesisRoot, err := stateutil.BlockRoot(genesis.Block) genesisRoot, err := genesis.Block.HashTreeRoot()
require.NoError(t, err, "Could not get signing root") require.NoError(t, err, "Could not get signing root")
height := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix() height := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix()
@@ -87,7 +85,7 @@ func TestGetDuties_OK(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
bs, err := state.GenesisBeaconState(deposits, 0, eth1Data) bs, err := state.GenesisBeaconState(deposits, 0, eth1Data)
require.NoError(t, err, "Could not setup genesis bs") require.NoError(t, err, "Could not setup genesis bs")
genesisRoot, err := stateutil.BlockRoot(genesis.Block) genesisRoot, err := genesis.Block.HashTreeRoot()
require.NoError(t, err, "Could not get signing root") require.NoError(t, err, "Could not get signing root")
pubKeys := make([][]byte, len(deposits)) pubKeys := make([][]byte, len(deposits))
@@ -161,7 +159,7 @@ func TestGetDuties_CurrentEpoch_ShouldNotFail(t *testing.T) {
// Set state to non-epoch start slot. // Set state to non-epoch start slot.
require.NoError(t, bState.SetSlot(5)) require.NoError(t, bState.SetSlot(5))
genesisRoot, err := stateutil.BlockRoot(genesis.Block) genesisRoot, err := genesis.Block.HashTreeRoot()
require.NoError(t, err, "Could not get signing root") require.NoError(t, err, "Could not get signing root")
pubKeys := make([][48]byte, len(deposits)) pubKeys := make([][48]byte, len(deposits))
@@ -202,7 +200,7 @@ func TestGetDuties_MultipleKeys_OK(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
bs, err := state.GenesisBeaconState(deposits, 0, eth1Data) bs, err := state.GenesisBeaconState(deposits, 0, eth1Data)
require.NoError(t, err, "Could not setup genesis bs") require.NoError(t, err, "Could not setup genesis bs")
genesisRoot, err := stateutil.BlockRoot(genesis.Block) genesisRoot, err := genesis.Block.HashTreeRoot()
require.NoError(t, err, "Could not get signing root") require.NoError(t, err, "Could not get signing root")
pubKeys := make([][48]byte, len(deposits)) pubKeys := make([][48]byte, len(deposits))
@@ -265,7 +263,7 @@ func TestStreamDuties_OK(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
bs, err := state.GenesisBeaconState(deposits, 0, eth1Data) bs, err := state.GenesisBeaconState(deposits, 0, eth1Data)
require.NoError(t, err, "Could not setup genesis bs") require.NoError(t, err, "Could not setup genesis bs")
genesisRoot, err := ssz.HashTreeRoot(genesis.Block) genesisRoot, err := genesis.Block.HashTreeRoot()
require.NoError(t, err, "Could not get signing root") require.NoError(t, err, "Could not get signing root")
pubKeys := make([][]byte, len(deposits)) pubKeys := make([][]byte, len(deposits))
@@ -324,7 +322,7 @@ func TestStreamDuties_OK_ChainReorg(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
bs, err := state.GenesisBeaconState(deposits, 0, eth1Data) bs, err := state.GenesisBeaconState(deposits, 0, eth1Data)
require.NoError(t, err, "Could not setup genesis bs") require.NoError(t, err, "Could not setup genesis bs")
genesisRoot, err := ssz.HashTreeRoot(genesis.Block) genesisRoot, err := genesis.Block.HashTreeRoot()
require.NoError(t, err, "Could not get signing root") require.NoError(t, err, "Could not get signing root")
pubKeys := make([][]byte, len(deposits)) pubKeys := make([][]byte, len(deposits))
@@ -415,7 +413,7 @@ func BenchmarkCommitteeAssignment(b *testing.B) {
require.NoError(b, err) require.NoError(b, err)
bs, err := state.GenesisBeaconState(deposits, 0, eth1Data) bs, err := state.GenesisBeaconState(deposits, 0, eth1Data)
require.NoError(b, err, "Could not setup genesis bs") require.NoError(b, err, "Could not setup genesis bs")
genesisRoot, err := stateutil.BlockRoot(genesis.Block) genesisRoot, err := genesis.Block.HashTreeRoot()
require.NoError(b, err, "Could not get signing root") require.NoError(b, err, "Could not get signing root")
pubKeys := make([][48]byte, len(deposits)) pubKeys := make([][48]byte, len(deposits))

View File

@@ -12,7 +12,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/featureconfig"
@@ -146,7 +145,7 @@ func (vs *Server) ProposeAttestation(ctx context.Context, att *ethpb.Attestation
return nil, status.Error(codes.InvalidArgument, "Incorrect attestation signature") return nil, status.Error(codes.InvalidArgument, "Incorrect attestation signature")
} }
root, err := stateutil.AttestationDataRoot(att.Data) root, err := att.Data.HashTreeRoot()
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "Could not tree hash attestation: %v", err) return nil, status.Errorf(codes.Internal, "Could not tree hash attestation: %v", err)
} }

Some files were not shown because too many files have changed in this diff Show More