Skip to content

Commit

Permalink
fix(validator): remove inJail status in the validator client
Browse files Browse the repository at this point in the history
  • Loading branch information
sm-stack authored and 0xHansLee committed Apr 29, 2024
1 parent 333f513 commit 95665a2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
49 changes: 37 additions & 12 deletions kroma-validator/l2_output_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,21 +325,34 @@ func (l *L2OutputSubmitter) tryStartValidator(ctx context.Context) (bool, error)
return false, fmt.Errorf("failed to fetch the vault status: %w", err)
}

if vaultStatus == val.StatusNone || vaultStatus == val.StatusInactive || vaultStatus == val.StatusInJail || vaultStatus == val.StatusActive {
l.log.Info("vault has not started yet", "vaultStatus", vaultStatus)
if vaultStatus == val.StatusNone || vaultStatus == val.StatusInactive || vaultStatus == val.StatusActive {
l.log.Info("vault has not started yet", "currentStatus", vaultStatus)
return false, nil
} else if vaultStatus == val.StatusCanStart {
data, err := l.valManagerAbi.Pack("startValidator")
if err != nil {
return false, fmt.Errorf("failed to create start validator transaction data: %w", err)
}
}

if txResponse := l.startValidatorTx(data); txResponse.Err != nil {
return false, txResponse.Err
}
if vaultStatus == val.StatusCanSubmitOutput {
l.log.Info("vault has started, no need to start again", "currentStatus", val.StatusStarted)
return false, nil
}

if isInJail, err := l.isInJail(ctx); err != nil {
return false, err
} else if isInJail {
l.log.Warn("validator is in jail")
return false, nil
}

data, err := l.valManagerAbi.Pack("startValidator")
if err != nil {
return false, fmt.Errorf("failed to create start validator transaction data: %w", err)
}

l.log.Info("startValidator successfully submitted")
if txResponse := l.startValidatorTx(data); txResponse.Err != nil {
return false, txResponse.Err
}

l.log.Info("startValidator successfully submitted")

return true, nil
}

Expand Down Expand Up @@ -424,7 +437,7 @@ func (l *L2OutputSubmitter) CanSubmitOutput(ctx context.Context) (bool, error) {
}

if vaultStatus != val.StatusCanSubmitOutput {
l.log.Warn("vault has started, but currently has not enough tokens", "vaultStatus", val.StatusStarted)
l.log.Warn("vault has started, but currently has not enough tokens", "currentStatus", val.StatusStarted)
return false, nil
}

Expand Down Expand Up @@ -499,6 +512,18 @@ func (l *L2OutputSubmitter) getLeftTimeForL2Blocks(currentBlockNumber *big.Int,
return waitDuration
}

func (l *L2OutputSubmitter) isInJail(ctx context.Context) (bool, error) {
cCtx, cCancel := context.WithTimeout(ctx, l.cfg.NetworkTimeout)
defer cCancel()
from := l.cfg.TxManager.From()
isInJail, err := l.valManagerContract.InJail(optsutils.NewSimpleCallOpts(cCtx), from)
if err != nil {
return false, fmt.Errorf("failed to fetch the jail status: %w", err)
}

return isInJail, nil
}

type roundInfo struct {
isPublicRound bool
isPriorityValidator bool
Expand Down
1 change: 0 additions & 1 deletion kroma-validator/validator/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const (
// The other status are regarded as a challenge is in progress.
StatusNone uint8 = iota
StatusInactive
StatusInJail
StatusActive
StatusCanStart
StatusStarted
Expand Down

0 comments on commit 95665a2

Please sign in to comment.