From e39459d3edd479b0e9ec94b925d34a654fc94dec Mon Sep 17 00:00:00 2001 From: sm-stack Date: Mon, 22 Apr 2024 22:52:47 +0900 Subject: [PATCH] fix(validator): remove inJail status in the validator client --- kroma-validator/l2_output_submitter.go | 49 +++++++++++++++++++------- kroma-validator/validator/status.go | 1 - 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/kroma-validator/l2_output_submitter.go b/kroma-validator/l2_output_submitter.go index 48b03e7f7..01ec8f1e7 100644 --- a/kroma-validator/l2_output_submitter.go +++ b/kroma-validator/l2_output_submitter.go @@ -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 } @@ -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 } @@ -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 diff --git a/kroma-validator/validator/status.go b/kroma-validator/validator/status.go index e7fad6a53..7a2b8b5c5 100644 --- a/kroma-validator/validator/status.go +++ b/kroma-validator/validator/status.go @@ -5,7 +5,6 @@ const ( // The other status are regarded as a challenge is in progress. StatusNone uint8 = iota StatusInactive - StatusInJail StatusActive StatusCanStart StatusStarted