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

set timeout after simulation and before sign #951

Merged
merged 27 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9578bc8
set timeout after simulation and before sign
BlaineHeffron May 1, 2024
53ce40e
`SentTransaction` will `allowHttp` iff its `AssembledTransaction#opti…
chadoh May 2, 2024
2a42574
set timeout after simulation and before sign
BlaineHeffron May 1, 2024
1af928d
Merge branch 'timeout-before-signing' of https://github.com/blainehef…
BlaineHeffron May 2, 2024
920bf90
add back set timeout in assembled transaction
BlaineHeffron May 2, 2024
1aed8f9
minor formatting cleanup
BlaineHeffron May 2, 2024
41cc0cf
Prepare v12.0.0-rc.1 (Protocol 21) for release (#953)
Shaptic May 2, 2024
3e79c6f
pass new timebounds in cloneFrom to avoid set timeout error
BlaineHeffron May 2, 2024
4153588
formatting
BlaineHeffron May 2, 2024
356bf80
Prepare v12.0.0-rc.1 for release (#954)
Shaptic May 2, 2024
01f63e2
Update src/contract_client/sent_transaction.ts
BlaineHeffron May 2, 2024
7f266ad
no need to convert the bytes before passing to SorobanDataBuilder
BlaineHeffron May 2, 2024
e12cdd6
Merge branch 'timeout-before-signing' of https://github.com/blainehef…
BlaineHeffron May 2, 2024
fec9349
fix typo
BlaineHeffron May 2, 2024
1d5f5bb
cleaner way of passing timeout
BlaineHeffron May 2, 2024
73d97d7
set timeout after simulation and before sign
BlaineHeffron May 1, 2024
2a16ac9
set timeout after simulation and before sign
BlaineHeffron May 1, 2024
57f09f4
add back set timeout in assembled transaction
BlaineHeffron May 2, 2024
3605bb5
minor formatting cleanup
BlaineHeffron May 2, 2024
1409be6
pass new timebounds in cloneFrom to avoid set timeout error
BlaineHeffron May 2, 2024
cf84b8f
formatting
BlaineHeffron May 2, 2024
242db45
no need to convert the bytes before passing to SorobanDataBuilder
BlaineHeffron May 2, 2024
0fe9aaa
Update src/contract_client/sent_transaction.ts
BlaineHeffron May 2, 2024
3f5e227
fix typo
BlaineHeffron May 2, 2024
2ef7510
cleaner way of passing timeout
BlaineHeffron May 2, 2024
15bc773
Merge branch 'timeout-before-signing' of https://github.com/blainehef…
BlaineHeffron May 2, 2024
b94ef51
add changelog entry
BlaineHeffron May 2, 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
7 changes: 6 additions & 1 deletion .github/workflows/npm_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ jobs:
run: yarn install

- name: Build, Test, and Package
run: yarn preversion
run: |
npm unpublish @stellar/stellar-sdk@v12.0.0
npm unpublish stellar-sdk@v12.0.0
yarn preversion
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish npm package to both places
run: |
Expand Down
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ A breaking change will get clearly marked in this log.
## Unreleased


## [v12.0.0](https://github.com/stellar/js-stellar-sdk/compare/v11.3.0...v12.0.0)
## [v12.0.0-rc.1](https://github.com/stellar/js-stellar-sdk/compare/v11.3.0...v12.0.0-rc.1)

### Breaking Changes
* **This update supports Protocol 21** ([#949](https://github.com/stellar/js-stellar-sdk/pull/949)).
* **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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stellar/stellar-sdk",
"version": "12.0.0",
"version": "12.0.0-rc.1",
"description": "A library for working with the Stellar network, including communication with the Horizon and Soroban RPC servers.",
"keywords": [
"stellar"
Expand Down
49 changes: 27 additions & 22 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 @@ -41,19 +41,19 @@ export class SentTransaction<T> {
static Errors = {
SendFailed: class SendFailedError extends Error {},
SendResultOnly: class SendResultOnlyError extends Error {},
}
};

constructor(
public signTransaction: ContractClientOptions["signTransaction"],
public assembled: AssembledTransaction<T>
public assembled: AssembledTransaction<T>,
) {
if (!signTransaction) {
throw new Error(
"You must provide a `signTransaction` function to send a transaction"
"You must provide a `signTransaction` function to send a transaction",
);
}
this.server = new SorobanRpc.Server(this.assembled.options.rpcUrl, {
allowHttp: this.assembled.options.rpcUrl.startsWith("http://"),
allowHttp: this.assembled.options.allowHttp ?? false,
});
}

Expand All @@ -72,30 +72,35 @@ export class SentTransaction<T> {

private send = async (): Promise<this> => {
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`
this.assembled.built!.toXDR(),
{
networkPassphrase: this.assembled.options.networkPassphrase,
}
},
);

this.signed = TransactionBuilder.fromXDR(
signature,
this.assembled.options.networkPassphrase
this.assembled.options.networkPassphrase,
) as Tx;

this.sendTransactionResponse = await this.server.sendTransaction(this.signed);
this.sendTransactionResponse = await this.server.sendTransaction(
this.signed,
);

if (this.sendTransactionResponse.status !== "PENDING") {
throw new SentTransaction.Errors.SendFailed(
'Sending the transaction to the network failed!\n' +
JSON.stringify(
this.sendTransactionResponse,
null,
2
)
"Sending the transaction to the network failed!\n" +
JSON.stringify(this.sendTransactionResponse, null, 2),
);
}

Expand All @@ -104,7 +109,7 @@ export class SentTransaction<T> {
this.getTransactionResponseAll = await withExponentialBackoff(
() => this.server.getTransaction(hash),
(resp) => resp.status === SorobanRpc.Api.GetTransactionStatus.NOT_FOUND,
timeoutInSeconds
timeoutInSeconds,
);

this.getTransactionResponse =
Expand All @@ -119,13 +124,13 @@ export class SentTransaction<T> {
`Sent transaction: ${JSON.stringify(
this.sendTransactionResponse,
null,
2
2,
)}\n` +
`All attempts to get the result: ${JSON.stringify(
this.getTransactionResponseAll,
null,
2
)}`
2,
)}`,
);
}

Expand All @@ -138,7 +143,7 @@ export class SentTransaction<T> {
// getTransactionResponse has a `returnValue` field unless it failed
if ("returnValue" in this.getTransactionResponse) {
return this.assembled.options.parseResultXdr(
this.getTransactionResponse.returnValue!
this.getTransactionResponse.returnValue!,
);
}

Expand All @@ -151,17 +156,17 @@ export class SentTransaction<T> {
const errorResult = this.sendTransactionResponse.errorResult?.result();
if (errorResult) {
throw new SentTransaction.Errors.SendFailed(
`Transaction simulation looked correct, but attempting to send the transaction failed. Check \`simulation\` and \`sendTransactionResponseAll\` to troubleshoot. Decoded \`sendTransactionResponse.errorResultXdr\`: ${errorResult}`
`Transaction simulation looked correct, but attempting to send the transaction failed. Check \`simulation\` and \`sendTransactionResponseAll\` to troubleshoot. Decoded \`sendTransactionResponse.errorResultXdr\`: ${errorResult}`,
);
}
throw new SentTransaction.Errors.SendResultOnly(
`Transaction was sent to the network, but not yet awaited. No result to show. Await transaction completion with \`getTransaction(sendTransactionResponse.hash)\``
`Transaction was sent to the network, but not yet awaited. No result to show. Await transaction completion with \`getTransaction(sendTransactionResponse.hash)\``,
);
}

// 3. finally, if neither of those are present, throw an error
throw new Error(
`Sending transaction failed: ${JSON.stringify(this.assembled)}`
`Sending transaction failed: ${JSON.stringify(this.assembled)}`,
);
}
}
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;
Shaptic marked this conversation as resolved.
Show resolved Hide resolved

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