Skip to content

Commit

Permalink
upgraded prysm version
Browse files Browse the repository at this point in the history
  • Loading branch information
begmaroman committed Sep 4, 2021
1 parent 1186c41 commit 67874dd
Show file tree
Hide file tree
Showing 37 changed files with 1,381 additions and 1,139 deletions.
17 changes: 9 additions & 8 deletions beaconchain/beaconchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,35 @@ package beaconchain
import (
"context"

ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
types "github.com/prysmaticlabs/eth2-types"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
)

// SubnetSubscription contains data to subscribe on subnets
type SubnetSubscription struct {
ValidatorIndex uint64
CommitteeIndex uint64
ValidatorIndex types.ValidatorIndex
CommitteeIndex types.CommitteeIndex
CommitteesAtSlot uint64
Slot uint64
Slot types.Slot
IsAggregator bool
}

// BeaconChain represents beacon chain behavior
type BeaconChain interface {
// GetAttestationData returns attestation data by the given data
GetAttestationData(ctx context.Context, slot, committeeIndex uint64) (*ethpb.AttestationData, error)
GetAttestationData(ctx context.Context, slot types.Slot, committeeIndex types.CommitteeIndex) (*ethpb.AttestationData, error)

// ProposeAttestation proposed the given attestation
ProposeAttestation(ctx context.Context, data *ethpb.AttestationData, aggregationBits, signature []byte) error

// GetBlock returns block by the given request
GetBlock(ctx context.Context, slot uint64, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error)
GetBlock(ctx context.Context, slot types.Slot, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error)

// ProposeBlock proposes block
ProposeBlock(ctx context.Context, signature []byte, block *ethpb.BeaconBlock) error

// GetAggregateSelectionProof returns aggregated attestation
GetAggregateSelectionProof(ctx context.Context, slot, committeeIndex uint64, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error)
GetAggregateSelectionProof(ctx context.Context, slot types.Slot, committeeIndex types.CommitteeIndex, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error)

// SubmitSignedAggregateSelectionProof verifies given aggregate and proofs and publishes them on appropriate gossipsub topic
SubmitSignedAggregateSelectionProof(ctx context.Context, signature []byte, message *ethpb.AggregateAttestationAndProof) error
Expand All @@ -39,7 +40,7 @@ type BeaconChain interface {
SubnetsSubscribe(ctx context.Context, subscriptions []SubnetSubscription) error

// DomainData returns domain data by the given request
DomainData(ctx context.Context, epoch uint64, domain []byte) ([]byte, error)
DomainData(ctx context.Context, epoch types.Epoch, domain []byte) ([]byte, error)

// StreamDuties returns client to stream duties
StreamDuties(ctx context.Context, pubKeys [][]byte) (ethpb.BeaconNodeValidator_StreamDutiesClient, error)
Expand Down
11 changes: 6 additions & 5 deletions beaconchain/combined/combined.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (

"github.com/ethereum/go-ethereum/event"
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
types "github.com/prysmaticlabs/eth2-types"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"

"github.com/begmaroman/beaconspot/beaconchain"
)
Expand All @@ -25,7 +26,7 @@ func New(beaconChains ...beaconchain.BeaconChain) beaconchain.BeaconChain {
}

// GetAttestationData returns attestation data
func (c *combined) GetAttestationData(ctx context.Context, slot, index uint64) (*ethpb.AttestationData, error) {
func (c *combined) GetAttestationData(ctx context.Context, slot types.Slot, index types.CommitteeIndex) (*ethpb.AttestationData, error) {
type result struct {
attData *ethpb.AttestationData
err error
Expand Down Expand Up @@ -86,7 +87,7 @@ func (c *combined) ProposeAttestation(ctx context.Context, data *ethpb.Attestati
}

// GetBlock returns block by the given data
func (c *combined) GetBlock(ctx context.Context, slot uint64, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
func (c *combined) GetBlock(ctx context.Context, slot types.Slot, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
type result struct {
block *ethpb.BeaconBlock
err error
Expand Down Expand Up @@ -147,7 +148,7 @@ func (c *combined) ProposeBlock(ctx context.Context, signature []byte, block *et
}

// GetAggregateSelectionProof returns aggregated attestation
func (c *combined) GetAggregateSelectionProof(ctx context.Context, slot, committeeIndex uint64, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
func (c *combined) GetAggregateSelectionProof(ctx context.Context, slot types.Slot, committeeIndex types.CommitteeIndex, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
type result struct {
res *ethpb.AggregateAttestationAndProof
err error
Expand Down Expand Up @@ -233,7 +234,7 @@ func (c *combined) SubnetsSubscribe(ctx context.Context, subscriptions []beaconc
}

// DomainData returns domain data by the given request
func (c *combined) DomainData(ctx context.Context, epoch uint64, domain []byte) ([]byte, error) {
func (c *combined) DomainData(ctx context.Context, epoch types.Epoch, domain []byte) ([]byte, error) {
type result struct {
res []byte
err error
Expand Down
71 changes: 36 additions & 35 deletions beaconchain/combined/combined_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"testing"
"time"

ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
types "github.com/prysmaticlabs/eth2-types"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"

"github.com/begmaroman/beaconspot/beaconchain"
"github.com/begmaroman/beaconspot/beaconchain/mock"
Expand All @@ -19,8 +20,8 @@ func Test_combined_GetAttestationData(t *testing.T) {
}
type args struct {
ctx context.Context
slot uint64
index uint64
slot types.Slot
index types.CommitteeIndex
}
tests := []struct {
name string
Expand All @@ -34,23 +35,23 @@ func Test_combined_GetAttestationData(t *testing.T) {
fields: fields{
beaconChains: []beaconchain.BeaconChain{
&mock.BeaconChain{
GetAttestationDataFn: func(ctx context.Context, slot, index uint64) (*ethpb.AttestationData, error) {
GetAttestationDataFn: func(ctx context.Context, slot types.Slot, index types.CommitteeIndex) (*ethpb.AttestationData, error) {
time.Sleep(time.Second / 2)
return &ethpb.AttestationData{
Slot: 1,
}, nil
},
},
&mock.BeaconChain{
GetAttestationDataFn: func(ctx context.Context, slot, index uint64) (*ethpb.AttestationData, error) {
GetAttestationDataFn: func(ctx context.Context, slot types.Slot, index types.CommitteeIndex) (*ethpb.AttestationData, error) {
time.Sleep(time.Second / 4)
return &ethpb.AttestationData{
Slot: 2,
}, nil
},
},
&mock.BeaconChain{
GetAttestationDataFn: func(ctx context.Context, slot, index uint64) (*ethpb.AttestationData, error) {
GetAttestationDataFn: func(ctx context.Context, slot types.Slot, index types.CommitteeIndex) (*ethpb.AttestationData, error) {
return &ethpb.AttestationData{
Slot: 3,
}, nil
Expand All @@ -67,12 +68,12 @@ func Test_combined_GetAttestationData(t *testing.T) {
fields: fields{
beaconChains: []beaconchain.BeaconChain{
&mock.BeaconChain{
GetAttestationDataFn: func(ctx context.Context, slot, index uint64) (*ethpb.AttestationData, error) {
GetAttestationDataFn: func(ctx context.Context, slot types.Slot, index types.CommitteeIndex) (*ethpb.AttestationData, error) {
return nil, errors.New("test error")
},
},
&mock.BeaconChain{
GetAttestationDataFn: func(ctx context.Context, slot, index uint64) (*ethpb.AttestationData, error) {
GetAttestationDataFn: func(ctx context.Context, slot types.Slot, index types.CommitteeIndex) (*ethpb.AttestationData, error) {
return &ethpb.AttestationData{
Slot: 2,
}, nil
Expand All @@ -89,12 +90,12 @@ func Test_combined_GetAttestationData(t *testing.T) {
fields: fields{
beaconChains: []beaconchain.BeaconChain{
&mock.BeaconChain{
GetAttestationDataFn: func(ctx context.Context, slot, index uint64) (*ethpb.AttestationData, error) {
GetAttestationDataFn: func(ctx context.Context, slot types.Slot, index types.CommitteeIndex) (*ethpb.AttestationData, error) {
return nil, errors.New("test error 1")
},
},
&mock.BeaconChain{
GetAttestationDataFn: func(ctx context.Context, slot, index uint64) (*ethpb.AttestationData, error) {
GetAttestationDataFn: func(ctx context.Context, slot types.Slot, index types.CommitteeIndex) (*ethpb.AttestationData, error) {
return nil, errors.New("test error 2")
},
},
Expand Down Expand Up @@ -207,7 +208,7 @@ func Test_combined_GetBlock(t *testing.T) {
}
type args struct {
ctx context.Context
slot uint64
slot types.Slot
randaoReveal []byte
graffiti []byte
}
Expand All @@ -223,23 +224,23 @@ func Test_combined_GetBlock(t *testing.T) {
fields: fields{
beaconChains: []beaconchain.BeaconChain{
&mock.BeaconChain{
GetBlockFn: func(ctx context.Context, slot uint64, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
GetBlockFn: func(ctx context.Context, slot types.Slot, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
time.Sleep(time.Second / 2)
return &ethpb.BeaconBlock{
Slot: 1,
}, nil
},
},
&mock.BeaconChain{
GetBlockFn: func(ctx context.Context, slot uint64, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
GetBlockFn: func(ctx context.Context, slot types.Slot, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
time.Sleep(time.Second / 4)
return &ethpb.BeaconBlock{
Slot: 2,
}, nil
},
},
&mock.BeaconChain{
GetBlockFn: func(ctx context.Context, slot uint64, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
GetBlockFn: func(ctx context.Context, slot types.Slot, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
return &ethpb.BeaconBlock{
Slot: 3,
}, nil
Expand All @@ -256,12 +257,12 @@ func Test_combined_GetBlock(t *testing.T) {
fields: fields{
beaconChains: []beaconchain.BeaconChain{
&mock.BeaconChain{
GetBlockFn: func(ctx context.Context, slot uint64, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
GetBlockFn: func(ctx context.Context, slot types.Slot, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
return nil, errors.New("test error")
},
},
&mock.BeaconChain{
GetBlockFn: func(ctx context.Context, slot uint64, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
GetBlockFn: func(ctx context.Context, slot types.Slot, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
return &ethpb.BeaconBlock{
Slot: 2,
}, nil
Expand All @@ -278,12 +279,12 @@ func Test_combined_GetBlock(t *testing.T) {
fields: fields{
beaconChains: []beaconchain.BeaconChain{
&mock.BeaconChain{
GetBlockFn: func(ctx context.Context, slot uint64, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
GetBlockFn: func(ctx context.Context, slot types.Slot, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
return nil, errors.New("test error 1")
},
},
&mock.BeaconChain{
GetBlockFn: func(ctx context.Context, slot uint64, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
GetBlockFn: func(ctx context.Context, slot types.Slot, randaoReveal, graffiti []byte) (*ethpb.BeaconBlock, error) {
return nil, errors.New("test error 2")
},
},
Expand Down Expand Up @@ -395,8 +396,8 @@ func Test_combined_GetAggregateSelectionProof(t *testing.T) {
}
type args struct {
ctx context.Context
slot uint64
committeeIndex uint64
slot types.Slot
committeeIndex types.CommitteeIndex
publicKey []byte
sig []byte
}
Expand All @@ -412,23 +413,23 @@ func Test_combined_GetAggregateSelectionProof(t *testing.T) {
fields: fields{
beaconChains: []beaconchain.BeaconChain{
&mock.BeaconChain{
GetAggregateSelectionProofFn: func(ctx context.Context, slot, committeeIndex uint64, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
GetAggregateSelectionProofFn: func(ctx context.Context, slot types.Slot, committeeIndex types.CommitteeIndex, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
time.Sleep(time.Second / 2)
return &ethpb.AggregateAttestationAndProof{
AggregatorIndex: 1,
}, nil
},
},
&mock.BeaconChain{
GetAggregateSelectionProofFn: func(ctx context.Context, slot, committeeIndex uint64, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
GetAggregateSelectionProofFn: func(ctx context.Context, slot types.Slot, committeeIndex types.CommitteeIndex, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
time.Sleep(time.Second / 4)
return &ethpb.AggregateAttestationAndProof{
AggregatorIndex: 2,
}, nil
},
},
&mock.BeaconChain{
GetAggregateSelectionProofFn: func(ctx context.Context, slot, committeeIndex uint64, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
GetAggregateSelectionProofFn: func(ctx context.Context, slot types.Slot, committeeIndex types.CommitteeIndex, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
return &ethpb.AggregateAttestationAndProof{
AggregatorIndex: 3,
}, nil
Expand All @@ -445,12 +446,12 @@ func Test_combined_GetAggregateSelectionProof(t *testing.T) {
fields: fields{
beaconChains: []beaconchain.BeaconChain{
&mock.BeaconChain{
GetAggregateSelectionProofFn: func(ctx context.Context, slot, committeeIndex uint64, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
GetAggregateSelectionProofFn: func(ctx context.Context, slot types.Slot, committeeIndex types.CommitteeIndex, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
return nil, errors.New("test error")
},
},
&mock.BeaconChain{
GetAggregateSelectionProofFn: func(ctx context.Context, slot, committeeIndex uint64, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
GetAggregateSelectionProofFn: func(ctx context.Context, slot types.Slot, committeeIndex types.CommitteeIndex, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
return &ethpb.AggregateAttestationAndProof{
AggregatorIndex: 2,
}, nil
Expand All @@ -467,12 +468,12 @@ func Test_combined_GetAggregateSelectionProof(t *testing.T) {
fields: fields{
beaconChains: []beaconchain.BeaconChain{
&mock.BeaconChain{
GetAggregateSelectionProofFn: func(ctx context.Context, slot, committeeIndex uint64, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
GetAggregateSelectionProofFn: func(ctx context.Context, slot types.Slot, committeeIndex types.CommitteeIndex, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
return nil, errors.New("test error 1")
},
},
&mock.BeaconChain{
GetAggregateSelectionProofFn: func(ctx context.Context, slot, committeeIndex uint64, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
GetAggregateSelectionProofFn: func(ctx context.Context, slot types.Slot, committeeIndex types.CommitteeIndex, publicKey, sig []byte) (*ethpb.AggregateAttestationAndProof, error) {
return nil, errors.New("test error 2")
},
},
Expand Down Expand Up @@ -663,7 +664,7 @@ func Test_combined_DomainData(t *testing.T) {
}
type args struct {
ctx context.Context
epoch uint64
epoch types.Epoch
domain []byte
}
tests := []struct {
Expand All @@ -678,19 +679,19 @@ func Test_combined_DomainData(t *testing.T) {
fields: fields{
beaconChains: []beaconchain.BeaconChain{
&mock.BeaconChain{
DomainDataFn: func(ctx context.Context, epoch uint64, domain []byte) ([]byte, error) {
DomainDataFn: func(ctx context.Context, epoch types.Epoch, domain []byte) ([]byte, error) {
time.Sleep(time.Second / 2)
return []byte("1"), nil
},
},
&mock.BeaconChain{
DomainDataFn: func(ctx context.Context, epoch uint64, domain []byte) ([]byte, error) {
DomainDataFn: func(ctx context.Context, epoch types.Epoch, domain []byte) ([]byte, error) {
time.Sleep(time.Second / 4)
return []byte("2"), nil
},
},
&mock.BeaconChain{
DomainDataFn: func(ctx context.Context, epoch uint64, domain []byte) ([]byte, error) {
DomainDataFn: func(ctx context.Context, epoch types.Epoch, domain []byte) ([]byte, error) {
return []byte("3"), nil
},
},
Expand All @@ -703,12 +704,12 @@ func Test_combined_DomainData(t *testing.T) {
fields: fields{
beaconChains: []beaconchain.BeaconChain{
&mock.BeaconChain{
DomainDataFn: func(ctx context.Context, epoch uint64, domain []byte) ([]byte, error) {
DomainDataFn: func(ctx context.Context, epoch types.Epoch, domain []byte) ([]byte, error) {
return nil, errors.New("test error")
},
},
&mock.BeaconChain{
DomainDataFn: func(ctx context.Context, epoch uint64, domain []byte) ([]byte, error) {
DomainDataFn: func(ctx context.Context, epoch types.Epoch, domain []byte) ([]byte, error) {
return []byte("2"), nil
},
},
Expand All @@ -721,12 +722,12 @@ func Test_combined_DomainData(t *testing.T) {
fields: fields{
beaconChains: []beaconchain.BeaconChain{
&mock.BeaconChain{
DomainDataFn: func(ctx context.Context, epoch uint64, domain []byte) ([]byte, error) {
DomainDataFn: func(ctx context.Context, epoch types.Epoch, domain []byte) ([]byte, error) {
return nil, errors.New("test error 1")
},
},
&mock.BeaconChain{
DomainDataFn: func(ctx context.Context, epoch uint64, domain []byte) ([]byte, error) {
DomainDataFn: func(ctx context.Context, epoch types.Epoch, domain []byte) ([]byte, error) {
return nil, errors.New("test error 2")
},
},
Expand Down
2 changes: 1 addition & 1 deletion beaconchain/combined/stream_duties.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/ethereum/go-ethereum/event"
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"google.golang.org/grpc/metadata"
)

Expand Down
Loading

0 comments on commit 67874dd

Please sign in to comment.