From 132c666f67937676bea1cc145c242b857f9852a2 Mon Sep 17 00:00:00 2001 From: warptangent Date: Sun, 31 Jan 2016 05:10:14 -0800 Subject: Update schema for "tx_outputs" to use array containing amount output indices This speeds up wallet refresh by directly retrieving a tx's amount output indices. It removes the indirection and walking the amount output duplicate list for every amount in each requested tx. "tx_outputs" is used by: Amount output indices are needed for wallet refresh. Global output indices are needed for removing a tx. Both amount output indices and global output indices are now stored in an array of 64-bit unsigned ints: tx_outputs[] -> [ ] Previously it was: tx_outputs[] -> duplicate list of The amount output list had to be walked for every amount in order to find each amount's output index, by comparing the amount's global output index with each one in the duplicate list until a match was found. See also d045dfa7ce0bf131681193c97560da26f9f37900 --- src/blockchain_db/blockchain_db.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/blockchain_db/blockchain_db.cpp') diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp index a66f4a403..b1b233b58 100644 --- a/src/blockchain_db/blockchain_db.cpp +++ b/src/blockchain_db/blockchain_db.cpp @@ -84,12 +84,19 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti add_transaction_data(blk_hash, tx, tx_hash); + std::vector amount_output_indices; + std::vector global_output_indices; + // iterate tx.vout using indices instead of C++11 foreach syntax because // we need the index for (uint64_t i = 0; i < tx.vout.size(); ++i) { - add_output(tx_hash, tx.vout[i], i, tx.unlock_time); + uint64_t amount_output_index, global_output_index; + add_output(tx_hash, tx.vout[i], i, tx.unlock_time, amount_output_index, global_output_index); + amount_output_indices.push_back(amount_output_index); + global_output_indices.push_back(global_output_index); } + add_amount_and_global_output_indices(tx_hash, amount_output_indices, global_output_indices); } uint64_t BlockchainDB::add_block( const block& blk -- cgit v1.2.3 From a2f518aa014163e63e39ce5e83a4f0d4d5be5c3f Mon Sep 17 00:00:00 2001 From: warptangent Date: Fri, 4 Mar 2016 11:37:41 -0800 Subject: Schema update: tx_indices - yet less indirection --- src/blockchain_db/blockchain_db.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/blockchain_db/blockchain_db.cpp') diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp index b1b233b58..8cde4f138 100644 --- a/src/blockchain_db/blockchain_db.cpp +++ b/src/blockchain_db/blockchain_db.cpp @@ -82,7 +82,7 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti } } - add_transaction_data(blk_hash, tx, tx_hash); + uint64_t tx_index = add_transaction_data(blk_hash, tx, tx_hash); std::vector amount_output_indices; std::vector global_output_indices; @@ -96,7 +96,7 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti amount_output_indices.push_back(amount_output_index); global_output_indices.push_back(global_output_index); } - add_amount_and_global_output_indices(tx_hash, amount_output_indices, global_output_indices); + add_amount_and_global_output_indices(tx_index, amount_output_indices, global_output_indices); } uint64_t BlockchainDB::add_block( const block& blk -- cgit v1.2.3 From 591e421875988ea63313a7da22062f62f06b30ab Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Mon, 4 Apr 2016 02:10:58 +0100 Subject: Cleanup and clarify Try to rationalize the variable names, document usage. --- src/blockchain_db/blockchain_db.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/blockchain_db/blockchain_db.cpp') diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp index 8cde4f138..68f635d18 100644 --- a/src/blockchain_db/blockchain_db.cpp +++ b/src/blockchain_db/blockchain_db.cpp @@ -82,21 +82,17 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti } } - uint64_t tx_index = add_transaction_data(blk_hash, tx, tx_hash); + uint64_t tx_id = add_transaction_data(blk_hash, tx, tx_hash); std::vector amount_output_indices; - std::vector global_output_indices; // iterate tx.vout using indices instead of C++11 foreach syntax because // we need the index for (uint64_t i = 0; i < tx.vout.size(); ++i) { - uint64_t amount_output_index, global_output_index; - add_output(tx_hash, tx.vout[i], i, tx.unlock_time, amount_output_index, global_output_index); - amount_output_indices.push_back(amount_output_index); - global_output_indices.push_back(global_output_index); + amount_output_indices.push_back(add_output(tx_hash, tx.vout[i], i, tx.unlock_time)); } - add_amount_and_global_output_indices(tx_index, amount_output_indices, global_output_indices); + add_tx_amount_output_indices(tx_id, amount_output_indices); } uint64_t BlockchainDB::add_block( const block& blk -- cgit v1.2.3