Skip to content

Commit b3aeb14

Browse files
authored
Merge pull request #4351 from sisuresh/upgrade-restore
Add tx to restore wasm blob to get-settings-upgrade-txs Reviewed-by: dmkozh
2 parents 99cbf44 + 6935d82 commit b3aeb14

File tree

5 files changed

+68
-12
lines changed

5 files changed

+68
-12
lines changed

docs/software/commands.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,15 @@ Command options can only by placed after command.
100100
Option **--signtxs** will prompt for a secret key and sign the TransactionEnvelopes.<br>
101101

102102
Output format by line -
103-
1. Base64 upload tx envelope XDR
104-
2. Hex tx ID for the upload tx.
105-
3. Base 64 create tx envelope XDR
106-
4. Hex tx ID for the create tx.
107-
5. Base64 invoke tx envelope XDR
108-
6. Hex tx ID for the invoke tx.
109-
7. Base64 ConfigUpgradeSetKey XDR.
103+
1. Base64 wasm restore tx envelope XDR
104+
2. Hex tx ID for the wasm restore tx.
105+
3. Base64 upload tx envelope XDR
106+
4. Hex tx ID for the upload tx.
107+
5. Base 64 create tx envelope XDR
108+
6. Hex tx ID for the create tx.
109+
7. Base64 invoke tx envelope XDR
110+
8. Hex tx ID for the invoke tx.
111+
9. Base64 ConfigUpgradeSetKey XDR.
110112

111113
* **help**: Print the available command line options and then exit..
112114
* **http-command <COMMAND>** Send an [HTTP command](#http-commands) to an

scripts/settings-helper.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ echo "----- TX #3 -----"
4747
echo "curl -G 'http://localhost:11626/tx' --data-urlencode 'blob=$(echo "$OUTPUT" | sed -n '5p')'"
4848
echo "-----"
4949

50-
echo "curl -G 'http://localhost:11626/dumpproposedsettings' --data-urlencode 'blob=$(echo "$OUTPUT" | sed -n '7p')'"
50+
echo "----- TX #4 -----"
51+
echo "curl -G 'http://localhost:11626/tx' --data-urlencode 'blob=$(echo "$OUTPUT" | sed -n '7p')'"
52+
echo "-----"
53+
54+
echo "curl -G 'http://localhost:11626/dumpproposedsettings' --data-urlencode 'blob=$(echo "$OUTPUT" | sed -n '9p')'"
5155
echo "-----"
5256

5357
echo "distribute the following command with the upgradetime set to an agreed upon point in the future"
54-
echo "curl -G 'http://localhost:11626/upgrades?mode=set&upgradetime=YYYY-MM-DDT01:25:00Z' --data-urlencode 'configupgradesetkey=$(echo "$OUTPUT" | sed -n '7p')'"
58+
echo "curl -G 'http://localhost:11626/upgrades?mode=set&upgradetime=YYYY-MM-DDT01:25:00Z' --data-urlencode 'configupgradesetkey=$(echo "$OUTPUT" | sed -n '9p')'"

src/main/CommandLine.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -1293,20 +1293,22 @@ getSettingsUpgradeTransactions(CommandLineArgs const& args)
12931293
PublicKey pk = KeyUtils::fromStrKey<PublicKey>(id);
12941294

12951295
std::vector<TransactionEnvelope> txsToSign;
1296+
auto restoreRes = getWasmRestoreTx(pk, seqNum + 1);
1297+
txsToSign.emplace_back(restoreRes.first);
12961298

1297-
auto uploadRes = getUploadTx(pk, seqNum + 1);
1299+
auto uploadRes = getUploadTx(pk, seqNum + 2);
12981300
txsToSign.emplace_back(uploadRes.first);
12991301
auto const& contractCodeLedgerKey = uploadRes.second;
13001302

13011303
auto createRes =
1302-
getCreateTx(pk, contractCodeLedgerKey, netId, seqNum + 2);
1304+
getCreateTx(pk, contractCodeLedgerKey, netId, seqNum + 3);
13031305
txsToSign.emplace_back(std::get<0>(createRes));
13041306
auto const& contractSourceRefLedgerKey = std::get<1>(createRes);
13051307
auto const& contractID = std::get<2>(createRes);
13061308

13071309
auto invokeRes = getInvokeTx(pk, contractCodeLedgerKey,
13081310
contractSourceRefLedgerKey, contractID,
1309-
upgradeSet, seqNum + 3);
1311+
upgradeSet, seqNum + 4);
13101312
txsToSign.emplace_back(invokeRes.first);
13111313
auto const& upgradeSetKey = invokeRes.second;
13121314

src/main/SettingsUpgradeUtils.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,51 @@
77
namespace stellar
88
{
99

10+
std::pair<TransactionEnvelope, LedgerKey>
11+
getWasmRestoreTx(PublicKey const& publicKey, SequenceNumber seqNum)
12+
{
13+
TransactionEnvelope txEnv;
14+
txEnv.type(ENVELOPE_TYPE_TX);
15+
16+
auto& tx = txEnv.v1().tx;
17+
tx.sourceAccount = toMuxedAccount(publicKey);
18+
tx.fee = 100'000'000;
19+
tx.seqNum = seqNum;
20+
21+
Preconditions cond;
22+
cond.type(PRECOND_NONE);
23+
tx.cond = cond;
24+
25+
Memo memo;
26+
memo.type(MEMO_NONE);
27+
tx.memo = memo;
28+
29+
Operation restoreOp;
30+
restoreOp.body.type(RESTORE_FOOTPRINT);
31+
32+
tx.operations.emplace_back(restoreOp);
33+
34+
auto const writeByteWasm = rust_bridge::get_write_bytes();
35+
std::vector<uint8_t> wasm(writeByteWasm.data.begin(),
36+
writeByteWasm.data.end());
37+
38+
LedgerKey contractCodeLedgerKey;
39+
contractCodeLedgerKey.type(CONTRACT_CODE);
40+
contractCodeLedgerKey.contractCode().hash = sha256(wasm);
41+
42+
SorobanResources restoreResources;
43+
restoreResources.footprint.readWrite = {contractCodeLedgerKey};
44+
restoreResources.instructions = 0;
45+
restoreResources.readBytes = 2000;
46+
restoreResources.writeBytes = 2000;
47+
48+
tx.ext.v(1);
49+
tx.ext.sorobanData().resources = restoreResources;
50+
tx.ext.sorobanData().resourceFee = 55'000'000;
51+
52+
return {txEnv, contractCodeLedgerKey};
53+
}
54+
1055
std::pair<TransactionEnvelope, LedgerKey>
1156
getUploadTx(PublicKey const& publicKey, SequenceNumber seqNum)
1257
{

src/main/SettingsUpgradeUtils.h

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
namespace stellar
66
{
77

8+
std::pair<TransactionEnvelope, LedgerKey>
9+
getWasmRestoreTx(PublicKey const& publicKey, SequenceNumber seqNum);
10+
811
std::pair<TransactionEnvelope, LedgerKey>
912
getUploadTx(PublicKey const& publicKey, SequenceNumber seqNum);
1013

0 commit comments

Comments
 (0)