2020-09-14 18:42:08 +00:00
|
|
|
// +build libfuzzer
|
|
|
|
|
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-11-19 05:15:58 +00:00
|
|
|
"time"
|
2020-09-14 18:42:08 +00:00
|
|
|
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
|
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
2020-11-19 05:15:58 +00:00
|
|
|
gcache "github.com/patrickmn/go-cache"
|
2020-09-14 18:42:08 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewRegularSyncFuzz service without registering handlers.
|
|
|
|
func NewRegularSyncFuzz(cfg *Config) *Service {
|
|
|
|
rLimiter := newRateLimiter(cfg.P2P)
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
r := &Service{
|
|
|
|
ctx: ctx,
|
|
|
|
cancel: cancel,
|
|
|
|
db: cfg.DB,
|
|
|
|
p2p: cfg.P2P,
|
|
|
|
attPool: cfg.AttPool,
|
|
|
|
exitPool: cfg.ExitPool,
|
|
|
|
slashingPool: cfg.SlashingPool,
|
|
|
|
chain: cfg.Chain,
|
|
|
|
initialSync: cfg.InitialSync,
|
|
|
|
attestationNotifier: cfg.AttestationNotifier,
|
2020-11-19 05:15:58 +00:00
|
|
|
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
2020-09-14 18:42:08 +00:00
|
|
|
seenPendingBlocks: make(map[[32]byte]bool),
|
|
|
|
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
|
|
|
stateNotifier: cfg.StateNotifier,
|
|
|
|
blockNotifier: cfg.BlockNotifier,
|
|
|
|
stateSummaryCache: cfg.StateSummaryCache,
|
|
|
|
stateGen: cfg.StateGen,
|
|
|
|
rateLimiter: rLimiter,
|
|
|
|
}
|
|
|
|
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
// FuzzValidateBeaconBlockPubSub exports private method validateBeaconBlockPubSub for fuzz testing.
|
|
|
|
func (s *Service) FuzzValidateBeaconBlockPubSub(ctx context.Context, pid peer.ID, msg *pubsub.Message) pubsub.ValidationResult {
|
|
|
|
return s.validateBeaconBlockPubSub(ctx, pid, msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
// FuzzBeaconBlockSubscriber exports private method beaconBlockSubscriber for fuzz testing.
|
|
|
|
func (s *Service) FuzzBeaconBlockSubscriber(ctx context.Context, msg proto.Message) error {
|
|
|
|
return s.beaconBlockSubscriber(ctx, msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) InitCaches() error {
|
|
|
|
return s.initCaches()
|
|
|
|
}
|