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

Soroban settings upgrade contract and script #3843

Merged
merged 6 commits into from
Jul 31, 2023

Conversation

sisuresh
Copy link
Contributor

Description

This is still a work in progress.

What it can do -

  1. Retrieve settings through Soroban RPC -
python3 SorobanSettingsUpgrade.py getSettings -id 10
<LedgerEntryData [type=8, config_setting=<ConfigSettingEntry [config_setting_id=10, state_expiration_settings=<StateExpirationSettings [max_entry_expiration=<Uint32 [uint32=6312000]>, min_temp_entry_expiration=<Uint32 [uint32=16]>, min_persistent_entry_expiration=<Uint32 [uint32=86400]>, auto_bump_ledgers=<Uint32 [uint32=0]>, persistent_rent_rate_denominator=<Int64 [int64=0]>, temp_rent_rate_denominator=<Int64 [int64=0]>, max_entries_to_expire=<Uint32 [uint32=0]>, bucket_list_size_window_sample_size=<Uint32 [uint32=0]>, eviction_scan_size=<Uint64 [uint64=0]>]>]>]>
  1. Setup an upgrade that is hardcoded in the script through Soroban RPC -
python3 SorobanSettingsUpgrade.py setupUpgrade
...
...
url encoded upgrade: /SW4vX5dqlA1GNLaAPt%2BtIiLqZjGIOpJ1lrBoV4pA8tvy3TMBHuWLuVigdUG2XA/k1KxRH6RQ8WUKprvSRfm4A%3D%3D

What we can't do yet -

  1. Specify which settings to upgrade with a better UX than updating the hardcoded setting in the script. Maybe a JSON file with the upgrades will work well.
  2. Update the network used (futurenet vs standalone vs pubnet) on the command line.
  3. Directly submit the setup transactions to stellar-core through the tx endpoint to reduce dependencies during emergencies.
  4. Fund the source account with friendbot if it doesn't exist.
  5. Add an endpoint in stellar-core that takes a proposed ConfigUpgradeSetKey and returns what the upgrade diff will be.

Checklist

  • Reviewed the contributing document
  • Rebased on top of master (no merge commits)
  • Ran clang-format v8.0.0 (via make format or the Visual Studio extension)
  • Compiles
  • Ran all tests
  • If change impacts performance, include supporting evidence per the performance document

- Description - A python script that can setup a setting upgrade or retrieve
current settings for Futurenet through Soroban RPC. The next step is to submit all transactions directly to stellar-core's `tx` endpoint. Note that the actual upgrade command will have to be
submitted manually on the core nodes.
- Prerequisites - run `make build` under `soroban-settings/write_upgrade_bytes`
Copy link
Contributor

Choose a reason for hiding this comment

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

make build wanted me to install the target wasm32-unknown-unknown so we can add a pre-requisite to run rustup target add wasm32-unknown-unknown.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

submitted manually on the core nodes.
- Prerequisites - run `make build` under `soroban-settings/write_upgrade_bytes`
to the build WASM contract used to write the proposed upgrade.
- Usage - Ex. `SorobanSettingsUpgrade.py getSettings -id 10` to print out the
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Maybe mention to install python

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 added python3 to the commands.

from stellar_sdk.soroban import SorobanServer
from stellar_sdk.soroban.types import Address, Int128, Bytes
from stellar_sdk.soroban.soroban_rpc import GetTransactionStatus
from stellar_sdk.xdr import TransactionMeta, LedgerKey, ConfigUpgradeSet, ConfigSettingContractExecutionLanesV0, ConfigUpgradeSetKey, ConfigSettingEntry, StateExpirationSettings, Uint32, Uint64, Int64, Hash, LedgerKeyConfigSetting, ConfigSettingID
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding ConfigSettingContractLedgerCostV0 since that has read/write bytes and ledger settings there? We can throttle those using this script.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or we can add this in next iteration of the script.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah! I see what the id argument corresponds to ConfigSettingEntry XDR union. So passing 9 would fetch us contract_data_entry_size_bytes.

Copy link

@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.

quick drive-by review 🏎️💨

from stellar_sdk.soroban import SorobanServer
from stellar_sdk.soroban.types import Address, Int128, Bytes
from stellar_sdk.soroban.soroban_rpc import GetTransactionStatus
from stellar_sdk.xdr import TransactionMeta, LedgerKey, ConfigUpgradeSet, ConfigSettingContractExecutionLanesV0, ConfigUpgradeSetKey, ConfigSettingEntry, StateExpirationSettings, Uint32, Uint64, Int64, Hash, LedgerKeyConfigSetting, ConfigSettingID
Copy link

Choose a reason for hiding this comment

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

why don't you from stellar_sdk.xdr import * and then you don't need that weird alias at the top heh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Fixed

import argparse
import time
import sys
sys.path.append("/Users/siddharthsuresh/dev/py-stellar-base")
Copy link

Choose a reason for hiding this comment

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

this has no effect if it's after the imports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. This wasn't necessary.


assert wasm_id, "wasm id should not be empty"

print("creating contract...")
Copy link

Choose a reason for hiding this comment

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

you're gonna wanna check the GetTransactionStatus.FAILED case here heh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Updated to assert success.

@MonsieurNicolas
Copy link
Contributor

Not sure if you want to do this in this PR, but there is a section on network upgrades https://github.com/stellar/stellar-core/blob/master/docs/software/admin.md#network-configuration that needs to updated for Soroban (it's the operator user guide)

@sisuresh
Copy link
Contributor Author

Not sure if you want to do this in this PR, but there is a section on network upgrades https://github.com/stellar/stellar-core/blob/master/docs/software/admin.md#network-configuration that needs to updated for Soroban (it's the operator user guide)

Updated.

import sys

# The soroban branch of py-stellar-base hasn't been merged into main and released yet, so we have to install it locally.
sys.path.append("/Users/dev/py-stellar-base")
Copy link

Choose a reason for hiding this comment

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

you can install from the branch via pip, if you want to add that to the instructions

pip install git+https://github.com/StellarCN/py-stellar-base.git@soroban

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wow I'm a python noob. This is good to know. Thanks!

I removed this line here and added instructions yesterday for installing from source but the PR isn't updating for some reason.

Copy link

Choose a reason for hiding this comment

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

Heh this is thanks to @overcat, from here: stellar/sorobanathon#20. I do see it's gone from the branch, though 👍

# Get upgrade xdr

upgrade = get_upgrade_set()
upgrade_xdr = upgrade.to_xdr()
Copy link

Choose a reason for hiding this comment

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

nit: unused

# Get upgrade
upgrade_key = get_upgrade_key(contract_id_hash, upgrade_hash).to_xdr()
url_encoded_key = urllib.parse.quote(upgrade_key)
print(f"url encoded upgrade: {url_encoded_key}")
Copy link

@Shaptic Shaptic Jul 28, 2023

Choose a reason for hiding this comment

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

Just to be sure, Core's http server can handle the /s in the encoded key and won't treat them as endpoint paths? You can pass safe='' to quote if not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah core handles it

@dmkozh
Copy link
Contributor

dmkozh commented Jul 31, 2023

r+ a8ef9cc

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.

6 participants