Migrated user inputs from domain sockets to memfd. (#159)

This commit is contained in:
Ravin Perera
2020-11-23 21:52:05 +05:30
committed by GitHub
parent bf710c6bde
commit 9c1f62dbde
18 changed files with 512 additions and 527 deletions

View File

@@ -162,7 +162,8 @@ namespace consensus
// Prepare the consensus candidate user inputs that we have acumulated so far. (We receive them periodically via NUPs)
// The candidate inputs will be included in the new round proposal.
verify_and_populate_candidate_user_inputs(lcl_seq_no);
if (verify_and_populate_candidate_user_inputs(lcl_seq_no) == -1)
return -1;
const p2p::proposal new_round_prop = create_new_round_proposal(lcl, state);
broadcast_proposal(new_round_prop);
@@ -385,7 +386,7 @@ namespace consensus
* Verifies the user signatures and populate non-expired user inputs from collected
* non-unl proposals (if any) into consensus candidate data.
*/
void verify_and_populate_candidate_user_inputs(const uint64_t lcl_seq_no)
int verify_and_populate_candidate_user_inputs(const uint64_t lcl_seq_no)
{
// Move over NUPs collected from the network into a local list.
std::list<p2p::nonunl_proposal> collected_nups;
@@ -433,17 +434,21 @@ namespace consensus
}
else
{
std::string hash, input;
util::buffer_view input;
std::string hash;
uint64_t max_lcl_seqno;
reject_reason = usr::validate_user_input_submission(pubkey, umsg, lcl_seq_no, total_input_len, recent_user_input_hashes,
hash, input, max_lcl_seqno);
if (input.is_null())
return -1;
if (reject_reason == NULL)
{
// No reject reason means we should go ahead and subject the input to consensus.
ctx.candidate_user_inputs.try_emplace(
hash,
candidate_user_input(pubkey, std::move(input), max_lcl_seqno));
candidate_user_input(pubkey, input, max_lcl_seqno));
}
else if (reject_reason == msg::usrmsg::REASON_APPBILL_BALANCE_EXCEEDED)
{
@@ -486,6 +491,8 @@ namespace consensus
}
}
}
return 0;
}
p2p::proposal create_new_round_proposal(std::string_view lcl, hpfs::h32 state)
@@ -732,7 +739,7 @@ namespace consensus
{
{
std::scoped_lock lock(ctx.contract_ctx_mutex);
ctx.contract_ctx.emplace();
ctx.contract_ctx.emplace(usr::input_store);
}
sc::contract_execution_args &args = ctx.contract_ctx->args;
@@ -742,7 +749,8 @@ namespace consensus
args.lcl = new_lcl;
// Populate user bufs.
feed_user_inputs_to_contract_bufmap(args.userbufs, cons_prop);
if (feed_user_inputs_to_contract_bufmap(args.userbufs, cons_prop) == -1)
return -1;
if (sc::execute_contract(ctx.contract_ctx.value()) == -1)
{
@@ -814,7 +822,7 @@ namespace consensus
* @param bufmap The contract bufmap which needs to be populated with inputs.
* @param cons_prop The proposal that achieved consensus.
*/
void feed_user_inputs_to_contract_bufmap(sc::contract_bufmap_t &bufmap, const p2p::proposal &cons_prop)
int feed_user_inputs_to_contract_bufmap(sc::contract_bufmap_t &bufmap, const p2p::proposal &cons_prop)
{
// Populate the buf map with all currently connected users regardless of whether they have inputs or not.
// This is in case the contract wanted to emit some data to a user without needing any input.
@@ -830,26 +838,22 @@ namespace consensus
const bool hashfound = (itr != ctx.candidate_user_inputs.end());
if (!hashfound)
{
LOG_ERROR << "input required but wasn't in our candidate inputs map, this will potentially cause desync.";
// TODO: consider fatal
LOG_ERROR << "Input required but wasn't in our candidate inputs map, this will potentially cause desync.";
return -1;
}
else
{
// Populate the input content into the bufmap.
candidate_user_input &cand_input = itr->second;
std::string inputtofeed;
inputtofeed.swap(cand_input.input);
sc::contract_iobufs &bufs = bufmap[cand_input.userpubkey];
bufs.inputs.push_back(std::move(inputtofeed));
sc::contract_iobufs &contract_user = bufmap[cand_input.userpubkey];
contract_user.inputs.push_back(cand_input.input);
// Remove the input from the candidate set because we no longer need it.
//LOG_DEBUG << "candidate input deleted.";
ctx.candidate_user_inputs.erase(itr);
}
}
return 0;
}
/**