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

Commit

Permalink
Introduce error codes to SFV (#1817)
Browse files Browse the repository at this point in the history
* Introduced error codes to SQL

Signed-off-by: Akvinikym <[email protected]>

* Builds

Signed-off-by: Akvinikym <[email protected]>

* 4/16 commands

Signed-off-by: Akvinikym <[email protected]>

* 13/16 done

Signed-off-by: Akvinikym <[email protected]>

* Tests are finished

Signed-off-by: Akvinikym <[email protected]>

* Review issues

Signed-off-by: Akvinikym <[email protected]>

* Introduced error codes to SFV

Signed-off-by: Akvinikym <[email protected]>

* Is now built

Signed-off-by: Akvinikym <[email protected]>

* Added a separated function for parsing SQL errors and making an error

Signed-off-by: Akvinikym <[email protected]>

* Review issues are addressed

Signed-off-by: Akvinikym <[email protected]>

* Added ToDos

Signed-off-by: Akvinikym <[email protected]>

* Some after-POW issues

Signed-off-by: Akvinikym <[email protected]>

* Error codes has good ordering

Signed-off-by: Akvinikym <[email protected]>

* More fixes

Signed-off-by: Akvinikym <[email protected]>

* Build fix

Signed-off-by: Akvinikym <[email protected]>

* And more

Signed-off-by: Akvinikym <[email protected]>

* Refactored switch-case

Signed-off-by: Akvinikym <[email protected]>
  • Loading branch information
Akvinikym authored Nov 8, 2018
1 parent 71cba32 commit b95771c
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 30 deletions.
27 changes: 15 additions & 12 deletions irohad/ametsuchi/impl/temporary_wsv_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,25 @@ namespace iroha {
soci::use(boost::size(keys_range), "signatures_count"),
soci::use(transaction.creatorAccountId(), "account_id");
} catch (const std::exception &e) {
log_->error(e.what());
return expected::makeError(validation::CommandError{
"signatures validation",
(boost::format("database error: %s") % e.what()).str(),
false});
log_->error(
"Transaction %s failed signatures validation with db error: %s",
transaction.toString(),
e.what());
// TODO [IR-1816] Akvinikym 29.10.18: substitute error code magic number
// with named constant
return expected::makeError(
validation::CommandError{"signatures validation", 1, false});
}

if (signatories_valid and *signatories_valid) {
return {};
} else {
return expected::makeError(validation::CommandError{
"signatures validation",
"possible reasons: no account, number of signatures is less than "
"account quorum, signatures are not a subset of account "
"signatories",
false});
log_->error("Transaction %s failed signatures validation",
transaction.toString());
// TODO [IR-1816] Akvinikym 29.10.18: substitute error code magic number
// with named constant
return expected::makeError(
validation::CommandError{"signatures validation", 2, false});
}
}

Expand Down Expand Up @@ -101,7 +104,7 @@ namespace iroha {
.match([](expected::Value<void> &) { return true; },
[i, &cmd_error](expected::Error<CommandError> &error) {
cmd_error = {error.error.command_name,
error.error.toString(),
error.error.error_code,
true,
i};
return false;
Expand Down
8 changes: 4 additions & 4 deletions irohad/torii/processor/impl/transaction_processor_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ namespace iroha {
if (not tx_error.first.tx_passed_initial_validation) {
return (boost::format("Stateful validation error: transaction %s "
"did not pass initial verification: "
"checking '%s', error message '%s'")
"checking '%s', error code '%d'")
% tx_error.second.hex() % tx_error.first.name
% tx_error.first.error)
% tx_error.first.error_code)
.str();
}
return (boost::format("Stateful validation error in transaction %s: "
"command '%s' with index '%d' did not pass "
"verification with error '%s'")
"verification with error code '%d'")
% tx_error.second.hex() % tx_error.first.name
% tx_error.first.index % tx_error.first.error)
% tx_error.first.index % tx_error.first.error_code)
.str();
}
} // namespace
Expand Down
2 changes: 1 addition & 1 deletion irohad/validation/impl/stateful_validator_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace iroha {
* @param temporary_wsv to apply commands on
* @param transactions_errors_log to write errors to
* @param tx to be checked
* @return empty result, if check is succesfull, command error otherwise
* @return empty result, if check is successful, command error otherwise
*/
static bool checkTransactions(
ametsuchi::TemporaryWsv &temporary_wsv,
Expand Down
4 changes: 2 additions & 2 deletions irohad/validation/stateful_validator_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace iroha {
/// Name of the failed command
std::string name;

/// Error, with which the command failed
std::string error;
/// Error code, with which the command failed
uint32_t error_code;

/// Shows, if transaction has passed initial validation
bool tx_passed_initial_validation;
Expand Down
4 changes: 2 additions & 2 deletions test/module/iroha-cli/client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ TEST_F(ClientServerTest, SendTxWhenStatefulInvalid) {
std::make_pair(verified_proposal,
iroha::validation::TransactionsErrors{std::make_pair(
iroha::validation::CommandError{
"CommandName", "CommandError", true, 2},
"CommandName", 2, true, 2},
tx.hash())})));
auto stringified_error = "Stateful validation error in transaction "
+ tx.hash().hex() + ": command 'CommandName' with "
"index '2' did not pass verification with "
"error 'CommandError'";
"error code '2'";

auto getAnswer = [&]() {
return client.getTxStatus(shared_model::crypto::toBinaryString(tx.hash()))
Expand Down
4 changes: 2 additions & 2 deletions test/module/irohad/simulator/simulator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ TEST_F(SimulatorTest, RightNumberOfFailedTxs) {
.transactions(std::vector<shared_model::proto::Transaction>{tx})
.build());
auto tx_errors = iroha::validation::TransactionsErrors{
std::make_pair(validation::CommandError{"SomeCommand", "SomeError", true},
std::make_pair(validation::CommandError{"SomeCommand", 1, true},
shared_model::crypto::Hash(std::string(32, '0'))),
std::make_pair(validation::CommandError{"SomeCommand", "SomeError", true},
std::make_pair(validation::CommandError{"SomeCommand", 1, true},
shared_model::crypto::Hash(std::string(32, '0')))};
shared_model::proto::Block block = makeBlock(proposal->height() - 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,7 @@ TEST_F(TransactionProcessorTest, TransactionProcessorInvalidTxsTest) {
auto txs_errors = iroha::validation::TransactionsErrors{};
for (size_t i = 0; i < invalid_txs.size(); ++i) {
txs_errors.push_back(std::make_pair(
iroha::validation::CommandError{
"SomeCommandName", "SomeCommandError", true, i},
iroha::validation::CommandError{"SomeCommandName", 1, true, i},
invalid_txs[i].hash()));
}
verified_prop_notifier.get_subscriber().on_next(
Expand Down
5 changes: 2 additions & 3 deletions test/module/irohad/torii/torii_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,12 @@ TEST_F(ToriiServiceTest, StatusWhenBlocking) {
.build());
auto errors = iroha::validation::TransactionsErrors{std::make_pair(
iroha::validation::CommandError{
"FailedCommand", "stateful validation failed", true, 2},
"FailedCommand", 2, true, 2},
failed_tx_hash)};
auto stringified_error = "Stateful validation error in transaction "
+ failed_tx_hash.hex() + ": "
"command 'FailedCommand' with index '2' "
"did not pass verification with error 'stateful "
"validation failed'";
"did not pass verification with error code '2'";
verified_prop_notifier_.get_subscriber().on_next(
std::make_shared<iroha::validation::VerifiedProposalAndErrors>(
std::make_pair(verified_proposal, errors)));
Expand Down
7 changes: 5 additions & 2 deletions test/module/irohad/validation/stateful_validator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,14 @@ TEST_F(Validator, SomeTxsFail) {
.build();

EXPECT_CALL(*temp_wsv_mock, apply(Eq(ByRef(invalid_tx))))
.WillOnce(Return(iroha::expected::Error<CommandError>({})));
.WillOnce(Return(iroha::expected::makeError(CommandError{"", 2, false})));
EXPECT_CALL(*temp_wsv_mock, apply(Eq(ByRef(valid_tx))))
.WillRepeatedly(Return(iroha::expected::Value<void>({})));

auto verified_proposal_and_errors = sfv->validate(proposal, *temp_wsv_mock);
ASSERT_EQ(verified_proposal_and_errors.first->transactions().size(), 2);
ASSERT_EQ(verified_proposal_and_errors.second.size(), 1);
ASSERT_EQ(verified_proposal_and_errors.second[0].first.error_code, 2);
}

/**
Expand Down Expand Up @@ -267,7 +268,8 @@ TEST_F(Validator, Batches) {
EXPECT_CALL(*temp_wsv_mock, apply(Eq(ByRef(txs[2]))))
.WillOnce(Return(iroha::expected::Value<void>({})));
EXPECT_CALL(*temp_wsv_mock, apply(Eq(ByRef(txs[3]))))
.WillOnce(Return(iroha::expected::Error<CommandError>({})));
.WillOnce(
Return(iroha::expected::makeError(CommandError({"", 2, false}))));
EXPECT_CALL(*temp_wsv_mock, apply(Eq(ByRef(txs[5]))))
.WillOnce(Return(iroha::expected::Value<void>({})));
EXPECT_CALL(*temp_wsv_mock, apply(Eq(ByRef(txs[6]))))
Expand All @@ -276,4 +278,5 @@ TEST_F(Validator, Batches) {
auto verified_proposal_and_errors = sfv->validate(proposal, *temp_wsv_mock);
ASSERT_EQ(verified_proposal_and_errors.first->transactions().size(), 5);
ASSERT_EQ(verified_proposal_and_errors.second.size(), 1);
ASSERT_EQ(verified_proposal_and_errors.second[0].first.error_code, 2);
}

0 comments on commit b95771c

Please sign in to comment.