Patch config and hpfs sync refactor. (#208)

* Terminology changes from state to hpfs.
* Syncing hpfs parents in priority order.
* Changing how the hash is calculate in hpfs response validate check.
This commit is contained in:
Savinda Senevirathne
2021-01-06 10:50:58 +05:30
committed by GitHub
parent a16eb39d1f
commit c87ae6693d
31 changed files with 790 additions and 688 deletions

View File

@@ -37,6 +37,8 @@ add_executable(hpcore
src/sc.cpp
src/bill/corebill.cpp
src/hpfs/hpfs.cpp
src/hpfs/hpfs_serve.cpp
src/hpfs/hpfs_sync.cpp
src/comm/comm_session.cpp
src/msg/fbuf/common_helpers.cpp
src/msg/fbuf/p2pmsg_helpers.cpp
@@ -58,9 +60,6 @@ add_executable(hpcore
src/usr/read_req.cpp
src/ledger.cpp
src/consensus.cpp
src/state/state_common.cpp
src/state/state_sync.cpp
src/state/state_serve.cpp
src/main.cpp
)
target_link_libraries(hpcore

View File

@@ -25,8 +25,8 @@
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define TABLE_FILE "appbill.table"
#define TABLE_FILE_2 "./state/appbill.table" // if TABLE_FILE can't be found try here
#define TABLE_FILE "./state/appbill.table"
#define TABLE_FILE_2 "appbill.table" // if TABLE_FILE can't be found try here
uint64_t new_balance(uint64_t balance, int64_t to_credit) {
if (to_credit < 0 && -to_credit > balance) {

View File

@@ -3,6 +3,7 @@
#include "crypto.hpp"
#include "hpfs/hpfs.hpp"
#include "util/util.hpp"
#include "sc.hpp"
namespace conf
{
@@ -22,8 +23,6 @@ namespace conf
const static char *PUBLIC = "public";
const static char *PRIVATE = "private";
const static char *PATCH_FILE_NAME = "patch.cfg"; // Config patch filename.
bool init_success = false;
/**
@@ -111,10 +110,11 @@ namespace conf
util::create_dir_tree_recursive(ctx.hist_dir);
util::create_dir_tree_recursive(ctx.full_hist_dir);
util::create_dir_tree_recursive(ctx.log_dir);
util::create_dir_tree_recursive(ctx.state_dir);
util::create_dir_tree_recursive(ctx.hpfs_dir);
// Creating state seed dir in advance so hpfs doesn't cause mkdir race conditions during first-run.
util::create_dir_tree_recursive(ctx.state_dir + "/seed");
// Creating hpfs seed dir in advance so hpfs doesn't cause mkdir race conditions during first-run.
util::create_dir_tree_recursive(ctx.hpfs_dir + "/seed");
util::create_dir_tree_recursive(ctx.hpfs_dir + std::string("/seed").append(sc::STATE_DIR_PATH));
//Create config file with default settings.
@@ -200,9 +200,9 @@ namespace conf
ctx.tls_cert_file = ctx.config_dir + "/tlscert.pem";
ctx.hist_dir = basedir + "/hist";
ctx.full_hist_dir = basedir + "/fullhist";
ctx.state_dir = basedir + "/state";
ctx.state_rw_dir = ctx.state_dir + "/rw";
ctx.state_serve_dir = ctx.state_dir + "/ss";
ctx.hpfs_dir = basedir + "/hpfs";
ctx.hpfs_rw_dir = ctx.hpfs_dir + "/rw";
ctx.hpfs_serve_dir = ctx.hpfs_dir + "/ss";
ctx.log_dir = basedir + "/log";
}
@@ -390,7 +390,7 @@ namespace conf
// Uncomment for docker-based execution.
// std::string volumearg;
// volumearg.append("type=bind,source=").append(ctx.state_dir).append(",target=/state");
// volumearg.append("type=bind,source=").append(ctx.hpfs_dir).append(",target=/hpfs");
// const char *dockerargs[] = {"/usr/bin/docker", "run", "--rm", "-i", "--mount", volumearg.data(), cfg.contract.bin_path.data()};
// cfg.contract.runtime_binexec_args.insert(cfg.contract.runtime_binexec_args.begin(), std::begin(dockerargs), std::end(dockerargs));
}
@@ -689,7 +689,7 @@ namespace conf
ctx.config_file,
ctx.hist_dir,
ctx.full_hist_dir,
ctx.state_dir,
ctx.hpfs_dir,
ctx.tls_key_file,
ctx.tls_cert_file,
ctx.hpfs_exe_path,
@@ -795,7 +795,7 @@ namespace conf
*/
int validate_and_apply_patch_config(contract_params &contract_config, std::string_view mount_dir)
{
const std::string path = std::string(mount_dir).append("/").append(PATCH_FILE_NAME);
const std::string path = std::string(mount_dir).append(PATCH_FILE_PATH);
if (util::is_file_exists(path))
{
std::ifstream ifs(path);
@@ -889,8 +889,8 @@ namespace conf
if (!contract_config.appbill.bin_args.empty())
util::split_string(contract_config.appbill.runtime_args, contract_config.appbill.bin_args, " ");
contract_config.appbill.runtime_args.insert(contract_config.appbill.runtime_args.begin(), (contract_config.appbill.mode[0] == '/' ? contract_config.appbill.mode : util::realpath(conf::ctx.contract_dir + "/bin/" + contract_config.appbill.mode)));
std::cout << "Contract config updated from " << PATCH_FILE_NAME << " file\n";
std::cout << "Contract config updated from patch file\n";
}
catch (const std::exception &e)
{

View File

@@ -137,17 +137,17 @@ namespace conf
std::string hpws_exe_path; // hpws executable file path.
std::string hpfs_exe_path; // hpfs executable file path.
std::string contract_dir; // Contract base directory full path
std::string full_hist_dir; // Contract full history dir full path
std::string hist_dir; // Contract ledger history dir full path
std::string state_dir; // Contract state maintenence path (hpfs path)
std::string state_rw_dir; // Contract executation read/write state path.
std::string state_serve_dir; // State server hpfs mount path.
std::string log_dir; // Contract log dir full path
std::string config_dir; // Contract config dir full path
std::string config_file; // Full path to the contract config file
std::string tls_key_file; // Full path to the tls private key file
std::string tls_cert_file; // Full path to the tls certificate
std::string contract_dir; // Contract base directory full path
std::string full_hist_dir; // Contract full history dir full path
std::string hist_dir; // Contract ledger history dir full path
std::string hpfs_dir; // Hpfs file system mount path (hpfs path)
std::string hpfs_rw_dir; // Hpfs read/write mount path.
std::string hpfs_serve_dir; // Hpfs server hpfs mount path.
std::string log_dir; // Contract log dir full path
std::string config_dir; // Contract config dir full path
std::string config_file; // Full path to the contract config file
std::string tls_key_file; // Full path to the tls private key file
std::string tls_cert_file; // Full path to the tls certificate
int config_fd; // Config file file descriptor
struct flock config_lock; // Config file record log
@@ -173,6 +173,8 @@ namespace conf
// Other modeuls will access config values via this.
extern contract_config cfg;
const static char *PATCH_FILE_PATH = "/patch.cfg"; // Config patch filename.
int init();
void deinit();

View File

@@ -13,8 +13,7 @@
#include "sc.hpp"
#include "util/h32.hpp"
#include "hpfs/hpfs.hpp"
#include "state/state_common.hpp"
#include "state/state_sync.hpp"
#include "hpfs/hpfs_sync.hpp"
#include "unl.hpp"
#include "ledger.hpp"
#include "consensus.hpp"
@@ -112,7 +111,8 @@ namespace consensus
// Get current lcl and state.
std::string lcl = ledger::ctx.get_lcl();
const uint64_t lcl_seq_no = ledger::ctx.get_seq_no();
util::h32 state = state_common::ctx.get_state();
util::h32 state_hash = hpfs::ctx.get_hash(hpfs::HPFS_PARENT_COMPONENTS::STATE);
util::h32 patch_hash = hpfs::ctx.get_hash(hpfs::HPFS_PARENT_COMPONENTS::PATCH);
std::string unl_hash = unl::get_hash();
if (ctx.stage == 0)
@@ -122,7 +122,7 @@ namespace consensus
if (verify_and_populate_candidate_user_inputs(lcl_seq_no) == -1)
return -1;
const p2p::proposal p = create_stage0_proposal(lcl, state, unl_hash);
const p2p::proposal p = create_stage0_proposal(lcl, state_hash, patch_hash, unl_hash);
broadcast_proposal(p);
ctx.stage = 1; // Transition to next stage.
@@ -138,11 +138,11 @@ namespace consensus
if (sync_status == 0)
{
// If we are in sync, vote and broadcast the winning votes to next stage.
const p2p::proposal p = create_stage123_proposal(votes, lcl, unl_count, state, unl_hash);
const p2p::proposal p = create_stage123_proposal(votes, lcl, unl_count, state_hash, patch_hash, unl_hash);
broadcast_proposal(p);
// Upon successful consensus at stage 3, update the ledger and execute the contract using the consensus proposal.
if (ctx.stage == 3 && update_ledger_and_execute_contract(p, lcl, state) == -1)
if (ctx.stage == 3 && update_ledger_and_execute_contract(p, lcl, state_hash) == -1)
LOG_ERROR << "Error occured in Stage 3 consensus execution.";
}
@@ -167,7 +167,7 @@ namespace consensus
/**
* Checks whether we are in sync with the received votes.
* @return 0 if we are in sync. -1 on lcl or state desync. -2 if majority lcl unreliable.
* @return 0 if we are in sync. -1 on lcl, hpfs or unl desync. -2 if majority lcl unreliable.
*/
int check_sync_status(std::string_view lcl, std::string_view unl_hash, const size_t unl_count, vote_counter &votes)
{
@@ -187,14 +187,17 @@ namespace consensus
// Check our state with majority state.
bool is_state_desync = false;
util::h32 majority_state = util::h32_empty;
check_state_votes(is_state_desync, majority_state, votes);
bool is_patch_desync = false;
util::h32 majority_state_hash = util::h32_empty;
util::h32 majority_patch_hash = util::h32_empty;
check_patch_votes(is_patch_desync, majority_patch_hash, votes);
check_state_votes(is_state_desync, majority_state_hash, votes);
// Start state sync if we are out-of-sync with majority state.
if (is_state_desync)
// Start hpfs sync if we are out-of-sync with majority hpfs state.
if (is_state_desync || is_patch_desync)
{
conf::change_role(conf::ROLE::OBSERVER);
state_sync::set_target(majority_state);
hpfs_sync::set_target(majority_state_hash, majority_patch_hash);
}
// Check unl hash with the majority unl hash.
@@ -209,13 +212,13 @@ namespace consensus
}
// Proceed further only if both lcl and state are in sync with majority.
if (!is_lcl_desync && !is_state_desync && !is_unl_desync)
if (!is_lcl_desync && !is_state_desync && !is_patch_desync && !is_unl_desync)
{
conf::change_role(conf::ROLE::VALIDATOR);
return 0;
}
// lcl or state desync.
// lcl, hpfs or unl desync.
return -1;
}
@@ -229,7 +232,7 @@ namespace consensus
*/
void check_sync_completion()
{
if (conf::cfg.node.role == conf::ROLE::OBSERVER && !state_sync::ctx.is_syncing && !ledger::sync_ctx.is_syncing)
if (conf::cfg.node.role == conf::ROLE::OBSERVER && !hpfs_sync::ctx.is_syncing && !ledger::sync_ctx.is_syncing && !unl::sync_ctx.is_syncing)
conf::change_role(conf::ROLE::VALIDATOR);
}
@@ -272,7 +275,8 @@ namespace consensus
<< "/" << cp.input_hashes.size()
<< " ts:" << std::to_string(cp.time)
<< " lcl:" << cp.lcl.substr(0, 15)
<< " state:" << cp.state
<< " state hash:" << cp.state_hash
<< " patch hash:" << cp.patch_hash
<< " [from:" << ((cp.pubkey == conf::cfg.node.public_key) ? "self" : util::to_hex(cp.pubkey).substr(2, 10)) << "]"
<< "(" << std::to_string(cp.recv_timestamp > cp.sent_timestamp ? cp.recv_timestamp - cp.sent_timestamp : 0) << "ms)";
@@ -388,7 +392,8 @@ namespace consensus
<< "/" << p.input_hashes.size()
<< " ts:" << std::to_string(p.time)
<< " lcl:" << p.lcl.substr(0, 15)
<< " state:" << p.state;
<< " state hash:" << p.state_hash
<< " patch hash:" << p.patch_hash;
}
/**
@@ -530,7 +535,7 @@ namespace consensus
return 0;
}
p2p::proposal create_stage0_proposal(std::string_view lcl, util::h32 state, std::string_view unl_hash)
p2p::proposal create_stage0_proposal(std::string_view lcl, util::h32 state_hash, util::h32 patch_hash, std::string_view unl_hash)
{
// This is the proposal that stage 0 votes on.
// We report our own values in stage 0.
@@ -538,7 +543,8 @@ namespace consensus
p.time = ctx.round_start_time;
p.stage = 0;
p.lcl = lcl;
p.state = state;
p.state_hash = state_hash;
p.patch_hash = patch_hash;
p.unl_hash = unl_hash;
crypto::random_bytes(p.nonce, ROUND_NONCE_SIZE);
@@ -559,12 +565,13 @@ namespace consensus
return p;
}
p2p::proposal create_stage123_proposal(vote_counter &votes, std::string_view lcl, const size_t unl_count, const util::h32 state, std::string_view unl_hash)
p2p::proposal create_stage123_proposal(vote_counter &votes, std::string_view lcl, const size_t unl_count, const util::h32 state_hash, const util::h32 patch_hash, std::string_view unl_hash)
{
// The proposal to be emited at the end of this stage.
p2p::proposal p;
p.stage = ctx.stage;
p.state = state;
p.state_hash = state_hash;
p.patch_hash = patch_hash;
// We always vote for our current lcl and state regardless of what other peers are saying.
// If there's a fork condition we will either request history and state from
@@ -762,27 +769,55 @@ namespace consensus
}
/**
* Check state against the winning and canonical state
* Check state hash against the winning and canonical state hash.
* @param is_state_desync Flag to determine whether contract state is out of sync.
* @param majority_state_hash Consensused state hash.
* @param votes The voting table.
*/
void check_state_votes(bool &is_desync, util::h32 &majority_state, vote_counter &votes)
void check_state_votes(bool &is_state_desync, util::h32 &majority_state_hash, vote_counter &votes)
{
for (const auto &[pubkey, cp] : ctx.candidate_proposals)
{
increment(votes.state, cp.state);
increment(votes.state_hash, cp.state_hash);
}
uint32_t winning_votes = 0;
for (const auto [state, votes] : votes.state)
for (const auto [state_hash, votes] : votes.state_hash)
{
if (votes > winning_votes)
{
winning_votes = votes;
majority_state = state;
majority_state_hash = state_hash;
}
}
is_desync = (state_common::ctx.get_state() != majority_state);
is_state_desync = (hpfs::ctx.get_hash(hpfs::HPFS_PARENT_COMPONENTS::STATE) != majority_state_hash);
}
/**
* Check state hash against the winning and canonical state hash.
* @param is_patch_desync Flag to determine whether patch file is out of sync.
* @param majority_patch_hash Consensused patch hash.
* @param votes The voting table.
*/
void check_patch_votes(bool &is_patch_desync, util::h32 &majority_patch_hash, vote_counter &votes)
{
for (const auto &[pubkey, cp] : ctx.candidate_proposals)
{
increment(votes.patch_hash, cp.patch_hash);
}
uint32_t winning_votes = 0;
for (const auto [patch_hash, votes] : votes.patch_hash)
{
if (votes > winning_votes)
{
winning_votes = votes;
majority_patch_hash = patch_hash;
}
}
is_patch_desync = (hpfs::ctx.get_hash(hpfs::HPFS_PARENT_COMPONENTS::PATCH) != majority_patch_hash);
}
/**
@@ -816,7 +851,7 @@ namespace consensus
* Update the ledger and execute the contract after consensus.
* @param cons_prop The proposal that reached consensus.
*/
int update_ledger_and_execute_contract(const p2p::proposal &cons_prop, std::string &new_lcl, util::h32 &new_state)
int update_ledger_and_execute_contract(const p2p::proposal &cons_prop, std::string &new_lcl, util::h32 &new_state_hash)
{
// Map to temporarily store the raw inputs along with the hash.
std::unordered_map<std::string, usr::raw_user_input> raw_inputs;
@@ -848,7 +883,7 @@ namespace consensus
new_lcl = ledger::ctx.get_lcl();
const uint64_t new_lcl_seq_no = ledger::ctx.get_seq_no();
LOG_INFO << "****Ledger created**** (lcl:" << new_lcl.substr(0, 15) << " state:" << cons_prop.state << ")";
LOG_INFO << "****Ledger created**** (lcl:" << new_lcl.substr(0, 15) << " state hash:" << cons_prop.state_hash << " patch hash:" << cons_prop.patch_hash << ")";
// After the current ledger seq no is updated, we remove any newly expired inputs from candidate set.
{
@@ -879,7 +914,7 @@ namespace consensus
}
sc::contract_execution_args &args = ctx.contract_ctx->args;
args.state_dir = conf::ctx.state_rw_dir;
args.hpfs_dir = conf::ctx.hpfs_rw_dir;
args.readonly = false;
args.time = cons_prop.time;
args.lcl = new_lcl;
@@ -894,8 +929,8 @@ namespace consensus
return -1;
}
state_common::ctx.set_state(args.post_execution_state_hash);
new_state = args.post_execution_state_hash;
hpfs::ctx.set_hash(hpfs::HPFS_PARENT_COMPONENTS::STATE, args.post_execution_state_hash);
new_state_hash = args.post_execution_state_hash;
extract_user_outputs_from_contract_bufmap(args.userbufs);
@@ -905,7 +940,7 @@ namespace consensus
std::vector<std::string_view> hashes;
for (const auto &[hash, output] : ctx.generated_user_outputs)
hashes.push_back(hash);
hashes.push_back(new_state.to_string_view());
hashes.push_back(new_state_hash.to_string_view());
ctx.user_outputs_hashtree.populate(hashes);
ctx.user_outputs_our_sig = crypto::sign(ctx.user_outputs_hashtree.root_hash(), conf::cfg.node.private_key);
}

View File

@@ -95,7 +95,8 @@ namespace consensus
std::map<std::string, uint32_t> users;
std::map<std::string, uint32_t> inputs;
std::map<std::string, uint32_t> output_hash;
std::map<util::h32, uint32_t> state;
std::map<util::h32, uint32_t> state_hash;
std::map<util::h32, uint32_t> patch_hash;
std::map<std::string, uint32_t> unl;
std::map<std::string, uint32_t> unl_additions;
std::map<std::string, uint32_t> unl_removals;
@@ -125,15 +126,17 @@ namespace consensus
int verify_and_populate_candidate_user_inputs(const uint64_t lcl_seq_no);
p2p::proposal create_stage0_proposal(std::string_view lcl, util::h32 state, std::string_view unl_hash);
p2p::proposal create_stage0_proposal(std::string_view lcl, util::h32 state_hash, util::h32 patch_hash, std::string_view unl_hash);
p2p::proposal create_stage123_proposal(vote_counter &votes, std::string_view lcl, const size_t unl_count, const util::h32 state, std::string_view unl_hash);
p2p::proposal create_stage123_proposal(vote_counter &votes, std::string_view lcl, const size_t unl_count, const util::h32 state_hash, const util::h32 patch_hash, std::string_view unl_hash);
void broadcast_proposal(const p2p::proposal &p);
bool check_lcl_votes(bool &is_desync, std::string &majority_lcl, vote_counter &votes, std::string_view lcl, const size_t unl_count);
void check_state_votes(bool &is_desync, util::h32 &majority_state, vote_counter &votes);
void check_state_votes(bool &is_state_desync, util::h32 &majority_state_hash, vote_counter &votes);
void check_patch_votes(bool &is_patch_desync, util::h32 &majority_patch_hash, vote_counter &votes);
void check_unl_votes(bool &is_desync, std::string &majority_unl, vote_counter &votes, std::string_view unl_hash);
@@ -143,7 +146,7 @@ namespace consensus
uint64_t get_stage_time_resolution(const uint64_t time);
int update_ledger_and_execute_contract(const p2p::proposal &proposal, std::string &new_lcl, util::h32 &new_state);
int update_ledger_and_execute_contract(const p2p::proposal &proposal, std::string &new_lcl, util::h32 &new_state_hash);
int dispatch_user_outputs(const p2p::proposal &cons_prop, const uint64_t lcl_seq_no, std::string_view lcl);

View File

@@ -3,6 +3,7 @@
#include "../hplog.hpp"
#include "../util/util.hpp"
#include "../util/h32.hpp"
#include "../sc.hpp"
namespace hpfs
{
@@ -13,6 +14,60 @@ namespace hpfs
constexpr const char *HPFS_SESSION = "::hpfs.session";
constexpr ino_t HPFS_ROOT_INO = 2;
constexpr uint16_t INIT_CHECK_INTERVAL = 20;
bool init_success = false;
hpfs_context ctx;
/**
* Performs system startup activitites related to hpfs execution.
*/
int init()
{
if (start_merge_process(ctx.hpfs_merge_pid) == -1)
return -1;
if (start_ro_rw_process(ctx.hpfs_rw_pid, conf::ctx.hpfs_rw_dir, false, true, false) == -1)
{
// Stop the merge process in case of failure.
util::kill_process(ctx.hpfs_merge_pid, true);
return -1;
}
util::h32 initial_state_hash;
util::h32 initial_patch_hash;
if (start_fs_session(conf::ctx.hpfs_rw_dir) == -1 ||
get_hash(initial_state_hash, conf::ctx.hpfs_rw_dir, sc::STATE_DIR_PATH) == -1 ||
get_hash(initial_patch_hash, conf::ctx.hpfs_rw_dir, conf::PATCH_FILE_PATH) == -1 ||
stop_fs_session(conf::ctx.hpfs_rw_dir) == -1)
{
LOG_ERROR << "Failed to get initial state hash.";
return -1;
}
ctx.set_hash(HPFS_PARENT_COMPONENTS::STATE, initial_state_hash);
ctx.set_hash(HPFS_PARENT_COMPONENTS::PATCH, initial_patch_hash);
LOG_INFO << "Initial state hash: " << initial_state_hash;
LOG_INFO << "Initial patch hash: " << initial_patch_hash;
init_success = true;
return 0;
}
/**
* Performs global cleanup related to hpfs execution.
*/
void deinit()
{
if (init_success)
{
LOG_DEBUG << "Stopping hpfs rw process... pid:" << ctx.hpfs_rw_pid;
if (ctx.hpfs_rw_pid > 0 && util::kill_process(ctx.hpfs_rw_pid, true) == 0)
LOG_INFO << "Stopped hpfs rw process.";
LOG_DEBUG << "Stopping hpfs merge process... pid:" << ctx.hpfs_merge_pid;
if (ctx.hpfs_merge_pid > 0 && util::kill_process(ctx.hpfs_merge_pid, true) == 0)
LOG_INFO << "Stopped hpfs merge process.";
}
}
/**
* Starts hpfs merge process.
@@ -47,7 +102,7 @@ namespace hpfs
char *execv_args[] = {
conf::ctx.hpfs_exe_path.data(),
(char *)"merge",
conf::ctx.state_dir.data(),
conf::ctx.hpfs_dir.data(),
(char *)active_hpfs_trace_arg,
NULL};
@@ -80,7 +135,7 @@ namespace hpfs
// If the mount dir is not specified, assign a mount dir based on hpfs process id.
if (mount_dir.empty())
mount_dir = std::string(conf::ctx.state_dir)
mount_dir = std::string(conf::ctx.hpfs_dir)
.append("/")
.append(std::to_string(pid));
@@ -137,7 +192,7 @@ namespace hpfs
// If the mount dir is not specified, assign a mount dir based on hpfs process id.
const pid_t self_pid = getpid();
if (mount_dir.empty())
mount_dir = std::string(conf::ctx.state_dir)
mount_dir = std::string(conf::ctx.hpfs_dir)
.append("/")
.append(std::to_string(self_pid));
@@ -147,7 +202,7 @@ namespace hpfs
char *execv_args[] = {
conf::ctx.hpfs_exe_path.data(),
(char *)mode, // hpfs mode: rw | ro
conf::ctx.state_dir.data(),
conf::ctx.hpfs_dir.data(),
mount_dir.data(),
(char *)(hash_map_enabled ? "hmap=true" : "hmap=false"),
(char *)active_hpfs_trace_arg,
@@ -273,7 +328,7 @@ namespace hpfs
*/
int get_dir_children_hashes(std::vector<child_hash_node> &hash_nodes, const std::string_view mount_dir, const std::string_view dir_vpath)
{
const std::string path = std::string(mount_dir).append(dir_vpath).append("::hpfs.hmap.children");
const std::string path = std::string(mount_dir).append(dir_vpath).append(HPFS_HMAP_CHILDREN);
const int fd = open(path.c_str(), O_RDONLY | O_CLOEXEC);
if (fd == -1 && errno == ENOENT)
{

View File

@@ -3,9 +3,12 @@
#include "../pchheader.hpp"
#include "../util/h32.hpp"
#include "../conf.hpp"
namespace hpfs
{
constexpr size_t BLOCK_SIZE = 4 * 1024 * 1024; // 4MB;
struct child_hash_node
{
bool is_file = false;
@@ -18,8 +21,53 @@ namespace hpfs
}
};
// File block size;
constexpr size_t BLOCK_SIZE = 4194304; // 4MB
inline uint16_t get_request_resubmit_timeout()
{
return conf::cfg.contract.roundtime;
}
enum HPFS_PARENT_COMPONENTS
{
STATE,
PATCH
};
struct hpfs_context
{
private:
std::vector<util::h32> parent_hashes; // Keep hashes of each hpfs parent.
std::shared_mutex parent_mutexes[2] = {std::shared_mutex(), std::shared_mutex()}; // Mutexes for each parent.
public:
pid_t hpfs_merge_pid = 0;
pid_t hpfs_rw_pid = 0;
hpfs_context()
{
parent_hashes.reserve(2);
for (size_t i = 0; i < 2; i++)
{
parent_hashes.push_back(util::h32_empty);
}
}
util::h32 get_hash(const HPFS_PARENT_COMPONENTS parent)
{
std::shared_lock lock(parent_mutexes[parent]);
return parent_hashes[parent];
}
void set_hash(const HPFS_PARENT_COMPONENTS parent, util::h32 new_state)
{
std::unique_lock lock(parent_mutexes[parent]);
parent_hashes[parent] = new_state;
}
};
extern hpfs_context ctx;
int init();
void deinit();
int start_merge_process(pid_t &hpfs_pid);
int start_ro_rw_process(pid_t &hpfs_pid, std::string &mount_dir, const bool readonly,

View File

@@ -1,5 +1,4 @@
#include "../pchheader.hpp"
#include "../hpfs/hpfs.hpp"
#include "../util/h32.hpp"
#include "../util/util.hpp"
#include "../p2p/p2p.hpp"
@@ -8,15 +7,15 @@
#include "../msg/fbuf/common_helpers.hpp"
#include "../ledger.hpp"
#include "../hplog.hpp"
#include "state_serve.hpp"
#include "state_common.hpp"
#include "hpfs_serve.hpp"
#include "hpfs_sync.hpp"
namespace p2pmsg = msg::fbuf::p2pmsg;
/**
* Helper functions for serving state requests from other peers.
* Helper functions for serving hpfs requests from other peers.
*/
namespace state_serve
namespace hpfs_serve
{
constexpr uint16_t LOOP_WAIT = 20; // Milliseconds
@@ -25,16 +24,16 @@ namespace state_serve
bool is_shutting_down = false;
bool init_success = false;
pid_t hpfs_pid;
std::thread state_serve_thread;
std::thread hpfs_serve_thread;
int init()
{
REQUEST_BATCH_TIMEOUT = state_common::get_request_resubmit_timeout() * 0.9;
REQUEST_BATCH_TIMEOUT = hpfs::get_request_resubmit_timeout() * 0.9;
if (hpfs::start_ro_rw_process(hpfs_pid, conf::ctx.state_serve_dir, true, true, false) == -1)
if (hpfs::start_ro_rw_process(hpfs_pid, conf::ctx.hpfs_serve_dir, true, true, false) == -1)
return -1;
state_serve_thread = std::thread(state_serve_loop);
hpfs_serve_thread = std::thread(hpfs_serve_loop);
init_success = true;
return 0;
}
@@ -44,7 +43,7 @@ namespace state_serve
if (init_success)
{
is_shutting_down = true;
state_serve_thread.join();
hpfs_serve_thread.join();
LOG_DEBUG << "Stopping hpfs state serve process... pid:" << hpfs_pid;
if (hpfs_pid > 0 && util::kill_process(hpfs_pid, true) == 0)
@@ -52,13 +51,13 @@ namespace state_serve
}
}
void state_serve_loop()
void hpfs_serve_loop()
{
util::mask_signal();
LOG_INFO << "State server started.";
LOG_INFO << "Hpfs server started.";
std::list<std::pair<std::string, std::string>> state_requests;
std::list<std::pair<std::string, std::string>> hpfs_requests;
// Indicates whether any requests were processed in the previous loop iteration.
bool prev_requests_processed = false;
@@ -70,47 +69,47 @@ namespace state_serve
util::sleep(LOOP_WAIT);
{
std::scoped_lock<std::mutex> lock(p2p::ctx.collected_msgs.state_requests_mutex);
std::scoped_lock<std::mutex> lock(p2p::ctx.collected_msgs.hpfs_requests_mutex);
// Move collected state requests over to local requests list.
if (!p2p::ctx.collected_msgs.state_requests.empty())
state_requests.splice(state_requests.end(), p2p::ctx.collected_msgs.state_requests);
// Move collected hpfs requests over to local requests list.
if (!p2p::ctx.collected_msgs.hpfs_requests.empty())
hpfs_requests.splice(hpfs_requests.end(), p2p::ctx.collected_msgs.hpfs_requests);
}
prev_requests_processed = !state_requests.empty();
prev_requests_processed = !hpfs_requests.empty();
const uint64_t time_start = util::get_epoch_milliseconds();
const std::string lcl = ledger::ctx.get_lcl();
if (state_requests.empty())
if (hpfs_requests.empty())
continue;
if (hpfs::start_fs_session(conf::ctx.state_serve_dir) != -1)
if (hpfs::start_fs_session(conf::ctx.hpfs_serve_dir) != -1)
{
for (auto &[session_id, request] : state_requests)
for (auto &[session_id, request] : hpfs_requests)
{
if (is_shutting_down)
break;
// If we have spent too much time handling state requests, abandon the entire batch
// If we have spent too much time handling hpfs requests, abandon the entire batch
// because the requester would have stopped waiting for us.
const uint64_t time_now = util::get_epoch_milliseconds();
if ((time_now - time_start) > REQUEST_BATCH_TIMEOUT)
{
LOG_DEBUG << "State serve batch timeout. Abandonding state requests.";
LOG_DEBUG << "Hpfs serve batch timeout. Abandonding hpfs requests.";
break;
}
// Session id is in binary format. Converting to hex before printing.
LOG_DEBUG << "Serving state request from [" << util::to_hex(session_id).substr(2, 10) << "]";
LOG_DEBUG << "Serving hpfs request from [" << util::to_hex(session_id).substr(2, 10) << "]";
const msg::fbuf::p2pmsg::Content *content = msg::fbuf::p2pmsg::GetContent(request.data());
const p2p::state_request sr = p2pmsg::create_state_request_from_msg(*content->message_as_State_Request_Message());
const p2p::hpfs_request sr = p2pmsg::create_hpfs_request_from_msg(*content->message_as_Hpfs_Request_Message());
flatbuffers::FlatBufferBuilder fbuf(1024);
if (state_serve::create_state_response(fbuf, sr, lcl) == 1)
if (hpfs_serve::create_hpfs_response(fbuf, sr, lcl) == 1)
{
// Find the peer that we should send the state response to.
// Find the peer that we should send the hpfs response to.
std::scoped_lock<std::mutex> lock(p2p::ctx.peer_connections_mutex);
const auto peer_itr = p2p::ctx.peer_connections.find(session_id);
@@ -125,45 +124,45 @@ namespace state_serve
}
}
hpfs::stop_fs_session(conf::ctx.state_serve_dir);
hpfs::stop_fs_session(conf::ctx.hpfs_serve_dir);
}
state_requests.clear();
hpfs_requests.clear();
}
LOG_INFO << "State server stopped.";
LOG_INFO << "Hpfs server stopped.";
}
/**
* Creates the reply message for a given state request.
* Creates the reply message for a given hpfs request.
* @param fbuf The flatbuffer builder to construct the reply message.
* @param sr The state request which should be replied to.
* @return 1 if successful state response was generated. 0 if request is invalid
* @param hr The hpfs request which should be replied to.
* @return 1 if successful hpfs response was generated. 0 if request is invalid
* and no response was generated. -1 on error.
*/
int create_state_response(flatbuffers::FlatBufferBuilder &fbuf, const p2p::state_request &sr, std::string_view lcl)
int create_hpfs_response(flatbuffers::FlatBufferBuilder &fbuf, const p2p::hpfs_request &hr, std::string_view lcl)
{
LOG_DEBUG << "Serving state req. path:" << sr.parent_path << " block_id:" << sr.block_id;
LOG_DEBUG << "Serving hpfs req. path:" << hr.parent_path << " block_id:" << hr.block_id;
// If block_id > -1 this means this is a file block data request.
if (sr.block_id > -1)
if (hr.block_id > -1)
{
// Vector to hold the block bytes. Normally block size is constant BLOCK_SIZE (4MB), but the
// last block of a file may have a smaller size.
std::vector<uint8_t> block;
const int result = get_data_block(block, sr.parent_path, sr.block_id, sr.expected_hash);
const int result = get_data_block(block, hr.parent_path, hr.block_id, hr.expected_hash);
if (result == -1)
{
LOG_ERROR << "Error in getting file block: " << sr.parent_path;
LOG_ERROR << "Error in getting file block: " << hr.parent_path;
return -1;
}
else if (result == 1)
{
p2p::block_response resp;
resp.path = sr.parent_path;
resp.block_id = sr.block_id;
resp.hash = sr.expected_hash;
resp.path = hr.parent_path;
resp.block_id = hr.block_id;
resp.hash = hr.expected_hash;
resp.data = std::string_view(reinterpret_cast<const char *>(block.data()), block.size());
msg::fbuf::p2pmsg::create_msg_from_block_response(fbuf, resp, lcl);
@@ -172,53 +171,53 @@ namespace state_serve
}
else
{
// File state request means we have to reply with the file block hash map.
if (sr.is_file)
// File hpfs request means we have to reply with the file block hash map.
if (hr.is_file)
{
std::vector<util::h32> block_hashes;
std::size_t file_length = 0;
const int result = get_data_block_hashes(block_hashes, file_length, sr.parent_path, sr.expected_hash);
const int result = get_data_block_hashes(block_hashes, file_length, hr.parent_path, hr.expected_hash);
if (result == -1)
{
LOG_ERROR << "Error in getting block hashes: " << sr.parent_path;
LOG_ERROR << "Error in getting block hashes: " << hr.parent_path;
return -1;
}
else if (result == 1)
{
msg::fbuf::p2pmsg::create_msg_from_filehashmap_response(
fbuf, sr.parent_path, block_hashes,
file_length, sr.expected_hash, lcl);
fbuf, hr.parent_path, block_hashes,
file_length, hr.expected_hash, lcl);
return 1; // Success.
}
}
else
{
// If the state request is for a directory we need to reply with the
// If the hpfs request is for a directory we need to reply with the
// file system entries and their hashes inside that dir.
std::vector<hpfs::child_hash_node> child_hash_nodes;
const int result = get_fs_entry_hashes(child_hash_nodes, sr.parent_path, sr.expected_hash);
const int result = get_fs_entry_hashes(child_hash_nodes, hr.parent_path, hr.expected_hash);
if (result == -1)
{
LOG_ERROR << "Error in getting fs entries: " << sr.parent_path;
LOG_ERROR << "Error in getting fs entries: " << hr.parent_path;
return -1;
}
else if (result == 1)
{
msg::fbuf::p2pmsg::create_msg_from_fsentry_response(
fbuf, sr.parent_path, child_hash_nodes, sr.expected_hash, lcl);
fbuf, hr.parent_path, child_hash_nodes, hr.expected_hash, lcl);
return 1; // Success.
}
}
}
LOG_DEBUG << "No state response generated.";
LOG_DEBUG << "No hpfs response generated.";
return 0;
}
/**
* Retrieves the specified data block from a state file if expected hash matches.
* Retrieves the specified data block from a hpfs file if expected hash matches.
* @return 1 if block data was succefully fetched. 0 if vpath or block does not exist. -1 on error.
*/
int get_data_block(std::vector<uint8_t> &block, const std::string_view vpath,
@@ -226,7 +225,7 @@ namespace state_serve
{
// Check whether the existing block hash matches expected hash.
std::vector<util::h32> block_hashes;
int result = hpfs::get_file_block_hashes(block_hashes, conf::ctx.state_serve_dir, vpath);
int result = hpfs::get_file_block_hashes(block_hashes, conf::ctx.hpfs_serve_dir, vpath);
if (result == 1)
{
if (block_id >= block_hashes.size())
@@ -242,8 +241,8 @@ namespace state_serve
else // Get actual block data.
{
struct stat st;
const std::string file_path = std::string(conf::ctx.state_serve_dir).append(vpath);
const off_t block_offset = block_id * state_common::BLOCK_SIZE;
const std::string file_path = std::string(conf::ctx.hpfs_serve_dir).append(vpath);
const off_t block_offset = block_id * hpfs::BLOCK_SIZE;
const int fd = open(file_path.c_str(), O_RDONLY | O_CLOEXEC);
if (fd == -1)
{
@@ -269,7 +268,7 @@ namespace state_serve
}
else
{
const size_t read_len = MIN(state_common::BLOCK_SIZE, (st.st_size - block_offset));
const size_t read_len = MIN(hpfs::BLOCK_SIZE, (st.st_size - block_offset));
block.resize(read_len);
lseek(fd, block_offset, SEEK_SET);
@@ -303,7 +302,7 @@ namespace state_serve
{
// Check whether the existing file hash matches expected hash.
util::h32 file_hash = util::h32_empty;
int result = hpfs::get_hash(file_hash, conf::ctx.state_serve_dir, vpath);
int result = hpfs::get_hash(file_hash, conf::ctx.hpfs_serve_dir, vpath);
if (result == 1)
{
if (file_hash != expected_hash)
@@ -312,14 +311,14 @@ namespace state_serve
result = 0;
}
// Get the block hashes.
else if (hpfs::get_file_block_hashes(hashes, conf::ctx.state_serve_dir, vpath) < 0)
else if (hpfs::get_file_block_hashes(hashes, conf::ctx.hpfs_serve_dir, vpath) < 0)
{
result = -1;
}
else
{
// Get actual file length.
const std::string file_path = std::string(conf::ctx.state_serve_dir).append(vpath);
const std::string file_path = std::string(conf::ctx.hpfs_serve_dir).append(vpath);
struct stat st;
if (stat(file_path.c_str(), &st) == -1)
{
@@ -343,7 +342,7 @@ namespace state_serve
{
// Check whether the existing dir hash matches expected hash.
util::h32 dir_hash = util::h32_empty;
int result = hpfs::get_hash(dir_hash, conf::ctx.state_serve_dir, vpath);
int result = hpfs::get_hash(dir_hash, conf::ctx.hpfs_serve_dir, vpath);
if (result == 1)
{
if (dir_hash != expected_hash)
@@ -352,7 +351,7 @@ namespace state_serve
result = 0;
}
// Get the children hash nodes.
else if (hpfs::get_dir_children_hashes(hash_nodes, conf::ctx.state_serve_dir, vpath) < 0)
else if (hpfs::get_dir_children_hashes(hash_nodes, conf::ctx.hpfs_serve_dir, vpath) < 0)
{
result = -1;
}
@@ -364,4 +363,4 @@ namespace state_serve
return result;
}
} // namespace state_serve
} // namespace hpfs_serve

View File

@@ -1,20 +1,20 @@
#ifndef _HP_STATE_STATE_SERVE_
#define _HP_STATE_STATE_SERVE_
#ifndef _HP_HPFS_HPFS_SERVE_
#define _HP_HPFS_HPFS_SERVE_
#include "../util/h32.hpp"
#include "../hpfs/hpfs.hpp"
#include "hpfs.hpp"
#include "../p2p/p2p.hpp"
#include "../msg/fbuf/p2pmsg_content_generated.h"
namespace state_serve
namespace hpfs_serve
{
int init();
void deinit();
void state_serve_loop();
void hpfs_serve_loop();
int create_state_response(flatbuffers::FlatBufferBuilder &fbuf, const p2p::state_request &sr, std::string_view lcl);
int create_hpfs_response(flatbuffers::FlatBufferBuilder &fbuf, const p2p::hpfs_request &sr, std::string_view lcl);
int get_data_block(std::vector<uint8_t> &vec, const std::string_view vpath,
const uint32_t block_id, const util::h32 expected_hash);
@@ -24,6 +24,6 @@ namespace state_serve
int get_fs_entry_hashes(std::vector<hpfs::child_hash_node> &hash_nodes,
const std::string_view vpath, const util::h32 expected_hash);
} // namespace state_sync
} // namespace hpfs_sync
#endif

View File

@@ -8,10 +8,10 @@
#include "../util/util.hpp"
#include "../hpfs/hpfs.hpp"
#include "../util/h32.hpp"
#include "state_sync.hpp"
#include "state_common.hpp"
#include "hpfs_sync.hpp"
#include "../sc.hpp"
namespace state_sync
namespace hpfs_sync
{
// Idle loop sleep time (milliseconds).
constexpr uint16_t IDLE_WAIT = 40;
@@ -34,10 +34,14 @@ namespace state_sync
int init()
{
REQUEST_RESUBMIT_TIMEOUT = state_common::get_request_resubmit_timeout();
ctx.target_state = util::h32_empty;
ctx.state_sync_thread = std::thread(state_syncer_loop);
ctx.hpfs_mount_dir = conf::ctx.state_rw_dir;
REQUEST_RESUBMIT_TIMEOUT = hpfs::get_request_resubmit_timeout();
ctx.target_state_hash = util::h32_empty;
ctx.target_patch_hash = util::h32_empty;
ctx.current_parent_target_hash = util::h32_empty;
// Patch file sync has the highest priority.
ctx.current_syncing_parent = hpfs::HPFS_PARENT_COMPONENTS::PATCH;
ctx.hpfs_sync_thread = std::thread(hpfs_syncer_loop);
ctx.hpfs_mount_dir = conf::ctx.hpfs_rw_dir;
init_success = true;
return 0;
}
@@ -48,58 +52,72 @@ namespace state_sync
{
ctx.is_syncing = false;
ctx.is_shutting_down = true;
ctx.state_sync_thread.join();
ctx.hpfs_sync_thread.join();
}
}
/**
* Sets a new target state for the syncing process.
* @param target_state The target state which we should sync towards.
* @param completion_callback The callback function to call upon state sync completion.
* Sets a new target states for the syncing process.
* @param target_state_hash The target hpfs state which we should sync towards.
* @param target_patch_hash The target hpfs patch state which we should sync towards.
*/
void set_target(const util::h32 target_state)
void set_target(const util::h32 target_state_hash, const util::h32 target_patch_hash)
{
std::unique_lock lock(ctx.target_state_mutex);
// Do not do anything if we are already syncing towards the specified target state.
if (ctx.is_shutting_down || (ctx.is_syncing && ctx.target_state == target_state))
// Do not do anything if we are already syncing towards the specified target states.
if (ctx.is_shutting_down || (ctx.is_syncing && ctx.target_state_hash == target_state_hash && ctx.target_patch_hash == target_patch_hash))
return;
ctx.target_state = target_state;
ctx.target_state_hash = target_state_hash;
ctx.target_patch_hash = target_patch_hash;
if (hpfs::ctx.get_hash(hpfs::HPFS_PARENT_COMPONENTS::PATCH) != target_patch_hash)
{
ctx.current_syncing_parent = hpfs::HPFS_PARENT_COMPONENTS::PATCH;
ctx.current_parent_target_hash = ctx.target_patch_hash;
}
else
{
ctx.current_syncing_parent = hpfs::HPFS_PARENT_COMPONENTS::STATE;
ctx.current_parent_target_hash = ctx.target_state_hash;
}
ctx.is_syncing = true;
}
/**
* Runs the state sync worker loop.
* Runs the hpfs sync worker loop.
*/
void state_syncer_loop()
void hpfs_syncer_loop()
{
util::mask_signal();
LOG_INFO << "State sync: Worker started.";
LOG_INFO << "hpfs sync: Worker started.";
while (!ctx.is_shutting_down)
{
util::sleep(IDLE_WAIT);
// Keep idling if we are not doing any sync activity.
{
std::shared_lock lock(ctx.target_state_mutex);
if (!ctx.is_syncing)
continue;
LOG_INFO << "State sync: Starting sync for target state: " << ctx.target_state;
}
if (!ctx.is_syncing)
continue;
if (hpfs::start_fs_session(ctx.hpfs_mount_dir) != -1)
{
while (!ctx.is_shutting_down)
{
{
std::shared_lock lock(ctx.target_state_mutex);
if (ctx.current_syncing_parent == hpfs::HPFS_PARENT_COMPONENTS::PATCH)
LOG_INFO << "hpfs sync: Starting sync for target patch hash: " << ctx.target_patch_hash;
else
LOG_INFO << "hpfs sync: Starting sync for target state hash: " << ctx.target_state_hash;
}
util::h32 new_state = util::h32_empty;
const int result = request_loop(ctx.target_state, new_state);
const int result = request_loop(ctx.current_parent_target_hash, new_state);
ctx.pending_requests.clear();
ctx.candidate_state_responses.clear();
ctx.candidate_hpfs_responses.clear();
ctx.submitted_requests.clear();
if (result == -1 || ctx.is_shutting_down)
@@ -108,46 +126,74 @@ namespace state_sync
{
std::shared_lock lock(ctx.target_state_mutex);
if (new_state == ctx.target_state)
if (new_state == ctx.current_parent_target_hash)
{
LOG_INFO << "State sync: Target state achieved: " << new_state;
break;
if (ctx.current_syncing_parent == hpfs::HPFS_PARENT_COMPONENTS::PATCH)
{
ctx.target_patch_hash = util::h32_empty;
LOG_INFO << "hpfs sync: Target patch state achieved: " << new_state;
if (ctx.target_state_hash == hpfs::ctx.get_hash(hpfs::HPFS_PARENT_COMPONENTS::STATE))
break;
ctx.current_parent_target_hash = ctx.target_state_hash;
ctx.current_syncing_parent = hpfs::HPFS_PARENT_COMPONENTS::STATE;
continue;
}
else if (ctx.current_syncing_parent == hpfs::HPFS_PARENT_COMPONENTS::STATE)
{
ctx.target_state_hash = util::h32_empty;
LOG_INFO << "hpfs sync: Target state achieved: " << new_state;
break;
}
}
else
{
LOG_INFO << "State sync: Continuing sync for new target: " << ctx.target_state;
LOG_INFO << "hpfs sync: Continuing sync for new target: " << ctx.current_parent_target_hash;
continue;
}
}
}
LOG_INFO << "hpfs sync: All parents synced.";
hpfs::stop_fs_session(ctx.hpfs_mount_dir);
}
else
{
LOG_ERROR << "State sync: Failed to start hpfs rw session";
LOG_ERROR << "hpfs sync: Failed to start hpfs rw session";
}
std::unique_lock lock(ctx.target_state_mutex);
ctx.target_state = util::h32_empty;
ctx.current_parent_target_hash = util::h32_empty;
ctx.is_syncing = false;
}
LOG_INFO << "State sync: Worker stopped.";
LOG_INFO << "hpfs sync: Worker stopped.";
}
int request_loop(const util::h32 current_target, util::h32 &updated_state)
{
std::string target_parent_vpath;
BACKLOG_ITEM_TYPE target_parent_backlog_item_type;
if (ctx.current_syncing_parent == hpfs::HPFS_PARENT_COMPONENTS::STATE)
{
target_parent_vpath = sc::STATE_DIR_PATH;
target_parent_backlog_item_type = BACKLOG_ITEM_TYPE::DIR;
}
else if (ctx.current_syncing_parent == hpfs::HPFS_PARENT_COMPONENTS::PATCH)
{
target_parent_vpath = conf::PATCH_FILE_PATH;
target_parent_backlog_item_type = BACKLOG_ITEM_TYPE::FILE;
}
std::string lcl = ledger::ctx.get_lcl();
// Indicates whether any responses were processed in the previous loop iteration.
bool prev_responses_processed = false;
// No. of repetitive resubmissions so far. (This is reset whenever we receive a state response)
// No. of repetitive resubmissions so far. (This is reset whenever we receive a hpfs response)
uint16_t resubmissions_count = 0;
// Send the initial root state request.
submit_request(backlog_item{BACKLOG_ITEM_TYPE::DIR, "/", -1, current_target}, lcl);
// Send the initial root hpfs request.
submit_request(backlog_item{target_parent_backlog_item_type, target_parent_vpath, -1, current_target}, lcl);
while (!should_stop_request_loop(current_target))
{
@@ -159,28 +205,28 @@ namespace state_sync
std::string lcl = ledger::ctx.get_lcl();
{
std::scoped_lock lock(p2p::ctx.collected_msgs.state_responses_mutex);
std::scoped_lock lock(p2p::ctx.collected_msgs.hpfs_responses_mutex);
// Move collected state responses over to local candidate responses list.
if (!p2p::ctx.collected_msgs.state_responses.empty())
ctx.candidate_state_responses.splice(ctx.candidate_state_responses.end(), p2p::ctx.collected_msgs.state_responses);
// Move collected hpfs responses over to local candidate responses list.
if (!p2p::ctx.collected_msgs.hpfs_responses.empty())
ctx.candidate_hpfs_responses.splice(ctx.candidate_hpfs_responses.end(), p2p::ctx.collected_msgs.hpfs_responses);
}
prev_responses_processed = !ctx.candidate_state_responses.empty();
prev_responses_processed = !ctx.candidate_hpfs_responses.empty();
// Reset resubmissions counter whenever we have a resposne.
if (!ctx.candidate_state_responses.empty())
if (!ctx.candidate_hpfs_responses.empty())
resubmissions_count = 0;
for (auto &response : ctx.candidate_state_responses)
for (auto &response : ctx.candidate_hpfs_responses)
{
if (should_stop_request_loop(current_target))
return 0;
LOG_DEBUG << "State sync: Processing state response from [" << response.first.substr(2, 10) << "]";
LOG_DEBUG << "hpfs sync: Processing hpfs response from [" << response.first.substr(2, 10) << "]";
const msg::fbuf::p2pmsg::Content *content = msg::fbuf::p2pmsg::GetContent(response.second.data());
const msg::fbuf::p2pmsg::State_Response_Message *resp_msg = content->message_as_State_Response_Message();
const msg::fbuf::p2pmsg::Hpfs_Response_Message *resp_msg = content->message_as_Hpfs_Response_Message();
// Check whether we are actually waiting for this response. If not, ignore it.
std::string_view hash = msg::fbuf::flatbuff_bytes_to_sv(resp_msg->hash());
@@ -190,33 +236,33 @@ namespace state_sync
const auto pending_resp_itr = ctx.submitted_requests.find(key);
if (pending_resp_itr == ctx.submitted_requests.end())
{
LOG_DEBUG << "State sync: Skipping state response due to hash mismatch.";
LOG_DEBUG << "hpfs sync: Skipping hpfs response due to hash mismatch.";
continue;
}
// Process the message based on response type.
const msg::fbuf::p2pmsg::State_Response msg_type = resp_msg->state_response_type();
const msg::fbuf::p2pmsg::Hpfs_Response msg_type = resp_msg->hpfs_response_type();
if (msg_type == msg::fbuf::p2pmsg::State_Response_Fs_Entry_Response)
if (msg_type == msg::fbuf::p2pmsg::Hpfs_Response_Fs_Entry_Response)
{
const msg::fbuf::p2pmsg::Fs_Entry_Response *fs_resp = resp_msg->state_response_as_Fs_Entry_Response();
const msg::fbuf::p2pmsg::Fs_Entry_Response *fs_resp = resp_msg->hpfs_response_as_Fs_Entry_Response();
// Get fs entries we have received.
std::unordered_map<std::string, p2p::state_fs_hash_entry> peer_fs_entry_map;
msg::fbuf::p2pmsg::flatbuf_statefshashentry_to_statefshashentry(peer_fs_entry_map, fs_resp->entries());
std::unordered_map<std::string, p2p::hpfs_fs_hash_entry> peer_fs_entry_map;
msg::fbuf::p2pmsg::flatbuf_hpfsfshashentry_to_hpfsfshashentry(peer_fs_entry_map, fs_resp->entries());
// Validate received fs data against the hash.
if (!validate_fs_entry_hash(vpath, hash, peer_fs_entry_map))
{
LOG_INFO << "State sync: Skipping state response due to fs entry hash mismatch.";
LOG_INFO << "hpfs sync: Skipping hpfs response due to fs entry hash mismatch.";
continue;
}
handle_fs_entry_response(vpath, peer_fs_entry_map);
}
else if (msg_type == msg::fbuf::p2pmsg::State_Response_File_HashMap_Response)
else if (msg_type == msg::fbuf::p2pmsg::Hpfs_Response_File_HashMap_Response)
{
const msg::fbuf::p2pmsg::File_HashMap_Response *file_resp = resp_msg->state_response_as_File_HashMap_Response();
const msg::fbuf::p2pmsg::File_HashMap_Response *file_resp = resp_msg->hpfs_response_as_File_HashMap_Response();
// File block hashes we received from the peer.
const util::h32 *peer_hashes = reinterpret_cast<const util::h32 *>(file_resp->hash_map()->data());
@@ -225,15 +271,15 @@ namespace state_sync
// Validate received hashmap against the hash.
if (!validate_file_hashmap_hash(vpath, hash, peer_hashes, peer_hash_count))
{
LOG_INFO << "State sync: Skipping state response due to file hashmap hash mismatch.";
LOG_INFO << "hpfs sync: Skipping hpfs response due to file hashmap hash mismatch.";
continue;
}
handle_file_hashmap_response(vpath, peer_hashes, peer_hash_count, file_resp->file_length());
}
else if (msg_type == msg::fbuf::p2pmsg::State_Response_Block_Response)
else if (msg_type == msg::fbuf::p2pmsg::Hpfs_Response_Block_Response)
{
const msg::fbuf::p2pmsg::Block_Response *block_resp = resp_msg->state_response_as_Block_Response();
const msg::fbuf::p2pmsg::Block_Response *block_resp = resp_msg->hpfs_response_as_Block_Response();
// Get the file path of the block data we have received.
const uint32_t block_id = block_resp->block_id();
@@ -242,7 +288,7 @@ namespace state_sync
// Validate received block data against the hash.
if (!validate_file_block_hash(hash, block_id, buf))
{
LOG_INFO << "State sync: Skipping state response due to file block hash mismatch.";
LOG_INFO << "hpfs sync: Skipping hpfs response due to file block hash mismatch.";
continue;
}
@@ -252,22 +298,23 @@ namespace state_sync
// Now that we have received matching hash and handled it, remove it from the waiting list.
ctx.submitted_requests.erase(pending_resp_itr);
// After handling each response, check whether we have reached target state.
if (hpfs::get_hash(updated_state, ctx.hpfs_mount_dir, "/") < 1)
// After handling each response, check whether we have reached target hpfs state.
// get_hash returns 0 incase target parent is not existing in our side.
if (hpfs::get_hash(updated_state, ctx.hpfs_mount_dir, target_parent_vpath) == -1)
{
LOG_ERROR << "State sync: exiting due to hash check error.";
LOG_ERROR << "hpfs sync: exiting due to hash check error.";
return -1;
}
// Update the central state tracker.
state_common::ctx.set_state(updated_state);
// Update the central hpfs state tracker.
hpfs::ctx.set_hash(ctx.current_syncing_parent, updated_state);
LOG_DEBUG << "State sync: current:" << updated_state << " | target:" << current_target;
LOG_DEBUG << "hpfs sync: current:" << updated_state << " | target:" << current_target;
if (updated_state == current_target)
return 0;
}
ctx.candidate_state_responses.clear();
ctx.candidate_hpfs_responses.clear();
// Check for long-awaited responses and re-request them.
for (auto &[hash, request] : ctx.submitted_requests)
@@ -284,13 +331,13 @@ namespace state_sync
{
if (++resubmissions_count > ABANDON_THRESHOLD)
{
LOG_INFO << "State sync: Resubmission threshold exceeded. Abandoning sync.";
LOG_INFO << "hpfs sync: Resubmission threshold exceeded. Abandoning sync.";
return -1;
}
// Reset the counter and re-submit request.
request.waiting_time = 0;
LOG_DEBUG << "State sync: Resubmitting request...";
LOG_DEBUG << "hpfs sync: Resubmitting request...";
submit_request(request, lcl);
}
}
@@ -321,12 +368,14 @@ namespace state_sync
* @param fs_entry_map Received fs entry map.
* @returns true if hash is valid, otherwise false.
*/
bool validate_fs_entry_hash(std::string_view vpath, std::string_view hash, const std::unordered_map<std::string, p2p::state_fs_hash_entry> &fs_entry_map)
bool validate_fs_entry_hash(std::string_view vpath, std::string_view hash, const std::unordered_map<std::string, p2p::hpfs_fs_hash_entry> &fs_entry_map)
{
util::h32 content_hash;
const std::string vpath_name = util::get_name(vpath);
// Initilal hash is vpath hash.
content_hash = crypto::get_hash(vpath);
content_hash = crypto::get_hash(vpath_name);
// Then XOR the file hashes to the initial hash.
for (const auto &[name, fs_entry] : fs_entry_map)
@@ -349,8 +398,10 @@ namespace state_sync
{
util::h32 content_hash = util::h32_empty;
const std::string vpath_name = util::get_name(vpath);
// Initilal hash is vpath hash.
content_hash = crypto::get_hash(vpath);
content_hash = crypto::get_hash(vpath_name);
// Then XOR the block hashes to the initial hash.
for (int32_t block_id = 0; block_id < hash_count; block_id++)
@@ -377,7 +428,7 @@ namespace state_sync
}
/**
* Indicates whether to break out of state request processing loop.
* Indicates whether to break out of hpfs request processing loop.
*/
bool should_stop_request_loop(const util::h32 current_target)
{
@@ -386,11 +437,11 @@ namespace state_sync
// Stop request loop if the target has changed.
std::shared_lock lock(ctx.target_state_mutex);
return current_target != ctx.target_state;
return current_target != ctx.current_parent_target_hash;
}
/**
* Sends a state request to a random peer.
* Sends a hpfs request to a random peer.
* @param path Requested file or dir path.
* @param is_file Whether the requested path if a file or dir.
* @param block_id The requested block id. Only relevant if requesting a file block. Otherwise -1.
@@ -400,19 +451,19 @@ namespace state_sync
void request_state_from_peer(const std::string &path, const bool is_file, const int32_t block_id,
const util::h32 expected_hash, std::string_view lcl, std::string &target_pubkey)
{
p2p::state_request sr;
sr.parent_path = path;
sr.is_file = is_file;
sr.block_id = block_id;
sr.expected_hash = expected_hash;
p2p::hpfs_request hr;
hr.parent_path = path;
hr.is_file = is_file;
hr.block_id = block_id;
hr.expected_hash = expected_hash;
flatbuffers::FlatBufferBuilder fbuf(1024);
msg::fbuf::p2pmsg::create_msg_from_state_request(fbuf, sr, lcl);
p2p::send_message_to_random_peer(fbuf, target_pubkey); //todo: send to a node that hold the majority state to improve reliability of retrieving state.
msg::fbuf::p2pmsg::create_msg_from_state_request(fbuf, hr, lcl);
p2p::send_message_to_random_peer(fbuf, target_pubkey); //todo: send to a node that hold the majority hpfs state to improve reliability of retrieving hpfs state.
}
/**
* Submits a pending state request to the peer.
* Submits a pending hpfs request to the peer.
*/
void submit_request(const backlog_item &request, std::string_view lcl)
{
@@ -425,7 +476,7 @@ namespace state_sync
request_state_from_peer(request.path, is_file, request.block_id, request.expected_hash, lcl, target_pubkey);
if (!target_pubkey.empty())
LOG_DEBUG << "State sync: Requesting from [" << target_pubkey.substr(2, 10) << "]. type:" << request.type
LOG_DEBUG << "hpfs sync: Requesting from [" << target_pubkey.substr(2, 10) << "]. type:" << request.type
<< " path:" << request.path << " block_id:" << request.block_id
<< " hash:" << request.expected_hash;
}
@@ -436,10 +487,10 @@ namespace state_sync
* @param fs_entry_map Received fs entry map.
* @returns 0 on success, otherwise -1.
*/
int handle_fs_entry_response(std::string_view vpath, std::unordered_map<std::string, p2p::state_fs_hash_entry> &fs_entry_map)
int handle_fs_entry_response(std::string_view vpath, std::unordered_map<std::string, p2p::hpfs_fs_hash_entry> &fs_entry_map)
{
// Get the parent path of the fs entries we have received.
LOG_DEBUG << "State sync: Processing fs entries response for " << vpath;
LOG_DEBUG << "hpfs sync: Processing fs entries response for " << vpath;
// Create physical directory on our side if not exist.
std::string parent_physical_path = std::string(ctx.hpfs_mount_dir).append(vpath);
@@ -462,10 +513,10 @@ namespace state_sync
const auto peer_itr = fs_entry_map.find(ex_entry.name);
if (peer_itr != fs_entry_map.end())
{
// Request state if hash is different.
// Request hpfs state if hash is different.
if (peer_itr->second.hash != ex_entry.hash)
{
// Prioritize file state requests over directories.
// Prioritize file hpfs requests over directories.
if (ex_entry.is_file)
ctx.pending_requests.push_front(backlog_item{BACKLOG_ITEM_TYPE::FILE, child_vpath, -1, peer_itr->second.hash});
else
@@ -483,7 +534,7 @@ namespace state_sync
!ex_entry.is_file && util::remove_directory_recursively(child_physical_path.c_str()) == -1)
return -1;
LOG_DEBUG << "State sync: Deleted " << (ex_entry.is_file ? "file" : "dir") << " path " << child_vpath;
LOG_DEBUG << "hpfs sync: Deleted " << (ex_entry.is_file ? "file" : "dir") << " path " << child_vpath;
}
}
@@ -495,7 +546,7 @@ namespace state_sync
.append(vpath.back() != '/' ? "/" : "")
.append(name);
// Prioritize file state requests over directories.
// Prioritize file hpfs requests over directories.
if (fs_entry.is_file)
ctx.pending_requests.push_front(backlog_item{BACKLOG_ITEM_TYPE::FILE, child_vpath, -1, fs_entry.hash});
else
@@ -516,7 +567,7 @@ namespace state_sync
int handle_file_hashmap_response(std::string_view vpath, const util::h32 *hashes, const size_t hash_count, const uint64_t file_length)
{
// Get the file path of the block hashes we have received.
LOG_DEBUG << "State sync: Processing file block hashes response for " << vpath;
LOG_DEBUG << "hpfs sync: Processing file block hashes response for " << vpath;
// File block hashes on our side (file might not exist on our side).
std::vector<util::h32> existing_hashes;
@@ -554,7 +605,7 @@ namespace state_sync
*/
int handle_file_block_response(std::string_view vpath, const uint32_t block_id, std::string_view buf)
{
LOG_DEBUG << "State sync: Writing block_id " << block_id
LOG_DEBUG << "hpfs sync: Writing block_id " << block_id
<< " (len:" << buf.length()
<< ") of " << vpath;
@@ -566,7 +617,7 @@ namespace state_sync
return -1;
}
const off_t offset = block_id * state_common::BLOCK_SIZE;
const off_t offset = block_id * hpfs::BLOCK_SIZE;
const int res = pwrite(fd, buf.data(), buf.length(), offset);
close(fd);
if (res < buf.length())
@@ -578,4 +629,4 @@ namespace state_sync
return 0;
}
} // namespace state_sync
} // namespace hpfs_sync

View File

@@ -1,5 +1,5 @@
#ifndef _HP_STATE_STATE_SYNC_
#define _HP_STATE_STATE_SYNC_
#ifndef _HP_HPFS_HPFS_SYNC_
#define _HP_HPFS_HPFS_SYNC_
#include "../pchheader.hpp"
#include "../p2p/p2p.hpp"
@@ -7,7 +7,7 @@
#include "../util/h32.hpp"
#include "../crypto.hpp"
namespace state_sync
namespace hpfs_sync
{
enum BACKLOG_ITEM_TYPE
@@ -32,11 +32,15 @@ namespace state_sync
struct sync_context
{
// The current target state we are syncing towards.
util::h32 target_state;
// The current target hashes we are syncing towards.
util::h32 target_state_hash;
util::h32 target_patch_hash;
util::h32 current_parent_target_hash;
// List of sender pubkeys and state responses(flatbuffer messages) to be processed.
std::list<std::pair<std::string, std::string>> candidate_state_responses;
hpfs::HPFS_PARENT_COMPONENTS current_syncing_parent;
// List of sender pubkeys and hpfs responses(flatbuffer messages) to be processed.
std::list<std::pair<std::string, std::string>> candidate_hpfs_responses;
// List of pending sync requests to be sent out.
std::list<backlog_item> pending_requests;
@@ -44,7 +48,7 @@ namespace state_sync
// List of submitted requests we are awaiting responses for, keyed by expected response path+hash.
std::unordered_map<std::string, backlog_item> submitted_requests;
std::thread state_sync_thread;
std::thread hpfs_sync_thread;
std::shared_mutex target_state_mutex;
std::atomic<bool> is_syncing = false;
std::atomic<bool> is_shutting_down = false;
@@ -53,19 +57,17 @@ namespace state_sync
extern sync_context ctx;
extern std::list<std::string> candidate_state_responses;
int init();
void deinit();
void set_target(const util::h32 target_state);
void set_target(const util::h32 target_state_hash, const util::h32 target_patch_hash);
void state_syncer_loop();
void hpfs_syncer_loop();
int request_loop(const util::h32 current_target, util::h32 &updated_state);
bool validate_fs_entry_hash(std::string_view vpath, std::string_view hash, const std::unordered_map<std::string, p2p::state_fs_hash_entry> &fs_entry_map);
bool validate_fs_entry_hash(std::string_view vpath, std::string_view hash, const std::unordered_map<std::string, p2p::hpfs_fs_hash_entry> &fs_entry_map);
bool validate_file_hashmap_hash(std::string_view vpath, std::string_view hash, const util::h32 *hashes, const size_t hash_count);
@@ -78,12 +80,12 @@ namespace state_sync
void submit_request(const backlog_item &request, std::string_view lcl);
int handle_fs_entry_response(std::string_view vpath, std::unordered_map<std::string, p2p::state_fs_hash_entry> &fs_entry_map);
int handle_fs_entry_response(std::string_view vpath, std::unordered_map<std::string, p2p::hpfs_fs_hash_entry> &fs_entry_map);
int handle_file_hashmap_response(std::string_view vpath, const util::h32 *hashes, const size_t hash_count, const uint64_t file_length);
int handle_file_block_response(std::string_view vpath, const uint32_t block_id, std::string_view buf);
} // namespace state_sync
} // namespace hpfs_sync
#endif

View File

@@ -14,9 +14,8 @@
#include "consensus.hpp"
#include "ledger.hpp"
#include "hpfs/hpfs.hpp"
#include "state/state_common.hpp"
#include "state/state_sync.hpp"
#include "state/state_serve.hpp"
#include "hpfs/hpfs_sync.hpp"
#include "hpfs/hpfs_serve.hpp"
#include "unl.hpp"
/**
@@ -74,9 +73,9 @@ void deinit()
p2p::deinit();
read_req::deinit();
consensus::deinit();
state_sync::deinit();
state_serve::deinit();
sc::deinit();
hpfs_sync::deinit();
hpfs_serve::deinit();
hpfs::deinit();
unl::deinit();
ledger::deinit();
conf::deinit();
@@ -203,10 +202,9 @@ int main(int argc, char **argv)
if (ledger::init() == -1 ||
unl::init() == -1 ||
sc::init() == -1 ||
state_common::init() == -1 ||
state_serve::init() == -1 ||
state_sync::init() == -1 ||
hpfs::init() == -1 ||
hpfs_serve::init() == -1 ||
hpfs_sync::init() == -1 ||
consensus::init() == -1 ||
read_req::init() == -1 ||
p2p::init() == -1 ||

View File

@@ -25,7 +25,8 @@ namespace msg::fbuf::ledger
seq_no,
p.time,
sv_to_flatbuff_bytes(builder, p.lcl),
hash_to_flatbuff_bytes(builder, p.state),
hash_to_flatbuff_bytes(builder, p.state_hash),
hash_to_flatbuff_bytes(builder, p.patch_hash),
sv_to_flatbuff_bytes(builder, p.unl_hash),
stringlist_to_flatbuf_bytearrayvector(builder, p.users),
stringlist_to_flatbuf_bytearrayvector(builder, p.input_hashes),
@@ -40,7 +41,8 @@ namespace msg::fbuf::ledger
auto ledger = msg::fbuf::ledger::GetLedgerBlock(ledger_buf.data());
p2p::proposal p;
p.lcl = flatbuff_bytes_to_sv(ledger->lcl());
p.state = flatbuff_bytes_to_hash(ledger->state());
p.state_hash = flatbuff_bytes_to_hash(ledger->state_hash());
p.patch_hash = flatbuff_bytes_to_hash(ledger->patch_hash());
// We do not need to convert all the fields of the proposal due to them not being used for any ledger-specific logic.
return p;
}

View File

@@ -7,7 +7,8 @@ table LedgerBlock {
seq_no:uint64;
time:uint64;
lcl:[ubyte];
state:[ubyte];
state_hash:[ubyte];
patch_hash:[ubyte];
unl:[ubyte];
users: [ByteArray];
inputs: [ByteArray];

View File

@@ -25,12 +25,13 @@ struct LedgerBlock FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
VT_SEQ_NO = 6,
VT_TIME = 8,
VT_LCL = 10,
VT_STATE = 12,
VT_UNL = 14,
VT_USERS = 16,
VT_INPUTS = 18,
VT_OUTPUT = 20,
VT_UNL_CHANGESET = 22
VT_STATE_HASH = 12,
VT_PATCH_HASH = 14,
VT_UNL = 16,
VT_USERS = 18,
VT_INPUTS = 20,
VT_OUTPUT = 22,
VT_UNL_CHANGESET = 24
};
const flatbuffers::String *version() const {
return GetPointer<const flatbuffers::String *>(VT_VERSION);
@@ -56,11 +57,17 @@ struct LedgerBlock FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
flatbuffers::Vector<uint8_t> *mutable_lcl() {
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_LCL);
}
const flatbuffers::Vector<uint8_t> *state() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_STATE);
const flatbuffers::Vector<uint8_t> *state_hash() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_STATE_HASH);
}
flatbuffers::Vector<uint8_t> *mutable_state() {
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_STATE);
flatbuffers::Vector<uint8_t> *mutable_state_hash() {
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_STATE_HASH);
}
const flatbuffers::Vector<uint8_t> *patch_hash() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_PATCH_HASH);
}
flatbuffers::Vector<uint8_t> *mutable_patch_hash() {
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_PATCH_HASH);
}
const flatbuffers::Vector<uint8_t> *unl() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_UNL);
@@ -100,8 +107,10 @@ struct LedgerBlock FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
VerifyField<uint64_t>(verifier, VT_TIME) &&
VerifyOffset(verifier, VT_LCL) &&
verifier.VerifyVector(lcl()) &&
VerifyOffset(verifier, VT_STATE) &&
verifier.VerifyVector(state()) &&
VerifyOffset(verifier, VT_STATE_HASH) &&
verifier.VerifyVector(state_hash()) &&
VerifyOffset(verifier, VT_PATCH_HASH) &&
verifier.VerifyVector(patch_hash()) &&
VerifyOffset(verifier, VT_UNL) &&
verifier.VerifyVector(unl()) &&
VerifyOffset(verifier, VT_USERS) &&
@@ -134,8 +143,11 @@ struct LedgerBlockBuilder {
void add_lcl(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> lcl) {
fbb_.AddOffset(LedgerBlock::VT_LCL, lcl);
}
void add_state(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> state) {
fbb_.AddOffset(LedgerBlock::VT_STATE, state);
void add_state_hash(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> state_hash) {
fbb_.AddOffset(LedgerBlock::VT_STATE_HASH, state_hash);
}
void add_patch_hash(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> patch_hash) {
fbb_.AddOffset(LedgerBlock::VT_PATCH_HASH, patch_hash);
}
void add_unl(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> unl) {
fbb_.AddOffset(LedgerBlock::VT_UNL, unl);
@@ -156,7 +168,6 @@ struct LedgerBlockBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
LedgerBlockBuilder &operator=(const LedgerBlockBuilder &);
flatbuffers::Offset<LedgerBlock> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<LedgerBlock>(end);
@@ -170,7 +181,8 @@ inline flatbuffers::Offset<LedgerBlock> CreateLedgerBlock(
uint64_t seq_no = 0,
uint64_t time = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> lcl = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> state = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> state_hash = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> patch_hash = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> unl = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> users = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> inputs = 0,
@@ -184,7 +196,8 @@ inline flatbuffers::Offset<LedgerBlock> CreateLedgerBlock(
builder_.add_inputs(inputs);
builder_.add_users(users);
builder_.add_unl(unl);
builder_.add_state(state);
builder_.add_patch_hash(patch_hash);
builder_.add_state_hash(state_hash);
builder_.add_lcl(lcl);
builder_.add_version(version);
return builder_.Finish();
@@ -196,7 +209,8 @@ inline flatbuffers::Offset<LedgerBlock> CreateLedgerBlockDirect(
uint64_t seq_no = 0,
uint64_t time = 0,
const std::vector<uint8_t> *lcl = nullptr,
const std::vector<uint8_t> *state = nullptr,
const std::vector<uint8_t> *state_hash = nullptr,
const std::vector<uint8_t> *patch_hash = nullptr,
const std::vector<uint8_t> *unl = nullptr,
const std::vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *users = nullptr,
const std::vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *inputs = nullptr,
@@ -204,7 +218,8 @@ inline flatbuffers::Offset<LedgerBlock> CreateLedgerBlockDirect(
flatbuffers::Offset<msg::fbuf::ledger::Unl_Changeset> unl_changeset = 0) {
auto version__ = version ? _fbb.CreateString(version) : 0;
auto lcl__ = lcl ? _fbb.CreateVector<uint8_t>(*lcl) : 0;
auto state__ = state ? _fbb.CreateVector<uint8_t>(*state) : 0;
auto state_hash__ = state_hash ? _fbb.CreateVector<uint8_t>(*state_hash) : 0;
auto patch_hash__ = patch_hash ? _fbb.CreateVector<uint8_t>(*patch_hash) : 0;
auto unl__ = unl ? _fbb.CreateVector<uint8_t>(*unl) : 0;
auto users__ = users ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::ByteArray>>(*users) : 0;
auto inputs__ = inputs ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::ByteArray>>(*inputs) : 0;
@@ -215,7 +230,8 @@ inline flatbuffers::Offset<LedgerBlock> CreateLedgerBlockDirect(
seq_no,
time,
lcl__,
state__,
state_hash__,
patch_hash__,
unl__,
users__,
inputs__,
@@ -267,7 +283,6 @@ struct Unl_ChangesetBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Unl_ChangesetBuilder &operator=(const Unl_ChangesetBuilder &);
flatbuffers::Offset<Unl_Changeset> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Unl_Changeset>(end);

View File

@@ -31,8 +31,8 @@ union Message {
NonUnl_Proposal_Message,
Proposal_Message,
Npl_Message,
State_Request_Message,
State_Response_Message,
Hpfs_Request_Message,
Hpfs_Response_Message,
History_Request_Message,
History_Response_Message,
Peer_Requirement_Announcement_Message,
@@ -64,7 +64,8 @@ table Proposal_Message { //Proposal type message schema
input_hashes:[ByteArray];
output_hash:[ubyte];
output_sig:[ubyte];
state: [ubyte];
state_hash: [ubyte];
patch_hash: [ubyte];
unl_hash: [ubyte]; // Hash of the current unl list.
unl_changeset: Unl_Changeset;
}
@@ -109,23 +110,23 @@ table HistoryLedgerBlock {
block_buffer:[ubyte];
}
table State_Request_Message { //State request message schema
table Hpfs_Request_Message { //Hpfs request message schema
parent_path:string;
is_file:bool;
block_id:int32;
expected_hash:[ubyte];
}
union State_Response{ File_HashMap_Response, Block_Response, Fs_Entry_Response }
union Hpfs_Response{ File_HashMap_Response, Block_Response, Fs_Entry_Response }
table State_Response_Message{
state_response:State_Response;
table Hpfs_Response_Message{
hpfs_response:Hpfs_Response;
hash:[ubyte];
path: string;
}
table Fs_Entry_Response{
entries: [State_FS_Hash_Entry];
entries: [Hpfs_FS_Hash_Entry];
}
table File_HashMap_Response{
@@ -138,7 +139,7 @@ table Block_Response{
data: [ubyte];
}
table State_FS_Hash_Entry{
table Hpfs_FS_Hash_Entry{
name: string;
is_file: bool;
hash: [ubyte];

View File

@@ -57,11 +57,11 @@ struct HistoryLedgerBlockPairBuilder;
struct HistoryLedgerBlock;
struct HistoryLedgerBlockBuilder;
struct State_Request_Message;
struct State_Request_MessageBuilder;
struct Hpfs_Request_Message;
struct Hpfs_Request_MessageBuilder;
struct State_Response_Message;
struct State_Response_MessageBuilder;
struct Hpfs_Response_Message;
struct Hpfs_Response_MessageBuilder;
struct Fs_Entry_Response;
struct Fs_Entry_ResponseBuilder;
@@ -72,8 +72,8 @@ struct File_HashMap_ResponseBuilder;
struct Block_Response;
struct Block_ResponseBuilder;
struct State_FS_Hash_Entry;
struct State_FS_Hash_EntryBuilder;
struct Hpfs_FS_Hash_Entry;
struct Hpfs_FS_Hash_EntryBuilder;
struct Peer_Requirement_Announcement_Message;
struct Peer_Requirement_Announcement_MessageBuilder;
@@ -90,15 +90,15 @@ struct Peer_List_Response_MessageBuilder;
struct Peer_Properties;
struct Peer_PropertiesBuilder;
enum Message {
enum Message : uint8_t {
Message_NONE = 0,
Message_Peer_Challenge_Response_Message = 1,
Message_Peer_Challenge_Message = 2,
Message_NonUnl_Proposal_Message = 3,
Message_Proposal_Message = 4,
Message_Npl_Message = 5,
Message_State_Request_Message = 6,
Message_State_Response_Message = 7,
Message_Hpfs_Request_Message = 6,
Message_Hpfs_Response_Message = 7,
Message_History_Request_Message = 8,
Message_History_Response_Message = 9,
Message_Peer_Requirement_Announcement_Message = 10,
@@ -119,8 +119,8 @@ inline const Message (&EnumValuesMessage())[16] {
Message_NonUnl_Proposal_Message,
Message_Proposal_Message,
Message_Npl_Message,
Message_State_Request_Message,
Message_State_Response_Message,
Message_Hpfs_Request_Message,
Message_Hpfs_Response_Message,
Message_History_Request_Message,
Message_History_Response_Message,
Message_Peer_Requirement_Announcement_Message,
@@ -141,8 +141,8 @@ inline const char * const *EnumNamesMessage() {
"NonUnl_Proposal_Message",
"Proposal_Message",
"Npl_Message",
"State_Request_Message",
"State_Response_Message",
"Hpfs_Request_Message",
"Hpfs_Response_Message",
"History_Request_Message",
"History_Response_Message",
"Peer_Requirement_Announcement_Message",
@@ -186,12 +186,12 @@ template<> struct MessageTraits<msg::fbuf::p2pmsg::Npl_Message> {
static const Message enum_value = Message_Npl_Message;
};
template<> struct MessageTraits<msg::fbuf::p2pmsg::State_Request_Message> {
static const Message enum_value = Message_State_Request_Message;
template<> struct MessageTraits<msg::fbuf::p2pmsg::Hpfs_Request_Message> {
static const Message enum_value = Message_Hpfs_Request_Message;
};
template<> struct MessageTraits<msg::fbuf::p2pmsg::State_Response_Message> {
static const Message enum_value = Message_State_Response_Message;
template<> struct MessageTraits<msg::fbuf::p2pmsg::Hpfs_Response_Message> {
static const Message enum_value = Message_Hpfs_Response_Message;
};
template<> struct MessageTraits<msg::fbuf::p2pmsg::History_Request_Message> {
@@ -229,7 +229,7 @@ template<> struct MessageTraits<msg::fbuf::p2pmsg::Unl_Response_Message> {
bool VerifyMessage(flatbuffers::Verifier &verifier, const void *obj, Message type);
bool VerifyMessageVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types);
enum Ledger_Response_Error {
enum Ledger_Response_Error : uint8_t {
Ledger_Response_Error_None = 0,
Ledger_Response_Error_Invalid_Min_Ledger = 1,
Ledger_Response_Error_Req_Ledger_Not_Found = 2,
@@ -262,26 +262,26 @@ inline const char *EnumNameLedger_Response_Error(Ledger_Response_Error e) {
return EnumNamesLedger_Response_Error()[index];
}
enum State_Response {
State_Response_NONE = 0,
State_Response_File_HashMap_Response = 1,
State_Response_Block_Response = 2,
State_Response_Fs_Entry_Response = 3,
State_Response_MIN = State_Response_NONE,
State_Response_MAX = State_Response_Fs_Entry_Response
enum Hpfs_Response : uint8_t {
Hpfs_Response_NONE = 0,
Hpfs_Response_File_HashMap_Response = 1,
Hpfs_Response_Block_Response = 2,
Hpfs_Response_Fs_Entry_Response = 3,
Hpfs_Response_MIN = Hpfs_Response_NONE,
Hpfs_Response_MAX = Hpfs_Response_Fs_Entry_Response
};
inline const State_Response (&EnumValuesState_Response())[4] {
static const State_Response values[] = {
State_Response_NONE,
State_Response_File_HashMap_Response,
State_Response_Block_Response,
State_Response_Fs_Entry_Response
inline const Hpfs_Response (&EnumValuesHpfs_Response())[4] {
static const Hpfs_Response values[] = {
Hpfs_Response_NONE,
Hpfs_Response_File_HashMap_Response,
Hpfs_Response_Block_Response,
Hpfs_Response_Fs_Entry_Response
};
return values;
}
inline const char * const *EnumNamesState_Response() {
inline const char * const *EnumNamesHpfs_Response() {
static const char * const names[5] = {
"NONE",
"File_HashMap_Response",
@@ -292,30 +292,30 @@ inline const char * const *EnumNamesState_Response() {
return names;
}
inline const char *EnumNameState_Response(State_Response e) {
if (flatbuffers::IsOutRange(e, State_Response_NONE, State_Response_Fs_Entry_Response)) return "";
inline const char *EnumNameHpfs_Response(Hpfs_Response e) {
if (flatbuffers::IsOutRange(e, Hpfs_Response_NONE, Hpfs_Response_Fs_Entry_Response)) return "";
const size_t index = static_cast<size_t>(e);
return EnumNamesState_Response()[index];
return EnumNamesHpfs_Response()[index];
}
template<typename T> struct State_ResponseTraits {
static const State_Response enum_value = State_Response_NONE;
template<typename T> struct Hpfs_ResponseTraits {
static const Hpfs_Response enum_value = Hpfs_Response_NONE;
};
template<> struct State_ResponseTraits<msg::fbuf::p2pmsg::File_HashMap_Response> {
static const State_Response enum_value = State_Response_File_HashMap_Response;
template<> struct Hpfs_ResponseTraits<msg::fbuf::p2pmsg::File_HashMap_Response> {
static const Hpfs_Response enum_value = Hpfs_Response_File_HashMap_Response;
};
template<> struct State_ResponseTraits<msg::fbuf::p2pmsg::Block_Response> {
static const State_Response enum_value = State_Response_Block_Response;
template<> struct Hpfs_ResponseTraits<msg::fbuf::p2pmsg::Block_Response> {
static const Hpfs_Response enum_value = Hpfs_Response_Block_Response;
};
template<> struct State_ResponseTraits<msg::fbuf::p2pmsg::Fs_Entry_Response> {
static const State_Response enum_value = State_Response_Fs_Entry_Response;
template<> struct Hpfs_ResponseTraits<msg::fbuf::p2pmsg::Fs_Entry_Response> {
static const Hpfs_Response enum_value = Hpfs_Response_Fs_Entry_Response;
};
bool VerifyState_Response(flatbuffers::Verifier &verifier, const void *obj, State_Response type);
bool VerifyState_ResponseVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types);
bool VerifyHpfs_Response(flatbuffers::Verifier &verifier, const void *obj, Hpfs_Response type);
bool VerifyHpfs_ResponseVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types);
struct Peer_Challenge_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef Peer_Challenge_MessageBuilder Builder;
@@ -359,7 +359,6 @@ struct Peer_Challenge_MessageBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Peer_Challenge_MessageBuilder &operator=(const Peer_Challenge_MessageBuilder &);
flatbuffers::Offset<Peer_Challenge_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Peer_Challenge_Message>(end);
@@ -431,7 +430,6 @@ struct Peer_Challenge_Response_MessageBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Peer_Challenge_Response_MessageBuilder &operator=(const Peer_Challenge_Response_MessageBuilder &);
flatbuffers::Offset<Peer_Challenge_Response_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Peer_Challenge_Response_Message>(end);
@@ -514,7 +512,6 @@ struct UserInputBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
UserInputBuilder &operator=(const UserInputBuilder &);
flatbuffers::Offset<UserInput> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<UserInput>(end);
@@ -591,7 +588,6 @@ struct UserInputGroupBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
UserInputGroupBuilder &operator=(const UserInputGroupBuilder &);
flatbuffers::Offset<UserInputGroup> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<UserInputGroup>(end);
@@ -649,11 +645,11 @@ struct Content FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
const msg::fbuf::p2pmsg::Npl_Message *message_as_Npl_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_Npl_Message ? static_cast<const msg::fbuf::p2pmsg::Npl_Message *>(message()) : nullptr;
}
const msg::fbuf::p2pmsg::State_Request_Message *message_as_State_Request_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_State_Request_Message ? static_cast<const msg::fbuf::p2pmsg::State_Request_Message *>(message()) : nullptr;
const msg::fbuf::p2pmsg::Hpfs_Request_Message *message_as_Hpfs_Request_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_Hpfs_Request_Message ? static_cast<const msg::fbuf::p2pmsg::Hpfs_Request_Message *>(message()) : nullptr;
}
const msg::fbuf::p2pmsg::State_Response_Message *message_as_State_Response_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_State_Response_Message ? static_cast<const msg::fbuf::p2pmsg::State_Response_Message *>(message()) : nullptr;
const msg::fbuf::p2pmsg::Hpfs_Response_Message *message_as_Hpfs_Response_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_Hpfs_Response_Message ? static_cast<const msg::fbuf::p2pmsg::Hpfs_Response_Message *>(message()) : nullptr;
}
const msg::fbuf::p2pmsg::History_Request_Message *message_as_History_Request_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_History_Request_Message ? static_cast<const msg::fbuf::p2pmsg::History_Request_Message *>(message()) : nullptr;
@@ -711,12 +707,12 @@ template<> inline const msg::fbuf::p2pmsg::Npl_Message *Content::message_as<msg:
return message_as_Npl_Message();
}
template<> inline const msg::fbuf::p2pmsg::State_Request_Message *Content::message_as<msg::fbuf::p2pmsg::State_Request_Message>() const {
return message_as_State_Request_Message();
template<> inline const msg::fbuf::p2pmsg::Hpfs_Request_Message *Content::message_as<msg::fbuf::p2pmsg::Hpfs_Request_Message>() const {
return message_as_Hpfs_Request_Message();
}
template<> inline const msg::fbuf::p2pmsg::State_Response_Message *Content::message_as<msg::fbuf::p2pmsg::State_Response_Message>() const {
return message_as_State_Response_Message();
template<> inline const msg::fbuf::p2pmsg::Hpfs_Response_Message *Content::message_as<msg::fbuf::p2pmsg::Hpfs_Response_Message>() const {
return message_as_Hpfs_Response_Message();
}
template<> inline const msg::fbuf::p2pmsg::History_Request_Message *Content::message_as<msg::fbuf::p2pmsg::History_Request_Message>() const {
@@ -765,7 +761,6 @@ struct ContentBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
ContentBuilder &operator=(const ContentBuilder &);
flatbuffers::Offset<Content> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Content>(end);
@@ -814,7 +809,6 @@ struct NonUnl_Proposal_MessageBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
NonUnl_Proposal_MessageBuilder &operator=(const NonUnl_Proposal_MessageBuilder &);
flatbuffers::Offset<NonUnl_Proposal_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<NonUnl_Proposal_Message>(end);
@@ -883,7 +877,6 @@ struct Unl_ChangesetBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Unl_ChangesetBuilder &operator=(const Unl_ChangesetBuilder &);
flatbuffers::Offset<Unl_Changeset> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Unl_Changeset>(end);
@@ -923,9 +916,10 @@ struct Proposal_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
VT_INPUT_HASHES = 12,
VT_OUTPUT_HASH = 14,
VT_OUTPUT_SIG = 16,
VT_STATE = 18,
VT_UNL_HASH = 20,
VT_UNL_CHANGESET = 22
VT_STATE_HASH = 18,
VT_PATCH_HASH = 20,
VT_UNL_HASH = 22,
VT_UNL_CHANGESET = 24
};
uint8_t stage() const {
return GetField<uint8_t>(VT_STAGE, 0);
@@ -969,11 +963,17 @@ struct Proposal_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
flatbuffers::Vector<uint8_t> *mutable_output_sig() {
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_OUTPUT_SIG);
}
const flatbuffers::Vector<uint8_t> *state() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_STATE);
const flatbuffers::Vector<uint8_t> *state_hash() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_STATE_HASH);
}
flatbuffers::Vector<uint8_t> *mutable_state() {
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_STATE);
flatbuffers::Vector<uint8_t> *mutable_state_hash() {
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_STATE_HASH);
}
const flatbuffers::Vector<uint8_t> *patch_hash() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_PATCH_HASH);
}
flatbuffers::Vector<uint8_t> *mutable_patch_hash() {
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_PATCH_HASH);
}
const flatbuffers::Vector<uint8_t> *unl_hash() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_UNL_HASH);
@@ -1003,8 +1003,10 @@ struct Proposal_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
verifier.VerifyVector(output_hash()) &&
VerifyOffset(verifier, VT_OUTPUT_SIG) &&
verifier.VerifyVector(output_sig()) &&
VerifyOffset(verifier, VT_STATE) &&
verifier.VerifyVector(state()) &&
VerifyOffset(verifier, VT_STATE_HASH) &&
verifier.VerifyVector(state_hash()) &&
VerifyOffset(verifier, VT_PATCH_HASH) &&
verifier.VerifyVector(patch_hash()) &&
VerifyOffset(verifier, VT_UNL_HASH) &&
verifier.VerifyVector(unl_hash()) &&
VerifyOffset(verifier, VT_UNL_CHANGESET) &&
@@ -1038,8 +1040,11 @@ struct Proposal_MessageBuilder {
void add_output_sig(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> output_sig) {
fbb_.AddOffset(Proposal_Message::VT_OUTPUT_SIG, output_sig);
}
void add_state(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> state) {
fbb_.AddOffset(Proposal_Message::VT_STATE, state);
void add_state_hash(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> state_hash) {
fbb_.AddOffset(Proposal_Message::VT_STATE_HASH, state_hash);
}
void add_patch_hash(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> patch_hash) {
fbb_.AddOffset(Proposal_Message::VT_PATCH_HASH, patch_hash);
}
void add_unl_hash(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> unl_hash) {
fbb_.AddOffset(Proposal_Message::VT_UNL_HASH, unl_hash);
@@ -1051,7 +1056,6 @@ struct Proposal_MessageBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Proposal_MessageBuilder &operator=(const Proposal_MessageBuilder &);
flatbuffers::Offset<Proposal_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Proposal_Message>(end);
@@ -1068,14 +1072,16 @@ inline flatbuffers::Offset<Proposal_Message> CreateProposal_Message(
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> input_hashes = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> output_hash = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> output_sig = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> state = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> state_hash = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> patch_hash = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> unl_hash = 0,
flatbuffers::Offset<msg::fbuf::p2pmsg::Unl_Changeset> unl_changeset = 0) {
Proposal_MessageBuilder builder_(_fbb);
builder_.add_time(time);
builder_.add_unl_changeset(unl_changeset);
builder_.add_unl_hash(unl_hash);
builder_.add_state(state);
builder_.add_patch_hash(patch_hash);
builder_.add_state_hash(state_hash);
builder_.add_output_sig(output_sig);
builder_.add_output_hash(output_hash);
builder_.add_input_hashes(input_hashes);
@@ -1094,7 +1100,8 @@ inline flatbuffers::Offset<Proposal_Message> CreateProposal_MessageDirect(
const std::vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *input_hashes = nullptr,
const std::vector<uint8_t> *output_hash = nullptr,
const std::vector<uint8_t> *output_sig = nullptr,
const std::vector<uint8_t> *state = nullptr,
const std::vector<uint8_t> *state_hash = nullptr,
const std::vector<uint8_t> *patch_hash = nullptr,
const std::vector<uint8_t> *unl_hash = nullptr,
flatbuffers::Offset<msg::fbuf::p2pmsg::Unl_Changeset> unl_changeset = 0) {
auto nonce__ = nonce ? _fbb.CreateVector<uint8_t>(*nonce) : 0;
@@ -1102,7 +1109,8 @@ inline flatbuffers::Offset<Proposal_Message> CreateProposal_MessageDirect(
auto input_hashes__ = input_hashes ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::ByteArray>>(*input_hashes) : 0;
auto output_hash__ = output_hash ? _fbb.CreateVector<uint8_t>(*output_hash) : 0;
auto output_sig__ = output_sig ? _fbb.CreateVector<uint8_t>(*output_sig) : 0;
auto state__ = state ? _fbb.CreateVector<uint8_t>(*state) : 0;
auto state_hash__ = state_hash ? _fbb.CreateVector<uint8_t>(*state_hash) : 0;
auto patch_hash__ = patch_hash ? _fbb.CreateVector<uint8_t>(*patch_hash) : 0;
auto unl_hash__ = unl_hash ? _fbb.CreateVector<uint8_t>(*unl_hash) : 0;
return msg::fbuf::p2pmsg::CreateProposal_Message(
_fbb,
@@ -1113,7 +1121,8 @@ inline flatbuffers::Offset<Proposal_Message> CreateProposal_MessageDirect(
input_hashes__,
output_hash__,
output_sig__,
state__,
state_hash__,
patch_hash__,
unl_hash__,
unl_changeset);
}
@@ -1148,7 +1157,6 @@ struct Npl_MessageBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Npl_MessageBuilder &operator=(const Npl_MessageBuilder &);
flatbuffers::Offset<Npl_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Npl_Message>(end);
@@ -1203,7 +1211,6 @@ struct History_Request_MessageBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
History_Request_MessageBuilder &operator=(const History_Request_MessageBuilder &);
flatbuffers::Offset<History_Request_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<History_Request_Message>(end);
@@ -1258,7 +1265,6 @@ struct Unl_Request_MessageBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Unl_Request_MessageBuilder &operator=(const Unl_Request_MessageBuilder &);
flatbuffers::Offset<Unl_Request_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Unl_Request_Message>(end);
@@ -1326,7 +1332,6 @@ struct Unl_Response_MessageBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Unl_Response_MessageBuilder &operator=(const Unl_Response_MessageBuilder &);
flatbuffers::Offset<Unl_Response_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Unl_Response_Message>(end);
@@ -1410,7 +1415,6 @@ struct History_Response_MessageBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
History_Response_MessageBuilder &operator=(const History_Response_MessageBuilder &);
flatbuffers::Offset<History_Response_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<History_Response_Message>(end);
@@ -1485,7 +1489,6 @@ struct HistoryLedgerBlockPairBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
HistoryLedgerBlockPairBuilder &operator=(const HistoryLedgerBlockPairBuilder &);
flatbuffers::Offset<HistoryLedgerBlockPair> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<HistoryLedgerBlockPair>(end);
@@ -1545,7 +1548,6 @@ struct HistoryLedgerBlockBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
HistoryLedgerBlockBuilder &operator=(const HistoryLedgerBlockBuilder &);
flatbuffers::Offset<HistoryLedgerBlock> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<HistoryLedgerBlock>(end);
@@ -1575,8 +1577,8 @@ inline flatbuffers::Offset<HistoryLedgerBlock> CreateHistoryLedgerBlockDirect(
block_buffer__);
}
struct State_Request_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef State_Request_MessageBuilder Builder;
struct Hpfs_Request_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef Hpfs_Request_MessageBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_PARENT_PATH = 4,
VT_IS_FILE = 6,
@@ -1619,41 +1621,40 @@ struct State_Request_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tabl
}
};
struct State_Request_MessageBuilder {
typedef State_Request_Message Table;
struct Hpfs_Request_MessageBuilder {
typedef Hpfs_Request_Message Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_parent_path(flatbuffers::Offset<flatbuffers::String> parent_path) {
fbb_.AddOffset(State_Request_Message::VT_PARENT_PATH, parent_path);
fbb_.AddOffset(Hpfs_Request_Message::VT_PARENT_PATH, parent_path);
}
void add_is_file(bool is_file) {
fbb_.AddElement<uint8_t>(State_Request_Message::VT_IS_FILE, static_cast<uint8_t>(is_file), 0);
fbb_.AddElement<uint8_t>(Hpfs_Request_Message::VT_IS_FILE, static_cast<uint8_t>(is_file), 0);
}
void add_block_id(int32_t block_id) {
fbb_.AddElement<int32_t>(State_Request_Message::VT_BLOCK_ID, block_id, 0);
fbb_.AddElement<int32_t>(Hpfs_Request_Message::VT_BLOCK_ID, block_id, 0);
}
void add_expected_hash(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> expected_hash) {
fbb_.AddOffset(State_Request_Message::VT_EXPECTED_HASH, expected_hash);
fbb_.AddOffset(Hpfs_Request_Message::VT_EXPECTED_HASH, expected_hash);
}
explicit State_Request_MessageBuilder(flatbuffers::FlatBufferBuilder &_fbb)
explicit Hpfs_Request_MessageBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
State_Request_MessageBuilder &operator=(const State_Request_MessageBuilder &);
flatbuffers::Offset<State_Request_Message> Finish() {
flatbuffers::Offset<Hpfs_Request_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<State_Request_Message>(end);
auto o = flatbuffers::Offset<Hpfs_Request_Message>(end);
return o;
}
};
inline flatbuffers::Offset<State_Request_Message> CreateState_Request_Message(
inline flatbuffers::Offset<Hpfs_Request_Message> CreateHpfs_Request_Message(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::String> parent_path = 0,
bool is_file = false,
int32_t block_id = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> expected_hash = 0) {
State_Request_MessageBuilder builder_(_fbb);
Hpfs_Request_MessageBuilder builder_(_fbb);
builder_.add_expected_hash(expected_hash);
builder_.add_block_id(block_id);
builder_.add_parent_path(parent_path);
@@ -1661,7 +1662,7 @@ inline flatbuffers::Offset<State_Request_Message> CreateState_Request_Message(
return builder_.Finish();
}
inline flatbuffers::Offset<State_Request_Message> CreateState_Request_MessageDirect(
inline flatbuffers::Offset<Hpfs_Request_Message> CreateHpfs_Request_MessageDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const char *parent_path = nullptr,
bool is_file = false,
@@ -1669,7 +1670,7 @@ inline flatbuffers::Offset<State_Request_Message> CreateState_Request_MessageDir
const std::vector<uint8_t> *expected_hash = nullptr) {
auto parent_path__ = parent_path ? _fbb.CreateString(parent_path) : 0;
auto expected_hash__ = expected_hash ? _fbb.CreateVector<uint8_t>(*expected_hash) : 0;
return msg::fbuf::p2pmsg::CreateState_Request_Message(
return msg::fbuf::p2pmsg::CreateHpfs_Request_Message(
_fbb,
parent_path__,
is_file,
@@ -1677,32 +1678,32 @@ inline flatbuffers::Offset<State_Request_Message> CreateState_Request_MessageDir
expected_hash__);
}
struct State_Response_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef State_Response_MessageBuilder Builder;
struct Hpfs_Response_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef Hpfs_Response_MessageBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_STATE_RESPONSE_TYPE = 4,
VT_STATE_RESPONSE = 6,
VT_HPFS_RESPONSE_TYPE = 4,
VT_HPFS_RESPONSE = 6,
VT_HASH = 8,
VT_PATH = 10
};
msg::fbuf::p2pmsg::State_Response state_response_type() const {
return static_cast<msg::fbuf::p2pmsg::State_Response>(GetField<uint8_t>(VT_STATE_RESPONSE_TYPE, 0));
msg::fbuf::p2pmsg::Hpfs_Response hpfs_response_type() const {
return static_cast<msg::fbuf::p2pmsg::Hpfs_Response>(GetField<uint8_t>(VT_HPFS_RESPONSE_TYPE, 0));
}
const void *state_response() const {
return GetPointer<const void *>(VT_STATE_RESPONSE);
const void *hpfs_response() const {
return GetPointer<const void *>(VT_HPFS_RESPONSE);
}
template<typename T> const T *state_response_as() const;
const msg::fbuf::p2pmsg::File_HashMap_Response *state_response_as_File_HashMap_Response() const {
return state_response_type() == msg::fbuf::p2pmsg::State_Response_File_HashMap_Response ? static_cast<const msg::fbuf::p2pmsg::File_HashMap_Response *>(state_response()) : nullptr;
template<typename T> const T *hpfs_response_as() const;
const msg::fbuf::p2pmsg::File_HashMap_Response *hpfs_response_as_File_HashMap_Response() const {
return hpfs_response_type() == msg::fbuf::p2pmsg::Hpfs_Response_File_HashMap_Response ? static_cast<const msg::fbuf::p2pmsg::File_HashMap_Response *>(hpfs_response()) : nullptr;
}
const msg::fbuf::p2pmsg::Block_Response *state_response_as_Block_Response() const {
return state_response_type() == msg::fbuf::p2pmsg::State_Response_Block_Response ? static_cast<const msg::fbuf::p2pmsg::Block_Response *>(state_response()) : nullptr;
const msg::fbuf::p2pmsg::Block_Response *hpfs_response_as_Block_Response() const {
return hpfs_response_type() == msg::fbuf::p2pmsg::Hpfs_Response_Block_Response ? static_cast<const msg::fbuf::p2pmsg::Block_Response *>(hpfs_response()) : nullptr;
}
const msg::fbuf::p2pmsg::Fs_Entry_Response *state_response_as_Fs_Entry_Response() const {
return state_response_type() == msg::fbuf::p2pmsg::State_Response_Fs_Entry_Response ? static_cast<const msg::fbuf::p2pmsg::Fs_Entry_Response *>(state_response()) : nullptr;
const msg::fbuf::p2pmsg::Fs_Entry_Response *hpfs_response_as_Fs_Entry_Response() const {
return hpfs_response_type() == msg::fbuf::p2pmsg::Hpfs_Response_Fs_Entry_Response ? static_cast<const msg::fbuf::p2pmsg::Fs_Entry_Response *>(hpfs_response()) : nullptr;
}
void *mutable_state_response() {
return GetPointer<void *>(VT_STATE_RESPONSE);
void *mutable_hpfs_response() {
return GetPointer<void *>(VT_HPFS_RESPONSE);
}
const flatbuffers::Vector<uint8_t> *hash() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_HASH);
@@ -1718,9 +1719,9 @@ struct State_Response_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tab
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<uint8_t>(verifier, VT_STATE_RESPONSE_TYPE) &&
VerifyOffset(verifier, VT_STATE_RESPONSE) &&
VerifyState_Response(verifier, state_response(), state_response_type()) &&
VerifyField<uint8_t>(verifier, VT_HPFS_RESPONSE_TYPE) &&
VerifyOffset(verifier, VT_HPFS_RESPONSE) &&
VerifyHpfs_Response(verifier, hpfs_response(), hpfs_response_type()) &&
VerifyOffset(verifier, VT_HASH) &&
verifier.VerifyVector(hash()) &&
VerifyOffset(verifier, VT_PATH) &&
@@ -1729,72 +1730,71 @@ struct State_Response_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tab
}
};
template<> inline const msg::fbuf::p2pmsg::File_HashMap_Response *State_Response_Message::state_response_as<msg::fbuf::p2pmsg::File_HashMap_Response>() const {
return state_response_as_File_HashMap_Response();
template<> inline const msg::fbuf::p2pmsg::File_HashMap_Response *Hpfs_Response_Message::hpfs_response_as<msg::fbuf::p2pmsg::File_HashMap_Response>() const {
return hpfs_response_as_File_HashMap_Response();
}
template<> inline const msg::fbuf::p2pmsg::Block_Response *State_Response_Message::state_response_as<msg::fbuf::p2pmsg::Block_Response>() const {
return state_response_as_Block_Response();
template<> inline const msg::fbuf::p2pmsg::Block_Response *Hpfs_Response_Message::hpfs_response_as<msg::fbuf::p2pmsg::Block_Response>() const {
return hpfs_response_as_Block_Response();
}
template<> inline const msg::fbuf::p2pmsg::Fs_Entry_Response *State_Response_Message::state_response_as<msg::fbuf::p2pmsg::Fs_Entry_Response>() const {
return state_response_as_Fs_Entry_Response();
template<> inline const msg::fbuf::p2pmsg::Fs_Entry_Response *Hpfs_Response_Message::hpfs_response_as<msg::fbuf::p2pmsg::Fs_Entry_Response>() const {
return hpfs_response_as_Fs_Entry_Response();
}
struct State_Response_MessageBuilder {
typedef State_Response_Message Table;
struct Hpfs_Response_MessageBuilder {
typedef Hpfs_Response_Message Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_state_response_type(msg::fbuf::p2pmsg::State_Response state_response_type) {
fbb_.AddElement<uint8_t>(State_Response_Message::VT_STATE_RESPONSE_TYPE, static_cast<uint8_t>(state_response_type), 0);
void add_hpfs_response_type(msg::fbuf::p2pmsg::Hpfs_Response hpfs_response_type) {
fbb_.AddElement<uint8_t>(Hpfs_Response_Message::VT_HPFS_RESPONSE_TYPE, static_cast<uint8_t>(hpfs_response_type), 0);
}
void add_state_response(flatbuffers::Offset<void> state_response) {
fbb_.AddOffset(State_Response_Message::VT_STATE_RESPONSE, state_response);
void add_hpfs_response(flatbuffers::Offset<void> hpfs_response) {
fbb_.AddOffset(Hpfs_Response_Message::VT_HPFS_RESPONSE, hpfs_response);
}
void add_hash(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> hash) {
fbb_.AddOffset(State_Response_Message::VT_HASH, hash);
fbb_.AddOffset(Hpfs_Response_Message::VT_HASH, hash);
}
void add_path(flatbuffers::Offset<flatbuffers::String> path) {
fbb_.AddOffset(State_Response_Message::VT_PATH, path);
fbb_.AddOffset(Hpfs_Response_Message::VT_PATH, path);
}
explicit State_Response_MessageBuilder(flatbuffers::FlatBufferBuilder &_fbb)
explicit Hpfs_Response_MessageBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
State_Response_MessageBuilder &operator=(const State_Response_MessageBuilder &);
flatbuffers::Offset<State_Response_Message> Finish() {
flatbuffers::Offset<Hpfs_Response_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<State_Response_Message>(end);
auto o = flatbuffers::Offset<Hpfs_Response_Message>(end);
return o;
}
};
inline flatbuffers::Offset<State_Response_Message> CreateState_Response_Message(
inline flatbuffers::Offset<Hpfs_Response_Message> CreateHpfs_Response_Message(
flatbuffers::FlatBufferBuilder &_fbb,
msg::fbuf::p2pmsg::State_Response state_response_type = msg::fbuf::p2pmsg::State_Response_NONE,
flatbuffers::Offset<void> state_response = 0,
msg::fbuf::p2pmsg::Hpfs_Response hpfs_response_type = msg::fbuf::p2pmsg::Hpfs_Response_NONE,
flatbuffers::Offset<void> hpfs_response = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> hash = 0,
flatbuffers::Offset<flatbuffers::String> path = 0) {
State_Response_MessageBuilder builder_(_fbb);
Hpfs_Response_MessageBuilder builder_(_fbb);
builder_.add_path(path);
builder_.add_hash(hash);
builder_.add_state_response(state_response);
builder_.add_state_response_type(state_response_type);
builder_.add_hpfs_response(hpfs_response);
builder_.add_hpfs_response_type(hpfs_response_type);
return builder_.Finish();
}
inline flatbuffers::Offset<State_Response_Message> CreateState_Response_MessageDirect(
inline flatbuffers::Offset<Hpfs_Response_Message> CreateHpfs_Response_MessageDirect(
flatbuffers::FlatBufferBuilder &_fbb,
msg::fbuf::p2pmsg::State_Response state_response_type = msg::fbuf::p2pmsg::State_Response_NONE,
flatbuffers::Offset<void> state_response = 0,
msg::fbuf::p2pmsg::Hpfs_Response hpfs_response_type = msg::fbuf::p2pmsg::Hpfs_Response_NONE,
flatbuffers::Offset<void> hpfs_response = 0,
const std::vector<uint8_t> *hash = nullptr,
const char *path = nullptr) {
auto hash__ = hash ? _fbb.CreateVector<uint8_t>(*hash) : 0;
auto path__ = path ? _fbb.CreateString(path) : 0;
return msg::fbuf::p2pmsg::CreateState_Response_Message(
return msg::fbuf::p2pmsg::CreateHpfs_Response_Message(
_fbb,
state_response_type,
state_response,
hpfs_response_type,
hpfs_response,
hash__,
path__);
}
@@ -1804,11 +1804,11 @@ struct Fs_Entry_Response FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_ENTRIES = 4
};
const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>> *entries() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>> *>(VT_ENTRIES);
const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::Hpfs_FS_Hash_Entry>> *entries() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::Hpfs_FS_Hash_Entry>> *>(VT_ENTRIES);
}
flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>> *mutable_entries() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>> *>(VT_ENTRIES);
flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::Hpfs_FS_Hash_Entry>> *mutable_entries() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::Hpfs_FS_Hash_Entry>> *>(VT_ENTRIES);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
@@ -1823,14 +1823,13 @@ struct Fs_Entry_ResponseBuilder {
typedef Fs_Entry_Response Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_entries(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>>> entries) {
void add_entries(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::Hpfs_FS_Hash_Entry>>> entries) {
fbb_.AddOffset(Fs_Entry_Response::VT_ENTRIES, entries);
}
explicit Fs_Entry_ResponseBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Fs_Entry_ResponseBuilder &operator=(const Fs_Entry_ResponseBuilder &);
flatbuffers::Offset<Fs_Entry_Response> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Fs_Entry_Response>(end);
@@ -1840,7 +1839,7 @@ struct Fs_Entry_ResponseBuilder {
inline flatbuffers::Offset<Fs_Entry_Response> CreateFs_Entry_Response(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>>> entries = 0) {
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::Hpfs_FS_Hash_Entry>>> entries = 0) {
Fs_Entry_ResponseBuilder builder_(_fbb);
builder_.add_entries(entries);
return builder_.Finish();
@@ -1848,8 +1847,8 @@ inline flatbuffers::Offset<Fs_Entry_Response> CreateFs_Entry_Response(
inline flatbuffers::Offset<Fs_Entry_Response> CreateFs_Entry_ResponseDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const std::vector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>> *entries = nullptr) {
auto entries__ = entries ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>>(*entries) : 0;
const std::vector<flatbuffers::Offset<msg::fbuf::p2pmsg::Hpfs_FS_Hash_Entry>> *entries = nullptr) {
auto entries__ = entries ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::p2pmsg::Hpfs_FS_Hash_Entry>>(*entries) : 0;
return msg::fbuf::p2pmsg::CreateFs_Entry_Response(
_fbb,
entries__);
@@ -1896,7 +1895,6 @@ struct File_HashMap_ResponseBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
File_HashMap_ResponseBuilder &operator=(const File_HashMap_ResponseBuilder &);
flatbuffers::Offset<File_HashMap_Response> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<File_HashMap_Response>(end);
@@ -1966,7 +1964,6 @@ struct Block_ResponseBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Block_ResponseBuilder &operator=(const Block_ResponseBuilder &);
flatbuffers::Offset<Block_Response> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Block_Response>(end);
@@ -1995,8 +1992,8 @@ inline flatbuffers::Offset<Block_Response> CreateBlock_ResponseDirect(
data__);
}
struct State_FS_Hash_Entry FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef State_FS_Hash_EntryBuilder Builder;
struct Hpfs_FS_Hash_Entry FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef Hpfs_FS_Hash_EntryBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_NAME = 4,
VT_IS_FILE = 6,
@@ -2031,51 +2028,50 @@ struct State_FS_Hash_Entry FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table
}
};
struct State_FS_Hash_EntryBuilder {
typedef State_FS_Hash_Entry Table;
struct Hpfs_FS_Hash_EntryBuilder {
typedef Hpfs_FS_Hash_Entry Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
fbb_.AddOffset(State_FS_Hash_Entry::VT_NAME, name);
fbb_.AddOffset(Hpfs_FS_Hash_Entry::VT_NAME, name);
}
void add_is_file(bool is_file) {
fbb_.AddElement<uint8_t>(State_FS_Hash_Entry::VT_IS_FILE, static_cast<uint8_t>(is_file), 0);
fbb_.AddElement<uint8_t>(Hpfs_FS_Hash_Entry::VT_IS_FILE, static_cast<uint8_t>(is_file), 0);
}
void add_hash(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> hash) {
fbb_.AddOffset(State_FS_Hash_Entry::VT_HASH, hash);
fbb_.AddOffset(Hpfs_FS_Hash_Entry::VT_HASH, hash);
}
explicit State_FS_Hash_EntryBuilder(flatbuffers::FlatBufferBuilder &_fbb)
explicit Hpfs_FS_Hash_EntryBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
State_FS_Hash_EntryBuilder &operator=(const State_FS_Hash_EntryBuilder &);
flatbuffers::Offset<State_FS_Hash_Entry> Finish() {
flatbuffers::Offset<Hpfs_FS_Hash_Entry> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<State_FS_Hash_Entry>(end);
auto o = flatbuffers::Offset<Hpfs_FS_Hash_Entry>(end);
return o;
}
};
inline flatbuffers::Offset<State_FS_Hash_Entry> CreateState_FS_Hash_Entry(
inline flatbuffers::Offset<Hpfs_FS_Hash_Entry> CreateHpfs_FS_Hash_Entry(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::String> name = 0,
bool is_file = false,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> hash = 0) {
State_FS_Hash_EntryBuilder builder_(_fbb);
Hpfs_FS_Hash_EntryBuilder builder_(_fbb);
builder_.add_hash(hash);
builder_.add_name(name);
builder_.add_is_file(is_file);
return builder_.Finish();
}
inline flatbuffers::Offset<State_FS_Hash_Entry> CreateState_FS_Hash_EntryDirect(
inline flatbuffers::Offset<Hpfs_FS_Hash_Entry> CreateHpfs_FS_Hash_EntryDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const char *name = nullptr,
bool is_file = false,
const std::vector<uint8_t> *hash = nullptr) {
auto name__ = name ? _fbb.CreateString(name) : 0;
auto hash__ = hash ? _fbb.CreateVector<uint8_t>(*hash) : 0;
return msg::fbuf::p2pmsg::CreateState_FS_Hash_Entry(
return msg::fbuf::p2pmsg::CreateHpfs_FS_Hash_Entry(
_fbb,
name__,
is_file,
@@ -2111,7 +2107,6 @@ struct Peer_Requirement_Announcement_MessageBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Peer_Requirement_Announcement_MessageBuilder &operator=(const Peer_Requirement_Announcement_MessageBuilder &);
flatbuffers::Offset<Peer_Requirement_Announcement_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Peer_Requirement_Announcement_Message>(end);
@@ -2167,7 +2162,6 @@ struct Available_Capacity_Announcement_MessageBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Available_Capacity_Announcement_MessageBuilder &operator=(const Available_Capacity_Announcement_MessageBuilder &);
flatbuffers::Offset<Available_Capacity_Announcement_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Available_Capacity_Announcement_Message>(end);
@@ -2201,7 +2195,6 @@ struct Peer_List_Request_MessageBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Peer_List_Request_MessageBuilder &operator=(const Peer_List_Request_MessageBuilder &);
flatbuffers::Offset<Peer_List_Request_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Peer_List_Request_Message>(end);
@@ -2246,7 +2239,6 @@ struct Peer_List_Response_MessageBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Peer_List_Response_MessageBuilder &operator=(const Peer_List_Response_MessageBuilder &);
flatbuffers::Offset<Peer_List_Response_Message> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Peer_List_Response_Message>(end);
@@ -2334,7 +2326,6 @@ struct Peer_PropertiesBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
Peer_PropertiesBuilder &operator=(const Peer_PropertiesBuilder &);
flatbuffers::Offset<Peer_Properties> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Peer_Properties>(end);
@@ -2396,12 +2387,12 @@ inline bool VerifyMessage(flatbuffers::Verifier &verifier, const void *obj, Mess
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::Npl_Message *>(obj);
return verifier.VerifyTable(ptr);
}
case Message_State_Request_Message: {
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::State_Request_Message *>(obj);
case Message_Hpfs_Request_Message: {
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::Hpfs_Request_Message *>(obj);
return verifier.VerifyTable(ptr);
}
case Message_State_Response_Message: {
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::State_Response_Message *>(obj);
case Message_Hpfs_Response_Message: {
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::Hpfs_Response_Message *>(obj);
return verifier.VerifyTable(ptr);
}
case Message_History_Request_Message: {
@@ -2452,20 +2443,20 @@ inline bool VerifyMessageVector(flatbuffers::Verifier &verifier, const flatbuffe
return true;
}
inline bool VerifyState_Response(flatbuffers::Verifier &verifier, const void *obj, State_Response type) {
inline bool VerifyHpfs_Response(flatbuffers::Verifier &verifier, const void *obj, Hpfs_Response type) {
switch (type) {
case State_Response_NONE: {
case Hpfs_Response_NONE: {
return true;
}
case State_Response_File_HashMap_Response: {
case Hpfs_Response_File_HashMap_Response: {
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::File_HashMap_Response *>(obj);
return verifier.VerifyTable(ptr);
}
case State_Response_Block_Response: {
case Hpfs_Response_Block_Response: {
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::Block_Response *>(obj);
return verifier.VerifyTable(ptr);
}
case State_Response_Fs_Entry_Response: {
case Hpfs_Response_Fs_Entry_Response: {
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::Fs_Entry_Response *>(obj);
return verifier.VerifyTable(ptr);
}
@@ -2473,12 +2464,12 @@ inline bool VerifyState_Response(flatbuffers::Verifier &verifier, const void *ob
}
}
inline bool VerifyState_ResponseVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types) {
inline bool VerifyHpfs_ResponseVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types) {
if (!values || !types) return !values && !types;
if (values->size() != types->size()) return false;
for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {
if (!VerifyState_Response(
verifier, values->Get(i), types->GetEnum<State_Response>(i))) {
if (!VerifyHpfs_Response(
verifier, values->Get(i), types->GetEnum<Hpfs_Response>(i))) {
return false;
}
}

View File

@@ -232,7 +232,8 @@ namespace msg::fbuf::p2pmsg
p.stage = msg.stage();
p.lcl = flatbuff_bytes_to_sv(lcl);
p.unl_hash = flatbuff_bytes_to_sv(msg.unl_hash());
p.state = flatbuff_bytes_to_sv(msg.state());
p.state_hash = flatbuff_bytes_to_sv(msg.state_hash());
p.patch_hash = flatbuff_bytes_to_sv(msg.patch_hash());
const auto unl_changeset = msg.unl_changeset();
p.unl_changeset.additions = flatbuf_bytearrayvector_to_stringlist(unl_changeset->additions());
@@ -272,20 +273,20 @@ namespace msg::fbuf::p2pmsg
}
/**
* Creates a state request struct from the given state request message.
* @param msg Flatbuffer State request message received from the peer.
* @return A State request struct representing the message.
*/
const p2p::state_request create_state_request_from_msg(const State_Request_Message &msg)
* Creates a hpfs request struct from the given hpfs request message.
* @param msg Flatbuffer State request message received from the peer.
* @return A hpfs request struct representing the message.
*/
const p2p::hpfs_request create_hpfs_request_from_msg(const Hpfs_Request_Message &msg)
{
p2p::state_request sr;
p2p::hpfs_request hr;
sr.block_id = msg.block_id();
sr.is_file = msg.is_file();
sr.parent_path = flatbuff_str_to_sv(msg.parent_path());
sr.expected_hash = flatbuff_bytes_to_hash(msg.expected_hash());
hr.block_id = msg.block_id();
hr.is_file = msg.is_file();
hr.parent_path = flatbuff_str_to_sv(msg.parent_path());
hr.expected_hash = flatbuff_bytes_to_hash(msg.expected_hash());
return sr;
return hr;
}
/**
@@ -392,7 +393,8 @@ namespace msg::fbuf::p2pmsg
stringlist_to_flatbuf_bytearrayvector(builder, p.input_hashes),
sv_to_flatbuff_bytes(builder, p.output_hash),
sv_to_flatbuff_bytes(builder, p.output_sig),
hash_to_flatbuff_bytes(builder, p.state),
hash_to_flatbuff_bytes(builder, p.state_hash),
hash_to_flatbuff_bytes(builder, p.patch_hash),
sv_to_flatbuff_bytes(builder, p.unl_hash),
unl_changeset);
@@ -474,23 +476,23 @@ namespace msg::fbuf::p2pmsg
}
/**
* Create state request message from the given state request struct.
* @param container_builder Flatbuffer builder for the container message.
* @param sr The state request struct to be placed in the container message.
*/
void create_msg_from_state_request(flatbuffers::FlatBufferBuilder &container_builder, const p2p::state_request &hr, std::string_view lcl)
* Create hpfs request message from the given hpfs request struct.
* @param container_builder Flatbuffer builder for the container message.
* @param hr The hpfs request struct to be placed in the container message.
*/
void create_msg_from_state_request(flatbuffers::FlatBufferBuilder &container_builder, const p2p::hpfs_request &hr, std::string_view lcl)
{
flatbuffers::FlatBufferBuilder builder(1024);
flatbuffers::Offset<State_Request_Message> srmsg =
CreateState_Request_Message(
flatbuffers::Offset<Hpfs_Request_Message> srmsg =
CreateHpfs_Request_Message(
builder,
sv_to_flatbuff_str(builder, hr.parent_path),
hr.is_file,
hr.block_id,
hash_to_flatbuff_bytes(builder, hr.expected_hash));
flatbuffers::Offset<Content> message = CreateContent(builder, Message_State_Request_Message, srmsg.Union());
flatbuffers::Offset<Content> message = CreateContent(builder, Message_Hpfs_Request_Message, srmsg.Union());
builder.Finish(message); // Finished building message content to get serialised content.
// Now that we have built the content message,
@@ -515,15 +517,15 @@ namespace msg::fbuf::p2pmsg
const flatbuffers::Offset<Fs_Entry_Response> resp =
CreateFs_Entry_Response(
builder,
statefshashentry_to_flatbuff_statefshashentry(builder, hash_nodes));
hpfsfshashentry_to_flatbuff_hpfsfshashentry(builder, hash_nodes));
const flatbuffers::Offset<State_Response_Message> st_resp = CreateState_Response_Message(
builder, State_Response_Fs_Entry_Response,
const flatbuffers::Offset<Hpfs_Response_Message> st_resp = CreateHpfs_Response_Message(
builder, Hpfs_Response_Fs_Entry_Response,
resp.Union(),
hash_to_flatbuff_bytes(builder, expected_hash),
sv_to_flatbuff_str(builder, path));
flatbuffers::Offset<Content> message = CreateContent(builder, Message_State_Response_Message, st_resp.Union());
flatbuffers::Offset<Content> message = CreateContent(builder, Message_Hpfs_Response_Message, st_resp.Union());
builder.Finish(message); // Finished building message content to get serialised content.
// Now that we have built the content message,
@@ -553,14 +555,14 @@ namespace msg::fbuf::p2pmsg
file_length,
sv_to_flatbuff_bytes(builder, hashmap_sv));
const flatbuffers::Offset<State_Response_Message> st_resp = CreateState_Response_Message(
const flatbuffers::Offset<Hpfs_Response_Message> st_resp = CreateHpfs_Response_Message(
builder,
State_Response_File_HashMap_Response,
Hpfs_Response_File_HashMap_Response,
resp.Union(),
hash_to_flatbuff_bytes(builder, expected_hash),
sv_to_flatbuff_str(builder, path));
flatbuffers::Offset<Content> message = CreateContent(builder, Message_State_Response_Message, st_resp.Union());
flatbuffers::Offset<Content> message = CreateContent(builder, Message_Hpfs_Response_Message, st_resp.Union());
builder.Finish(message); // Finished building message content to get serialised content.
// Now that we have built the content message,
@@ -585,14 +587,14 @@ namespace msg::fbuf::p2pmsg
block_resp.block_id,
sv_to_flatbuff_bytes(builder, block_resp.data));
const flatbuffers::Offset<State_Response_Message> st_resp = CreateState_Response_Message(
const flatbuffers::Offset<Hpfs_Response_Message> st_resp = CreateHpfs_Response_Message(
builder,
State_Response_Block_Response,
Hpfs_Response_Block_Response,
resp.Union(),
hash_to_flatbuff_bytes(builder, block_resp.hash),
sv_to_flatbuff_str(builder, block_resp.path));
flatbuffers::Offset<Content> message = CreateContent(builder, Message_State_Response_Message, st_resp.Union());
flatbuffers::Offset<Content> message = CreateContent(builder, Message_Hpfs_Response_Message, st_resp.Union());
builder.Finish(message); // Finished building message content to get serialised content.
// Now that we have built the content message,
@@ -900,11 +902,11 @@ namespace msg::fbuf::p2pmsg
return builder.CreateVector(fbvec);
}
void flatbuf_statefshashentry_to_statefshashentry(std::unordered_map<std::string, p2p::state_fs_hash_entry> &fs_entries, const flatbuffers::Vector<flatbuffers::Offset<State_FS_Hash_Entry>> *fhashes)
void flatbuf_hpfsfshashentry_to_hpfsfshashentry(std::unordered_map<std::string, p2p::hpfs_fs_hash_entry> &fs_entries, const flatbuffers::Vector<flatbuffers::Offset<Hpfs_FS_Hash_Entry>> *fhashes)
{
for (const State_FS_Hash_Entry *f_hash : *fhashes)
for (const Hpfs_FS_Hash_Entry *f_hash : *fhashes)
{
p2p::state_fs_hash_entry entry;
p2p::hpfs_fs_hash_entry entry;
entry.name = flatbuff_str_to_sv(f_hash->name());
entry.is_file = f_hash->is_file();
entry.hash = flatbuff_bytes_to_hash(f_hash->hash());
@@ -913,22 +915,22 @@ namespace msg::fbuf::p2pmsg
}
}
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<State_FS_Hash_Entry>>>
statefshashentry_to_flatbuff_statefshashentry(
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Hpfs_FS_Hash_Entry>>>
hpfsfshashentry_to_flatbuff_hpfsfshashentry(
flatbuffers::FlatBufferBuilder &builder,
std::vector<hpfs::child_hash_node> &hash_nodes)
{
std::vector<flatbuffers::Offset<State_FS_Hash_Entry>> fbvec;
std::vector<flatbuffers::Offset<Hpfs_FS_Hash_Entry>> fbvec;
fbvec.reserve(hash_nodes.size());
for (auto const &hash_node : hash_nodes)
{
flatbuffers::Offset<State_FS_Hash_Entry> state_fs_entry = CreateState_FS_Hash_Entry(
flatbuffers::Offset<Hpfs_FS_Hash_Entry> hpfs_fs_entry = CreateHpfs_FS_Hash_Entry(
builder,
sv_to_flatbuff_str(builder, hash_node.name),
hash_node.is_file,
hash_to_flatbuff_bytes(builder, hash_node.hash));
fbvec.push_back(state_fs_entry);
fbvec.push_back(hpfs_fs_entry);
}
return builder.CreateVector(fbvec);
}

View File

@@ -36,7 +36,7 @@ namespace msg::fbuf::p2pmsg
const p2p::history_response create_history_response_from_msg(const History_Response_Message &msg);
const p2p::state_request create_state_request_from_msg(const State_Request_Message &msg);
const p2p::hpfs_request create_hpfs_request_from_msg(const Hpfs_Request_Message &msg);
const p2p::unl_sync_request create_unl_sync_request_from_msg(const Unl_Request_Message &unl_req_message);
@@ -59,7 +59,7 @@ namespace msg::fbuf::p2pmsg
void create_msg_from_npl_output(flatbuffers::FlatBufferBuilder &container_builder, const std::string_view &msg, std::string_view lcl);
void create_msg_from_state_request(flatbuffers::FlatBufferBuilder &container_builder, const p2p::state_request &hr, std::string_view lcl);
void create_msg_from_state_request(flatbuffers::FlatBufferBuilder &container_builder, const p2p::hpfs_request &hr, std::string_view lcl);
void create_msg_from_unl_sync_request(flatbuffers::FlatBufferBuilder &container_builder, const p2p::unl_sync_request &unl_sync_message);
@@ -108,14 +108,14 @@ namespace msg::fbuf::p2pmsg
const flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Peer_Properties>>>
peer_propertiesvector_to_flatbuf_peer_propertieslist(flatbuffers::FlatBufferBuilder &builder, const std::vector<conf::peer_properties> &peers, const std::optional<conf::ip_port_prop> &skipping_ip_port);
void flatbuf_statefshashentry_to_statefshashentry(std::unordered_map<std::string, p2p::state_fs_hash_entry> &fs_entries,
const flatbuffers::Vector<flatbuffers::Offset<State_FS_Hash_Entry>> *fhashes);
void flatbuf_hpfsfshashentry_to_hpfsfshashentry(std::unordered_map<std::string, p2p::hpfs_fs_hash_entry> &fs_entries,
const flatbuffers::Vector<flatbuffers::Offset<Hpfs_FS_Hash_Entry>> *fhashes);
void statefilehash_to_flatbuf_statefilehash(flatbuffers::FlatBufferBuilder &builder, std::vector<flatbuffers::Offset<State_FS_Hash_Entry>> &list,
void hpfsfilehash_to_flatbuf_hpfsfilehash(flatbuffers::FlatBufferBuilder &builder, std::vector<flatbuffers::Offset<Hpfs_FS_Hash_Entry>> &list,
std::string_view full_path, bool is_file, std::string_view hash);
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<State_FS_Hash_Entry>>>
statefshashentry_to_flatbuff_statefshashentry(
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Hpfs_FS_Hash_Entry>>>
hpfsfshashentry_to_flatbuff_hpfsfshashentry(
flatbuffers::FlatBufferBuilder &builder,
std::vector<hpfs::child_hash_node> &hash_nodes);

View File

@@ -47,13 +47,14 @@ namespace p2p
std::string pubkey;
uint64_t sent_timestamp = 0; // The timestamp of the sender when this proposal was sent.
uint64_t recv_timestamp = 0; // The timestamp when we received the proposal. (used for statsitics)
uint64_t recv_timestamp = 0; // The timestamp when we received the proposal. (used for statistics)
uint64_t time = 0; // The time value that is voted on.
uint8_t stage = 0;
std::string nonce; // Random nonce that is used to reduce lcl predictability.
std::string lcl;
std::string unl_hash; // Hash of the current unl list.
util::h32 state;
std::string unl_hash; // Hash of the current unl list.
util::h32 state_hash; // Contract state hash.
util::h32 patch_hash; // Patch file hash.
std::set<std::string> users;
std::set<std::string> input_hashes;
std::string output_hash;
@@ -124,8 +125,8 @@ namespace p2p
std::string data;
};
// Represents a state request sent to a peer.
struct state_request
// Represents a hpfs request sent to a peer.
struct hpfs_request
{
std::string parent_path; // The requested file or dir path.
bool is_file = false; // Whether the path is a file or dir.
@@ -133,8 +134,8 @@ namespace p2p
util::h32 expected_hash; // The expected hash of the requested result.
};
// Represents state file system entry.
struct state_fs_hash_entry
// Represents hpfs file system entry.
struct hpfs_fs_hash_entry
{
std::string name; // Name of the file/dir.
bool is_file = false; // Whether this is a file or dir.
@@ -158,13 +159,13 @@ namespace p2p
std::list<nonunl_proposal> nonunl_proposals;
std::mutex nonunl_proposals_mutex; // Mutex for non-unl proposals access race conditions.
// List of pairs indicating the session pubkey hex and the state requests.
std::list<std::pair<std::string, std::string>> state_requests;
std::mutex state_requests_mutex; // Mutex for state requests access race conditions.
// List of pairs indicating the session pubkey hex and the hpfs requests.
std::list<std::pair<std::string, std::string>> hpfs_requests;
std::mutex hpfs_requests_mutex; // Mutex for hpfs requests access race conditions.
// List of pairs indicating the session pubkey hex and the state responses.
std::list<std::pair<std::string, std::string>> state_responses;
std::mutex state_responses_mutex; // Mutex for state responses access race conditions.
// List of pairs indicating the session pubkey hex and the hpfs responses.
std::list<std::pair<std::string, std::string>> hpfs_responses;
std::mutex hpfs_responses_mutex; // Mutex for hpfs responses access race conditions.
};
struct connected_context

View File

@@ -9,7 +9,7 @@
#include "../msg/fbuf/p2pmsg_content_generated.h"
#include "../msg/fbuf/p2pmsg_helpers.hpp"
#include "../msg/fbuf/common_helpers.hpp"
#include "../state/state_sync.hpp"
#include "../hpfs/hpfs_sync.hpp"
#include "../ledger.hpp"
#include "peer_comm_session.hpp"
#include "p2p.hpp"
@@ -187,34 +187,34 @@ namespace p2p
handle_npl_message(container, content);
}
else if (content_message_type == p2pmsg::Message_State_Request_Message)
else if (content_message_type == p2pmsg::Message_Hpfs_Request_Message)
{
// Check the cap and insert request with lock.
std::scoped_lock<std::mutex> lock(ctx.collected_msgs.state_requests_mutex);
std::scoped_lock<std::mutex> lock(ctx.collected_msgs.hpfs_requests_mutex);
// If max number of state requests reached skip the rest.
if (ctx.collected_msgs.state_requests.size() < p2p::STATE_REQ_LIST_CAP)
if (ctx.collected_msgs.hpfs_requests.size() < p2p::STATE_REQ_LIST_CAP)
{
std::string state_request_msg(reinterpret_cast<const char *>(content_ptr), content_size);
ctx.collected_msgs.state_requests.push_back(std::make_pair(session.pubkey, std::move(state_request_msg)));
ctx.collected_msgs.hpfs_requests.push_back(std::make_pair(session.pubkey, std::move(state_request_msg)));
}
else
{
LOG_DEBUG << "State request rejected. Maximum state request count reached. " << session.display_name();
}
}
else if (content_message_type == p2pmsg::Message_State_Response_Message)
else if (content_message_type == p2pmsg::Message_Hpfs_Response_Message)
{
if (state_sync::ctx.is_syncing) // Only accept state responses if state is syncing.
if (hpfs_sync::ctx.is_syncing) // Only accept state responses if state is syncing.
{
// Check the cap and insert state_response with lock.
std::scoped_lock<std::mutex> lock(ctx.collected_msgs.state_responses_mutex);
std::scoped_lock<std::mutex> lock(ctx.collected_msgs.hpfs_responses_mutex);
// If max number of state responses reached skip the rest.
if (ctx.collected_msgs.state_responses.size() < p2p::STATE_RES_LIST_CAP)
if (ctx.collected_msgs.hpfs_responses.size() < p2p::STATE_RES_LIST_CAP)
{
std::string response(reinterpret_cast<const char *>(content_ptr), content_size);
ctx.collected_msgs.state_responses.push_back(std::make_pair(session.uniqueid, std::move(response)));
ctx.collected_msgs.hpfs_responses.push_back(std::make_pair(session.uniqueid, std::move(response)));
}
else
{

View File

@@ -13,47 +13,6 @@
namespace sc
{
const uint32_t READ_BUFFER_SIZE = 128 * 1024; // This has to be minimum 128KB to support sequence packets.
bool init_success = false;
// We maintain two hpfs global processes for merging and rw sessions.
pid_t hpfs_merge_pid = 0;
pid_t hpfs_rw_pid = 0;
/**
* Performs system startup activitites related to smart contract execution.
*/
int init()
{
if (hpfs::start_merge_process(hpfs_merge_pid) == -1)
return -1;
if (hpfs::start_ro_rw_process(hpfs_rw_pid, conf::ctx.state_rw_dir, false, true, false) == -1)
{
// Stop the merge process in case of failure.
util::kill_process(hpfs_merge_pid, true);
return -1;
}
init_success = true;
return 0;
}
/**
* Performs global cleanup related to smart contract execution.
*/
void deinit()
{
if (init_success)
{
LOG_DEBUG << "Stopping hpfs rw process... pid:" << hpfs_rw_pid;
if (hpfs_rw_pid > 0 && util::kill_process(hpfs_rw_pid, true) == 0)
LOG_INFO << "Stopped hpfs rw process.";
LOG_DEBUG << "Stopping hpfs merge process... pid:" << hpfs_merge_pid;
if (hpfs_merge_pid > 0 && util::kill_process(hpfs_merge_pid, true) == 0)
LOG_INFO << "Stopped hpfs merge process.";
}
}
/**
* Executes the contract process and passes the specified context arguments.
@@ -130,7 +89,8 @@ namespace sc
execv_args[j] = conf::cfg.contract.runtime_binexec_args[i].data();
execv_args[len - 1] = NULL;
chdir(ctx.args.state_dir.c_str());
const std::string current_dir = std::string(ctx.args.hpfs_dir).append(STATE_DIR_PATH);
chdir(current_dir.c_str());
execv(execv_args[0], execv_args);
std::cerr << errno << ": Contract process execv failed." << (ctx.args.readonly ? " (rdonly)" : "") << "\n";
@@ -188,7 +148,7 @@ namespace sc
}
/**
* Starts the hpfs read/write state filesystem.
* Starts the hpfs read/write virtual filesystem.
*/
int start_hpfs_session(execution_context &ctx)
{
@@ -196,33 +156,33 @@ namespace sc
// In RW mode, there is a global hpfs RW process so we only need to create an fs session.
if (ctx.args.readonly)
{
if (hpfs::start_ro_rw_process(ctx.hpfs_pid, ctx.args.state_dir, true, false, false) == -1)
if (hpfs::start_ro_rw_process(ctx.hpfs_pid, ctx.args.hpfs_dir, true, false, false) == -1)
return -1;
}
else
{
ctx.hpfs_pid = hpfs_rw_pid;
ctx.hpfs_pid = hpfs::ctx.hpfs_rw_pid;
}
if (hpfs::start_fs_session(ctx.args.state_dir) == -1)
if (hpfs::start_fs_session(ctx.args.hpfs_dir) == -1)
return -1;
return 0;
}
/**
* Stops the hpfs state filesystem.
* Stops the hpfs virtual filesystem.
*/
int stop_hpfs_session(execution_context &ctx)
{
int result = 0;
// Read the root hash if not in readonly mode.
if (!ctx.args.readonly && hpfs::get_hash(ctx.args.post_execution_state_hash, ctx.args.state_dir, "/") < 1)
if (!ctx.args.readonly && hpfs::get_hash(ctx.args.post_execution_state_hash, ctx.args.hpfs_dir, STATE_DIR_PATH) < 1)
result = -1;
LOG_DEBUG << "Stopping hpfs contract session..." << (ctx.args.readonly ? " (rdonly)" : "");
if (hpfs::stop_fs_session(ctx.args.state_dir) == -1)
if (hpfs::stop_fs_session(ctx.args.hpfs_dir) == -1)
return -1;
// In readonly mode, we must also stop the hpfs process itself after sopping the session.

View File

@@ -15,6 +15,7 @@ namespace sc
{
constexpr uint16_t MAX_NPL_MSG_QUEUE_SIZE = 64; // Maximum npl message queue size, The size passed is rounded to next number in binary sequence 1(1),11(3),111(7),1111(15),11111(31)....
constexpr uint16_t MAX_CONTROL_MSG_QUEUE_SIZE = 64; // Maximum out message queue size, The size passed is rounded to next number in binary sequence 1(1),11(3),111(7),1111(15),11111(31)....
constexpr const char *STATE_DIR_PATH = "/state"; // State directory name.
struct fd_pair
{
@@ -59,8 +60,8 @@ namespace sc
// Whether the contract should execute in read only mode (to serve read requests).
bool readonly = false;
// State dir path to be used for this execution.
std::string state_dir;
// Hpfs dir path to be used for this execution.
std::string hpfs_dir;
// Map of user I/O buffers (map key: user binary public key).
// The value is a pair holding consensus-verified inputs and contract-generated outputs.
@@ -131,10 +132,6 @@ namespace sc
}
};
int init();
void deinit();
int execute_contract(execution_context &ctx);
//------Internal-use functions for this namespace.

View File

@@ -1,28 +0,0 @@
#include "state_common.hpp"
#include "../hpfs/hpfs.hpp"
#include "../hplog.hpp"
namespace state_common
{
state_context ctx;
/**
* Get the contract state hash.
*/
int init()
{
util::h32 initial_state;
if (hpfs::start_fs_session(conf::ctx.state_rw_dir) == -1 ||
hpfs::get_hash(initial_state, conf::ctx.state_rw_dir, "/") == -1 ||
hpfs::stop_fs_session(conf::ctx.state_rw_dir) == -1)
{
LOG_ERROR << "Failed to get initial state hash.";
return -1;
}
ctx.set_state(initial_state);
LOG_INFO << "Initial state: " << initial_state;
return 0;
}
} // namespace state_common

View File

@@ -1,43 +0,0 @@
#ifndef _HP_STATE_STATE_COMMON_
#define _HP_STATE_STATE_COMMON_
#include "../pchheader.hpp"
#include "../conf.hpp"
#include "../util/h32.hpp"
namespace state_common
{
constexpr size_t BLOCK_SIZE = 4 * 1024 * 1024; // 4MB;
inline uint16_t get_request_resubmit_timeout()
{
return conf::cfg.contract.roundtime;
}
struct state_context
{
private:
util::h32 state;
std::shared_mutex state_mutex;
public:
util::h32 get_state()
{
std::shared_lock lock(state_mutex);
return state;
}
void set_state(util::h32 new_state)
{
std::unique_lock lock(state_mutex);
state = new_state;
}
};
extern state_context ctx;
int init();
} // namespace state_common
#endif

View File

@@ -218,8 +218,8 @@ namespace read_req
void initialize_execution_context(const user_read_req &read_request, const pthread_t thread_id, sc::execution_context &contract_ctx)
{
// Create new folder with the thread id per each thread.
contract_ctx.args.state_dir = conf::ctx.state_dir;
contract_ctx.args.state_dir.append("/rr_").append(std::to_string(thread_id));
contract_ctx.args.hpfs_dir = conf::ctx.hpfs_dir;
contract_ctx.args.hpfs_dir.append("/rr_").append(std::to_string(thread_id));
contract_ctx.args.readonly = true;
sc::contract_iobufs user_bufs;
user_bufs.inputs.push_back(read_request.content);

View File

@@ -389,7 +389,7 @@ namespace usr
util::fork_detach();
// before execution chdir into a valid the latest state data directory that contains an appbill.table
chdir(conf::ctx.state_rw_dir.c_str());
chdir(conf::ctx.hpfs_rw_dir.c_str());
int ret = execv(execv_args[0], execv_args);
std::cerr << errno << ": Appbill process execv failed.\n";
return false;

View File

@@ -355,6 +355,15 @@ namespace util
return 0;
}
// Returns the file/dir name of the given path.
const std::string get_name(std::string_view path)
{
char *path2 = strdup(path.data());
const std::string name = basename(path2);
free(path2);
return name;
}
/**
* Create a record lock for the file descriptor. Lock is associated with the process (Not for forked child processes).
* @param fd File descriptor to be locked.

View File

@@ -78,6 +78,8 @@ namespace util
int stoull(const std::string &str, uint64_t &result);
const std::string get_name(std::string_view path);
int set_lock(const int fd, struct flock &lock, const bool is_rwlock, const off_t start, const off_t len);
int release_lock(const int fd, struct flock &lock);

View File

@@ -172,13 +172,13 @@ done
for (( i=1; i<=$ncount; i++ ))
do
mkdir -p ./node$i/state/seed > /dev/null 2>&1
mkdir -p ./node$i/hpfs/seed/ > /dev/null 2>&1
pushd ./node$i/state/seed/ > /dev/null 2>&1
pushd ./node$i/hpfs/seed/state/ > /dev/null 2>&1
# Load credit balance for user for appbill testing purposes.
>appbill.table
../../../../bin/appbill --credit "705bf26354ee4c63c0e5d5d883c07cefc3196d049bd3825f827eb3bc23ead035" 10000
../../../../../bin/appbill --credit "705bf26354ee4c63c0e5d5d883c07cefc3196d049bd3825f827eb3bc23ead035" 10000
# Copy any more initial state files for testing.
# cp ~/my_big_file .