diff --git a/kroma-validator/challenger.go b/kroma-validator/challenger.go index f46dd13bc..42d5e732c 100644 --- a/kroma-validator/challenger.go +++ b/kroma-validator/challenger.go @@ -585,7 +585,7 @@ func (c *Challenger) handleChallenge(outputIndex *big.Int, asserter common.Addre continue } case chal.StatusChallengerTimeout: - // call challenger timeout to increase bond from pending bond + // call challenger timeout to take challenger's bond away tx, err := c.ChallengerTimeout(c.ctx, outputIndex, challenger) if err != nil { c.log.Error("failed to create challenger timeout tx", "err", err, "outputIndex", outputIndex, "challenger", challenger) @@ -601,8 +601,8 @@ func (c *Challenger) handleChallenge(outputIndex *big.Int, asserter common.Addre // if challenger if isChallenger && c.cfg.ChallengerEnabled { if isOutputDeleted { - // if output has been already deleted, cancel challenge to refund pending bond in ValidatorPool - if !c.IsValPoolTerminated(outputIndex) && status != chal.StatusChallengerTimeout { + // if output has been already deleted, cancel challenge to refund pending bond + if status != chal.StatusChallengerTimeout { tx, err := c.CancelChallenge(c.ctx, outputIndex) if err != nil { c.log.Error("failed to create cancel challenge tx", "err", err, "outputIndex", outputIndex) @@ -663,6 +663,7 @@ func (c *Challenger) CanCreateChallenge(ctx context.Context, outputIndex *big.In cCtx, cCancel := context.WithTimeout(ctx, c.cfg.NetworkTimeout) defer cCancel() from := c.cfg.TxManager.From() + var balance, requiredBondAmount *big.Int if c.IsValPoolTerminated(outputIndex) { if isInJail, err := c.isInJail(ctx); err != nil { @@ -683,7 +684,7 @@ func (c *Challenger) CanCreateChallenge(ctx context.Context, outputIndex *big.In return false, nil } - balance, err = c.assetMgrContract.TotalValidatorBalance(optsutils.NewSimpleCallOpts(cCtx), from) + balance, err = c.assetMgrContract.TotalValidatorKroNotBonded(optsutils.NewSimpleCallOpts(cCtx), from) if err != nil { return false, fmt.Errorf("failed to fetch balance: %w", err) } @@ -697,19 +698,19 @@ func (c *Challenger) CanCreateChallenge(ctx context.Context, outputIndex *big.In requiredBondAmount = c.requiredBondAmountV1 } - c.metr.RecordDepositAmount(balance) + c.metr.RecordUnbondedDepositAmount(balance) - // Check if the deposit amount is less than the required bond amount + // Check if the unbonded deposit amount is less than the required bond amount if balance.Cmp(requiredBondAmount) == -1 { c.log.Warn( - "deposit is less than bond attempt amount", + "unbonded deposit is less than bond attempt amount", "requiredBondAmount", requiredBondAmount, - "deposit", balance, + "unbonded_deposit", balance, ) return false, nil } - c.log.Info("deposit amount and bond amount", "deposit", balance, "bond", requiredBondAmount) + c.log.Info("unbonded deposit amount and bond amount", "unbonded_deposit", balance, "bond", requiredBondAmount) return true, nil } diff --git a/kroma-validator/l2_output_submitter.go b/kroma-validator/l2_output_submitter.go index b6bc0fb49..515435def 100644 --- a/kroma-validator/l2_output_submitter.go +++ b/kroma-validator/l2_output_submitter.go @@ -326,6 +326,7 @@ func (l *L2OutputSubmitter) assertCanSubmitOutput(ctx context.Context, outputInd cCtx, cCancel := context.WithTimeout(ctx, l.cfg.NetworkTimeout) defer cCancel() from := l.cfg.TxManager.From() + var balance, requiredBondAmount *big.Int if l.IsValPoolTerminated(outputIndex) { if isInJail, err := l.IsInJail(ctx); err != nil { @@ -346,7 +347,7 @@ func (l *L2OutputSubmitter) assertCanSubmitOutput(ctx context.Context, outputInd return nil } - balance, err = l.assetMgrContract.TotalValidatorBalance(optsutils.NewSimpleCallOpts(cCtx), from) + balance, err = l.assetMgrContract.TotalValidatorKroNotBonded(optsutils.NewSimpleCallOpts(cCtx), from) if err != nil { return fmt.Errorf("failed to fetch balance: %w", err) } @@ -360,19 +361,19 @@ func (l *L2OutputSubmitter) assertCanSubmitOutput(ctx context.Context, outputInd requiredBondAmount = l.requiredBondAmountV1 } - l.metr.RecordDepositAmount(balance) + l.metr.RecordUnbondedDepositAmount(balance) - // Check if the deposit amount is less than the required bond amount + // Check if the unbonded deposit amount is less than the required bond amount if balance.Cmp(requiredBondAmount) == -1 { l.log.Warn( - "deposit is less than bond attempt amount", + "unbonded deposit is less than bond attempt amount", "requiredBondAmount", requiredBondAmount, - "deposit", balance, + "unbonded_deposit", balance, ) return nil } - l.log.Info("deposit amount and bond amount", "deposit", balance, "bond", requiredBondAmount) + l.log.Info("unbonded deposit amount and bond amount", "unbonded_deposit", balance, "bond", requiredBondAmount) return nil } diff --git a/kroma-validator/metrics/metrics.go b/kroma-validator/metrics/metrics.go index 777f02c4e..a881537d7 100644 --- a/kroma-validator/metrics/metrics.go +++ b/kroma-validator/metrics/metrics.go @@ -30,7 +30,7 @@ type Metricer interface { txmetrics.TxMetricer RecordL2OutputSubmitted(l2ref eth.L2BlockRef) - RecordDepositAmount(amount *big.Int) + RecordUnbondedDepositAmount(amount *big.Int) RecordValidatorStatus(status uint8) RecordNextValidator(address common.Address) RecordChallengeCheckpoint(outputIndex *big.Int) @@ -45,12 +45,12 @@ type Metrics struct { txmetrics.TxMetrics opmetrics.RPCMetrics - Info prometheus.GaugeVec - Up prometheus.Gauge - DepositAmount prometheus.Gauge - ValidatorStatus prometheus.Gauge - NextValidator prometheus.GaugeVec - ChallengeCheckpoint prometheus.Gauge + Info prometheus.GaugeVec + Up prometheus.Gauge + UnbondedDepositAmount prometheus.Gauge + ValidatorStatus prometheus.Gauge + NextValidator prometheus.GaugeVec + ChallengeCheckpoint prometheus.Gauge } var _ Metricer = (*Metrics)(nil) @@ -85,10 +85,10 @@ func NewMetrics(procName string) *Metrics { Name: "up", Help: "1 if the kroma-validator has finished starting up", }), - DepositAmount: factory.NewGauge(prometheus.GaugeOpts{ + UnbondedDepositAmount: factory.NewGauge(prometheus.GaugeOpts{ Namespace: ns, - Name: "deposit_amount", - Help: "The amount deposited into the ValidatorPool contract", + Name: "unbonded_deposit_amount", + Help: "The amount of Validator balance excluding the bonded amount", }), ValidatorStatus: factory.NewGauge(prometheus.GaugeOpts{ Namespace: ns, @@ -142,9 +142,9 @@ func (m *Metrics) RecordL2OutputSubmitted(l2ref eth.L2BlockRef) { m.RecordL2Ref(L2OutputSubmitted, l2ref) } -// RecordDepositAmount sets the amount deposited into the ValidatorPool contract. -func (m *Metrics) RecordDepositAmount(amount *big.Int) { - m.DepositAmount.Set(opmetrics.WeiToEther(amount)) +// RecordUnbondedDepositAmount sets the amount deposited into the ValidatorPool contract. +func (m *Metrics) RecordUnbondedDepositAmount(amount *big.Int) { + m.UnbondedDepositAmount.Set(opmetrics.WeiToEther(amount)) } // RecordValidatorStatus sets the status of validator in the ValidatorManager contract. diff --git a/kroma-validator/metrics/noop.go b/kroma-validator/metrics/noop.go index bc6502b69..684d114d2 100644 --- a/kroma-validator/metrics/noop.go +++ b/kroma-validator/metrics/noop.go @@ -21,7 +21,7 @@ func (*noopMetrics) RecordInfo(version string) {} func (*noopMetrics) RecordUp() {} func (*noopMetrics) RecordL2OutputSubmitted(l2ref eth.L2BlockRef) {} -func (*noopMetrics) RecordDepositAmount(amount *big.Int) {} +func (*noopMetrics) RecordUnbondedDepositAmount(amount *big.Int) {} func (*noopMetrics) RecordValidatorStatus(status uint8) {} func (*noopMetrics) RecordNextValidator(address common.Address) {} func (*noopMetrics) RecordChallengeCheckpoint(outputIndex *big.Int) {} diff --git a/packages/contracts/contracts/L1/AssetManager.sol b/packages/contracts/contracts/L1/AssetManager.sol index d1619e4be..a7cf65309 100644 --- a/packages/contracts/contracts/L1/AssetManager.sol +++ b/packages/contracts/contracts/L1/AssetManager.sol @@ -255,13 +255,9 @@ contract AssetManager is ISemver, IERC721Receiver, IAssetManager { } /** - * @notice Returns the total amount of validator balance excluding the bond amount. - * - * @param validator Address of the validator. - * - * @return The total amount of validator balance excluding the bond amount. + * @inheritdoc IAssetManager */ - function totalValidatorBalance(address validator) external view returns (uint128) { + function totalValidatorKroNotBonded(address validator) external view returns (uint128) { return _vaults[validator].asset.validatorKro - _vaults[validator].asset.validatorKroBonded; } diff --git a/packages/contracts/contracts/L1/interfaces/IAssetManager.sol b/packages/contracts/contracts/L1/interfaces/IAssetManager.sol index a983fd4b0..f8680e57c 100644 --- a/packages/contracts/contracts/L1/interfaces/IAssetManager.sol +++ b/packages/contracts/contracts/L1/interfaces/IAssetManager.sol @@ -277,6 +277,15 @@ interface IAssetManager { */ function totalValidatorKroBonded(address validator) external view returns (uint128); + /** + * @notice Returns the total amount of validator balance excluding the bond amount. + * + * @param validator Address of the validator. + * + * @return The total amount of validator balance excluding the bond amount. + */ + function totalValidatorKroNotBonded(address validator) external view returns (uint128); + /** * @notice Returns the total amount of KRO that delegated by the delegators and accumulated as * KRO delegation reward.