From dafff2ab9b3d44ee09dd7b3c2625b2ec3e9fe8b3 Mon Sep 17 00:00:00 2001 From: Aurora Gaffney Date: Fri, 13 Sep 2024 20:15:53 -0500 Subject: [PATCH] fix: use non-inclusive chain iterator for chainsync --- blockfetch.go | 2 +- chainsync/chainsync.go | 2 +- state/chain.go | 6 +++++- state/state.go | 7 ++++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/blockfetch.go b/blockfetch.go index 7c39691..20585c7 100644 --- a/blockfetch.go +++ b/blockfetch.go @@ -39,7 +39,7 @@ func (n *Node) blockfetchServerRequestRange( end ocommon.Point, ) error { // TODO: check if we have requested block range available and send NoBlocks if not - chainIter, err := n.ledgerState.GetChainFromPoint(start) + chainIter, err := n.ledgerState.GetChainFromPoint(start, true) if err != nil { return err } diff --git a/chainsync/chainsync.go b/chainsync/chainsync.go index 19fb114..df92ee8 100644 --- a/chainsync/chainsync.go +++ b/chainsync/chainsync.go @@ -70,7 +70,7 @@ func (s *State) AddClient( s.Lock() defer s.Unlock() // Create initial chainsync state for connection - chainIter, err := s.ledgerState.GetChainFromPoint(intersectPoint) + chainIter, err := s.ledgerState.GetChainFromPoint(intersectPoint, false) if err != nil { return nil, err } diff --git a/state/chain.go b/state/chain.go index 6082980..1c40576 100644 --- a/state/chain.go +++ b/state/chain.go @@ -35,7 +35,7 @@ type ChainIteratorResult struct { Rollback bool } -func newChainIterator(ls *LedgerState, startPoint ocommon.Point) (*ChainIterator, error) { +func newChainIterator(ls *LedgerState, startPoint ocommon.Point, inclusive bool) (*ChainIterator, error) { ls.RLock() defer ls.RUnlock() // Lookup start block in metadata DB @@ -51,6 +51,10 @@ func newChainIterator(ls *LedgerState, startPoint ocommon.Point) (*ChainIterator startPoint: startPoint, blockNumber: tmpBlock.Number, } + // Increment next block number is non-inclusive + if !inclusive { + ci.blockNumber++ + } return ci, nil } diff --git a/state/state.go b/state/state.go index c1ea982..8798e47 100644 --- a/state/state.go +++ b/state/state.go @@ -392,9 +392,10 @@ func (ls *LedgerState) GetIntersectPoint(points []ocommon.Point) (*ocommon.Point return nil, nil } -// GetChainFromPoint returns a ChainIterator starting at the specified point -func (ls *LedgerState) GetChainFromPoint(point ocommon.Point) (*ChainIterator, error) { - return newChainIterator(ls, point) +// GetChainFromPoint returns a ChainIterator starting at the specified point. If inclusive is true, the iterator +// will start at the requested point, otherwise it will start at the next block. +func (ls *LedgerState) GetChainFromPoint(point ocommon.Point, inclusive bool) (*ChainIterator, error) { + return newChainIterator(ls, point, inclusive) } // Tip returns the current chain tip