From 79f2dca33aac623bbc35dba2e8c8da7c6c5f411f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Tue, 31 Oct 2017 17:59:14 +0100 Subject: [PATCH] Shell: fix possible stack overflow in validation. Ouch! That was a subtle Lwt misuse. With the current (very-old) validator code, when the validation of block is waiting to the validation of its predecessor, a "pending" Lwt thread is created. The validation of the predecessor might also wait on its own predecessor, potentially creating a very long chain of pending validation"... If in the process one of the block is tagged invalid, all the pending "successors" in the chain are 'wakeuped' immediatly and in sequence, potentially blowing the stack in the process. A quick fix is to add an `Lwt_unix.yield` to break the recursion. A better fix is to not create such long chain of "pending" validations. See merge request !59. --- src/node/shell/validator.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/node/shell/validator.ml b/src/node/shell/validator.ml index 6014a03fd..aa7b22cf9 100644 --- a/src/node/shell/validator.ml +++ b/src/node/shell/validator.ml @@ -474,6 +474,7 @@ module Context_db = struct let net_state = Distributed_db.state v.net_db in get_context v block.Block_header.shell.predecessor >>= function | Error _ as error -> + Lwt_unix.yield () >>= fun () -> set_context v hash (Error [(* TODO *)]) >>= fun () -> Lwt.return error | Ok _context ->