-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
wait_header_synced.go
48 lines (42 loc) · 1.07 KB
/
wait_header_synced.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
package processor
import (
"context"
"time"
"github.com/pkg/errors"
"github.com/taikoxyz/taiko-mono/packages/relayer"
)
// waitHeaderSynced waits for a event to appear in the database from the indexer
// for the type "ChainDataSynced" to be greater or less than the given blockNum.
// this is used to make sure a valid proof can be generated and verified on chain.
func (p *Processor) waitHeaderSynced(
ctx context.Context,
ethClient ethClient,
hopChainId uint64,
blockNum uint64,
) (*relayer.Event, error) {
chainId, err := ethClient.ChainID(ctx)
if err != nil {
return nil, err
}
ticker := time.NewTicker(time.Duration(p.headerSyncIntervalSeconds) * time.Second)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-ticker.C:
event, err := p.eventRepo.ChainDataSyncedEventByBlockNumberOrGreater(
ctx,
hopChainId,
chainId.Uint64(),
blockNum,
)
if err != nil {
return nil, errors.Wrap(err, "p.eventRepo.ChainDataSyncedEventByBlockNumberOrGreater")
}
if event != nil {
return event, nil
}
}
}
}