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

Fix to initialize grpc connection in prover constructor #12

Merged
merged 1 commit into from
Dec 18, 2023
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
6 changes: 1 addition & 5 deletions relay/client.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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),
Expand Down
4 changes: 0 additions & 4 deletions relay/lcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 8 additions & 16 deletions relay/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions relay/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down