Repository navigation
Two bug fixes #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gdeest
wants to merge
10
commits into
main
Choose a base branch
from
fix/gsa-functional-issues
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Two bug fixes #69
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6982de5
fix: hash-based stream bounds and ChainSync intersection probing
gdeest 12ccda3
test: shared-slot regression cases for stream-bound helpers
gdeest af74949
test: add test cases for near-miss where the truncation point search …
vreuter dc675c5
chore: factor out common pattern for building TestHash values
vreuter 7e0adc0
chore: reduce repetition by defining variable just once
vreuter 5d9d381
test: add extra check of slot number to cases for near-miss on iterat…
vreuter a2bd209
chore: remove 'chunk' from description of what's being exhausted in t…
vreuter 51e855c
test: cleaner definition of groups of Entry values by slot for test c…
vreuter d4612f2
test: fix naming of near-miss overshoot test case
vreuter 5b1bf49
Merge pull request #74 from tweag/vr/functional-issues-tweaks
gdeest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,29 +21,30 @@ module GenesisSyncAccelerator.OnDemand | |||||
| , OnDemandRuntime (..) | ||||||
| , OnDemandTip (..) | ||||||
| , OnDemandState (..) | ||||||
| , SizedEntry | ||||||
| , deleteChunkFiles | ||||||
| , dropUntilLowerBound | ||||||
| , firstChunkNotAvailable | ||||||
| , lastChunkNotAvailable | ||||||
| , newOnDemandRuntime | ||||||
| , onDemandIteratorForRange | ||||||
| , onDemandIteratorFrom | ||||||
| , readOnDemandTip | ||||||
| , refreshTip | ||||||
| , truncateAtUpperBound | ||||||
| ) where | ||||||
|
|
||||||
| import Control.Concurrent.Async (Async, async, cancelMany, poll, waitCatch) | ||||||
| import Control.Concurrent.MVar (MVar, modifyMVar, modifyMVar_, newMVar, putMVar, takeMVar) | ||||||
| import Control.Exception (Exception, throw) | ||||||
| import Control.Monad (unless, void) | ||||||
| import Control.Monad.IO.Class (MonadIO, liftIO) | ||||||
| import qualified Data.Bifunctor as Bifunctor | ||||||
| import Data.ByteString.Lazy (ByteString) | ||||||
| import qualified Data.ByteString.Lazy as LBS | ||||||
| import Data.Foldable (traverse_) | ||||||
| import Data.List (delete, foldl', genericSplitAt, genericTake, partition) | ||||||
| import qualified Data.List.NonEmpty as NEL | ||||||
| import qualified Data.Map.Strict as Map | ||||||
| import Data.Maybe (listToMaybe) | ||||||
| import Data.Proxy (Proxy (..)) | ||||||
| import Data.Set (Set) | ||||||
| import qualified Data.Set as Set | ||||||
|
|
@@ -317,24 +318,19 @@ mkOnDemandIterator | |||||
| , cs | ||||||
| , \c es -> | ||||||
| if isLast c | ||||||
| then | ||||||
| checkEntryMatch | ||||||
| odcChunkInfo | ||||||
| toSlot | ||||||
| toHash | ||||||
| (\entries -> if null entries then Nothing else Just (last entries)) | ||||||
| (takeWhile (\(WithBlockSize _ e) -> getEntrySlot odcChunkInfo e <= toSlot) es) | ||||||
| then truncateAtUpperBound odcChunkInfo toSlot toHash es | ||||||
| else Right es | ||||||
| , isLast | ||||||
| ) | ||||||
| applyFrom :: ChunkNo -> [SizedEntry blk] -> Either (IllegalStreamOperation blk) [SizedEntry blk] | ||||||
| applyFrom c es = if c == NEL.head chunks then finalizeFrom <$> validateFrom (getFrom es) else Right es | ||||||
| applyFrom c es = if c == NEL.head chunks then finalizeFrom <$> validateFrom es else Right es | ||||||
| where | ||||||
| dropInit fromSlot = dropWhile $ \(WithBlockSize _ e) -> getEntrySlot odcChunkInfo e < fromSlot | ||||||
| (getFrom, validateFrom, finalizeFrom) = case from of | ||||||
| StreamFromExclusive GenesisPoint -> (id, Right, id) | ||||||
| StreamFromExclusive (BlockPoint fromSlot fromHash) -> (dropInit fromSlot, checkEntryMatch odcChunkInfo fromSlot fromHash listToMaybe, drop 1) | ||||||
| StreamFromInclusive (RealPoint fromSlot fromHash) -> (dropInit fromSlot, checkEntryMatch odcChunkInfo fromSlot fromHash listToMaybe, id) | ||||||
| (validateFrom, finalizeFrom) = case from of | ||||||
| StreamFromExclusive GenesisPoint -> (Right, id) | ||||||
| StreamFromExclusive (BlockPoint fromSlot fromHash) -> | ||||||
| (dropUntilLowerBound odcChunkInfo fromSlot fromHash, drop 1) | ||||||
| StreamFromInclusive (RealPoint fromSlot fromHash) -> | ||||||
| (dropUntilLowerBound odcChunkInfo fromSlot fromHash, id) | ||||||
|
|
||||||
| -- Initialize state for chunks left to process and the current chunk iterator. | ||||||
| varChunks <- newTVarIO $ NEL.toList chunks | ||||||
|
|
@@ -696,21 +692,49 @@ deriving instance (StandardHash blk, Typeable blk) => Exception (IllegalStreamOp | |||||
|
|
||||||
| type SizedEntry blk = WithBlockSize (Entry blk) | ||||||
|
|
||||||
| checkEntryMatch :: | ||||||
| -- | Drop entries until the (slot, hash) match. Searching by hash, not | ||||||
| -- position, is required because Byron EBBs and the first main block of an | ||||||
| -- epoch share a slot. | ||||||
| dropUntilLowerBound :: | ||||||
| Eq (HeaderHash blk) => | ||||||
| ChunkInfo -> | ||||||
| SlotNo -> | ||||||
| HeaderHash blk -> | ||||||
| ([SizedEntry blk] -> Maybe (SizedEntry blk)) -> | ||||||
| [SizedEntry blk] -> | ||||||
| Either (IllegalStreamOperation blk) [SizedEntry blk] | ||||||
| checkEntryMatch ci s h getE es = | ||||||
| Bifunctor.first (StreamBoundNotFound (s, h)) $ | ||||||
| maybe | ||||||
| (Left Nothing) | ||||||
| ( \(WithBlockSize _ e) -> if (getEntrySlot ci e, headerHash e) == (s, h) then Right es else Left (Just e) | ||||||
| ) | ||||||
| (getE es) | ||||||
| dropUntilLowerBound ci fromSlot fromHash = go Nothing | ||||||
| where | ||||||
| -- 'mbNear' = most recent same-slot non-match, reported in StreamBoundNotFound. | ||||||
| go mbNear [] = Left (StreamBoundNotFound (fromSlot, fromHash) mbNear) | ||||||
| go mbNear (e@(WithBlockSize _ entry) : rest) = | ||||||
| case compare (getEntrySlot ci entry) fromSlot of | ||||||
| LT -> go mbNear rest | ||||||
| EQ | ||||||
| | headerHash entry == fromHash -> Right (e : rest) | ||||||
| | otherwise -> go (Just entry) rest | ||||||
| GT -> Left (StreamBoundNotFound (fromSlot, fromHash) (Just entry)) | ||||||
|
|
||||||
| -- | Truncate at the (slot, hash) match. As with 'dropUntilLowerBound', | ||||||
| -- searching by hash (not @last . takeWhile slot <= toSlot@) is required | ||||||
| -- because Byron EBBs and the first main block of an epoch share a slot. | ||||||
| truncateAtUpperBound :: | ||||||
| Eq (HeaderHash blk) => | ||||||
| ChunkInfo -> | ||||||
| SlotNo -> | ||||||
| HeaderHash blk -> | ||||||
| [SizedEntry blk] -> | ||||||
| Either (IllegalStreamOperation blk) [SizedEntry blk] | ||||||
| truncateAtUpperBound ci toSlot toHash = go [] Nothing | ||||||
| where | ||||||
| -- 'mbNear' = most recent same-slot non-match (see 'dropUntilLowerBound'). | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| go _ mbNear [] = Left (StreamBoundNotFound (toSlot, toHash) mbNear) | ||||||
| go acc mbNear (e@(WithBlockSize _ entry) : rest) = | ||||||
| case compare (getEntrySlot ci entry) toSlot of | ||||||
| LT -> go (e : acc) mbNear rest | ||||||
| EQ | ||||||
| | headerHash entry == toHash -> Right (reverse (e : acc)) | ||||||
| | otherwise -> go (e : acc) (Just entry) rest | ||||||
| GT -> Left (StreamBoundNotFound (toSlot, toHash) (Just entry)) | ||||||
|
|
||||||
| tipFromRemoteEnv :: | ||||||
| forall blk. | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way, it's clearer that the notion of recency applies to the algorithmic iteration, rather than somewhat suggesting that it's more recent on the blockchain (in the sense that a slot is an atomic unit in time, and therefore things in the same slot cannot be more or less recent than one another). The other small change here ("to report in") I think makes it clearer that the last slot of
StreamBoundNotFoundwon't always be an entry from the requested slot, but rather could be something from another slot. Small points, but I think worth the precision in the wording. WDYT?