• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

synapsecns / sanguine / 2797188271

04 Aug 2022 02:03PM UTC coverage: 64.929% (-0.1%) from 65.047%
2797188271

Pull #72

github

Max Planck
add: - change _historicalRoots to internal - add getter for historicalRoots to HomeHarness
Pull Request #72: Add getHistoricalRoot function with tests. Readme updated

1657 of 2552 relevant lines covered (64.93%)

0.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.19
/core/agents/updater/updater.go
1
package updater
2

3
import (
4
        "context"
5
        "fmt"
6
        "github.com/synapsecns/sanguine/core/config"
7
        "github.com/synapsecns/sanguine/core/db/datastore/pebble"
8
        "github.com/synapsecns/sanguine/core/db/datastore/sql"
9
        "github.com/synapsecns/sanguine/core/domains/evm"
10
        "github.com/synapsecns/sanguine/core/indexer"
11
        "github.com/synapsecns/sanguine/ethergo/signer/signer"
12
        "golang.org/x/sync/errgroup"
13
        "time"
14
)
15

16
// Updater updates the updater.
17
type Updater struct {
18
        indexers   map[string]indexer.DomainIndexer
19
        producers  map[string]UpdateProducer
20
        submitters map[string]UpdateSubmitter
21
        signer     signer.Signer
22
}
23

24
// RefreshInterval is how long to wait before refreshing.
25
//TODO: This should be done in config.
26
var RefreshInterval = 1 * time.Second
27

28
// NewUpdater creates a new updater.
29
func NewUpdater(ctx context.Context, cfg config.Config) (_ Updater, err error) {
1✔
30
        updater := Updater{
1✔
31
                indexers:   make(map[string]indexer.DomainIndexer),
1✔
32
                producers:  make(map[string]UpdateProducer),
1✔
33
                submitters: make(map[string]UpdateSubmitter),
1✔
34
        }
1✔
35

1✔
36
        updater.signer, err = config.SignerFromConfig(cfg.Signer)
1✔
37
        if err != nil {
1✔
38
                return Updater{}, fmt.Errorf("could not create updater: %w", err)
×
39
        }
×
40

41
        dbType, err := sql.DBTypeFromString(cfg.Database.Type)
1✔
42
        if err != nil {
1✔
43
                return Updater{}, fmt.Errorf("could not get db type: %w", err)
×
44
        }
×
45

46
        txQueueDB, err := sql.NewStoreFromConfig(ctx, dbType, cfg.Database.ConnString)
1✔
47
        if err != nil {
1✔
48
                return Updater{}, fmt.Errorf("could not connect to db: %w", err)
×
49
        }
×
50

51
        for name, domain := range cfg.Domains {
2✔
52
                domainClient, err := evm.NewEVM(ctx, name, domain)
1✔
53
                if err != nil {
1✔
54
                        return Updater{}, fmt.Errorf("could not create updater for: %w", err)
×
55
                }
×
56

57
                dbHandle, err := pebble.NewMessageDB(cfg.Database.DBPath, name)
1✔
58
                if err != nil {
1✔
59
                        return Updater{}, fmt.Errorf("can not create messageDB: %w", err)
×
60
                }
×
61

62
                updater.indexers[name] = indexer.NewDomainIndexer(dbHandle, domainClient, RefreshInterval)
1✔
63
                updater.producers[name] = NewUpdateProducer(domainClient, dbHandle, updater.signer, RefreshInterval)
1✔
64
                updater.submitters[name] = NewUpdateSubmitter(domainClient, dbHandle, txQueueDB, updater.signer, RefreshInterval)
1✔
65
        }
66

67
        return updater, nil
1✔
68
}
69

70
// Start starts the updater.{.
71
func (u Updater) Start(ctx context.Context) error {
1✔
72
        g, ctx := errgroup.WithContext(ctx)
1✔
73
        for i := range u.indexers {
2✔
74
                i := i // capture func literal
1✔
75
                g.Go(func() error {
2✔
76
                        //nolint: wrapcheck
1✔
77
                        return u.indexers[i].SyncMessages(ctx)
1✔
78
                })
1✔
79
        }
80

81
        for i := range u.producers {
2✔
82
                i := i // capture func literal
1✔
83
                g.Go(func() error {
2✔
84
                        //nolint: wrapcheck
1✔
85
                        return u.producers[i].Start(ctx)
1✔
86
                })
1✔
87
        }
88

89
        for i := range u.submitters {
2✔
90
                i := i // capture func literal
1✔
91
                g.Go(func() error {
2✔
92
                        //nolint: wrapcheck
1✔
93
                        return u.submitters[i].Start(ctx)
1✔
94
                })
1✔
95
        }
96

97
        err := g.Wait()
1✔
98
        if err != nil {
1✔
99
                return fmt.Errorf("could not start the updater: %w", err)
×
100
        }
×
101

102
        return nil
×
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2024 Coveralls, Inc