Skip to content

Commit fe370e9

Browse files
committed
blockchain sync: reduce disk writes from 2 to 1 per tx
1 parent 059028a commit fe370e9

22 files changed

+720
-1460
lines changed

src/blockchain_utilities/blockchain_import.cpp

Lines changed: 3 additions & 1 deletion
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;

src/cryptonote_basic/cryptonote_format_utils.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ namespace cryptonote
257257
CHECK_AND_ASSERT_MES(r, false, "Failed to parse transaction from blob");
258258
CHECK_AND_ASSERT_MES(expand_transaction_1(tx, false), false, "Failed to expand transaction data");
259259
tx.invalidate_hashes();
260+
tx.set_blob_size(tx_blob.size());
260261
//TODO: validate tx
261262

262263
return get_transaction_hash(tx, tx_hash);
@@ -520,6 +521,19 @@ namespace cryptonote
520521
return get_transaction_weight(tx, blob_size);
521522
}
522523
//---------------------------------------------------------------
524+
uint64_t get_transaction_blob_size(const transaction& tx)
525+
{
526+
if (!tx.is_blob_size_valid())
527+
{
528+
const cryptonote::blobdata tx_blob = tx_to_blob(tx);
529+
tx.set_blob_size(tx_blob.size());
530+
}
531+
532+
CHECK_AND_ASSERT_THROW_MES(tx.is_blob_size_valid(), "BUG: blob size valid not set");
533+
534+
return tx.blob_size;
535+
}
536+
//---------------------------------------------------------------
523537
bool get_tx_fee(const transaction& tx, uint64_t & fee)
524538
{
525539
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
@@ -68,6 +68,7 @@ namespace cryptonote
6868
bool m_marked_as_orphaned;
6969
bool m_already_exists;
7070
bool m_partial_block_reward;
71-
bool m_bad_pow; // if bad pow, bad peer outright for DoS protection
71+
bool m_bad_pow; // if bad pow, ban peer outright for DoS protection
72+
bool m_missing_txs; // set if, during verif, we don't have all the necessary txs available
7273
};
7374
}

0 commit comments

Comments
 (0)