From f03c207c02fed6461954de5e3605d8d9f0a62dc6 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 24 Mar 2019 15:12:17 -0400 Subject: [PATCH] Apply deterministic virtual_op numbering rule https://github.com/bitshares/bitshares-core/issues/1675 --- libraries/chain/db_block.cpp | 10 ++++++++++ libraries/chain/include/graphene/chain/config.hpp | 2 +- libraries/chain/include/graphene/chain/database.hpp | 2 +- .../graphene/chain/operation_history_object.hpp | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index e340d2dea1..7a711ea474 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -552,6 +552,12 @@ void database::_apply_block( const signed_block& next_block ) const auto& dynamic_global_props = get_dynamic_global_properties(); bool maint_needed = (dynamic_global_props.next_maintenance_time <= next_block.timestamp); + // trx_in_block starts from 0. + // For real operations which are explicitly included in a transaction, op_in_trx starts from 0, virtual_op is 0. + // For virtual operations that are derived directly from a real operation, + // use the real operation's (block_num,trx_in_block,op_in_trx), virtual_op starts from 1. + // For virtual operations created after processed all transactions, + // trx_in_block = the_block.trsanctions.size(), op_in_trx is 0, virtual_op starts from 0. _current_block_num = next_block_num; _current_trx_in_block = 0; @@ -569,6 +575,9 @@ void database::_apply_block( const signed_block& next_block ) ++_current_trx_in_block; } + _current_op_in_trx = 0; + _current_virtual_op = 0; + const uint32_t missed = update_witness_missed_blocks( next_block ); update_global_dynamic_data( next_block, missed ); update_signing_witness(signing_witness, next_block); @@ -671,6 +680,7 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx _current_op_in_trx = 0; for( const auto& op : ptrx.operations ) { + _current_virtual_op = 0; eval_state.operation_results.emplace_back(apply_operation(eval_state, op)); ++_current_op_in_trx; } diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index fdcd3312f8..c9d3c00db9 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -121,7 +121,7 @@ #define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4 #define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3 -#define GRAPHENE_CURRENT_DB_VERSION "20190219" +#define GRAPHENE_CURRENT_DB_VERSION "20190324" #define GRAPHENE_IRREVERSIBLE_THRESHOLD (70 * GRAPHENE_1_PERCENT) diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 7fa190cb66..ef07e0467b 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -534,7 +534,7 @@ namespace graphene { namespace chain { uint32_t _current_block_num = 0; uint16_t _current_trx_in_block = 0; uint16_t _current_op_in_trx = 0; - uint16_t _current_virtual_op = 0; + uint32_t _current_virtual_op = 0; vector _vote_tally_buffer; vector _witness_count_histogram_buffer; diff --git a/libraries/chain/include/graphene/chain/operation_history_object.hpp b/libraries/chain/include/graphene/chain/operation_history_object.hpp index 3aeaab1923..d4d05ca348 100644 --- a/libraries/chain/include/graphene/chain/operation_history_object.hpp +++ b/libraries/chain/include/graphene/chain/operation_history_object.hpp @@ -61,7 +61,7 @@ namespace graphene { namespace chain { /** the operation within the transaction */ uint16_t op_in_trx = 0; /** any virtual operations implied by operation in block */ - uint16_t virtual_op = 0; + uint32_t virtual_op = 0; }; /**