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

feat: simulate RPC to dry-run a tx (XLS-69d) #5069

Open
wants to merge 77 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
7520ed4
Initial simulate implementation (correct error code, no metadata)
mvadari May 24, 2024
d151a20
fix print statement
mvadari May 28, 2024
4ab69aa
get metadata to work
mvadari Jul 9, 2024
360ed6a
clean up
mvadari Jul 9, 2024
628e1e3
add basic tx_json support
mvadari Jul 9, 2024
0149c65
basic tests
mvadari Jul 10, 2024
f555b73
autofill fee
mvadari Jul 10, 2024
51cf3c6
autofill Sequence/SigningPubKey/TxnSignature
mvadari Jul 10, 2024
04e76d2
better erroring
mvadari Jul 10, 2024
eb691dc
run tx_blob through autofilling
mvadari Jul 10, 2024
26f3bb6
cleanup
mvadari Jul 10, 2024
3b4b354
simplify transaction engine exceptions
mvadari Jul 11, 2024
5c383a9
fix rebase issues
mvadari Jul 11, 2024
b6bf4c5
fix clang-format
mvadari Jul 11, 2024
d703935
add ledger_index
mvadari Jul 16, 2024
4489fae
update API changelog
mvadari Jul 16, 2024
449b2c6
better param validation
mvadari Jul 16, 2024
fa246bb
add tests
mvadari Jul 17, 2024
3fadb8d
add command line version
mvadari Jul 17, 2024
08b65d0
rename params
mvadari Jul 18, 2024
e217dc1
better binary/tx_blob testing
mvadari Jul 18, 2024
d824daf
test CLI version
mvadari Jul 18, 2024
cc011c0
improve codecov
mvadari Jul 18, 2024
db7ad89
more codecov tests
mvadari Jul 18, 2024
b30b3b9
fix tests
mvadari Jul 18, 2024
f222f44
add public key support
mvadari Jul 19, 2024
a3c0bb4
update field names
mvadari Jul 22, 2024
6c6ecc4
fix fee issues
mvadari Jul 22, 2024
c8f3862
backwards compatibility
mvadari Jul 22, 2024
03cae0d
add tests
mvadari Jul 23, 2024
4aa5a3f
add comment
mvadari Jul 23, 2024
a0c472f
add test for sign-and-submit higher base fee tx
mvadari Jul 23, 2024
b3ec935
add NetworkID support
mvadari Jul 23, 2024
d712dc9
add Signers and Signer to jss
mvadari Jul 23, 2024
834965b
Revert "add NetworkID support"
mvadari Jul 23, 2024
96599a2
Merge branch 'develop' into simulate
mvadari Jul 23, 2024
22fdaf7
handle blob errors better
mvadari Jul 24, 2024
c977d97
Merge branch 'develop' into simulate
mvadari Jul 29, 2024
4c1f93f
remove unneeded check
mvadari Jul 30, 2024
270fd02
fix tests
mvadari Jul 30, 2024
a3510c4
add signing failure test
mvadari Jul 31, 2024
588ed7f
Merge branch 'develop' into simulate
mvadari Jul 31, 2024
edfb185
Merge branch 'develop' into simulate
mvadari Aug 1, 2024
856c9fa
Merge branch 'develop' into simulate
mvadari Sep 11, 2024
01e5683
Merge branch 'develop' into simulate
mvadari Sep 11, 2024
c94c137
Merge branch 'develop' into simulate
mvadari Sep 30, 2024
45088d0
Merge branch 'develop' into simulate
mvadari Oct 28, 2024
fcea237
Merge branch 'develop' into simulate
mvadari Oct 28, 2024
6108fd9
fix merge issues
mvadari Oct 28, 2024
abed90c
Merge branch 'develop' into simulate
mvadari Oct 30, 2024
64378d5
Merge branch 'develop' into simulate
mvadari Nov 6, 2024
7f947d1
Merge branch 'develop' into simulate
mvadari Nov 6, 2024
ea59f60
fix spacing, compile error
mvadari Nov 6, 2024
92bd751
fix tests
mvadari Nov 7, 2024
8357e89
Merge branch 'develop' into simulate
mvadari Nov 11, 2024
6ff73ea
Merge branch 'develop' into simulate
mvadari Nov 25, 2024
ba499a9
Merge branch 'develop' into simulate
mvadari Dec 11, 2024
acaffb1
respond to comments
mvadari Dec 11, 2024
fcd7b1f
Merge branch 'develop' into simulate
mvadari Dec 18, 2024
e2f78a9
respond to comments
mvadari Jan 2, 2025
6b32c33
Merge branch 'develop' into simulate
mvadari Jan 2, 2025
05f1e59
Merge branch 'develop' into simulate
mvadari Jan 6, 2025
1c0b3a6
respond to comments
mvadari Jan 6, 2025
00f4f81
fix JSONRPC test
mvadari Jan 6, 2025
661219c
add tests
mvadari Jan 8, 2025
6b03bf9
rename ApplyResult -> ApplyTransactionResult and TxApplyResult -> App…
mvadari Jan 8, 2025
923ddc2
add more consts
mvadari Jan 8, 2025
3166396
clean up
mvadari Jan 8, 2025
929fd6a
Merge branch 'develop' into simulate
mvadari Jan 8, 2025
f1ac9b8
fix fees
mvadari Jan 9, 2025
8f65672
metadata helper function
mvadari Jan 9, 2025
b042607
Merge branch 'develop' into simulate
mvadari Jan 9, 2025
301868d
Merge branch 'develop' into simulate
mvadari Jan 9, 2025
0bbf589
more fixes
mvadari Jan 10, 2025
705ba58
Merge branch 'develop' into simulate
mvadari Jan 10, 2025
7a634df
fix flag due to conflict with Batch
mvadari Jan 13, 2025
ffa1c53
add &
mvadari Jan 13, 2025
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
5 changes: 3 additions & 2 deletions API-CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ The `network_id` field was added in the `server_info` response in version 1.5.0

## XRP Ledger server version 2.4.0

### Addition in 2.4
### Additions in 2.4

- `simulate`: A new RPC that executes a dry run of a transaction submission without actually submitting it to the network for inclusion.
- `ledger_entry`: `state` is added an alias for `ripple_state`.

## XRP Ledger server version 2.3.0
Expand All @@ -97,7 +98,7 @@ The `network_id` field was added in the `server_info` response in version 1.5.0

Admins can still attempt to retrieve old ledgers with the `ledger_request` RPC.

### Addition in 2.3
### Additions in 2.3

- `book_changes`: Returns a `validated` field in its response, which was missing in prior versions.

Expand Down
5 changes: 4 additions & 1 deletion include/xrpl/protocol/ErrorCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ enum error_code_i {
// deposit_authorized + credentials
rpcBAD_CREDENTIALS = 95,

rpcLAST = rpcBAD_CREDENTIALS // rpcLAST should always equal the last code.
// Simulate
rpcTX_SIGNED = 96,

rpcLAST = rpcTX_SIGNED // rpcLAST should always equal the last code.
};

/** Codes returned in the `warnings` array of certain RPC commands.
Expand Down
2 changes: 2 additions & 0 deletions include/xrpl/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ JSS(SettleDelay); // in: TransactionSign
JSS(SendMax); // in: TransactionSign
JSS(Sequence); // in/out: TransactionSign; field.
JSS(SetFlag); // field.
JSS(Signer); // field.
JSS(Signers); // field.
JSS(SigningPubKey); // field.
JSS(Subject); // in: Credential transactions
JSS(TakerGets); // field.
Expand Down
3 changes: 2 additions & 1 deletion src/libxrpl/protocol/ErrorCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ constexpr static ErrorInfo unorderedErrorInfos[]{
{rpcTXN_NOT_FOUND, "txnNotFound", "Transaction not found.", 404},
{rpcUNKNOWN_COMMAND, "unknownCmd", "Unknown method.", 405},
{rpcORACLE_MALFORMED, "oracleMalformed", "Oracle request is malformed.", 400},
{rpcBAD_CREDENTIALS, "badCredentials", "Credentials do not exist, are not accepted, or have expired.", 400}};
{rpcBAD_CREDENTIALS, "badCredentials", "Credentials do not exist, are not accepted, or have expired.", 400},
{rpcTX_SIGNED, "transactionSigned", "Transaction should not be signed.", 400}};
// clang-format on

// Sort and validate unorderedErrorInfos at compile time. Should be
Expand Down
2 changes: 1 addition & 1 deletion src/libxrpl/protocol/InnerObjectFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ InnerObjectFormats::InnerObjectFormats()
{sfWalletLocator, soeOPTIONAL},
});

add(sfSigner.jsonName.c_str(),
add(sfSigner.jsonName,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is curiously inconsistent with other entries in this file, why ?

Copy link
Collaborator Author

@mvadari mvadari Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove it in all the other ones (or leave it in) if you like - it's unnecessary.

sfSigner.getCode(),
{
{sfAccount, soeREQUIRED},
Expand Down
4 changes: 2 additions & 2 deletions src/test/app/NFToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2239,7 +2239,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite
BEAST_EXPECT(env.balance(minter, gwXAU) == gwXAU(990));

// minter sells the nft to alice. Because alice is part of the
// transaction no tranfer fee is removed.
// transaction no transfer fee is removed.
uint256 const minterSellOfferIndex =
keylet::nftoffer(minter, env.seq(minter)).key;
env(token::createOffer(minter, nftID, gwXAU(10)),
Expand Down Expand Up @@ -2331,7 +2331,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite
BEAST_EXPECT(env.balance(carol, gwXAU) == gwXAU(990));

// carol sells the nft to alice. Because alice is part of the
// transaction no tranfer fee is removed.
// transaction no transfer fee is removed.
uint256 const carolSellOfferIndex =
keylet::nftoffer(carol, env.seq(carol)).key;
env(token::createOffer(carol, nftID, gwXAU(10)),
Expand Down
4 changes: 2 additions & 2 deletions src/test/app/PseudoTx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ struct PseudoTx_test : public beast::unit_test::suite
[&](OpenView& view, beast::Journal j) {
auto const result =
ripple::apply(env.app(), view, stx, tapNONE, j);
BEAST_EXPECT(!result.second && result.first == temINVALID);
return result.second;
BEAST_EXPECT(!result.applied && result.ter == temINVALID);
return result.applied;
});
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/app/Regression_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ struct Regression_test : public beast::unit_test::suite

auto const result =
ripple::apply(env.app(), accum, *jt.stx, tapNONE, env.journal);
BEAST_EXPECT(result.first == tesSUCCESS);
BEAST_EXPECT(result.second);
BEAST_EXPECT(result.ter == tesSUCCESS);
BEAST_EXPECT(result.applied);

accum.apply(*next);
}
Expand All @@ -100,8 +100,8 @@ struct Regression_test : public beast::unit_test::suite

auto const result =
ripple::apply(env.app(), accum, *jt.stx, tapNONE, env.journal);
BEAST_EXPECT(result.first == tecINSUFF_FEE);
BEAST_EXPECT(result.second);
BEAST_EXPECT(result.ter == tecINSUFF_FEE);
BEAST_EXPECT(result.applied);

accum.apply(*next);
}
Expand Down
15 changes: 7 additions & 8 deletions src/test/app/TxQ_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,11 +1062,10 @@ class TxQPosNegFlows_test : public beast::unit_test::suite

env.app().openLedger().modify(
[&](OpenView& view, beast::Journal j) {
// No need to initialize, since it's about to get set
bool didApply;
std::tie(parsed.ter, didApply) = ripple::apply(
auto const result = ripple::apply(
env.app(), view, *jt.stx, tapNONE, env.journal);
return didApply;
parsed.ter = result.ter;
return result.applied;
});
env.postconditions(jt, parsed);
}
Expand Down Expand Up @@ -4174,8 +4173,8 @@ class TxQPosNegFlows_test : public beast::unit_test::suite
env.jt(noop(alice), seq(aliceSeq), openLedgerFee(env));
auto const result =
ripple::apply(env.app(), view, *tx.stx, tapUNLIMITED, j);
BEAST_EXPECT(result.first == tesSUCCESS && result.second);
return result.second;
BEAST_EXPECT(result.ter == tesSUCCESS && result.applied);
return result.applied;
});
// the queued transaction is still there
checkMetrics(__LINE__, env, 1, std::nullopt, 5, 3, 256);
Expand Down Expand Up @@ -4246,8 +4245,8 @@ class TxQPosNegFlows_test : public beast::unit_test::suite
noop(alice), ticket::use(tktSeq0 + 1), openLedgerFee(env));
auto const result =
ripple::apply(env.app(), view, *tx.stx, tapUNLIMITED, j);
BEAST_EXPECT(result.first == tesSUCCESS && result.second);
return result.second;
BEAST_EXPECT(result.ter == tesSUCCESS && result.applied);
return result.applied;
});
// the queued transaction is still there
checkMetrics(__LINE__, env, 1, std::nullopt, 5, 3, 256);
Expand Down
7 changes: 4 additions & 3 deletions src/test/consensus/NegativeUNL_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1922,11 +1922,12 @@ negUnlSizeTest(
bool
applyAndTestResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass)
{
auto res = apply(env.app(), view, tx, ApplyFlags::tapNONE, env.journal);
auto const res =
apply(env.app(), view, tx, ApplyFlags::tapNONE, env.journal);
if (pass)
return res.first == tesSUCCESS;
return res.ter == tesSUCCESS;
else
return res.first == tefFAILURE || res.first == temDISABLED;
return res.ter == tefFAILURE || res.ter == temDISABLED;
}

bool
Expand Down
22 changes: 22 additions & 0 deletions src/test/rpc/JSONRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,28 @@ class JSONRPC_test : public beast::unit_test::suite
BEAST_EXPECT(RPC::contains_error(result));
BEAST_EXPECT(!req[jss::tx_json].isMember(jss::Fee));
}

{
// transaction with a higher base fee
Json::Value req;
mvadari marked this conversation as resolved.
Show resolved Hide resolved
test::jtx::Account const alice("alice");
req[jss::tx_json] =
test::jtx::acctdelete(env.master.human(), alice.human());
Json::Value result = checkFee(
req,
Role::ADMIN,
true,
env.app().config(),
feeTrack,
env.app().getTxQ(),
env.app());

BEAST_EXPECT(result.size() == 0);
BEAST_EXPECT(
req[jss::tx_json].isMember(jss::Fee) &&
req[jss::tx_json][jss::Fee] ==
env.current()->fees().increment.jsonClipped());
}
}

void
Expand Down
Loading
Loading