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

improve deadline error #2015

Merged
merged 2 commits into from
Aug 13, 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
2 changes: 1 addition & 1 deletion go/enclave/nodetype/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func ExportCrossChainData(ctx context.Context, storage storage.Storage, fromSeqN
return nil, errutil.ErrCrossChainBundleNoBatches
}

//todo - siliev - all those fetches need to be atomic
// todo - siliev - all those fetches need to be atomic
header, err := storage.FetchHeadBatchHeader(ctx)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions tools/walletextension/rpcapi/transaction_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (s *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common.
}

func (s *TransactionAPI) SendTransaction(ctx context.Context, args gethapi.TransactionArgs) (common.Hash, error) {
txRec, err := ExecAuthRPC[common.Hash](ctx, s.we, &ExecCfg{account: args.From}, "eth_sendTransaction", args)
txRec, err := ExecAuthRPC[common.Hash](ctx, s.we, &ExecCfg{account: args.From, timeout: sendTransactionDuration}, "eth_sendTransaction", args)
if err != nil {
return common.Hash{}, err
}
Expand Down Expand Up @@ -131,7 +131,7 @@ func (s *TransactionAPI) FillTransaction(ctx context.Context, args gethapi.Trans
}

func (s *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) (common.Hash, error) {
txRec, err := ExecAuthRPC[common.Hash](ctx, s.we, &ExecCfg{tryAll: true}, "eth_sendRawTransaction", input)
txRec, err := ExecAuthRPC[common.Hash](ctx, s.we, &ExecCfg{tryAll: true, timeout: sendTransactionDuration}, "eth_sendRawTransaction", input)
if err != nil {
return common.Hash{}, err
}
Expand Down
16 changes: 14 additions & 2 deletions tools/walletextension/rpcapi/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ const (
ethCallAddrPadding = "000000000000000000000000"

notAuthorised = "not authorised"
serverBusy = "server busy. please retry later"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it say retry? i.e. the transaction might have actually gone through, so you wouldn't want to send again, just go into reconcilliation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the error response is generic for all rpc calls. The tx submission has a much higher timeout, so it shouldn't really be shown there, unless there is something really wrong


longCacheTTL = 5 * time.Hour
shortCacheTTL = 1 * time.Minute

// hardcoding the maximum time for an RPC request
// this value will be propagated to the node and enclave and all the operations
maximumRPCCallDuration = 5 * time.Second
maximumRPCCallDuration = 5 * time.Second
sendTransactionDuration = 20 * time.Second
)

var rpcNotImplemented = fmt.Errorf("rpc endpoint not implemented")
Expand All @@ -52,6 +54,7 @@ type ExecCfg struct {
tryUntilAuthorised bool
adjustArgs func(acct *GWAccount) []any
cacheCfg *CacheCfg
timeout time.Duration
}

type CacheStrategy uint8
Expand Down Expand Up @@ -136,10 +139,19 @@ func ExecAuthRPC[R any](ctx context.Context, w *Services, cfg *ExecCfg, method s
}

// wrap the context with a timeout to prevent long executions
timeoutContext, cancelCtx := context.WithTimeout(ctx, maximumRPCCallDuration)
deadline := cfg.timeout
// if not set, use default
if deadline == 0 {
deadline = maximumRPCCallDuration
}
timeoutContext, cancelCtx := context.WithTimeout(ctx, deadline)
defer cancelCtx()

err := rpcClient.CallContext(timeoutContext, &result, method, adjustedArgs...)
// return a friendly error to the user
if err != nil && errors.Is(err, context.DeadlineExceeded) {
return nil, fmt.Errorf(serverBusy)
}
return result, err
})
if err != nil {
Expand Down
Loading