From 4a7cbaf610a6fec3e70a2d750126f708c9e823af Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Mon, 6 Jul 2015 14:27:04 -0400 Subject: [PATCH 1/7] Set default genesis fees to 1 GPH; #17 --- libraries/app/application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index f615fd59..9da9323a 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -59,7 +59,7 @@ namespace detail { dlog("Allocating all stake to ${key}", ("key", utilities::key_to_wif(nathan_key))); genesis_state_type initial_state; fc::reflector::visit( - fee_schedule_type::fee_set_visitor{initial_state.initial_parameters.current_fees, 0}); + fee_schedule_type::fee_set_visitor{initial_state.initial_parameters.current_fees, GRAPHENE_BLOCKCHAIN_PRECISION}); secret_hash_type::encoder enc; fc::raw::pack(enc, nathan_key); fc::raw::pack(enc, secret_hash_type()); From fc7fb86cd20fad30ea1bc6f9de42d1e83aa2a27a Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Mon, 6 Jul 2015 14:41:31 -0400 Subject: [PATCH 2/7] Temporarily allow import BTS address/pubkey prefixes; #17 --- libraries/chain/address.cpp | 8 ++++++ .../chain/include/graphene/chain/types.hpp | 3 +++ libraries/chain/types.cpp | 25 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/libraries/chain/address.cpp b/libraries/chain/address.cpp index cb83a226..8ac6a127 100644 --- a/libraries/chain/address.cpp +++ b/libraries/chain/address.cpp @@ -29,12 +29,20 @@ namespace graphene { { FC_ASSERT( is_valid( base58str ) ); std::string prefix( GRAPHENE_ADDRESS_PREFIX ); + + // TODO: This is temporary for testing + if( is_valid( base58str, "BTS" ) ) prefix = std::string( "BTS" ); + std::vector v = fc::from_base58( base58str.substr( prefix.size() ) ); memcpy( (char*)addr._hash, v.data(), std::min( v.size()-4, sizeof( addr ) ) ); } bool address::is_valid( const std::string& base58str, const std::string& prefix ) { + // TODO: This is temporary for testing + if( prefix == GRAPHENE_ADDRESS_PREFIX && is_valid( base58str, "BTS" ) ) + return true; + const size_t prefix_len = prefix.size(); if( base58str.size() <= prefix_len ) return false; diff --git a/libraries/chain/include/graphene/chain/types.hpp b/libraries/chain/include/graphene/chain/types.hpp index 170909d3..1e502df7 100644 --- a/libraries/chain/include/graphene/chain/types.hpp +++ b/libraries/chain/include/graphene/chain/types.hpp @@ -422,6 +422,9 @@ namespace graphene { namespace chain { friend bool operator == ( const public_key_type& p1, const fc::ecc::public_key& p2); friend bool operator == ( const public_key_type& p1, const public_key_type& p2); friend bool operator != ( const public_key_type& p1, const public_key_type& p2); + + // TODO: This is temporary for testing + bool is_valid_v1( const std::string& base58str ); }; struct chain_parameters diff --git a/libraries/chain/types.cpp b/libraries/chain/types.cpp index 0dc3978c..bef1bba1 100644 --- a/libraries/chain/types.cpp +++ b/libraries/chain/types.cpp @@ -38,6 +38,17 @@ namespace graphene { namespace chain { // TODO: Refactor syntactic checks into static is_valid() // to make public_key_type API more similar to address API std::string prefix( GRAPHENE_ADDRESS_PREFIX ); + + // TODO: This is temporary for testing + try + { + if( is_valid_v1( base58str ) ) + prefix = std::string( "BTS" ); + } + catch( ... ) + { + } + const size_t prefix_len = prefix.size(); FC_ASSERT( base58str.size() > prefix_len ); FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) ); @@ -47,6 +58,20 @@ namespace graphene { namespace chain { FC_ASSERT( fc::ripemd160::hash( key_data.data, key_data.size() )._hash[0] == bin_key.check ); }; + // TODO: This is temporary for testing + bool public_key_type::is_valid_v1( const std::string& base58str ) + { + std::string prefix( "BTS" ); + const size_t prefix_len = prefix.size(); + FC_ASSERT( base58str.size() > prefix_len ); + FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) ); + auto bin = fc::from_base58( base58str.substr( prefix_len ) ); + auto bin_key = fc::raw::unpack(bin); + fc::ecc::public_key_data key_data = bin_key.data; + FC_ASSERT( fc::ripemd160::hash( key_data.data, key_data.size() )._hash[0] == bin_key.check ); + return true; + } + public_key_type::operator fc::ecc::public_key_data() const { return key_data; From df03598be95f48b7f89a00308b9ea61f9568bcc8 Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Mon, 6 Jul 2015 14:42:37 -0400 Subject: [PATCH 3/7] Do not capture genesis_state on exception --- libraries/chain/db_init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index d9852454..387632fe 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -458,6 +458,6 @@ void database::init_genesis(const genesis_state_type& genesis_state) }); _undo_db.enable(); -} FC_CAPTURE_AND_RETHROW((genesis_state)) } +} FC_CAPTURE_AND_RETHROW(()) } } } From 81df85aed7919d8dcc77b2a1551ed171dbd49956 Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Mon, 6 Jul 2015 14:53:02 -0400 Subject: [PATCH 4/7] Fix BTS genesis import error; #17 --- libraries/chain/operations.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libraries/chain/operations.cpp b/libraries/chain/operations.cpp index c274b6ed..11b32e46 100644 --- a/libraries/chain/operations.cpp +++ b/libraries/chain/operations.cpp @@ -187,11 +187,9 @@ share_type account_create_operation::calculate_fee( const fee_schedule_type& sch uint32_t s = name.size(); if( is_cheap_name(name) ) - s = 63; + s = 8; - FC_ASSERT( s >= 2 ); - - if( s >= 8 && s < 63 ) + if( s >= 8 ) core_fee_required = schedule.account_len8up_fee; else if( s == 7 ) core_fee_required = schedule.account_len7_fee; @@ -203,7 +201,7 @@ share_type account_create_operation::calculate_fee( const fee_schedule_type& sch core_fee_required = schedule.account_len4_fee; else if( s == 3 ) core_fee_required = schedule.account_len3_fee; - else if( s == 2 ) + else if( s <= 2 ) core_fee_required = schedule.account_len2_fee; // Authorities and vote lists can be arbitrarily large, so charge a data fee for big ones From 3d5f9ee7173e4cf3c593f278525a07314012bb77 Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Mon, 6 Jul 2015 14:57:03 -0400 Subject: [PATCH 5/7] Update README link --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b246ac24..7e06a971 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Starting Graphene For Ubuntu 14.04 LTS users, see this link first: https://github.com/cryptonomex/graphene/wiki/build-ubuntu - + and then proceed with: git clone https://github.com/cryptonomex/graphene.git @@ -18,7 +18,9 @@ and then proceed with: make ./programs/witness_node/witness_node -This will launch the witness node. If you would like to launch the command-line wallet, you must first specify a port for communication with the witness node. To do this, add text to `witness_node_data_dir/config.ini` as follows, then restart the node: +This will launch the witness node. If you would like to launch the command-line wallet, you must first specify a port +for communication with the witness node. To do this, add text to `witness_node_data_dir/config.ini` as follows, then +restart the node: rpc-endpoint = 127.0.0.1:8090 @@ -37,7 +39,8 @@ To import your initial balance: If you send private keys over this connection, `rpc-endpoint` should be bound to localhost for security. -A list of CLI wallet commands is available [here](https://bitshares.github.io/doxygen/classgraphene_1_1wallet_1_1wallet__api.html). +A list of CLI wallet commands is available +[here](https://github.com/cryptonomex/graphene/blob/master/libraries/wallet/include/graphene/wallet/wallet.hpp). Code coverage testing --------------------- @@ -79,7 +82,9 @@ Witness node The role of the witness node is to broadcast transactions, download blocks, and optionally sign them. -./witness_node --rpc-endpoint "127.0.0.1:8090" --enable-stale-production -w \""1.6.0"\" \""1.6.1"\" \""1.6.2"\" \""1.6.3"\" \""1.6.4"\" +``` +./witness_node --rpc-endpoint "127.0.0.1:8090" --enable-stale-production -w \""1.6.0"\" \""1.6.1"\" \""1.6.2"\" \""1.6.3"\" \""1.6.4"\" +``` Running specific tests ---------------------- @@ -107,7 +112,7 @@ Here is an example using `wscat` package from `npm` for websockets: We can do the same thing using an HTTP client such as `curl` for API's which do not require login or other session state: $ curl --data '{"jsonrpc": "2.0", "method": "call", "params": [0, "get_accounts", [["1.2.0"]]], "id": 1}' http://127.0.0.1:8090/rpc - {"id":1,"result":[{"id":"1.2.0","annotations":[],"registrar":"1.2.0","referrer":"1.2.0","referrer_percent":0,"name":"genesis","owner":{"weight_threshold":1,"key_auths":[["PUBLIC_KEY",1]]},"active":{"weight_threshold":1,"key_auths":[["PUBLIC_KEY",1]]},"memo_key":"PUBLIC_KEY","voting_account":"1.2.0","num_witness":0,"num_committee":0,"votes":[],"statistics":"2.7.0","whitelisting_accounts":[],"blacklisting_accounts":[]}]} + {"id":1,"result":[{"id":"1.2.0","annotations":[],"registrar":"1.2.0","referrer":"1.2.0","referrer_percent":0,"name":"genesis","owner":{"weight_threshold":1,"key_auths":[["PUBLIC_KEY",1]]},"active":{"weight_threshold":1,"key_auths":[["PUBLIC_KEY",1]]},"memo_key":"PUBLIC_KEY","voting_account":"1.2.0","num_witness":0,"num_committee":0,"votes":[],"statistics":"2.7.0","whitelisting_accounts":[],"blacklisting_accounts":[]}]} API 0 is accessible using regular JSON-RPC: From f175b4561cecb41a63fa2c35a35d05c59cd26c88 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Mon, 6 Jul 2015 14:35:59 -0400 Subject: [PATCH 6/7] Properly re-initialize witness scheduler state after a long block gap --- libraries/chain/db_witness_schedule.cpp | 22 ++++++++---- .../graphene/chain/witness_scheduler.hpp | 34 +++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/libraries/chain/db_witness_schedule.cpp b/libraries/chain/db_witness_schedule.cpp index 5095ac1b..a6d82bf6 100644 --- a/libraries/chain/db_witness_schedule.cpp +++ b/libraries/chain/db_witness_schedule.cpp @@ -106,6 +106,8 @@ void database::update_witness_schedule(signed_block next_block) // triggering FC_ASSERT elsewhere assert( schedule_slot > 0 ); + witness_id_type first_witness; + bool slot_is_near = wso.scheduler.get_slot( schedule_slot-1, first_witness ); witness_id_type wit; @@ -119,13 +121,21 @@ void database::update_witness_schedule(signed_block next_block) witness_scheduler_rng rng(wso.rng_seed.data, _wso.slots_since_genesis); _wso.scheduler._min_token_count = std::max(int(gpo.active_witnesses.size()) / 2, 1); - uint32_t drain = schedule_slot; - while( drain > 0 ) + + if( slot_is_near ) { - if( _wso.scheduler.size() == 0 ) - break; - _wso.scheduler.consume_schedule(); - --drain; + uint32_t drain = schedule_slot; + while( drain > 0 ) + { + if( _wso.scheduler.size() == 0 ) + break; + _wso.scheduler.consume_schedule(); + --drain; + } + } + else + { + _wso.scheduler.reset_schedule( first_witness ); } while( !_wso.scheduler.get_slot(schedule_needs_filled, wit) ) { diff --git a/libraries/chain/include/graphene/chain/witness_scheduler.hpp b/libraries/chain/include/graphene/chain/witness_scheduler.hpp index 77f67478..ec595922 100644 --- a/libraries/chain/include/graphene/chain/witness_scheduler.hpp +++ b/libraries/chain/include/graphene/chain/witness_scheduler.hpp @@ -313,6 +313,40 @@ class generic_witness_scheduler return true; } + /** + * Reset the schedule, then re-schedule the given witness as the + * first witness. + */ + void reset_schedule( WitnessID first_witness ) + { + _schedule.clear(); + for( const WitnessID& wid : _ineligible_no_turn ) + { + _eligible.push_back( wid ); + } + _turns += _ineligible_no_turn.size(); + _ineligible_no_turn.clear(); + for( const auto& item : _ineligible_waiting_for_token ) + { + _eligible.push_back( item.first ); + _turns += (item.second ? 0 : 1); + } + _tokens += _ineligible_waiting_for_token.size(); + _ineligible_waiting_for_token.clear(); + if( debug ) check_invariant(); + + auto it = std::find( _eligible.begin(), _eligible.end(), first_witness ); + assert( it != _eligible.end() ); + + _schedule.push_back( *it ); + _ineligible_waiting_for_token.emplace_back( *it, false ); + _eligible.erase( it ); + _turns--; + _tokens--; + if( debug ) check_invariant(); + return; + } + // keep track of total turns / tokens in existence CountType _turns = 0; CountType _tokens = 0; From fcf21683f354f70ecbf3898f01b260658d82a486 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Mon, 6 Jul 2015 15:47:12 -0400 Subject: [PATCH 7/7] operation_tests2.cpp: Remove extra generate_block() in witness_create test --- tests/tests/operation_tests2.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index b72688ed..c5edce81 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -467,7 +467,6 @@ BOOST_AUTO_TEST_CASE( witness_create ) generator_helper h = std::for_each(near_witnesses.begin(), near_witnesses.end(), generator_helper{*this, nathan_witness_id, nathan_private_key, false}); BOOST_CHECK(h.nathan_generated_block); - generate_block(0, nathan_private_key); } FC_LOG_AND_RETHROW() } /**