mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Basic consensus implementation (#45)
Consensus for user connections, user inputs, contract outputs and time.
This commit is contained in:
56
src/main.cpp
56
src/main.cpp
@@ -13,9 +13,9 @@
|
||||
#include "conf.hpp"
|
||||
#include "crypto.hpp"
|
||||
#include "usr/usr.hpp"
|
||||
#include "p2p/p2p.hpp"
|
||||
#include "proc.hpp"
|
||||
#include "hplog.hpp"
|
||||
#include "cons/cons.hpp"
|
||||
|
||||
/**
|
||||
* Parses CLI args and extracts hot pocket command and parameters given.
|
||||
@@ -124,65 +124,21 @@ int main(int argc, char **argv)
|
||||
|
||||
hplog::init();
|
||||
|
||||
if (usr::init() != 0)
|
||||
if (p2p::init() != 0)
|
||||
return -1;
|
||||
|
||||
if (p2p::init() != 0)
|
||||
if (usr::init() != 0)
|
||||
return -1;
|
||||
|
||||
// After initializing primary subsystems, register the SIGINT handler.
|
||||
signal(SIGINT, signal_handler);
|
||||
|
||||
// This will start hosting the contract and start consensus rounds.
|
||||
// TODO
|
||||
cons::ctx.stage = 0;
|
||||
cons::ctx.lcl = "static_lcl";
|
||||
|
||||
while (true)
|
||||
{
|
||||
sleep(2);
|
||||
|
||||
// Test code to execute contract and collect outputs.
|
||||
std::unordered_map<std::string, std::pair<std::string, std::string>> userbufs;
|
||||
for (auto &[sid, user] : usr::users)
|
||||
{
|
||||
std::pair<std::string, std::string> bufpair;
|
||||
std::string inputtosend;
|
||||
inputtosend.swap(user.inbuffer);
|
||||
bufpair.first = std::move(inputtosend);
|
||||
|
||||
userbufs.emplace(user.pubkey, std::move(bufpair));
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> hpscbufpair;
|
||||
hpscbufpair.first = "{msg:'Message from HP'}";
|
||||
|
||||
std::unordered_map<std::string, std::pair<std::string, std::string>> nplbufs;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
std::pair<std::string, std::string> bufpair;
|
||||
nplbufs.emplace("aaa", std::move(bufpair));
|
||||
}
|
||||
|
||||
proc::ContractExecArgs eargs(123123345, userbufs, nplbufs, hpscbufpair);
|
||||
proc::exec_contract(eargs);
|
||||
|
||||
for (auto &[pubkey, bufpair] : userbufs)
|
||||
{
|
||||
if (!bufpair.second.empty())
|
||||
{
|
||||
// Find the user session id by the pubkey.
|
||||
const std::string sessionid = usr::sessionids[pubkey];
|
||||
|
||||
// Find the user by session id.
|
||||
auto itr = usr::users.find(sessionid);
|
||||
const usr::connected_user &user = itr->second;
|
||||
user.session->send(std::move(bufpair.second));
|
||||
}
|
||||
}
|
||||
|
||||
if (!hpscbufpair.second.empty())
|
||||
LOG_DBG << "Message from SC: " << hpscbufpair.second;
|
||||
|
||||
userbufs.clear();
|
||||
cons::consensus();
|
||||
}
|
||||
|
||||
// Free resources.
|
||||
|
||||
Reference in New Issue
Block a user