Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fix(core): set miner.etherbase in clique mode (#2210)
Browse files Browse the repository at this point in the history
* fix(core): set miner.etherbase in clique mode

 * ethereum/go-ethereum#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
  • Loading branch information
Rjected authored Mar 1, 2023
1 parent ded611e commit 9c09c2d
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions ethers-core/src/utils/geth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Into<SigningKey>>(mut self, private_key: T) -> Self {
self.clique_private_key = Some(private_key.into());
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9c09c2d

Please sign in to comment.