grin/core/src/genesis.rs

159 lines
5.1 KiB
Rust
Raw Normal View History

// Copyright 2018 The Grin Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2016-10-21 03:06:12 +03:00
//! Definition of the genesis block. Placeholder for now.
// required for genesis replacement
//! #![allow(unused_imports)]
use chrono::prelude::{TimeZone, Utc};
2016-10-21 03:06:12 +03:00
use crate::core;
use crate::global;
use crate::pow::{Difficulty, Proof, ProofOfWork};
use crate::util;
use crate::util::secp::constants::SINGLE_BULLET_PROOF_SIZE;
2018-12-14 03:46:41 +03:00
use crate::util::secp::pedersen::{Commitment, RangeProof};
2018-12-15 01:13:05 +03:00
use crate::util::secp::Signature;
2016-10-21 03:06:12 +03:00
use crate::core::hash::Hash;
use crate::keychain::BlindingFactor;
/// Genesis block definition for development networks. The proof of work size
/// is small enough to mine it on the fly, so it does not contain its own
/// proof of work solution. Can also be easily mutated for different tests.
pub fn genesis_dev() -> core::Block {
core::Block::with_header(core::BlockHeader {
height: 0,
// previous: core::hash::Hash([0xff; 32]),
timestamp: Utc.ymd(1997, 8, 4).and_hms(0, 0, 0),
pow: ProofOfWork {
nonce: global::get_genesis_nonce(),
..Default::default()
},
..Default::default()
})
}
/// Placeholder for floonet genesis block, will definitely change before
/// release
pub fn genesis_floo() -> core::Block {
let gen = core::Block::with_header(core::BlockHeader {
height: 0,
timestamp: Utc.ymd(2018, 12, 20).and_hms(20, 0, 0), // REPLACE
prev_root: Hash::default(), // REPLACE
output_root: Hash::default(), // REPLACE
range_proof_root: Hash::default(), // REPLACE
kernel_root: Hash::default(), // REPLACE
total_kernel_offset: BlindingFactor::zero(), // REPLACE
output_mmr_size: 1,
kernel_mmr_size: 1,
pow: ProofOfWork {
total_difficulty: Difficulty::from_num(10_u64.pow(6)),
secondary_scaling: 1856,
nonce: 1, // REPLACE
2018-11-25 01:50:50 +03:00
proof: Proof {
nonces: vec![0; 42], // REPLACE
2018-11-25 01:50:50 +03:00
edge_bits: 29,
},
},
..Default::default()
});
let kernel = core::TxKernel {
features: core::KernelFeatures::COINBASE,
fee: 0,
lock_height: 0,
excess: Commitment::from_vec(vec![]), // REPLACE
excess_sig: Signature::from_raw_data(&[0; 64]).unwrap(), //REPLACE
};
let output = core::Output {
features: core::OutputFeatures::COINBASE,
commit: Commitment::from_vec(vec![]), // REPLACE
proof: RangeProof {
plen: SINGLE_BULLET_PROOF_SIZE,
proof: [0; SINGLE_BULLET_PROOF_SIZE], // REPLACE
},
};
gen.with_reward(output, kernel)
}
/// Placeholder for mainnet genesis block, will definitely change before
/// release so no use trying to pre-mine it.
pub fn genesis_main() -> core::Block {
2018-12-14 03:46:41 +03:00
let gen = core::Block::with_header(core::BlockHeader {
height: 0,
timestamp: Utc.ymd(2019, 1, 15).and_hms(12, 0, 0), // REPLACE
2018-12-14 03:46:41 +03:00
prev_root: Hash::default(), // REPLACE
output_root: Hash::default(), // REPLACE
range_proof_root: Hash::default(), // REPLACE
kernel_root: Hash::default(), // REPLACE
total_kernel_offset: BlindingFactor::zero(), // REPLACE
output_mmr_size: 1,
kernel_mmr_size: 1,
pow: ProofOfWork {
total_difficulty: Difficulty::from_num(10_u64.pow(8)),
secondary_scaling: 1856,
nonce: 1, // REPLACE
proof: Proof {
nonces: vec![0; 42], // REPLACE
edge_bits: 29,
},
},
..Default::default()
2018-12-14 03:46:41 +03:00
});
let kernel = core::TxKernel {
features: core::KernelFeatures::COINBASE,
2018-12-14 03:46:41 +03:00
fee: 0,
lock_height: 0,
excess: Commitment::from_vec(vec![]), // REPLACE
excess_sig: Signature::from_raw_data(&[0; 64]).unwrap(), //REPLACE
};
let output = core::Output {
features: core::OutputFeatures::COINBASE,
2018-12-14 03:46:41 +03:00
commit: Commitment::from_vec(vec![]), // REPLACE
proof: RangeProof {
plen: SINGLE_BULLET_PROOF_SIZE,
proof: [0; SINGLE_BULLET_PROOF_SIZE], // REPLACE
2018-12-15 01:13:05 +03:00
},
2018-12-14 03:46:41 +03:00
};
gen.with_reward(output, kernel)
2016-10-21 03:06:12 +03:00
}
#[cfg(test)]
mod test {
use super::*;
2018-12-15 01:35:59 +03:00
use crate::ser;
use crate::core::hash::Hashed;
// TODO hardcode the hashes once genesis is set
#[test]
fn floonet_genesis_hash() {
let gen_hash = genesis_floo().hash();
println!("floonet genesis hash: {}", gen_hash.to_hex());
let gen_bin = ser::ser_vec(&genesis_floo()).unwrap();
println!("floonet genesis full hash: {}\n", gen_bin.hash().to_hex());
//assert_eq!(gene_hash.to_hex, "");
}
2018-12-15 01:12:54 +03:00
// TODO hardcode the hashes once genesis is set
#[test]
fn mainnet_genesis_hash() {
let gen_hash = genesis_main().hash();
println!("mainnet genesis hash: {}", gen_hash.to_hex());
2018-12-15 01:35:59 +03:00
let gen_bin = ser::ser_vec(&genesis_main()).unwrap();
2018-12-15 01:12:54 +03:00
println!("mainnet genesis full hash: {}\n", gen_bin.hash().to_hex());
//assert_eq!(gene_hash.to_hex, "");
}
}