This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
/
cmd.go
803 lines (724 loc) · 22.5 KB
/
cmd.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
package query
import (
"context"
"encoding/json"
"fmt"
"math/big"
"os"
"path/filepath"
"strconv"
"time"
"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/base"
"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/orchestrator"
"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/relayer"
"github.com/spf13/viper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
common2 "github.com/ethereum/go-ethereum/common"
celestiatypes "github.com/celestiaorg/celestia-app/x/qgb/types"
"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/common"
"github.com/celestiaorg/orchestrator-relayer/p2p"
"github.com/celestiaorg/orchestrator-relayer/rpc"
"github.com/celestiaorg/orchestrator-relayer/types"
ds "github.com/ipfs/go-datastore"
dssync "github.com/ipfs/go-datastore/sync"
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/pkg/errors"
"github.com/spf13/cobra"
tmlog "github.com/tendermint/tendermint/libs/log"
)
func Command() *cobra.Command {
queryCmd := &cobra.Command{
Use: "query",
Aliases: []string{"q"},
Short: "Query relevant information from a running Blobstream",
SilenceUsage: true,
}
queryCmd.AddCommand(
Signers(),
Signature(),
)
queryCmd.SetHelpCommand(&cobra.Command{})
return queryCmd
}
func Signers() *cobra.Command {
signersCmd := &cobra.Command{
Use: "signers",
Aliases: []string{"s"},
Short: "Query orchestrators information that are running blobstream",
SilenceUsage: true,
}
signersCmd.AddCommand(
SignersNonce(),
SignersRange(),
)
signersCmd.SetHelpCommand(&cobra.Command{})
return signersCmd
}
func SignersNonce() *cobra.Command {
command := &cobra.Command{
Use: "nonce <nonce>",
Args: cobra.ExactArgs(1),
Short: "Queries the Blobstream for attestations signers by nonce",
Long: "Queries the Blobstream for attestations signers. The nonce is the attestation nonce that the command" +
" will query signatures for. It should be either a specific nonce starting from 2 and on." +
" Or, use 'latest' as argument to check the latest attestation nonce",
RunE: func(cmd *cobra.Command, args []string) error {
// creating the logger
logger := tmlog.NewTMLogger(os.Stdout)
fileConfig, err := tryToGetExistingConfig(cmd, logger)
if err != nil {
return err
}
config, err := parseFlags(cmd, &fileConfig)
if err != nil {
return err
}
logger.Debug("initializing queriers")
ctx, cancel := context.WithCancel(cmd.Context())
defer cancel()
tmQuerier, appQuerier, p2pQuerier, stopFuncs, err := startResources(ctx, config, logger)
if err != nil {
return err
}
defer func() {
for _, f := range stopFuncs {
err := f()
if err != nil {
logger.Error(err.Error())
}
}
}()
nonce, err := parseNonce(ctx, appQuerier, args[0])
if err != nil {
return err
}
if nonce == 1 {
return fmt.Errorf("nonce 1 doesn't need to be signed. signatures start from nonce 2")
}
qOutput, err := getSignatures(ctx, logger, appQuerier, tmQuerier, p2pQuerier, nonce)
if err != nil {
return err
}
if config.outputFile == "" {
printConfirms(logger, *qOutput)
} else {
err := writeConfirmsToJSONFile(logger, *qOutput, config.outputFile)
if err != nil {
return err
}
}
return nil
},
}
return addFlags(command)
}
func startResources(ctx context.Context, config Config, logger tmlog.Logger) (*rpc.TmQuerier, *rpc.AppQuerier, *p2p.Querier, []func() error, error) {
stopFuncs := make([]func() error, 0, 1)
// create tm querier and app querier
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(
logger,
config.coreRPC,
config.coreGRPC,
config.grpcInsecure,
)
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return nil, nil, nil, stopFuncs, err
}
// creating the host
h, err := libp2p.New()
if err != nil {
return nil, nil, nil, stopFuncs, err
}
addrInfo, err := peer.AddrInfoFromString(config.targetNode)
if err != nil {
return nil, nil, nil, stopFuncs, err
}
for i := 0; i < 5; i++ {
logger.Debug("connecting to target node...")
err := h.Connect(ctx, *addrInfo)
if err != nil {
logger.Error("couldn't connect to target node", "err", err.Error())
}
if err == nil {
logger.Debug("connected to target node")
break
}
time.Sleep(5 * time.Second)
}
// creating the data store
dataStore := dssync.MutexWrap(ds.NewMapDatastore())
// creating the dht
dht, err := p2p.NewBlobstreamDHT(ctx, h, dataStore, []peer.AddrInfo{}, logger)
if err != nil {
return nil, nil, nil, stopFuncs, err
}
// creating the p2p querier
p2pQuerier := p2p.NewQuerier(dht, logger)
return tmQuerier, appQuerier, p2pQuerier, stopFuncs, nil
}
func SignersRange() *cobra.Command {
command := &cobra.Command{
Use: "range <start_nonce> <end_nonce>",
Args: cobra.ExactArgs(2),
Short: "Queries the Blobstream for the orchestrators that signed a certain range of nonces",
Long: "Queries the Blobstream for attestations signers. The range of the nonces can start from two" +
" and can use the keyword `latest` to denominate the latest nonce. The range is end exclusive.",
RunE: func(cmd *cobra.Command, args []string) error {
// creating the logger
logger := tmlog.NewTMLogger(os.Stdout)
fileConfig, err := tryToGetExistingConfig(cmd, logger)
if err != nil {
return err
}
config, err := parseFlags(cmd, &fileConfig)
if err != nil {
return err
}
logger.Debug("initializing queriers")
ctx, cancel := context.WithCancel(cmd.Context())
defer cancel()
tmQuerier, appQuerier, p2pQuerier, stopFuncs, err := startResources(ctx, config, logger)
if err != nil {
return err
}
defer func() {
for _, f := range stopFuncs {
err := f()
if err != nil {
logger.Error(err.Error())
}
}
}()
if args[0] == "latest" {
return fmt.Errorf("start nonce can't be the `latest` nonce")
}
startNonce, err := parseNonce(ctx, appQuerier, args[0])
if err != nil {
return err
}
endNonce, err := parseNonce(ctx, appQuerier, args[1])
if err != nil {
return err
}
err = validateRange(startNonce, endNonce)
if err != nil {
return err
}
qOutputs := make([]*queryOutput, endNonce-startNonce)
for nonce := startNonce; nonce < endNonce; nonce++ {
qOutputs[nonce-startNonce], err = getSignatures(ctx, logger, appQuerier, tmQuerier, p2pQuerier, nonce)
if err != nil {
return err
}
}
signersMap := make(map[validatorInfo]uint64)
for _, qOutput := range qOutputs {
for _, sig := range qOutput.Signatures {
if sig.Signed {
// increment the number of the signatures
signersMap[validatorInfo{
EvmAddress: sig.EvmAddress,
Moniker: sig.Moniker,
ValopAddress: sig.ValopAddress,
}]++
} else {
// keep the same number of signatures the same but still have the value in the map
val := signersMap[validatorInfo{
EvmAddress: sig.EvmAddress,
Moniker: sig.Moniker,
ValopAddress: sig.ValopAddress,
}]
signersMap[validatorInfo{
EvmAddress: sig.EvmAddress,
Moniker: sig.Moniker,
ValopAddress: sig.ValopAddress,
}] = val
}
}
}
if config.outputFile == "" {
printSignersForRange(logger, signersMap)
} else {
err := writeSignersForRangeToJSONFile(logger, signersMap, config.outputFile)
if err != nil {
return err
}
}
return nil
},
}
return addFlags(command)
}
func writeSignersForRangeToJSONFile(logger tmlog.Logger, signersMap map[validatorInfo]uint64, outputFile string) error {
logger.Info("writing number of signatures to json file", "path", outputFile)
file, err := os.OpenFile(outputFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
if err != nil {
return err
}
defer func(file *os.File) {
err := file.Close()
if err != nil {
logger.Error("failed to close file", "err", err.Error())
}
}(file)
encoder := json.NewEncoder(file)
type encodedSignersStruct struct {
EvmAddress string `json:"evmAddress"`
Moniker string `json:"moniker"`
ValopAddress string `json:"valopAddress"`
NumberOfSignatures uint64 `json:"number_of_signatures"`
}
encodedSigners := make([]encodedSignersStruct, 0)
for key, val := range signersMap {
encodedSigners = append(encodedSigners, encodedSignersStruct{
EvmAddress: key.EvmAddress,
Moniker: key.Moniker,
ValopAddress: key.ValopAddress,
NumberOfSignatures: val,
})
}
err = encoder.Encode(encodedSigners)
if err != nil {
return err
}
logger.Info("output written to file successfully", "path", outputFile)
return nil
}
func printSignersForRange(logger tmlog.Logger, signersMap map[validatorInfo]uint64) {
for signer, numberOfSignatures := range signersMap {
logger.Info(signer.Moniker, "evm_address", signer.EvmAddress, "valop_address", signer.ValopAddress, "number_of_signatures", numberOfSignatures)
}
logger.Info("done")
}
func validateRange(start uint64, end uint64) error {
if start == 0 {
return fmt.Errorf("start cannot be 0. attestations start at 1")
}
if end == 0 {
return fmt.Errorf("end cannot be 0. attestations start at 1")
}
if start == end {
return fmt.Errorf("start cannot be equal to end")
}
if start > end {
return fmt.Errorf("start cannot be higher than end")
}
return nil
}
type signature struct {
EvmAddress string `json:"evmAddress"`
Moniker string `json:"moniker"`
Signature string `json:"signature"`
Signed bool `json:"signed"`
ValopAddress string `json:"valopAddress"`
}
type validatorInfo struct {
EvmAddress string `json:"evmAddress"`
Moniker string `json:"moniker"`
ValopAddress string `json:"valopAddress"`
}
type queryOutput struct {
Signatures []signature `json:"signatures"`
Nonce uint64 `json:"nonce"`
MajorityThreshold uint64 `json:"majority_threshold"`
CurrentThreshold uint64 `json:"current_threshold"`
CanRelay bool `json:"can_relay"`
}
func getSignatures(
ctx context.Context,
logger tmlog.Logger,
appQuerier *rpc.AppQuerier,
tmQuerier *rpc.TmQuerier,
p2pQuerier *p2p.Querier,
nonce uint64,
) (*queryOutput, error) {
logger.Info("getting signatures for nonce", "nonce", nonce)
lastValset, err := appQuerier.QueryLastValsetBeforeNonce(ctx, nonce)
if err != nil {
return nil, err
}
validatorSet, err := appQuerier.QueryStakingValidatorSet(ctx)
if err != nil {
return nil, err
}
validatorsInfo, err := toValidatorsInfo(ctx, appQuerier, validatorSet)
if err != nil {
return nil, err
}
att, err := appQuerier.QueryAttestationByNonce(ctx, nonce)
if err != nil {
return nil, err
}
if att == nil {
return nil, celestiatypes.ErrAttestationNotFound
}
switch castedAtt := att.(type) {
case *celestiatypes.Valset:
signBytes, err := castedAtt.SignBytes()
if err != nil {
return nil, err
}
confirms, err := p2pQuerier.QueryValsetConfirms(ctx, nonce, *lastValset, signBytes.Hex())
if err != nil {
return nil, err
}
qOutput := toQueryOutput(toValsetConfirmsMap(confirms), validatorsInfo, nonce, *lastValset)
return &qOutput, nil
case *celestiatypes.DataCommitment:
commitment, err := tmQuerier.QueryCommitment(
ctx,
castedAtt.BeginBlock,
castedAtt.EndBlock,
)
if err != nil {
return nil, err
}
dataRootHash := types.DataCommitmentTupleRootSignBytes(big.NewInt(int64(castedAtt.Nonce)), commitment)
confirms, err := p2pQuerier.QueryDataCommitmentConfirms(ctx, *lastValset, nonce, dataRootHash.Hex())
if err != nil {
return nil, err
}
qOutput := toQueryOutput(toDataCommitmentConfirmsMap(confirms), validatorsInfo, nonce, *lastValset)
return &qOutput, nil
default:
return nil, errors.Wrap(types.ErrUnknownAttestationType, strconv.FormatUint(nonce, 10))
}
}
func toValidatorsInfo(ctx context.Context, appQuerier *rpc.AppQuerier, validatorSet []stakingtypes.Validator) (map[string]validatorInfo, error) {
validatorsInfo := make(map[string]validatorInfo)
for _, val := range validatorSet {
evmAddr, err := appQuerier.QueryEVMAddress(ctx, val.OperatorAddress)
if err != nil {
return nil, err
}
if evmAddr != "" {
validatorsInfo[evmAddr] = validatorInfo{
EvmAddress: evmAddr,
Moniker: val.GetMoniker(),
ValopAddress: val.OperatorAddress,
}
}
}
return validatorsInfo, nil
}
func parseNonce(ctx context.Context, querier *rpc.AppQuerier, nonce string) (uint64, error) {
switch nonce {
case "latest":
return querier.QueryLatestAttestationNonce(ctx)
default:
return strconv.ParseUint(nonce, 10, 0)
}
}
func toValsetConfirmsMap(confirms []types.ValsetConfirm) map[string]string {
// create a map for the signatures to get them easily
confirmsMap := make(map[string]string)
for _, confirm := range confirms {
confirmsMap[confirm.EthAddress] = confirm.Signature
}
return confirmsMap
}
func toDataCommitmentConfirmsMap(confirms []types.DataCommitmentConfirm) map[string]string {
// create a map for the signatures to get them easily
confirmsMap := make(map[string]string)
for _, confirm := range confirms {
confirmsMap[confirm.EthAddress] = confirm.Signature
}
return confirmsMap
}
func toQueryOutput(confirmsMap map[string]string, validatorsInfo map[string]validatorInfo, nonce uint64, lastValset celestiatypes.Valset) queryOutput {
currThreshold := uint64(0)
signatures := make([]signature, len(lastValset.Members))
// create the signature slice to be used for outputting the data
for key, val := range lastValset.Members {
sig, found := confirmsMap[val.EvmAddress]
if found {
signatures[key] = signature{
EvmAddress: val.EvmAddress,
Signature: sig,
Signed: true,
Moniker: validatorsInfo[val.EvmAddress].Moniker,
ValopAddress: validatorsInfo[val.EvmAddress].ValopAddress,
}
currThreshold += val.Power
} else {
signatures[key] = signature{
EvmAddress: val.EvmAddress,
Signature: "",
Signed: false,
Moniker: validatorsInfo[val.EvmAddress].Moniker,
ValopAddress: validatorsInfo[val.EvmAddress].ValopAddress,
}
}
}
return queryOutput{
Signatures: signatures,
Nonce: nonce,
MajorityThreshold: lastValset.TwoThirdsThreshold(),
CurrentThreshold: currThreshold,
CanRelay: lastValset.TwoThirdsThreshold() <= currThreshold,
}
}
func printConfirms(logger tmlog.Logger, qOutput queryOutput) {
logger.Info(
"query output",
"nonce",
qOutput.Nonce,
"majority_threshold",
qOutput.MajorityThreshold,
"current_threshold",
qOutput.CurrentThreshold,
"can_relay",
qOutput.CanRelay,
)
logger.Info("orchestrators that signed the attestation")
for _, sig := range qOutput.Signatures {
if sig.Signed {
logger.Info(sig.Moniker, "signed", sig.Signed, "evm_address", sig.EvmAddress, "valop_address", sig.ValopAddress, "signature", sig.Signature)
}
}
logger.Info("orchestrators that missed signing the attestation")
for _, sig := range qOutput.Signatures {
if !sig.Signed {
logger.Info(sig.Moniker, "signed", sig.Signed, "evm_address", sig.EvmAddress, "valop_address", sig.ValopAddress)
}
}
logger.Info("done")
}
func writeConfirmsToJSONFile(logger tmlog.Logger, qOutput queryOutput, outputFile string) error {
logger.Info("writing confirms json file", "path", outputFile)
file, err := os.OpenFile(outputFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
if err != nil {
return err
}
defer func(file *os.File) {
err := file.Close()
if err != nil {
logger.Error("failed to close file", "err", err.Error())
}
}(file)
encoder := json.NewEncoder(file)
err = encoder.Encode(qOutput)
if err != nil {
return err
}
logger.Info("output written to file successfully", "path", outputFile)
return nil
}
func Signature() *cobra.Command {
command := &cobra.Command{
Use: "signature <nonce> <evm_account>",
Args: cobra.ExactArgs(2),
Short: "Queries a specific signature referenced by an EVM account address and a nonce",
Long: "Queries a specific signature referenced by an EVM account address and a nonce. The nonce is the attestation" +
" nonce that the command will query signatures for. The EVM address is the address registered by the validator " +
"in the staking module.",
RunE: func(cmd *cobra.Command, args []string) error {
// creating the logger
logger := tmlog.NewTMLogger(os.Stdout)
fileConfig, err := tryToGetExistingConfig(cmd, logger)
if err != nil {
return err
}
config, err := parseFlags(cmd, &fileConfig)
if err != nil {
return err
}
logger.Debug("initializing queriers")
ctx, cancel := context.WithCancel(cmd.Context())
defer cancel()
stopFuncs := make([]func() error, 0, 1)
defer func() {
for _, f := range stopFuncs {
err := f()
if err != nil {
logger.Error(err.Error())
}
}
}()
// create tm querier and app querier
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC, config.grpcInsecure)
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return err
}
// creating the host
h, err := libp2p.New()
if err != nil {
return err
}
addrInfo, err := peer.AddrInfoFromString(config.targetNode)
if err != nil {
return err
}
for i := 0; i < 5; i++ {
logger.Debug("connecting to target node...")
err := h.Connect(ctx, *addrInfo)
if err != nil {
logger.Error("couldn't connect to target node", "err", err.Error())
}
if err == nil {
logger.Debug("connected to target node")
break
}
time.Sleep(5 * time.Second)
}
// creating the data store
dataStore := dssync.MutexWrap(ds.NewMapDatastore())
// creating the dht
dht, err := p2p.NewBlobstreamDHT(cmd.Context(), h, dataStore, []peer.AddrInfo{}, logger)
if err != nil {
return err
}
// creating the p2p querier
p2pQuerier := p2p.NewQuerier(dht, logger)
nonce, err := parseNonce(ctx, appQuerier, args[0])
if err != nil {
return err
}
if nonce == 1 {
return fmt.Errorf("nonce 1 doesn't need to be signed. signatures start from nonce 2")
}
if !common2.IsHexAddress(args[1]) {
return fmt.Errorf("invalid EVM address provided")
}
err = getSignatureAndPrintIt(ctx, logger, appQuerier, tmQuerier, p2pQuerier, args[1], nonce)
if err != nil {
return err
}
return nil
},
}
return addFlags(command)
}
func getSignatureAndPrintIt(
ctx context.Context,
logger tmlog.Logger,
appQuerier *rpc.AppQuerier,
tmQuerier *rpc.TmQuerier,
p2pQuerier *p2p.Querier,
evmAddress string,
nonce uint64,
) error {
logger.Info("getting signature for address and nonce", "nonce", nonce, "evm_account", evmAddress)
att, err := appQuerier.QueryAttestationByNonce(ctx, nonce)
if err != nil {
return err
}
if att == nil {
return celestiatypes.ErrAttestationNotFound
}
switch castedAtt := att.(type) {
case *celestiatypes.Valset:
signBytes, err := castedAtt.SignBytes()
if err != nil {
return err
}
confirm, err := p2pQuerier.QueryValsetConfirmByEVMAddress(ctx, nonce, evmAddress, signBytes.Hex())
if err != nil {
return err
}
if confirm == nil {
logger.Info("couldn't find orchestrator signature", "nonce", nonce, "evm_account", evmAddress)
} else {
logger.Info("found orchestrator signature", "nonce", nonce, "evm_account", evmAddress, "signature", confirm.Signature)
}
case *celestiatypes.DataCommitment:
commitment, err := tmQuerier.QueryCommitment(
ctx,
castedAtt.BeginBlock,
castedAtt.EndBlock,
)
if err != nil {
return err
}
dataRootHash := types.DataCommitmentTupleRootSignBytes(big.NewInt(int64(castedAtt.Nonce)), commitment)
confirm, err := p2pQuerier.QueryDataCommitmentConfirmByEVMAddress(ctx, nonce, evmAddress, dataRootHash.Hex())
if err != nil {
return err
}
if confirm == nil {
logger.Info("couldn't find orchestrator signature", "nonce", nonce, "evm_account", evmAddress)
} else {
logger.Info("found orchestrator signature", "nonce", nonce, "evm_account", evmAddress, "signature", confirm.Signature)
}
default:
return errors.Wrap(types.ErrUnknownAttestationType, strconv.FormatUint(nonce, 10))
}
return nil
}
// tryToGetExistingConfig tries to get the query config from existing
// orchestrator/relayer homes. It first checks whether the `--home` flag was
// changed. If so, it gets the config from there. If not, then it tries the
// orchestrator default home directory, then the relayer default home directory.
func tryToGetExistingConfig(cmd *cobra.Command, logger tmlog.Logger) (Config, error) {
v := viper.New()
v.SetEnvPrefix("")
v.AutomaticEnv()
homeDir, changed, err := base.GetHomeFlag(cmd)
if err != nil {
return Config{}, err
}
// the --home flag was set to some directory
if changed && homeDir != "" {
logger.Debug("using home", "home", homeDir)
configPath := filepath.Join(homeDir, "config")
// assume this home is an orchestrator home directory
orchConf, err := orchestrator.GetStartConfig(v, configPath)
if err == nil {
// it is an orchestrator, so we get the config from it
return *NewPartialConfig(
orchConf.CoreGRPC,
orchConf.CoreRPC,
orchConf.Bootstrappers,
orchConf.GRPCInsecure,
), nil
}
// assume this home is a relayer home directory
relConf, err := relayer.GetStartConfig(v, configPath)
if err == nil {
// it is a relayer, so we get the config from it
return *NewPartialConfig(
relConf.CoreGRPC,
relConf.CoreRPC,
relConf.Bootstrappers,
relConf.GrpcInsecure,
), nil
}
return Config{}, fmt.Errorf("the provided home directory is neither an orchestrator nor a relayer home directory")
}
// try to get the config from the orchestrator home directory
orchHome, err := base.GetHomeDirectory(cmd, orchestrator.ServiceNameOrchestrator)
if err != nil {
return Config{}, err
}
orchConf, err := orchestrator.GetStartConfig(v, filepath.Join(orchHome, "config"))
if err == nil {
// found orchestrator home, get the config from it
logger.Debug("using home", "home", orchHome)
return *NewPartialConfig(
orchConf.CoreGRPC,
orchConf.CoreRPC,
orchConf.Bootstrappers,
orchConf.GRPCInsecure,
), nil
}
// try to get the config from the relayer home directory
relHome, err := base.GetHomeDirectory(cmd, relayer.ServiceNameRelayer)
if err != nil {
return Config{}, err
}
relConf, err := relayer.GetStartConfig(v, filepath.Join(relHome, "config"))
if err == nil {
// found relayer home, so we get the config from it
logger.Debug("using home", "home", relHome)
return *NewPartialConfig(
relConf.CoreGRPC,
relConf.CoreRPC,
relConf.Bootstrappers,
relConf.GrpcInsecure,
), nil
}
return *DefaultConfig(), nil
}