From ba21c6b419d9984c46463f75d6ab8466e8ffdd43 Mon Sep 17 00:00:00 2001 From: Carlos Souza Date: Wed, 24 Jan 2024 08:25:59 -0500 Subject: [PATCH 1/4] Attempt to prevent disconnection. --- lib/xogmios/chain_sync/connection.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xogmios/chain_sync/connection.ex b/lib/xogmios/chain_sync/connection.ex index 6f02b2c..d065e03 100644 --- a/lib/xogmios/chain_sync/connection.ex +++ b/lib/xogmios/chain_sync/connection.ex @@ -43,7 +43,7 @@ defmodule Xogmios.ChainSync.Connection do @impl true def ondisconnect(_reason, state) do - {:ok, state} + {:reconnect, 5_000, state} end @impl true From bb08ab835902d22567e961b8a63d44a770da1332 Mon Sep 17 00:00:00 2001 From: Carlos Souza Date: Wed, 24 Jan 2024 15:12:58 -0500 Subject: [PATCH 2/4] Previous fix works but trying keepalive instead --- lib/xogmios/chain_sync.ex | 4 +++- lib/xogmios/chain_sync/connection.ex | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/xogmios/chain_sync.ex b/lib/xogmios/chain_sync.ex index 3a9b826..bc26a31 100644 --- a/lib/xogmios/chain_sync.ex +++ b/lib/xogmios/chain_sync.ex @@ -8,10 +8,12 @@ defmodule Xogmios.ChainSync do @callback handle_block(map(), any()) :: {:ok, :next_block, map()} | {:ok, map()} | {:ok, :close, map()} + @keepalive_in_ms 5_000 + def start_link(client, opts) do {url, opts} = Keyword.pop(opts, :url) initial_state = Keyword.merge(opts, handler: client) - :websocket_client.start_link(url, client, initial_state) + :websocket_client.start_link(url, client, initial_state, keepalive: @keepalive_in_ms) end defmacro __using__(_opts) do diff --git a/lib/xogmios/chain_sync/connection.ex b/lib/xogmios/chain_sync/connection.ex index d065e03..6f02b2c 100644 --- a/lib/xogmios/chain_sync/connection.ex +++ b/lib/xogmios/chain_sync/connection.ex @@ -43,7 +43,7 @@ defmodule Xogmios.ChainSync.Connection do @impl true def ondisconnect(_reason, state) do - {:reconnect, 5_000, state} + {:ok, state} end @impl true From 4d58b08d019850e4f2c47645599eaa1d050ad358 Mon Sep 17 00:00:00 2001 From: Carlos Souza Date: Thu, 25 Jan 2024 05:41:36 -0500 Subject: [PATCH 3/4] Add comments for keepalive --- lib/xogmios/chain_sync.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/xogmios/chain_sync.ex b/lib/xogmios/chain_sync.ex index bc26a31..5601907 100644 --- a/lib/xogmios/chain_sync.ex +++ b/lib/xogmios/chain_sync.ex @@ -8,6 +8,8 @@ defmodule Xogmios.ChainSync do @callback handle_block(map(), any()) :: {:ok, :next_block, map()} | {:ok, map()} | {:ok, :close, map()} + # The keepalive option is used to maintain the connection active. + # This is important because proxies might close idle connections after a few seconds. @keepalive_in_ms 5_000 def start_link(client, opts) do From 41ab5994ef9175ba2461ccc2dff0eb7051fbb12a Mon Sep 17 00:00:00 2001 From: Carlos Souza Date: Thu, 25 Jan 2024 05:50:12 -0500 Subject: [PATCH 4/4] Update README --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9850a96..782d088 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,15 @@ An Elixir client for [Ogmios](https://github.com/CardanoSolutions/ogmios). > Ogmios is a lightweight bridge interface for a Cardano node. It offers a WebSockets API that enables local clients to speak Ouroboros' mini-protocols via JSON/RPC. - https://ogmios.dev/ -It currently only partially supports the **Chain Synchronization** and **State Query** mini-protocols. See [Examples](#examples) section below for information on how to use it. +Mini-Protocols supported by this library: + +- [x] Chain Synchronization +- [ ] State Query (partially supported) +- [ ] Mempool Monitoring +- [ ] Tx Submission + + +See [Examples](#examples) section below for information on how to use. ## Installing