Skip to content

Commit

Permalink
improve evm proposer vm activation error handling (#2534)
Browse files Browse the repository at this point in the history
* improve evm proposer vm activation error handling

* address PR comment
  • Loading branch information
felipemadero authored Jan 10, 2025
1 parent b84aabd commit b4fe5fc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 41 deletions.
47 changes: 13 additions & 34 deletions pkg/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,38 +660,17 @@ func SetupProposerVM(
if err != nil {
return err
}
return IssueTxsToActivateProposerVMFork(client, chainID, privKey)
}

func IssueTxsToActivateProposerVMFork(
client ethclient.Client,
chainID *big.Int,
privKey *ecdsa.PrivateKey,
) error {
var errorList []error
var err error
for i := 0; i < repeatsOnFailure; i++ {
ctx, cancel := utils.GetAPILargeContext()
defer cancel()
err = issueTxsToActivateProposerVMFork(client, ctx, chainID, privKey)
err = issueTxsToActivateProposerVMFork(client, chainID, privKey)
if err == nil {
break
}
err = fmt.Errorf(
"failure issuing txs to activate proposer VM fork for client %#v: %w",
client,
err,
)
err = fmt.Errorf("failure issuing tx to activate proposer VM: %w", err)
errorList = append(errorList, err)
time.Sleep(sleepBetweenRepeats)
}
// this means that on the last try there is error
// print out all previous errors
if err != nil {
for _, indivError := range errorList {
ux.Logger.RedXToUser("%s", indivError)
}
}
utils.PrintUnreportedErrors(errorList, err, ux.Logger.RedXToUser)
return err
}

Expand All @@ -703,7 +682,6 @@ func IssueTxsToActivateProposerVMFork(
// BuildBlockWithContext.
func issueTxsToActivateProposerVMFork(
client ethclient.Client,
ctx context.Context,
chainID *big.Int,
fundedKey *ecdsa.PrivateKey,
) error {
Expand All @@ -712,25 +690,26 @@ func issueTxsToActivateProposerVMFork(
gasPrice := big.NewInt(params.MinGasPrice)
txSigner := types.LatestSignerForChainID(chainID)
for i := 0; i < numTriggerTxs; i++ {
ctx, cancel := utils.GetTimedContext(1 * time.Minute)
defer cancel()
prevBlockNumber, err := client.BlockNumber(ctx)
if err != nil {
return err
return fmt.Errorf("client.BlockNumber failure at step %d: %w", i, err)
}
nonce, err := client.NonceAt(ctx, addr, nil)
if err != nil {
return err
return fmt.Errorf("client.NonceAt failure at step %d: %w", i, err)
}
tx := types.NewTransaction(
nonce, addr, common.Big1, params.TxGas, gasPrice, nil)
tx := types.NewTransaction(nonce, addr, common.Big1, params.TxGas, gasPrice, nil)
triggerTx, err := types.SignTx(tx, txSigner, fundedKey)
if err != nil {
return err
return fmt.Errorf("types.SignTx failure at step %d: %w", i, err)
}
if err := client.SendTransaction(ctx, triggerTx); err != nil {
return err
return fmt.Errorf("client.SendTransaction failure at step %d: %w", i, err)
}
if err := WaitForNewBlock(client, ctx, prevBlockNumber, 0, 0); err != nil {
return err
return fmt.Errorf("WaitForNewBlock failure at step %d: %w", i, err)
}
}
return nil
Expand All @@ -750,7 +729,7 @@ func WaitForNewBlock(
totalDuration = 10 * time.Second
}
steps := totalDuration / stepDuration
for seconds := 0; seconds < int(steps); seconds++ {
for step := 0; step < int(steps); step++ {
blockNumber, err := client.BlockNumber(ctx)
if err != nil {
return err
Expand All @@ -760,7 +739,7 @@ func WaitForNewBlock(
}
time.Sleep(stepDuration)
}
return fmt.Errorf("new block not produced in %f seconds", totalDuration.Seconds())
return fmt.Errorf("no new block produced in %f seconds", totalDuration.Seconds())
}

func ExtractWarpMessageFromReceipt(
Expand Down
11 changes: 8 additions & 3 deletions pkg/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,22 @@ func SplitKeyValueStringToMap(str string, delimiter string) (map[string]string,

// Context for ANR network operations
func GetANRContext() (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), constants.ANRRequestTimeout)
return GetTimedContext(constants.ANRRequestTimeout)
}

// Context for API requests
func GetAPIContext() (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), constants.APIRequestTimeout)
return GetTimedContext(constants.APIRequestTimeout)
}

// Context for API requests with large timeout
func GetAPILargeContext() (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), constants.APIRequestLargeTimeout)
return GetTimedContext(constants.APIRequestLargeTimeout)
}

// Timed Context
func GetTimedContext(timeout time.Duration) (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), timeout)
}

func GetRealFilePath(path string) string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/validatormanager/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ func FinishValidatorRegistration(
rpcURL,
privateKey,
); err != nil {
return err
ux.Logger.RedXToUser("failure setting proposer VM on L1: %w", err)
}
tx, _, err := CompleteValidatorRegistration(
rpcURL,
Expand Down
2 changes: 1 addition & 1 deletion pkg/validatormanager/removal.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func FinishValidatorRemoval(
rpcURL,
privateKey,
); err != nil {
return err
ux.Logger.RedXToUser("failure setting proposer VM on L1: %w", err)
}
tx, _, err := CompleteValidatorRemoval(
rpcURL,
Expand Down
4 changes: 2 additions & 2 deletions sdk/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func (c *Subnet) InitializeProofOfAuthority(
c.RPC,
privateKey,
); err != nil {
return err
ux.Logger.RedXToUser("failure setting proposer VM on L1: %w", err)
}

managerAddress := common.HexToAddress(validatormanager.ProxyContractAddress)
Expand Down Expand Up @@ -433,7 +433,7 @@ func (c *Subnet) InitializeProofOfStake(
c.RPC,
privateKey,
); err != nil {
return err
ux.Logger.RedXToUser("failure setting proposer VM on L1: %w", err)
}
managerAddress := common.HexToAddress(validatormanager.ProxyContractAddress)
tx, _, err := validatormanager.PoSValidatorManagerInitialize(
Expand Down

0 comments on commit b4fe5fc

Please sign in to comment.