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 support for running both a TESTNET and an alpha PUBLIC network Turret #1

Merged
merged 25 commits into from
Feb 28, 2022

Conversation

kalepail
Copy link
Contributor

We're finally ready to take our first (very safe) steps in the universe of public network Turrets! 🎉

This PR adds all the necessary config and script changes to make this functionality possible.

Note that when the STELLAR_NETWORK = "PUBLIC" a new check will come into play on the txFunction upload endpoint blocking all contract uploads except for those hashes which have been manually added to the new ALLOWED KV store.

So here are the necessary steps to get everything up and running.

  1. As per a community Discord discussion the name of Stellar Turrets has changed from TSS to Stellar Turrets so I'm phasing out stellar-tss or tss-stellar in favor of stellar-turrets. (note I'll probably change the name of this repo as well). Because of this change you'll likely need to delete your AWS deployment and spin up a new one under this new name. AWS is weird with name changes. To do that just navigate into your AWS console under CloudFormation and delete the tss-stellar stack.
  2. Next we need to reconfigure the existing testnet Wrangler deploy to match the new name. This is as simple as just going into the Wrangler dashboard and manually renaming it to, in my case, stellar-turrets-testnet. You could also delete the existing Worker as it would get recreated the next time you deploy. For the KV navigate to the KV tab and re-prefix the existing KV stores with the new stellar-turrets-testnet. For Cloudflare these changes are more cosmetic than necessary as CF works of ids not names of things, but it should help in the future if we start matching everything with their name.
  3. Next we need to add the stellar-turrets-alpha to our Cloudflare account. The best way to accomplish this is first to run the setup.sh script from within the ./wrangler directory again. You may need to comment out the commands for the existing testnet KV stores but I think it should just error out or skip those. Keep track of the alpha outputs and I strongly suggest using a new Stellar key for the TURRET_SIGNER than you're using for the testnet.
  4. Once you've got your new (and old) KV ids you're ready to run the npm run preinit and then npm run init. As the script walks you through the flow just paste in all the appropriate values. If you've forgotten what they were or are they should be in the old .env file or in the Cloudflare dashboard.
  5. Assuming this all worked you should now have a wrangler.toml file and stellar.toml file which "check out", full of meaningful and appropriate values. Feel free to edit or modify as necessary. The init and preint scripts are helpers not have-tos.
  6. You can now deploy the wrangler scripts with wrangler publish (for testnet) and wranger publish --env alpha (for alpha, duh)
    6.1. On the first publish of a new --env you'll need to also create the Durable Object so you'll need to run the publish command with the --new-class TxFees flag. So in the case of an alpha publish it would be wrangler --env alpha --new-class TxFees publish
  7. Finally we move to the ./serverless directory and run npx envdist testnet and npx envdist alpha and fill in the appropriate values. Note if you already have a .env file you can delete that as we'll now be creating and relying on .env.testnet and .env.alpha for the deploy process. Once those are built you should be able to just run sls deploy (for testnet) and sls deploy --stage alpha (for alpha, again, duh)
  8. Assuming these all go off without a hitch you should be fully setup with both a testnet and an alpha public network Turrets! Remember to go back to the Wrangler vars and fill in the {TESTNET|ALPHA}_TURRET_FUNCTION_RUNNER_URL values if you didn't have them earlier. Same goes for the SLS_TURRET_BASE_URL variable in the Serverless env files. The deployments are only as good as your configuration so please ensure you've done it right.
  9. Finally please please please use different {TESTNET|ALPHA}_TURRET_ADDRESS/SLS_TURRET_SIGNER_ACCOUNT addresses between your testnet and alpha Turrets. Duplicating these is a bad idea as a leak to a Testnet key is no big deal but a leak on the public network could equal loss of funds. The time to be safe is now!

If any of these instructions were wrong, incomplete or out of order please comment here so we can adjust. Good luck!

@kalepail
Copy link
Contributor Author

Note this PR breaks the current GitHub Actions for Serverless. The current flow alters the env variables depending on which Turret you're deploying. With GitHub secrets you would have to set once either for testnet or alpha but it wound't support deploying to both. Will need to address this before merging to main.

kalepail and others added 2 commits February 25, 2022 09:07
* force exclude sodium-native

* Update yarn.lock

* Added btfdev to TURRETS_LIST

* removed docs directory as that now exists in a separate repo

* STRI 1,2,4,5,6,7, semi-automated deployments (#2)

* Minimum fix for STRI 4. - requires exact upload fee

* addresses stri 7 this validates that the xdr is valid.

* this validates that the function fields are valid json or throws an err

* Addresses STRI 1 + 2
Adds: SLS_TIMEOUT env var
 - Prevent multiple contracts from running at one time without having enough money
 - Adds const reserveFee = new BigNumber(SLS_TIMEOUT).dividedBy(RUN_DIVISOR).toFixed(7)
 - Hold a fee in reserver for the maximum amount of possible charges based on the
   SLS_TIMEOUT and RUN_DIVISOR env vars
 - subtracts the reserve fee from the current fee balance for the auth'ed hash.
   after execution unused fees are refunded, and cost returned.

* update build system to use esbuild-loader and update lodash for lodash-es

* remove residual docs github actions definition

* refactor from alpha to public

* update package.json and add license

* update dotenv template file.

* update wrangler.toml.dist template file for new bindings

* remove run-script-os

* Assisted automated deployment.
This commit brings automated deployment of the wrangler CLI in one step.
This is still slightly a WIP but it does work.
To deploy a turret, go to the wrangler folder and run "node deploy.mjs"
You might need to have turned on the node --experimental-vm-modules
Please use node version 16.13.0 or higher.

 On branch template
 Changes to be committed:
	modified:   ../README.md
	new file:   deploy.mjs
	new file:   deployrest.mjs
	modified:   package.json
	modified:   wrangler.toml.dist

 Changes not staged for commit:
	modified:   package-lock.json

 Untracked files:
	curlrequests.ps
	deploy/
	foralex.mjs
   tests.js
   ci.js
   sockets/

* remove docs folder

* Rewrite Heal Function
This commit rewrites the heal function and moves the endpoint to
/trust/heal

* Update package.json, add toml

* add missing const

* Update the TOML parser in heal for new format

This commit updates the toml parser in the heal function to use the
following format for future turret tomls.
```toml
[[TURRETS]]
NAME="script3-mainnet"
HOME_DOMAIN="www.turret.script3.io"
PUBLIC_KEY="GABMKJM6I25XI4K7U6XWMULOUQIQ27BCTMLS6BYYSOWKTBUXVRJSXHYQ"
[[TURRETS]]
NAME="script3-mainnet"
HOME_DOMAIN="www.turret.script3.io"
PUBLIC_KEY="GABMKJM6I25XI4K7U6XWMULOUQIQ27BCTMLS6BYYSOWKTBUXVRJSXHYQ"
```

* cache control account response in heal

Co-authored-by: Alex Mootz <alexmootz@hotmail.com>

* reordered and renamed some things for consistency

* use underscores to denote legacy or wip files

* Final changes for STRI  (#11)

* Clarify inputs and make heal return user sourced xdr

* update to no use setTimeout

* Code Cleanup

* update toml format

* update imports of lodash-es

* update alpha to public

* pass env to helper functions

* readd cache for get calls

* update heal helper functions

Co-authored-by: Alex Mootz <alexmootz@hotmail.com>

* Clarify inputs and make heal return user sourced xdr (#10)

* Clarify inputs and make heal return user sourced xdr

* update to no use setTimeout

Co-authored-by: Tyler van der Hoeven <hi@tyvdh.com>

Co-authored-by: lmorgan824 <usa51008@gmail.com>
Co-authored-by: Silence <35656692+silence48@users.noreply.github.com>
Co-authored-by: Alex Mootz <alexmootz@hotmail.com>
Co-authored-by: mootz12 <38118608+mootz12@users.noreply.github.com>
@kalepail kalepail merged commit cf6de0e into main Feb 28, 2022
@kalepail kalepail deleted the alpha-public-network branch February 28, 2022 14:43
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.

2 participants