2022-08-01 14:43:47 +00:00
|
|
|
package execution
|
2021-11-04 18:19:44 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/cache/depositcache"
|
|
|
|
statefeed "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/feed/state"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/db"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state/stategen"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/network/authorization"
|
2021-11-04 18:19:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Option func(s *Service) error
|
|
|
|
|
2022-08-16 17:22:34 +00:00
|
|
|
// WithHttpEndpoint parse http endpoint for the powchain service to use.
|
|
|
|
func WithHttpEndpoint(endpointString string) Option {
|
2021-11-04 18:19:44 +00:00
|
|
|
return func(s *Service) error {
|
2022-08-16 17:22:34 +00:00
|
|
|
s.cfg.currHttpEndpoint = HttpEndpoint(endpointString)
|
2021-11-04 18:19:44 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-16 17:22:34 +00:00
|
|
|
// WithHttpEndpointAndJWTSecret for authenticating the execution node JSON-RPC endpoint.
|
|
|
|
func WithHttpEndpointAndJWTSecret(endpointString string, secret []byte) Option {
|
2022-04-09 09:03:05 +00:00
|
|
|
return func(s *Service) error {
|
2022-04-01 18:04:24 +00:00
|
|
|
if len(secret) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2022-08-16 17:22:34 +00:00
|
|
|
// Overwrite authorization type for all endpoints to be of a bearer type.
|
|
|
|
hEndpoint := HttpEndpoint(endpointString)
|
|
|
|
hEndpoint.Auth.Method = authorization.Bearer
|
|
|
|
hEndpoint.Auth.Value = string(secret)
|
|
|
|
|
|
|
|
s.cfg.currHttpEndpoint = hEndpoint
|
2022-02-25 19:08:43 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-29 23:34:29 +00:00
|
|
|
// WithHeaders adds headers to the execution node JSON-RPC requests.
|
|
|
|
func WithHeaders(headers []string) Option {
|
|
|
|
return func(s *Service) error {
|
|
|
|
s.cfg.headers = headers
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 18:19:44 +00:00
|
|
|
// WithDepositContractAddress for the deposit contract.
|
|
|
|
func WithDepositContractAddress(addr common.Address) Option {
|
|
|
|
return func(s *Service) error {
|
|
|
|
s.cfg.depositContractAddr = addr
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithDatabase for the beacon chain database.
|
|
|
|
func WithDatabase(database db.HeadAccessDatabase) Option {
|
|
|
|
return func(s *Service) error {
|
|
|
|
s.cfg.beaconDB = database
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithDepositCache for caching deposits.
|
|
|
|
func WithDepositCache(cache *depositcache.DepositCache) Option {
|
|
|
|
return func(s *Service) error {
|
|
|
|
s.cfg.depositCache = cache
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithStateNotifier for subscribing to state changes.
|
|
|
|
func WithStateNotifier(notifier statefeed.Notifier) Option {
|
|
|
|
return func(s *Service) error {
|
|
|
|
s.cfg.stateNotifier = notifier
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithStateGen to regenerate beacon states from checkpoints.
|
|
|
|
func WithStateGen(gen *stategen.State) Option {
|
|
|
|
return func(s *Service) error {
|
|
|
|
s.cfg.stateGen = gen
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithEth1HeaderRequestLimit to set the upper limit of eth1 header requests.
|
|
|
|
func WithEth1HeaderRequestLimit(limit uint64) Option {
|
|
|
|
return func(s *Service) error {
|
|
|
|
s.cfg.eth1HeaderReqLimit = limit
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithBeaconNodeStatsUpdater to set the beacon node stats updater.
|
|
|
|
func WithBeaconNodeStatsUpdater(updater BeaconNodeStatsUpdater) Option {
|
|
|
|
return func(s *Service) error {
|
|
|
|
s.cfg.beaconNodeStatsUpdater = updater
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2021-11-06 13:45:16 +00:00
|
|
|
|
|
|
|
// WithFinalizedStateAtStartup to set the beacon node's finalized state at startup.
|
|
|
|
func WithFinalizedStateAtStartup(st state.BeaconState) Option {
|
|
|
|
return func(s *Service) error {
|
|
|
|
s.cfg.finalizedStateAtStartup = st
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|