This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstake_withdrawals.go
67 lines (56 loc) · 1.81 KB
/
stake_withdrawals.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
package commander
import (
"context"
"github.com/Worldcoin/hubble-commander/contracts/rollup"
"github.com/Worldcoin/hubble-commander/eth"
"github.com/Worldcoin/hubble-commander/metrics"
"github.com/Worldcoin/hubble-commander/models"
"github.com/Worldcoin/hubble-commander/storage"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/prometheus/client_golang/prometheus"
)
func (c *Commander) syncStakeWithdrawals(ctx context.Context, startBlock, endBlock uint64) error {
_, span := newBlockTracer.Start(ctx, "syncStakeWithdrawls")
defer span.End()
duration, err := metrics.MeasureDuration(func() (err error) {
err = c.unmeasuredSyncStakeWithdrawals(startBlock, endBlock)
return err
})
if err != nil {
return err
}
metrics.SaveHistogramMeasurement(duration, c.metrics.SyncingMethodDuration, prometheus.Labels{
"method": metrics.SyncStakeWithdrawalsMethod,
})
return nil
}
func (c *Commander) unmeasuredSyncStakeWithdrawals(startBlock, endBlock uint64) error {
it, err := c.getStakeWithdrawIterator(startBlock, endBlock)
if err != nil {
return err
}
defer func() { _ = it.Close() }()
for it.Next() {
if it.Event.Committed != c.client.Blockchain.GetAccount().From {
continue
}
// TODO: why are we ignoring the cases where it is not found? Should we
// at least log?
err = c.storage.RemovePendingStakeWithdrawal(models.MakeUint256FromBig(*it.Event.BatchID))
if err != nil && !storage.IsNotFoundError(err) {
return err
}
}
return nil
}
func (c *Commander) getStakeWithdrawIterator(start, end uint64) (*rollup.StakeWithdrawIterator, error) {
it := &rollup.StakeWithdrawIterator{}
err := c.client.FilterLogs(c.client.Rollup.BoundContract, eth.StakeWithdrawEvent, &bind.FilterOpts{
Start: start,
End: &end,
}, it)
if err != nil {
return nil, err
}
return it, nil
}