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

test(validator): modify e2e tests related to V2 #366

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"validatorManagerMaxFinalizations": 10,
"validatorManagerBaseReward": "0x1",
"assetManagerKgh": "0xff000000000000000000000000000000000000ff",
"assetManagerVault": "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955",
"assetManagerVault": "0x14dc79964da2c08b23698b3d3cc7ca32193d9955",
"assetManagerMinDelegationPeriod": 2,
"assetManagerBondAmount": "0xa",
"securityCouncilOwners": [
Expand Down
5 changes: 3 additions & 2 deletions kroma-validator/challenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,16 @@ func (c *Challenger) InitConfig(ctx context.Context) error {
if err != nil {
if errors.Is(err, errors.New("method 'BOND_AMOUNT' not found")) {
requiredBondAmountV2 = big.NewInt(0)
} else {
return fmt.Errorf("failed to get required bond amount: %w", err)
}
return fmt.Errorf("failed to get required bond amount: %w", err)
}
c.requiredBondAmountV2 = requiredBondAmountV2

return nil
})
if err != nil {
return fmt.Errorf("failed to initiate assetMgr config: %w, err")
return fmt.Errorf("failed to initiate assetMgr config: %w", err)
}

return nil
Expand Down
42 changes: 24 additions & 18 deletions kroma-validator/l2_output_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,16 @@ func (l *L2OutputSubmitter) InitConfig(ctx context.Context) error {
if err != nil {
if errors.Is(err, errors.New("method 'BOND_AMOUNT' not found")) {
requiredBondAmountV2 = big.NewInt(0)
} else {
return fmt.Errorf("failed to get required bond amount: %w", err)
}
return fmt.Errorf("failed to get required bond amount: %w", err)
}
l.requiredBondAmountV2 = requiredBondAmountV2

return nil
})
if err != nil {
return fmt.Errorf("failed to initiate assetMgr config: %w, err")
return fmt.Errorf("failed to initiate assetMgr config: %w", err)
}

return nil
Expand Down Expand Up @@ -230,23 +231,30 @@ func (l *L2OutputSubmitter) repeatSubmitL2Output(ctx context.Context) {
// If it needs to wait, it will calculate how long the validator should wait and
// try again after the delay.
func (l *L2OutputSubmitter) trySubmitL2Output(ctx context.Context) (time.Duration, error) {
defaultWaitTime := l.cfg.OutputSubmitterRetryInterval

nextBlockNumber, err := l.FetchNextBlockNumber(ctx)
if err != nil {
return l.cfg.OutputSubmitterRetryInterval, err
return defaultWaitTime, err
}

outputIndex, err := l.FetchNextOutputIndex(ctx)
if err != nil {
return l.cfg.OutputSubmitterRetryInterval, err
return defaultWaitTime, err
}

calculatedWaitTime := l.CalculateWaitTime(ctx, nextBlockNumber, outputIndex)
if calculatedWaitTime > 0 {
return calculatedWaitTime, nil
}

canSubmitOutput, err := l.CanSubmitOutput(ctx, outputIndex)
if err != nil || !canSubmitOutput {
return defaultWaitTime, err
}

0xHansLee marked this conversation as resolved.
Show resolved Hide resolved
if err = l.doSubmitL2Output(ctx, nextBlockNumber, outputIndex); err != nil {
return l.cfg.OutputSubmitterRetryInterval, err
return defaultWaitTime, err
}

// successfully submitted. start next loop immediately.
Expand Down Expand Up @@ -286,7 +294,7 @@ func (l *L2OutputSubmitter) CalculateWaitTime(ctx context.Context, nextBlockNumb
return defaultWaitTime
}

if err = l.assertCanSubmitOutput(ctx, outputIndex); err != nil {
if _, err = l.CanSubmitOutput(ctx, outputIndex); err != nil {
l.log.Error("failed to check the validator can submit output", "err", err)
return defaultWaitTime
}
Expand Down Expand Up @@ -321,46 +329,45 @@ func (l *L2OutputSubmitter) CalculateWaitTime(ctx context.Context, nextBlockNumb
return 0
}

// assertCanSubmitOutput asserts that the validator satisfies the condition to submit L2Output.
func (l *L2OutputSubmitter) assertCanSubmitOutput(ctx context.Context, outputIndex *big.Int) error {
// CanSubmitOutput checks that the validator satisfies the condition to submit L2Output.
func (l *L2OutputSubmitter) CanSubmitOutput(ctx context.Context, outputIndex *big.Int) (bool, error) {
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 {
return err
return false, err
} else if isInJail {
l.log.Warn("validator is in jail")
return nil
return false, nil
}

validatorStatus, err := l.GetValidatorStatus(ctx)
if err != nil {
return err
return false, err
}
l.metr.RecordValidatorStatus(validatorStatus)

if validatorStatus != StatusActive {
l.log.Warn("validator is not in the status to submit output", "currentStatus", validatorStatus)
return nil
return false, nil
}

balance, err = l.assetMgrContract.TotalValidatorKroNotBonded(optsutils.NewSimpleCallOpts(cCtx), from)
if err != nil {
return fmt.Errorf("failed to fetch balance: %w", err)
return false, fmt.Errorf("failed to fetch balance: %w", err)
}
requiredBondAmount = l.requiredBondAmountV2
} else {
var err error
balance, err = l.valPoolContract.BalanceOf(optsutils.NewSimpleCallOpts(cCtx), from)
if err != nil {
return fmt.Errorf("failed to fetch deposit amount: %w", err)
return false, fmt.Errorf("failed to fetch deposit amount: %w", err)
}
requiredBondAmount = l.requiredBondAmountV1
}

l.metr.RecordUnbondedDepositAmount(balance)

// Check if the unbonded deposit amount is less than the required bond amount
Expand All @@ -370,12 +377,11 @@ func (l *L2OutputSubmitter) assertCanSubmitOutput(ctx context.Context, outputInd
"requiredBondAmount", requiredBondAmount,
"unbonded_deposit", balance,
)
return nil
return false, nil
}

l.log.Info("unbonded deposit amount and bond amount", "unbonded_deposit", balance, "bond", requiredBondAmount)

return nil
return true, nil
}

func (l *L2OutputSubmitter) FetchNextOutputIndex(ctx context.Context) (*big.Int, error) {
Expand Down
4 changes: 2 additions & 2 deletions op-e2e/actions/l2_challenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (v *L2Validator) ActCreateChallenge(t Testing, outputIndex *big.Int) common
}, "challenge is already in progress")

canCreateChallenge, err := v.challenger.CanCreateChallenge(t.Ctx(), outputIndex)
require.NoError(t, err, "unable to check if challenger is in the status that can create challenge")
require.True(t, canCreateChallenge, "challenger is not in the status that can create challenge")
require.NoError(t, err, "unable to check if challenger can create challenge")
require.True(t, canCreateChallenge, "challenger cannot create challenge")

tx, err := v.challenger.CreateChallenge(t.Ctx(), outputRange)
require.NoError(t, err, "unable to create create challenge tx")
Expand Down
Loading
Loading