-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
271 lines (228 loc) · 8.9 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
package gossip
import (
"fmt"
"math/big"
"time"
"github.com/skyhighblockchain/push-base/gossip/dagprocessor"
"github.com/skyhighblockchain/push-base/gossip/dagstream/streamleecher"
"github.com/skyhighblockchain/push-base/gossip/dagstream/streamseeder"
"github.com/skyhighblockchain/push-base/gossip/itemsfetcher"
"github.com/skyhighblockchain/push-base/inter/dag"
"github.com/skyhighblockchain/push-base/inter/idx"
"github.com/skyhighblockchain/push-base/utils/cachescale"
"github.com/syndtr/goleveldb/leveldb/opt"
"github.com/skyhighblockchain/skyhigh/eventcheck/heavycheck"
"github.com/skyhighblockchain/skyhigh/evmcore"
"github.com/skyhighblockchain/skyhigh/gossip/blockproc/verwatcher"
"github.com/skyhighblockchain/skyhigh/gossip/emitter"
"github.com/skyhighblockchain/skyhigh/gossip/evmstore"
"github.com/skyhighblockchain/skyhigh/gossip/filters"
"github.com/skyhighblockchain/skyhigh/gossip/gasprice"
)
const nominalSize uint = 1
type (
// ProtocolConfig is config for p2p protocol
ProtocolConfig struct {
// 0/M means "optimize only for throughput", N/0 means "optimize only for latency", N/M is a balanced mode
LatencyImportance int
ThroughputImportance int
EventsSemaphoreLimit dag.Metric
MsgsSemaphoreLimit dag.Metric
MsgsSemaphoreTimeout time.Duration
ProgressBroadcastPeriod time.Duration
Processor dagprocessor.Config
DagFetcher itemsfetcher.Config
TxFetcher itemsfetcher.Config
StreamLeecher streamleecher.Config
StreamSeeder streamseeder.Config
MaxInitialTxHashesSend int
MaxRandomTxHashesSend int
RandomTxHashesSendPeriod time.Duration
PeerCache PeerCacheConfig
}
// Config for the gossip service.
Config struct {
Emitter emitter.Config
TxPool evmcore.TxPoolConfig
FilterAPI filters.Config
TxIndex bool // Whether to enable indexing transactions and receipts or not
// Protocol options
Protocol ProtocolConfig
HeavyCheck heavycheck.Config
// Gas Price Oracle options
GPO gasprice.Config
VersionWatcher verwatcher.Config
// RPCGasCap is the global gas cap for eth-call variants.
RPCGasCap uint64 `toml:",omitempty"`
// RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for
// send-transction variants. The unit is ether.
RPCTxFeeCap float64 `toml:",omitempty"`
// allows only for EIP155 transactions.
AllowUnprotectedTxs bool
ExtRPCEnabled bool
RPCLogsBloom bool
}
StoreCacheConfig struct {
// Cache size for full events.
EventsNum int
EventsSize uint
// Cache size for full blocks.
BlocksNum int
BlocksSize uint
}
// StoreConfig is a config for store db.
StoreConfig struct {
Cache StoreCacheConfig
// EVM is EVM store config
EVM evmstore.StoreConfig
MaxNonFlushedSize int
MaxNonFlushedPeriod time.Duration
}
)
type PeerCacheConfig struct {
MaxKnownTxs int // Maximum transactions hashes to keep in the known list (prevent DOS)
MaxKnownEvents int // Maximum event hashes to keep in the known list (prevent DOS)
// MaxQueuedItems is the maximum number of items to queue up before
// dropping broadcasts. This is a sensitive number as a transaction list might
// contain a single transaction, or thousands.
MaxQueuedItems idx.Event
MaxQueuedSize uint64
}
// DefaultConfig returns the default configurations for the gossip service.
func DefaultConfig(scale cachescale.Func) Config {
cfg := Config{
Emitter: emitter.DefaultConfig(),
TxPool: evmcore.DefaultTxPoolConfig,
FilterAPI: filters.DefaultConfig(),
TxIndex: true,
HeavyCheck: heavycheck.DefaultConfig(),
Protocol: ProtocolConfig{
LatencyImportance: 60,
ThroughputImportance: 40,
MsgsSemaphoreLimit: dag.Metric{
Num: scale.Events(1000),
Size: scale.U64(30 * opt.MiB),
},
EventsSemaphoreLimit: dag.Metric{
Num: scale.Events(10000),
Size: scale.U64(30 * opt.MiB),
},
MsgsSemaphoreTimeout: 10 * time.Second,
ProgressBroadcastPeriod: 10 * time.Second,
Processor: dagprocessor.DefaultConfig(scale),
DagFetcher: itemsfetcher.Config{
ForgetTimeout: 1 * time.Minute,
ArriveTimeout: 1000 * time.Millisecond,
GatherSlack: 100 * time.Millisecond,
HashLimit: 20000,
MaxBatch: scale.I(512),
MaxQueuedBatches: scale.I(32),
MaxParallelRequests: 192,
},
TxFetcher: itemsfetcher.Config{
ForgetTimeout: 1 * time.Minute,
ArriveTimeout: 1000 * time.Millisecond,
GatherSlack: 100 * time.Millisecond,
HashLimit: 10000,
MaxBatch: scale.I(512),
MaxQueuedBatches: scale.I(32),
MaxParallelRequests: 64,
},
StreamLeecher: streamleecher.DefaultConfig(),
StreamSeeder: streamseeder.DefaultConfig(scale),
MaxInitialTxHashesSend: 20000,
MaxRandomTxHashesSend: 128,
RandomTxHashesSendPeriod: 20 * time.Second,
PeerCache: DefaultPeerCacheConfig(scale),
},
GPO: gasprice.Config{
MaxPrice: gasprice.DefaultMaxPrice,
MinPrice: new(big.Int),
MaxPriceMultiplierRatio: big.NewInt(20 * gasprice.DecimalUnit),
MiddlePriceMultiplierRatio: big.NewInt(4 * gasprice.DecimalUnit),
GasPowerWallRatio: big.NewInt(0.05 * gasprice.DecimalUnit),
},
VersionWatcher: verwatcher.Config{
ShutDownIfNotUpgraded: false,
WarningIfNotUpgradedEvery: 5 * time.Second,
},
RPCLogsBloom: true,
RPCGasCap: 25000000,
RPCTxFeeCap: 100, // 100 SKH
}
cfg.Protocol.Processor.EventsBufferLimit.Num = idx.Event(cfg.Protocol.StreamLeecher.Session.ParallelChunksDownload)*cfg.Protocol.StreamLeecher.Session.DefaultChunkSize.Num + softLimitItems
cfg.Protocol.Processor.EventsBufferLimit.Size = uint64(cfg.Protocol.StreamLeecher.Session.ParallelChunksDownload)*cfg.Protocol.StreamLeecher.Session.DefaultChunkSize.Size + 8*opt.MiB
cfg.Protocol.StreamLeecher.MaxSessionRestart = 4 * time.Minute
cfg.Protocol.DagFetcher.ArriveTimeout = 4 * time.Second
cfg.Protocol.DagFetcher.HashLimit = 10000
cfg.Protocol.TxFetcher.HashLimit = 10000
return cfg
}
func (c *Config) Validate() error {
if c.Protocol.StreamLeecher.Session.DefaultChunkSize.Num > hardLimitItems-1 {
return fmt.Errorf("DefaultChunkSize.Num has to be at not greater than %d", hardLimitItems-1)
}
if c.Protocol.StreamLeecher.Session.DefaultChunkSize.Size > protocolMaxMsgSize/2 {
return fmt.Errorf("DefaultChunkSize.Num has to be at not greater than %d", protocolMaxMsgSize/2)
}
if c.Protocol.EventsSemaphoreLimit.Num < 2*c.Protocol.StreamLeecher.Session.DefaultChunkSize.Num ||
c.Protocol.EventsSemaphoreLimit.Size < 2*c.Protocol.StreamLeecher.Session.DefaultChunkSize.Size {
return fmt.Errorf("EventsSemaphoreLimit has to be at least 2 times greater than %s (DefaultChunkSize)", c.Protocol.StreamLeecher.Session.DefaultChunkSize.String())
}
if c.Protocol.EventsSemaphoreLimit.Num < 2*c.Protocol.Processor.EventsBufferLimit.Num ||
c.Protocol.EventsSemaphoreLimit.Size < 2*c.Protocol.Processor.EventsBufferLimit.Size {
return fmt.Errorf("EventsSemaphoreLimit has to be at least 2 times greater than %s (EventsBufferLimit)", c.Protocol.Processor.EventsBufferLimit.String())
}
if c.Protocol.EventsSemaphoreLimit.Size < 2*protocolMaxMsgSize {
return fmt.Errorf("EventsSemaphoreLimit.Size has to be at least %d", 2*protocolMaxMsgSize)
}
if c.Protocol.MsgsSemaphoreLimit.Size < protocolMaxMsgSize {
return fmt.Errorf("MsgsSemaphoreLimit.Size has to be at least %d", protocolMaxMsgSize)
}
if c.Protocol.Processor.EventsBufferLimit.Size < protocolMaxMsgSize {
return fmt.Errorf("EventsBufferLimit.Size has to be at least %d", protocolMaxMsgSize)
}
return nil
}
// FakeConfig returns the default configurations for the gossip service in fakenet.
func FakeConfig(num int, scale cachescale.Func) Config {
cfg := DefaultConfig(scale)
cfg.Emitter = emitter.FakeConfig(num)
return cfg
}
// DefaultStoreConfig for product.
func DefaultStoreConfig(scale cachescale.Func) StoreConfig {
return StoreConfig{
Cache: StoreCacheConfig{
EventsNum: scale.I(5000),
EventsSize: scale.U(6 * opt.MiB),
BlocksNum: scale.I(5000),
BlocksSize: scale.U(512 * opt.KiB),
},
EVM: evmstore.DefaultStoreConfig(scale),
MaxNonFlushedSize: 17*opt.MiB + scale.I(5*opt.MiB),
MaxNonFlushedPeriod: 30 * time.Minute,
}
}
// LiteStoreConfig is for tests or inmemory.
func LiteStoreConfig() StoreConfig {
return StoreConfig{
Cache: StoreCacheConfig{
EventsNum: 500,
EventsSize: 512 * opt.KiB,
BlocksNum: 100,
BlocksSize: 50 * opt.KiB,
},
EVM: evmstore.LiteStoreConfig(),
MaxNonFlushedSize: 800 * opt.KiB,
MaxNonFlushedPeriod: 30 * time.Minute,
}
}
func DefaultPeerCacheConfig(scale cachescale.Func) PeerCacheConfig {
return PeerCacheConfig{
MaxKnownTxs: 24576*3/4 + scale.I(24576/4),
MaxKnownEvents: 24576*3/4 + scale.I(24576/4),
MaxQueuedItems: 4096*3/4 + scale.Events(4096/4),
MaxQueuedSize: protocolMaxMsgSize*3/4 + 1024 + scale.U64(protocolMaxMsgSize/4),
}
}