Skip to content

Commit

Permalink
Merge pull request mvs-org#153 from mvs-org/bugfix/deposit_same_amoun…
Browse files Browse the repository at this point in the history
…t_address_tx_not_pack_into_block

mvs-org#151 deposit reward tx with same output value and target address can …
  • Loading branch information
wdyoschina authored Oct 16, 2017
2 parents f72959f + c05aa48 commit 64f4176
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/metaverse/consensus/miner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class miner
static block_ptr create_genesis_block(bool is_mainnet);
bool script_hash_signature_operations_count(size_t &count, chain::input::list& inputs, vector<transaction_ptr>& transactions);
bool script_hash_signature_operations_count(size_t &count, chain::input& input, vector<transaction_ptr>& transactions);
transaction_ptr create_coinbase_tx(const wallet::payment_address& pay_addres, uint64_t value, uint64_t block_height, int lock_height);
transaction_ptr create_coinbase_tx(const wallet::payment_address& pay_addres, uint64_t value, uint64_t block_height, int lock_height, uint32_t reward_lock_time);

block_ptr get_block(bool is_force_create_block = false);
bool get_work(std::string& seed_hash, std::string& header_hash, std::string& boundary);
Expand Down
11 changes: 7 additions & 4 deletions src/lib/consensus/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,19 @@ miner::block_ptr miner::create_genesis_block(bool is_mainnet)
return pblock;
}

miner::transaction_ptr miner::create_coinbase_tx(const wallet::payment_address& pay_address, uint64_t value, uint64_t block_height, int lock_height)
miner::transaction_ptr miner::create_coinbase_tx(const wallet::payment_address& pay_address, uint64_t value, uint64_t block_height, int lock_height, uint32_t reward_lock_time)
{
transaction_ptr ptransaction = make_shared<message::transaction_message>();

ptransaction->inputs.resize(1);
ptransaction->version = version;
ptransaction->inputs[0].previous_output = {null_hash, max_uint32};
ptransaction->inputs[0].previous_output = {null_hash, max_uint32};
script_number number(block_height);
ptransaction->inputs[0].script.operations.push_back({ chain::opcode::special, number.data() });

ptransaction->outputs.resize(1);
ptransaction->outputs[0].value = value;
ptransaction->locktime = reward_lock_time;
if(lock_height > 0) {
ptransaction->outputs[0].script.operations = chain::operation::to_pay_key_hash_with_lock_height_pattern(short_hash(pay_address), lock_height);
} else {
Expand Down Expand Up @@ -275,7 +276,7 @@ miner::block_ptr miner::create_new_block(const wallet::payment_address& pay_addr
}

// Create coinbase tx
pblock->transactions.push_back(*create_coinbase_tx(pay_address, 0, current_block_height + 1, 0));
pblock->transactions.push_back(*create_coinbase_tx(pay_address, 0, current_block_height + 1, 0, 0));

// Largest block you're willing to create:
unsigned int block_max_size = blockchain::max_block_size / 2;
Expand Down Expand Up @@ -359,6 +360,7 @@ miner::block_ptr miner::create_new_block(const wallet::payment_address& pay_addr
make_heap(transaction_prioritys.begin(), transaction_prioritys.end(), sort_func);

transaction_priority *next_transaction_priority = NULL;
uint32_t reward_lock_time = current_block_height-1;
while (!transaction_prioritys.empty() || next_transaction_priority)
{
transaction_priority temp_priority;
Expand Down Expand Up @@ -394,13 +396,14 @@ miner::block_ptr miner::create_new_block(const wallet::payment_address& pay_addr
for(auto& output : ptx->outputs){
if(chain::operation::is_pay_key_hash_with_lock_height_pattern(output.script.operations)) {
int lock_height = chain::operation::get_lock_height_from_pay_key_hash_with_lock_height(output.script.operations);
coinage_reward_coinbase = create_coinbase_tx(wallet::payment_address::extract(ptx->outputs[0].script), calculate_lockblock_reward(lock_height, output.value), current_block_height + 1, lock_height);
coinage_reward_coinbase = create_coinbase_tx(wallet::payment_address::extract(ptx->outputs[0].script), calculate_lockblock_reward(lock_height, output.value), current_block_height + 1, lock_height, reward_lock_time);
unsigned int tx_sig_length = blockchain::validate_block::validate_block::legacy_sigops_count(*coinage_reward_coinbase);
if (total_tx_sig_length + tx_sig_length >= blockchain::max_block_script_sigops)
continue;
total_tx_sig_length += tx_sig_length;
serialized_size += coinage_reward_coinbase->serialized_size(1);
coinage_reward_coinbases.push_back(coinage_reward_coinbase);
--reward_lock_time;
}
}

Expand Down

0 comments on commit 64f4176

Please sign in to comment.