Skip to content

Commit

Permalink
Add tx to restore wasm blob to get-settings-upgrade-txs
Browse files Browse the repository at this point in the history
  • Loading branch information
sisuresh committed Jun 6, 2024
1 parent 982c95a commit 6935d82
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 12 deletions.
16 changes: 9 additions & 7 deletions docs/software/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ Command options can only by placed after command.
Option **--signtxs** will prompt for a secret key and sign the TransactionEnvelopes.<br>

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 <COMMAND>** Send an [HTTP command](#http-commands) to an
Expand Down
8 changes: 6 additions & 2 deletions scripts/settings-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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')'"
8 changes: 5 additions & 3 deletions src/main/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,20 +1293,22 @@ getSettingsUpgradeTransactions(CommandLineArgs const& args)
PublicKey pk = KeyUtils::fromStrKey<PublicKey>(id);

std::vector<TransactionEnvelope> 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;

Expand Down
45 changes: 45 additions & 0 deletions src/main/SettingsUpgradeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,51 @@
namespace stellar
{

std::pair<TransactionEnvelope, LedgerKey>
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<uint8_t> 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<TransactionEnvelope, LedgerKey>
getUploadTx(PublicKey const& publicKey, SequenceNumber seqNum)
{
Expand Down
3 changes: 3 additions & 0 deletions src/main/SettingsUpgradeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
namespace stellar
{

std::pair<TransactionEnvelope, LedgerKey>
getWasmRestoreTx(PublicKey const& publicKey, SequenceNumber seqNum);

std::pair<TransactionEnvelope, LedgerKey>
getUploadTx(PublicKey const& publicKey, SequenceNumber seqNum);

Expand Down

5 comments on commit 6935d82

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

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

saw approval from dmkozh
at sisuresh@6935d82

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

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

merging sisuresh/stellar-core/upgrade-restore = 6935d82 into auto

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

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

sisuresh/stellar-core/upgrade-restore = 6935d82 merged ok, testing candidate = b3aeb14

@latobarita
Copy link
Contributor

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

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

fast-forwarding master to auto = b3aeb14

Please sign in to comment.