diff --git a/src/pool_block.cpp b/src/pool_block.cpp index ecedfdf..15710d4 100644 --- a/src/pool_block.cpp +++ b/src/pool_block.cpp @@ -63,7 +63,6 @@ PoolBlock::PoolBlock() m_transactions.reserve(256); m_sideChainData.reserve(512); m_uncles.reserve(8); - m_tmpTxExtra.reserve(80); } PoolBlock::PoolBlock(const PoolBlock& b) @@ -109,7 +108,6 @@ PoolBlock& PoolBlock::operator=(const PoolBlock& b) m_difficulty = b.m_difficulty; m_cumulativeDifficulty = b.m_cumulativeDifficulty; m_sidechainId = b.m_sidechainId; - m_tmpTxExtra = b.m_tmpTxExtra; m_depth = b.m_depth; m_verified = b.m_verified; m_invalid = b.m_invalid; @@ -169,28 +167,37 @@ void PoolBlock::serialize_mainchain_data(uint32_t nonce, uint32_t extra_nonce, c m_mainChainOutputsBlobSize = static_cast(m_mainChainData.size()) - m_mainChainOutputsOffset; - m_tmpTxExtra.clear(); + uint8_t tx_extra[128]; + uint8_t* p = tx_extra; - m_tmpTxExtra.push_back(TX_EXTRA_TAG_PUBKEY); - m_tmpTxExtra.insert(m_tmpTxExtra.end(), m_txkeyPub.h, m_txkeyPub.h + HASH_SIZE); + *(p++) = TX_EXTRA_TAG_PUBKEY; + memcpy(p, m_txkeyPub.h, HASH_SIZE); + p += HASH_SIZE; - m_tmpTxExtra.push_back(TX_EXTRA_NONCE); - writeVarint(m_extraNonceSize, m_tmpTxExtra); - - m_extraNonce = extra_nonce; - m_tmpTxExtra.insert(m_tmpTxExtra.end(), reinterpret_cast(&m_extraNonce), reinterpret_cast(&m_extraNonce) + EXTRA_NONCE_SIZE); - if (m_extraNonceSize > EXTRA_NONCE_SIZE) { - m_tmpTxExtra.insert(m_tmpTxExtra.end(), m_extraNonceSize - EXTRA_NONCE_SIZE, 0); + uint64_t extra_nonce_size = m_extraNonceSize; + if (extra_nonce_size > EXTRA_NONCE_MAX_SIZE) { + LOGERR(1, "extra nonce size is too large (" << extra_nonce_size << "), fix the code!"); + extra_nonce_size = EXTRA_NONCE_MAX_SIZE; } - m_tmpTxExtra.push_back(TX_EXTRA_MERGE_MINING_TAG); - writeVarint(HASH_SIZE, m_tmpTxExtra); - m_tmpTxExtra.insert(m_tmpTxExtra.end(), sidechain_hash.h, sidechain_hash.h + HASH_SIZE); + *(p++) = TX_EXTRA_NONCE; + *(p++) = static_cast(extra_nonce_size); - writeVarint(m_tmpTxExtra.size(), m_mainChainData); - m_mainChainData.insert(m_mainChainData.end(), m_tmpTxExtra.begin(), m_tmpTxExtra.end()); + m_extraNonce = extra_nonce; + memcpy(p, &m_extraNonce, EXTRA_NONCE_SIZE); + p += EXTRA_NONCE_SIZE; + if (extra_nonce_size > EXTRA_NONCE_SIZE) { + memset(p, 0, extra_nonce_size - EXTRA_NONCE_SIZE); + p += extra_nonce_size - EXTRA_NONCE_SIZE; + } - m_tmpTxExtra.clear(); + *(p++) = TX_EXTRA_MERGE_MINING_TAG; + *(p++) = HASH_SIZE; + memcpy(p, sidechain_hash.h, HASH_SIZE); + p += HASH_SIZE; + + writeVarint(static_cast(p - tx_extra), m_mainChainData); + m_mainChainData.insert(m_mainChainData.end(), tx_extra, p); m_mainChainData.push_back(0); @@ -234,8 +241,6 @@ void PoolBlock::serialize_sidechain_data() void PoolBlock::reset_offchain_data() { // Defaults for off-chain variables - m_tmpTxExtra.clear(); - m_depth = 0; m_verified = false; diff --git a/src/pool_block.h b/src/pool_block.h index d865b67..8231d18 100644 --- a/src/pool_block.h +++ b/src/pool_block.h @@ -122,8 +122,6 @@ struct PoolBlock hash m_sidechainId; // Just temporary stuff, not a part of the block - std::vector m_tmpTxExtra; - uint64_t m_depth; bool m_verified; diff --git a/tests/src/pool_block_tests.cpp b/tests/src/pool_block_tests.cpp index 78b9d8e..4d644c0 100644 --- a/tests/src/pool_block_tests.cpp +++ b/tests/src/pool_block_tests.cpp @@ -72,7 +72,6 @@ TEST(pool_block, deserialize) ASSERT_EQ(b.m_difficulty.hi, 0); ASSERT_EQ(b.m_cumulativeDifficulty.lo, 12544665764606ull); ASSERT_EQ(b.m_cumulativeDifficulty.hi, 0); - ASSERT_EQ(b.m_tmpTxExtra.size(), 0); ASSERT_EQ(b.m_depth, 0); ASSERT_EQ(b.m_verified, false); ASSERT_EQ(b.m_invalid, false);