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

Conversation

BlaineHeffron
Copy link
Contributor

@BlaineHeffron BlaineHeffron commented May 1, 2024

Timeout for a transaction is now set to start after the simulation returns and before it is signed and sent. This makes sure its more in line with the time used in the retry logic. We also increased the default value to 60 from 10 seconds so that people using freighter have time to review and sign the transaction.
This gives enough time to avoid the txTooLate error in #950

@BlaineHeffron BlaineHeffron reopened this May 1, 2024
@BlaineHeffron BlaineHeffron marked this pull request as draft May 1, 2024 20:48
@chadoh
Copy link
Contributor

chadoh commented May 2, 2024

Currently marked as draft because TransactionBuilder throws an exception when you try to simulate the transaction without time bounds set:

  Error {
    message: 'TimeBounds has to be set or you must call setTimeout(TimeoutInfinite).',
  }

  › TransactionBuilder.build (node_modules/@stellar/stellar-base/lib/transaction_builder.js:544:15)

Also you can't set the timeout after the max time is already set so cloning the transaction and then calling setTimeout doesn't work:

message: 'TimeBounds.max_time has been already set - setting timeout would overwrite it.',

You get the same error if you use setTimebounds.

I've tried working around it by doing this:

const timeoutInSeconds =
  this.assembled.options.timeoutInSeconds ?? DEFAULT_TIMEOUT;
const timeoutTimestamp =
  Math.floor(Date.now() / 1000) + timeoutInSeconds + 1;
this.assembled.built = TransactionBuilder.cloneFrom(this.assembled.built!, {
  fee: this.assembled.built!.fee,
  timebounds: {
    minTime: 0,
    maxTime: timeoutTimestamp,
  },
}).build();

But this gets me a txMalformed RPC error without much extra info.

@Shaptic
Copy link
Contributor

Shaptic commented May 2, 2024

@chadoh @BlaineHeffron you probably need to inject the SorobanTransactionData from the original transaction as this is not cloned by cloneFrom. I think your code can be fixed with something like:

const timeoutInSeconds = this.assembled.options.timeoutInSeconds ?? DEFAULT_TIMEOUT;
this.assembled.built = TransactionBuilder.cloneFrom(this.assembled.built!)
  .setTimeout(timeoutInSeconds)
  .setSorobanData(new SorobanDataBuilder(this.assembled.built!.[dig and get the data structure out]).build())
  .build();

@BlaineHeffron BlaineHeffron marked this pull request as ready for review May 2, 2024 20:07
@BlaineHeffron
Copy link
Contributor Author

With the following changes all e2e tests are passing.

  1. Add back in the setTimeout call in assembled_transaction.ts
  2. Set the proper time bounds before signing by using cloneFrom to clone the transaction from this.assembled.built while manually passing in the new bounds, and making sure to add the sorobanData which doesn't get copied via cloneFrom.

Copy link
Contributor

@chadoh chadoh left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good. Feel free to use my syntax or keep yours.

cleaner way to pass sorobanData

Co-authored-by: Chad Ostrowski <[email protected]>
Copy link
Contributor

@Shaptic Shaptic left a comment

Choose a reason for hiding this comment

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

coupla minor comments ⬇️ also can you add a changelog entry?

src/contract_client/sent_transaction.ts Outdated Show resolved Hide resolved
src/contract_client/sent_transaction.ts Outdated Show resolved Hide resolved
src/contract_client/utils.ts Show resolved Hide resolved
@BlaineHeffron BlaineHeffron marked this pull request as draft May 2, 2024 20:50
@BlaineHeffron
Copy link
Contributor Author

BlaineHeffron commented May 2, 2024

rebased and added CL entry
sorry about the obnoxiously long commit history...

@BlaineHeffron BlaineHeffron marked this pull request as ready for review May 2, 2024 21:53
Copy link
Contributor

@Shaptic Shaptic left a comment

Choose a reason for hiding this comment

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

Nice work!!

@Shaptic Shaptic merged commit 2bcbc6a into stellar:master May 2, 2024
10 checks passed
@BlaineHeffron BlaineHeffron deleted the timeout-before-signing branch May 15, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants