Add genesis_state_type::initial_timestamp; #17
This commit is contained in:
parent
38956692ee
commit
9b5bd12c67
8 changed files with 23 additions and 18 deletions
|
|
@ -138,6 +138,9 @@ void database::initialize_indexes()
|
||||||
|
|
||||||
void database::init_genesis(const genesis_state_type& genesis_state)
|
void database::init_genesis(const genesis_state_type& genesis_state)
|
||||||
{ try {
|
{ try {
|
||||||
|
FC_ASSERT( genesis_state.initial_timestamp != time_point_sec(), "Must initialize genesis timestamp." );
|
||||||
|
FC_ASSERT( genesis_state.initial_timestamp.sec_since_epoch() % GRAPHENE_DEFAULT_BLOCK_INTERVAL == 0,
|
||||||
|
"Genesis timestamp must be divisible by GRAPHENE_DEFAULT_BLOCK_INTERVAL." );
|
||||||
FC_ASSERT(genesis_state.initial_witness_candidates.size() > 0,
|
FC_ASSERT(genesis_state.initial_witness_candidates.size() > 0,
|
||||||
"Cannot start a chain with zero witnesses.");
|
"Cannot start a chain with zero witnesses.");
|
||||||
FC_ASSERT(genesis_state.initial_active_witnesses <= genesis_state.initial_witness_candidates.size(),
|
FC_ASSERT(genesis_state.initial_active_witnesses <= genesis_state.initial_witness_candidates.size(),
|
||||||
|
|
@ -246,7 +249,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
||||||
|
|
||||||
});
|
});
|
||||||
create<dynamic_global_property_object>( [&](dynamic_global_property_object& p) {
|
create<dynamic_global_property_object>( [&](dynamic_global_property_object& p) {
|
||||||
p.time = fc::time_point_sec(GRAPHENE_GENESIS_TIMESTAMP);
|
p.time = genesis_state.initial_timestamp;
|
||||||
p.witness_budget = 0;
|
p.witness_budget = 0;
|
||||||
});
|
});
|
||||||
create<block_summary_object>([&](block_summary_object&) {});
|
create<block_summary_object>([&](block_summary_object&) {});
|
||||||
|
|
@ -426,7 +429,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
||||||
{
|
{
|
||||||
worker_create_operation op;
|
worker_create_operation op;
|
||||||
op.owner = get_account_id( worker.owner_name );
|
op.owner = get_account_id( worker.owner_name );
|
||||||
op.work_begin_date = time_point_sec( GRAPHENE_GENESIS_TIMESTAMP );
|
op.work_begin_date = genesis_state.initial_timestamp;
|
||||||
op.work_end_date = time_point_sec::maximum();
|
op.work_end_date = time_point_sec::maximum();
|
||||||
op.daily_pay = worker.daily_pay;
|
op.daily_pay = worker.daily_pay;
|
||||||
op.name = "Genesis-Worker-" + worker.owner_name;
|
op.name = "Genesis-Worker-" + worker.owner_name;
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,6 @@
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
static_assert((GRAPHENE_GENESIS_TIMESTAMP % GRAPHENE_DEFAULT_BLOCK_INTERVAL) == 0,
|
|
||||||
"GRAPHENE_GENESIS_TIMESTAMP must be aligned to a block interval.");
|
|
||||||
|
|
||||||
pair<witness_id_type, bool> database::get_scheduled_witness(uint32_t slot_num)const
|
pair<witness_id_type, bool> database::get_scheduled_witness(uint32_t slot_num)const
|
||||||
{
|
{
|
||||||
if( slot_num == 0 )
|
if( slot_num == 0 )
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,6 @@
|
||||||
#define GRAPHENE_DEFAULT_FEE_LIQUIDATION_THRESHOLD GRAPHENE_BLOCKCHAIN_PRECISION * 100;
|
#define GRAPHENE_DEFAULT_FEE_LIQUIDATION_THRESHOLD GRAPHENE_BLOCKCHAIN_PRECISION * 100;
|
||||||
#define GRAPHENE_DEFAULT_ACCOUNTS_PER_FEE_SCALE 1000
|
#define GRAPHENE_DEFAULT_ACCOUNTS_PER_FEE_SCALE 1000
|
||||||
#define GRAPHENE_DEFAULT_ACCOUNT_FEE_SCALE_BITSHIFTS 4
|
#define GRAPHENE_DEFAULT_ACCOUNT_FEE_SCALE_BITSHIFTS 4
|
||||||
#define GRAPHENE_GENESIS_TIMESTAMP (1431700000) /// Should be divisible by GRAPHENE_DEFAULT_BLOCK_INTERVAL
|
|
||||||
|
|
||||||
#define GRAPHENE_MAX_WORKER_NAME_LENGTH 63
|
#define GRAPHENE_MAX_WORKER_NAME_LENGTH 63
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,6 @@ FC_REFLECT(graphene::chain::genesis_state_type::initial_committee_member_type, (
|
||||||
FC_REFLECT(graphene::chain::genesis_state_type::initial_worker_type, (owner_name)(daily_pay))
|
FC_REFLECT(graphene::chain::genesis_state_type::initial_worker_type, (owner_name)(daily_pay))
|
||||||
|
|
||||||
FC_REFLECT(graphene::chain::genesis_state_type,
|
FC_REFLECT(graphene::chain::genesis_state_type,
|
||||||
(initial_parameters)(initial_accounts)(initial_assets)(initial_balances)
|
(initial_timestamp)(initial_parameters)(initial_accounts)(initial_assets)(initial_balances)
|
||||||
(initial_vesting_balances)(initial_active_witnesses)(initial_witness_candidates)
|
(initial_vesting_balances)(initial_active_witnesses)(initial_witness_candidates)
|
||||||
(initial_committee_candidates)(initial_worker_candidates))
|
(initial_committee_candidates)(initial_worker_candidates))
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,8 @@ BOOST_AUTO_TEST_CASE( two_node_network )
|
||||||
fc::temp_directory app2_dir;
|
fc::temp_directory app2_dir;
|
||||||
fc::temp_file genesis_json;
|
fc::temp_file genesis_json;
|
||||||
|
|
||||||
fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP );
|
// TODO: Time should be read from the blockchain
|
||||||
|
fc::time_point_sec now( 1431700000 );
|
||||||
|
|
||||||
graphene::app::application app1;
|
graphene::app::application app1;
|
||||||
app1.register_plugin<graphene::account_history::account_history_plugin>();
|
app1.register_plugin<graphene::account_history::account_history_plugin>();
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,8 @@ database_fixture::database_fixture()
|
||||||
mhplugin->plugin_set_app(&app);
|
mhplugin->plugin_set_app(&app);
|
||||||
mhplugin->plugin_initialize(options);
|
mhplugin->plugin_initialize(options);
|
||||||
|
|
||||||
|
genesis_state.initial_timestamp = time_point_sec( GRAPHENE_TESTING_GENESIS_TIMESTAMP );
|
||||||
|
|
||||||
genesis_state.initial_active_witnesses = 10;
|
genesis_state.initial_active_witnesses = 10;
|
||||||
for( int i = 0; i < genesis_state.initial_active_witnesses; ++i )
|
for( int i = 0; i < genesis_state.initial_active_witnesses; ++i )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
using namespace graphene::db;
|
using namespace graphene::db;
|
||||||
|
|
||||||
|
#define GRAPHENE_TESTING_GENESIS_TIMESTAMP (1431700000)
|
||||||
|
|
||||||
#define PUSH_TX \
|
#define PUSH_TX \
|
||||||
graphene::chain::test::_push_transaction
|
graphene::chain::test::_push_transaction
|
||||||
|
|
||||||
|
|
@ -102,8 +104,6 @@ struct database_fixture {
|
||||||
fc::ecc::private_key delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
|
fc::ecc::private_key delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
|
||||||
public_key_type delegate_pub_key;
|
public_key_type delegate_pub_key;
|
||||||
|
|
||||||
fc::time_point_sec genesis_time = fc::time_point_sec( GRAPHENE_GENESIS_TIMESTAMP );
|
|
||||||
fc::time_point_sec now = fc::time_point_sec( GRAPHENE_GENESIS_TIMESTAMP );
|
|
||||||
optional<fc::temp_directory> data_dir;
|
optional<fc::temp_directory> data_dir;
|
||||||
bool skip_key_index_test = false;
|
bool skip_key_index_test = false;
|
||||||
uint32_t anon_acct_count;
|
uint32_t anon_acct_count;
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,9 @@ using namespace graphene::chain;
|
||||||
|
|
||||||
genesis_state_type make_genesis() {
|
genesis_state_type make_genesis() {
|
||||||
genesis_state_type genesis_state;
|
genesis_state_type genesis_state;
|
||||||
|
|
||||||
|
genesis_state.initial_timestamp = time_point_sec( GRAPHENE_TESTING_GENESIS_TIMESTAMP );
|
||||||
|
|
||||||
auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")));
|
auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")));
|
||||||
genesis_state.initial_active_witnesses = 10;
|
genesis_state.initial_active_witnesses = 10;
|
||||||
for( int i = 0; i < genesis_state.initial_active_witnesses; ++i )
|
for( int i = 0; i < genesis_state.initial_active_witnesses; ++i )
|
||||||
|
|
@ -117,7 +120,7 @@ BOOST_AUTO_TEST_CASE( block_database_test )
|
||||||
BOOST_AUTO_TEST_CASE( generate_empty_blocks )
|
BOOST_AUTO_TEST_CASE( generate_empty_blocks )
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP );
|
fc::time_point_sec now( GRAPHENE_TESTING_GENESIS_TIMESTAMP );
|
||||||
fc::temp_directory data_dir;
|
fc::temp_directory data_dir;
|
||||||
signed_block b;
|
signed_block b;
|
||||||
|
|
||||||
|
|
@ -169,7 +172,7 @@ BOOST_AUTO_TEST_CASE( undo_block )
|
||||||
{
|
{
|
||||||
database db;
|
database db;
|
||||||
db.open(data_dir.path(), make_genesis() );
|
db.open(data_dir.path(), make_genesis() );
|
||||||
fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP );
|
fc::time_point_sec now( GRAPHENE_TESTING_GENESIS_TIMESTAMP );
|
||||||
|
|
||||||
auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
|
auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
|
||||||
for( uint32_t i = 0; i < 5; ++i )
|
for( uint32_t i = 0; i < 5; ++i )
|
||||||
|
|
@ -205,7 +208,7 @@ BOOST_AUTO_TEST_CASE( fork_blocks )
|
||||||
try {
|
try {
|
||||||
fc::temp_directory data_dir1;
|
fc::temp_directory data_dir1;
|
||||||
fc::temp_directory data_dir2;
|
fc::temp_directory data_dir2;
|
||||||
fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP );
|
fc::time_point_sec now( GRAPHENE_TESTING_GENESIS_TIMESTAMP );
|
||||||
|
|
||||||
database db1;
|
database db1;
|
||||||
db1.open(data_dir1.path(), make_genesis());
|
db1.open(data_dir1.path(), make_genesis());
|
||||||
|
|
@ -269,7 +272,7 @@ BOOST_AUTO_TEST_CASE( fork_blocks )
|
||||||
BOOST_AUTO_TEST_CASE( undo_pending )
|
BOOST_AUTO_TEST_CASE( undo_pending )
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
fc::time_point_sec now(GRAPHENE_GENESIS_TIMESTAMP);
|
fc::time_point_sec now(GRAPHENE_TESTING_GENESIS_TIMESTAMP);
|
||||||
fc::temp_directory data_dir;
|
fc::temp_directory data_dir;
|
||||||
{
|
{
|
||||||
database db;
|
database db;
|
||||||
|
|
@ -334,7 +337,7 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create )
|
||||||
db1.open(dir1.path(), make_genesis());
|
db1.open(dir1.path(), make_genesis());
|
||||||
db2.open(dir2.path(), make_genesis());
|
db2.open(dir2.path(), make_genesis());
|
||||||
|
|
||||||
fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP );
|
fc::time_point_sec now( GRAPHENE_TESTING_GENESIS_TIMESTAMP );
|
||||||
auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
|
auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
|
||||||
public_key_type delegate_pub_key = delegate_priv_key.get_public_key();
|
public_key_type delegate_pub_key = delegate_priv_key.get_public_key();
|
||||||
const graphene::db::index& account_idx = db1.get_index(protocol_ids, account_object_type);
|
const graphene::db::index& account_idx = db1.get_index(protocol_ids, account_object_type);
|
||||||
|
|
@ -355,7 +358,7 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create )
|
||||||
|
|
||||||
BOOST_CHECK(nathan_id(db1).name == "nathan");
|
BOOST_CHECK(nathan_id(db1).name == "nathan");
|
||||||
|
|
||||||
now = fc::time_point_sec( GRAPHENE_GENESIS_TIMESTAMP );
|
now = fc::time_point_sec( GRAPHENE_TESTING_GENESIS_TIMESTAMP );
|
||||||
now += db2.block_interval();
|
now += db2.block_interval();
|
||||||
b = db2.generate_block(now, db2.get_scheduled_witness(1).first, delegate_priv_key, database::skip_nothing);
|
b = db2.generate_block(now, db2.get_scheduled_witness(1).first, delegate_priv_key, database::skip_nothing);
|
||||||
db1.push_block(b);
|
db1.push_block(b);
|
||||||
|
|
@ -384,7 +387,7 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create )
|
||||||
BOOST_AUTO_TEST_CASE( duplicate_transactions )
|
BOOST_AUTO_TEST_CASE( duplicate_transactions )
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP );
|
fc::time_point_sec now( GRAPHENE_TESTING_GENESIS_TIMESTAMP );
|
||||||
fc::temp_directory dir1,
|
fc::temp_directory dir1,
|
||||||
dir2;
|
dir2;
|
||||||
database db1,
|
database db1,
|
||||||
|
|
@ -433,7 +436,7 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions )
|
||||||
BOOST_AUTO_TEST_CASE( tapos )
|
BOOST_AUTO_TEST_CASE( tapos )
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP );
|
fc::time_point_sec now( GRAPHENE_TESTING_GENESIS_TIMESTAMP );
|
||||||
fc::temp_directory dir1,
|
fc::temp_directory dir1,
|
||||||
dir2;
|
dir2;
|
||||||
database db1,
|
database db1,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue