From 456b71b1512f2779c6dabe6a00c7d7f842a57076 Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Mon, 18 Dec 2023 12:28:26 +0900 Subject: [PATCH] fix to initialize grpc connection in prover constructor Signed-off-by: Jun Kimura --- relay/client.go | 6 +----- relay/lcp.go | 4 ---- relay/prover.go | 24 ++++++++---------------- relay/restore.go | 3 --- 4 files changed, 9 insertions(+), 28 deletions(-) diff --git a/relay/client.go b/relay/client.go index a06dd7a..90556b7 100644 --- a/relay/client.go +++ b/relay/client.go @@ -1,7 +1,6 @@ package relay import ( - "github.com/cosmos/cosmos-sdk/codec" "github.com/datachainlab/lcp-go/relay/elc" "github.com/datachainlab/lcp-go/relay/enclave" "google.golang.org/grpc" @@ -14,16 +13,13 @@ type ( ) type LCPServiceClient struct { - codec codec.ProtoCodecMarshaler - ELCMsgClient ELCQueryClient EnclaveQueryClient } -func NewLCPServiceClient(conn *grpc.ClientConn, codec codec.ProtoCodecMarshaler) LCPServiceClient { +func NewLCPServiceClient(conn *grpc.ClientConn) LCPServiceClient { return LCPServiceClient{ - codec: codec, ELCMsgClient: elc.NewMsgClient(conn), ELCQueryClient: elc.NewQueryClient(conn), EnclaveQueryClient: enclave.NewQueryClient(conn), diff --git a/relay/lcp.go b/relay/lcp.go index 63d35f4..bdf3e69 100644 --- a/relay/lcp.go +++ b/relay/lcp.go @@ -119,10 +119,6 @@ func checkMsgStatus(verifier core.FinalityAwareChain, msgID core.MsgID) (bool, b // if returns true, query new key and register key and set it to memory func (pr *Prover) loadEKIAndCheckUpdateNeeded(ctx context.Context, verifier core.FinalityAwareChain) (bool, error) { - if err := pr.initServiceClient(); err != nil { - return false, err - } - now := time.Now() // no active enclave key in memory diff --git a/relay/prover.go b/relay/prover.go index 7a81bca..367ac36 100644 --- a/relay/prover.go +++ b/relay/prover.go @@ -43,24 +43,19 @@ var ( ) func NewProver(config ProverConfig, originChain core.Chain, originProver core.Prover) (*Prover, error) { - return &Prover{config: config, originChain: originChain, originProver: originProver}, nil -} - -func (pr *Prover) GetOriginProver() core.Prover { - return pr.originProver -} - -func (pr *Prover) initServiceClient() error { conn, err := grpc.Dial( - pr.config.LcpServiceAddress, + config.LcpServiceAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock(), ) if err != nil { - return err + return nil, err } - pr.lcpServiceClient = NewLCPServiceClient(conn, pr.codec) - return nil + return &Prover{config: config, originChain: originChain, originProver: originProver, lcpServiceClient: NewLCPServiceClient(conn)}, nil +} + +func (pr *Prover) GetOriginProver() core.Prover { + return pr.originProver } // Init initializes the chain @@ -90,7 +85,7 @@ func (pr *Prover) SetRelayInfo(path *core.PathEnd, counterparty *core.ProvableCh // SetupForRelay performs chain-specific setup before starting the relay func (pr *Prover) SetupForRelay(ctx context.Context) error { - return pr.initServiceClient() + return nil } // GetChainID returns the chain ID @@ -102,9 +97,6 @@ func (pr *Prover) GetChainID() string { // These states will be submitted to the counterparty chain as MsgCreateClient. // If `height` is nil, the latest finalized height is selected automatically. func (pr *Prover) CreateInitialLightClientState(height exported.Height) (exported.ClientState, exported.ConsensusState, error) { - if err := pr.initServiceClient(); err != nil { - return nil, nil, err - } // NOTE: Query the LCP for available keys, but no need to register it into on-chain here tmpEKI, err := pr.selectNewEnclaveKey(context.TODO()) if err != nil { diff --git a/relay/restore.go b/relay/restore.go index 56aa3f0..3f501a9 100644 --- a/relay/restore.go +++ b/relay/restore.go @@ -15,9 +15,6 @@ import ( ) func (pr *Prover) restoreELCState(ctx context.Context, counterparty core.FinalityAwareChain, height uint64) error { - if err := pr.initServiceClient(); err != nil { - return err - } // ensure the client does not exist in the LCP service _, err := pr.lcpServiceClient.Client(ctx, &elc.QueryClientRequest{