From 79d6a1d0d58a18ac9def6661bc7c8be63a994d5a Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Fri, 21 Jun 2024 11:23:24 +0900 Subject: [PATCH] fix to create an ELC after building client state and consensus state Signed-off-by: Jun Kimura --- relay/prover.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/relay/prover.go b/relay/prover.go index c771c22..fb2ede0 100644 --- a/relay/prover.go +++ b/relay/prover.go @@ -109,12 +109,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 res, err := pr.createELC(pr.config.ElcClientId, height); err != nil { - return nil, nil, fmt.Errorf("failed to create ELC: %w", err) - } else if res == nil { - pr.getLogger().Info("no need to create ELC", "elc_client_id", pr.config.ElcClientId) - } - ops, err := pr.GetOperators() if err != nil { return nil, nil, err @@ -123,6 +117,7 @@ func (pr *Prover) CreateInitialLightClientState(height exported.Height) (exporte for _, op := range ops { operators = append(operators, op.Bytes()) } + clientState := &lcptypes.ClientState{ LatestHeight: clienttypes.Height{}, Mrenclave: pr.config.GetMrenclave(), @@ -135,6 +130,13 @@ func (pr *Prover) CreateInitialLightClientState(height exported.Height) (exporte OperatorsThresholdDenominator: pr.GetOperatorsThreshold().Denominator, } consensusState := &lcptypes.ConsensusState{} + + if res, err := pr.createELC(pr.config.ElcClientId, height); err != nil { + return nil, nil, fmt.Errorf("failed to create ELC: %w", err) + } else if res == nil { + pr.getLogger().Info("no need to create ELC", "elc_client_id", pr.config.ElcClientId) + } + // NOTE after creates client, register an enclave key into the client state return clientState, consensusState, nil }