Skip to content

Commit

Permalink
Add multisig setup
Browse files Browse the repository at this point in the history
  • Loading branch information
clemensgg committed Jan 17, 2024
1 parent 2e2ae2b commit 3536e71
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
10 changes: 9 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ CR_REPO_OWNER='cosmos'
CR_REPO_NAME='chain-registry'
CR_FOLDER_PATH='_IBC'
CR_CHAIN_NAME='cosmoshub'
RPC_URL = "https://rpc.cosmos.directory:443/cosmoshub"
RPC_URL='https://rpc.cosmos.directory:443/cosmoshub'
REST_URL='https://rest.cosmos.directory:443/cosmoshub'

GRANTER_ACCOUNT='cosmos14r8ff03jkyac2fukjtfrfgaj8ehjlhds5ec2zp'
PERIOD_DURATION='86400'

TOTAL_SIGNERS='5'
MULTISIG_THRESHOLD='3'
SIGNER_1_PUBKEY='AiIW8DesZL5lGOihwuuFvy68qpsgNnagoqPyiL1gRxlP'
SIGNER_2_PUBKEY='AwtmdDXDpjJnujcV4QRpL7mSrXr/rTru+oKKQNbe4v0h'
SIGNER_3_PUBKEY='ApClmSS+8M3x3lLWPdGEzd3fyVCx4jXEPrDmcXs0CRzh'
SIGNER_4_PUBKEY='A67JHk7NWw3pKfEk/DkjsAWXhqN+OeZHKS0cmdh6dSry'
SIGNER_5_PUBKEY='A2zAex39vqIQw/oxrFS/D5FemgA+N/xxDwCB7HzlPKrP'

# INDEXER
START_BLOCK_HEIGHT='18734300'

Expand Down
44 changes: 43 additions & 1 deletion utils/generate_feegrant_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,48 @@
rpc = os.getenv('RPC_URL', 'https://rpc.cosmos.directory:443/cosmoshub')
period_duration = os.getenv('PERIOD_DURATION', '86400')

total_signers_str = os.getenv('TOTAL_SIGNERS', '5')
multisig_threshold_str = os.getenv('MULTISIG_THRESHOLD', '3')

try:
total_signers = int(total_signers_str)
multisig_threshold = int(multisig_threshold_str)
except ValueError:
raise ValueError("Error: Invalid values for TOTAL_SIGNERS or MULTISIG_THRESHOLD in the environment variables.")

signer_pubkeys = [
os.getenv(f"SIGNER_{i}_PUBKEY") for i in range(1, total_signers + 1)
]

if None in signer_pubkeys:
raise ValueError("Error: Not all signer public keys are provided.")

# Check if the local key named multisig-relayer-feegrant exists
def check_if_key_exists():
command = f"{daemon_name} --home {daemon_home} keys list --output json"
try:
result = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
keys_list = json.loads(result.stdout)
return any(key.get("name") == "multisig-relayer-feegrant" for key in keys_list)
except subprocess.CalledProcessError as e:
print(f"Error running command: {e.stderr}")
return False
except json.JSONDecodeError as e:
print(f"Error parsing JSON from command output: {e.msg}")
return False

if not check_if_key_exists():
# Add individual signer keys to the keyring
for i, signer_pubkey in enumerate(signer_pubkeys, start=1):
signer_pubkey_json = f'{{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"{signer_pubkey}"}}'
add_signer_key_command = f"{daemon_name} --home {daemon_home} keys add ms{i} --pubkey '{signer_pubkey_json}'"
subprocess.run(add_signer_key_command, shell=True, check=True)

# Add the multisig key
multisig_pubkeys = ",".join([f"ms{i}" for i in range(1, total_signers + 1)]) # Adjust for the number of signers
add_multisig_key_command = f"{daemon_name} --home {daemon_home} keys add multisig-relayer-feegrant --multisig {multisig_pubkeys} --multisig-threshold {multisig_threshold}"
subprocess.run(add_multisig_key_command, shell=True, check=True)

def fetch_account_data(granter_account):
url = f"https://rest.cosmos.directory/cosmoshub/cosmos/auth/v1beta1/accounts/{granter_account}"
response = requests.get(url)
Expand Down Expand Up @@ -91,7 +133,7 @@ def main():
print(f" - Revocation due to either disabled status or renewal requirement.")

total_gas_limit = 80000 + 40000 * (len(all_messages) + 1)
flags = f"--home '{daemon_home}' --from '{granter_account}' --chain-id '{chain_id}' --gas {total_gas_limit} --gas-prices '{gas_prices}' --node '{rpc}' --offline --output json --yes --generate-only --sequence {sequence} --account-number {account_number}"
flags = f"--home '{daemon_home}' --from multisig-relayer-feegrant --chain-id '{chain_id}' --gas {total_gas_limit} --gas-prices '{gas_prices}' --node '{rpc}' --offline --output json --yes --generate-only --sequence {sequence} --account-number {account_number}"

if renew_needed or revoke_needed:
revoke_command = generate_feegrant_command(granter_account, operator['address'], None, None, None, flags, revoke=True)
Expand Down

0 comments on commit 3536e71

Please sign in to comment.