This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 295
Feature/rejected txs index #1846
Merged
kamilsa
merged 7 commits into
trunk/tx_persistent_cache
from
feature/rejected_txs_index
Nov 16, 2018
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
05fb5c1
Add rejected tx index
kamilsa 84c9aa8
Add test on rejected transaction hash
kamilsa 1466006
Rename hasTxWithHash -> hasCommittedTxWithHash
kamilsa 060fb90
Add missing methods to mock
kamilsa 39875f1
Refactor tx presence methods in block query
kamilsa 3a894c0
Fix build
kamilsa 8aeeaa0
Fix test
kamilsa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,11 +242,38 @@ namespace iroha { | |
}; | ||
} | ||
|
||
bool PostgresBlockQuery::hasTxWithHash( | ||
TxCacheStatusType PostgresBlockQuery::checkTxPresence( | ||
const shared_model::crypto::Hash &hash) { | ||
if (hasCommittedTxWithHash(hash)) { | ||
return tx_cache_status_responses::Committed(); | ||
} | ||
if (hasRejectedTxWithHash(hash)) { | ||
return tx_cache_status_responses::Rejected(); | ||
} | ||
return tx_cache_status_responses::Missing(); | ||
} | ||
|
||
bool PostgresBlockQuery::hasCommittedTxWithHash( | ||
const shared_model::crypto::Hash &hash) { | ||
return getBlockId(hash) != boost::none; | ||
} | ||
|
||
bool PostgresBlockQuery::hasRejectedTxWithHash( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why should we separate hashes storage on two methods? something like:
That approach will let us avoid looking up in two independent sources for the single transaction in the worst case. |
||
const shared_model::crypto::Hash &hash) { | ||
boost::optional<uint64_t> blockId = boost::none; | ||
boost::optional<std::string> block_str; | ||
const auto &hash_str = hash.hex(); | ||
|
||
sql_ << "SELECT height FROM height_by_rejected_hash WHERE hash = :hash", | ||
soci::into(block_str), soci::use(hash_str); | ||
if (block_str) { | ||
blockId = std::stoull(block_str.get()); | ||
} else { | ||
log_->info("No block with rejected transaction {}", hash.toString()); | ||
} | ||
return (bool)blockId; | ||
} | ||
|
||
uint32_t PostgresBlockQuery::getTopBlockHeight() { | ||
return block_store_.last_id(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -508,6 +508,12 @@ CREATE TABLE IF NOT EXISTS height_by_hash ( | |
hash varchar, | ||
height text | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS height_by_rejected_hash ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add drop table please (somewhere) |
||
hash varchar, | ||
height text | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS height_by_account_set ( | ||
account_id text, | ||
height text | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest a bit different naming -
storeRejectedTxHash
Otherwise
make index
sounds likeCREATE INDEX index_name ON table_name (column1, column2, ...);
will be executed under the hood :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you. My intention was to keep the naming consisted with other methods here. I can add the task to provide better naming for that function