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

Switch to HTTP interface for Ogmios #1669

Merged
merged 27 commits into from
Feb 18, 2025
Merged

Switch to HTTP interface for Ogmios #1669

merged 27 commits into from
Feb 18, 2025

Conversation

marcusbfs
Copy link
Collaborator

@marcusbfs marcusbfs commented Jan 27, 2025

Closes #1575.

Ogmios still requires a WebSocket connection for mempool operations that depend on an acquired snapshot (hasTransaction, nextTransaction, sizeOfMempool, releaseMempool). We’ve opened a discussion proposing a stateless HTTP API for mempool functionality.

In the meanwhile, the plan is to extract the mempool functionality into its own package (wip).

Pre-review checklist

  • All code has been formatted using our config (make format)
  • Any new API features or modification of existing behavior are covered with tests
  • The template (templates/ctl-scaffold) has been updated
  • The changelog has been updated under the ## Unreleased header, using the appropriate sub-headings (### Added, ### Changed, ### Removed, ### Fixed), and the links to the appropriate issues/PRs have been included

@marcusbfs marcusbfs force-pushed the marcusbfs/http-ogmios branch from bc3f67b to 14a6d9d Compare February 5, 2025 14:32
@marcusbfs marcusbfs requested a review from errfrom February 5, 2025 18:03
@marcusbfs marcusbfs marked this pull request as ready for review February 5, 2025 20:32
Copy link
Collaborator

@errfrom errfrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work overall, some comments below

src/Internal/QueryM/Ogmios/Types.purs Outdated Show resolved Hide resolved
src/Internal/QueryM/Ogmios/Types.purs Outdated Show resolved Hide resolved
src/Internal/QueryM/Ogmios/Types.purs Outdated Show resolved Hide resolved
src/Internal/QueryM/Ogmios.purs Show resolved Hide resolved
Comment on lines +200 to +203
if result ^? _Right <<< to _.status == Just (StatusCode 503) then
delay delayMs *>
ogmiosPostRequestRetryAff (Milliseconds (unwrap delayMs * 2.0)) config
body
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is neat

src/Internal/QueryM/Ogmios.purs Outdated Show resolved Hide resolved
src/Internal/QueryM/Ogmios/JsonRpc2.purs Outdated Show resolved Hide resolved
src/Internal/QueryM/CurrentEpoch.purs Outdated Show resolved Hide resolved
Comment on lines 300 to 309
resendPendingSubmitRequests
:: MkUniqueId
-> OgmiosWebSocket
-> IsTxConfirmed
-> Logger
-> (RequestBody -> Effect Unit)
-> Dispatcher
-> PendingSubmitTxRequests
-> Effect Unit
resendPendingSubmitRequests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can be removed entirely since we no longer submit transactions over WebSocket

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this causes the runtime failure - likely due to Ogmios waiting for a transaction to be included in the mempool. I can try submitting these transactions over HTTP, but this might entangle the code, though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But since we don't submit transactions over WebSocket anymore, why do we need this code in the first place?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 99b98a0. Removing Ogmios' websocket initialization from the Contract initialization logic simplified the process and the runtime failure is gone.

Comment on lines 278 to 279
ogmiosWs <- mkOgmiosWebSocketAff uniqueId isTxConfirmed logger
(mkWsUrl ogmiosConfig)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to initialize a WebSocket connection to Ogmios anymore as part of the Contract initialization logic. Anyone who needs to use the Mempool API should manage the connection themselves.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. We can change this to ws :: Maybe OgmiosWebSocket and let the user handle it. Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that sounds reasonable.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I would prefer to make the core Kupmios provider entirely independent of the Mempool extension, meaning the Mempool API should reside in its own package as an optional plugin, while the core provider should not reference WebSockets in any way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully that makes sense, let me know what you think

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in febc66a. Now, the mempool functionality depends on Ogmios.Types and some Ctl.Internal helpers. Other than this, the module is self contained. When extracting Kupmios provider, we can refactor to decouple Kupmios and Ogmios.Mempool package.

@marcusbfs marcusbfs requested a review from errfrom February 14, 2025 00:04
Copy link
Collaborator

@errfrom errfrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcusbfs LGTM. Please update the changelog and let's merge it.

-- Server responded with error.
= ErrorResponse (Maybe OgmiosError)
-- Server responded with result, parsing of which failed
| ClientErrorResponse ClientError
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClientError is excessive here, since only one ClientDecodeJsonError constructor is actually used.
Also, it would be helpful to differentiate between a failure in decoding the RPC result and a failure in decoding the RPC error:

Suggested change
| ClientErrorResponse ClientError
| InvalidRpcResultResponse JsonDecodeError
| InvalidRpcErrorResponse JsonDecodeError

Comment on lines 25 to 38
:: forall err intermediate result
. (Affjax.Error -> err)
-- ^ Convert an Affjax error into custom error
-> (Int -> String -> err)
-- ^ Convert a non-2xx status code into custom error
-> (String -> JsonDecodeError -> err)
-- ^ Wrap aeson-parse/decode errors
-> (String -> Either JsonDecodeError intermediate)
-- ^ Parse the response body
-> (intermediate -> Either err result)
-- ^ Function from `intermediate` to `result`
-> Either Affjax.Error (Affjax.Response String)
-- ^ Argument
-> Either err result
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function could accept a record for better readability. Also, it might not need to be so generic, especially if we can reuse the same error type.

@marcusbfs marcusbfs merged commit 31e48fb into develop Feb 18, 2025
3 checks passed
@marcusbfs marcusbfs deleted the marcusbfs/http-ogmios branch February 18, 2025 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch to HTTP interface for ogmios
2 participants