Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

Commit

Permalink
Do not return next block production time in the past (resolves #362)
Browse files Browse the repository at this point in the history
  • Loading branch information
vikramrajkumar committed Jun 23, 2014
1 parent fecd6ee commit 92886ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 8 additions & 2 deletions libraries/wallet/wallet.cpp
Expand Up @@ -1258,7 +1258,8 @@ namespace bts { namespace wallet {
{ try {
auto sorted_delegates = my->_blockchain->get_active_delegates();

uint32_t interval_number = bts::blockchain::now().sec_since_epoch() / BTS_BLOCKCHAIN_BLOCK_INTERVAL_SEC;
auto current_time = bts::blockchain::now();
uint32_t interval_number = current_time.sec_since_epoch() / BTS_BLOCKCHAIN_BLOCK_INTERVAL_SEC;
auto next_block_time = fc::time_point_sec( interval_number * BTS_BLOCKCHAIN_BLOCK_INTERVAL_SEC );
if( next_block_time == my->_blockchain->now() ) next_block_time += BTS_BLOCKCHAIN_BLOCK_INTERVAL_SEC;
auto last_block_time = next_block_time + (BTS_BLOCKCHAIN_NUM_DELEGATES * BTS_BLOCKCHAIN_BLOCK_INTERVAL_SEC);
Expand All @@ -1276,7 +1277,12 @@ namespace bts { namespace wallet {
{
auto key = my->_wallet_db.lookup_key( delegate_record->active_key() );
if( key.valid() && key->has_private_key() )
return next_block_time;
{
if( next_block_time >= current_time )
return next_block_time;
else
last_block_time += BTS_BLOCKCHAIN_NUM_DELEGATES * BTS_BLOCKCHAIN_BLOCK_INTERVAL_SEC;
}
}
}
return fc::time_point_sec();
Expand Down
7 changes: 4 additions & 3 deletions libraries/wallet/wallet_db.cpp
Expand Up @@ -385,15 +385,16 @@ namespace bts{ namespace wallet {
void wallet_db::clear_pending_transactions()
{
vector<transaction_id_type> clear_list;
for (auto id_trx_pair : transactions)
for( const auto& id_trx_pair : transactions )
{
if (id_trx_pair.second.block_num == 0)
if( id_trx_pair.second.block_num == 0 )
{
clear_list.push_back( id_trx_pair.first );
my->_records.remove( id_trx_pair.second.wallet_record_index );
}
}
for( auto id : clear_list ) transactions.erase(id);
for( const auto& id : clear_list )
transactions.erase( id );
}

void wallet_db::export_to_json( const path& filename )const
Expand Down

0 comments on commit 92886ed

Please sign in to comment.