-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
639 lines (579 loc) · 22.7 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
// Copyright © 2021 - 2024 Weald Technology Trading.
// 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 contains the entrypoint for execd.
package main
import (
"context"
"encoding/hex"
"fmt"
"net/http"
"time"
// #nosec G108
_ "net/http/pprof"
"os"
"os/signal"
"runtime"
"runtime/debug"
"strings"
"syscall"
execclient "github.com/attestantio/go-execution-client"
"github.com/attestantio/go-execution-client/types"
"github.com/fsnotify/fsnotify"
homedir "github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/wealdtech/execd/services/balances"
batchbalances "github.com/wealdtech/execd/services/balances/batch"
"github.com/wealdtech/execd/services/blockrewards"
batchblockrewards "github.com/wealdtech/execd/services/blockrewards/batch"
"github.com/wealdtech/execd/services/blocks"
batchblocks "github.com/wealdtech/execd/services/blocks/batch"
individualblocks "github.com/wealdtech/execd/services/blocks/individual"
execdb "github.com/wealdtech/execd/services/execdb"
postgresqlexecdb "github.com/wealdtech/execd/services/execdb/postgresql"
"github.com/wealdtech/execd/services/metrics"
nullmetrics "github.com/wealdtech/execd/services/metrics/null"
prometheusmetrics "github.com/wealdtech/execd/services/metrics/prometheus"
"github.com/wealdtech/execd/services/scheduler"
standardscheduler "github.com/wealdtech/execd/services/scheduler/standard"
"github.com/wealdtech/execd/util"
)
// ReleaseVersion is the release version for the code.
var ReleaseVersion = "0.5.3"
func main() {
os.Exit(main2())
}
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
}
if err := initLogging(); err != nil {
fmt.Fprintf(os.Stderr, "Failed to initialise logging: %v\n", err)
return 1
}
// runCommands will not return if a command is run.
runCommands(ctx)
logModules()
log.Info().Str("version", ReleaseVersion).Msg("Starting execd")
majordomo, err := util.InitMajordomo(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to initialise majordomo: %v\n", err)
return 1
}
if err := initTracing(ctx, majordomo); err != nil {
log.Error().Err(err).Msg("Failed to initialise tracing")
return 1
}
initProfiling()
runtime.GOMAXPROCS(runtime.NumCPU() * 8)
log.Trace().Msg("Starting metrics service")
monitor, err := startMonitor(ctx)
if err != nil {
log.Error().Err(err).Msg("Failed to start metrics service")
return 1
}
if err := registerMetrics(ctx, monitor); err != nil {
log.Error().Err(err).Msg("Failed to register metrics")
return 1
}
setRelease(ctx, ReleaseVersion)
setReady(ctx, false)
balances, err := startServices(ctx, monitor)
if err != nil {
log.Error().Err(err).Msg("Failed to initialise services")
return 1
}
setReady(ctx, true)
log.Info().Msg("All services operational")
// Handle configuration change.
viper.OnConfigChange(func(_ fsnotify.Event) {
log.Debug().Msg("Configuration change detected")
addresses := make([]types.Address, len(viper.GetStringSlice("balances.addresses")))
for i, str := range viper.GetStringSlice("balances.addresses") {
tmp, err := hex.DecodeString(strings.TrimPrefix(str, "0x"))
if err != nil {
log.Error().Err(err).Msg("Invalid balance address")
return
}
copy(addresses[i][:], tmp)
}
if balances != nil {
balances.SetAddresses(addresses)
}
})
viper.WatchConfig()
// Wait for signal.
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
for {
sig := <-sigCh
if sig == syscall.SIGINT || sig == syscall.SIGTERM || sig == os.Interrupt || sig == os.Kill {
break
}
}
log.Info().Msg("Stopping execd")
return 0
}
// fetchConfig fetches configuration from various sources.
func fetchConfig() error {
pflag.String("base-dir", "", "base directory for configuration files")
pflag.Bool("version", false, "show version and exit")
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.Uint32("track-distance", 64, "Number of blocks from head to fetch data")
pflag.Bool("blocks.enable", true, "Enable fetching of block-related information")
pflag.Bool("blocks.transactions.enable", true, "Enable fetching of transaction-related information (requires blocks to be enabled)")
pflag.Bool("blocks.transactions.events.enable", true, "Enable fetching of transaction event information (requires blocks and transactions to be enabled)")
pflag.Bool("blocks.transactions.balances.enable", true, "Enable fetching of balance change information (requires blocks and transactions to be enabled)")
pflag.Bool("blocks.transactions.storage.enable", true, "Enable fetching of storage change information (requires blocks and transactions to be enabled)")
pflag.String("blocks.style", "batch", "Use different blocks fetcher (available: batch, individual)")
pflag.Duration("blocks.interval", 10*time.Second, "Interval between block updates")
pflag.Int32("blocks.start-height", -1, "Slot from which to start fetching blocks")
pflag.Bool("balances.enable", true, "Enable fetching of balance-related information")
pflag.Int32("balances.start-height", -1, "Slot from which to start fetching balances")
pflag.String("balances.style", "batch", "Use different balances fetcher (available: batch)")
pflag.Duration("balances.interval", 10*time.Second, "Interval between balance updates")
pflag.Bool("blockrewards.enable", true, "Enable setting block reward information")
pflag.Int32("blockrewards.start-height", -1, "Slot from which to start setting block reward information")
pflag.Duration("blockrewards.interval", 10*time.Second, "Interval between block reward updates")
pflag.String("execclient.address", "", "Address for execution node JSON-RPC endpoint")
pflag.Duration("execclient.timeout", 60*time.Second, "Timeout for execution node requests")
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(util.ResolvePath(""))
viper.SetConfigName("execd")
} else {
// Home directory.
home, err := homedir.Dir()
if err != nil {
return errors.Wrap(err, "failed to obtain home directory")
}
viper.AddConfigPath(home)
viper.SetConfigName(".execd")
}
// Environment settings.
viper.SetEnvPrefix("EXECD")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_"))
viper.AutomaticEnv()
// Defaults.
viper.SetDefault("process-concurrency", int64(runtime.GOMAXPROCS(-1)))
if err := viper.ReadInConfig(); err != nil {
switch {
case errors.As(err, &viper.ConfigFileNotFoundError{}):
// It is allowable for execd 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 execution nodes configured, as if not we aren't going to
// get very far anyway.
if viper.Get("executionclient.addrees") == 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")
runtime.SetMutexProfileFraction(1)
server := &http.Server{
Addr: profileAddress,
ReadHeaderTimeout: 20 * time.Second,
}
if err := server.ListenAndServe(); err != nil {
log.Warn().Str("profile_address", profileAddress).Err(err).Msg("Failed to run profile server")
}
}()
}
}
func startMonitor(ctx context.Context) (metrics.Service, error) {
var monitor metrics.Service
if viper.Get("metrics.prometheus.listen-address") != nil {
var err error
monitor, err = prometheusmetrics.New(ctx,
prometheusmetrics.WithLogLevel(util.LogLevel("metrics.prometheus")),
prometheusmetrics.WithAddress(viper.GetString("metrics.prometheus.listen-address")),
)
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.Service{}
}
return monitor, nil
}
func startServices(ctx context.Context, monitor metrics.Service) (
balances.Service,
error,
) {
log.Trace().Msg("Starting exec database service")
execDB, err := postgresqlexecdb.New(ctx,
postgresqlexecdb.WithLogLevel(util.LogLevel("execdb")),
postgresqlexecdb.WithServer(viper.GetString("execdb.server")),
postgresqlexecdb.WithPort(viper.GetInt32("execdb.port")),
postgresqlexecdb.WithUser(viper.GetString("execdb.user")),
postgresqlexecdb.WithPassword(viper.GetString("execdb.password")),
)
if err != nil {
return nil, errors.Wrap(err, "failed to start exec database service")
}
log.Trace().Msg("Checking for schema upgrades")
if err := execDB.Upgrade(ctx); err != nil {
return nil, errors.Wrap(err, "failed to upgrade exec database")
}
log.Trace().Str("address", viper.GetString("execclient.address")).Msg("Fetching execution client")
execClient, err := fetchClient(ctx, viper.GetString("execclient.address"))
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %q", viper.GetString("execclient.address")))
}
if err != nil {
return nil, errors.Wrap(err, "failed to fetch execution client")
}
// Wait for the node to sync.
for {
syncState, err := execClient.(execclient.SyncingProvider).Syncing(ctx)
if err != nil {
log.Debug().Err(err).Msg("Failed to obtain node sync state; will re-test in 1 minute")
time.Sleep(time.Minute)
continue
}
if syncState == nil {
log.Debug().Msg("No node sync state; will re-test in 1 minute")
time.Sleep(time.Minute)
continue
}
if syncState.Syncing {
log.Debug().Msg("Node syncing; will re-test in 1 minute")
time.Sleep(time.Minute)
continue
}
break
}
scheduler, err := standardscheduler.New(ctx,
standardscheduler.WithLogLevel(util.LogLevel("scheduler")),
standardscheduler.WithMonitor(monitor),
)
if err != nil {
return nil, errors.Wrap(err, "failed to start scheduler service")
}
log.Trace().Msg("Starting blocks service")
if _, err := startBlocks(ctx, execClient, execDB, monitor, scheduler); err != nil {
return nil, errors.Wrap(err, "failed to start blocks service")
}
log.Trace().Msg("Starting balances service")
balances, err := startBalances(ctx, execClient, execDB, monitor, scheduler)
if err != nil {
return nil, errors.Wrap(err, "failed to start balances service")
}
log.Trace().Msg("Starting block rewards service")
if _, err := startBlockRewards(ctx, execDB, monitor); err != nil {
return nil, errors.Wrap(err, "failed to start block rewards service")
}
return balances, nil
}
func logModules() {
buildInfo, ok := debug.ReadBuildInfo()
if ok {
log.Trace().Str("path", buildInfo.Path).Msg("Main package")
for _, dep := range buildInfo.Deps {
log := log.Trace()
if dep.Replace == nil {
log = log.Str("path", dep.Path).Str("version", dep.Version)
} else {
log = log.Str("path", dep.Replace.Path).Str("version", dep.Replace.Version)
}
log.Msg("Dependency")
}
}
}
func startBlocks(
ctx context.Context,
execClient execclient.Service,
execDB execdb.Service,
monitor metrics.Service,
scheduler scheduler.Service,
) (
blocks.Service,
error,
) {
if !viper.GetBool("blocks.enable") {
return nil, nil
}
var err error
if viper.GetString("blocks.execclient.address") != "" {
execClient, err = fetchClient(ctx, viper.GetString("blocks.execclient.address"))
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %q", viper.GetString("blocks.execclient.address")))
}
}
chainHeightProvider, isProvider := execClient.(execclient.ChainHeightProvider)
if !isProvider {
return nil, errors.New("client does not provide chain height")
}
blocksProvider, isProvider := execClient.(execclient.BlocksProvider)
if !isProvider {
return nil, errors.New("client does not provide blocks")
}
blockReplaysProvider, isProvider := execClient.(execclient.BlockReplaysProvider)
if !isProvider {
return nil, errors.New("client does not provide block replays")
}
issuanceProvider, isProvider := execClient.(execclient.IssuanceProvider)
if isProvider {
// Confirm that it can fetch issuance.
_, err := issuanceProvider.Issuance(ctx, "1")
if err != nil {
// It can't, remove the provider.
log.Trace().Err(err).Msg("Failed to obtain test issuance")
issuanceProvider = nil
}
}
transactionReceiptsProvider, isProvider := execClient.(execclient.TransactionReceiptsProvider)
if !isProvider {
return nil, errors.New("client does not provide transaction receipts")
}
// blockTransactionReceiptsProvider, isProvider := execClient.(execclient.BlockTransactionReceiptsProvider)
// if !isProvider {
// return nil, errors.New("client does not provide block transaction receipts")
// }
blocksSetter, isSetter := execDB.(execdb.BlocksSetter)
if !isSetter {
return nil, errors.New("database does not store blocks")
}
transactionsSetter, isSetter := execDB.(execdb.TransactionsSetter)
if !isSetter {
return nil, errors.New("database does not store transactions")
}
transactionStateDiffsSetter, isSetter := execDB.(execdb.TransactionStateDiffsSetter)
if !isSetter {
return nil, errors.New("database does not store transaction state differences")
}
eventsSetter, isSetter := execDB.(execdb.EventsSetter)
if !isSetter {
return nil, errors.New("database does not store events")
}
var s blocks.Service
switch viper.GetString("blocks.style") {
case "individual":
s, err = individualblocks.New(ctx,
individualblocks.WithLogLevel(util.LogLevel("blocks.individual")),
individualblocks.WithMonitor(monitor),
individualblocks.WithScheduler(scheduler),
individualblocks.WithChainHeightProvider(chainHeightProvider),
individualblocks.WithBlocksProvider(blocksProvider),
individualblocks.WithBlockReplaysProvider(blockReplaysProvider),
individualblocks.WithIssuanceProvider(issuanceProvider),
individualblocks.WithTransactionReceiptsProvider(transactionReceiptsProvider),
individualblocks.WithBlocksSetter(blocksSetter),
individualblocks.WithTransactionsSetter(transactionsSetter),
individualblocks.WithTransactionStateDiffsSetter(transactionStateDiffsSetter),
individualblocks.WithEventsSetter(eventsSetter),
individualblocks.WithTrackDistance(viper.GetUint32("track-distance")),
individualblocks.WithStartHeight(viper.GetInt64("blocks.start-height")),
individualblocks.WithTransactions(viper.GetBool("blocks.transactions.enable")),
individualblocks.WithStorageChanges(viper.GetBool("blocks.transactions.storage.enable")),
individualblocks.WithBalanceChanges(viper.GetBool("blocks.transactions.balances.enable")),
individualblocks.WithTransactionEvents(viper.GetBool("blocks.transactions.events.enable")),
individualblocks.WithInterval(viper.GetDuration("blocks.interval")),
)
case "batch":
s, err = batchblocks.New(ctx,
batchblocks.WithLogLevel(util.LogLevel("blocks.batch")),
batchblocks.WithMonitor(monitor),
batchblocks.WithScheduler(scheduler),
batchblocks.WithChainHeightProvider(chainHeightProvider),
batchblocks.WithBlocksProvider(blocksProvider),
batchblocks.WithBlockReplaysProvider(blockReplaysProvider),
batchblocks.WithIssuanceProvider(issuanceProvider),
batchblocks.WithTransactionReceiptsProvider(transactionReceiptsProvider),
// batchblocks.WithBlockTransactionReceiptsProvider(blockTransactionReceiptsProvider),
batchblocks.WithBlocksSetter(blocksSetter),
batchblocks.WithTransactionsSetter(transactionsSetter),
batchblocks.WithTransactionStateDiffsSetter(transactionStateDiffsSetter),
batchblocks.WithEventsSetter(eventsSetter),
batchblocks.WithTrackDistance(viper.GetUint32("track-distance")),
batchblocks.WithStartHeight(viper.GetInt64("blocks.start-height")),
batchblocks.WithTransactions(viper.GetBool("blocks.transactions.enable")),
batchblocks.WithStorageChanges(viper.GetBool("blocks.transactions.storage.enable")),
batchblocks.WithBalanceChanges(viper.GetBool("blocks.transactions.balances.enable")),
batchblocks.WithTransactionEvents(viper.GetBool("blocks.transactions.events.enable")),
batchblocks.WithProcessConcurrency(util.ProcessConcurrency("blocks")),
batchblocks.WithInterval(viper.GetDuration("blocks.interval")),
)
default:
return nil, errors.New("unknown blocks style")
}
if err != nil {
return nil, errors.Wrap(err, "failed to create blocks service")
}
return s, nil
}
func startBalances(
ctx context.Context,
execClient execclient.Service,
execDB execdb.Service,
monitor metrics.Service,
scheduler scheduler.Service,
) (
balances.Service,
error,
) {
if !viper.GetBool("balances.enable") {
return nil, nil
}
var err error
if viper.GetString("balances.execclient.address") != "" {
execClient, err = fetchClient(ctx, viper.GetString("balances.execclient.address"))
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %q", viper.GetString("balances.execclient.address")))
}
}
chainHeightProvider, isProvider := execClient.(execclient.ChainHeightProvider)
if !isProvider {
return nil, errors.New("client does not provide chain height")
}
blocksProvider, isProvider := execClient.(execclient.BlocksProvider)
if !isProvider {
return nil, errors.New("client does not provide blocks")
}
balancesProvider, isProvider := execClient.(execclient.BalancesProvider)
if !isProvider {
return nil, errors.New("client does not provide balances")
}
balancesSetter, isSetter := execDB.(execdb.BalancesSetter)
if !isSetter {
return nil, errors.New("database does not store balances")
}
dbBalancesProvider, isProvider := execDB.(execdb.BalancesProvider)
if !isProvider {
return nil, errors.New("database does not provide balances")
}
if len(viper.GetStringSlice("balances.addresses")) == 0 {
log.Warn().Msg("Balances module enabled but no balance supplied; individual balances will not be stored")
// Not an error, but the end of our setup.
return nil, nil
}
addresses := make([]types.Address, len(viper.GetStringSlice("balances.addresses")))
for i, str := range viper.GetStringSlice("balances.addresses") {
tmp, err := hex.DecodeString(strings.TrimPrefix(str, "0x"))
if err != nil {
return nil, errors.Wrap(err, "invalid address")
}
copy(addresses[i][:], tmp)
}
var s balances.Service
switch viper.GetString("balances.style") {
case "individual":
return nil, errors.New("individual balances module not implemented")
case "batch":
s, err = batchbalances.New(ctx,
batchbalances.WithLogLevel(util.LogLevel("balances")),
batchbalances.WithMonitor(monitor),
batchbalances.WithScheduler(scheduler),
batchbalances.WithChainHeightProvider(chainHeightProvider),
batchbalances.WithBalancesProvider(balancesProvider),
batchbalances.WithBlocksProvider(blocksProvider),
batchbalances.WithBalancesSetter(balancesSetter),
batchbalances.WithDBBalancesProvider(dbBalancesProvider),
batchbalances.WithTrackDistance(viper.GetUint32("track-distance")),
batchbalances.WithAddresses(addresses),
batchbalances.WithStartHeight(viper.GetInt64("balances.start-height")),
batchbalances.WithProcessConcurrency(util.ProcessConcurrency("balances")),
batchbalances.WithInterval(viper.GetDuration("balances.interval")),
batchbalances.WithInterval(viper.GetDuration("balances.interval")),
)
default:
return nil, errors.New("unknown balances style")
}
if err != nil {
return nil, errors.Wrap(err, "failed to create balances service")
}
return s, nil
}
func startBlockRewards(
ctx context.Context,
execDB execdb.Service,
monitor metrics.Service,
) (
blocks.Service,
error,
) {
if !viper.GetBool("blockrewards.enable") {
return nil, nil
}
scheduler, err := standardscheduler.New(ctx,
standardscheduler.WithLogLevel(util.LogLevel("scheduler")),
standardscheduler.WithMonitor(monitor),
)
if err != nil {
return nil, errors.Wrap(err, "failed to start scheduler service")
}
blocksProvider, isProvider := execDB.(execdb.BlocksProvider)
if !isProvider {
return nil, errors.New("database does not provide blocks")
}
transactionsProvider, isProvider := execDB.(execdb.TransactionsProvider)
if !isProvider {
return nil, errors.New("database does not provide transactions")
}
transactionStateDiffsProvider, isProvider := execDB.(execdb.TransactionStateDiffsProvider)
if !isProvider {
return nil, errors.New("database does not provide transaction state diffs")
}
blockRewardsSetter, isSetter := execDB.(execdb.BlockRewardsSetter)
if !isSetter {
return nil, errors.New("database does not store block rewards")
}
var s blockrewards.Service
s, err = batchblockrewards.New(ctx,
batchblockrewards.WithLogLevel(util.LogLevel("blockrewards")),
batchblockrewards.WithMonitor(monitor),
batchblockrewards.WithScheduler(scheduler),
batchblockrewards.WithBlocksProvider(blocksProvider),
batchblockrewards.WithTransactionsProvider(transactionsProvider),
batchblockrewards.WithTransactionStateDiffsProvider(transactionStateDiffsProvider),
batchblockrewards.WithBlockRewardsSetter(blockRewardsSetter),
batchblockrewards.WithStartHeight(viper.GetInt64("blockrewards.start-height")),
batchblockrewards.WithProcessConcurrency(util.ProcessConcurrency("blockrewards")),
batchblockrewards.WithInterval(viper.GetDuration("blockrewards.interval")),
)
if err != nil {
return nil, errors.Wrap(err, "failed to create block rewards service")
}
return s, nil
}
func runCommands(_ context.Context) {
if viper.GetBool("version") {
fmt.Fprintf(os.Stdout, "%s\n", ReleaseVersion)
os.Exit(0)
}
}