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: add seq_num as an option for transactions #1702

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 14 additions & 0 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Deploy builtin Soroban Asset Contract
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
Copy link
Member

Choose a reason for hiding this comment

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

After playing with this new option, I think we should change the design.

The new option is not really usable where it is in a meaningful way without being coupled with --build-only. The reason being is that any use where the tx will be sent immediately really just needs to use the current sequence number plus one. The only need for setting a different sequence number occurs when building and later sending.

Since the option is only usable in that advanced build-only case, I think we should make this something they can do with the stellar tx ... commands. It will keep the options advertised smaller for each of the subcommands being changed here, and keeps the advanced functionality for tx modifications in the same place. Maybe as a way to simply change a sequence number stellar tx set seq, where those commands could grow to support others like stellar tx set source-account. Or maybe by using the stellar tx edit.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think stellar tx edit is a good place for this ^
We can also allow to modify the fee in tx edit

Copy link
Member

@leighmcculloch leighmcculloch Nov 7, 2024

Choose a reason for hiding this comment

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

stellar tx edit was envisioned as a interactive editor, where I think the thing @willemneal is adding here is more of a non-interactive modification of the transaction. Both things have a place, and for the non-interactive modification I think it's helpful to think about the user api being modifying a single thing, similar to how stellar tx op add modifies one thing by adding a single tx and that's why I suggest a stellar tx set, something that is separate to the interactive modification.

* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout


Expand Down Expand Up @@ -379,6 +380,7 @@ If no keys are specified the contract itself is extended.
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout


Expand Down Expand Up @@ -408,6 +410,7 @@ Deploy a wasm contract
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts

Expand Down Expand Up @@ -689,6 +692,7 @@ Install a WASM file to the ledger without creating a contract instance
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--wasm <WASM>` — Path to wasm binary
* `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts
Expand Down Expand Up @@ -729,6 +733,7 @@ stellar contract invoke ... -- --help
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--send <SEND>` — Whether or not to send a transaction

Expand Down Expand Up @@ -843,6 +848,7 @@ If no keys are specificed the contract itself is restored.
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout


Expand Down Expand Up @@ -1422,6 +1428,7 @@ Transfers the XLM balance of an account to another account and removes the sourc
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down Expand Up @@ -1449,6 +1456,7 @@ Bumps forward the sequence number of the source account to the given sequence nu
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down Expand Up @@ -1476,6 +1484,7 @@ Creates, updates, or deletes a trustline Learn more about trustlines https://dev
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down Expand Up @@ -1506,6 +1515,7 @@ Creates and funds a new account with the specified starting balance
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down Expand Up @@ -1536,6 +1546,7 @@ Sets, modifies, or deletes a data entry (name/value pair) that is attached to an
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down Expand Up @@ -1564,6 +1575,7 @@ Sends an amount in a specific asset to a destination account
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down Expand Up @@ -1595,6 +1607,7 @@ Set option for an account such as flags, inflation destination, signers, home do
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down Expand Up @@ -1637,6 +1650,7 @@ Allows issuing account to configure authorization and trustline flags to an asse
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down
7 changes: 7 additions & 0 deletions cmd/soroban-cli/src/assembled.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use sha2::{Digest, Sha256};
use soroban_sdk::xdr::SequenceNumber;
use stellar_xdr::curr::{
self as xdr, ExtensionPoint, Hash, InvokeHostFunctionOp, LedgerFootprint, Limits, Memo,
Operation, OperationBody, Preconditions, ReadXdr, RestoreFootprintOp,
Expand Down Expand Up @@ -102,6 +103,12 @@ impl Assembled {
self
}

#[must_use]
pub fn set_seq_num(mut self, seq_num: impl Into<SequenceNumber>) -> Self {
self.txn.seq_num = seq_num.into();
self
}

///
/// # Errors
#[must_use]
Expand Down
11 changes: 7 additions & 4 deletions cmd/soroban-cli/src/commands/tx/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ pub enum Error {
impl Args {
pub async fn tx(&self, body: impl Into<xdr::OperationBody>) -> Result<xdr::Transaction, Error> {
let source_account = self.source_account()?;
let seq_num = self
.config
.next_sequence_number(&source_account.to_string())
.await?;
let seq_num = if let Some(seq_num) = self.fee.sequence_number {
seq_num.into()
} else {
self.config
.next_sequence_number(&source_account.to_string())
.await?
};
// Once we have a way to add operations this will be updated to allow for a different source account
let operation = xdr::Operation {
source_account: None,
Expand Down
11 changes: 10 additions & 1 deletion cmd/soroban-cli/src/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub struct Args {
/// Build the transaction and only write the base64 xdr to stdout
#[arg(long, help_heading = HEADING_RPC)]
pub build_only: bool,
#[arg(long, visible_alias = "seq-num", help_heading = HEADING_RPC)]
willemneal marked this conversation as resolved.
Show resolved Hide resolved
/// Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one
pub sequence_number: Option<i64>,
/// (Deprecated) simulate the transaction and only write the base64 xdr to stdout
#[arg(
long,
Expand All @@ -37,10 +40,15 @@ pub struct Args {

impl Args {
pub fn apply_to_assembled_txn(&self, txn: Assembled) -> Assembled {
if let Some(instructions) = self.instructions {
let txn = if let Some(instructions) = self.instructions {
txn.set_max_instructions(instructions)
} else {
add_padding_to_instructions(txn)
};
if let Some(sequence_number) = self.sequence_number {
txn.set_seq_num(sequence_number)
} else {
txn
}
}
}
Expand All @@ -66,6 +74,7 @@ impl Default for Args {
instructions: None,
build_only: false,
sim_only: false,
sequence_number: None,
}
}
}
Loading