Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare Hook API [DO NOT MERGE] #413

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ripple/app/hook/Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,5 +434,9 @@ static const std::map<std::string, std::vector<uint8_t>> import_whitelist{
// featureHooks1
static const std::map<std::string, std::vector<uint8_t>> import_whitelist_1{
{"xpop_slot", {0x7EU, 0x7FU, 0x7FU}}};
// featureHooks2
static const std::map<std::string, std::vector<uint8_t>> import_whitelist_2{
{"prepare", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}}};
}; // namespace hook_api

#endif
13 changes: 12 additions & 1 deletion src/ripple/app/hook/Guard.h
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,13 @@ validateGuards(
{
// PASS, this is a version 1 api
}
else if (
rulesVersion > 1 &&
hook_api::import_whitelist_2.find(import_name) !=
hook_api::import_whitelist_2.end())
{
// PASS, this is a version 2 api
}
else
{
GUARDLOG(hook::log::IMPORT_ILLEGAL)
Expand Down Expand Up @@ -1234,7 +1241,11 @@ validateGuards(
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)
: hook_api::import_whitelist_1.find(api_name) !=
hook_api::import_whitelist_1.end()
? hook_api::import_whitelist_1.find(api_name)
->second
: hook_api::import_whitelist_2.find(api_name)
->second;

if (!first_signature)
Expand Down
8 changes: 8 additions & 0 deletions src/ripple/app/hook/applyHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ DECLARE_HOOK_FUNCTION(
etxn_nonce,
uint32_t write_ptr,
uint32_t write_len);
DECLARE_HOOK_FUNCTION(
int64_t,
prepare,
uint32_t write_ptr,
uint32_t write_len,
uint32_t read_ptr,
uint32_t read_len);
DECLARE_HOOK_FUNCTION(
int64_t,
emit,
Expand Down Expand Up @@ -802,6 +809,7 @@ class HookExecutor
ADD_HOOK_FUNCTION(sto_erase, ctx);
ADD_HOOK_FUNCTION(util_keylet, ctx);

ADD_HOOK_FUNCTION(prepare, ctx);
ADD_HOOK_FUNCTION(emit, ctx);
ADD_HOOK_FUNCTION(etxn_burden, ctx);
ADD_HOOK_FUNCTION(etxn_fee_base, ctx);
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/hook/guard_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ main(int argc, char** argv)

close(fd);

auto result = validateGuards(hook, std::cout, "", 1);
auto result = validateGuards(hook, std::cout, "", 2);

if (!result)
{
Expand Down
Loading
Loading