Skip to content

Commit

Permalink
fix: prefund container suffixes for k8s (#818)
Browse files Browse the repository at this point in the history
**purpose:**
- fix issue when running with k8s backend, where prefunded accts
services are not destroyed instantaneously and this causes 'service
already exists' errors

**tests:**

original error:
```
Running ethereal to derive private keys of key 1
There was an error executing Starlark code
An error occurred executing instruction (number 9) at github.com/rebelArtists/ethereum-package/src/prefunded_accounts/get_prefunded_accounts.star[12:34]:
  run_sh(name="run-ethereal-private-key", run="private_key=$(/app/ethereal hd keys --seed=\"code code code code code code code code code code code quality\" --path=\"m/44'/60'/0'/0/1\" | awk '/Private key/{print substr($NF, 3)}'); echo -n $private_key", image="wealdtech/ethereal:latest", description="Running ethereal to derive private keys of key 1")
  Caused by: error occurred while creating a run_sh task with image: wealdtech/ethereal:latest
  Caused by: Failed registering service with name: 'run-ethereal-private-key'
  Caused by: Error registering service 'run-ethereal-private-key'
  Caused by: An error occurred creating Kubernetes service in enclave '629c500d8cda49d3b743a3d143d336b7' with ID 'run-ethereal-private-key'
  Caused by: Failed to create service 'run-ethereal-private-key' in namespace 'kt-cdk'
  Caused by: services "run-ethereal-private-key" already exists

Error encountered running Starlark code.
```

with fix (service name has key number suffix to prevent clash):
```
...
Running ethereal to derive eth address of key 19
Command returned with exit code '0' and the following output: 0x6d5821d6D50108649480A63d6f337F8473d661ef

Running ethereal to derive private keys of key 20
Command returned with exit code '0' and the following output: efa8369dbb93b8b452535ab87f526465e9441c7c5809a942908662b925eaff42

Running ethereal to derive eth address of key 20
Command returned with exit code '0' and the following output: 0x31C916e6EAD0DB63BeD514a6f292C526696F0549

Printing a message
PRE_FUNDED_ACCOUNTS: [struct(address = "0xXYZ", private_key = "ABCDEFG"),...]
```

---------

Co-authored-by: Rafael Matias <[email protected]>
  • Loading branch information
rebelArtists and skylenet authored Oct 31, 2024
1 parent bf0313f commit 968cfbd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/prefunded_accounts/get_prefunded_accounts.star
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ def get_accounts(plan, mnemonic, num_of_keys=21):
PRE_FUNDED_ACCOUNTS = []
plan.print("mnemonic: {0}".format(mnemonic))
for current_key in range(num_of_keys):
private_key_service_name = "run-ethereal-private-key-{0}".format(current_key)
eth_address_service_name = "run-ethereal-eth-address-{0}".format(current_key)

private_key = plan.run_sh(
name="run-ethereal-private-key",
name=private_key_service_name,
image=IMAGE,
description="Running ethereal to derive private keys of key {0}".format(
current_key
Expand All @@ -20,7 +23,7 @@ def get_accounts(plan, mnemonic, num_of_keys=21):
),
)
eth_address = plan.run_sh(
name="run-ethereal-eth-address",
name=eth_address_service_name,
image=IMAGE,
description="Running ethereal to derive eth address of key {0}".format(
current_key
Expand Down

0 comments on commit 968cfbd

Please sign in to comment.