Skip to content

Commit

Permalink
fix: use non-inclusive chain iterator for chainsync
Browse files Browse the repository at this point in the history
  • Loading branch information
agaffney committed Sep 14, 2024
1 parent d8e85df commit a660329
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion blockfetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion chainsync/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion state/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
7 changes: 4 additions & 3 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand Down

0 comments on commit a660329

Please sign in to comment.