mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
[FOLD] First round of review changes
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
declare user options/settings
|
||||
#]===================================================================]
|
||||
|
||||
option (assert "Enables asserts, even in release builds" ON)
|
||||
option (assert "Enables asserts, even in release builds" OFF)
|
||||
|
||||
option (reporting "Build rippled with reporting mode enabled" OFF)
|
||||
|
||||
|
||||
@@ -218,6 +218,7 @@ namespace hook_api
|
||||
RESERVE_INSUFFICIENT = -38, // setting a new state object would exceed account reserve
|
||||
COMPLEX_NOT_SUPPORTED = -39,
|
||||
DOES_NOT_MATCH = -40, // two keylets were required to be the same type but werent
|
||||
INVALID_KEY = -41, // user supplied key was not valid
|
||||
|
||||
};
|
||||
|
||||
@@ -229,10 +230,10 @@ namespace hook_api
|
||||
ACCEPT = 3,
|
||||
};
|
||||
|
||||
const int max_slots = 255;
|
||||
const int max_nonce = 255;
|
||||
const int max_emit = 255;
|
||||
const int max_params = 16;
|
||||
const uint8_t max_slots = 255;
|
||||
const uint8_t max_nonce = 255;
|
||||
const uint8_t max_emit = 255;
|
||||
const uint8_t max_params = 16;
|
||||
const double fee_base_multiplier = 1.1f;
|
||||
|
||||
|
||||
|
||||
@@ -254,7 +254,7 @@ namespace hook
|
||||
bool isCallback,
|
||||
bool isStrongTSH,
|
||||
uint32_t wasmParam,
|
||||
int32_t hookChainPosition,
|
||||
uint8_t hookChainPosition,
|
||||
// result of apply() if this is weak exec
|
||||
std::shared_ptr<STObject const> const& provisionalMeta
|
||||
);
|
||||
@@ -306,7 +306,7 @@ namespace hook
|
||||
bool isStrong = false;
|
||||
uint32_t wasmParam = 0;
|
||||
uint32_t overrideCount = 0;
|
||||
int32_t hookChainPosition = -1;
|
||||
uint8_t hookChainPosition = 0;
|
||||
bool foreignStateSetDisabled = false;
|
||||
bool executeAgainAsWeak = false; // hook_again allows strong pre-apply to nominate
|
||||
// additional weak post-apply execution
|
||||
@@ -330,14 +330,14 @@ namespace hook
|
||||
// keep the underlying object alive for the duration of the hook's execution
|
||||
// slot number -> { keylet or hash, { pointer to current object, storage for that object } }
|
||||
std::map<int, SlotEntry> slot {};
|
||||
int slot_counter { 1 };
|
||||
uint8_t slot_counter { 1 };
|
||||
std::queue<int> slot_free {};
|
||||
int64_t expected_etxn_count { -1 }; // make this a 64bit int so the uint32 from the hookapi cant overflow it
|
||||
int emit_nonce_counter { 0 }; // incremented whenever nonce is called to ensure unique nonces
|
||||
int ledger_nonce_counter { 0 };
|
||||
uint8_t emit_nonce_counter { 0 }; // incremented whenever nonce is called to ensure unique nonces
|
||||
uint8_t ledger_nonce_counter { 0 };
|
||||
std::map<ripple::uint256, bool> nonce_used {};
|
||||
uint32_t generation = 0; // used for caching, only generated when txn_generation is called
|
||||
int64_t burden = 0; // used for caching, only generated when txn_burden is called
|
||||
uint64_t burden = 0; // used for caching, only generated when txn_burden is called
|
||||
std::map<uint32_t, uint32_t> guard_map {}; // iteration guard map <id -> upto_iteration>
|
||||
HookResult result;
|
||||
std::optional<ripple::STObject> emitFailure; // if this is a callback from a failed
|
||||
|
||||
@@ -464,14 +464,13 @@ std::optional<ripple::Keylet>
|
||||
unserialize_keylet(uint8_t* ptr, uint32_t len)
|
||||
{
|
||||
if (len != 34)
|
||||
return std::nullopt;
|
||||
return {};
|
||||
|
||||
uint16_t ktype =
|
||||
((uint16_t)ptr[0] << 8) +
|
||||
((uint16_t)ptr[1]);
|
||||
|
||||
ripple::Keylet reconstructed { (ripple::LedgerEntryType)ktype, ripple::uint256::fromVoid(ptr + 2) };
|
||||
return reconstructed;
|
||||
return ripple::Keylet{ static_cast<LedgerEntryType>(ktype), ripple::uint256::fromVoid(ptr + 2) };
|
||||
}
|
||||
|
||||
|
||||
@@ -501,7 +500,6 @@ bool hook::isEmittedTxn(ripple::STTx const& tx)
|
||||
}
|
||||
|
||||
|
||||
#define U32MAX ((uint32_t)(-1))
|
||||
int64_t hook::computeExecutionFee(uint64_t instructionCount)
|
||||
{
|
||||
int64_t fee = (int64_t)instructionCount;
|
||||
@@ -605,7 +603,7 @@ hook::setHookState(
|
||||
bool createNew = !hookState;
|
||||
|
||||
// if the blob is nil then delete the entry if it exists
|
||||
if (data.size() == 0)
|
||||
if (data.empty())
|
||||
{
|
||||
|
||||
if (!view.peek(hookStateKeylet))
|
||||
@@ -722,21 +720,11 @@ hook::setHookState(
|
||||
// update namespace vector where necessary
|
||||
if (!nsExists)
|
||||
{
|
||||
if (!sleAccount->isFieldPresent(sfHookNamespaces))
|
||||
{
|
||||
sleAccount->setFieldV256(sfHookNamespaces, STVector256{std::vector<uint256>{ns}});
|
||||
view.update(sleAccount);
|
||||
}
|
||||
else
|
||||
{
|
||||
STVector256 const& vec = sleAccount->getFieldV256(sfHookNamespaces);
|
||||
std::vector<uint256> nv { vec.value() };
|
||||
nv.push_back(ns);
|
||||
sleAccount->setFieldV256(sfHookNamespaces, STVector256{std::move(nv)});
|
||||
view.update(sleAccount);
|
||||
}
|
||||
STVector256 vec = sleAccount->getFieldV256(sfHookNamespaces);
|
||||
vec.push_back(ns);
|
||||
sleAccount->setFieldV256(sfHookNamespaces, vec);
|
||||
view.update(sleAccount);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -769,7 +757,7 @@ hook::apply(
|
||||
bool isCallback,
|
||||
bool isStrong,
|
||||
uint32_t wasmParam,
|
||||
int32_t hookChainPosition,
|
||||
uint8_t hookChainPosition,
|
||||
std::shared_ptr<STObject const> const& provisionalMeta)
|
||||
{
|
||||
|
||||
@@ -1406,7 +1394,7 @@ finalizeHookResult(
|
||||
keylet::emittedDir(),
|
||||
emittedId,
|
||||
[&](SLE::ref sle) {
|
||||
// RH TODO: should something be here?
|
||||
(*sle)[sfFlags] = lsfEmittedDir;
|
||||
});
|
||||
|
||||
|
||||
@@ -2351,7 +2339,7 @@ DEFINE_HOOK_FUNCTION(
|
||||
return INVALID_ARGUMENT;
|
||||
|
||||
ripple::AccountID id =
|
||||
ripple::base_uint<160, ripple::detail::AccountIDTag>::fromVoid(memory + read_ptr);
|
||||
AccountID::fromVoid(memory + read_ptr);
|
||||
|
||||
ripple::Keylet kl =
|
||||
keylet_type == keylet_code::HOOK ? ripple::keylet::hook(id) :
|
||||
@@ -2382,7 +2370,7 @@ DEFINE_HOOK_FUNCTION(
|
||||
return INVALID_ARGUMENT;
|
||||
|
||||
ripple::AccountID id =
|
||||
ripple::base_uint<160, ripple::detail::AccountIDTag>::fromVoid(memory + read_ptr);
|
||||
AccountID::fromVoid(memory + read_ptr);
|
||||
|
||||
ripple::Keylet kl =
|
||||
keylet_type == keylet_code::CHECK ? ripple::keylet::check(id, c) :
|
||||
@@ -2434,7 +2422,7 @@ DEFINE_HOOK_FUNCTION(
|
||||
|
||||
ripple::Keylet kl =
|
||||
ripple::keylet::hookState(
|
||||
ripple::base_uint<160, ripple::detail::AccountIDTag>::fromVoid(memory + aread_ptr),
|
||||
AccountID::fromVoid(memory + aread_ptr),
|
||||
ripple::base_uint<256>::fromVoid(memory + kread_ptr),
|
||||
ripple::base_uint<256>::fromVoid(memory + nread_ptr));
|
||||
|
||||
@@ -2464,13 +2452,30 @@ DEFINE_HOOK_FUNCTION(
|
||||
if (a != 0 || b != 0 || c != 0 || d != 0 || e != 0 || f != 0)
|
||||
return INVALID_ARGUMENT;
|
||||
|
||||
ripple::Keylet kl =
|
||||
keylet_type == keylet_code::AMENDMENTS ? ripple::keylet::amendments() :
|
||||
keylet_type == keylet_code::FEES ? ripple::keylet::fees() :
|
||||
keylet_type == keylet_code::NEGATIVE_UNL ? ripple::keylet::negativeUNL() :
|
||||
ripple::keylet::emittedDir();
|
||||
auto makeKeyCache = [](ripple::Keylet kl) -> std::array<uint8_t, 34>
|
||||
{
|
||||
std::array<uint8_t, 34> d;
|
||||
|
||||
return serialize_keylet(kl, memory, write_ptr, write_len);
|
||||
d[0] = (kl.type >> 8) & 0xFFU;
|
||||
d[1] = (kl.type >> 0) & 0xFFU;
|
||||
for (int i = 0; i < 32; ++i)
|
||||
d[2 + i] = kl.key.data()[i];
|
||||
|
||||
return d;
|
||||
};
|
||||
|
||||
static std::array<uint8_t, 34> cAmendments = makeKeyCache(ripple::keylet::amendments());
|
||||
static std::array<uint8_t, 34> cFees = makeKeyCache(ripple::keylet::fees());
|
||||
static std::array<uint8_t, 34> cNegativeUNL = makeKeyCache(ripple::keylet::negativeUNL());
|
||||
static std::array<uint8_t, 34> cEmittedDir = makeKeyCache(ripple::keylet::emittedDir());
|
||||
|
||||
WRITE_WASM_MEMORY_AND_RETURN(
|
||||
write_ptr, write_len,
|
||||
keylet_type == keylet_code::AMENDMENTS ? cAmendments.data() :
|
||||
keylet_type == keylet_code::FEES ? cFees.data() :
|
||||
keylet_type == keylet_code::NEGATIVE_UNL ? cNegativeUNL.data() :
|
||||
cEmittedDir.data(), 34,
|
||||
memory, memory_length);
|
||||
}
|
||||
|
||||
case keylet_code::LINE:
|
||||
@@ -2488,12 +2493,10 @@ DEFINE_HOOK_FUNCTION(
|
||||
if (hi_len != 20 || lo_len != 20 || cu_len != 20)
|
||||
return INVALID_ARGUMENT;
|
||||
|
||||
ripple::AccountID a0 = ripple::base_uint<160, ripple::detail::AccountIDTag>::fromVoid(memory + hi_ptr);
|
||||
ripple::AccountID a1 = ripple::base_uint<160, ripple::detail::AccountIDTag>::fromVoid(memory + lo_ptr);
|
||||
ripple::Currency cu = ripple::base_uint<160, ripple::detail::CurrencyTag>::fromVoid(memory + cu_ptr);
|
||||
|
||||
ripple::Keylet kl =
|
||||
ripple::keylet::line(a0, a1, cu);
|
||||
auto kl = ripple::keylet::line(
|
||||
AccountID::fromVoid(memory + hi_ptr),
|
||||
AccountID::fromVoid(memory + lo_ptr),
|
||||
Currency::fromVoid(memory + cu_ptr));
|
||||
return serialize_keylet(kl, memory, write_ptr, write_len);
|
||||
}
|
||||
|
||||
@@ -2517,9 +2520,9 @@ DEFINE_HOOK_FUNCTION(
|
||||
return INVALID_ARGUMENT;
|
||||
|
||||
ripple::AccountID aid =
|
||||
ripple::base_uint<160, ripple::detail::AccountIDTag>::fromVoid(memory + aread_ptr);
|
||||
AccountID::fromVoid(memory + aread_ptr);
|
||||
ripple::AccountID bid =
|
||||
ripple::base_uint<160, ripple::detail::AccountIDTag>::fromVoid(memory + bread_ptr);
|
||||
AccountID::fromVoid(memory + bread_ptr);
|
||||
|
||||
ripple::Keylet kl =
|
||||
ripple::keylet::depositPreauth(aid, bid);
|
||||
@@ -2547,9 +2550,9 @@ DEFINE_HOOK_FUNCTION(
|
||||
return INVALID_ARGUMENT;
|
||||
|
||||
ripple::AccountID aid =
|
||||
ripple::base_uint<160, ripple::detail::AccountIDTag>::fromVoid(memory + aread_ptr);
|
||||
AccountID::fromVoid(memory + aread_ptr);
|
||||
ripple::AccountID bid =
|
||||
ripple::base_uint<160, ripple::detail::AccountIDTag>::fromVoid(memory + bread_ptr);
|
||||
AccountID::fromVoid(memory + bread_ptr);
|
||||
|
||||
ripple::Keylet kl =
|
||||
ripple::keylet::payChan(aid, bid, e);
|
||||
@@ -2612,6 +2615,13 @@ DEFINE_HOOK_FUNCTION(
|
||||
return EMISSION_FAILURE;
|
||||
}
|
||||
|
||||
if (isPseudoTx(*stpTrans))
|
||||
{
|
||||
JLOG(j.trace())
|
||||
<< "HookEmit[" << HC_ACC() << "]: Attempted to emit pseudo txn.";
|
||||
return EMISSION_FAILURE;
|
||||
}
|
||||
|
||||
// check the emitted txn is valid
|
||||
/* Emitted TXN rules
|
||||
* 1. Sequence: 0
|
||||
@@ -2966,7 +2976,7 @@ DEFINE_HOOK_FUNCTION(
|
||||
|
||||
std::optional<Account> acc = hookCtx.result.account;
|
||||
if (aread_len == 20 && !(NOT_IN_BOUNDS(aread_ptr, aread_len, memory_length)))
|
||||
acc = ripple::base_uint<160, ripple::detail::AccountIDTag>::fromVoid(memory + aread_ptr);
|
||||
acc = AccountID::fromVoid(memory + aread_ptr);
|
||||
|
||||
assert(kl || hookno);
|
||||
|
||||
@@ -3788,6 +3798,10 @@ DEFINE_HOOK_FUNCTION(
|
||||
ripple::Slice keyslice {reinterpret_cast<const void*>(kread_ptr + memory), kread_len};
|
||||
ripple::Slice data {reinterpret_cast<const void*>(dread_ptr + memory), dread_len};
|
||||
ripple::Slice sig {reinterpret_cast<const void*>(sread_ptr + memory), sread_len};
|
||||
|
||||
if (!publicKeyType(keyslice))
|
||||
return INVALID_KEY;
|
||||
|
||||
ripple::PublicKey key { keyslice };
|
||||
return verify(key, data, sig, false) ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -779,9 +779,6 @@ run(int argc, char** argv)
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
// Must be outside the namespace for obvious reasons
|
||||
//
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
|
||||
@@ -1500,7 +1500,7 @@ SetHook::setHook()
|
||||
// do any pending removals
|
||||
for (auto const& p : keyletsToDestroy)
|
||||
{
|
||||
auto const& sle = view().peek(p);
|
||||
auto const sle = view().peek(p);
|
||||
if (!sle)
|
||||
continue;
|
||||
if (sle->isFieldPresent(sfReferenceCount))
|
||||
|
||||
@@ -941,7 +941,7 @@ executeHookChain(
|
||||
>> hookParamOverrides {};
|
||||
|
||||
auto const& hooks = hookSLE->getFieldArray(sfHooks);
|
||||
int hook_no = 0;
|
||||
uint8_t hook_no = 0;
|
||||
|
||||
for (auto const& hook : hooks)
|
||||
{
|
||||
@@ -1105,7 +1105,7 @@ Transactor::doHookCallback(std::shared_ptr<STObject const> const& provisionalMet
|
||||
|
||||
bool found = false;
|
||||
auto const& hooks = hooksCallback->getFieldArray(sfHooks);
|
||||
int hook_no = 0;
|
||||
uint8_t hook_no = 0;
|
||||
for (auto const& hook : hooks)
|
||||
{
|
||||
hook_no++;
|
||||
@@ -1352,7 +1352,7 @@ doTSH(
|
||||
}
|
||||
|
||||
void
|
||||
Transactor::doAaw(
|
||||
Transactor::doAgainAsWeak(
|
||||
AccountID const& hookAccountID,
|
||||
std::set<uint256> const& hookHashes,
|
||||
hook::HookStateMap& stateMap,
|
||||
@@ -1377,7 +1377,7 @@ Transactor::doAaw(
|
||||
}
|
||||
|
||||
auto const& hooks = hooksArray->getFieldArray(sfHooks);
|
||||
int hook_no = 0;
|
||||
uint8_t hook_no = 0;
|
||||
for (auto const& hook : hooks)
|
||||
{
|
||||
hook_no++;
|
||||
@@ -1566,7 +1566,7 @@ Transactor::operator()()
|
||||
if (ctx_.size() > oversizeMetaDataCap)
|
||||
result = tecOVERSIZE;
|
||||
|
||||
if ((isTecClaim(result) && (view().flags() & tapFAIL_HARD)))
|
||||
if (isTecClaim(result) && (view().flags() & tapFAIL_HARD))
|
||||
{
|
||||
// If the tapFAIL_HARD flag is set, a tec result
|
||||
// must not do anything
|
||||
@@ -1702,7 +1702,7 @@ Transactor::operator()()
|
||||
|
||||
// execute any hooks that nominated for 'again as weak'
|
||||
for (auto const& [accID, hookHashes] : aawMap)
|
||||
doAaw(accID, hookHashes, stateMap, weakResults, proMeta);
|
||||
doAgainAsWeak(accID, hookHashes, stateMap, weakResults, proMeta);
|
||||
|
||||
// write hook results
|
||||
hook::finalizeHookState(stateMap, ctx_, ctx_.tx.getTransactionID());
|
||||
|
||||
@@ -201,7 +201,7 @@ protected:
|
||||
// a hook that which is being executed pre-application of the otxn
|
||||
// to request an additional post-application execution.
|
||||
void
|
||||
doAaw(
|
||||
doAgainAsWeak(
|
||||
AccountID const& hookAccountID,
|
||||
std::set<uint256> const& hookHashes,
|
||||
hook::HookStateMap& stateMap,
|
||||
|
||||
@@ -278,6 +278,7 @@ enum LedgerSpecificFlags {
|
||||
// ltDIR_NODE
|
||||
lsfNFTokenBuyOffers = 0x00000001,
|
||||
lsfNFTokenSellOffers = 0x00000002,
|
||||
lsfEmittedDir = 0x00000004,
|
||||
|
||||
// ltNFTOKEN_OFFER
|
||||
lsfSellNFToken = 0x00000001,
|
||||
|
||||
Reference in New Issue
Block a user