Skip to content
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

Chain state in head state not updated on replayed observation #931

Closed
ch1bo opened this issue Jun 14, 2023 · 3 comments
Closed

Chain state in head state not updated on replayed observation #931

ch1bo opened this issue Jun 14, 2023 · 3 comments
Assignees
Labels
bug 🐛 Something isn't working

Comments

@ch1bo
Copy link
Member

ch1bo commented Jun 14, 2023

Context & versions

Any current version, master

Steps to reproduce

  1. Create and open a Head at block x+1, check the persisted state, it should have an Open chain state
  2. Configure hydra-node to --start-chain-from block x
  3. Restart the hydra-node and check state again as the node resynchronizes with the L1

Actual behavior

The chainState is reset to Idle and weirdly has previous chain states attached.

Expected behavior

The chainState is Idle at first with no previous, and update accordingly as the chain component synchronizes with the L1. Expect to see an Open chain state next to an Open head state in the end.

Solution idea

In the HeadLogic.update function, we could be writing the chainState also on any observation (if not matched and resulting in a headState transition already)

  (currentState, OnChainEvent Observation{newChainState}) ->
      NewState (setChainState newChainState currentState) []
@ch1bo ch1bo added the bug 🐛 Something isn't working label Jun 14, 2023
@ffakenz ffakenz self-assigned this Aug 21, 2023
@ffakenz
Copy link
Member

ffakenz commented Aug 22, 2023

From my pov, it is not clear what is needed for this story.

@ffakenz
Copy link
Member

ffakenz commented Aug 23, 2023

We started a draft branch (fix-start-chain-from) on Monday to explore this, but we could not get the problem.

@ffakenz
Copy link
Member

ffakenz commented Aug 29, 2023

We tried to reproduced the problem using this scenario but the persisted state seems to be fine.

startChainFromReplayed :: FilePath -> Tracer IO EndToEndLog -> RunningNode -> TxId -> IO ()
startChainFromReplayed tmpDir tracer node@RunningNode{networkId, nodeSocket} hydraScriptsTxId = do
  (aliceCardanoVk, _) <- keysFor Alice
  let aliceSk = generateSigningKey "alice-timed"
  let alice = deriveParty aliceSk
  let contestationPeriod = UnsafeContestationPeriod 2
  aliceChainConfig <- chainConfigFor Alice tmpDir nodeSocket [] contestationPeriod
  (chainPointBeforeComit, committedUTxOByAlice, headId) <- withHydraNode tracer aliceChainConfig tmpDir 1 aliceSk [] [1] hydraScriptsTxId $ \n1 -> do
    waitForNodesConnected tracer [n1]
    let lovelaceBalanceValue = 100_000_000

    -- Funds to be used as fuel by Hydra protocol transactions
    seedFromFaucet_ node aliceCardanoVk lovelaceBalanceValue (contramap FromFaucet tracer)
    send n1 $ input "Init" []
    headId <- waitForAllMatch 10 [n1] $ headIsInitializingWith (Set.fromList [alice])

    -- Get some UTXOs to commit to a head
    (aliceExternalVk, aliceExternalSk) <- generate genKeyPair
    committedUTxOByAlice <- seedFromFaucet node aliceExternalVk aliceCommittedToHead (contramap FromFaucet tracer)
    chainPointBeforeComit <- queryTip networkId nodeSocket
    requestCommitTx n1 committedUTxOByAlice <&> signTx aliceExternalSk >>= submitTx node

    waitFor tracer 3 [n1] $ output "HeadIsOpen" ["utxo" .= committedUTxOByAlice, "headId" .= headId]
    pure (chainPointBeforeComit, committedUTxOByAlice, headId)

  let aliceChainConfigBeforeOpen = aliceChainConfig{startChainFrom = Just chainPointBeforeComit}
  withHydraNode tracer aliceChainConfigBeforeOpen tmpDir 1 aliceSk [] [1] hydraScriptsTxId $ \n1 -> do
    threadDelay 5
    send n1 $ input "Close" []
    waitMatch 3 n1 $ \v -> do
      guard $ v ^? key "tag" == Just "HeadIsClosed"
    stateContents <- readFileLBS $ tmpDir </> "state-1" </> "state"
    putLBSLn stateContents

This likely got fixed when implementing #913

@ffakenz ffakenz closed this as completed Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants