Skip to content

Commit

Permalink
Set transaction timeout after simulation and before sign (#951)
Browse files Browse the repository at this point in the history
Co-authored-by: Chad Ostrowski <221614+chadoh@users.noreply.github.com>
Co-authored-by: George <Shaptic@users.noreply.github.com>
  • Loading branch information
3 people committed May 2, 2024
1 parent 356bf80 commit 2bcbc6a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ A breaking change will get clearly marked in this log.

### Breaking Changes
* **This update supports Protocol 21**. It is an additive change to the protocol so there are no true backwards incompatibilities, but your software may break if you encounter new unexpected fields from this Protocol ([#949](https://github.com/stellar/js-stellar-sdk/pull/949)).
* **Default timeout for transaction calls is now set to 60 seconds from previous default of 10**. 10 seconds is often not enough time to review transactions before signing, which would cause a `txTooLate` error response from the server.

### Fixed
* Each item in the `GetEventsResponse.events` list will now have a `txHash` item corresponding to the transaction hash that triggered a particular event ([#939](https://github.com/stellar/js-stellar-sdk/pull/939)).
* `ContractClient` now properly handles methods that take no arguments by making `MethodOptions` the only parameter, bringing it inline with the types generated by Soroban CLI's `soroban contract bindings typescript` ([#940](https://github.com/stellar/js-stellar-sdk/pull/940)).
* `ContractClient` now allows `publicKey` to be undefined ([#941](https://github.com/stellar/js-stellar-sdk/pull/941)).
* `SentTransaction` will only pass `allowHttp` if (and only if) its corresponding `AssembledTransaction#options` config allowed it ([#952](https://github.com/stellar/js-stellar-sdk/pull/952)).

* `SentTransaction` will now modify the time bounds of the transaction to be `timeoutInSeconds` seconds after the transaction has been simulated. Previously this was set when the transaction is built, before the simulation. This makes the time bounds line up with the timeout retry logic in `SentTransaction`.

## [v11.3.0](https://github.com/stellar/js-stellar-sdk/compare/v11.2.2...v11.3.0)

Expand Down
12 changes: 9 additions & 3 deletions src/contract_client/sent_transaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ContractClientOptions, Tx } from "./types";
import { SorobanRpc, TransactionBuilder } from "..";
import { SorobanDataBuilder, SorobanRpc, TransactionBuilder } from "..";
import { DEFAULT_TIMEOUT, withExponentialBackoff } from "./utils";
import { AssembledTransaction } from "./assembled_transaction";

Expand Down Expand Up @@ -71,8 +71,14 @@ export class SentTransaction<T> {
};

private send = async (): Promise<this> => {
const timeoutInSeconds =
this.assembled.options.timeoutInSeconds ?? DEFAULT_TIMEOUT;
const timeoutInSeconds = this.assembled.options.timeoutInSeconds ?? DEFAULT_TIMEOUT
this.assembled.built = TransactionBuilder.cloneFrom(this.assembled.built!, {
fee: this.assembled.built!.fee,
timebounds: undefined,
sorobanData: new SorobanDataBuilder(this.assembled.simulationData.transactionData.toXDR()).build()
})
.setTimeout(timeoutInSeconds)
.build();

const signature = await this.signTransaction!(
// `signAndSend` checks for `this.built` before calling `SentTransaction.init`
Expand Down
2 changes: 1 addition & 1 deletion src/contract_client/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* The default timeout for waiting for a transaction to be included in a block.
*/
export const DEFAULT_TIMEOUT = 10;
export const DEFAULT_TIMEOUT = 60;

/**
* Keep calling a `fn` for `timeoutInSeconds` seconds, if `keepWaitingIf` is true.
Expand Down

0 comments on commit 2bcbc6a

Please sign in to comment.