-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.go
1953 lines (1792 loc) · 85.9 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright © 2020 - 2024 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"context"
"encoding/hex"
"fmt"
"math/big"
"net/http"
// #nosec G108
_ "net/http/pprof"
"os"
"os/signal"
"path/filepath"
"runtime"
"runtime/debug"
"strings"
"syscall"
"time"
"github.com/attestantio/go-block-relay/services/blockauctioneer"
eth2client "github.com/attestantio/go-eth2-client"
"github.com/attestantio/go-eth2-client/api"
"github.com/attestantio/go-eth2-client/spec/bellatrix"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/attestantio/vouch/services/accountmanager"
dirkaccountmanager "github.com/attestantio/vouch/services/accountmanager/dirk"
walletaccountmanager "github.com/attestantio/vouch/services/accountmanager/wallet"
"github.com/attestantio/vouch/services/attestationaggregator"
standardattestationaggregator "github.com/attestantio/vouch/services/attestationaggregator/standard"
"github.com/attestantio/vouch/services/attester"
standardattester "github.com/attestantio/vouch/services/attester/standard"
"github.com/attestantio/vouch/services/beaconblockproposer"
standardbeaconblockproposer "github.com/attestantio/vouch/services/beaconblockproposer/standard"
"github.com/attestantio/vouch/services/beaconcommitteesubscriber"
standardbeaconcommitteesubscriber "github.com/attestantio/vouch/services/beaconcommitteesubscriber/standard"
"github.com/attestantio/vouch/services/blockrelay"
standardblockrelay "github.com/attestantio/vouch/services/blockrelay/standard"
"github.com/attestantio/vouch/services/cache"
standardcache "github.com/attestantio/vouch/services/cache/standard"
"github.com/attestantio/vouch/services/chaintime"
standardchaintime "github.com/attestantio/vouch/services/chaintime/standard"
standardcontroller "github.com/attestantio/vouch/services/controller/standard"
"github.com/attestantio/vouch/services/graffitiprovider"
dynamicgraffitiprovider "github.com/attestantio/vouch/services/graffitiprovider/dynamic"
staticgraffitiprovider "github.com/attestantio/vouch/services/graffitiprovider/static"
"github.com/attestantio/vouch/services/metrics"
nullmetrics "github.com/attestantio/vouch/services/metrics/null"
prometheusmetrics "github.com/attestantio/vouch/services/metrics/prometheus"
"github.com/attestantio/vouch/services/proposalpreparer"
standardproposalpreparer "github.com/attestantio/vouch/services/proposalpreparer/standard"
"github.com/attestantio/vouch/services/scheduler"
advancedscheduler "github.com/attestantio/vouch/services/scheduler/advanced"
"github.com/attestantio/vouch/services/signer"
standardsigner "github.com/attestantio/vouch/services/signer/standard"
"github.com/attestantio/vouch/services/submitter"
immediatesubmitter "github.com/attestantio/vouch/services/submitter/immediate"
multinodesubmitter "github.com/attestantio/vouch/services/submitter/multinode"
"github.com/attestantio/vouch/services/synccommitteeaggregator"
standardsynccommitteeaggregator "github.com/attestantio/vouch/services/synccommitteeaggregator/standard"
"github.com/attestantio/vouch/services/synccommitteemessenger"
standardsynccommitteemessenger "github.com/attestantio/vouch/services/synccommitteemessenger/standard"
"github.com/attestantio/vouch/services/synccommitteesubscriber"
standardsynccommitteesubscriber "github.com/attestantio/vouch/services/synccommitteesubscriber/standard"
"github.com/attestantio/vouch/services/validatorsmanager"
standardvalidatorsmanager "github.com/attestantio/vouch/services/validatorsmanager/standard"
bestaggregateattestationstrategy "github.com/attestantio/vouch/strategies/aggregateattestation/best"
firstaggregateattestationstrategy "github.com/attestantio/vouch/strategies/aggregateattestation/first"
bestattestationdatastrategy "github.com/attestantio/vouch/strategies/attestationdata/best"
firstattestationdatastrategy "github.com/attestantio/vouch/strategies/attestationdata/first"
majorityattestationdatastrategy "github.com/attestantio/vouch/strategies/attestationdata/majority"
firstbeaconblockheaderstrategy "github.com/attestantio/vouch/strategies/beaconblockheader/first"
bestbeaconblockproposalstrategy "github.com/attestantio/vouch/strategies/beaconblockproposal/best"
firstbeaconblockproposalstrategy "github.com/attestantio/vouch/strategies/beaconblockproposal/first"
firstbeaconblockrootstrategy "github.com/attestantio/vouch/strategies/beaconblockroot/first"
majoritybeaconblockrootstrategy "github.com/attestantio/vouch/strategies/beaconblockroot/majority"
"github.com/attestantio/vouch/strategies/builderbid"
bestbuilderbidstrategy "github.com/attestantio/vouch/strategies/builderbid/best"
deadlinebuilderbidstrategy "github.com/attestantio/vouch/strategies/builderbid/deadline"
firstsignedbeaconblockstrategy "github.com/attestantio/vouch/strategies/signedbeaconblock/first"
bestsynccommitteecontributionstrategy "github.com/attestantio/vouch/strategies/synccommitteecontribution/best"
firstsynccommitteecontributionstrategy "github.com/attestantio/vouch/strategies/synccommitteecontribution/first"
"github.com/attestantio/vouch/util"
"github.com/aws/aws-sdk-go/aws/credentials"
homedir "github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"github.com/spf13/pflag"
"github.com/spf13/viper"
e2types "github.com/wealdtech/go-eth2-types/v2"
majordomo "github.com/wealdtech/go-majordomo"
asmconfidant "github.com/wealdtech/go-majordomo/confidants/asm"
directconfidant "github.com/wealdtech/go-majordomo/confidants/direct"
fileconfidant "github.com/wealdtech/go-majordomo/confidants/file"
gsmconfidant "github.com/wealdtech/go-majordomo/confidants/gsm"
httpconfidant "github.com/wealdtech/go-majordomo/confidants/http"
standardmajordomo "github.com/wealdtech/go-majordomo/standard"
)
// ReleaseVersion is the release version for the code.
var ReleaseVersion = "1.10.0-dev"
func main() {
exitCode := main2()
if exitCode != 0 {
// Exit immediately.
os.Exit(exitCode)
}
// Leave without an explicit exit; this allows cancelled contexts to tidy themselves up.
}
func main2() int {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err := fetchConfig(); err != nil {
fmt.Fprintf(os.Stderr, "failed to fetch configuration: %v\n", err)
return 1
}
majordomo, err := initMajordomo(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to initialise majordomo: %v\n", err)
return 1
}
if exit := runCommands(ctx, majordomo); exit {
return 0
}
if err := initLogging(); err != nil {
fmt.Fprintf(os.Stderr, "failed to initialise logging: %v\n", err)
return 1
}
logModules()
log.Info().Str("version", ReleaseVersion).Str("commit_hash", util.CommitHash()).Msg("Starting vouch")
initProfiling()
if err := initTracing(ctx, majordomo); err != nil {
log.Error().Err(err).Msg("Failed to initialise tracing")
return 1
}
runtime.GOMAXPROCS(runtime.NumCPU() * 8)
if err := e2types.InitBLS(); err != nil {
log.Error().Err(err).Msg("Failed to initialise BLS library")
return 1
}
chainTime, controller, err := startServices(ctx, majordomo)
if err != nil {
log.Error().Err(err).Msg("Failed to initialise services")
return 1
}
setReady(true)
log.Info().Msg("All services operational")
// Wait for signal.
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sigCh
// Received a signal to stop, but don't do so until we have finished attesting for this slot.
slot := chainTime.CurrentSlot()
first := true
for {
if !controller.HasPendingAttestations(ctx, slot) {
log.Info().Uint64("slot", uint64(slot)).Msg("Attestations complete; shutting down")
break
}
if first {
log.Info().Uint64("slot", uint64(slot)).Msg("Waiting for attestations to complete")
first = false
}
time.Sleep(100 * time.Millisecond)
}
log.Info().Msg("Stopping vouch")
return 0
}
// fetchConfig fetches configuration from various sources.
func fetchConfig() error {
pflag.String("base-dir", "", "base directory for configuration files")
pflag.String("log-level", "info", "minimum level of messsages to log")
pflag.String("log-file", "", "redirect log output to a file")
pflag.String("profile-address", "", "Address on which to run Go profile server")
pflag.String("tracing-address", "", "Address to which to send tracing data")
pflag.String("beacon-node-address", "", "Address on which to contact the beacon node")
pflag.Bool("version", false, "show Vouch version and exit")
pflag.String("proposer-config-check", "", "show the proposer configuration for the given public key and exit")
pflag.Parse()
if err := viper.BindPFlags(pflag.CommandLine); err != nil {
return errors.Wrap(err, "failed to bind pflags to viper")
}
if viper.GetString("base-dir") != "" {
// User-defined base directory.
viper.AddConfigPath(resolvePath(""))
viper.SetConfigName("vouch")
} else {
// Home directory.
home, err := homedir.Dir()
if err != nil {
return errors.Wrap(err, "failed to obtain home directory")
}
viper.AddConfigPath(home)
viper.SetConfigName(".vouch")
}
// Environment settings.
viper.SetEnvPrefix("VOUCH")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_"))
viper.AutomaticEnv()
// Defaults.
viper.SetDefault("logging.timestamp.format", "2006-01-02T15:04:05.000Z07:00")
viper.SetDefault("process-concurrency", int64(runtime.GOMAXPROCS(-1)))
viper.SetDefault("timeout", 2*time.Second)
viper.SetDefault("eth2client.timeout", 2*time.Minute)
viper.SetDefault("eth2client.allow-delayed-start", true)
viper.SetDefault("controller.max-proposal-delay", 0)
viper.SetDefault("controller.max-attestation-delay", 4*time.Second)
viper.SetDefault("controller.max-sync-committee-message-delay", 4*time.Second)
viper.SetDefault("controller.attestation-aggregation-delay", 8*time.Second)
viper.SetDefault("controller.sync-committee-aggregation-delay", 8*time.Second)
viper.SetDefault("controller.verify-sync-committee-inclusion", false)
viper.SetDefault("controller.fast-track.attestations", true)
viper.SetDefault("controller.fast-track.sync-committees", true)
viper.SetDefault("controller.fast-track.grace", 500*time.Millisecond)
viper.SetDefault("blockrelay.timeout", 1*time.Second)
viper.SetDefault("blockrelay.listen-address", "0.0.0.0:18550")
viper.SetDefault("blockrelay.fallback-gas-limit", uint64(30000000))
viper.SetDefault("accountmanager.dirk.timeout", 30*time.Second)
viper.SetDefault("strategies.beaconblockproposal.best.execution-payload-factor", float64(0.0005))
viper.SetDefault("beaconblockproposer.builder-boost-factor", 91)
viper.SetDefault("strategies.builderbid.deadline.deadline", time.Second)
viper.SetDefault("strategies.builderbid.deadline.bid-gap", 100*time.Millisecond)
viper.SetDefault("submitter.style", "multinode")
if err := viper.ReadInConfig(); err != nil {
switch {
case errors.As(err, &viper.ConfigFileNotFoundError{}):
// It is allowable for Vouch to not have a configuration file, but only if
// we have the information from elsewhere (e.g. environment variables). Check
// to see if we have any beacon nodes configured, as if not we aren't going to
// get very far anyway.
if util.BeaconNodeAddresses("") == nil {
// Assume the underlying issue is that the configuration file is missing.
return errors.Wrap(err, "could not find the configuration file")
}
case errors.As(err, &viper.ConfigParseError{}):
return errors.Wrap(err, "could not parse the configuration file")
default:
return errors.Wrap(err, "failed to obtain configuration")
}
}
return nil
}
// initProfiling initialises the profiling server.
func initProfiling() {
profileAddress := viper.GetString("profile-address")
if profileAddress != "" {
go func() {
log.Info().Str("profile_address", profileAddress).Msg("Starting profile server")
server := &http.Server{
Addr: profileAddress,
ReadHeaderTimeout: 5 * time.Second,
}
runtime.SetMutexProfileFraction(1)
if err := server.ListenAndServe(); err != nil {
log.Warn().Str("profile_address", profileAddress).Err(err).Msg("Failed to run profile server")
}
}()
}
}
func startClient(ctx context.Context, monitor metrics.Service) (eth2client.Service, error) {
log.Trace().Msg("Starting consensus client service")
var consensusClient eth2client.Service
var err error
if len(viper.GetStringSlice("beacon-node-addresses")) > 0 {
consensusClient, err = fetchMultiClient(ctx, monitor, "main", viper.GetStringSlice("beacon-node-addresses"))
} else {
consensusClient, err = fetchClient(ctx, monitor, viper.GetString("beacon-node-address"))
}
if err != nil {
return nil, err
}
return consensusClient, nil
}
func startServices(ctx context.Context,
majordomo majordomo.Service,
) (
chaintime.Service,
*standardcontroller.Service,
error,
) {
eth2Client, chainTime, monitor, err := startBasicServices(ctx)
if err != nil {
return nil, nil, err
}
// Some beacon nodes do not respond pre-genesis, so we must wait for genesis before proceeding.
waitedForGenesis, err := waitForGenesis(ctx, chainTime)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to wait for genesis block")
}
altairCapable, bellatrixCapable, _, err := consensusClientCapabilities(ctx, eth2Client)
if err != nil {
return nil, nil, err
}
signedBeaconBlockProvider, beaconBlockHeaderProvider, err := startProviderServices(ctx, monitor, eth2Client)
if err != nil {
return nil, nil, err
}
schedulerSvc, cacheSvc, signerSvc, accountManager, err := startSharedServices(ctx, eth2Client, majordomo, chainTime, monitor, beaconBlockHeaderProvider, signedBeaconBlockProvider)
if err != nil {
return nil, nil, err
}
submitter, err := selectSubmitterStrategy(ctx, monitor, eth2Client)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to select submitter")
}
blockRelay, err := startBlockRelay(ctx, majordomo, monitor, eth2Client, schedulerSvc, chainTime, accountManager, signerSvc)
if err != nil {
return nil, nil, err
}
beaconBlockProposer, attesterSvc, attestationAggregator, beaconCommitteeSubscriber, err := startSigningServices(ctx, majordomo, monitor, eth2Client, chainTime, cacheSvc, signerSvc, blockRelay, accountManager, submitter)
if err != nil {
return nil, nil, err
}
var syncCommitteeSubscriber synccommitteesubscriber.Service
var syncCommitteeMessenger synccommitteemessenger.Service
var syncCommitteeAggregator synccommitteeaggregator.Service
if altairCapable {
syncCommitteeSubscriber, syncCommitteeMessenger, syncCommitteeAggregator, err = startAltairServices(ctx, monitor, eth2Client, submitter, signerSvc, accountManager, chainTime, cacheSvc)
if err != nil {
return nil, nil, err
}
}
// We need to submit proposal preparations to all nodes that are acting as beacon block proposers.
proposalPreparer, err := initProposalPreparer(ctx, monitor, chainTime, bellatrixCapable, accountManager, blockRelay)
if err != nil {
return nil, nil, err
}
controller, err := initController(ctx, monitor, chainTime, eth2Client,
schedulerSvc, attesterSvc, cacheSvc,
waitedForGenesis, accountManager, beaconBlockProposer, signedBeaconBlockProvider, proposalPreparer, attestationAggregator, beaconCommitteeSubscriber,
syncCommitteeMessenger, syncCommitteeAggregator, syncCommitteeSubscriber)
if err != nil {
return nil, nil, err
}
return chainTime, controller, nil
}
func initController(ctx context.Context, monitor metrics.Service, chainTime chaintime.Service, eth2Client eth2client.Service,
schedulerSvc scheduler.Service, attesterSvc attester.Service, cacheSvc cache.Service,
waitedForGenesis bool, accountManager accountmanager.Service, beaconBlockProposer beaconblockproposer.Service, signedBeaconBlockProvider eth2client.SignedBeaconBlockProvider,
proposalPreparer proposalpreparer.Service, attestationAggregator attestationaggregator.Service, beaconCommitteeSubscriber beaconcommitteesubscriber.Service,
syncCommitteeMessenger synccommitteemessenger.Service, syncCommitteeAggregator synccommitteeaggregator.Service, syncCommitteeSubscriber synccommitteesubscriber.Service,
) (*standardcontroller.Service, error) {
// The events provider for the controller should only use beacon nodes that are used for attestation data.
eventsConsensusClient, err := fetchMultiClient(ctx, monitor, "events", util.BeaconNodeAddressesForAttesting())
if err != nil {
return nil, errors.Wrap(err, "failed to fetch multiclient for controller")
}
log.Trace().Msg("Starting controller")
controller, err := standardcontroller.New(ctx,
standardcontroller.WithLogLevel(util.LogLevel("controller")),
standardcontroller.WithMonitor(monitor),
standardcontroller.WithSpecProvider(eth2Client.(eth2client.SpecProvider)),
standardcontroller.WithChainTimeService(chainTime),
standardcontroller.WithWaitedForGenesis(waitedForGenesis),
standardcontroller.WithProposerDutiesProvider(eth2Client.(eth2client.ProposerDutiesProvider)),
standardcontroller.WithAttesterDutiesProvider(eth2Client.(eth2client.AttesterDutiesProvider)),
standardcontroller.WithSyncCommitteeDutiesProvider(eth2Client.(eth2client.SyncCommitteeDutiesProvider)),
standardcontroller.WithEventsProvider(eventsConsensusClient.(eth2client.EventsProvider)),
standardcontroller.WithScheduler(schedulerSvc),
standardcontroller.WithValidatingAccountsProvider(accountManager.(accountmanager.ValidatingAccountsProvider)),
standardcontroller.WithAttester(attesterSvc),
standardcontroller.WithSyncCommitteeMessenger(syncCommitteeMessenger),
standardcontroller.WithSyncCommitteeAggregator(syncCommitteeAggregator),
standardcontroller.WithBeaconBlockProposer(beaconBlockProposer),
standardcontroller.WithBeaconBlockHeadersProvider(eth2Client.(eth2client.BeaconBlockHeadersProvider)),
standardcontroller.WithSignedBeaconBlockProvider(signedBeaconBlockProvider),
standardcontroller.WithProposalsPreparer(proposalPreparer),
standardcontroller.WithAttestationAggregator(attestationAggregator),
standardcontroller.WithBeaconCommitteeSubscriber(beaconCommitteeSubscriber),
standardcontroller.WithSyncCommitteeSubscriber(syncCommitteeSubscriber),
standardcontroller.WithAccountsRefresher(accountManager.(accountmanager.Refresher)),
standardcontroller.WithBlockToSlotSetter(cacheSvc.(cache.BlockRootToSlotSetter)),
standardcontroller.WithMaxProposalDelay(viper.GetDuration("controller.max-proposal-delay")),
standardcontroller.WithMaxAttestationDelay(viper.GetDuration("controller.max-attestation-delay")),
standardcontroller.WithAttestationAggregationDelay(viper.GetDuration("controller.attestation-aggregation-delay")),
standardcontroller.WithMaxSyncCommitteeMessageDelay(viper.GetDuration("controller.max-sync-committee-message-delay")),
standardcontroller.WithSyncCommitteeAggregationDelay(viper.GetDuration("controller.sync-committee-aggregation-delay")),
standardcontroller.WithVerifySyncCommitteeInclusion(viper.GetBool("controller.verify-sync-committee-inclusion")),
standardcontroller.WithFastTrackAttestations(viper.GetBool("controller.fast-track.attestations")),
standardcontroller.WithFastTrackSyncCommittees(viper.GetBool("controller.fast-track.sync-committees")),
standardcontroller.WithFastTrackGrace(viper.GetDuration("controller.fast-track.grace")),
)
if err != nil {
return nil, errors.Wrap(err, "failed to start controller service")
}
return controller, nil
}
func initProposalPreparer(ctx context.Context, monitor metrics.Service, chainTime chaintime.Service, bellatrixCapable bool, accountManager accountmanager.Service, blockRelay blockrelay.Service) (proposalpreparer.Service, error) {
// We need to submit proposal preparations to all nodes that are acting as beacon block proposers.
nodeAddresses := util.BeaconNodeAddressesForProposing()
proposalPreparationsSubmitters := make([]eth2client.ProposalPreparationsSubmitter, 0, len(nodeAddresses))
for _, address := range nodeAddresses {
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for proposal preparation submitter", address))
}
proposalPreparationsSubmitters = append(proposalPreparationsSubmitters, client.(eth2client.ProposalPreparationsSubmitter))
}
if bellatrixCapable {
log.Trace().Msg("Starting proposals preparer")
proposalPreparer, err := standardproposalpreparer.New(ctx,
standardproposalpreparer.WithLogLevel(util.LogLevel("proposalspreparor")),
standardproposalpreparer.WithMonitor(monitor),
standardproposalpreparer.WithChainTimeService(chainTime),
standardproposalpreparer.WithValidatingAccountsProvider(accountManager.(accountmanager.ValidatingAccountsProvider)),
standardproposalpreparer.WithProposalPreparationsSubmitters(proposalPreparationsSubmitters),
standardproposalpreparer.WithExecutionConfigProvider(blockRelay.(blockrelay.ExecutionConfigProvider)),
)
if err != nil {
return nil, errors.Wrap(err, "failed to start proposal preparer service")
}
return proposalPreparer, nil
}
var proposalPreparer proposalpreparer.Service
return proposalPreparer, nil
}
func waitForGenesis(ctx context.Context, chainTime chaintime.Service) (bool, error) {
genesisTime := chainTime.GenesisTime()
now := time.Now()
waitedForGenesis := false
if now.Before(genesisTime) {
waitedForGenesis = true
// Wait for genesis (or signal, or context cancel).
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
log.Info().Str("genesis", fmt.Sprintf("%v", genesisTime)).Msg("Waiting for genesis")
ctx, cancel := context.WithDeadline(ctx, genesisTime)
defer cancel()
select {
case <-sigCh:
return false, errors.New("signal received")
case <-ctx.Done():
switch ctx.Err() {
case context.DeadlineExceeded:
log.Info().Msg("Genesis time")
case context.Canceled:
return false, errors.New("context cancelled")
}
}
}
return waitedForGenesis, nil
}
func startProviderServices(ctx context.Context, monitor metrics.Service, eth2Client eth2client.Service) (eth2client.SignedBeaconBlockProvider, eth2client.BeaconBlockHeadersProvider, error) {
// The signed beacon block provider from the configured strategy to define how we get signed beacon blocks.
signedBeaconBlockProvider, err := selectSignedBeaconBlockProvider(ctx, monitor, eth2Client)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to fetch signed beacon block provider for controller")
}
// The block header provider from the configured strategy to define how we get block headers.
beaconBlockHeaderProvider, err := selectBeaconHeaderProvider(ctx, monitor, eth2Client)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to fetch beacon block header provider for controller")
}
return signedBeaconBlockProvider, beaconBlockHeaderProvider, nil
}
func startBasicServices(ctx context.Context,
) (
eth2client.Service,
chaintime.Service,
metrics.Service,
error,
) {
// Initialise monitor without chainTime service and server for now, so the
// client can provide metrics.
monitor, err := startMonitor(ctx, nil, false)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "failed to start metrics service")
}
eth2Client, err := startClient(ctx, monitor)
if err != nil {
return nil, nil, nil, err
}
log.Trace().Msg("Starting chain time service")
chainTime, err := standardchaintime.New(ctx,
standardchaintime.WithLogLevel(util.LogLevel("chaintime")),
standardchaintime.WithGenesisProvider(eth2Client.(eth2client.GenesisProvider)),
standardchaintime.WithSpecProvider(eth2Client.(eth2client.SpecProvider)),
)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "failed to start chain time service")
}
log.Trace().Msg("Starting metrics service")
// Reinitialise monitor with chainTime service and an operational server.
monitor, err = startMonitor(ctx, chainTime, true)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "failed to start metrics service")
}
if err := registerMetrics(monitor); err != nil {
return nil, nil, nil, errors.Wrap(err, "failed to register metrics")
}
setRelease(ReleaseVersion)
setReady(false)
return eth2Client, chainTime, monitor, nil
}
func startSharedServices(ctx context.Context,
eth2Client eth2client.Service,
majordomo majordomo.Service,
chainTime chaintime.Service,
monitor metrics.Service,
beaconBlockHeaderProvider eth2client.BeaconBlockHeadersProvider,
signedBeaconBlockProvider eth2client.SignedBeaconBlockProvider,
) (
scheduler.Service,
cache.Service,
signer.Service,
accountmanager.Service,
error,
) {
log.Trace().Msg("Selecting scheduler")
scheduler, err := selectScheduler(ctx, monitor)
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "failed to select scheduler")
}
log.Trace().Msg("Starting cache")
cacheSvc, err := startCache(ctx, monitor, chainTime, scheduler, eth2Client, beaconBlockHeaderProvider, signedBeaconBlockProvider)
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "failed to start cache")
}
log.Trace().Msg("Starting validators manager")
validatorsManager, err := startValidatorsManager(ctx, monitor, eth2Client)
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "failed to start validators manager")
}
log.Trace().Msg("Starting signer")
signerSvc, err := startSigner(ctx, monitor, eth2Client)
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "failed to start signer")
}
log.Trace().Msg("Starting account manager")
accountManager, err := startAccountManager(ctx, monitor, eth2Client, validatorsManager, majordomo, chainTime)
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "failed to start account manager")
}
return scheduler, cacheSvc, signerSvc, accountManager, nil
}
func startProviders(ctx context.Context,
majordomo majordomo.Service,
monitor metrics.Service,
eth2Client eth2client.Service,
chainTime chaintime.Service,
cache cache.Service,
) (
graffitiprovider.Service,
eth2client.ProposalProvider,
eth2client.AttestationDataProvider,
eth2client.AggregateAttestationProvider,
error,
) {
log.Trace().Msg("Starting graffiti provider")
graffitiProvider, err := startGraffitiProvider(ctx, majordomo)
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "failed to start graffiti provider")
}
log.Trace().Msg("Selecting beacon block proposal provider")
beaconBlockProposalProvider, err := selectProposalProvider(ctx, monitor, eth2Client, chainTime, cache)
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "failed to select beacon block proposal provider")
}
log.Trace().Msg("Selecting attestation data provider")
attestationDataProvider, err := selectAttestationDataProvider(ctx, monitor, eth2Client, chainTime, cache)
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "failed to select attestation data provider")
}
log.Trace().Msg("Selecting aggregate attestation provider")
aggregateAttestationProvider, err := selectAggregateAttestationProvider(ctx, monitor, eth2Client)
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "failed to select aggregate attestation provider")
}
return graffitiProvider, beaconBlockProposalProvider, attestationDataProvider, aggregateAttestationProvider, nil
}
func startAltairServices(ctx context.Context,
monitor metrics.Service,
eth2Client eth2client.Service,
submitterStrategy submitter.Service,
signerSvc signer.Service,
accountManager accountmanager.Service,
chainTime chaintime.Service,
cacheSvc cache.Service,
) (
synccommitteesubscriber.Service,
synccommitteemessenger.Service,
synccommitteeaggregator.Service,
error,
) {
log.Trace().Msg("Starting sync committee subscriber service")
syncCommitteeSubscriber, err := standardsynccommitteesubscriber.New(ctx,
standardsynccommitteesubscriber.WithLogLevel(util.LogLevel("synccommiteesubscriber")),
standardsynccommitteesubscriber.WithMonitor(monitor),
standardsynccommitteesubscriber.WithSyncCommitteeSubmitter(submitterStrategy.(submitter.SyncCommitteeSubscriptionsSubmitter)),
)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "failed to start beacon committee subscriber service")
}
log.Trace().Msg("Selecting sync committee contribution provider")
syncCommitteeContributionProvider, err := selectSyncCommitteeContributionProvider(ctx, monitor, eth2Client)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "failed to select sync committee contribution provider")
}
log.Trace().Msg("Selecting beacon block root provider")
beaconBlockRootProvider, err := selectBeaconBlockRootProvider(ctx, monitor, eth2Client, cacheSvc)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "failed to select beacon block root provider")
}
log.Trace().Msg("Starting sync committee aggregator")
syncCommitteeAggregator, err := standardsynccommitteeaggregator.New(ctx,
standardsynccommitteeaggregator.WithLogLevel(util.LogLevel("synccommitteeaggregator")),
standardsynccommitteeaggregator.WithMonitor(monitor),
standardsynccommitteeaggregator.WithSpecProvider(eth2Client.(eth2client.SpecProvider)),
standardsynccommitteeaggregator.WithBeaconBlockRootProvider(beaconBlockRootProvider),
standardsynccommitteeaggregator.WithContributionAndProofSigner(signerSvc.(signer.ContributionAndProofSigner)),
standardsynccommitteeaggregator.WithValidatingAccountsProvider(accountManager.(accountmanager.ValidatingAccountsProvider)),
standardsynccommitteeaggregator.WithSyncCommitteeContributionProvider(syncCommitteeContributionProvider),
standardsynccommitteeaggregator.WithSyncCommitteeContributionsSubmitter(submitterStrategy.(submitter.SyncCommitteeContributionsSubmitter)),
standardsynccommitteeaggregator.WithChainTime(chainTime),
)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "failed to start sync committee aggregator service")
}
log.Trace().Msg("Starting sync committee messenger")
syncCommitteeMessenger, err := standardsynccommitteemessenger.New(ctx,
standardsynccommitteemessenger.WithLogLevel(util.LogLevel("synccommitteemessenger")),
standardsynccommitteemessenger.WithProcessConcurrency(viper.GetInt64("process-concurrency")),
standardsynccommitteemessenger.WithMonitor(monitor),
standardsynccommitteemessenger.WithSpecProvider(eth2Client.(eth2client.SpecProvider)),
standardsynccommitteemessenger.WithChainTimeService(chainTime),
standardsynccommitteemessenger.WithSyncCommitteeAggregator(syncCommitteeAggregator),
standardsynccommitteemessenger.WithBeaconBlockRootProvider(beaconBlockRootProvider),
standardsynccommitteemessenger.WithSyncCommitteeMessagesSubmitter(submitterStrategy.(submitter.SyncCommitteeMessagesSubmitter)),
standardsynccommitteemessenger.WithValidatingAccountsProvider(accountManager.(accountmanager.ValidatingAccountsProvider)),
standardsynccommitteemessenger.WithSyncCommitteeRootSigner(signerSvc.(signer.SyncCommitteeRootSigner)),
standardsynccommitteemessenger.WithSyncCommitteeSelectionSigner(signerSvc.(signer.SyncCommitteeSelectionSigner)),
standardsynccommitteemessenger.WithSyncCommitteeSubscriptionsSubmitter(submitterStrategy.(submitter.SyncCommitteeSubscriptionsSubmitter)),
)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "failed to start sync committee messenger service")
}
return syncCommitteeSubscriber, syncCommitteeMessenger, syncCommitteeAggregator, nil
}
func startSigningServices(ctx context.Context,
majordomo majordomo.Service,
monitor metrics.Service,
eth2Client eth2client.Service,
chainTime chaintime.Service,
cacheSvc cache.Service,
signerSvc signer.Service,
blockRelay blockrelay.Service,
accountManager accountmanager.Service,
submitterStrategy submitter.Service,
) (
beaconblockproposer.Service,
attester.Service,
attestationaggregator.Service,
beaconcommitteesubscriber.Service,
error,
) {
graffitiProvider, proposalProvider, attestationDataProvider, aggregateAttestationProvider, err := startProviders(ctx, majordomo, monitor, eth2Client, chainTime, cacheSvc)
if err != nil {
return nil, nil, nil, nil, err
}
beaconBlockProposer, err := standardbeaconblockproposer.New(ctx,
standardbeaconblockproposer.WithLogLevel(util.LogLevel("beaconblockproposer")),
standardbeaconblockproposer.WithChainTime(chainTime),
standardbeaconblockproposer.WithProposalDataProvider(proposalProvider),
standardbeaconblockproposer.WithBlockAuctioneer(blockRelay.(blockauctioneer.BlockAuctioneer)),
standardbeaconblockproposer.WithValidatingAccountsProvider(accountManager.(accountmanager.ValidatingAccountsProvider)),
standardbeaconblockproposer.WithExecutionChainHeadProvider(cacheSvc.(cache.ExecutionChainHeadProvider)),
standardbeaconblockproposer.WithGraffitiProvider(graffitiProvider),
standardbeaconblockproposer.WithMonitor(monitor),
standardbeaconblockproposer.WithProposalSubmitter(submitterStrategy.(submitter.ProposalSubmitter)),
standardbeaconblockproposer.WithRANDAORevealSigner(signerSvc.(signer.RANDAORevealSigner)),
standardbeaconblockproposer.WithBeaconBlockSigner(signerSvc.(signer.BeaconBlockSigner)),
standardbeaconblockproposer.WithBlobSidecarSigner(signerSvc.(signer.BlobSidecarSigner)),
standardbeaconblockproposer.WithUnblindFromAllRelays(viper.GetBool("beaconblockproposer.unblind-from-all-relays")),
standardbeaconblockproposer.WithBuilderBoostFactor(viper.GetUint64("beaconblockproposer.builder-boost-factor")),
)
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "failed to start beacon block proposer service")
}
log.Trace().Msg("Starting attester")
attester, err := standardattester.New(ctx,
standardattester.WithLogLevel(util.LogLevel("attester")),
standardattester.WithProcessConcurrency(util.ProcessConcurrency("attester")),
standardattester.WithChainTime(chainTime),
standardattester.WithSpecProvider(eth2Client.(eth2client.SpecProvider)),
standardattester.WithAttestationDataProvider(attestationDataProvider),
standardattester.WithAttestationsSubmitter(submitterStrategy.(submitter.AttestationsSubmitter)),
standardattester.WithMonitor(monitor),
standardattester.WithValidatingAccountsProvider(accountManager.(accountmanager.ValidatingAccountsProvider)),
standardattester.WithBeaconAttestationsSigner(signerSvc.(signer.BeaconAttestationsSigner)),
)
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "failed to start attester service")
}
log.Trace().Msg("Starting beacon attestation aggregator")
attestationAggregator, err := standardattestationaggregator.New(ctx,
standardattestationaggregator.WithLogLevel(util.LogLevel("attestationaggregator")),
standardattestationaggregator.WithAggregateAttestationProvider(aggregateAttestationProvider),
standardattestationaggregator.WithAggregateAttestationsSubmitter(submitterStrategy.(submitter.AggregateAttestationsSubmitter)),
standardattestationaggregator.WithMonitor(monitor),
standardattestationaggregator.WithValidatingAccountsProvider(accountManager.(accountmanager.ValidatingAccountsProvider)),
standardattestationaggregator.WithSlotSelectionSigner(signerSvc.(signer.SlotSelectionSigner)),
standardattestationaggregator.WithAggregateAndProofSigner(signerSvc.(signer.AggregateAndProofSigner)),
standardattestationaggregator.WithSpecProvider(eth2Client.(eth2client.SpecProvider)),
standardattestationaggregator.WithChainTime(chainTime),
)
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "failed to start beacon attestation aggregator service")
}
log.Trace().Msg("Starting beacon committee subscriber service")
beaconCommitteeSubscriber, err := standardbeaconcommitteesubscriber.New(ctx,
standardbeaconcommitteesubscriber.WithLogLevel(util.LogLevel("beaconcommiteesubscriber")),
standardbeaconcommitteesubscriber.WithProcessConcurrency(util.ProcessConcurrency("beaconcommitteesubscriber")),
standardbeaconcommitteesubscriber.WithMonitor(monitor),
standardbeaconcommitteesubscriber.WithChainTimeService(chainTime),
standardbeaconcommitteesubscriber.WithAttesterDutiesProvider(eth2Client.(eth2client.AttesterDutiesProvider)),
standardbeaconcommitteesubscriber.WithAttestationAggregator(attestationAggregator),
standardbeaconcommitteesubscriber.WithBeaconCommitteeSubmitter(submitterStrategy.(submitter.BeaconCommitteeSubscriptionsSubmitter)),
)
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "failed to start beacon committee subscriber service")
}
return beaconBlockProposer, attester, attestationAggregator, beaconCommitteeSubscriber, nil
}
// logModules logs a list of modules with their versions.
func logModules() {
buildInfo, ok := debug.ReadBuildInfo()
if ok {
log.Trace().Str("path", buildInfo.Path).Msg("Main package")
for _, dep := range buildInfo.Deps {
path := dep.Path
if dep.Replace != nil {
path = dep.Replace.Path
}
log.Trace().Str("path", path).Str("version", dep.Version).Msg("Dependency")
}
}
}
// resolvePath resolves a potentially relative path to an absolute path.
func resolvePath(path string) string {
if filepath.IsAbs(path) {
return path
}
baseDir := viper.GetString("base-dir")
if baseDir == "" {
homeDir, err := homedir.Dir()
if err != nil {
log.Fatal().Err(err).Msg("Could not determine a home directory")
}
baseDir = homeDir
}
return filepath.Join(baseDir, path)
}
// initMajordomo initialises majordomo and its required confidants given user input.
func initMajordomo(ctx context.Context) (majordomo.Service, error) {
majordomo, err := standardmajordomo.New(ctx,
standardmajordomo.WithLogLevel(util.LogLevel("majordomo")),
)
if err != nil {
return nil, errors.Wrap(err, "failed to create majordomo service")
}
directConfidant, err := directconfidant.New(ctx,
directconfidant.WithLogLevel(util.LogLevel("majordomo.confidants.direct")),
)
if err != nil {
return nil, errors.Wrap(err, "failed to create direct confidant")
}
if err := majordomo.RegisterConfidant(ctx, directConfidant); err != nil {
return nil, errors.Wrap(err, "failed to register direct confidant")
}
fileConfidant, err := fileconfidant.New(ctx,
fileconfidant.WithLogLevel(util.LogLevel("majordomo.confidants.file")),
)
if err != nil {
return nil, errors.Wrap(err, "failed to create file confidant")
}
if err := majordomo.RegisterConfidant(ctx, fileConfidant); err != nil {
return nil, errors.Wrap(err, "failed to register file confidant")
}
if viper.GetString("majordomo.asm.region") != "" {
var asmCredentials *credentials.Credentials
if viper.GetString("majordomo.asm.id") != "" {
asmCredentials = credentials.NewStaticCredentials(viper.GetString("majordomo.asm.id"), viper.GetString("majordomo.asm.secret"), "")
}
asmConfidant, err := asmconfidant.New(ctx,
asmconfidant.WithLogLevel(util.LogLevel("majordomo.confidants.asm")),
asmconfidant.WithCredentials(asmCredentials),
asmconfidant.WithRegion(viper.GetString("majordomo.asm.region")),
)
if err != nil {
return nil, errors.Wrap(err, "failed to create AWS secrets manager confidant")
}
if err := majordomo.RegisterConfidant(ctx, asmConfidant); err != nil {
return nil, errors.Wrap(err, "failed to register AWS secrets manager confidant")
}
}
if viper.GetString("majordomo.gsm.credentials") != "" {
gsmConfidant, err := gsmconfidant.New(ctx,
gsmconfidant.WithLogLevel(util.LogLevel("majordomo.confidants.gsm")),
gsmconfidant.WithCredentialsPath(resolvePath(viper.GetString("majordomo.gsm.credentials"))),
gsmconfidant.WithProject(viper.GetString("majordomo.gsm.project")),
)
if err != nil {
return nil, errors.Wrap(err, "failed to create Google secret manager confidant")
}
if err := majordomo.RegisterConfidant(ctx, gsmConfidant); err != nil {
return nil, errors.Wrap(err, "failed to register Google secret manager confidant")
}
}
httpConfidant, err := httpconfidant.New(ctx,
httpconfidant.WithLogLevel(util.LogLevel("majordomo.confidants.http")),
)
if err != nil {
return nil, errors.Wrap(err, "failed to create HTTP confidant")
}
if err := majordomo.RegisterConfidant(ctx, httpConfidant); err != nil {
return nil, errors.Wrap(err, "failed to register HTTP confidant")
}
return majordomo, nil
}
// startMonitor starts the relevant metrics monitor given user input.
func startMonitor(ctx context.Context,
chainTime chaintime.Service,
createServer bool,
) (
metrics.Service,
error,
) {
log.Trace().Msg("Starting metrics service")
var monitor metrics.Service
if viper.GetString("metrics.prometheus.listen-address") != "" {
var err error
monitor, err = prometheusmetrics.New(ctx,
prometheusmetrics.WithLogLevel(util.LogLevel("metrics.prometheus")),
prometheusmetrics.WithAddress(viper.GetString("metrics.prometheus.listen-address")),
prometheusmetrics.WithChainTime(chainTime),
prometheusmetrics.WithCreateServer(createServer),
)
if err != nil {
return nil, errors.Wrap(err, "failed to start prometheus metrics service")
}
log.Info().Str("listen_address", viper.GetString("metrics.prometheus.listen-address")).Msg("Started prometheus metrics service")
} else {
log.Debug().Msg("No metrics service supplied; monitor not starting")
monitor = nullmetrics.New()
}
return monitor, nil
}
// selectScheduler selects the appropriate scheduler given user input.
func selectScheduler(ctx context.Context, monitor metrics.Service) (scheduler.Service, error) {
var scheduler scheduler.Service
var err error
switch viper.GetString("scheduler.style") {
case "basic":
log.Warn().Msg("Basic scheduler is no longer available; defaulting to advanced scheduler. To avoid this message in future please change your scheduler type to 'advanced'")
scheduler, err = advancedscheduler.New(ctx,
advancedscheduler.WithLogLevel(util.LogLevel("scheduler.advanced")),
advancedscheduler.WithMonitor(monitor),
)
default:
log.Info().Msg("Starting advanced scheduler")
scheduler, err = advancedscheduler.New(ctx,
advancedscheduler.WithLogLevel(util.LogLevel("scheduler.advanced")),
advancedscheduler.WithMonitor(monitor),
)
}
if err != nil {
return nil, errors.Wrap(err, "failed to start scheduler service")
}
return scheduler, nil
}
// startCache starts the relevant cache given user input.
func startCache(ctx context.Context,
monitor metrics.Service,
chainTime chaintime.Service,
scheduler scheduler.Service,
consensusClient eth2client.Service,
beaconBlockHeaderProvider eth2client.BeaconBlockHeadersProvider,
signedBeaconBlockProvider eth2client.SignedBeaconBlockProvider,
) (cache.Service, error) {
log.Trace().Msg("Starting cache")
cache, err := standardcache.New(ctx,
standardcache.WithLogLevel(util.LogLevel("cache.standard")),
standardcache.WithMonitor(monitor),
standardcache.WithScheduler(scheduler),
standardcache.WithChainTime(chainTime),
standardcache.WithEventsProvider(consensusClient.(eth2client.EventsProvider)),
standardcache.WithSignedBeaconBlockProvider(signedBeaconBlockProvider),
standardcache.WithBeaconBlockHeadersProvider(beaconBlockHeaderProvider),
)
if err != nil {
return nil, err
}
return cache, nil
}
// startGraffitiProvider starts the appropriate graffiti provider given user input.
func startGraffitiProvider(ctx context.Context, majordomo majordomo.Service) (graffitiprovider.Service, error) {
switch {
case viper.Get("graffiti.dynamic") != nil:
log.Info().Msg("Starting dynamic graffiti provider")
return dynamicgraffitiprovider.New(ctx,
dynamicgraffitiprovider.WithMajordomo(majordomo),
dynamicgraffitiprovider.WithLogLevel(util.LogLevel("graffiti.dynamic")),
dynamicgraffitiprovider.WithLocation(viper.GetString("graffiti.dynamic.location")),
dynamicgraffitiprovider.WithFallbackLocation(viper.GetString("graffiti.dynamic.fallback-location")),
)