Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Commit

Permalink
RC4 Hotfix 1 - TemporaryWsv deadlock, checkTxPresence performance (#2140
Browse files Browse the repository at this point in the history
)

* Fix deadlock on TemporaryWsv creation

Signed-off-by: Andrei Lebedev <[email protected]>

* Add hash index for transaction status

Signed-off-by: Andrei Lebedev <[email protected]>
  • Loading branch information
lebdron authored and neewy committed Mar 5, 2019
1 parent 4e9fac8 commit 28b3b39
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion irohad/ametsuchi/impl/storage_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ namespace iroha {
return expected::makeError("Connection was closed");
}
auto sql = std::make_unique<soci::session>(*connection_);
// if we create temporary storage, then we intend to validate a new
// proposal. this means that any state prepared before that moment is not
// needed and must be removed to prevent locking
if (block_is_prepared) {
rollbackPrepared(*sql);
}

return expected::makeValue<std::unique_ptr<TemporaryWsv>>(
std::make_unique<TemporaryWsvImpl>(
Expand All @@ -118,7 +124,7 @@ namespace iroha {
auto sql = std::make_unique<soci::session>(*connection_);
// if we create mutable storage, then we intend to mutate wsv
// this means that any state prepared before that moment is not needed
// and must be removed to preventy locking
// and must be removed to prevent locking
if (block_is_prepared) {
rollbackPrepared(*sql);
}
Expand Down Expand Up @@ -547,6 +553,7 @@ DROP TABLE IF EXISTS signatory;
DROP TABLE IF EXISTS peer;
DROP TABLE IF EXISTS role;
DROP TABLE IF EXISTS height_by_hash;
DROP INDEX IF EXISTS tx_status_by_hash_hash_index;
DROP TABLE IF EXISTS tx_status_by_hash;
DROP TABLE IF EXISTS height_by_account_set;
DROP TABLE IF EXISTS index_by_creator_height;
Expand Down Expand Up @@ -648,6 +655,7 @@ CREATE TABLE IF NOT EXISTS tx_status_by_hash (
hash varchar,
status boolean
);
CREATE INDEX IF NOT EXISTS tx_status_by_hash_hash_index ON tx_status_by_hash USING hash (hash);

CREATE TABLE IF NOT EXISTS height_by_account_set (
account_id text,
Expand Down
1 change: 1 addition & 0 deletions test/module/irohad/ametsuchi/ametsuchi_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ CREATE TABLE IF NOT EXISTS tx_status_by_hash (
hash varchar,
status boolean
);
CREATE INDEX IF NOT EXISTS tx_status_by_hash_hash_index ON tx_status_by_hash USING hash (hash);
CREATE TABLE IF NOT EXISTS height_by_account_set (
account_id text,
Expand Down
18 changes: 18 additions & 0 deletions test/module/irohad/ametsuchi/ametsuchi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,3 +667,21 @@ TEST_F(PreparedBlockTest, CommitPreparedFailsAfterCommit) {
shared_model::interface::Amount resultingBalance{"15.00"};
validateAccountAsset(sql_query, "admin@test", "coin#test", resultingBalance);
}

/**
* @given Storage with prepared state
* @when another temporary wsv is created and transaction is applied
* @then previous state is dropped and new transaction is applied successfully
*/
TEST_F(PreparedBlockTest, TemporaryWsvUnlocks) {
auto result = temp_wsv->apply(*initial_tx);
ASSERT_TRUE(framework::expected::val(result));
storage->prepareBlock(std::move(temp_wsv));

using framework::expected::val;
temp_wsv = std::move(val(storage->createTemporaryWsv())->value);

result = temp_wsv->apply(*initial_tx);
ASSERT_TRUE(framework::expected::val(result));
storage->prepareBlock(std::move(temp_wsv));
}

0 comments on commit 28b3b39

Please sign in to comment.