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

fix(validator): modify validator to be able to turn on without V2 #368

Merged
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
34 changes: 15 additions & 19 deletions kroma-validator/challenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,8 @@ func (c *Challenger) InitConfig(ctx context.Context) error {
valPoolTerminationIndex, err := c.valPoolContract.TERMINATEOUTPUTINDEX(optsutils.NewSimpleCallOpts(cCtx))
if err != nil {
// If method is not in ValidatorPool, set the termination index to big value to ensure it sticks to validator system V1.
if errors.Is(err, errors.New("method 'TERMINATION_OUTPUT_INDEX' not found")) {
valPoolTerminationIndex = big.NewInt(math.MaxUint32)
} else {
return fmt.Errorf("failed to get valPool termination index: %w", err)
}
c.log.Error("failed to get validator pool termination index", "err", err)
valPoolTerminationIndex = maxValPoolTerminationIndex
}
c.valPoolTerminationIndex = valPoolTerminationIndex

Expand All @@ -184,23 +181,22 @@ func (c *Challenger) InitConfig(ctx context.Context) error {
return fmt.Errorf("failed to initiate valPool config: %w", err)
}

err = contractWatcher.WatchUpgraded(c.cfg.AssetManagerAddr, func() error {
cCtx, cCancel := context.WithTimeout(ctx, c.cfg.NetworkTimeout)
defer cCancel()
requiredBondAmountV2, err := c.assetMgrContract.BONDAMOUNT(optsutils.NewSimpleCallOpts(cCtx))
if err != nil {
if errors.Is(err, errors.New("method 'BOND_AMOUNT' not found")) {
requiredBondAmountV2 = big.NewInt(0)
} else {
// Init asset manager config only when termination index is set properly
if c.valPoolTerminationIndex.Cmp(maxValPoolTerminationIndex) == -1 {
err = contractWatcher.WatchUpgraded(c.cfg.AssetManagerAddr, func() error {
cCtx, cCancel := context.WithTimeout(ctx, c.cfg.NetworkTimeout)
defer cCancel()
requiredBondAmountV2, err := c.assetMgrContract.BONDAMOUNT(optsutils.NewSimpleCallOpts(cCtx))
if err != nil {
return fmt.Errorf("failed to get required bond amount: %w", err)
}
}
c.requiredBondAmountV2 = requiredBondAmountV2
c.requiredBondAmountV2 = requiredBondAmountV2

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

return nil
Expand Down
36 changes: 17 additions & 19 deletions kroma-validator/l2_output_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const (

var PublicRoundAddress = common.HexToAddress(publicRoundHex)

var maxValPoolTerminationIndex = big.NewInt(math.MaxUint32)

// L2OutputSubmitter is responsible for submitting outputs.
type L2OutputSubmitter struct {
ctx context.Context
Expand Down Expand Up @@ -138,11 +140,8 @@ func (l *L2OutputSubmitter) InitConfig(ctx context.Context) error {
valPoolTerminationIndex, err := l.valPoolContract.TERMINATEOUTPUTINDEX(optsutils.NewSimpleCallOpts(cCtx))
if err != nil {
// If method is not in ValidatorPool, set the termination index to big value to ensure it sticks to validator system V1.
if errors.Is(err, errors.New("method 'TERMINATION_OUTPUT_INDEX' not found")) {
valPoolTerminationIndex = big.NewInt(math.MaxUint32)
} else {
return fmt.Errorf("failed to get valPool termination index: %w", err)
}
l.log.Error("failed to get validator pool termination index", "err", err)
valPoolTerminationIndex = maxValPoolTerminationIndex
}
l.valPoolTerminationIndex = valPoolTerminationIndex

Expand All @@ -152,23 +151,22 @@ func (l *L2OutputSubmitter) InitConfig(ctx context.Context) error {
return fmt.Errorf("failed to initiate valPool config: %w", err)
}

err = contractWatcher.WatchUpgraded(l.cfg.AssetManagerAddr, func() error {
cCtx, cCancel := context.WithTimeout(ctx, l.cfg.NetworkTimeout)
defer cCancel()
requiredBondAmountV2, err := l.assetMgrContract.BONDAMOUNT(optsutils.NewSimpleCallOpts(cCtx))
if err != nil {
if errors.Is(err, errors.New("method 'BOND_AMOUNT' not found")) {
requiredBondAmountV2 = big.NewInt(0)
} else {
// Init asset manager config only when termination index is set properly
if l.valPoolTerminationIndex.Cmp(maxValPoolTerminationIndex) == -1 {
err = contractWatcher.WatchUpgraded(l.cfg.AssetManagerAddr, func() error {
cCtx, cCancel := context.WithTimeout(ctx, l.cfg.NetworkTimeout)
defer cCancel()
requiredBondAmountV2, err := l.assetMgrContract.BONDAMOUNT(optsutils.NewSimpleCallOpts(cCtx))
if err != nil {
return fmt.Errorf("failed to get required bond amount: %w", err)
}
}
l.requiredBondAmountV2 = requiredBondAmountV2
l.requiredBondAmountV2 = requiredBondAmountV2

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

return nil
Expand Down
Loading