From e2332f3163795cd2a4a5907112f01dece2e09144 Mon Sep 17 00:00:00 2001 From: Aurora Gaffney Date: Sat, 14 Jun 2025 22:58:12 -0400 Subject: [PATCH] fix: handle rollback from chain iterator in chainsync server Fixes #769 Signed-off-by: Aurora Gaffney --- chainsync.go | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/chainsync.go b/chainsync.go index 34847ae2..3d18f4c4 100644 --- a/chainsync.go +++ b/chainsync.go @@ -151,11 +151,19 @@ func (n *Node) chainsyncServerRequestNext( } } if next != nil { - return ctx.Server.RollForward( - next.Block.Type, - next.Block.Cbor, - tip, - ) + if next.Rollback { + err = ctx.Server.RollBackward( + next.Point, + tip, + ) + } else { + err = ctx.Server.RollForward( + next.Block.Type, + next.Block.Cbor, + tip, + ) + } + return err } // Send AwaitReply if err := ctx.Server.AwaitReply(); err != nil { @@ -168,11 +176,18 @@ func (n *Node) chainsyncServerRequestNext( return } tip := n.ledgerState.Tip() - _ = ctx.Server.RollForward( - next.Block.Type, - next.Block.Cbor, - tip, - ) + if next.Rollback { + _ = ctx.Server.RollBackward( + next.Point, + tip, + ) + } else { + _ = ctx.Server.RollForward( + next.Block.Type, + next.Block.Cbor, + tip, + ) + } }() return nil }