diff --git a/ethers-core/src/utils/geth.rs b/ethers-core/src/utils/geth.rs index e0368acc4..a5ce02e90 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 {