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 58 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 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
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
31 changes: 17 additions & 14 deletions API-CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,34 +85,37 @@ 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

### Breaking change in 2.3
### BREAKING CHANGES

- `book_changes`: If the requested ledger version is not available on this node, a `ledgerNotFound` error is returned and the node does not attempt to acquire the ledger from the p2p network (as with other non-admin RPCs).
- `book_changes`: If the requested ledger version is not available on this node, a `ledgerNotFound` error is returned and the node does not attempt to acquire the ledger from the p2p network (as with other non-admin RPCs). Admins can still attempt to retrieve old ledgers with the `ledger_request` RPC.
Copy link
Collaborator

@oleks-rip oleks-rip Dec 5, 2024

Choose a reason for hiding this comment

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

I believe this document and changes are outdated, please re-base to the latest develop version and make any changes if need

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed


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

### Addition in 2.3
Additions are intended to be non-breaking (because they are purely additive).

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

The following additions are non-breaking (because they are purely additive).

- `server_definitions`: A new RPC that generates a `definitions.json`-like output that can be used in XRPL libraries.
- In `Payment` transactions, `DeliverMax` has been added. This is a replacement for the `Amount` field, which should not be used. Typically, the `delivered_amount` (in transaction metadata) should be used. To ease the transition, `DeliverMax` is present regardless of API version, since adding a field is non-breaking.
- API version 2 has been moved from beta to supported, meaning that it is generally available (regardless of the `beta_rpc_api` setting).

## XRP Ledger server version 2.2.0

The following is a non-breaking addition to the API.

- The `feature` method now has a non-admin mode for users. (It was previously only available to admin connections.) The method returns an updated list of amendments, including their names and other information. ([#4781](https://github.com/XRPLF/rippled/pull/4781))

## XRP Ledger server version 2.0.0

The following additions are non-breaking (because they are purely additive).

- `server_definitions`: A new RPC that generates a `definitions.json`-like output that can be used in XRPL libraries.
- In `Payment` transactions, `DeliverMax` has been added. This is a replacement for the `Amount` field, which should not be used. Typically, the `delivered_amount` (in transaction metadata) should be used. To ease the transition, `DeliverMax` is present regardless of API version, since adding a field is non-breaking.
- API version 2 has been moved from beta to supported, meaning that it is generally available (regardless of the `beta_rpc_api` setting).

## XRP Ledger server version 1.12.0

[Version 1.12.0](https://github.com/XRPLF/rippled/releases/tag/1.12.0) was released on Sep 6, 2023. The following additions are non-breaking (because they are purely additive).
Expand Down Expand Up @@ -155,7 +158,7 @@ The following is a non-breaking addition to the API.

[Version 1.11.0](https://github.com/XRPLF/rippled/releases/tag/1.11.0) was released on Jun 20, 2023.

### Breaking changes in 1.11
### Breaking changes

- Added the ability to mark amendments as obsolete. For the `feature` admin API, there is a new possible value for the `vetoed` field. (https://github.com/XRPLF/rippled/pull/4291)
- The value of `vetoed` can now be `true`, `false`, or `"Obsolete"`.
Expand All @@ -174,7 +177,7 @@ The following is a non-breaking addition to the API.
- `telREQUIRES_NETWORK_ID`: a `NetworkID` is required, but is not present. Add the field to the transaction, and try again.
- `telWRONG_NETWORK`: a `NetworkID` is specified, but it is for a different network. Submit the transaction to a different server which is connected to the correct network.

### Additions and bug fixes in 1.11
### Additions and bug fixes

- Added `nftoken_id`, `nftoken_ids` and `offer_id` meta fields into NFT `tx` and `account_tx` responses. (https://github.com/XRPLF/rippled/pull/4447)
- Added an `account_flags` object to the `account_info` method response. (https://github.com/XRPLF/rippled/pull/4459)
Expand All @@ -186,7 +189,7 @@ The following is a non-breaking addition to the API.
[Version 1.10.0](https://github.com/XRPLF/rippled/releases/tag/1.10.0)
was released on Mar 14, 2023.

### Breaking changes in 1.10
### Breaking changes

- If the `XRPFees` feature is enabled, the `fee_ref` field will be
removed from the [ledger subscription stream](https://xrpl.org/subscribe.html#ledger-stream), because it will no longer
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 @@ -107,7 +107,9 @@ JSS(SettleDelay); // in: TransactionSign
JSS(SendMax); // in: TransactionSign
JSS(Sequence); // in/out: TransactionSign; field.
JSS(SetFlag); // field.
JSS(Signer); // field.
JSS(SignerList); // ledger type.
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,
sfSigner.getCode(),
{
{sfAccount, soeREQUIRED},
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
25 changes: 25 additions & 0 deletions src/test/rpc/JSONRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,31 @@ 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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

A bit unclear, maybe request?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

req is used for all the other tests

test::jtx::Account const alice("alice");
Json::Reader().parse(
"{ \"tx_json\" : { \"TransactionType\": \"AccountDelete\", "
"\"Account\": \"" +
env.master.human() + "\", \"Destination\": \"" +
alice.human() + "\" } } ",
req);
Json::Value result = checkFee(
req,
Role::ADMIN,
true,
env.app().config(),
feeTrack,
env.app().getTxQ(),
env.app());

BEAST_EXPECT(!RPC::contains_error(result));
BEAST_EXPECT(
req[jss::tx_json].isMember(jss::Fee) &&
req[jss::tx_json][jss::Fee] == 50000000);
Copy link
Collaborator

Choose a reason for hiding this comment

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

How this magic number was calculated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is the default owner reserve

Copy link
Collaborator

Choose a reason for hiding this comment

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

So use it, it can be obtained through env.current()->fees()

}
}

void
Expand Down
Loading
Loading