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

boot script #429

Merged
merged 22 commits into from
Nov 6, 2024
Merged

boot script #429

merged 22 commits into from
Nov 6, 2024

Conversation

frankiebee
Copy link
Contributor

This adds a sort of "boot script" to the dev dir. It will jump start and deploy and fund faucets
it also fixs a bug with registering where we were getting "stale" events for a previous registration attempt found while writing this script includes this doc add in the dev/README.md:

sdk "boot script"

For convince at ./deploy-faucets.mjs is a script we use to "deploy" and fund the faucets for our entropy network you can refer to this section and the script itself to deploy your own faucets! Here is it running with a dev environment setup from the root of this project:

dev/bin/spin-up.sh four-nodes

I would take a deep breath here to allow for the 4 nodes to connect before running the next command bellow. On that note the deploy faucet script takes 3 arguments as you can see right now this script assumes you know what your doing if you are running it. So not a lot of bells and whitelist here.

the first argument is the endpoint to target, the second is the fundingSeed and the third faucetLookUpSeed

node dev/deploy-facuets.mjs ws://127.0.0.1:9944 0x786ad0e2df456fe43dd1f91ebca22e235bc162e0bb8d53c633e8c85b2af68b7a 0x20423b5ff4984bcb8922483c98afb7eaa056c40fc431f8a314211e3d94a4222f

this example above should run in a dev enviroment the funding seed is eve and the report looks something like this and will log to your console:

{
  'jump start status at start': 'Ready',
  'using faucet program pointer': '0x3a1d45fecdee990925286ccce71f78693ff2bb27eae62adf8cfb7d3d61e142aa',
  'faucet program pointer from deployment': '0x3a1d45fecdee990925286ccce71f78693ff2bb27eae62adf8cfb7d3d61e142aa',
  'faucet config': {
    max_transfer_amount: 20000000000,
    genesis_hash: 'a4b29c6895ae775fd291377fde31882f66244eaecbdc81e017ebb64d13b27b72'
  },
  'initial balance for funding account': 99999880954644628n,
  'initial funding faucet amount': 24999970238661157n,
  'modifiableKeys on chain': [
    '0x03cd98af667e48b4912c66576f5cdf18aee3764c7aad1c40b9c61d5ac012acf1f6',
    '0x0228aba3e529d3b78b0cd7454a5f694eb09a648ec488b0b4b8ce7cd9abedd96c28',
    '0x03b7c87542f57895d37f1a37a3460e27ec74de7216e6ed48609ffd2fac976ea94a'
  ],
  'faucet look up address': '5EqZMUYz7jjaG2baQWJRzUzM7YhBP4E8TAj6GgqDqWdXriTn',
  faucets: [
    {
      vk: '0x03cd98af667e48b4912c66576f5cdf18aee3764c7aad1c40b9c61d5ac012acf1f6',
      address: '5Gm6JA2ikMK1FfNn3MRmUPLWfi4p6eBzcFtKE1dnJvQpJgpg',
      balance: '24,999,970,238,661,157'
    },
    {
      vk: '0x0228aba3e529d3b78b0cd7454a5f694eb09a648ec488b0b4b8ce7cd9abedd96c28',
      address: '5FqourMb6c3z4rogDnaBb36Ku53ndy3eCiSdjRg2TUAztJ3X',
      balance: '24,999,970,238,661,157'
    },
    {
      vk: '0x03b7c87542f57895d37f1a37a3460e27ec74de7216e6ed48609ffd2fac976ea94a',
      address: '5CUQuSMxTzx74Zb8gsDobhaYSte9vt9a3Db5X6oio4X1pSX1',
      balance: '24,999,970,238,661,157'
    }
  ],
  endpoint: 'ws://127.0.0.1:9944'
}

```
I would take a deep breath here to allow for the 4 nodes to connect before running the next command bellow. On that note the deploy faucet script takes 3 arguments as you can see right now this script assumes you know what your doing if you are running it. So not a lot of bells and whitelist here.

the first argument is the `endpoint` to target, the second is the `fundingSeed` and the third `faucetLookUpSeed` <!--yes seeds()! not mnemonic go play alone this script will never take a mnemonic maybe one day i'll make it preterite to use like asci fireworks or something else integrated with the cli-->
Copy link
Contributor

Choose a reason for hiding this comment

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

can't really decipher what youre trying to say here, so we can go through it when youre online

max_transfer_amount: 20000000000,
genesis_hash: 'a4b29c6895ae775fd291377fde31882f66244eaecbdc81e017ebb64d13b27b72'
},
'initial balance for funding account': 99999880954644628n,
Copy link
Contributor

Choose a reason for hiding this comment

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

are we able to update the report to show human readable numbers with commas and such?

Copy link
Contributor

Choose a reason for hiding this comment

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

or just an inline comment here saying what that unit is. This doesn't need to be super pretty, it's diagnostic

genesis_hash: 'a4b29c6895ae775fd291377fde31882f66244eaecbdc81e017ebb64d13b27b72'
},
'initial balance for funding account': 99999880954644628n,
'initial funding faucet amount': 24999970238661157n,
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, re: human readable numbers

Comment on lines 13 to 15
if (!endpoint) throw new Error('please provide arguments for endpoint, fundingSeed, faucetLookUpSeed')
if (!fundingSeed) throw new Error('please provide arguments for fundingSeed, faucetLookUpSeed')
if (!faucetLookUpSeed) throw new Error('please provide arguments for faucetLookUpSeed')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!endpoint) throw new Error('please provide arguments for endpoint, fundingSeed, faucetLookUpSeed')
if (!fundingSeed) throw new Error('please provide arguments for fundingSeed, faucetLookUpSeed')
if (!faucetLookUpSeed) throw new Error('please provide arguments for faucetLookUpSeed')
if (!endpoint || !fundingSeed || !faucetLookUpSeed) throw new Error('endpoint, fundingSeed, and faucetLookupSeed are required arguments')

frankiebee and others added 3 commits November 5, 2024 07:52
Co-authored-by: Nayyir Jutha <nayyir.jutha@gmail.com>
Co-authored-by: Nayyir Jutha <nayyir.jutha@gmail.com>
…when running the script and move reporter proxy to a reusable function in testing-utils.mjs
Copy link
Contributor

Choose a reason for hiding this comment

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

🌶️ Trade offs!

  • this is a large file to include in repo / every CLI install?
  • might be needed if deploy-faucets.mjs is gonna be exported?

just double checking before we commit to this.... I wonder if this "deploy faucets" would be better in an optional stand-alone. It's likely too late for this release (no desire to rush), fine to kick that question down the road

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'm kicking down the road this one

@@ -78,7 +78,7 @@ export default class ProgramDev extends ExtrinsicBaseClass {
const responseOption = await this.substrate.query.programs.programs(pointer)

const programInfo = responseOption.toJSON()

if (programInfo === null) return null
Copy link
Contributor

Choose a reason for hiding this comment

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

🌶️ why would it ever be null ?
That feels more like it should throw an Error?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see your test, seems reasonable. I was worried it might have further reaching implications.

This is "new/ fixed" behaviour => CHANGELOG

Copy link
Contributor

Choose a reason for hiding this comment

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

program info is null if the program doesn't exist, which is still a valid return type so i don;t believe it constitutes an error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's null if it's not on chain


await registrationTxResult
const verifyingKey = await dataFromEvents
const result = await registrationTxResult
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend: consolidate with above line, i.e.

const result = await this.sendAndWaitFor(registerTx, {

const verifyingKey = await dataFromEvents
const result = await registrationTxResult
// @ts-ignore: not sure where the void is coming from
const verifyingKey = result.toHuman().event.data[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

Something like this could more clearly document what's being pulled and why data[1]

Suggested change
const verifyingKey = result.toHuman().event.data[1]
const [ address, verifyingKey ] = result.toHuman().event.data

Copy link
Contributor

Choose a reason for hiding this comment

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

we don't use the address here, not sure if this is a valid updated for now

Comment on lines +6 to +8
const endpoint = process.argv[2]
const fundingSeed = process.argv[3]
const faucetLookUpSeed = process.argv[4]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const endpoint = process.argv[2]
const fundingSeed = process.argv[3]
const faucetLookUpSeed = process.argv[4]
const [_, __, endpoint, fundingSeed, faucetLookupSeed] = process.argv

Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if this is a necessary improvement at this moment, we can clean up the code after the initial release, and just push out a minor patch

Comment on lines +13 to +15
if (!endpoint) throw new Error('please provide arguments for endpoint, fundingSeed, faucetLookUpSeed')
if (!fundingSeed) throw new Error('please provide arguments for fundingSeed, faucetLookUpSeed')
if (!faucetLookUpSeed) throw new Error('please provide arguments for faucetLookUpSeed')
Copy link
Contributor

Choose a reason for hiding this comment

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

move these into checkEndpoint functions etc

Comment on lines 66 to 69
const jumpStartStatus = (await moneyBags.substrate.query.stakingExtension.jumpStartProgress()).toHuman().jumpStartStatus
report['jump start status at start'] = jumpStartStatus
// deploy faucet program to chain if not already up
if (jumpStartStatus === 'Ready') await jumpStartNetwork(moneyBags, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Break the steps up a bit more with space + comments?

Suggested change
const jumpStartStatus = (await moneyBags.substrate.query.stakingExtension.jumpStartProgress()).toHuman().jumpStartStatus
report['jump start status at start'] = jumpStartStatus
// deploy faucet program to chain if not already up
if (jumpStartStatus === 'Ready') await jumpStartNetwork(moneyBags, true)
// Jump Start
const jumpStartStatus = (await moneyBags.substrate.query.stakingExtension.jumpStartProgress()).toHuman().jumpStartStatus
report['jump start status at start'] = jumpStartStatus
if (jumpStartStatus === 'Ready') await jumpStartNetwork(moneyBags, true)

report['faucet program pointer from deployment'] = await moneyBags.programs.dev.deploy(faucetProgram, configurationSchema, auxDataSchema)
}
// transfer funds to faucet account "enough" to register (5 whole tokens)
await sendMoney(moneyBags, faucetRing.accounts.registration.address, BigInt(5 * 10 ** 10))
Copy link
Contributor

@mixmix mixmix Nov 5, 2024

Choose a reason for hiding this comment

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

🔥
Do we have the 1e10 / 10**10 constant defined anywhere in this Repo
I'd like to see at least at top of file

const BITS_PER_TOKEN = 1e10
Suggested change
await sendMoney(moneyBags, faucetRing.accounts.registration.address, BigInt(5 * 10 ** 10))
await sendMoney(moneyBags, faucetRing.accounts.registration.address, BigInt(5 * BITS_PER_TOKEN))

Copy link
Contributor

Choose a reason for hiding this comment

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

This number should be related to the FAUCET_COUNT ??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 10 to 12
const faucetCount = 3
// change me if you change the schemas!
const pointer = '0x3a1d45fecdee990925286ccce71f78693ff2bb27eae62adf8cfb7d3d61e142aa'
Copy link
Contributor

Choose a reason for hiding this comment

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

style: I like these things as CONST so when I see them I know to look at top of file

Suggested change
const faucetCount = 3
// change me if you change the schemas!
const pointer = '0x3a1d45fecdee990925286ccce71f78693ff2bb27eae62adf8cfb7d3d61e142aa'
const FAUCET_COUNT = 3
// change me if you change the schemas!
const POINTER = '0x3a1d45fecdee990925286ccce71f78693ff2bb27eae62adf8cfb7d3d61e142aa'

Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think style updates are needed right now to get this out the door, we can polish the boot script after the release sicne we don't really have that many devs that are going to be using the script at the moment

Copy link
Contributor

Choose a reason for hiding this comment

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

falls in category "important but not urgent" - if we align our code styles a little we get faster parsing + code reviews.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes will do this my side so i can make sure it's every where

Comment on lines 133 to 134
const modifiableKeys = await moneyBags.substrate.query.registry.modifiableKeys(faucetRing.accounts.registration.address)
report['modifiableKeys on chain'] = modifiableKeys.toHuman()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const modifiableKeys = await moneyBags.substrate.query.registry.modifiableKeys(faucetRing.accounts.registration.address)
report['modifiableKeys on chain'] = modifiableKeys.toHuman()
const verifiyingKeys = await moneyBags.substrate.query.registry.modifiableKeys(faucetRing.accounts.registration.address)
report['verifyingKeys on chain'] = verifyingKeys.toHuman()
// These should be the same as faucets.map(faucet => faucet['verification key'])

@@ -0,0 +1,20 @@
const monkeys = ['🙉 - pandemonium', '🙈 - chaos', '🙊 - anarchy', '🐵 - entropy']
Copy link
Contributor

Choose a reason for hiding this comment

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

great addition

rh0delta
rh0delta previously approved these changes Nov 6, 2024
Co-authored-by: mix irving <mix@protozoa.nz>
Copy link
Contributor

@mixmix mixmix left a comment

Choose a reason for hiding this comment

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

Looks good to me

@frankiebee frankiebee merged commit 5cfbb7c into main Nov 6, 2024
3 checks passed
@frankiebee frankiebee deleted the frankie/boot-script branch November 6, 2024 09:28
@github-actions github-actions bot locked and limited conversation to collaborators Nov 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants