Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove buildingblock from manager struct
  • Loading branch information
tac0turtle
tac0turtle committed May 2, 2025
commit 10592a28f4bf8170d1835048f5a7d11fb551da84
15 changes: 6 additions & 9 deletions block/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,33 @@ func (m *Manager) lazyAggregationLoop(ctx context.Context, blockTimer *time.Time
lazyTimer := time.NewTimer(0)
defer lazyTimer.Stop()

// Track if we've received transactions but haven't built a block yet
pendingTxs := false
buildingBlock := false

for {
select {
case <-ctx.Done():
return

case <-lazyTimer.C:
m.buildingBlock = false
pendingTxs = false
buildingBlock = true
m.produceBlockLazy(ctx, "lazy_timer", lazyTimer, blockTimer)
buildingBlock = false

case <-blockTimer.C:
if pendingTxs {
m.buildingBlock = true
buildingBlock = true
m.produceBlockLazy(ctx, "tx_collection_complete", lazyTimer, blockTimer)
buildingBlock = false
pendingTxs = false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we should call it pendingTxs, since txs could still be pending even after we finish building a block since a block only consumes one batch

} else {
// Reset the block timer if no pending transactions

Copilot AI May 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] It may be helpful to document why the block timer is reset when no pending transactions are present, clarifying the intended timing behavior.

Suggested change
// Reset the block timer if no pending transactions
// Reset the block timer if no pending transactions
// This ensures that the timer continues to trigger at regular intervals,
// even during periods of inactivity, maintaining consistent block timing.

Copilot uses AI. Check for mistakes.
blockTimer.Reset(m.config.Node.BlockTime.Duration)
}

case <-m.txNotifyCh:
if m.buildingBlock {
if buildingBlock {
continue
}

Expand Down Expand Up @@ -118,11 +120,6 @@ func (m *Manager) produceBlockLazy(ctx context.Context, trigger string, lazyTime
// Record the start time
start := time.Now()

m.buildingBlock = true
defer func() {
m.buildingBlock = false
}()

// Attempt to publish the block
if err := m.publishBlock(ctx); err != nil && ctx.Err() == nil {
m.logger.Error("error while publishing block", "trigger", trigger, "error", err)
Expand Down
4 changes: 0 additions & 4 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ type Manager struct {

logger log.Logger

// For usage by Lazy Aggregator mode
buildingBlock bool

pendingHeaders *PendingHeaders

// for reporting metrics
Expand Down Expand Up @@ -349,7 +346,6 @@ func NewManager(
dataCache: cache.NewCache[types.Data](),
retrieveCh: make(chan struct{}, 1),
logger: logger,
buildingBlock: false,
pendingHeaders: pendingHeaders,
metrics: seqMetrics,
sequencer: sequencer,
Expand Down