-
Notifications
You must be signed in to change notification settings - Fork 30
Fix unstaking flows #342
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
Fix unstaking flows #342
Conversation
scripts/utils.py
Outdated
@@ -69,7 +69,7 @@ | |||
GAS_PARAMS = { | |||
"maxFeePerGas": 30_000_000_000, | |||
"maxPriorityFeePerGas": 3_000_000_000, | |||
"gas": 500_000, | |||
"gas": 5_000_000, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives issues on Tenderly sometimes. Discuss if this should be increased
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xArdi "gas": 500_000
has caused issues sometimes on Tenderly when sending the unstake transaction. I suspect it usually runs out of gas due to being executed when several checkpoints have not been called (thus it needs to do extra work). This seems not happening on mainnet, where the checkpoint is periodically called. What do you suggest to do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we do this using automatic gas estimation. Let's keep it as-is for now, the middleware doesnt have this problem, and is supposed to be the long-term solution for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but in this script we are not doing it. So what should we do? keep it asi it is 500.000 ? increase it?
SERVICE_ID_PATH = Path(STORE_PATH, "service_id.txt") | ||
PACKAGES_PATH = Path(SCRIPT_PATH, "..", "trader", "packages") | ||
|
||
REGISTRY_JSON = PACKAGES_PATH / "valory" / "contracts" / "service_registry" / "build" / "ServiceRegistryL2.json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant file from contracts (ServiceRegistryL2.json)
@@ -61,7 +61,6 @@ | |||
DEFAULT_ON_CHAIN_INTERACT_SLEEP = 6.0 | |||
|
|||
|
|||
ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already imported
if [ "${USE_STAKING}" = true ]; then | ||
poetry run python "../scripts/staking.py" "$service_id" "$CUSTOM_SERVICE_REGISTRY_ADDRESS" "$CUSTOM_STAKING_ADDRESS" "../$operator_pkey_path" "$rpc" "$unstake"; | ||
fi | ||
# Unstake if applicable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script already takes care if the service is staked or not.
contracts/AgentMech.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used anymore. It was used when the mech events were retrieved through the RPC. Now they are retrieved through the Subgraph.
contracts/ServiceRegistryL2.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already available on the packages folder of the service.
# Display information of the Git repository | ||
current_branch=$(git rev-parse --abbrev-ref HEAD) | ||
latest_commit_hash=$(git rev-parse HEAD) | ||
echo "Current branch: $current_branch" | ||
echo "Commit hash: $latest_commit_hash" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Help identify commit user is running when users request help.
cost_of_bonding=$MIN_STAKING_BOND_XDAI | ||
fi | ||
|
||
if [ "$local_service_hash" != "$remote_service_hash" ] || [ "$on_chain_agent_id" != "$AGENT_ID" ] || [ "$on_chain_agent_bond" != "$cost_of_bonding" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If hash, agent_id or bond don't match the expected values, it requires an on-chain service update.
cmd="poetry run autonomy mint \ | ||
--retries $RPC_RETRIES \ | ||
--timeout $RPC_TIMEOUT_SECONDS \ | ||
--use-custom-chain \ | ||
service packages/valory/services/trader/ \ | ||
--key \"../$operator_pkey_path\" $password_argument \ | ||
--nft $nft \ | ||
-a $AGENT_ID \ | ||
-n $n_agents \ | ||
--threshold $n_agents \ | ||
--update \"$service_id\"" | ||
|
||
if [ "${USE_STAKING}" = true ]; then | ||
cost_of_bonding=$MIN_STAKING_BOND_OLAS | ||
poetry run python "../scripts/update_service.py" "../$operator_pkey_path" "$nft" "$AGENT_ID" "$service_id" "$CUSTOM_OLAS_ADDRESS" "$cost_of_bonding" "packages/valory/services/trader/" "$rpc" $password_argument | ||
cmd+=" -c $cost_of_bonding --token $CUSTOM_OLAS_ADDRESS" | ||
else | ||
cost_of_bonding=$MIN_STAKING_BOND_XDAI | ||
cmd="poetry run autonomy mint \ | ||
--retries $RPC_RETRIES \ | ||
--timeout $RPC_TIMEOUT_SECONDS \ | ||
--use-custom-chain \ | ||
service packages/valory/services/trader/ \ | ||
--key \"../$operator_pkey_path\" $password_argument \ | ||
--nft $nft \ | ||
-a $AGENT_ID \ | ||
-n $n_agents \ | ||
-c $cost_of_bonding \ | ||
--threshold $n_agents \ | ||
--update \"$service_id\"" | ||
cmd+=" -c $cost_of_bonding" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the already available autonomy command (--token
option was not available and a custom script was created)
NO_STAKING_PROGRAM_ID: ZERO_ADDRESS, | ||
"quickstart_beta_hobbyist": "0x389B46c259631Acd6a69Bde8B6cEe218230bAE8C", | ||
"quickstart_beta_expert": "0x5344B7DD311e5d3DdDd46A4f71481bD7b05AAA3e", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified this data structure - we only need the contract address. All remaining information can be fetch on-chain.
Resolves #151 |
This PR contains several improvements in terms of updating the staking/unstaking flow:
run_service.sh
/contracts
and uses the files already available on the packages folder.update_service.py
script and uses the built-in autonomy command.