Skip to content

Commit

Permalink
fix(manager): validate blocks revision when submit (#1261)
Browse files Browse the repository at this point in the history
  • Loading branch information
srene authored Nov 29, 2024
1 parent 6cb5796 commit 8e19195
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 5 additions & 5 deletions block/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ const (

// MonitorForkUpdateLoop monitors the hub for fork updates in a loop
func (m *Manager) MonitorForkUpdateLoop(ctx context.Context) error {
// if instruction already exists no need to check for fork update
if types.InstructionExists(m.RootDir) {
return nil
}

ticker := time.NewTicker(ForkMonitorInterval) // TODO make this configurable
defer ticker.Stop()

Expand All @@ -44,6 +39,11 @@ func (m *Manager) MonitorForkUpdateLoop(ctx context.Context) error {

// checkForkUpdate checks if the hub has a fork update
func (m *Manager) checkForkUpdate(msg string) error {
// if instruction exists no need to check for fork update
if types.InstructionExists(m.RootDir) {
return nil
}

rollapp, err := m.SLClient.GetRollapp()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion block/retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (m *Manager) ApplyBatchFromSL(slBatch *settlement.Batch) error {
}

if block.GetRevision() != m.State.GetRevision() {
err := m.checkForkUpdate("syncing to fork height. please restart the node.")
err := m.checkForkUpdate(fmt.Sprintf("syncing to fork height. received block revision: %d node revision: %d. please restart the node.", block.GetRevision(), m.State.GetRevision()))
return err
}

Expand Down
6 changes: 6 additions & 0 deletions block/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ func (m *Manager) CreateBatch(maxBatchSize uint64, startHeight uint64, endHeight
if err != nil {
return nil, fmt.Errorf("load drs version: h: %d: %w", h, err)
}

// check all blocks have the same revision
if len(batch.Blocks) > 0 && batch.Blocks[len(batch.Blocks)-1].GetRevision() != block.GetRevision() {
return nil, fmt.Errorf("create batch: batch includes blocks with different revisions: %w", gerrc.ErrInternal)
}

batch.Blocks = append(batch.Blocks, block)
batch.Commits = append(batch.Commits, commit)
batch.DRSVersion = append(batch.DRSVersion, drsVersion)
Expand Down

0 comments on commit 8e19195

Please sign in to comment.