From a01470e34876dcf67969063e1fc900ae947a0a54 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Thu, 31 Oct 2024 15:24:24 +0100 Subject: [PATCH] fix: read stacks-core http event POST payloads for ignored events (#673) Workaround for bug in stacks-core event emitter http code. Regression in stacks-core where http requests must now have their POST body read before closing the connection. ``` chainhook-1 | {"msg":"POST /drop_mempool_tx","level":"DEBUG","ts":"2024-10-30T10:41:34.030361652Z"} stacks-node-1 | WARN [1730284894.031170] [testnet/stacks-node/src/event_dispatcher.rs:496] [relayer-http://0.0.0.0:20443/] Event dispatcher: connection or request failed to chainhook:20455 - Custom { kind: Other, error: "Failed to send 8192 bytes: \"Failed to send socket data\"" }, backoff: 158.191s, attempts: 10 ``` Chainhook ignored some events by returning a 200 http response and closing the connection after reading the http request headers, and ignoring the request body. --- .../src/service/tests/observer_tests.rs | 4 ++-- components/chainhook-sdk/src/observer/http.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/chainhook-cli/src/service/tests/observer_tests.rs b/components/chainhook-cli/src/service/tests/observer_tests.rs index 449ee1378..e06df1d87 100644 --- a/components/chainhook-cli/src/service/tests/observer_tests.rs +++ b/components/chainhook-cli/src/service/tests/observer_tests.rs @@ -170,8 +170,8 @@ async fn start_and_ping_event_observer(config: EventObserverConfig, ingestion_po .unwrap(); await_observer_started(ingestion_port).await; } -#[test_case("/drop_mempool_tx", Method::POST, None)] -#[test_case("/attachments/new", Method::POST, None)] +#[test_case("/drop_mempool_tx", Method::POST, Some(&json!({})))] +#[test_case("/attachments/new", Method::POST, Some(&json!({})))] #[test_case("/mined_block", Method::POST, Some(&json!({})))] #[test_case("/mined_microblock", Method::POST, Some(&json!({})))] #[tokio::test] diff --git a/components/chainhook-sdk/src/observer/http.rs b/components/chainhook-sdk/src/observer/http.rs index 5a5938f51..8f0cbc76a 100644 --- a/components/chainhook-sdk/src/observer/http.rs +++ b/components/chainhook-sdk/src/observer/http.rs @@ -301,9 +301,9 @@ pub fn handle_new_mempool_tx( success_response() } -#[post("/drop_mempool_tx", format = "application/json")] -pub fn handle_drop_mempool_tx(ctx: &State) -> Json { - ctx.try_log(|logger| slog::debug!(logger, "POST /drop_mempool_tx")); +#[post("/drop_mempool_tx", format = "application/json", data = "")] +pub fn handle_drop_mempool_tx(payload: Json, ctx: &State) -> Json { + ctx.try_log(|logger| slog::debug!(logger, "POST /drop_mempool_tx {:?}", payload)); // TODO(lgalabru): use propagate mempool events Json(json!({ "status": 200, @@ -311,9 +311,9 @@ pub fn handle_drop_mempool_tx(ctx: &State) -> Json { })) } -#[post("/attachments/new", format = "application/json")] -pub fn handle_new_attachement(ctx: &State) -> Json { - ctx.try_log(|logger| slog::debug!(logger, "POST /attachments/new")); +#[post("/attachments/new", format = "application/json", data = "")] +pub fn handle_new_attachement(payload: Json, ctx: &State) -> Json { + ctx.try_log(|logger| slog::debug!(logger, "POST /attachments/new {:?}", payload)); Json(json!({ "status": 200, "result": "Ok",