Skip to content

Commit

Permalink
improve logging
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Jun 17, 2024
1 parent 04877b4 commit 2f3a03a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
37 changes: 21 additions & 16 deletions relay/lcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ type EIP712DomainParams struct {
}

// UpdateEKIIfNeeded checks if the enclave key needs to be updated
func (pr *Prover) UpdateEKIfNeeded(ctx context.Context, verifier core.FinalityAwareChain) error {
updateNeeded, err := pr.loadEKIAndCheckUpdateNeeded(ctx, verifier)
func (pr *Prover) UpdateEKIfNeeded(ctx context.Context, counterparty core.FinalityAwareChain) error {
updateNeeded, err := pr.loadEKIAndCheckUpdateNeeded(ctx, counterparty)
if err != nil {
return fmt.Errorf("failed loadEKIAndCheckUpdateNeeded: %w", err)
return fmt.Errorf("failed to call loadEKIAndCheckUpdateNeeded: %w", err)
}
pr.getLogger().Info("loadEKIAndCheckUpdateNeeded", "updateNeeded", updateNeeded)
if !updateNeeded {
Expand All @@ -49,20 +49,23 @@ func (pr *Prover) UpdateEKIfNeeded(ctx context.Context, verifier core.FinalityAw

eki, err := pr.selectNewEnclaveKey(ctx)
if err != nil {
return fmt.Errorf("failed selectNewEnclaveKey: %w", err)
return fmt.Errorf("failed to call selectNewEnclaveKey: %w", err)
}
pr.getLogger().Info("selected available enclave key", "eki", eki)

msgID, err := pr.registerEnclaveKey(verifier, eki)
pr.getLogger().Info("try to register a new enclave key", "eki", eki)

msgID, err := pr.registerEnclaveKey(counterparty, eki)
if err != nil {
return fmt.Errorf("failed registerEnclaveKey: %w", err)
return fmt.Errorf("failed to call registerEnclaveKey: %w", err)
}
finalized, success, err := pr.checkMsgStatus(verifier, msgID)
pr.getLogger().Info("registered a new enclave key", "enclave_key", hex.EncodeToString(eki.EnclaveKeyAddress), "msg_id", msgID.String())
finalized, success, err := pr.checkMsgStatus(counterparty, msgID)
if err != nil {
return fmt.Errorf("failed checkMsgStatus: %w", err)
return fmt.Errorf("failed to call checkMsgStatus: %w", err)
} else if !success {
return fmt.Errorf("msg(id=%v) execution failed", msgID)
}
pr.getLogger().Info("check the msg status", "msg_id", msgID.String(), "finalized", finalized, "success", success)

if finalized {
// this path is for chans have instant finality
Expand Down Expand Up @@ -111,12 +114,12 @@ func (pr *Prover) checkEKIUpdateNeeded(ctx context.Context, timestamp time.Time,
// finalized: true if the msg is finalized
// success: true if the msg is successfully executed in the origin chain
// error: non-nil if the msg may not exist in the origin chain
func (pr *Prover) checkMsgStatus(verifier core.FinalityAwareChain, msgID core.MsgID) (bool, bool, error) {
lfHeader, err := verifier.GetLatestFinalizedHeader()
func (pr *Prover) checkMsgStatus(counterparty core.FinalityAwareChain, msgID core.MsgID) (bool, bool, error) {
lfHeader, err := counterparty.GetLatestFinalizedHeader()
if err != nil {
return false, false, err
}
msgRes, err := verifier.GetMsgResult(msgID)
msgRes, err := counterparty.GetMsgResult(msgID)
if err != nil {
return false, false, err
} else if ok, failureReason := msgRes.Status(); !ok {
Expand All @@ -127,7 +130,7 @@ func (pr *Prover) checkMsgStatus(verifier core.FinalityAwareChain, msgID core.Ms
}

// 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) {
func (pr *Prover) loadEKIAndCheckUpdateNeeded(ctx context.Context, counterparty core.FinalityAwareChain) (bool, error) {
now := time.Now()

// no active enclave key in memory
Expand Down Expand Up @@ -171,7 +174,7 @@ func (pr *Prover) loadEKIAndCheckUpdateNeeded(ctx context.Context, verifier core

pr.getLogger().Info("active enclave key is unfinalized")

if _, err := verifier.GetMsgResult(pr.unfinalizedMsgID); err != nil {
if _, err := counterparty.GetMsgResult(pr.unfinalizedMsgID); err != nil {
// err means that the msg is not included in the latest block
pr.getLogger().Info("the msg is not included in the latest block", "msg_id", pr.unfinalizedMsgID.String(), "error", err)
if err := pr.removeUnfinalizedEnclaveKeyInfo(ctx); err != nil {
Expand All @@ -180,7 +183,7 @@ func (pr *Prover) loadEKIAndCheckUpdateNeeded(ctx context.Context, verifier core
return true, nil
}

finalized, success, err := pr.checkMsgStatus(verifier, pr.unfinalizedMsgID)
finalized, success, err := pr.checkMsgStatus(counterparty, pr.unfinalizedMsgID)
pr.getLogger().Info("check the unfinalized msg status", "msg_id", pr.unfinalizedMsgID.String(), "finalized", finalized, "success", success, "error", err)
if err != nil {
return false, err
Expand Down Expand Up @@ -337,10 +340,12 @@ func (pr *Prover) registerEnclaveKey(counterparty core.Chain, eki *enclave.Encla
if err != nil {
return nil, fmt.Errorf("failed to get quote from AVR: %w", err)
}
_, expectedOperator, err := ias.GetEKAndOperator(quote)
ek, expectedOperator, err := ias.GetEKAndOperator(quote)
if err != nil {
return nil, fmt.Errorf("failed to get EK and operator: %w", err)
}
clientLogger.Info("got EK and operator from report data", "ek", ek.String(), "operator", expectedOperator.String())

cplatestHeight, err := counterparty.LatestHeight()
if err != nil {
return nil, err
Expand Down
2 changes: 0 additions & 2 deletions scripts/init_lcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ LCP_BIN=./bin/lcp
ENCLAVE_PATH=./bin/enclave.signed.so
CERTS_DIR=./lcp/tests/certs

export LCP_ENCLAVE_DEBUG=1

rm -rf ~/.lcp

enclave_key=$(${LCP_BIN} --log_level=off enclave generate-key --enclave=${ENCLAVE_PATH})
Expand Down
4 changes: 2 additions & 2 deletions scripts/run_e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ set -ex

# Usage: run_e2e_test.sh <--operators_enabled>

export LCP_ENCLAVE_DEBUG=1

export OPERATORS_ENABLED=false
if [ "$1" = "--operators_enabled" ]; then
OPERATORS_ENABLED=true
Expand All @@ -14,8 +16,6 @@ LCP_BIN=./bin/lcp
ENCLAVE_PATH=./bin/enclave.signed.so
CERTS_DIR=./lcp/tests/certs

export LCP_ENCLAVE_DEBUG=1

./scripts/init_lcp.sh

if [ "$SGX_MODE" = "SW" ]; then
Expand Down

0 comments on commit 2f3a03a

Please sign in to comment.