From 5af2800f156f0082f16a8ea587892b03425d1223 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Fri, 2 Dec 2022 15:11:31 -0500 Subject: [PATCH] fix(core): always set p2p port in non-dev mode (#1919) * if geth is in non-dev mode, it has been explicitly set by either disabling discovery or setting a p2p port. To prevent geth from crashing if another process is using the default p2p port, always set the p2p port if geth is in non-dev mode. --- ethers-core/src/utils/geth.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ethers-core/src/utils/geth.rs b/ethers-core/src/utils/geth.rs index 657b8da3..04921c90 100644 --- a/ethers-core/src/utils/geth.rs +++ b/ethers-core/src/utils/geth.rs @@ -339,9 +339,9 @@ impl Geth { } } GethMode::NonDev(PrivateNetOptions { p2p_port, discovery }) => { - if let Some(p2p_port) = p2p_port { - cmd.arg("--port").arg(p2p_port.to_string()); - } + // automatically enable and set the p2p port if we are in non-dev mode + let port = if let Some(port) = p2p_port { port } else { unused_port() }; + cmd.arg("--port").arg(port.to_string()); // disable discovery if the flag is set if !discovery {