Skip to content

Commit

Permalink
fix: keep track of DA height of latest *applied* block
Browse files Browse the repository at this point in the history
Previously, latest processed DA block height was saved, and as a result
syncing couldn't restart.

Resolves rollkit/rollkit#376
  • Loading branch information
tzdybal committed Apr 25, 2022
1 parent 4b75f1f commit e71c361
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 12 additions & 5 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import (
// defaultDABlockTime is used only if DABlockTime is not configured for manager
const defaultDABlockTime = 30 * time.Second

type newBlockEvent struct {
block *types.Block
daHeight uint64
}

// Manager is responsible for aggregating transactions into blocks.
type Manager struct {
lastState state.State
Expand All @@ -48,7 +53,7 @@ type Manager struct {
HeaderInCh chan *types.Header

syncTarget uint64
blockInCh chan *types.Block
blockInCh chan newBlockEvent
syncCache map[uint64]*types.Block

// retrieveMtx is used by retrieveCond
Expand Down Expand Up @@ -123,7 +128,7 @@ func NewManager(
// channels are buffered to avoid blocking on input/output operations, buffer sizes are arbitrary
HeaderOutCh: make(chan *types.Header, 100),
HeaderInCh: make(chan *types.Header, 100),
blockInCh: make(chan *types.Block, 100),
blockInCh: make(chan newBlockEvent, 100),
retrieveMtx: new(sync.Mutex),
syncCache: make(map[uint64]*types.Block),
logger: logger,
Expand Down Expand Up @@ -180,7 +185,9 @@ func (m *Manager) SyncLoop(ctx context.Context) {
atomic.StoreUint64(&m.syncTarget, newHeight)
m.retrieveCond.Signal()
}
case block := <-m.blockInCh:
case blockEvent := <-m.blockInCh:
block := blockEvent.block
daHeight := blockEvent.daHeight
m.logger.Debug("block body retrieved from DALC",
"height", block.Header.Height,
"hash", block.Hash(),
Expand All @@ -207,7 +214,7 @@ func (m *Manager) SyncLoop(ctx context.Context) {
continue
}

newState.DAHeight = atomic.LoadUint64(&m.daHeight)
newState.DAHeight = daHeight
m.lastState = newState
err = m.store.UpdateState(m.lastState)
if err != nil {
Expand Down Expand Up @@ -273,7 +280,7 @@ func (m *Manager) processNextDABlock() error {
time.Sleep(100 * time.Millisecond)
} else {
for _, block := range blockResp.Blocks {
m.blockInCh <- block
m.blockInCh <- newBlockEvent{block, daHeight}
}
return nil
}
Expand Down
1 change: 1 addition & 0 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type State struct {
LastBlockID types.BlockID
LastBlockTime time.Time

// DAHeight identifies DA block containing the latest applied Optimint block.
DAHeight uint64

// In the MVP implementation, there will be only one Validator
Expand Down

0 comments on commit e71c361

Please sign in to comment.