forked from okx/xlayer-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
67 lines (54 loc) · 2.51 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
67
package state
import (
"github.com/0xPolygonHermez/zkevm-node/config/types"
"github.com/0xPolygonHermez/zkevm-node/db"
)
// Config is state config
type Config struct {
// MaxCumulativeGasUsed is the max gas allowed per batch
MaxCumulativeGasUsed uint64
// ChainID is the L2 ChainID provided by the Network Config
ChainID uint64
// ForkIdIntervals is the list of fork id intervals
ForkIDIntervals []ForkIDInterval
// MaxResourceExhaustedAttempts is the max number of attempts to make a transaction succeed because of resource exhaustion
MaxResourceExhaustedAttempts int
// WaitOnResourceExhaustion is the time to wait before retrying a transaction because of resource exhaustion
WaitOnResourceExhaustion types.Duration
// Batch number from which there is a forkid change (fork upgrade)
ForkUpgradeBatchNumber uint64
// New fork id to be used for batches greaters than ForkUpgradeBatchNumber (fork upgrade)
ForkUpgradeNewForkId uint64
// DB is the database configuration
DB db.Config `mapstructure:"DB"`
// Configuration for the batch constraints
Batch BatchConfig `mapstructure:"Batch"`
}
// BatchConfig represents the configuration of the batch constraints
type BatchConfig struct {
Constraints BatchConstraintsCfg `mapstructure:"Constraints"`
}
// BatchConstraintsCfg represents the configuration of the batch constraints
type BatchConstraintsCfg struct {
MaxTxsPerBatch uint64 `mapstructure:"MaxTxsPerBatch"`
MaxBatchBytesSize uint64 `mapstructure:"MaxBatchBytesSize"`
MaxCumulativeGasUsed uint64 `mapstructure:"MaxCumulativeGasUsed"`
MaxKeccakHashes uint32 `mapstructure:"MaxKeccakHashes"`
MaxPoseidonHashes uint32 `mapstructure:"MaxPoseidonHashes"`
MaxPoseidonPaddings uint32 `mapstructure:"MaxPoseidonPaddings"`
MaxMemAligns uint32 `mapstructure:"MaxMemAligns"`
MaxArithmetics uint32 `mapstructure:"MaxArithmetics"`
MaxBinaries uint32 `mapstructure:"MaxBinaries"`
MaxSteps uint32 `mapstructure:"MaxSteps"`
}
// IsWithinConstraints checks if the counters are within the batch constraints
func (c BatchConstraintsCfg) IsWithinConstraints(counters ZKCounters) bool {
return counters.CumulativeGasUsed <= c.MaxCumulativeGasUsed &&
counters.UsedKeccakHashes <= c.MaxKeccakHashes &&
counters.UsedPoseidonHashes <= c.MaxPoseidonHashes &&
counters.UsedPoseidonPaddings <= c.MaxPoseidonPaddings &&
counters.UsedMemAligns <= c.MaxMemAligns &&
counters.UsedArithmetics <= c.MaxArithmetics &&
counters.UsedBinaries <= c.MaxBinaries &&
counters.UsedSteps <= c.MaxSteps
}