Already submitted input detection. (#170)

* Added same nonce/sig for input comparison.
* Added status response withholding for already submitted inputs.
This commit is contained in:
Ravin Perera
2020-11-26 23:27:40 +05:30
committed by GitHub
parent d476f787a7
commit 4de1bb2393
5 changed files with 49 additions and 27 deletions

View File

@@ -151,7 +151,8 @@ namespace usr
uint64_t max_lcl_seqno;
parser.extract_input_container(input_data, nonce, max_lcl_seqno, input_container);
if (nonce_map.is_valid(user.pubkey, nonce, true))
const int nonce_status = nonce_map.check(user.pubkey, nonce, sig, true);
if (nonce_status == 0)
{
//Add to the submitted input list.
user.submitted_inputs.push_back(user_input(
@@ -162,7 +163,8 @@ namespace usr
}
else
{
send_input_status(parser, user.session, msg::usrmsg::STATUS_REJECTED, msg::usrmsg::REASON_NONCE_EXPIRED, sig);
const char *reason = nonce_status == 1 ? msg::usrmsg::REASON_NONCE_EXPIRED : msg::usrmsg::REASON_ALREADY_SUBMITTED;
send_input_status(parser, user.session, msg::usrmsg::STATUS_REJECTED, reason, sig);
return -1;
}
}
@@ -301,10 +303,11 @@ namespace usr
return msg::usrmsg::REASON_MAX_LEDGER_EXPIRED;
}
if (!nonce_map.is_valid(user_pubkey, nonce))
const int nonce_status = nonce_map.check(user_pubkey, nonce, umsg.sig);
if (nonce_status > 0)
{
LOG_DEBUG << "User message nonce expired.";
return msg::usrmsg::REASON_NONCE_EXPIRED;
LOG_DEBUG << (nonce_status == 1 ? "User message nonce expired." : "User message with same nonce/sig already submitted.");
return (nonce_status == 1 ? msg::usrmsg::REASON_NONCE_EXPIRED : msg::usrmsg::REASON_ALREADY_SUBMITTED);
}
// Keep checking the subtotal of inputs extracted so far with the appbill account balance.