Skip to content
Snippets Groups Projects
Commit 9b8ddcae authored by Anthony GRAIGNIC's avatar Anthony GRAIGNIC
Browse files

Add desired_vdf_duration in mining param

parent 0e7b3965
No related branches found
No related tags found
1 merge request!14Update mobility quantification
......@@ -86,6 +86,8 @@ struct MineParams {
rpc_url: Option<String>,
// Chain ID
chain_id: Option<u64>,
/// Desired VDF mean duration in seconds
desired_vdf_duration: Option<u64>,
}
async fn init() -> (u64, String) {
......@@ -217,8 +219,6 @@ async fn main() -> Result<(), anyhow::Error> {
if params.chain_id.clone().is_some() {
chain_id = params.chain_id.unwrap();
}
// println!("Processing {:?}", params.file);
// csv::Reader::from_path(path)
let records = read_csv(csv::Reader::from_path(params.file.clone())?);
if let Err(err) = records {
error!("error running example: {}", err);
......@@ -444,13 +444,26 @@ async fn main() -> Result<(), anyhow::Error> {
let miner_addr = wallet.address();
info!("Mining with 0x{:02x} ...", miner_addr);
let behavior = get_miner_behavior(wallet, chain_id, miner_addr);
// SEND IT
let provider = Provider::<Http>::try_from(rpc_url.clone()).unwrap();
let latest_block = provider.get_block(BlockNumber::Latest).await;
let network_difficulty = Some(
ethnum::U256::from_str(&latest_block.unwrap().unwrap().difficulty.to_string())
.unwrap(),
);
let behavior = get_miner_behavior(
wallet,
chain_id,
miner_addr,
network_difficulty,
params.desired_vdf_duration,
);
debug!(
"Miner behavior: {:?}",
serde_json::to_string(&behavior.clone())
);
// SEND IT
let block = provider
.request::<[Behavior; 1], Block>("emc_mine", [behavior])
.await
......
......@@ -13,17 +13,40 @@ use ethers::{
use ethnum::U256;
/// Get a RPC Behavior for miner with default values, ready to send.
pub fn get_miner_behavior(wallet: LocalWallet, chain_id: u64, to: Address) -> Behavior {
pub fn get_miner_behavior(
wallet: LocalWallet,
chain_id: u64,
to: Address,
network_difficulty: Option<U256>,
desired_vdf_duration: Option<u64>,
) -> Behavior {
let now = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs();
// const VDF_DIFFICULTY_FOR_10_MIN: u64 = 72;
// Mean VDF difficulty per sec = 72/600 on current machine (Macbook M1) and a hash maxed to 1 day.
// for a network difficulty of 1000000
const MEAN_VDF_DIFFICULTY_PER_SEC: u64 = 12;
let quantity = match network_difficulty {
Some(net_dif) => match desired_vdf_duration {
Some(vdf_dur) => net_dif
.saturating_mul(U256::from(MEAN_VDF_DIFFICULTY_PER_SEC * vdf_dur))
.saturating_div(U256::from(1000000_u128)),
_ => net_dif
.saturating_mul(U256::from(MEAN_VDF_DIFFICULTY_PER_SEC * 60))
.saturating_div(U256::from(1000000_u128)),
},
// default 1 min
_ => U256::from(MEAN_VDF_DIFFICULTY_PER_SEC * 60),
};
let behavior_msg = BehaviorMessage{
chain_id: U64::from(chain_id),
to:Some(to),
timestamp: U64::from(now),
quantity: U256::from(210000_u64),
quantity,
input: Bytes::from("0x015d8eb90000000000000000000000000000000000000000000000000000000000878c1c00000000000000000000000000000000000000000000000000000000644662bc0000000000000000000000000000000000000000000000000000001ee24fba17b7e19cc10812911dfa8a438e0a81a9933f843aa5b528899b8d9e221b649ae0df00000000000000000000000000000000000000000000000000000000000000060000000000000000000000007431310e026b69bfc676c0013e12a1a11411eec9000000000000000000000000000000000000000000000000000000000000083400000000000000000000000000000000000000000000000000000000000f4240") };
// let behavior = wallet.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment