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

Implement checkpoint call for staking #135

Merged
merged 16 commits into from
Nov 16, 2023
Merged

Implement checkpoint call for staking #135

merged 16 commits into from
Nov 16, 2023

Conversation

Adamantios
Copy link
Collaborator

No description provided.

@Adamantios Adamantios added the enhancement New feature or request label Nov 15, 2023
@@ -88,9 +95,12 @@
FailedTransactionSubmissionRound: HandleFailedTxRound,
FinishedDecisionRequestTxRound: DecisionReceiveRound,
FinishedBetPlacementTxRound: RedeemRound,
FinishedRedeemingTxRound: ResetAndPauseRound,
FinishedRedeemingTxRound: CallCheckpointRound,
Copy link
Contributor

Choose a reason for hiding this comment

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

This means all services, even non-staking ones need to transition here...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct. Conceptually, it would not make much sense to add a check to any of the existing rounds on whether we should transition here or not. Therefore, CallCheckpointRound is always entered and immediately exits if the service is not staked.

)
self._safe_tx_hash = safe_hash[2:]

def wait_for_condition_with_sleep(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In order to perform the contract calls in a serialized manner, and only continue to the next step if the current call succeeded. Otherwise, the behaviour sleeps and retries the same call.

def async_act(self) -> Generator:
"""Do the action."""
with self.context.benchmark_tool.measure(self.behaviour_id).local():
yield from self.wait_for_condition_with_sleep(self._check_service_staked)
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't make sense for non-staking services.

I would have preferred non-staking services never reach this FSM. But given this design, you need at least some sort of boolean to track if this service even needs to do anything here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean now that it is implemented this way, it will work..

Copy link
Collaborator Author

@Adamantios Adamantios Nov 15, 2023

Choose a reason for hiding this comment

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

It does have a boolean in the synced data and checks on-chain only during the first period:

if self.synchronized_data.period_count != 0:
self.is_service_staked = self.synchronized_data.is_service_staked
return True

If not staked, it does nothing:

checkpoint_tx_hex = None
if self.is_service_staked:
yield from self.wait_for_condition_with_sleep(self._get_next_checkpoint)
if self.is_checkpoint_reached:
checkpoint_tx_hex = yield from self._prepare_safe_tx()
tx_submitter = self.matching_round.auto_round_id()
payload = CallCheckpointPayload(
self.context.agent_address,
tx_submitter,
checkpoint_tx_hex,
self.is_service_staked,
)

As mentioned above, it would not make much sense conceptually to check whether the service is staked in any of the other abcis.
Moreover, this implementation makes this component as much independent as possible, so that future services can easily make use of it.

Adamantios and others added 5 commits November 15, 2023 16:58
Also check if the maximum bet amount is available before sending a request, in case that the service is not using the kelly criterion. If the sum of the maximum bet amount and the mech price cannot be covered, then wait until the safe is refilled.
@Adamantios Adamantios merged commit 6a2db66 into main Nov 16, 2023
6 checks passed
@Adamantios Adamantios deleted the feat/checkpoint branch November 16, 2023 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants