AbsorbingChaos / stx-miner-script

Script and tips to setup a Blockstack Testnet Miner
https://stacks101.com
MIT License
8 stars 7 forks source link

Download stacks-node (instead of building it) #17

Open friedger opened 4 years ago

friedger commented 4 years ago

There are regular nightly builds that could be used.

whoabuddy commented 4 years ago

That is definitely a direction I considered, I wrote this script before the builds were setup. I would need to figure out how to grab the most current ones each time.

whoabuddy commented 4 years ago

This may not be possible without being authenticated against GitHub, which is undesirable from the viewpoint of this script.

Some more info from searching the Internets:

Anyone with read access to the repository can use this endpoint. If the repository is private you must use an access token with the repo scope. GitHub Apps must have the actions:read permission to use this endpoint.

Sample code that fails:

curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/blockstack/stacks-blockchain/actions/artifacts/186057766/zip
{
  "message": "You must have the actions scope to download artifacts.",
  "documentation_url": "https://developer.github.com/v3/actions/artifacts/#download-an-artifact"
}

edit this may be a possible solution if Blockstack is interested: https://github.com/actions/upload-release-asset

friedger commented 4 years ago

We should ask for proper releases that contain the assets

Jason Schrader notifications@github.com schrieb am Do., 30. Juli 2020, 19:53:

This may not be possible without being authenticated against GitHub, which is undesirable from the viewpoint of this script.

Some more info from searching the Internets:

Anyone with read access to the repository can use this endpoint. If the repository is private you must use an access token with the repo scope. GitHub Apps must have the actions:read permission to use this endpoint.

Sample code that fails:

curl \ -H "Accept: application/vnd.github.v3+json" \https://api.github.com/repos/blockstack/stacks-blockchain/actions/artifacts/186057766/zip { "message": "You must have the actions scope to download artifacts.", "documentation_url": "https://developer.github.com/v3/actions/artifacts/#download-an-artifact" }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/AbsorbingChaos/bks-setup-miner/issues/17#issuecomment-666562821, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALBYWJ74E3HAEB4YIRMLQ3R6GXR7ANCNFSM4O62FJFA .

whoabuddy commented 4 years ago

@friedger I agree, just not sure they are ready for it, see blockstack/stacks-blockchain#1780

If the artifacts could be automatically converted to assets under a release, then it would be much faster to use something pre-compiled for a tool like this shell script, and save us the time of building the code manually.

whoabuddy commented 4 years ago

Update 20200906 - blockstack/stacks-blockchain#1821 is now merged that closes the issue linked above and contains two jobs that should create a release with distributables accessible via a (non-authenticated) script.

stacks-blockchain.yml#L131: # Create a new release if we're building a tag or a tag was passed in

stacks-blockchain.yml#L155: # Upload distributables to a new release if we're building a tag or a tag was passed in

However, at this time these two jobs have been skipped by every run since the master branch has not been updated yet, so we don't have a way to test. My guess is that once the new phase is released we will be able to try this out versus manually building everything! :+1:

whoabuddy commented 4 years ago

Looks like this may officially be possible now!

https://github.com/blockstack/stacks-blockchain/releases/tag/v23.0.0.0-krypton

UPDATE: close, but not quite there, will require some investigation

  1. curl works for the download curl -sS -O https://github.com/blockstack/stacks-blockchain/releases/tag/v23.0.0.0-krypton/linux-x64.zip
  2. installed unzip utility (not there by default?) sudo apt-get install unzip
  3. received error unzipping the file unzip linux-x64.zip

results in:

Archive: linux-x64.zip End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive. unzip: cannot find zipfile directory in one of linux-x64.zip or linuz-x64.zip.zip, and cannot find linux-x64.zip.ZIP, period.

I thought the period. was a nice touch at the end.

whoabuddy commented 4 years ago

Link to "latest" release will always be:

https://github.com/blockstack/stacks-blockchain/releases/latest/download/linux-x64.zip

Testing with v23.0.0.3-krypton release from Linux Mint, able to extract via built-in file manager menu option Extract Here and using the command-line unzip utility.

Testing with same release from Ubuntu Server, turns out curl is downloading a 163 byte file rather than the actual zip file. Add option -L to get the correct file and unzip works as expected.

Time to implement this in a new version of the script!

whoabuddy commented 4 years ago

Per GH documentation we can grab the latest release info via the API, which includes some info that might help prevent multiple downloads of the same version.

Example:

curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/blockstack/stacks-blockchain/releases/latest | jq .name

output: Release v23.0.0.3-krypton

Other notable fields:

Assets are available via the json as well, but each contains an ID and it may be easier to just use the URL listed in the previous comment. For example:

whoabuddy commented 4 years ago

First pass, seems to be working!

  1. unzip linux-x64.zip
  2. check for nvm, node, rustc and source env vars
  3. npx blockstack-cli (bundled version doesn't create same info with generate-sk --testnet, may be releated to #34)
  4. request BTC from faucet
  5. download krypton-miner-conf.toml from repo
  6. replace private key in krypton-miner-conf.toml
  7. start miner with: ./stacks-node start --config=krypton-miner-conf.toml

Per the last comment, storing/comparing tag_name and created_at would be a nice first step, followed by using the binary versus building the code.

Debug could still have an option to build the code from stacks-blockchain via #27 or similar.

whoabuddy commented 4 years ago

Download could apply to Mac or Linux

Windows could use a separate batch script?