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

add guide for extending a persistent entry and contract using the javascript sdk #1163

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Mackenzie-OO7
Copy link
Contributor

closes #610

@briwylde08
Copy link
Contributor

Heya @Mackenzie-OO7! Thank you for another great submission. Apologies for the delay in review, we'll get to this ASAP!

@briwylde08 briwylde08 requested review from carstenjacobsen and anataliocs and removed request for ElliotFriend January 21, 2025 19:16
anataliocs

This comment was marked as outdated.

@briwylde08
Copy link
Contributor

Hi @Mackenzie-OO7 - thanks again so much for your contributions! Have you been able to look at the feedback yet?

Copy link
Contributor

@anataliocs anataliocs left a comment

Choose a reason for hiding this comment

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

Please review:

https://developers.stellar.org/docs/learn/encyclopedia/storage/state-archival#extendfootprintttlop

Operation.extendFootprintTtl The Read-only set needs to contain the ledger key and the read/write section needs to be empty

ExtendFootprintTTLOp is a Soroban operation that will extend the live until ledger of the entries specified in the read-only set of the footprint. The read-write set must be empty.

// Create footprint for the entry
const footprint = new StellarSdk.xdr.LedgerFootprint({
readOnly: [],
readWrite: [persistentEntry],
Copy link
Contributor

Choose a reason for hiding this comment

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

The Read/Write set must be empty. The LedgerKey needs to be added to the readOnly footprint:

https://developers.stellar.org/docs/learn/encyclopedia/storage/state-archival#extendfootprintttlop

}),
)
.setTimeout(30)
.build();
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably want to prepareTransaction first before it gets sent so that simulateTransaction and assembleTransaction gets run

// Create footprint with both identifiers
const footprint = new StellarSdk.xdr.LedgerFootprint({
readOnly: [],
readWrite: [contractHash, persistentEntry],
Copy link
Contributor

@anataliocs anataliocs Feb 3, 2025

Choose a reason for hiding this comment

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

  1. The extend footprint operations needs to be in the readOnly footprint

https://developers.stellar.org/docs/learn/encyclopedia/storage/state-archival#extendfootprintttlop

ExtendFootprintTTLOp is a Soroban operation that will extend the live until ledger of the entries specified in the read-only set of the footprint. The read-write set must be empty.

  1. This needs to be executed as 2 operations because the 2 ledger keys have different TTL entries.

Persistence storage entries are extended individually by passing in their key
Instance storage and the contract instance are extended together, but their thresholds are evaluated separately

https://developers.stellar.org/docs/build/guides/conventions/extending-wasm-ttl#breaking-down-the-code

ExtendFootprintTTLOp is a Soroban operation, and therefore must be the only operation in a transaction.

You can only have 1 soroban operation per transaction

.addOperation(
StellarSdk.Operation.extendFootprintTtl({
extendTo: 500_000,
footprint: footprint,
Copy link
Contributor

@anataliocs anataliocs Feb 3, 2025

Choose a reason for hiding this comment

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

// Create footprint for contract code
const footprint = new StellarSdk.xdr.LedgerFootprint({
readOnly: [],
readWrite: [contractHash],
Copy link
Contributor

Choose a reason for hiding this comment

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

- Add the `extendFootprintTtl` operation with your intended TTL
- Sign and submit the transaction

:::note TTL can only be extended by the deployer or an authorized account. :::
Copy link
Contributor

@anataliocs anataliocs Feb 3, 2025

Choose a reason for hiding this comment

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

This is actually not accurate:

https://developers.stellar.org/docs/learn/encyclopedia/storage/persisting-data#access-control

There is no access control for TTL extension operations. Any user may invoke ExtendFootprintTTLOp on any LedgerEntry.

description: How to extend a persistent entry and contract using the JavaScript SDK
---

Persistent storage is used for storing data and contracts that need to remain on the network for a long period.
Copy link
Contributor

Choose a reason for hiding this comment

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

Contract instances and contract code(wasm hash) are actually instance storage with persistent durability

.build();

transaction.sign(sourceKeypair);
return await server.sendTransaction(transaction);
Copy link
Contributor

Choose a reason for hiding this comment

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

const fee = "200100";

// Create the contract code identifier
const contractHash = new StellarSdk.xdr.LedgerKey.contractCode({
Copy link
Contributor

Choose a reason for hiding this comment

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

const contract = new Contract(getDeployedContractId());
    const instance = contract.getFootprint();

It's easier to use the contract getFootprint() function

@Mackenzie-OO7
Copy link
Contributor Author

Hi @Mackenzie-OO7 - thanks again so much for your contributions! Have you been able to look at the feedback yet?

hi! somehow I missed this, but I see there's new feedback now and I'll get to it. thanks for the reminder.

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.

Create a guide on how to extend a persistent entry or contract using the JavaScript SDK
3 participants