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
This commit is contained in:
Dan Cline 2023-02-28 19:21:44 -05:00 committed by GitHub
parent ded611e714
commit 9c09c2d98b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 11 deletions

View File

@ -243,6 +243,9 @@ impl Geth {
/// 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. /// 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] #[must_use]
pub fn set_clique_private_key<T: Into<SigningKey>>(mut self, private_key: T) -> Self { pub fn set_clique_private_key<T: Into<SigningKey>>(mut self, private_key: T) -> Self {
self.clique_private_key = Some(private_key.into()); self.clique_private_key = Some(private_key.into());
@ -392,24 +395,34 @@ impl Geth {
let clique_config = CliqueConfig { period: Some(0), epoch: Some(8) }; let clique_config = CliqueConfig { period: Some(0), epoch: Some(8) };
genesis.config.clique = Some(clique_config); genesis.config.clique = Some(clique_config);
// set the extraData field let clique_addr = secret_key_to_address(
let extra_data_bytes = [
&[0u8; 32][..],
secret_key_to_address(
self.clique_private_key.as_ref().expect("is_clique == true"), self.clique_private_key.as_ref().expect("is_clique == true"),
) );
.as_ref(),
&[0u8; 65][..], // set the extraData field
] let extra_data_bytes =
.concat(); [&[0u8; 32][..], clique_addr.as_ref(), &[0u8; 65][..]].concat();
let extra_data = Bytes::from(extra_data_bytes); let extra_data = Bytes::from(extra_data_bytes);
genesis.extra_data = extra_data; 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 { } 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.genesis = Some(Genesis::new(
self.chain_id.expect("chain id must be set in clique mode"), 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 { if let Some(ref genesis) = self.genesis {