forked from lthn/blockchain
fixed chain_switching_when_out_spent_in_alt_chain_ref_id
This commit is contained in:
parent
41ca8cff41
commit
e3ef3dc704
5 changed files with 48 additions and 4 deletions
|
|
@ -1720,6 +1720,34 @@ bool blockchain_storage::handle_alternative_block(const block& b, const crypto::
|
|||
alt_block_extended_info abei = AUTO_VAL_INIT(abei);
|
||||
abei.bl = b;
|
||||
abei.onboard_transactions.swap(bvc.m_onboard_transactions);
|
||||
//for altblocks we should be sure that all transactions kept in onboard_transactions
|
||||
for (auto& h: abei.bl.tx_hashes)
|
||||
{
|
||||
if (abei.onboard_transactions.count(h) == 0)
|
||||
{
|
||||
//need to take if from pool
|
||||
transaction tx = AUTO_VAL_INIT(tx);
|
||||
bool r = m_tx_pool.get_transaction(h, tx);
|
||||
if (!r)
|
||||
{
|
||||
//transaction could be in main chain
|
||||
auto tx_ptr = m_db_transactions.find(h);
|
||||
if (!tx_ptr)
|
||||
{
|
||||
LOG_ERROR("Transaction " << h << " for altblock " << get_block_hash(abei.bl) << " not found");
|
||||
}
|
||||
else
|
||||
{
|
||||
abei.onboard_transactions[h] = tx_ptr->tx;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
abei.onboard_transactions[h] = tx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abei.timestamp = m_core_runtime_config.get_core_time();
|
||||
abei.height = alt_chain.size() ? it_prev->second.height + 1 : *ptr_main_prev + 1;
|
||||
CHECK_AND_ASSERT_MES_CUSTOM(coinbase_height == abei.height, false, bvc.m_verification_failed = true, "block coinbase height doesn't match with altchain height, declined");
|
||||
|
|
|
|||
|
|
@ -685,11 +685,19 @@ bool chain_switching_when_out_spent_in_alt_chain_mixin::generate(std::vector<tes
|
|||
|
||||
bool chain_switching_when_out_spent_in_alt_chain_ref_id::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
random_state_test_restorer::reset_random(0); // to make the test deterministic
|
||||
uint64_t ts = 1450000000;
|
||||
test_core_time::adjust(ts);
|
||||
|
||||
// Test idea: make sure tx can spend (using ref_by_id) an output from another tx when both txs are in an altchain.
|
||||
bool r = false;
|
||||
GENERATE_ACCOUNT(miner_acc);
|
||||
GENERATE_ACCOUNT(miner_acc);
|
||||
GENERATE_ACCOUNT(alice_acc);
|
||||
GENERATE_ACCOUNT(bob_acc);
|
||||
miner_acc.set_createtime(ts);
|
||||
alice_acc.set_createtime(ts);
|
||||
bob_acc.set_createtime(ts);
|
||||
|
||||
MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time());
|
||||
MAKE_NEXT_BLOCK(events, blk_1, blk_0, miner_acc);
|
||||
REWIND_BLOCKS_N(events, blk_1r, blk_1, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
|
||||
|
|
|
|||
|
|
@ -159,7 +159,15 @@ void test_generator::add_block(const currency::block& blk,
|
|||
get_block_reward(is_pos_block(blk), misc_utils::median(block_sizes), block_size, already_generated_coins, block_reward, currency::get_block_height(blk));
|
||||
|
||||
m_blocks_info[get_block_hash(blk)] = block_info(blk, already_generated_coins + block_reward, block_size, cum_diff, tx_list, ks_hash);
|
||||
LOG_PRINT_MAGENTA("ADDED_BLOCK[" << get_block_hash(blk) << "][" << (is_pos_block(blk)? "PoS":"PoW") <<"][" << get_block_height(blk) << "][cumul_diff:" << cum_diff << "]", LOG_LEVEL_0);
|
||||
|
||||
|
||||
std::stringstream ss_tx_hashes;
|
||||
for (auto& h : blk.tx_hashes)
|
||||
{
|
||||
ss_tx_hashes << " [tx]: " << h << ENDL;
|
||||
}
|
||||
|
||||
LOG_PRINT_MAGENTA("ADDED_BLOCK[" << get_block_hash(blk) << "][" << (is_pos_block(blk)? "PoS":"PoW") <<"][" << get_block_height(blk) << "][cumul_diff:" << cum_diff << "]" << ENDL << ss_tx_hashes.str(), LOG_LEVEL_0);
|
||||
}
|
||||
|
||||
void test_generator::add_block_info(const block_info& bi)
|
||||
|
|
|
|||
|
|
@ -900,7 +900,7 @@ int main(int argc, char* argv[])
|
|||
GENERATE_AND_PLAY(alt_blocks_validation_and_same_new_amount_in_two_txs);
|
||||
GENERATE_AND_PLAY(alt_blocks_with_the_same_txs);
|
||||
GENERATE_AND_PLAY(chain_switching_when_out_spent_in_alt_chain_mixin);
|
||||
// GENERATE_AND_PLAY(chain_switching_when_out_spent_in_alt_chain_ref_id);
|
||||
GENERATE_AND_PLAY(chain_switching_when_out_spent_in_alt_chain_ref_id);
|
||||
|
||||
|
||||
// miscellaneous tests
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ void transfer_multisig(tools::wallet2& w,
|
|||
|
||||
// prepare transaction will sign ms input partially with wallet's keys - it needed to be signed fully with the others
|
||||
tools::construct_tx_param ctp = AUTO_VAL_INIT(ctp);
|
||||
tools::finalize_tx_param ftp = AUTO_VAL_INIT(ftp);
|
||||
currency::finalize_tx_param ftp = AUTO_VAL_INIT(ftp);
|
||||
ctp.attachments = attachments;
|
||||
ctp.crypt_address = crypt_address;
|
||||
ctp.dsts = dsts;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue