From 6935d8250fd6d37667ea221dcec44add9c73dcfb Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Thu, 6 Jun 2024 15:13:30 -0700 Subject: [PATCH] Add tx to restore wasm blob to get-settings-upgrade-txs --- docs/software/commands.md | 16 ++++++----- scripts/settings-helper.sh | 8 ++++-- src/main/CommandLine.cpp | 8 +++--- src/main/SettingsUpgradeUtils.cpp | 45 +++++++++++++++++++++++++++++++ src/main/SettingsUpgradeUtils.h | 3 +++ 5 files changed, 68 insertions(+), 12 deletions(-) diff --git a/docs/software/commands.md b/docs/software/commands.md index 5a2c98cd64..b7c686ad93 100644 --- a/docs/software/commands.md +++ b/docs/software/commands.md @@ -100,13 +100,15 @@ Command options can only by placed after command. Option **--signtxs** will prompt for a secret key and sign the TransactionEnvelopes.
Output format by line - - 1. Base64 upload tx envelope XDR - 2. Hex tx ID for the upload tx. - 3. Base 64 create tx envelope XDR - 4. Hex tx ID for the create tx. - 5. Base64 invoke tx envelope XDR - 6. Hex tx ID for the invoke tx. - 7. Base64 ConfigUpgradeSetKey XDR. + 1. Base64 wasm restore tx envelope XDR + 2. Hex tx ID for the wasm restore tx. + 3. Base64 upload tx envelope XDR + 4. Hex tx ID for the upload tx. + 5. Base 64 create tx envelope XDR + 6. Hex tx ID for the create tx. + 7. Base64 invoke tx envelope XDR + 8. Hex tx ID for the invoke tx. + 9. Base64 ConfigUpgradeSetKey XDR. * **help**: Print the available command line options and then exit.. * **http-command ** Send an [HTTP command](#http-commands) to an diff --git a/scripts/settings-helper.sh b/scripts/settings-helper.sh index a9e4207fd3..2224d08c08 100644 --- a/scripts/settings-helper.sh +++ b/scripts/settings-helper.sh @@ -47,8 +47,12 @@ echo "----- TX #3 -----" echo "curl -G 'http://localhost:11626/tx' --data-urlencode 'blob=$(echo "$OUTPUT" | sed -n '5p')'" echo "-----" -echo "curl -G 'http://localhost:11626/dumpproposedsettings' --data-urlencode 'blob=$(echo "$OUTPUT" | sed -n '7p')'" +echo "----- TX #4 -----" +echo "curl -G 'http://localhost:11626/tx' --data-urlencode 'blob=$(echo "$OUTPUT" | sed -n '7p')'" +echo "-----" + +echo "curl -G 'http://localhost:11626/dumpproposedsettings' --data-urlencode 'blob=$(echo "$OUTPUT" | sed -n '9p')'" echo "-----" echo "distribute the following command with the upgradetime set to an agreed upon point in the future" -echo "curl -G 'http://localhost:11626/upgrades?mode=set&upgradetime=YYYY-MM-DDT01:25:00Z' --data-urlencode 'configupgradesetkey=$(echo "$OUTPUT" | sed -n '7p')'" +echo "curl -G 'http://localhost:11626/upgrades?mode=set&upgradetime=YYYY-MM-DDT01:25:00Z' --data-urlencode 'configupgradesetkey=$(echo "$OUTPUT" | sed -n '9p')'" diff --git a/src/main/CommandLine.cpp b/src/main/CommandLine.cpp index f27e941d60..67dc6cf239 100644 --- a/src/main/CommandLine.cpp +++ b/src/main/CommandLine.cpp @@ -1293,20 +1293,22 @@ getSettingsUpgradeTransactions(CommandLineArgs const& args) PublicKey pk = KeyUtils::fromStrKey(id); std::vector txsToSign; + auto restoreRes = getWasmRestoreTx(pk, seqNum + 1); + txsToSign.emplace_back(restoreRes.first); - auto uploadRes = getUploadTx(pk, seqNum + 1); + auto uploadRes = getUploadTx(pk, seqNum + 2); txsToSign.emplace_back(uploadRes.first); auto const& contractCodeLedgerKey = uploadRes.second; auto createRes = - getCreateTx(pk, contractCodeLedgerKey, netId, seqNum + 2); + getCreateTx(pk, contractCodeLedgerKey, netId, seqNum + 3); txsToSign.emplace_back(std::get<0>(createRes)); auto const& contractSourceRefLedgerKey = std::get<1>(createRes); auto const& contractID = std::get<2>(createRes); auto invokeRes = getInvokeTx(pk, contractCodeLedgerKey, contractSourceRefLedgerKey, contractID, - upgradeSet, seqNum + 3); + upgradeSet, seqNum + 4); txsToSign.emplace_back(invokeRes.first); auto const& upgradeSetKey = invokeRes.second; diff --git a/src/main/SettingsUpgradeUtils.cpp b/src/main/SettingsUpgradeUtils.cpp index 12bf659a7e..6873d29dbb 100644 --- a/src/main/SettingsUpgradeUtils.cpp +++ b/src/main/SettingsUpgradeUtils.cpp @@ -7,6 +7,51 @@ namespace stellar { +std::pair +getWasmRestoreTx(PublicKey const& publicKey, SequenceNumber seqNum) +{ + TransactionEnvelope txEnv; + txEnv.type(ENVELOPE_TYPE_TX); + + auto& tx = txEnv.v1().tx; + tx.sourceAccount = toMuxedAccount(publicKey); + tx.fee = 100'000'000; + tx.seqNum = seqNum; + + Preconditions cond; + cond.type(PRECOND_NONE); + tx.cond = cond; + + Memo memo; + memo.type(MEMO_NONE); + tx.memo = memo; + + Operation restoreOp; + restoreOp.body.type(RESTORE_FOOTPRINT); + + tx.operations.emplace_back(restoreOp); + + auto const writeByteWasm = rust_bridge::get_write_bytes(); + std::vector wasm(writeByteWasm.data.begin(), + writeByteWasm.data.end()); + + LedgerKey contractCodeLedgerKey; + contractCodeLedgerKey.type(CONTRACT_CODE); + contractCodeLedgerKey.contractCode().hash = sha256(wasm); + + SorobanResources restoreResources; + restoreResources.footprint.readWrite = {contractCodeLedgerKey}; + restoreResources.instructions = 0; + restoreResources.readBytes = 2000; + restoreResources.writeBytes = 2000; + + tx.ext.v(1); + tx.ext.sorobanData().resources = restoreResources; + tx.ext.sorobanData().resourceFee = 55'000'000; + + return {txEnv, contractCodeLedgerKey}; +} + std::pair getUploadTx(PublicKey const& publicKey, SequenceNumber seqNum) { diff --git a/src/main/SettingsUpgradeUtils.h b/src/main/SettingsUpgradeUtils.h index c7c3ee3ea7..d7d8c11fc8 100644 --- a/src/main/SettingsUpgradeUtils.h +++ b/src/main/SettingsUpgradeUtils.h @@ -5,6 +5,9 @@ namespace stellar { +std::pair +getWasmRestoreTx(PublicKey const& publicKey, SequenceNumber seqNum); + std::pair getUploadTx(PublicKey const& publicKey, SequenceNumber seqNum);