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

feature: add auto restore functionality for contract client #974

Closed
wants to merge 14 commits into from

Conversation

BlaineHeffron
Copy link
Contributor

Adds the ability to set restore to true in contract method invocation options. This will utilize the signTransaction method to sign a restoreFootprint operation when found that it is needed during a simulation.

@BlaineHeffron
Copy link
Contributor Author

A couple of interesting things I found:

  • At first I wanted to reuse the Account object so we don't query the server a second time for it. The problem I found was that the sequence number increments the first time the AssembledTransaction is built, and since that method call doesn't go through it is then off by 1 for the restoreFootprint operation. If I had a way to decrement the sequence number I could avoid this problem and reuse the Account object.
  • I was having trouble testing the case where the actual contract wasm hash footprint / contract wasm was expired. The way I was testing was by setting the minimum expire ledgers to some low number (around 300) in the quickstart config. Since persistent and instance storage use this same number, it would seem that the persistent storage and instance storage (which would presumably include the wasm hash) would expire at the same time. It seemed that regardless of what had expired, using the restorePreamble to construct the restoreFootprint operation always worked. In other words, I never needed to perform the actual restore of the contract wasm hash / contract wasm footprints. I did write code to do that in case its needed, and I can add that as a method if it is needed. I just wasn't able to find a test case where it was.

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.

This is gonna be so great! Various notes on the interface below. Really curious to hear from @Shaptic on your questions above.

src/contract/assembled_transaction.ts Outdated Show resolved Hide resolved
src/contract/assembled_transaction.ts Outdated Show resolved Hide resolved
src/contract/assembled_transaction.ts Outdated Show resolved Hide resolved
src/contract/assembled_transaction.ts Outdated Show resolved Hide resolved
src/contract/assembled_transaction.ts Outdated Show resolved Hide resolved
test/unit/server/soroban/assembled_transaction_test.js Outdated Show resolved Hide resolved
test/unit/server/soroban/assembled_transaction_test.js Outdated Show resolved Hide resolved
updateTimeout: false
}))
.then((result) => {
expect(result.getTransactionResponse.status).to.equal(rpc.Api.GetTransactionStatus.SUCCESS);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you find this test satisfying? Is there a meaningful way it can fail? Seems sorta like "if I make f(x) always return 1 then it will return 1".

Is there a better test we could write, that exercises real functionality? Like our e2e tests do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, its not the most satisfying test. However, I'm not sure how to do something like the e2e tests because you can't force a restore via any parameters. It has to be done at the server level (changing the minimum TTL) which would still require you to wait x amount of time, or if you put it too low it breaks functionality. So the only way I coudl think to write a test was to mock the response. What I could do is a better pattern match for the request, I was having trouble getting it to match exactly what the request is but its possible - just would take more detailed reconstruction of the specific transaction objects.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah unfortunately testing restores is difficult by default at all levels of the stack. We'd have to have a custom rpc+core in the e2e tests that speeds up archiving :/

Copy link
Contributor

Choose a reason for hiding this comment

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

which makes me wonder: maybe we can run e2e tests only in CI and use a custom quickstart image?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we discussed on the call this week, we will add the ability to modify the minimum TTL as a quickstart variable or some preset config which we can then use for an e2e test of this. For now I suppose the current test is okay?

src/contract/assembled_transaction.ts Show resolved Hide resolved
src/contract/assembled_transaction.ts Show resolved Hide resolved
@Shaptic
Copy link
Contributor

Shaptic commented May 30, 2024

The problem I found was that the sequence number increments the first time the AssembledTransaction is built, and since that method call doesn't go through it is then off by 1 for the restoreFootprint operation.

Yeahh this has been a long-standing issue with the Account object. That's why TransactionBuilder.cloneFrom() does this janky -1n workaround. We can definitely make changes to that interface and its implementations, though. See also stellar/js-stellar-base#574 and stellar/js-stellar-base#436 for more stuff related to this. I'm definitely for it!

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.

We'll have to release this in a minor release so that I can tag v12 stable today with no changes from the RC. This'll be better for the CLI release train too, I think.

src/contract/assembled_transaction.ts Outdated Show resolved Hide resolved
src/contract/sent_transaction.ts Outdated Show resolved Hide resolved
src/contract/sent_transaction.ts Outdated Show resolved Hide resolved
src/contract/sent_transaction.ts Outdated Show resolved Hide resolved
updateTimeout: false
}))
.then((result) => {
expect(result.getTransactionResponse.status).to.equal(rpc.Api.GetTransactionStatus.SUCCESS);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah unfortunately testing restores is difficult by default at all levels of the stack. We'd have to have a custom rpc+core in the e2e tests that speeds up archiving :/

updateTimeout: false
}))
.then((result) => {
expect(result.getTransactionResponse.status).to.equal(rpc.Api.GetTransactionStatus.SUCCESS);
Copy link
Contributor

Choose a reason for hiding this comment

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

which makes me wonder: maybe we can run e2e tests only in CI and use a custom quickstart image?

src/contract/assembled_transaction.ts Show resolved Hide resolved
src/contract/assembled_transaction.ts Outdated Show resolved Hide resolved
src/contract/assembled_transaction.ts Outdated Show resolved Hide resolved
@BlaineHeffron
Copy link
Contributor Author

All comments are addressed except regarding the test. I think we can use this test for now until we have a way of using a quickstart image with a short minimum TTL that would be suitable for this type of e2e test. Changelog has been added.

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.

Awesome work here, thanks @BlaineHeffron!

@Shaptic
Copy link
Contributor

Shaptic commented Jun 13, 2024

@BlaineHeffron if you can resolve the conflicts I can merge this asap!

@chadoh
Copy link
Contributor

chadoh commented Jun 13, 2024

@BlaineHeffron is out today! I resolved the conflicts but didn't have permission to push to Blaine's fork, so I made a new PR, if you want to merge that one and close this one, @Shaptic! #991

@Shaptic Shaptic closed this Jun 13, 2024
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