From 9c09c2d98b022be0499b5ffdd3515be3f606b9a9 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Tue, 28 Feb 2023 19:21:44 -0500 Subject: [PATCH] fix(core): set miner.etherbase in clique mode (#2210) * fix(core): set miner.etherbase in clique mode * https://github.com/ethereum/go-ethereum/pull/26413 caused the default clique configuration for the GethInstance to fail to start, because we did not pass a `miner.etherbase` flag on startup * adds a `miner.etherbase` flag with the clique signer address as the argument * use format str instead of to_string * add comment on Debug * update is_clique comment for miner.etherbase * fix first etherbase flag * cargo fmt --- ethers-core/src/utils/geth.rs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/ethers-core/src/utils/geth.rs b/ethers-core/src/utils/geth.rs index e0368acc..a5ce02e9 100644 --- a/ethers-core/src/utils/geth.rs +++ b/ethers-core/src/utils/geth.rs @@ -241,8 +241,11 @@ impl Geth { self } - /// Sets the Clique Private Key to the `geth` executable, which will be later + /// Sets the Clique Private Key to the `geth` executable, which will be later /// loaded on the node. + /// + /// The address derived from this private key will be used to set the `miner.etherbase` field + /// on the node. #[must_use] pub fn set_clique_private_key>(mut self, private_key: T) -> Self { self.clique_private_key = Some(private_key.into()); @@ -392,24 +395,34 @@ impl Geth { let clique_config = CliqueConfig { period: Some(0), epoch: Some(8) }; genesis.config.clique = Some(clique_config); + let clique_addr = secret_key_to_address( + self.clique_private_key.as_ref().expect("is_clique == true"), + ); + // set the extraData field - let extra_data_bytes = [ - &[0u8; 32][..], - secret_key_to_address( - self.clique_private_key.as_ref().expect("is_clique == true"), - ) - .as_ref(), - &[0u8; 65][..], - ] - .concat(); + let extra_data_bytes = + [&[0u8; 32][..], clique_addr.as_ref(), &[0u8; 65][..]].concat(); let extra_data = Bytes::from(extra_data_bytes); genesis.extra_data = extra_data; + + // we must set the etherbase if using clique + // need to use format! / Debug here because the Address Display impl doesn't show + // the entire address + cmd.arg("--miner.etherbase").arg(format!("{clique_addr:?}")); } } else if is_clique { + let clique_addr = + secret_key_to_address(self.clique_private_key.as_ref().expect("is_clique == true")); + self.genesis = Some(Genesis::new( self.chain_id.expect("chain id must be set in clique mode"), - secret_key_to_address(self.clique_private_key.as_ref().expect("is_clique == true")), + clique_addr, )); + + // we must set the etherbase if using clique + // need to use format! / Debug here because the Address Display impl doesn't show the + // entire address + cmd.arg("--miner.etherbase").arg(format!("{clique_addr:?}")); } if let Some(ref genesis) = self.genesis {