Skip to content

Commit

Permalink
Add externally configurable parameters to OS and consensus
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Lebedev <[email protected]>
  • Loading branch information
lebdron committed Oct 24, 2017
1 parent cbd97c7 commit 696f743
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 22 deletions.
6 changes: 5 additions & 1 deletion example/config.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
"internal_port" : 10001,
"pg_opt" : "host=localhost port=5432 user=postgres password=mysecretpassword",
"redis_host" : "localhost",
"redis_port" : 6379
"redis_port" : 6379,
"max_proposal_size" : 10,
"proposal_delay" : 5000,
"vote_delay" : 5000,
"load_delay" : 5000
}
23 changes: 13 additions & 10 deletions irohad/main/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ Irohad::Irohad(const std::string &block_store_dir,
const std::string &pg_conn,
size_t torii_port,
size_t internal_port,
size_t max_proposal_size,
size_t proposal_delay,
size_t vote_delay,
size_t load_delay,
const keypair_t &keypair)
: block_store_dir_(block_store_dir),
redis_host_(redis_host),
redis_port_(redis_port),
pg_conn_(pg_conn),
torii_port_(torii_port),
internal_port_(internal_port),
max_proposal_size_(max_proposal_size),
proposal_delay_(proposal_delay),
vote_delay_(vote_delay),
load_delay_(load_delay),
keypair(keypair) {
log_ = logger::log("IROHAD");
log_->info("created");
Expand Down Expand Up @@ -118,15 +126,8 @@ void Irohad::initValidators() {
}

void Irohad::initOrderingGate() {
// const set maximum transactions that possible appears in one proposal

auto max_transactions_in_proposal = 10u;

// const set maximum waiting time util emitting new proposal
auto delay_for_new_proposal = 5000u;

ordering_gate = ordering_init.initOrderingGate(
wsv, max_transactions_in_proposal, delay_for_new_proposal);
ordering_gate =
ordering_init.initOrderingGate(wsv, max_proposal_size_, proposal_delay_);
log_->info("[Init] => init ordering gate - [{}]",
logger::logBool(ordering_gate));
}
Expand Down Expand Up @@ -154,7 +155,9 @@ void Irohad::initConsensusGate() {
wsv,
simulator,
block_loader,
keypair);
keypair,
vote_delay_,
load_delay_);

log_->info("[Init] => consensus gate");
}
Expand Down
14 changes: 14 additions & 0 deletions irohad/main/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class Irohad {
* @param torii_port - port for torii binding
* @param internal_port - port for internal communication - ordering service,
* consensus, and block loader
* @param max_proposal_size - maximum transactions that possible appears in
* one proposal
* @param proposal_delay - maximum waiting time util emitting new proposal
* @param vote_delay - waiting time before sending vote to next peer
* @param load_delay - waiting time before loading committed block from next
* peer
* @param keypair - public and private keys for crypto provider
*/
Irohad(const std::string &block_store_dir,
Expand All @@ -65,6 +71,10 @@ class Irohad {
const std::string &pg_conn,
size_t torii_port,
size_t internal_port,
size_t max_proposal_size,
size_t proposal_delay,
size_t vote_delay,
size_t load_delay,
const iroha::keypair_t &keypair);

/**
Expand Down Expand Up @@ -120,6 +130,10 @@ class Irohad {
std::string pg_conn_;
size_t torii_port_;
size_t internal_port_;
size_t max_proposal_size_;
size_t proposal_delay_;
size_t vote_delay_;
size_t load_delay_;

// ------------------------| internal dependencies |-------------------------

Expand Down
14 changes: 9 additions & 5 deletions irohad/main/impl/consensus_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,31 @@ namespace iroha {
std::shared_ptr<consensus::yac::Yac> YacInit::createYac(
std::string network_address,
ClusterOrdering initial_order,
const keypair_t &keypair) {
const keypair_t &keypair,
uint64_t delay_milliseconds) {
return Yac::create(
YacVoteStorage(),
createNetwork(std::move(network_address), initial_order.getPeers()),
createCryptoProvider(keypair),
createTimer(),
initial_order,
delay_seconds_ * 1000);
delay_milliseconds);
}

std::shared_ptr<YacGate> YacInit::initConsensusGate(
std::string network_address,
std::shared_ptr<ametsuchi::PeerQuery> wsv,
std::shared_ptr<simulator::BlockCreator> block_creator,
std::shared_ptr<network::BlockLoader> block_loader,
const keypair_t &keypair) {
const keypair_t &keypair,
uint64_t vote_delay_milliseconds,
uint64_t load_delay_milliseconds) {
auto peer_orderer = createPeerOrderer(wsv);

auto yac = createYac(std::move(network_address),
peer_orderer->getInitialOrdering().value(),
keypair);
keypair,
vote_delay_milliseconds);
consensus_network->subscribe(yac);

auto hash_provider = createHashProvider();
Expand All @@ -84,7 +88,7 @@ namespace iroha {
hash_provider,
block_creator,
block_loader,
delay_seconds_ * 1000);
load_delay_milliseconds);
}

} // namespace yac
Expand Down
9 changes: 5 additions & 4 deletions irohad/main/impl/consensus_init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,18 @@ namespace iroha {
std::shared_ptr<consensus::yac::Yac> createYac(
std::string network_address,
ClusterOrdering initial_order,
const keypair_t &keypair);

uint64_t delay_seconds_ = 5;
const keypair_t &keypair,
uint64_t delay_milliseconds);

public:
std::shared_ptr<YacGate> initConsensusGate(
std::string network_address,
std::shared_ptr<ametsuchi::PeerQuery> wsv,
std::shared_ptr<simulator::BlockCreator> block_creator,
std::shared_ptr<network::BlockLoader> block_loader,
const keypair_t &keypair);
const keypair_t &keypair,
uint64_t vote_delay_milliseconds,
uint64_t load_delay_milliseconds);

std::shared_ptr<NetworkImpl> consensus_network;
};
Expand Down
20 changes: 20 additions & 0 deletions irohad/main/iroha_conf_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ namespace config_members {
const char* PgOpt = "pg_opt";
const char* RedisHost = "redis_host";
const char* RedisPort = "redis_port";
const char* MaxProposalSize = "max_proposal_size";
const char* ProposalDelay = "proposal_delay";
const char* VoteDelay = "vote_delay";
const char* LoadDelay = "load_delay";
} // namespace config_members

/**
Expand Down Expand Up @@ -71,6 +75,22 @@ inline rapidjson::Document parse_iroha_config(std::string const& iroha_conf_path
assert_fatal(doc.HasMember(mbr::RedisPort), no_member_error(mbr::RedisPort));
assert_fatal(doc[mbr::RedisPort].IsUint(),
type_error(mbr::RedisPort, "uint"));

assert_fatal(doc.HasMember(mbr::MaxProposalSize), no_member_error(mbr::MaxProposalSize));
assert_fatal(doc[mbr::MaxProposalSize].IsUint(),
type_error(mbr::MaxProposalSize, "uint"));

assert_fatal(doc.HasMember(mbr::ProposalDelay), no_member_error(mbr::ProposalDelay));
assert_fatal(doc[mbr::ProposalDelay].IsUint(),
type_error(mbr::ProposalDelay, "uint"));

assert_fatal(doc.HasMember(mbr::VoteDelay), no_member_error(mbr::VoteDelay));
assert_fatal(doc[mbr::VoteDelay].IsUint(),
type_error(mbr::VoteDelay, "uint"));

assert_fatal(doc.HasMember(mbr::LoadDelay), no_member_error(mbr::LoadDelay));
assert_fatal(doc[mbr::LoadDelay].IsUint(),
type_error(mbr::LoadDelay, "uint"));
return doc;
}

Expand Down
4 changes: 4 additions & 0 deletions irohad/main/irohad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ int main(int argc, char *argv[]) {
config[mbr::PgOpt].GetString(),
config[mbr::ToriiPort].GetUint(),
config[mbr::InternalPort].GetUint(),
config[mbr::MaxProposalSize].GetUint(),
config[mbr::ProposalDelay].GetUint(),
config[mbr::VoteDelay].GetUint(),
config[mbr::LoadDelay].GetUint(),
keypair);

if (not irohad.storage) {
Expand Down
21 changes: 19 additions & 2 deletions test/integration/pipeline/tx_pipeline_integration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,21 @@ class TestIrohad : public Irohad {
const std::string &pg_conn,
size_t torii_port,
size_t internal_port,
size_t max_proposal_size,
size_t proposal_delay,
size_t vote_delay,
size_t load_delay,
const iroha::keypair_t &keypair)
: Irohad(block_store_dir,
redis_host,
redis_port,
pg_conn,
torii_port,
internal_port,
max_proposal_size,
proposal_delay,
vote_delay,
load_delay,
keypair) {}

auto &getCommandService() { return command_service; }
Expand Down Expand Up @@ -82,8 +90,17 @@ class TxPipelineIntegrationTest : public iroha::ametsuchi::AmetsuchiTest {
manager = std::make_shared<iroha::KeysManagerImpl>("node0");
auto keypair = manager->loadKeys().value();

irohad = std::make_shared<TestIrohad>(
block_store_path, redishost_, redisport_, pgopt_, 0, 10001, keypair);
irohad = std::make_shared<TestIrohad>(block_store_path,
redishost_,
redisport_,
pgopt_,
0,
10001,
10,
5000,
5000,
5000,
keypair);

ASSERT_TRUE(irohad->storage);

Expand Down

0 comments on commit 696f743

Please sign in to comment.