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

feat: handle slashing state #51

Merged
merged 7 commits into from
Nov 19, 2024
Merged

feat: handle slashing state #51

merged 7 commits into from
Nov 19, 2024

Conversation

gusin13
Copy link
Collaborator

@gusin13 gusin13 commented Nov 16, 2024

Intercepts the slashing event from Babylon and then transitions all delegations for the slashed fp to "Slashed" state.

Note -
Currently Babylon doesn't emit slashing tx so indexer cannot identify when the slashing output is spent and the slashing withdrawal has happened or not.
Have added a todo for now regarding this, also created a ticket on babylon
babylonlabs-io/babylon#271

@gusin13 gusin13 marked this pull request as ready for review November 17, 2024 16:19
if dbErr != nil {
return false, types.NewError(
if dbErr := s.db.UpdateDelegationsStateByFinalityProvider(
ctx, fpBTCPKHex, types.StateSlashed,
Copy link
Collaborator

Choose a reason for hiding this comment

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

what if service restart in the mid of this process? e.g there are 1m delegations under the FP PK. we only processed 10k of those then we deployed the service again

Copy link
Collaborator Author

@gusin13 gusin13 Nov 19, 2024

Choose a reason for hiding this comment

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

hmm so if this happens then last processed height not updated.

in next restart, it picks up from same height (at which it failed in prev run), finds this slashing event and then tries to make a bulk update again 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, but slashing operation is very time consuming. we shall not couple it with the main processing thread.
Given the same example above, say u have 1 million delegations under this FP. our indexer will be blocked on this operation until all delegations are updated.

My proposal is to perform this slashing operation in a different go routine, you can do this by either:

  1. Emit "slashing msg" into rabbitmq, then process it by indexer itself. only delete the msg once all delegations are processed.
  2. OR, you create a temporary db collection just for slashing. let's say slashing_registry. then a go routing monitoring this collection and remove the entry once no more delegations to process.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i see, sure created a ticket to optimize the slashing process
#57

Copy link
Collaborator

@jrwbabylonlab jrwbabylonlab left a comment

Choose a reason for hiding this comment

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

Approved but with a comment in which you can probably handle it in a seperate PR to get the state transition out of the door for now

@gusin13 gusin13 merged commit 41ff1a7 into main Nov 19, 2024
11 checks passed
@gusin13 gusin13 deleted the gusin13/handle-slashing-state branch November 19, 2024 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants