2018-03-05 22:33:44 +03:00
|
|
|
// Copyright 2018 The Grin Developers
|
2016-10-22 21:35:48 +03:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2018-12-14 05:56:45 +03:00
|
|
|
// required for genesis replacement
|
|
|
|
//! #![allow(unused_imports)]
|
|
|
|
|
2018-08-10 17:00:18 +03:00
|
|
|
use chrono::prelude::{TimeZone, Utc};
|
2016-10-21 03:06:12 +03:00
|
|
|
|
2018-12-08 02:59:40 +03:00
|
|
|
use crate::core;
|
|
|
|
use crate::global;
|
|
|
|
use crate::pow::{Difficulty, Proof, ProofOfWork};
|
2018-12-14 05:56:45 +03:00
|
|
|
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
|
|
|
|
2018-12-13 04:54:25 +03:00
|
|
|
use crate::core::hash::Hash;
|
|
|
|
use crate::keychain::BlindingFactor;
|
|
|
|
|
2017-11-16 00:49:15 +03:00
|
|
|
/// 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 {
|
2018-08-16 00:14:48 +03:00
|
|
|
core::Block::with_header(core::BlockHeader {
|
|
|
|
height: 0,
|
2018-11-01 12:51:32 +03:00
|
|
|
// previous: core::hash::Hash([0xff; 32]),
|
2018-08-16 00:14:48 +03:00
|
|
|
timestamp: Utc.ymd(1997, 8, 4).and_hms(0, 0, 0),
|
2018-09-19 01:12:57 +03:00
|
|
|
pow: ProofOfWork {
|
2018-09-11 01:36:57 +03:00
|
|
|
nonce: global::get_genesis_nonce(),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2018-08-16 00:14:48 +03:00
|
|
|
..Default::default()
|
|
|
|
})
|
2017-11-16 00:49:15 +03:00
|
|
|
}
|
|
|
|
|
2018-12-19 01:03:55 +03:00
|
|
|
/// Placeholder for floonet genesis block, will definitely change before
|
|
|
|
/// release
|
|
|
|
pub fn genesis_floo() -> core::Block {
|
|
|
|
let gen = core::Block::with_header(core::BlockHeader {
|
2018-10-10 12:09:44 +03:00
|
|
|
height: 0,
|
2018-12-19 01:03:55 +03:00
|
|
|
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,
|
2018-10-10 12:09:44 +03:00
|
|
|
pow: ProofOfWork {
|
2018-12-19 01:03:55 +03:00
|
|
|
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 {
|
2018-12-19 01:03:55 +03:00
|
|
|
nonces: vec![0; 42], // REPLACE
|
2018-11-25 01:50:50 +03:00
|
|
|
edge_bits: 29,
|
|
|
|
},
|
2018-10-10 12:09:44 +03:00
|
|
|
},
|
|
|
|
..Default::default()
|
2018-12-19 01:03:55 +03:00
|
|
|
});
|
|
|
|
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)
|
2018-10-10 12:09:44 +03:00
|
|
|
}
|
2018-12-14 05:56:45 +03:00
|
|
|
|
2017-11-16 00:49:15 +03:00
|
|
|
/// 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 {
|
2018-08-16 00:14:48 +03:00
|
|
|
height: 0,
|
2018-12-13 04:54:25 +03:00
|
|
|
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
|
2018-12-11 04:07:17 +03:00
|
|
|
output_mmr_size: 1,
|
|
|
|
kernel_mmr_size: 1,
|
2018-09-19 01:12:57 +03:00
|
|
|
pow: ProofOfWork {
|
2018-12-11 04:07:17 +03:00
|
|
|
total_difficulty: Difficulty::from_num(10_u64.pow(8)),
|
|
|
|
secondary_scaling: 1856,
|
2018-12-13 04:54:25 +03:00
|
|
|
nonce: 1, // REPLACE
|
2018-12-11 04:07:17 +03:00
|
|
|
proof: Proof {
|
2018-12-13 04:54:25 +03:00
|
|
|
nonces: vec![0; 42], // REPLACE
|
2018-12-11 04:07:17 +03:00
|
|
|
edge_bits: 29,
|
|
|
|
},
|
2018-09-11 01:36:57 +03:00
|
|
|
},
|
2018-08-16 00:14:48 +03:00
|
|
|
..Default::default()
|
2018-12-14 03:46:41 +03:00
|
|
|
});
|
|
|
|
let kernel = core::TxKernel {
|
2018-12-19 01:03:55 +03:00
|
|
|
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 {
|
2018-12-19 01:03:55 +03:00
|
|
|
features: core::OutputFeatures::COINBASE,
|
2018-12-14 03:46:41 +03:00
|
|
|
commit: Commitment::from_vec(vec![]), // REPLACE
|
2018-12-14 05:56:45 +03:00
|
|
|
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
|
|
|
}
|
2018-12-13 04:54:25 +03:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
2018-12-15 01:35:59 +03:00
|
|
|
use crate::ser;
|
|
|
|
use crate::core::hash::Hashed;
|
2018-12-13 04:54:25 +03:00
|
|
|
|
2018-12-19 01:03:55 +03:00
|
|
|
// 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
|
2018-12-13 04:54:25 +03:00
|
|
|
#[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());
|
2018-12-13 04:54:25 +03:00
|
|
|
//assert_eq!(gene_hash.to_hex, "");
|
|
|
|
}
|
|
|
|
}
|