Skip to content

Commit 1ea4930

Browse files
authored
feat: improve config and use toml (#2047)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> -->
1 parent 104787b commit 1ea4930

45 files changed

Lines changed: 1641 additions & 1075 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Dockerfile‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#
33
FROM golang AS base
44

5-
RUN apt update && \
6-
apt-get install -y \
5+
RUN apt-get update && \
6+
apt-get install -y --no-install-recommends \
77
build-essential \
88
ca-certificates \
9-
curl
9+
curl \
10+
&& rm -rf /var/lib/apt/lists/*
1011

1112
# enable faster module downloading.
1213
ENV GOPROXY=https://proxy.golang.org
@@ -17,13 +18,12 @@ FROM base AS builder
1718

1819
WORKDIR /rollkit
1920

20-
# Copiar todo el código fuente primero
21+
# Copy all source code first
2122
COPY . .
2223

23-
# Ahora descargar las dependencias
24-
RUN go mod download
25-
26-
RUN make install
24+
# Now download dependencies and build
25+
RUN go mod download && \
26+
make install
2727

2828
## prep the final image.
2929
#

‎block/manager.go‎

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ type Manager struct {
115115
lastStateMtx *sync.RWMutex
116116
store store.Store
117117

118-
conf config.BlockManagerConfig
118+
config config.Config
119119
genesis *RollkitGenesis
120120

121121
proposerKey crypto.PrivKey
@@ -247,7 +247,7 @@ func getInitialState(ctx context.Context, genesis *RollkitGenesis, store store.S
247247
func NewManager(
248248
ctx context.Context,
249249
proposerKey crypto.PrivKey,
250-
conf config.BlockManagerConfig,
250+
config config.Config,
251251
genesis *RollkitGenesis,
252252
store store.Store,
253253
exec coreexecutor.Executor,
@@ -268,28 +268,28 @@ func NewManager(
268268
//set block height in store
269269
store.SetHeight(ctx, s.LastBlockHeight)
270270

271-
if s.DAHeight < conf.DAStartHeight {
272-
s.DAHeight = conf.DAStartHeight
271+
if s.DAHeight < config.DA.StartHeight {
272+
s.DAHeight = config.DA.StartHeight
273273
}
274274

275-
if conf.DABlockTime == 0 {
275+
if config.DA.BlockTime == 0 {
276276
logger.Info("Using default DA block time", "DABlockTime", defaultDABlockTime)
277-
conf.DABlockTime = defaultDABlockTime
277+
config.DA.BlockTime = defaultDABlockTime
278278
}
279279

280-
if conf.BlockTime == 0 {
280+
if config.Node.BlockTime == 0 {
281281
logger.Info("Using default block time", "BlockTime", defaultBlockTime)
282-
conf.BlockTime = defaultBlockTime
282+
config.Node.BlockTime = defaultBlockTime
283283
}
284284

285-
if conf.LazyBlockTime == 0 {
285+
if config.Node.LazyBlockTime == 0 {
286286
logger.Info("Using default lazy block time", "LazyBlockTime", defaultLazyBlockTime)
287-
conf.LazyBlockTime = defaultLazyBlockTime
287+
config.Node.LazyBlockTime = defaultLazyBlockTime
288288
}
289289

290-
if conf.DAMempoolTTL == 0 {
290+
if config.DA.MempoolTTL == 0 {
291291
logger.Info("Using default mempool ttl", "MempoolTTL", defaultMempoolTTL)
292-
conf.DAMempoolTTL = defaultMempoolTTL
292+
config.DA.MempoolTTL = defaultMempoolTTL
293293
}
294294

295295
//proposerAddress := s.Validators.Proposer.Address.Bytes()
@@ -321,7 +321,7 @@ func NewManager(
321321

322322
agg := &Manager{
323323
proposerKey: proposerKey,
324-
conf: conf,
324+
config: config,
325325
genesis: genesis,
326326
lastState: s,
327327
store: store,
@@ -454,15 +454,15 @@ func (m *Manager) IsDAIncluded(hash types.Hash) bool {
454454
// getRemainingSleep calculates the remaining sleep time based on config and a start time.
455455
func (m *Manager) getRemainingSleep(start time.Time) time.Duration {
456456
elapsed := time.Since(start)
457-
interval := m.conf.BlockTime
457+
interval := m.config.Node.BlockTime
458458

459-
if m.conf.LazyAggregator {
459+
if m.config.Node.LazyAggregator {
460460
if m.buildingBlock && elapsed >= interval {
461461
// Special case to give time for transactions to accumulate if we
462462
// are coming out of a period of inactivity.
463463
return (interval * time.Duration(defaultLazySleepPercent) / 100)
464464
} else if !m.buildingBlock {
465-
interval = m.conf.LazyBlockTime
465+
interval = m.config.Node.LazyBlockTime
466466
}
467467
}
468468

@@ -506,7 +506,7 @@ func (m *Manager) BatchRetrieveLoop(ctx context.Context) {
506506
if err != nil {
507507
m.logger.Error("error while retrieving batch", "error", err)
508508
// Always reset timer on error
509-
batchTimer.Reset(m.conf.BlockTime)
509+
batchTimer.Reset(m.config.Node.BlockTime)
510510
continue
511511
}
512512

@@ -530,7 +530,7 @@ func (m *Manager) BatchRetrieveLoop(ctx context.Context) {
530530

531531
// Always reset timer
532532
elapsed := time.Since(start)
533-
remainingSleep := m.conf.BlockTime - elapsed
533+
remainingSleep := m.config.Node.BlockTime - elapsed
534534
if remainingSleep < 0 {
535535
remainingSleep = 0
536536
}
@@ -550,7 +550,7 @@ func (m *Manager) AggregationLoop(ctx context.Context) {
550550
delay = time.Until(m.genesis.GenesisTime)
551551
} else {
552552
lastBlockTime := m.getLastBlockTime()
553-
delay = time.Until(lastBlockTime.Add(m.conf.BlockTime))
553+
delay = time.Until(lastBlockTime.Add(m.config.Node.BlockTime))
554554
}
555555

556556
if delay > 0 {
@@ -567,7 +567,7 @@ func (m *Manager) AggregationLoop(ctx context.Context) {
567567
// Lazy Aggregator mode.
568568
// In Lazy Aggregator mode, blocks are built only when there are
569569
// transactions or every LazyBlockTime.
570-
if m.conf.LazyAggregator {
570+
if m.config.Node.LazyAggregator {
571571
m.lazyAggregationLoop(ctx, blockTimer)
572572
return
573573
}
@@ -634,7 +634,7 @@ func (m *Manager) normalAggregationLoop(ctx context.Context, blockTimer *time.Ti
634634

635635
// HeaderSubmissionLoop is responsible for submitting blocks to the DA layer.
636636
func (m *Manager) HeaderSubmissionLoop(ctx context.Context) {
637-
timer := time.NewTicker(m.conf.DABlockTime)
637+
timer := time.NewTicker(m.config.DA.BlockTime)
638638
defer timer.Stop()
639639
for {
640640
select {
@@ -685,9 +685,9 @@ func (m *Manager) handleEmptyDataHash(ctx context.Context, header *types.Header)
685685
// SyncLoop processes headers gossiped in P2P network to know what's the latest block height,
686686
// block data is retrieved from DA layer.
687687
func (m *Manager) SyncLoop(ctx context.Context) {
688-
daTicker := time.NewTicker(m.conf.DABlockTime)
688+
daTicker := time.NewTicker(m.config.DA.BlockTime)
689689
defer daTicker.Stop()
690-
blockTicker := time.NewTicker(m.conf.BlockTime)
690+
blockTicker := time.NewTicker(m.config.Node.BlockTime)
691691
defer blockTicker.Stop()
692692
for {
693693
select {
@@ -1118,9 +1118,9 @@ func (m *Manager) publishBlock(ctx context.Context) error {
11181118
return ErrNotProposer
11191119
}
11201120

1121-
if m.conf.MaxPendingBlocks != 0 && m.pendingHeaders.numPendingHeaders() >= m.conf.MaxPendingBlocks {
1121+
if m.config.Node.MaxPendingBlocks != 0 && m.pendingHeaders.numPendingHeaders() >= m.config.Node.MaxPendingBlocks {
11221122
return fmt.Errorf("refusing to create block: pending blocks [%d] reached limit [%d]",
1123-
m.pendingHeaders.numPendingHeaders(), m.conf.MaxPendingBlocks)
1123+
m.pendingHeaders.numPendingHeaders(), m.config.Node.MaxPendingBlocks)
11241124
}
11251125

11261126
var (
@@ -1438,7 +1438,7 @@ daSubmitRetryLoop:
14381438
m.logger.Debug("resetting DA layer submission options", "backoff", backoff, "gasPrice", gasPrice, "maxBlobSize", maxBlobSize)
14391439
case coreda.StatusNotIncludedInBlock, coreda.StatusAlreadyInMempool:
14401440
m.logger.Error("DA layer submission failed", "error", res.Message, "attempt", attempt)
1441-
backoff = m.conf.DABlockTime * time.Duration(m.conf.DAMempoolTTL) //nolint:gosec
1441+
backoff = m.config.DA.BlockTime * time.Duration(m.config.DA.MempoolTTL) //nolint:gosec
14421442
if m.gasMultiplier > 0 && gasPrice != -1 {
14431443
gasPrice = gasPrice * m.gasMultiplier
14441444
}
@@ -1471,8 +1471,8 @@ func (m *Manager) exponentialBackoff(backoff time.Duration) time.Duration {
14711471
if backoff == 0 {
14721472
backoff = initialBackoff
14731473
}
1474-
if backoff > m.conf.DABlockTime {
1475-
backoff = m.conf.DABlockTime
1474+
if backoff > m.config.DA.BlockTime {
1475+
backoff = m.config.DA.BlockTime
14761476
}
14771477
return backoff
14781478
}

0 commit comments

Comments
 (0)