Skip to content

Commit c069c04

Browse files
committed
blockchain sync: reduce disk writes from 2 to 1 per tx
1 parent 1bd57c8 commit c069c04

25 files changed

+1169
-1155
lines changed

src/blockchain_utilities/blockchain_import.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ int check_flush(cryptonote::core &core, std::vector<block_complete_entry> &block
173173
for(auto& tx_blob: block_entry.txs)
174174
{
175175
tx_verification_context tvc = AUTO_VAL_INIT(tvc);
176-
core.handle_incoming_tx(tx_blob, tvc, relay_method::block, true);
176+
CHECK_AND_ASSERT_THROW_MES(tx_blob.prunable_hash == crypto::null_hash,
177+
"block entry must not contain pruned txs");
178+
core.handle_incoming_tx(tx_blob.blob, tvc, relay_method::block, true);
177179
if(tvc.m_verifivation_failed)
178180
{
179181
cryptonote::transaction transaction;
@@ -189,8 +191,9 @@ int check_flush(cryptonote::core &core, std::vector<block_complete_entry> &block
189191
// process block
190192

191193
block_verification_context bvc = {};
194+
pool_supplement ps{};
192195

193-
core.handle_incoming_block(block_entry.block, pblocks.empty() ? NULL : &pblocks[blockidx++], bvc, false); // <--- process block
196+
core.handle_incoming_block(block_entry.block, pblocks.empty() ? NULL : &pblocks[blockidx++], bvc, ps, false); // <--- process block
194197

195198
if(bvc.m_verifivation_failed)
196199
{

src/cryptonote_basic/cryptonote_format_utils.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ namespace cryptonote
234234
CHECK_AND_ASSERT_MES(r, false, "Failed to parse transaction from blob");
235235
CHECK_AND_ASSERT_MES(expand_transaction_1(tx, false), false, "Failed to expand transaction data");
236236
tx.invalidate_hashes();
237+
tx.set_blob_size(tx_blob.size());
237238
//TODO: validate tx
238239

239240
return get_transaction_hash(tx, tx_hash);
@@ -497,6 +498,19 @@ namespace cryptonote
497498
return get_transaction_weight(tx, blob_size);
498499
}
499500
//---------------------------------------------------------------
501+
uint64_t get_transaction_blob_size(const transaction& tx)
502+
{
503+
if (!tx.is_blob_size_valid())
504+
{
505+
const cryptonote::blobdata tx_blob = tx_to_blob(tx);
506+
tx.set_blob_size(tx_blob.size());
507+
}
508+
509+
CHECK_AND_ASSERT_THROW_MES(tx.is_blob_size_valid(), "BUG: blob size valid not set");
510+
511+
return tx.blob_size;
512+
}
513+
//---------------------------------------------------------------
500514
bool get_tx_fee(const transaction& tx, uint64_t & fee)
501515
{
502516
if (tx.version > 1)

src/cryptonote_basic/cryptonote_format_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ namespace cryptonote
137137
uint64_t get_transaction_weight(const transaction &tx);
138138
uint64_t get_transaction_weight(const transaction &tx, size_t blob_size);
139139
uint64_t get_pruned_transaction_weight(const transaction &tx);
140+
uint64_t get_transaction_blob_size(const transaction& tx);
140141

141142
bool check_money_overflow(const transaction& tx);
142143
bool check_outs_overflow(const transaction& tx);

src/cryptonote_basic/verification_context.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace cryptonote
6969
bool m_marked_as_orphaned;
7070
bool m_already_exists;
7171
bool m_partial_block_reward;
72-
bool m_bad_pow; // if bad pow, bad peer outright for DoS protection
72+
bool m_bad_pow; // if bad pow, ban peer outright for DoS protection
73+
bool m_missing_txs; // set if, during verif, we don't have all the necessary txs available
7374
};
7475
}

0 commit comments

Comments
 (0)