mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
Use stateutil AttestationDataRoot instead of go-ssz (#6136)
* Change usages of ssz.HashTreeRoot(att.Data) to stateutil * Gaz * Tests * Imports * Merge branch 'master' into use-stateutil-attdata * Fix tests * Merge branch 'use-stateutil-attdata' of github.com:prysmaticlabs/prysm into use-stateutil-attdata * Merge refs/heads/master into use-stateutil-attdata * Merge refs/heads/master into use-stateutil-attdata
This commit is contained in:
@@ -39,6 +39,8 @@ func ComputeSigningRoot(object interface{}, domain []byte) ([32]byte, error) {
|
||||
switch object.(type) {
|
||||
case *ethpb.BeaconBlock:
|
||||
return stateutil.BlockRoot(object.(*ethpb.BeaconBlock))
|
||||
case *ethpb.AttestationData:
|
||||
return stateutil.AttestationDataRoot(object.(*ethpb.AttestationData))
|
||||
default:
|
||||
// utilise generic ssz library
|
||||
return ssz.HashTreeRoot(object)
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
dbpb "github.com/prysmaticlabs/prysm/proto/beacon/db"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/sliceutil"
|
||||
@@ -153,7 +153,7 @@ func (k *Store) SaveAttestation(ctx context.Context, att *ethpb.Attestation) err
|
||||
return err
|
||||
}
|
||||
|
||||
attDataRoot, err := ssz.HashTreeRoot(att.Data)
|
||||
attDataRoot, err := stateutil.AttestationDataRoot(att.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -196,7 +196,7 @@ func (k *Store) SaveAttestations(ctx context.Context, atts []*ethpb.Attestation)
|
||||
|
||||
err := k.db.Update(func(tx *bolt.Tx) error {
|
||||
for _, att := range atts {
|
||||
attDataRoot, err := ssz.HashTreeRoot(att.Data)
|
||||
attDataRoot, err := stateutil.AttestationDataRoot(att.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,21 +8,33 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
)
|
||||
|
||||
func TestStore_AttestationCRUD(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
att := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{Slot: 10},
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 10,
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b00000001, 0b1},
|
||||
}
|
||||
ctx := context.Background()
|
||||
attDataRoot, err := ssz.HashTreeRoot(att.Data)
|
||||
attDataRoot, err := stateutil.AttestationDataRoot(att.Data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -58,6 +70,7 @@ func TestStore_AttestationsBatchDelete(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
ctx := context.Background()
|
||||
numAtts := 10
|
||||
blockRoot := bytesutil.PadTo([]byte("head"), 32)
|
||||
totalAtts := make([]*ethpb.Attestation, numAtts)
|
||||
// We track the data roots for the even indexed attestations.
|
||||
attDataRoots := make([][32]byte, 0)
|
||||
@@ -65,13 +78,19 @@ func TestStore_AttestationsBatchDelete(t *testing.T) {
|
||||
for i := 0; i < len(totalAtts); i++ {
|
||||
totalAtts[i] = ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: []byte("head"),
|
||||
Slot: uint64(i),
|
||||
BeaconBlockRoot: blockRoot,
|
||||
Source: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b00000001, 0b1},
|
||||
}
|
||||
if i%2 == 0 {
|
||||
r, err := ssz.HashTreeRoot(totalAtts[i].Data)
|
||||
r, err := stateutil.AttestationDataRoot(totalAtts[i].Data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -83,7 +102,7 @@ func TestStore_AttestationsBatchDelete(t *testing.T) {
|
||||
if err := db.SaveAttestations(ctx, totalAtts); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
retrieved, err := db.Attestations(ctx, filters.NewFilter().SetHeadBlockRoot([]byte("head")))
|
||||
retrieved, err := db.Attestations(ctx, filters.NewFilter().SetHeadBlockRoot(blockRoot))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -95,7 +114,7 @@ func TestStore_AttestationsBatchDelete(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// When we retrieve the data, only the odd indexed attestations should remain.
|
||||
retrieved, err = db.Attestations(ctx, filters.NewFilter().SetHeadBlockRoot([]byte("head")))
|
||||
retrieved, err = db.Attestations(ctx, filters.NewFilter().SetHeadBlockRoot(blockRoot))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -114,14 +133,18 @@ func TestStore_BoltDontPanic(t *testing.T) {
|
||||
for i := 0; i <= 100; i++ {
|
||||
att := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: uint64(i),
|
||||
Source: ðpb.Checkpoint{},
|
||||
Target: ðpb.Checkpoint{},
|
||||
Slot: uint64(i),
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
}
|
||||
ctx := context.Background()
|
||||
attDataRoot, err := ssz.HashTreeRoot(att.Data)
|
||||
attDataRoot, err := stateutil.AttestationDataRoot(att.Data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -142,11 +165,19 @@ func TestStore_BoltDontPanic(t *testing.T) {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
att := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{Slot: uint64(startEpoch)},
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: uint64(startEpoch),
|
||||
BeaconBlockRoot: make([]byte, 32),
|
||||
Source: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32)},
|
||||
Target: ðpb.Checkpoint{
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
}
|
||||
ctx := context.Background()
|
||||
attDataRoot, err := ssz.HashTreeRoot(att.Data)
|
||||
attDataRoot, err := stateutil.AttestationDataRoot(att.Data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ go_library(
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/operations/attestations/kv:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//beacon-chain/state/stateutil:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/roughtime:go_default_library",
|
||||
@@ -26,7 +27,6 @@ go_library(
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@io_opencensus_go//trace:go_default_library",
|
||||
],
|
||||
|
||||
@@ -15,6 +15,7 @@ go_library(
|
||||
deps = [
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//beacon-chain/state/stateutil:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
)
|
||||
|
||||
// AggregateUnaggregatedAttestations aggregates the unaggregated attestations and save the
|
||||
@@ -16,7 +17,7 @@ func (p *AttCaches) AggregateUnaggregatedAttestations() error {
|
||||
attsByDataRoot := make(map[[32]byte][]*ethpb.Attestation)
|
||||
unaggregatedAtts := p.UnaggregatedAttestations()
|
||||
for _, att := range unaggregatedAtts {
|
||||
attDataRoot, err := ssz.HashTreeRoot(att.Data)
|
||||
attDataRoot, err := stateutil.AttestationDataRoot(att.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"go.opencensus.io/trace"
|
||||
@@ -62,7 +62,7 @@ func (s *Service) batchForkChoiceAtts(ctx context.Context) error {
|
||||
continue
|
||||
}
|
||||
|
||||
attDataRoot, err := ssz.HashTreeRoot(att.Data)
|
||||
attDataRoot, err := stateutil.AttestationDataRoot(att.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@ go_library(
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@org_golang_google_grpc//codes:go_default_library",
|
||||
"@org_golang_google_grpc//status:go_default_library",
|
||||
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
|
||||
ptypes "github.com/gogo/protobuf/types"
|
||||
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/operation"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/attestationutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
@@ -355,7 +355,7 @@ func (bs *Server) collectReceivedAttestations(ctx context.Context) {
|
||||
bs.CollectedAttestationsBuffer <- atts
|
||||
}
|
||||
case att := <-bs.ReceivedAttestationsBuffer:
|
||||
attDataRoot, err := ssz.HashTreeRoot(att.Data)
|
||||
attDataRoot, err := stateutil.AttestationDataRoot(att.Data)
|
||||
if err != nil {
|
||||
log.Errorf("Could not hash tree root data: %v", err)
|
||||
continue
|
||||
|
||||
@@ -5,13 +5,13 @@ import (
|
||||
|
||||
ptypes "github.com/gogo/protobuf/types"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed/operation"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/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/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
@@ -152,7 +152,7 @@ func (vs *Server) ProposeAttestation(ctx context.Context, att *ethpb.Attestation
|
||||
return nil, status.Error(codes.InvalidArgument, "Incorrect attestation signature")
|
||||
}
|
||||
|
||||
root, err := ssz.HashTreeRoot(att.Data)
|
||||
root, err := stateutil.AttestationDataRoot(att.Data)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not tree hash attestation: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user