Skip to content

Commit

Permalink
added rpc call timeout strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
mralj committed Oct 4, 2024
1 parent f0dd217 commit c4b24af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/vm/contracts_rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"math/big"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -90,8 +91,16 @@ func (c *L1SLoad) Run(input []byte) ([]byte, error) {

// TODO:
// 1. Batch multiple storage slots
// 2. What about timeout strategy here?
res, err := c.L1RpcClient.StorageAt(context.Background(), contractAddress, contractStorageKeys[0], c.GetLatestL1BlockNumber())
var ctx context.Context
if params.L1SLoadRPCTimeoutInSec > 0 {
c, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(params.L1SLoadRPCTimeoutInSec))
ctx = c
defer cancel()
} else {
ctx = context.Background()
}

res, err := c.L1RpcClient.StorageAt(ctx, contractAddress, contractStorageKeys[0], c.GetLatestL1BlockNumber())
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions params/protocol_params_rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ const (
L1SLoadPerLoadGas uint64 = 2000 // Per-load price for loading one storage slot
L1SLoadMaxNumStorageSlots = 5 // Max number of storage slots requested in L1Sload precompile
)

var L1SLoadRPCTimeoutInSec = MainnetChainConfig.Clique.Period // After how many ms will RPC call timeout

0 comments on commit c4b24af

Please sign in to comment.