Skip to content

Commit

Permalink
Irohad: Check ledger keypair on init
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Matson <alexmat2on@protonmail.com>
  • Loading branch information
alexmat2on authored and lebdron committed Nov 16, 2019
1 parent ffb71f3 commit de4365e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
10 changes: 8 additions & 2 deletions irohad/ametsuchi/impl/postgres_wsv_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,14 @@ namespace iroha {
soci::use(public_key.hex(), "public_key"));
});

return getPeersFromSociRowSet(result) | [](auto &&peers) {
return boost::make_optional(std::move(peers.front()));
return getPeersFromSociRowSet(result) | [](auto &&peers)
-> boost::optional<
std::shared_ptr<shared_model::interface::Peer>> {
if (!peers.empty()) {
assert(peers.size() == 1);
return boost::make_optional(std::move(peers.front()));
}
return boost::none;
};
}
} // namespace ametsuchi
Expand Down
12 changes: 12 additions & 0 deletions irohad/main/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Irohad::RunResult Irohad::init() {
// to be sure it is consistent
}
| [this]{ return restoreWsv();}
| [this]{ return validateKeypair();}
| [this]{ return initTlsCredentials();}
| [this]{ return initPeerCertProvider();}
| [this]{ return initCryptoProvider();}
Expand Down Expand Up @@ -324,6 +325,17 @@ Irohad::RunResult Irohad::restoreWsv() {
};
}

Irohad::RunResult Irohad::validateKeypair() {
auto peers = storage->createPeerQuery() | [this](auto &&peer_query) {
return peer_query->getLedgerPeerByPublicKey(keypair.publicKey());
};
if (not peers) {
log_->warn("There is no peer in the ledger with my public key!");
}

return {};
}

/**
* Initializing own TLS credentials.
*/
Expand Down
5 changes: 5 additions & 0 deletions irohad/main/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ class Irohad {
*/
RunResult restoreWsv();

/**
* Check that the provided keypair is present in the ledger
*/
RunResult validateKeypair();

/**
* Drop wsv and block store
*/
Expand Down

0 comments on commit de4365e

Please sign in to comment.