-
Notifications
You must be signed in to change notification settings - Fork 656
/
gaspricesuggester.go
43 lines (38 loc) · 1.17 KB
/
gaspricesuggester.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
package gasprice
import (
"context"
"time"
"github.com/0xPolygonHermez/zkevm-node/etherman"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/state"
)
// L2GasPricer interface for gas price suggester.
type L2GasPricer interface {
UpdateGasPriceAvg()
}
// NewL2GasPriceSuggester init.
func NewL2GasPriceSuggester(ctx context.Context, cfg Config, pool pool, ethMan *etherman.Client, state *state.State) {
var gpricer L2GasPricer
switch cfg.Type {
case LastNBatchesType:
log.Info("Lastnbatches type selected")
gpricer = newLastNL2BlocksGasPriceSuggester(ctx, cfg, state, pool)
case FollowerType:
log.Info("Follower type selected")
gpricer = newFollowerGasPriceSuggester(ctx, cfg, pool, ethMan)
case DefaultType:
log.Info("Default type selected")
gpricer = newDefaultGasPriceSuggester(ctx, cfg, pool)
default:
log.Fatal("unknown l2 gas price suggester type ", cfg.Type, ". Please specify a valid one: 'lastnbatches', 'follower' or 'default'")
}
for {
select {
case <-ctx.Done():
log.Info("Finishing l2 gas price suggester...")
return
case <-time.After(cfg.UpdatePeriod.Duration):
gpricer.UpdateGasPriceAvg()
}
}
}