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

Hello World Offchain Contract IO Blocking #103

Closed
tbidne opened this issue May 10, 2022 · 5 comments
Closed

Hello World Offchain Contract IO Blocking #103

tbidne opened this issue May 10, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@tbidne
Copy link
Contributor

tbidne commented May 10, 2022

Problem

Currently, our initialize endpoint logic in HelloWorld.Contract looks like this:

initializeHandler :: Integer -> Contract (Last CurrencySymbol) InitHelloWorldSchema Text ()
initializeHandler initialInt = do
  ownPkh <- ownPaymentPubKeyHash
  -- TODO: remove waitNSlots. this was added because the e2e tests are
  -- started immediately after the network is online. there seems to be a synchr problem
  _ <- waitNSlots 1
  cs <- currencySymbol <$> mapError (pack . show) (mintContract ownPkh [(TokenName "", 1)] :: Contract w s CurrencyError OneShotCurrency)
  let lookups = otherScript helloValidator
      tx = mustPayToOtherScript helloValidatorHash (Datum $ mkI initialInt) (singleton cs "" 1)
  adjustedTx <- adjustUnbalancedTx <$> mkTxConstraints @Void lookups tx
  ledgerTx <- submitUnbalancedTx adjustedTx
  awaitTxConfirmed $ getCardanoTxId ledgerTx
  tell $ Last $ Just cs
  logInfo $ "Successfully initialized datum with value: " <> show initialInt

The key line is _ <- waitNSlots 1. This line was added to make the unit tests pass. Unfortunately, when we run the local-cluster for real, it blocks infinitely. This was discovered when implementing #67, as this obviously impacts the e2e tests. The reason it wasn't initially discovered is that we don't know the contract gets "stuck" unless we check the observable state. Thus the tests should be updated to actually check this state, but we cannot do that until we first fix this issue.

If we remove the _ <- waitNSlots 1 line, we receive this error:

[chain-index:Warning:1323] [2022-05-10 00:19:03.81 UTC] TipIsGenesis
[pab:Error:1306] [2022-05-10 00:19:03.84 UTC] 8aa5fc33-0341-44ef-979a-82d5eff91f81: "CurContractError (ConstraintResolutionContractError (TxOutRefNotFound (TxOutRef {txOutRefId = d3e4ff652ffb1bdda69bd60ca331cf2444cd49149255f1aad50564593c830bbf, txOutRefIdx = 6})))"

So right now we have a choice between two errors:

  1. With the wait line, contract gets stuck in an infinite loop.
  2. Without the wait, we get some lookup error, possibly suggestive of a race condition (i.e. those two logs maybe shouldn't be happening at the same time?).

Reproducing

First error (infinite blocking)

Run:

cabal run hello-world-cluster

Once that is up, from a second terminal:

curl -H "Content-Type: application/json" -X POST -d '{"caID": {"tag": "Initialize"}, "caWallet": {"getWalletId": "2d4cc31a4b3116ab86bfe529d30d9c362acd0b44"}}' localhost:9080/api/contract/activate | jq

curl -H "Content-Type: application/json" -X POST -d '2' localhost:9080/api/contract/instance/<contractIdFromPreviousCurl>/endpoint/initialize | jq

curl localhost:9080/api/contract/instance/<contractIdFromPreviousCurl>/status | jq

Had the initialize step completed, the observableState in the final json output should not be null. Alternatively, you can edit the initializeHandler to call error "die" after the _ <- waitNSlots 1 line, which would crash the server (and show up in the console logs) if we were not getting blocked.

Second error (lookup)

Reproducing the 2nd error is the same as above, except you must comment out the _ <- waitNSlots 1 line, and there is no need to run the final status curl. Instead, check the cluster logs after the 2nd curl command with initialize. You should see the error message in the terminal.

CC @CSVdB, @marijanp, @locallycompact

@tbidne tbidne added the bug Something isn't working label May 10, 2022
@tbidne
Copy link
Contributor Author

tbidne commented May 10, 2022

Here's a description of that error term:

The transaction output consumed by a transaction input could not be found (either because it was already spent, or because there was no transaction with the given hash on the blockchain).

https://marlowe-playground-staging.plutus.aws.iohkdev.io/doc/haddock/plutus-ledger/html/Ledger-Index.html#t:ValidationError

@tbidne
Copy link
Contributor Author

tbidne commented May 10, 2022

@tbidne
Copy link
Contributor Author

tbidne commented May 10, 2022

Reproduced in Uniswap: IntersectMBO/plutus-apps#451

@tbidne
Copy link
Contributor Author

tbidne commented May 23, 2022

@Geometer1729
Copy link
Contributor

AFAICT this pertains to PAB which we no longer use

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