haskoin-store 1.16.3 → 1.16.4
raw patch · 4 files changed
+70/−5 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Haskoin.Store.Fleet.Member: Unsettled :: Way
Files
- CHANGELOG.md +16/−0
- haskoin-store.cabal +1/−1
- src/Haskoin/Store/Fleet/Member.hs +19/−3
- test/Haskoin/Store/Fleet/CacheSpec.hs +34/−1
CHANGELOG.md view
@@ -4,6 +4,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html) +## [1.16.4] - 2026-11-18++### Fixed+- **A reorganisation no longer loses the transactions of the abandoned+ blocks.** A store alone in its fleet that reverted a block between its+ report and its move of the fleet tip found the reported block off its+ main chain, took that as a way it did not know, and moved the tip with an+ emptied pool. The transactions of the abandoned blocks that no node had+ any more were lost, and answered 404. Such a store now leaves the tip for+ its next turn (`Unsettled` in `Haskoin.Store.Fleet.Member`). The+ transactions still come back only in the commit that moves the tip, so+ none is ever both confirmed at the tip and in the pool. This was the+ intermittent failure of the integration test "sends again a payment that+ the nodes forgot and the store lists"; a test of the fleet's cache now+ makes the race happen every time.+ ## [1.16.3] - 2026-11-18 ### Added
haskoin-store.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: haskoin-store-version: 1.16.3+version: 1.16.4 synopsis: Storage and index for Bitcoin and Bitcoin Cash description: An indexer for Bitcoin and Bitcoin Cash. It downloads blocks and mempool transactions from the peer-to-peer network, indexes them in RocksDB, and
src/Haskoin/Store/Fleet/Member.hs view
@@ -584,6 +584,13 @@ -- blocks did, the pool is emptied, and the cache with it: Redis allows that -- to a store that is alone, and to any store when the way is too long for -- all of them (v'TooFar').+--+-- When the block that the stores agree on is no longer on this store's main+-- chain, because the store moved its chain after it reported the block, the+-- tip stays until the next turn (v'Unsettled'). Treating that as a way it+-- does not know emptied the pool of a store that was alone in the middle of+-- a reorganisation, and lost the transactions of the abandoned blocks that+-- no node had any more. moveTip :: Member -> IO Bool moveTip m = do seen <- fleetTip m.redis m.keys@@ -630,6 +637,8 @@ Just moves -> cachePieces m.redis m.keys token (fromMaybe "" seen) moves Nothing -> return False (Way _, _) -> return False+ -- the store's chain moved since its report: not this turn+ (Unsettled, _) -> return False _ -> return True moved <- if not written@@ -656,6 +665,7 @@ case way of Way _ -> "" NoWay -> " (this store does not know the way)"+ Unsettled -> " (the chain of this store moved since its report)" TooFar -> " (the way is too long)" ] case moved of@@ -723,9 +733,14 @@ data Way = -- | what the blocks between them did Way !Between- | -- | nothing: it does not have one of the tips, or the second is not- -- on its main chain. Another store may know.+ | -- | nothing: it does not have the first tip, or no view of the+ -- database at it. Another store may know. NoWay+ | -- | not yet: the second tip is not on its main chain as the database+ -- has it now. The store reported the tip, and its chain has moved+ -- since, as when it reverts blocks in a reorganisation; its next report+ -- says where it is. The tip waits for the next turn.+ Unsettled | -- | it has both, and the way is longer than 'farthest' blocks on one -- side of the fork. That is so for every store. TooFar@@ -775,7 +790,8 @@ down 0 fork bd >>= \case Left none -> return none Right added -> maybe (return NoWay) (wayWith r bd abandoned added) =<< abandonedBodies (reverse abandoned)- _ -> return NoWay+ -- the store reported the second tip, and has moved on since+ _ -> return Unsettled where wayWith r bd abandoned added old = do new <- concat <$> mapM (confirmedBy r) (reverse added)
test/Haskoin/Store/Fleet/CacheSpec.hs view
@@ -19,7 +19,7 @@ import Data.HashMap.Strict qualified as HashMap import Data.IORef (IORef, atomicModifyIORef', newIORef) import Data.IntMap.Strict qualified as IntMap-import Data.List (find)+import Data.List (find, sortOn) import Data.List.NonEmpty (NonEmpty (..)) import Data.Maybe (catMaybes, fromMaybe) import Data.Serialize (encode)@@ -106,6 +106,8 @@ it "never answers an entry that a move of the tip is writing" (`withBed` markedTest) it "keeps the cache across a reorganisation, as the chain and the pool give it" (`withBed` reorgTest) it "fills the pool again after Redis lost its data" (`withBed` refillTest)+ it "keeps what an abandoned block gave back when the chain moves under a move of the tip" $+ (`withBed` unsettledTest) it "fetches no transaction that another member received" (`withBed` seenTest) modifyMaxSuccess (const 10) $ it "keeps every cached entry equal to the chain at the tip and the pool" $ \r ->@@ -271,6 +273,37 @@ inPool bed tx `shouldReturn` True xpubAsk bed.a.door x `shouldReturn` Indexed sameAsChain bed bed.a x++-- | A store alone in its fleet reports a block, and reverts it before it+-- moves the tip there, as a block store does in a reorganisation while the+-- member takes its turn. The tip waits for the next report instead of+-- moving with an emptied pool: a payment of an abandoned block that no+-- node has any more comes back to the pool, and is never in the pool while+-- the tip still has it confirmed.+unsettledTest :: Bed -> IO ()+unsettledTest bed = do+ -- the oldest coin, of a block that is not abandoned+ coin : _ <- sortOn (.block) <$> coins bed+ let tx = spend [coin] [(script, 100000)]+ confirmedAtTip = atTip bed $ \q -> maybe False (confirmed . (.block)) <$> q.getTxData (txHash tx)+ mineBlock bed [tx]+ settle bed+ confirmedAtTip `shouldReturn` True+ -- the other member stops: this one is alone+ void . Redis.runRedis bed.conn $ do+ void $ Redis.hdel bed.a.keys.lease ("b" :| [])+ Redis.hdel bed.a.keys.recent ("b" :| [])+ -- the block of the payment is reverted, and the store reports its parent+ revert bed.db >> noted bed+ report bed.a+ -- and reverts the parent too before it moves the tip+ revert bed.db+ moveTip bed.a `shouldReturn` False+ confirmedAtTip `shouldReturn` True+ noted bed+ replicateM_ 3 (mineBlock bed [])+ settle bed+ inPool bed tx `shouldReturn` True ------------------------------------------------------------------------------- -- The model test