forked from 0xPolygonHermez/zkevm-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
66 lines (54 loc) · 2.36 KB
/
config.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
package aggregator
import (
"fmt"
"math/big"
"time"
"github.com/hermeznetwork/hermez-core/encoding"
)
// Duration is a wrapper type that parses time duration from text.
type Duration struct {
time.Duration `validate:"required"`
}
// UnmarshalText unmarshalls time duration from text.
func (d *Duration) UnmarshalText(data []byte) error {
duration, err := time.ParseDuration(string(data))
if err != nil {
return err
}
d.Duration = duration
return nil
}
// TokenAmountWithDecimals is a wrapper type that parses token amount with decimals to big int
type TokenAmountWithDecimals struct {
*big.Int `validate:"required"`
}
// UnmarshalText unmarshal token amount from float string to big int
func (t *TokenAmountWithDecimals) UnmarshalText(data []byte) error {
amount, ok := new(big.Float).SetString(string(data))
if !ok {
return fmt.Errorf("failed to unmarshal string to float")
}
coin := new(big.Float).SetInt(big.NewInt(encoding.TenToThePowerOf18))
bigval := new(big.Float).Mul(amount, coin)
result := new(big.Int)
bigval.Int(result)
t.Int = result
return nil
}
// Config represents the configuration of the aggregator
type Config struct {
// IntervalToConsolidateState is the time the aggregator waits until
// trying to consolidate a new state
IntervalToConsolidateState Duration `mapstructure:"IntervalToConsolidateState"`
// IntervalFrequencyToGetProofGenerationStateInSeconds is the time the aggregator waits until
// trying to get proof generation status, in case prover client returns PENDING state
IntervalFrequencyToGetProofGenerationStateInSeconds Duration `mapstructure:"IntervalFrequencyToGetProofGenerationStateInSeconds"`
// TxProfitabilityCheckerType type for checking is it profitable for aggregator to validate batch
// possible values: base/acceptall
TxProfitabilityCheckerType TxProfitabilityCheckerType `mapstructure:"TxProfitabilityCheckerType"`
// TxProfitabilityMinReward min reward for base tx profitability checker when aggregator will validate batch
// this parameter is used for the base tx profitability checker
TxProfitabilityMinReward TokenAmountWithDecimals `mapstructure:"TxProfitabilityMinReward"`
// IntervalAfterWhichBatchConsolidateAnyway this is interval for the main sequencer, that will check if there is no transactions
IntervalAfterWhichBatchConsolidateAnyway Duration `mapstructure:"IntervalAfterWhichBatchConsolidateAnyway"`
}