Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): set miner.etherbase in clique mode #2210

Merged
merged 6 commits into from Mar 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 24 additions & 11 deletions ethers-core/src/utils/geth.rs
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