bug fixes, ensure import invariant is correct

This commit is contained in:
Richard Holland
2023-07-11 13:19:21 +00:00
parent f06124e8c7
commit 4f86551fb3
4 changed files with 22 additions and 33 deletions

View File

@@ -1109,8 +1109,11 @@ validateGuards(
{
for (auto const& [import_idx, api_name] : usage->second)
{
auto const& api_signature =
hook_api::import_whitelist.find(api_name)->second;
auto const& api_signature =
hook_api::import_whitelist.find(api_name) != hook_api::import_whitelist.end()
? hook_api::import_whitelist.find(api_name)->second
: hook_api::import_whitelist_1.find(api_name)->second;
if (!first_signature)
{

View File

@@ -5521,7 +5521,7 @@ DEFINE_HOOK_FUNCTION(
if (slot_into_tx > hook_api::max_slots || slot_into_meta > hook_api::max_slots)
return INVALID_ARGUMENT;
size_t free_count = hookCtx.slot_free.size();
size_t free_count = hook_api::max_slots - hookCtx.slot.size();
size_t needed_count =
slot_into_tx == 0 && slot_into_meta == 0 ? 2 : slot_into_tx != 0 && slot_into_meta != 0 ? 0 : 1;

View File

@@ -280,19 +280,6 @@ Import::preflight(PreflightContext const& ctx)
return telWRONG_NETWORK;
}
/*
// ensure the inner txn is an accountset or signerlistset
auto const tt = stpTrans->getTxnType();
if (tt != ttACCOUNT_SET && tt != ttSIGNER_LIST_SET && tt != ttREGULAR_KEY_SET)
{
JLOG(ctx.j.warn())
<< "Import: inner txn must be an AccountSet, SetRegularKey or SignerListSet transaction. "
<< tx.getTransactionID();
return temMALFORMED;
}
*/
// check if the inner transaction is signed using the same keying as the outer txn
{
auto outer = tx.getSigningPubKey();
@@ -838,20 +825,6 @@ Import::preflight(PreflightContext const& ctx)
return temMALFORMED;
}
/*
* RH TODO: put this in preclaim, place sequence on an unowned object
else if (sequence < listCollection.current.sequence)
{
return ListDisposition::stale;
}
else if (sequence == listCollection.current.sequence)
return ListDisposition::same_sequence;
*/
//
// finally in preclaim check the sfImportSequence field on the account
// if it is less than the Account Sequence in the xpop then mint and
// update sfImportSequence
// Duplicate / Sanity
if (!stpTrans->isFieldPresent(sfSequence) ||
!stpTrans->isFieldPresent(sfFee) ||
@@ -862,11 +835,18 @@ Import::preflight(PreflightContext const& ctx)
<< tx.getTransactionID();
return temMALFORMED;
}
if (stpTrans->getFieldAmount(sfFee) < beast::zero)
{
JLOG(ctx.j.warn())
<< "Import: xpop contained negative fee. "
<< tx.getTransactionID();
return temMALFORMED;
}
return preflight2(ctx);
}
// RH TODO: manifest serials should be kept on chain
TER
Import::preclaim(PreclaimContext const& ctx)
{

View File

@@ -196,7 +196,13 @@ XRPNotCreated::finalize(
<< " drops_: " << drops_
<< " dropsAdded - fee.drops(): " << dropsAdded - fee.drops();
return (drops_ == dropsAdded.drops() - fee.drops());
int64_t drops = dropsAdded.drops() - fee.drops();
// catch any overflow or funny business
if (drops > dropsAdded.drops() || drops > fee.drops())
return false;
return drops_ == drops;
}