mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 05:47:59 -05:00
Compare commits
7 Commits
v2.1.2
...
dynamic-co
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34c49e9fe8 | ||
|
|
38f99a4ff1 | ||
|
|
61033ebea1 | ||
|
|
e808025b17 | ||
|
|
7db0435ee0 | ||
|
|
1f086e4333 | ||
|
|
184e5be9de |
@@ -21,7 +21,7 @@ func testServiceOptsWithDB(t *testing.T) []Option {
|
||||
}
|
||||
}
|
||||
|
||||
// warning: only use these opts when you are certain there are no db calls
|
||||
// WARNING: only use these opts when you are certain there are no db calls
|
||||
// in your code path. this is a lightweight way to satisfy the stategen/beacondb
|
||||
// initialization requirements w/o the overhead of db init.
|
||||
func testServiceOptsNoDB() []Option {
|
||||
|
||||
@@ -176,7 +176,7 @@ func (s *Service) UpdateHead(ctx context.Context) error {
|
||||
|
||||
// This calls notify Forkchoice Update in the event that the head has changed
|
||||
func (s *Service) notifyEngineIfChangedHead(ctx context.Context, newHeadRoot [32]byte) {
|
||||
if s.headRoot() == newHeadRoot {
|
||||
if newHeadRoot == [32]byte{} || s.headRoot() == newHeadRoot {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -199,6 +199,11 @@ func TestNotifyEngineIfChangedHead(t *testing.T) {
|
||||
require.Equal(t, true, has)
|
||||
require.Equal(t, types.ValidatorIndex(1), vId)
|
||||
require.Equal(t, [8]byte{1}, payloadID)
|
||||
|
||||
// Test zero headRoot returns immediately.
|
||||
headRoot := service.headRoot()
|
||||
service.notifyEngineIfChangedHead(ctx, [32]byte{})
|
||||
require.Equal(t, service.headRoot(), headRoot)
|
||||
}
|
||||
|
||||
func TestService_ProcessAttestationsAndUpdateHead(t *testing.T) {
|
||||
|
||||
@@ -37,7 +37,7 @@ func newStateBalanceCache(sg *stategen.State) (*stateBalanceCache, error) {
|
||||
// the previously read value. This cache assumes we only want to cache one
|
||||
// set of balances for a single root (the current justified root).
|
||||
//
|
||||
// warning: this is not thread-safe on its own, relies on get() for locking
|
||||
// WARNING: this is not thread-safe on its own, relies on get() for locking
|
||||
func (c *stateBalanceCache) update(ctx context.Context, justifiedRoot [32]byte) ([]uint64, error) {
|
||||
stateBalanceCacheMiss.Inc()
|
||||
justifiedState, err := c.stateGen.StateByRoot(ctx, justifiedRoot)
|
||||
|
||||
@@ -203,3 +203,26 @@ func TestSetOptimisticToInvalid_ProposerBoost(t *testing.T) {
|
||||
require.DeepEqual(t, params.BeaconConfig().ZeroHash, f.store.previousProposerBoostRoot)
|
||||
f.store.proposerBoostLock.RUnlock()
|
||||
}
|
||||
|
||||
// This is a regression test (10565)
|
||||
// ----- C
|
||||
// /
|
||||
// A <- B
|
||||
// \
|
||||
// ----------D
|
||||
// D is invalid
|
||||
|
||||
func TestSetOptimisticToInvalid_CorrectChildren(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
f := setup(1, 1)
|
||||
|
||||
require.NoError(t, f.InsertOptimisticBlock(ctx, 100, [32]byte{'a'}, params.BeaconConfig().ZeroHash, [32]byte{'A'}, 1, 1))
|
||||
require.NoError(t, f.InsertOptimisticBlock(ctx, 101, [32]byte{'b'}, [32]byte{'a'}, [32]byte{'B'}, 1, 1))
|
||||
require.NoError(t, f.InsertOptimisticBlock(ctx, 102, [32]byte{'c'}, [32]byte{'a'}, [32]byte{'C'}, 1, 1))
|
||||
require.NoError(t, f.InsertOptimisticBlock(ctx, 103, [32]byte{'d'}, [32]byte{'a'}, [32]byte{'D'}, 1, 1))
|
||||
|
||||
_, err := f.store.setOptimisticToInvalid(ctx, [32]byte{'d'}, [32]byte{'a'}, [32]byte{'A'})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, len(f.store.nodeByRoot[[32]byte{'a'}].children))
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ func (f *ForkChoice) IsOptimistic(root [32]byte) (bool, error) {
|
||||
|
||||
// SetOptimisticToValid is called with the root of a block that was returned as
|
||||
// VALID by the EL.
|
||||
//
|
||||
// WARNING: This method returns an error if the root is not found in forkchoice
|
||||
func (f *ForkChoice) SetOptimisticToValid(ctx context.Context, root [32]byte) error {
|
||||
f.store.nodesLock.Lock()
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/cmd"
|
||||
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
@@ -117,7 +118,18 @@ func configureExecutionSetting(cliCtx *cli.Context) error {
|
||||
if !common.IsHexAddress(ha) {
|
||||
return fmt.Errorf("%s is not a valid fee recipient address", ha)
|
||||
}
|
||||
c.DefaultFeeRecipient = common.HexToAddress(ha)
|
||||
mixedcaseAddress, err := common.NewMixedcaseAddressFromString(ha)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not decode fee recipient %s", ha)
|
||||
}
|
||||
checksumAddress := common.HexToAddress(ha)
|
||||
if !mixedcaseAddress.ValidChecksum() {
|
||||
log.Warnf("Fee recipient %s is not a checksum Ethereum address. "+
|
||||
"The checksummed address is %s and will be used as the fee recipient. "+
|
||||
"We recommend using a mixed-case address (checksum) "+
|
||||
"to prevent spelling mistakes in your fee recipient Ethereum address", ha, checksumAddress.Hex())
|
||||
}
|
||||
c.DefaultFeeRecipient = checksumAddress
|
||||
params.OverrideBeaconConfig(c)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ func TestConfigureProofOfWork(t *testing.T) {
|
||||
|
||||
func TestConfigureExecutionSetting(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
hook := logTest.NewGlobal()
|
||||
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
@@ -102,11 +103,15 @@ func TestConfigureExecutionSetting(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, common.HexToAddress("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"), params.BeaconConfig().DefaultFeeRecipient)
|
||||
|
||||
require.NoError(t, set.Set(flags.SuggestedFeeRecipient.Name, "0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))
|
||||
assert.LogsContain(t, hook,
|
||||
"is not a checksum Ethereum address",
|
||||
)
|
||||
require.NoError(t, set.Set(flags.SuggestedFeeRecipient.Name, "0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa"))
|
||||
cliCtx = cli.NewContext(&app, set, nil)
|
||||
err = configureExecutionSetting(cliCtx)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, common.HexToAddress("0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"), params.BeaconConfig().DefaultFeeRecipient)
|
||||
assert.Equal(t, common.HexToAddress("0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa"), params.BeaconConfig().DefaultFeeRecipient)
|
||||
|
||||
}
|
||||
|
||||
func TestConfigureNetwork(t *testing.T) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
@@ -130,7 +131,7 @@ func (vs *Server) getExecutionPayload(ctx context.Context, slot types.Slot, vIdx
|
||||
if bytes.Equal(feeRecipient.Bytes(), burnAddr) {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"validatorIndex": vIdx,
|
||||
"burnAddress": burnAddr,
|
||||
"burnAddress": common.BytesToAddress(burnAddr).Hex(),
|
||||
}).Error("Fee recipient not set. Using burn address")
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -154,7 +154,8 @@ func (b *BeaconState) NumValidators() int {
|
||||
}
|
||||
|
||||
// ReadFromEveryValidator reads values from every validator and applies it to the provided function.
|
||||
// Warning: This method is potentially unsafe, as it exposes the actual validator registry.
|
||||
//
|
||||
// WARNING: This method is potentially unsafe, as it exposes the actual validator registry.
|
||||
func (b *BeaconState) ReadFromEveryValidator(f func(idx int, val state.ReadOnlyValidator) error) error {
|
||||
if b.validators == nil {
|
||||
return errors.New("nil validators in state")
|
||||
|
||||
@@ -541,6 +541,7 @@ func (b *BeaconState) HashTreeRoot(ctx context.Context) ([32]byte, error) {
|
||||
}
|
||||
|
||||
// Initializes the Merkle layers for the beacon state if they are empty.
|
||||
//
|
||||
// WARNING: Caller must acquire the mutex before using.
|
||||
func (b *BeaconState) initializeMerkleLayers(ctx context.Context) error {
|
||||
if len(b.merkleLayers) > 0 {
|
||||
@@ -565,6 +566,7 @@ func (b *BeaconState) initializeMerkleLayers(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// Recomputes the Merkle layers for the dirty fields in the state.
|
||||
//
|
||||
// WARNING: Caller must acquire the mutex before using.
|
||||
func (b *BeaconState) recomputeDirtyFields(ctx context.Context) error {
|
||||
for field := range b.dirtyFields {
|
||||
|
||||
@@ -174,7 +174,8 @@ func (b *BeaconState) NumValidators() int {
|
||||
}
|
||||
|
||||
// ReadFromEveryValidator reads values from every validator and applies it to the provided function.
|
||||
// Warning: This method is potentially unsafe, as it exposes the actual validator registry.
|
||||
//
|
||||
// WARNING: This method is potentially unsafe, as it exposes the actual validator registry.
|
||||
func (b *BeaconState) ReadFromEveryValidator(f func(idx int, val state.ReadOnlyValidator) error) error {
|
||||
if !b.hasInnerState() {
|
||||
return ErrNilInnerState
|
||||
|
||||
@@ -213,6 +213,7 @@ func (b *BeaconState) HashTreeRoot(ctx context.Context) ([32]byte, error) {
|
||||
}
|
||||
|
||||
// Initializes the Merkle layers for the beacon state if they are empty.
|
||||
//
|
||||
// WARNING: Caller must acquire the mutex before using.
|
||||
func (b *BeaconState) initializeMerkleLayers(ctx context.Context) error {
|
||||
if len(b.merkleLayers) > 0 {
|
||||
@@ -229,6 +230,7 @@ func (b *BeaconState) initializeMerkleLayers(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// Recomputes the Merkle layers for the dirty fields in the state.
|
||||
//
|
||||
// WARNING: Caller must acquire the mutex before using.
|
||||
func (b *BeaconState) recomputeDirtyFields(ctx context.Context) error {
|
||||
for field := range b.dirtyFields {
|
||||
|
||||
@@ -175,7 +175,8 @@ func (b *BeaconState) NumValidators() int {
|
||||
}
|
||||
|
||||
// ReadFromEveryValidator reads values from every validator and applies it to the provided function.
|
||||
// Warning: This method is potentially unsafe, as it exposes the actual validator registry.
|
||||
//
|
||||
// WARNING: This method is potentially unsafe, as it exposes the actual validator registry.
|
||||
func (b *BeaconState) ReadFromEveryValidator(f func(idx int, val state.ReadOnlyValidator) error) error {
|
||||
if !b.hasInnerState() {
|
||||
return ErrNilInnerState
|
||||
|
||||
@@ -218,6 +218,7 @@ func (b *BeaconState) HashTreeRoot(ctx context.Context) ([32]byte, error) {
|
||||
}
|
||||
|
||||
// Initializes the Merkle layers for the beacon state if they are empty.
|
||||
//
|
||||
// WARNING: Caller must acquire the mutex before using.
|
||||
func (b *BeaconState) initializeMerkleLayers(ctx context.Context) error {
|
||||
if len(b.merkleLayers) > 0 {
|
||||
@@ -234,6 +235,7 @@ func (b *BeaconState) initializeMerkleLayers(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// Recomputes the Merkle layers for the dirty fields in the state.
|
||||
//
|
||||
// WARNING: Caller must acquire the mutex before using.
|
||||
func (b *BeaconState) recomputeDirtyFields(ctx context.Context) error {
|
||||
for field := range b.dirtyFields {
|
||||
|
||||
@@ -175,7 +175,8 @@ func (b *BeaconState) NumValidators() int {
|
||||
}
|
||||
|
||||
// ReadFromEveryValidator reads values from every validator and applies it to the provided function.
|
||||
// Warning: This method is potentially unsafe, as it exposes the actual validator registry.
|
||||
//
|
||||
// WARNING: This method is potentially unsafe, as it exposes the actual validator registry.
|
||||
func (b *BeaconState) ReadFromEveryValidator(f func(idx int, val state.ReadOnlyValidator) error) error {
|
||||
if !b.hasInnerState() {
|
||||
return ErrNilInnerState
|
||||
|
||||
@@ -218,6 +218,7 @@ func (b *BeaconState) HashTreeRoot(ctx context.Context) ([32]byte, error) {
|
||||
}
|
||||
|
||||
// Initializes the Merkle layers for the beacon state if they are empty.
|
||||
//
|
||||
// WARNING: Caller must acquire the mutex before using.
|
||||
func (b *BeaconState) initializeMerkleLayers(ctx context.Context) error {
|
||||
if len(b.merkleLayers) > 0 {
|
||||
@@ -234,6 +235,7 @@ func (b *BeaconState) initializeMerkleLayers(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// Recomputes the Merkle layers for the dirty fields in the state.
|
||||
//
|
||||
// WARNING: Caller must acquire the mutex before using.
|
||||
func (b *BeaconState) recomputeDirtyFields(_ context.Context) error {
|
||||
for field := range b.dirtyFields {
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
package sync
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -13,41 +14,265 @@ import (
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
pb "github.com/libp2p/go-libp2p-pubsub/pb"
|
||||
gcache "github.com/patrickmn/go-cache"
|
||||
chainMock "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/signing"
|
||||
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/encoder"
|
||||
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
|
||||
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
||||
lruwrpr "github.com/prysmaticlabs/prysm/cache/lru"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/consensus-types/wrapper"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/testing/util"
|
||||
)
|
||||
|
||||
func FuzzValidateBeaconBlockPubSub(f *testing.F) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
func FuzzValidateBeaconBlockPubSub_Phase0(f *testing.F) {
|
||||
db := dbtest.SetupDB(f)
|
||||
p := p2ptest.NewFuzzTestP2P()
|
||||
ctx := context.Background()
|
||||
beaconState, privKeys := util.DeterministicGenesisState(f, 100)
|
||||
parentBlock := util.NewBeaconBlock()
|
||||
wsb, err := wrapper.WrappedSignedBeaconBlock(parentBlock)
|
||||
require.NoError(f, err)
|
||||
require.NoError(f, db.SaveBlock(ctx, wsb))
|
||||
bRoot, err := parentBlock.Block.HashTreeRoot()
|
||||
require.NoError(f, err)
|
||||
require.NoError(f, db.SaveState(ctx, beaconState, bRoot))
|
||||
require.NoError(f, db.SaveStateSummary(ctx, ðpb.StateSummary{Root: bRoot[:]}))
|
||||
copied := beaconState.Copy()
|
||||
require.NoError(f, copied.SetSlot(1))
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(ctx, copied)
|
||||
require.NoError(f, err)
|
||||
msg := util.NewBeaconBlock()
|
||||
msg.Block.ParentRoot = bRoot[:]
|
||||
msg.Block.Slot = 1
|
||||
msg.Block.ProposerIndex = proposerIdx
|
||||
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
|
||||
require.NoError(f, err)
|
||||
|
||||
stateGen := stategen.New(db)
|
||||
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
|
||||
State: beaconState,
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
DB: db,
|
||||
}
|
||||
r := &Service{
|
||||
cfg: &config{
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
chain: &chainMock.ChainService{},
|
||||
beaconDB: db,
|
||||
p2p: p,
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
chain: chainService,
|
||||
blockNotifier: chainService.BlockNotifier(),
|
||||
stateGen: stateGen,
|
||||
},
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
||||
seenBlockCache: lruwrpr.New(10),
|
||||
badBlockCache: lruwrpr.New(10),
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
}
|
||||
validTopic := fmt.Sprintf(p2p.BlockSubnetTopicFormat, []byte{0xb5, 0x30, 0x3f, 0x2a}) + "/" + encoder.ProtocolSuffixSSZSnappy
|
||||
f.Add("junk", []byte("junk"), []byte("junk"), []byte("junk"), []byte(validTopic), []byte("junk"), []byte("junk"))
|
||||
f.Fuzz(func(t *testing.T, pid string, from, data, seqno, topic, signature, key []byte) {
|
||||
buf := new(bytes.Buffer)
|
||||
_, err = p.Encoding().EncodeGossip(buf, msg)
|
||||
require.NoError(f, err)
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(msg)]
|
||||
digest, err := r.currentForkDigest()
|
||||
assert.NoError(f, err)
|
||||
topic = r.addDigestToTopic(topic, digest)
|
||||
|
||||
f.Add("junk", []byte("junk"), buf.Bytes(), []byte(topic))
|
||||
f.Fuzz(func(t *testing.T, pid string, from, data, topic []byte) {
|
||||
r.cfg.p2p = p2ptest.NewFuzzTestP2P()
|
||||
r.rateLimiter = newRateLimiter(r.cfg.p2p)
|
||||
cService := &mock.ChainService{
|
||||
Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot*10000000), 0),
|
||||
State: beaconState,
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
DB: db,
|
||||
}
|
||||
r.cfg.chain = cService
|
||||
r.cfg.blockNotifier = cService.BlockNotifier()
|
||||
strTop := string(topic)
|
||||
msg := &pubsub.Message{
|
||||
Message: &pb.Message{
|
||||
From: from,
|
||||
Data: data,
|
||||
Seqno: seqno,
|
||||
Topic: &strTop,
|
||||
Signature: signature,
|
||||
Key: key,
|
||||
From: from,
|
||||
Data: data,
|
||||
Topic: &strTop,
|
||||
},
|
||||
}
|
||||
_, err := r.validateBeaconBlockPubSub(ctx, peer.ID(pid), msg)
|
||||
_ = err
|
||||
})
|
||||
}
|
||||
|
||||
func FuzzValidateBeaconBlockPubSub_Altair(f *testing.F) {
|
||||
db := dbtest.SetupDB(f)
|
||||
p := p2ptest.NewFuzzTestP2P()
|
||||
ctx := context.Background()
|
||||
beaconState, privKeys := util.DeterministicGenesisStateAltair(f, 100)
|
||||
parentBlock := util.NewBeaconBlockAltair()
|
||||
wsb, err := wrapper.WrappedSignedBeaconBlock(parentBlock)
|
||||
require.NoError(f, err)
|
||||
require.NoError(f, db.SaveBlock(ctx, wsb))
|
||||
bRoot, err := parentBlock.Block.HashTreeRoot()
|
||||
require.NoError(f, err)
|
||||
require.NoError(f, db.SaveState(ctx, beaconState, bRoot))
|
||||
require.NoError(f, db.SaveStateSummary(ctx, ðpb.StateSummary{Root: bRoot[:]}))
|
||||
copied := beaconState.Copy()
|
||||
require.NoError(f, copied.SetSlot(1))
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(ctx, copied)
|
||||
require.NoError(f, err)
|
||||
msg := util.NewBeaconBlock()
|
||||
msg.Block.ParentRoot = bRoot[:]
|
||||
msg.Block.Slot = 1
|
||||
msg.Block.ProposerIndex = proposerIdx
|
||||
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
|
||||
require.NoError(f, err)
|
||||
|
||||
stateGen := stategen.New(db)
|
||||
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
|
||||
State: beaconState,
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
DB: db,
|
||||
}
|
||||
r := &Service{
|
||||
cfg: &config{
|
||||
beaconDB: db,
|
||||
p2p: p,
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
chain: chainService,
|
||||
blockNotifier: chainService.BlockNotifier(),
|
||||
stateGen: stateGen,
|
||||
},
|
||||
seenBlockCache: lruwrpr.New(10),
|
||||
badBlockCache: lruwrpr.New(10),
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
_, err = p.Encoding().EncodeGossip(buf, msg)
|
||||
require.NoError(f, err)
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(msg)]
|
||||
digest, err := r.currentForkDigest()
|
||||
assert.NoError(f, err)
|
||||
topic = r.addDigestToTopic(topic, digest)
|
||||
|
||||
f.Add("junk", []byte("junk"), buf.Bytes(), []byte(topic))
|
||||
f.Fuzz(func(t *testing.T, pid string, from, data, topic []byte) {
|
||||
r.cfg.p2p = p2ptest.NewFuzzTestP2P()
|
||||
r.rateLimiter = newRateLimiter(r.cfg.p2p)
|
||||
cService := &mock.ChainService{
|
||||
Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot*10000000), 0),
|
||||
State: beaconState,
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
DB: db,
|
||||
}
|
||||
r.cfg.chain = cService
|
||||
r.cfg.blockNotifier = cService.BlockNotifier()
|
||||
strTop := string(topic)
|
||||
msg := &pubsub.Message{
|
||||
Message: &pb.Message{
|
||||
From: from,
|
||||
Data: data,
|
||||
Topic: &strTop,
|
||||
},
|
||||
}
|
||||
_, err := r.validateBeaconBlockPubSub(ctx, peer.ID(pid), msg)
|
||||
_ = err
|
||||
})
|
||||
}
|
||||
|
||||
func FuzzValidateBeaconBlockPubSub_Bellatrix(f *testing.F) {
|
||||
db := dbtest.SetupDB(f)
|
||||
p := p2ptest.NewFuzzTestP2P()
|
||||
ctx := context.Background()
|
||||
beaconState, privKeys := util.DeterministicGenesisStateBellatrix(f, 100)
|
||||
parentBlock := util.NewBeaconBlockBellatrix()
|
||||
wsb, err := wrapper.WrappedSignedBeaconBlock(parentBlock)
|
||||
require.NoError(f, err)
|
||||
require.NoError(f, db.SaveBlock(ctx, wsb))
|
||||
bRoot, err := parentBlock.Block.HashTreeRoot()
|
||||
require.NoError(f, err)
|
||||
require.NoError(f, db.SaveState(ctx, beaconState, bRoot))
|
||||
require.NoError(f, db.SaveStateSummary(ctx, ðpb.StateSummary{Root: bRoot[:]}))
|
||||
copied := beaconState.Copy()
|
||||
require.NoError(f, copied.SetSlot(1))
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(ctx, copied)
|
||||
require.NoError(f, err)
|
||||
msg := util.NewBeaconBlock()
|
||||
msg.Block.ParentRoot = bRoot[:]
|
||||
msg.Block.Slot = 1
|
||||
msg.Block.ProposerIndex = proposerIdx
|
||||
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
|
||||
require.NoError(f, err)
|
||||
|
||||
stateGen := stategen.New(db)
|
||||
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
|
||||
State: beaconState,
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
DB: db,
|
||||
}
|
||||
r := &Service{
|
||||
cfg: &config{
|
||||
beaconDB: db,
|
||||
p2p: p,
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
chain: chainService,
|
||||
blockNotifier: chainService.BlockNotifier(),
|
||||
stateGen: stateGen,
|
||||
},
|
||||
seenBlockCache: lruwrpr.New(10),
|
||||
badBlockCache: lruwrpr.New(10),
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
_, err = p.Encoding().EncodeGossip(buf, msg)
|
||||
require.NoError(f, err)
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(msg)]
|
||||
digest, err := r.currentForkDigest()
|
||||
assert.NoError(f, err)
|
||||
topic = r.addDigestToTopic(topic, digest)
|
||||
|
||||
f.Add("junk", []byte("junk"), buf.Bytes(), []byte(topic))
|
||||
f.Fuzz(func(t *testing.T, pid string, from, data, topic []byte) {
|
||||
r.cfg.p2p = p2ptest.NewFuzzTestP2P()
|
||||
r.rateLimiter = newRateLimiter(r.cfg.p2p)
|
||||
cService := &mock.ChainService{
|
||||
Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot*10000000), 0),
|
||||
State: beaconState,
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
Root: make([]byte, 32),
|
||||
},
|
||||
DB: db,
|
||||
}
|
||||
r.cfg.chain = cService
|
||||
r.cfg.blockNotifier = cService.BlockNotifier()
|
||||
strTop := string(topic)
|
||||
msg := &pubsub.Message{
|
||||
Message: &pb.Message{
|
||||
From: from,
|
||||
Data: data,
|
||||
Topic: &strTop,
|
||||
},
|
||||
}
|
||||
_, err := r.validateBeaconBlockPubSub(ctx, peer.ID(pid), msg)
|
||||
|
||||
@@ -25,6 +25,7 @@ go_library(
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//math:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//params:go_default_library",
|
||||
"@com_github_mohae_deepcopy//:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
)
|
||||
|
||||
@@ -75,7 +76,7 @@ var mainnetBeaconConfig = &BeaconChainConfig{
|
||||
FarFutureSlot: math.MaxUint64,
|
||||
BaseRewardsPerEpoch: 4,
|
||||
DepositContractTreeDepth: 32,
|
||||
GenesisDelay: 604800, // 1 week.
|
||||
GenesisDelay: 300, // 1 week.
|
||||
|
||||
// Misc constant.
|
||||
TargetCommitteeSize: 128,
|
||||
@@ -84,8 +85,8 @@ var mainnetBeaconConfig = &BeaconChainConfig{
|
||||
MinPerEpochChurnLimit: 4,
|
||||
ChurnLimitQuotient: 1 << 16,
|
||||
ShuffleRoundCount: 90,
|
||||
MinGenesisActiveValidatorCount: 16384,
|
||||
MinGenesisTime: 1606824000, // Dec 1, 2020, 12pm UTC.
|
||||
MinGenesisActiveValidatorCount: 95000,
|
||||
MinGenesisTime: 1647007200, // Dec 1, 2020, 12pm UTC.
|
||||
TargetAggregatorsPerCommittee: 16,
|
||||
HysteresisQuotient: 4,
|
||||
HysteresisDownwardMultiplier: 1,
|
||||
@@ -113,7 +114,7 @@ var mainnetBeaconConfig = &BeaconChainConfig{
|
||||
MinValidatorWithdrawabilityDelay: 256,
|
||||
ShardCommitteePeriod: 256,
|
||||
MinEpochsToInactivityPenalty: 4,
|
||||
Eth1FollowDistance: 2048,
|
||||
Eth1FollowDistance: 16,
|
||||
SafeSlotsToUpdateJustified: 8,
|
||||
|
||||
// Fork choice algorithm constants.
|
||||
@@ -121,9 +122,9 @@ var mainnetBeaconConfig = &BeaconChainConfig{
|
||||
IntervalsPerSlot: 3,
|
||||
|
||||
// Ethereum PoW parameters.
|
||||
DepositChainID: 1, // Chain ID of eth1 mainnet.
|
||||
DepositNetworkID: 1, // Network ID of eth1 mainnet.
|
||||
DepositContractAddress: "0x00000000219ab540356cBB839Cbe05303d7705Fa",
|
||||
DepositChainID: 1337802, // Chain ID of eth1 mainnet.
|
||||
DepositNetworkID: 1337802, // Network ID of eth1 mainnet.
|
||||
DepositContractAddress: "0x4242424242424242424242424242424242424242",
|
||||
|
||||
// Validator params.
|
||||
RandomSubnetsPerValidator: 1 << 0,
|
||||
@@ -183,7 +184,7 @@ var mainnetBeaconConfig = &BeaconChainConfig{
|
||||
MaxPeersToSync: 15,
|
||||
SlotsPerArchivedPoint: 2048,
|
||||
GenesisCountdownInterval: time.Minute,
|
||||
ConfigName: MainnetName,
|
||||
ConfigName: "kiln",
|
||||
PresetBase: "mainnet",
|
||||
BeaconStateFieldCount: 21,
|
||||
BeaconStateAltairFieldCount: 24,
|
||||
@@ -199,11 +200,11 @@ var mainnetBeaconConfig = &BeaconChainConfig{
|
||||
|
||||
// Fork related values.
|
||||
GenesisEpoch: genesisForkEpoch,
|
||||
GenesisForkVersion: []byte{0, 0, 0, 0},
|
||||
AltairForkVersion: []byte{1, 0, 0, 0},
|
||||
AltairForkEpoch: mainnetAltairForkEpoch,
|
||||
BellatrixForkVersion: []byte{2, 0, 0, 0},
|
||||
BellatrixForkEpoch: mainnetBellatrixForkEpoch,
|
||||
GenesisForkVersion: hexutil.MustDecode("0x70000069"),
|
||||
AltairForkVersion: hexutil.MustDecode("0x70000070"),
|
||||
AltairForkEpoch: 50,
|
||||
BellatrixForkVersion: hexutil.MustDecode("0x70000071"),
|
||||
BellatrixForkEpoch: 150,
|
||||
ShardingForkVersion: []byte{3, 0, 0, 0},
|
||||
ShardingForkEpoch: math.MaxUint64,
|
||||
|
||||
@@ -245,5 +246,5 @@ var mainnetBeaconConfig = &BeaconChainConfig{
|
||||
// Bellatrix
|
||||
TerminalBlockHashActivationEpoch: 18446744073709551615,
|
||||
TerminalBlockHash: [32]byte{},
|
||||
TerminalTotalDifficulty: "115792089237316195423570985008687907853269984665640564039457584007913129638912",
|
||||
TerminalTotalDifficulty: "20000000000000",
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@ func UseE2EMainnetConfig() {
|
||||
}
|
||||
|
||||
// E2ETestConfig retrieves the configurations made specifically for E2E testing.
|
||||
// Warning: This config is only for testing, it is not meant for use outside of E2E.
|
||||
//
|
||||
// WARNING: This config is only for testing, it is not meant for use outside of E2E.
|
||||
func E2ETestConfig() *BeaconChainConfig {
|
||||
e2eConfig := MinimalSpecConfig()
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/consensus-types/interfaces"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/network/forks"
|
||||
|
||||
ssz "github.com/ferranbt/fastssz"
|
||||
@@ -56,24 +55,21 @@ var ErrForkNotFound = errors.New("version found in fork schedule but can't be ma
|
||||
// FromForkVersion uses a lookup table to resolve a Version (from a beacon node api for instance, or obtained by peeking at
|
||||
// the bytes of a marshaled BeaconState) to a VersionedUnmarshaler.
|
||||
func FromForkVersion(cv [fieldparams.VersionLength]byte) (*VersionedUnmarshaler, error) {
|
||||
cfg, err := params.ConfigForVersion(cv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var fork int
|
||||
switch cv {
|
||||
case bytesutil.ToBytes4(cfg.GenesisForkVersion):
|
||||
fork = version.Phase0
|
||||
case bytesutil.ToBytes4(cfg.AltairForkVersion):
|
||||
fork = version.Altair
|
||||
case bytesutil.ToBytes4(cfg.BellatrixForkVersion):
|
||||
fork = version.Bellatrix
|
||||
default:
|
||||
return nil, errors.Wrapf(ErrForkNotFound, "version=%#x", cv)
|
||||
}
|
||||
cfg := params.KnownConfigs[params.MainnetName]()
|
||||
//var fork int
|
||||
//switch cv {
|
||||
//case bytesutil.ToBytes4(cfg.GenesisForkVersion):
|
||||
// fork = version.Phase0
|
||||
//case bytesutil.ToBytes4(cfg.AltairForkVersion):
|
||||
// fork = version.Altair
|
||||
//case bytesutil.ToBytes4(cfg.BellatrixForkVersion):
|
||||
// fork = version.Bellatrix
|
||||
//default:
|
||||
// return nil, errors.Wrapf(ErrForkNotFound, "version=%#x", cv)
|
||||
//}
|
||||
return &VersionedUnmarshaler{
|
||||
Config: cfg,
|
||||
Fork: fork,
|
||||
Fork: version.Bellatrix,
|
||||
Version: cv,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ go_test(
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/validator/service:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//testing/assert:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
"//validator/accounts:go_default_library",
|
||||
"//validator/accounts/wallet:go_default_library",
|
||||
|
||||
@@ -539,8 +539,19 @@ func feeRecipientConfig(cliCtx *cli.Context) (*validatorServiceConfig.FeeRecipie
|
||||
if !common.IsHexAddress(option.FeeRecipient) {
|
||||
return nil, errors.New("fee recipient is not a valid eth1 address")
|
||||
}
|
||||
mixedcaseAddress, err := common.NewMixedcaseAddressFromString(option.FeeRecipient)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not decode fee recipient %s", option.FeeRecipient)
|
||||
}
|
||||
checksumAddress := common.BytesToAddress(feebytes)
|
||||
if !mixedcaseAddress.ValidChecksum() {
|
||||
log.Warnf("Fee recipient %s is not a checksum Ethereum address. "+
|
||||
"The checksummed address is %s and will be used as the fee recipient. "+
|
||||
"We recommend using a mixed-case address (checksum) "+
|
||||
"to prevent spelling mistakes in your fee recipient Ethereum address", option.FeeRecipient, checksumAddress.Hex())
|
||||
}
|
||||
frConfig.ProposeConfig[bytesutil.ToBytes48(decodedKey)] = &validatorServiceConfig.FeeRecipientOptions{
|
||||
FeeRecipient: common.BytesToAddress(feebytes),
|
||||
FeeRecipient: checksumAddress,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
validator_service_config "github.com/prysmaticlabs/prysm/config/validator/service"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
@@ -312,6 +313,8 @@ func TestUnmarshalFromURL(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFeeRecipientConfig(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
|
||||
type feeRecipientFlag struct {
|
||||
dir string
|
||||
url string
|
||||
@@ -326,12 +329,13 @@ func TestFeeRecipientConfig(t *testing.T) {
|
||||
want func() *validator_service_config.FeeRecipientConfig
|
||||
urlResponse string
|
||||
wantErr string
|
||||
wantLog string
|
||||
}{
|
||||
{
|
||||
name: "Happy Path Config file File",
|
||||
name: "Happy Path Config file File, bad checksum",
|
||||
args: args{
|
||||
feeRecipientFlagValues: &feeRecipientFlag{
|
||||
dir: "./testdata/good-prepare-beacon-proposer-config.json",
|
||||
dir: "./testdata/good-prepare-beacon-proposer-config-badchecksum.json",
|
||||
url: "",
|
||||
defaultfee: "",
|
||||
},
|
||||
@@ -342,15 +346,16 @@ func TestFeeRecipientConfig(t *testing.T) {
|
||||
return &validator_service_config.FeeRecipientConfig{
|
||||
ProposeConfig: map[[fieldparams.BLSPubkeyLength]byte]*validator_service_config.FeeRecipientOptions{
|
||||
bytesutil.ToBytes48(key1): {
|
||||
FeeRecipient: common.HexToAddress("0x50155530FCE8a85ec7055A5F8b2bE214B3DaeFd3"),
|
||||
FeeRecipient: common.HexToAddress("0xae967917c465db8578ca9024c205720b1a3651A9"),
|
||||
},
|
||||
},
|
||||
DefaultConfig: &validator_service_config.FeeRecipientOptions{
|
||||
FeeRecipient: common.HexToAddress("0x6e35733c5af9B61374A128e6F85f553aF09ff89A"),
|
||||
FeeRecipient: common.HexToAddress("0xae967917c465db8578ca9024c205720b1a3651A9"),
|
||||
},
|
||||
}
|
||||
},
|
||||
wantErr: "",
|
||||
wantLog: "is not a checksum Ethereum address",
|
||||
},
|
||||
{
|
||||
name: "Happy Path Config file File multiple fee recipients",
|
||||
@@ -506,6 +511,11 @@ func TestFeeRecipientConfig(t *testing.T) {
|
||||
require.ErrorContains(t, tt.wantErr, err)
|
||||
return
|
||||
}
|
||||
if tt.wantLog != "" {
|
||||
assert.LogsContain(t, hook,
|
||||
tt.wantLog,
|
||||
)
|
||||
}
|
||||
w := tt.want()
|
||||
require.DeepEqual(t, w, got)
|
||||
})
|
||||
|
||||
10
validator/node/testdata/good-prepare-beacon-proposer-config-badchecksum.json
vendored
Normal file
10
validator/node/testdata/good-prepare-beacon-proposer-config-badchecksum.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"proposer_config": {
|
||||
"0xa057816155ad77931185101128655c0191bd0214c201ca48ed887f6c4c6adf334070efcd75140eada5ac83a92506dd7a": {
|
||||
"fee_recipient": "0xae967917c465db8578ca9024c205720b1a3651A9"
|
||||
}
|
||||
},
|
||||
"default_config": {
|
||||
"fee_recipient": "0xae967917c465db8578ca9024c205720b1a3651A9"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user