From 8e191956af4c180cc73fd4902eba09ff1494bd08 Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Fri, 29 Nov 2024 16:25:03 +0100 Subject: [PATCH] fix(manager): validate blocks revision when submit (#1261) --- block/fork.go | 10 +++++----- block/retriever.go | 2 +- block/submit.go | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/block/fork.go b/block/fork.go index b341ce1b9..0f2e366c7 100644 --- a/block/fork.go +++ b/block/fork.go @@ -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() @@ -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 diff --git a/block/retriever.go b/block/retriever.go index e94d486d7..3475bd398 100644 --- a/block/retriever.go +++ b/block/retriever.go @@ -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 } diff --git a/block/submit.go b/block/submit.go index 7f6dab4e1..3ee4e2dc4 100644 --- a/block/submit.go +++ b/block/submit.go @@ -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)