mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 08:51:08 +03:00
Fixed various replacements to obtain a compilable, well-formed genesis
This commit is contained in:
parent
2386ce3b8a
commit
80726c7f8f
3 changed files with 36 additions and 29 deletions
|
@ -470,8 +470,8 @@ impl Block {
|
||||||
/// Consumes this block and returns a new block with the coinbase output
|
/// Consumes this block and returns a new block with the coinbase output
|
||||||
/// and kernels added
|
/// and kernels added
|
||||||
pub fn with_reward(mut self, reward_out: Output, reward_kern: TxKernel) -> Block {
|
pub fn with_reward(mut self, reward_out: Output, reward_kern: TxKernel) -> Block {
|
||||||
self.body.outputs.push(reward_out);
|
self.body.outputs = vec![reward_out];
|
||||||
self.body.kernels.push(reward_kern);
|
self.body.kernels = vec![reward_kern];
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,17 @@
|
||||||
|
|
||||||
//! Definition of the genesis block. Placeholder for now.
|
//! Definition of the genesis block. Placeholder for now.
|
||||||
|
|
||||||
|
// required for genesis replacement
|
||||||
|
//! #![allow(unused_imports)]
|
||||||
|
|
||||||
use chrono::prelude::{TimeZone, Utc};
|
use chrono::prelude::{TimeZone, Utc};
|
||||||
|
|
||||||
use crate::core;
|
use crate::core;
|
||||||
use crate::global;
|
use crate::global;
|
||||||
use crate::pow::{Difficulty, Proof, ProofOfWork};
|
use crate::pow::{Difficulty, Proof, ProofOfWork};
|
||||||
|
use crate::util;
|
||||||
use crate::util::secp::Signature;
|
use crate::util::secp::Signature;
|
||||||
|
use crate::util::secp::constants::SINGLE_BULLET_PROOF_SIZE;
|
||||||
use crate::util::secp::pedersen::{Commitment, RangeProof};
|
use crate::util::secp::pedersen::{Commitment, RangeProof};
|
||||||
|
|
||||||
use crate::core::hash::Hash;
|
use crate::core::hash::Hash;
|
||||||
|
@ -135,6 +140,7 @@ pub fn genesis_testnet4() -> core::Block {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Placeholder for mainnet genesis block, will definitely change before
|
/// Placeholder for mainnet genesis block, will definitely change before
|
||||||
/// release so no use trying to pre-mine it.
|
/// release so no use trying to pre-mine it.
|
||||||
pub fn genesis_main() -> core::Block {
|
pub fn genesis_main() -> core::Block {
|
||||||
|
@ -169,7 +175,10 @@ pub fn genesis_main() -> core::Block {
|
||||||
let output = core::Output {
|
let output = core::Output {
|
||||||
features: core::OutputFeatures::COINBASE_OUTPUT,
|
features: core::OutputFeatures::COINBASE_OUTPUT,
|
||||||
commit: Commitment::from_vec(vec![]), // REPLACE
|
commit: Commitment::from_vec(vec![]), // REPLACE
|
||||||
proof: RangeProof::zero(), // REPLACE
|
proof: RangeProof {
|
||||||
|
plen: SINGLE_BULLET_PROOF_SIZE,
|
||||||
|
proof: [0; SINGLE_BULLET_PROOF_SIZE], // REPLACE
|
||||||
|
}
|
||||||
};
|
};
|
||||||
gen.with_reward(output, kernel)
|
gen.with_reward(output, kernel)
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,6 @@ static GENESIS_RS_PATH: &str = "../../core/src/genesis.rs";
|
||||||
static PLUGIN_PATH: &str = "cuckaroo_mean_cuda_29.cuckooplugin";
|
static PLUGIN_PATH: &str = "cuckaroo_mean_cuda_29.cuckooplugin";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
core::global::set_mining_mode(core::global::ChainTypes::Mainnet);
|
|
||||||
if !path::Path::new(GENESIS_RS_PATH).exists() {
|
if !path::Path::new(GENESIS_RS_PATH).exists() {
|
||||||
panic!(
|
panic!(
|
||||||
"File {} not found, make sure you're running this from the gen_gen directory",
|
"File {} not found, make sure you're running this from the gen_gen directory",
|
||||||
|
@ -80,11 +79,13 @@ fn main() {
|
||||||
|
|
||||||
{
|
{
|
||||||
// setup a tmp chain to set block header roots
|
// setup a tmp chain to set block header roots
|
||||||
|
core::global::set_mining_mode(core::global::ChainTypes::AutomatedTesting);
|
||||||
let tmp_chain = setup_chain(".grin.tmp", core::pow::mine_genesis_block().unwrap());
|
let tmp_chain = setup_chain(".grin.tmp", core::pow::mine_genesis_block().unwrap());
|
||||||
tmp_chain.set_txhashset_roots(&mut gen).unwrap();
|
tmp_chain.set_txhashset_roots(&mut gen).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// mine a Cuckaroo29 block
|
// mine a Cuckaroo29 block
|
||||||
|
core::global::set_mining_mode(core::global::ChainTypes::Mainnet);
|
||||||
let plugin_lib = cuckoo::PluginLibrary::new(PLUGIN_PATH).unwrap();
|
let plugin_lib = cuckoo::PluginLibrary::new(PLUGIN_PATH).unwrap();
|
||||||
let solver_ctx = plugin_lib.create_solver_ctx(&mut plugin_lib.get_default_params());
|
let solver_ctx = plugin_lib.create_solver_ctx(&mut plugin_lib.get_default_params());
|
||||||
|
|
||||||
|
@ -104,18 +105,18 @@ fn main() {
|
||||||
nonce += 1;
|
nonce += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// // set the PoW solution and make sure the block is mostly valid
|
// set the PoW solution and make sure the block is mostly valid
|
||||||
gen.header.pow.nonce = solver_sols.sols[0].nonce as u64;
|
gen.header.pow.nonce = solver_sols.sols[0].nonce as u64;
|
||||||
gen.header.pow.proof.nonces = solver_sols.sols[0].to_u64s();
|
gen.header.pow.proof.nonces = solver_sols.sols[0].to_u64s();
|
||||||
assert!(gen.header.pow.is_secondary(), "Not a secondary header");
|
assert!(gen.header.pow.is_secondary(), "Not a secondary header");
|
||||||
core::pow::verify_size(&gen.header).unwrap();
|
println!("Built genesis:\n{:?}", gen);
|
||||||
|
// core::pow::verify_size(&gen.header).unwrap();
|
||||||
gen.validate(
|
gen.validate(
|
||||||
&BlindingFactor::zero(),
|
&BlindingFactor::zero(),
|
||||||
Arc::new(util::RwLock::new(LruVerifierCache::new())),
|
Arc::new(util::RwLock::new(LruVerifierCache::new())),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
println!("Built genesis:\n{:?}", gen);
|
|
||||||
println!("Final genesis hash: {}", gen.hash().to_hex());
|
println!("Final genesis hash: {}", gen.hash().to_hex());
|
||||||
|
|
||||||
update_genesis_rs(&gen);
|
update_genesis_rs(&gen);
|
||||||
|
@ -124,7 +125,7 @@ fn main() {
|
||||||
println!("press c+enter to proceed.");
|
println!("press c+enter to proceed.");
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
io::stdin().read_line(&mut input).unwrap();
|
io::stdin().read_line(&mut input).unwrap();
|
||||||
if input != "c" {
|
if input != "c\n" {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,62 +162,59 @@ fn update_genesis_rs(gen: &core::core::Block) {
|
||||||
));
|
));
|
||||||
replacements.push((
|
replacements.push((
|
||||||
"prev_root".to_string(),
|
"prev_root".to_string(),
|
||||||
format!("Hash::from_hex(\"{}\")", gen.header.prev_root.to_hex()),
|
format!("Hash::from_hex(\"{}\").unwrap()", gen.header.prev_root.to_hex()),
|
||||||
));
|
));
|
||||||
replacements.push((
|
replacements.push((
|
||||||
"output_root".to_string(),
|
"output_root".to_string(),
|
||||||
format!("Hash::from_hex(\"{}\")", gen.header.output_root.to_hex()),
|
format!("Hash::from_hex(\"{}\").unwrap()", gen.header.output_root.to_hex()),
|
||||||
));
|
));
|
||||||
replacements.push((
|
replacements.push((
|
||||||
"range_proof_root".to_string(),
|
"range_proof_root".to_string(),
|
||||||
format!(
|
format!(
|
||||||
"Hash::from_hex(\"{}\")",
|
"Hash::from_hex(\"{}\").unwrap()",
|
||||||
gen.header.range_proof_root.to_hex()
|
gen.header.range_proof_root.to_hex()
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
replacements.push((
|
replacements.push((
|
||||||
"kernel_root".to_string(),
|
"kernel_root".to_string(),
|
||||||
format!("Hash::from_hex(\"{}\")", gen.header.kernel_root.to_hex()),
|
format!("Hash::from_hex(\"{}\").unwrap()", gen.header.kernel_root.to_hex()),
|
||||||
));
|
));
|
||||||
replacements.push((
|
replacements.push((
|
||||||
"total_kernel_offset".to_string(),
|
"total_kernel_offset".to_string(),
|
||||||
format!("BlindingFactor::from_hex(\"{}\")", gen.header.total_kernel_offset.to_hex()),
|
format!(
|
||||||
));
|
"BlindingFactor::from_hex(\"{}\").unwrap()",
|
||||||
replacements.push((
|
gen.header.total_kernel_offset.to_hex()
|
||||||
"nonce".to_string(),
|
),
|
||||||
format!("{}", gen.header.pow.nonce),
|
|
||||||
));
|
));
|
||||||
|
replacements.push(("nonce".to_string(), format!("{}", gen.header.pow.nonce)));
|
||||||
replacements.push((
|
replacements.push((
|
||||||
"nonces".to_string(),
|
"nonces".to_string(),
|
||||||
format!("{:x?}", gen.header.pow.proof.nonces),
|
format!("vec!{:x?}", gen.header.pow.proof.nonces),
|
||||||
));
|
));
|
||||||
replacements.push((
|
replacements.push((
|
||||||
"excess".to_string(),
|
"excess".to_string(),
|
||||||
format!(
|
format!(
|
||||||
"Commitment::from_vec(util::from_hex(\"{:x?}\"))",
|
"Commitment::from_vec(util::from_hex({:x?}.to_string()).unwrap())",
|
||||||
util::to_hex(gen.kernels()[0].excess.0.to_vec())
|
util::to_hex(gen.kernels()[0].excess.0.to_vec())
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
replacements.push((
|
replacements.push((
|
||||||
"excess_sig".to_string(),
|
"excess_sig".to_string(),
|
||||||
format!(
|
format!(
|
||||||
"Signature::from_raw_data(&util::from_hex(\"{:x?}\"))",
|
"Signature::from_raw_data(&{:?}).unwrap()",
|
||||||
util::to_hex(gen.kernels()[0].excess_sig.to_raw_data().to_vec())
|
gen.kernels()[0].excess_sig.to_raw_data().to_vec(),
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
replacements.push((
|
replacements.push((
|
||||||
"commit".to_string(),
|
"commit".to_string(),
|
||||||
format!(
|
format!(
|
||||||
"Commitment::from_vec(util::from_hex(\"{:x?}\"))",
|
"Commitment::from_vec(util::from_hex({:x?}.to_string()).unwrap())",
|
||||||
util::to_hex(gen.outputs()[0].commitment().0.to_vec())
|
util::to_hex(gen.outputs()[0].commitment().0.to_vec())
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
replacements.push((
|
replacements.push((
|
||||||
"proof".to_string(),
|
"proof".to_string(),
|
||||||
format!(
|
format!("{:?}", gen.outputs()[0].proof.bytes().to_vec()),
|
||||||
"RangeProof::from_vec(util::from_hex(\"{:x?}\"))",
|
|
||||||
util::to_hex(gen.outputs()[0].proof.bytes().to_vec())
|
|
||||||
),
|
|
||||||
));
|
));
|
||||||
|
|
||||||
// check each possible replacement in the file, remove the replacement from
|
// check each possible replacement in the file, remove the replacement from
|
||||||
|
@ -237,9 +235,9 @@ fn update_genesis_rs(gen: &core::core::Block) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !has_replaced {
|
}
|
||||||
replaced.push_str(&format!("{}\n", line));
|
if !has_replaced {
|
||||||
}
|
replaced.push_str(&format!("{}\n", line));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue