From 4af74cfa8e6a697ed2dd6ed5b6de03a36dbde878 Mon Sep 17 00:00:00 2001 From: Sebastian Nagel Date: Mon, 17 Jun 2024 16:50:49 +0200 Subject: [PATCH] Use max of start-chain-from and last known point (#1471) Instead of using the oldest, use the newest point when both, a last known head state and start-chain-from is present. --- * [x] CHANGELOG updated or not needed * [x] Documentation updated or not needed * [x] Haddocks not needed * [x] No new TODOs introduced --- CHANGELOG.md | 2 ++ docs/docs/configuration.md | 19 +++++++++++++++++++ hydra-node/src/Hydra/Chain/Direct.hs | 2 +- hydra-node/src/Hydra/Options.hs | 10 ++++++---- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3af8d33bf64..e1379ed2919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ changes. - **BREAKING** Changes to the `hydra-node` API `/commit` endpoint [#1463](https://github.com/input-output-hk/hydra/pull/1463): - Removed the check that prevented committing UTxOs from an internal `hydra-node` wallet. - `SpendingNodeUtxoForbidden` error was removed. + +- Change `--start-chain-from` to always use the newer point when also a head state is known. ## [0.17.0] - 2024-05-20 diff --git a/docs/docs/configuration.md b/docs/docs/configuration.md index 8a91e26deba..ea2d43115fe 100644 --- a/docs/docs/configuration.md +++ b/docs/docs/configuration.md @@ -161,7 +161,26 @@ hydra-node \ --node-socket devnet/node.socket \ ``` +:::info The `hydra-node` is compatible with the Cardano `mainnet` network, and can consequently operate using **real funds**. Please be sure to read the [known issues](/docs/known-issues) to fully understand the limitations and consequences of running Hydra nodes on mainnet. To choose `mainnet`, use `--mainnet` instead of `--testnet-magic`. +::: + +Using the direct node connection, the `hydra-node` does synchronize the chain and observes Hydra protocol transactions. On first startup, it will start observing from the chain's tip. Once a Hydra head has been observed, the point of the last known state change is used automatically. + +You can manually set the intersection point using `--start-chain-from .` which specifies a `slot` and block header `hash`. For example: + +```shell +hydra-node \ + --testnet-magic 2 \ + --node-socket preview/node.socket \ + --start-chain-from 49533501.e364500a42220ea47314215679b7e42e9bbb81fa69d1366fe738d8aef900f7ee +``` + +To synchronize from the genesis block, use `--start-chain-from 0`. + +:::info +If the `hydra-node` already tracks a head in its `state` and `--start-chain-from` is given, the **newer** point is used. +::: ## Offline mode diff --git a/hydra-node/src/Hydra/Chain/Direct.hs b/hydra-node/src/Hydra/Chain/Direct.hs index f6d630d888b..658a8b3f890 100644 --- a/hydra-node/src/Hydra/Chain/Direct.hs +++ b/hydra-node/src/Hydra/Chain/Direct.hs @@ -168,7 +168,7 @@ withDirectChain tracer config ctx wallet chainStateHistory callback action = do queue <- newTQueueIO -- Select a chain point from which to start synchronizing chainPoint <- maybe (queryTip networkId nodeSocket) pure $ do - (min <$> startChainFrom <*> persistedPoint) + (max <$> startChainFrom <*> persistedPoint) <|> persistedPoint <|> startChainFrom diff --git a/hydra-node/src/Hydra/Options.hs b/hydra-node/src/Hydra/Options.hs index 8386fbb7239..2d56b103774 100644 --- a/hydra-node/src/Hydra/Options.hs +++ b/hydra-node/src/Hydra/Options.hs @@ -646,10 +646,12 @@ startChainFromParser = ( long "start-chain-from" <> metavar "SLOT.HEADER_HASH" <> help - "The id of the block we want to start observing the chain from. \ - \If not given, uses the chain tip at startup. Composed by the slot \ - \number, a separator ('.') and the hash of the block header. \ - \For example: 52970883.d36a9936ae7a07f5f4bdc9ad0b23761cb7b14f35007e54947e27a1510f897f04." + "The id of the block we want to start observing the chain from. Only \ + \used if the last known head state is older than given point. If not \ + \given and no known head state, the chain tip is used. Composed by the \ + \slot number, a separator ('.') and the hash of the block header. For \ + \example: \ + \52970883.d36a9936ae7a07f5f4bdc9ad0b23761cb7b14f35007e54947e27a1510f897f04." ) where readChainPoint :: String -> Maybe ChainPoint