Skip to content

Commit

Permalink
Wait in loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanIliev545 committed Dec 5, 2024
1 parent e9d7db0 commit 46472e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 4 additions & 2 deletions go/enclave/crypto/rpc_key_service.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package crypto

import (
"fmt"
"errors"

gethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/ecies"
Expand All @@ -11,6 +11,8 @@ import (

const rpcSuffix = 1

var ErrNotInitialised = errors.New("rpc key service is not initialised")

// RPCKeyService - manages the "TEN - RPC key" used by clients (like the TEN gateway) to make RPC requests
type RPCKeyService struct {
privKey *ecies.PrivateKey
Expand Down Expand Up @@ -51,7 +53,7 @@ func (s *RPCKeyService) DecryptRPCRequest(bytes []byte) ([]byte, error) {

func (s *RPCKeyService) PublicKey() ([]byte, error) {
if s.privKey == nil {
return nil, fmt.Errorf("rpc key service is not initialised")
return nil, ErrNotInitialised
}
return gethcrypto.CompressPubkey(s.privKey.PublicKey.ExportECDSA()), nil
}
12 changes: 11 additions & 1 deletion tools/walletextension/services/conn_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ package services
import (
"context"
"fmt"
"strings"
"time"

gethlog "github.com/ethereum/go-ethereum/log"
pool "github.com/jolestar/go-commons-pool/v2"
"github.com/ten-protocol/go-ten/go/common/log"
"github.com/ten-protocol/go-ten/go/common/measure"
"github.com/ten-protocol/go-ten/go/enclave/core"
"github.com/ten-protocol/go-ten/go/enclave/crypto"
tenrpc "github.com/ten-protocol/go-ten/go/rpc"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"
gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc"
wecommon "github.com/ten-protocol/go-ten/tools/walletextension/common"
"google.golang.org/grpc/status"
)

type BackendRPC struct {
Expand Down Expand Up @@ -72,7 +76,13 @@ func readEncKey(hostAddrHTTP string, logger gethlog.Logger) []byte {
}
defer rpcClient.Close()
k, err := tenrpc.ReadEnclaveKey(rpcClient)
if err != nil {
for ; err != nil; k, err = tenrpc.ReadEnclaveKey(rpcClient) {
status := status.Convert(err)
rpcErr := status.Message()
if strings.Contains(rpcErr, crypto.ErrNotInitialised.Error()) {
time.Sleep(1 * time.Second)
continue
}
logger.Crit("failed to read enc key", "err", err)
}
return k
Expand Down

0 comments on commit 46472e0

Please sign in to comment.