Skip to content

Commit

Permalink
Made safe nbr of block confirmations configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ffakenz committed Oct 3, 2024
1 parent a5b63cd commit dc9c73c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions hydra-chain-observer/src/Hydra/Blockfrost/ChainObserver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ blockfrostClient tracer projectPath blockConfirmations = do
stateTVar <- newTVarIO (blockHash, mempty)
void $
retrying (retryPolicy blockTime) shouldRetry $ \_ -> do
loop tracer prj networkId blockTime observerHandler stateTVar
loop tracer prj networkId blockTime observerHandler blockConfirmations stateTVar
}
where
shouldRetry _ = \case
Expand All @@ -116,13 +116,14 @@ loop ::
NetworkId ->
DiffTime ->
ObserverHandler m ->
Integer ->
TVar m (Blockfrost.BlockHash, UTxO) ->
m a
loop tracer prj networkId blockTime observerHandler stateTVar = do
loop tracer prj networkId blockTime observerHandler blockConfirmations stateTVar = do
current <- readTVarIO stateTVar
next <- rollForward tracer prj networkId observerHandler current
next <- rollForward tracer prj networkId observerHandler blockConfirmations current
atomically $ writeTVar stateTVar next
loop tracer prj networkId blockTime observerHandler stateTVar
loop tracer prj networkId blockTime observerHandler blockConfirmations stateTVar

-- | From the current block and UTxO view, we collect Hydra observations
-- and yield the next block and adjusted UTxO view.
Expand All @@ -132,9 +133,10 @@ rollForward ::
Blockfrost.Project ->
NetworkId ->
ObserverHandler m ->
Integer ->
(Blockfrost.BlockHash, UTxO) ->
m (Blockfrost.BlockHash, UTxO)
rollForward tracer prj networkId observerHandler (blockHash, utxo) = do
rollForward tracer prj networkId observerHandler blockConfirmations (blockHash, utxo) = do
block@Blockfrost.Block
{ _blockHash
, _blockConfirmations
Expand All @@ -144,8 +146,7 @@ rollForward tracer prj networkId observerHandler (blockHash, utxo) = do
runBlockfrostM prj $ Blockfrost.getBlock (Right blockHash)

-- Check if block within the safe zone to be processes
-- FIXME: should be configurable
when (_blockConfirmations < 1) $
when (_blockConfirmations < blockConfirmations) $
throwIO (NotEnoughBlockConfirmations _blockHash)

-- Check if block contains a reference to its next
Expand Down

0 comments on commit dc9c73c

Please sign in to comment.