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

Improve logging #21

Merged
merged 3 commits into from
May 29, 2024
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: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ module github.com/datachainlab/lcp-go
go 1.21

require (
cosmossdk.io/core v0.11.0
cosmossdk.io/errors v1.0.1
cosmossdk.io/store v1.0.2
github.com/cosmos/cosmos-sdk v0.50.5
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/ibc-go/v8 v8.2.0
github.com/deckarep/golang-set/v2 v2.1.0
github.com/ethereum/go-ethereum v1.12.0
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/hyperledger-labs/yui-relayer v0.5.1
github.com/hyperledger-labs/yui-relayer v0.5.3
github.com/oasisprotocol/oasis-core/go v0.2201.11
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
Expand All @@ -28,7 +28,6 @@ require (
cloud.google.com/go/storage v1.36.0 // indirect
cosmossdk.io/api v0.7.3 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/core v0.11.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/math v1.3.0 // indirect
Expand Down Expand Up @@ -103,6 +102,7 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,8 @@ github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0Jr
github.com/huandu/skiplist v1.2.0 h1:gox56QD77HzSC0w+Ws3MH3iie755GBJU1OER3h5VsYw=
github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w=
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/hyperledger-labs/yui-relayer v0.5.1 h1:3F5PEdyV4VyHOjW4s8KFja9acNMm6zmu5JEEGP+zeB0=
github.com/hyperledger-labs/yui-relayer v0.5.1/go.mod h1:GeCb1dtZjtQdkBNw1L9+LAUHzNQQhQK+kkoOnZYffw0=
github.com/hyperledger-labs/yui-relayer v0.5.3 h1:K7lcqkaqsGtpXImcz/cuClZsTtWCobLC9zh76KGzhP8=
github.com/hyperledger-labs/yui-relayer v0.5.3/go.mod h1:GeCb1dtZjtQdkBNw1L9+LAUHzNQQhQK+kkoOnZYffw0=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down
59 changes: 48 additions & 11 deletions light-clients/lcp/types/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"math/big"
"time"
Expand Down Expand Up @@ -95,25 +96,47 @@ var (

type StateID [32]byte

func (id StateID) String() string {
return fmt.Sprintf("0x%x", id[:])
}

func (id StateID) EqualBytes(bz []byte) bool {
return bytes.Equal(id[:], bz)
}

func (id StateID) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("\"%s\"", id.String())), nil
}

type UpdateStateProxyMessage struct {
PrevHeight *clienttypes.Height
PrevStateID *StateID
PostHeight clienttypes.Height
PostStateID StateID
Timestamp *big.Int
Context ValidationContext
EmittedStates []EmittedState
PrevHeight *clienttypes.Height `json:"prev_height"`
PrevStateID *StateID `json:"prev_state_id"`
PostHeight clienttypes.Height `json:"post_height"`
PostStateID StateID `json:"post_state_id"`
Timestamp *big.Int `json:"timestamp"`
Context ValidationContext `json:"context"`
EmittedStates []EmittedState `json:"emitted_states"`
}

type EmittedState struct {
Height clienttypes.Height
State codectypes.Any
}

func (es EmittedState) MarshalJSON() ([]byte, error) {
var es2 struct {
Height clienttypes.Height `json:"height"`
State struct {
TypeUrl string `json:"type_url"`
Value []byte `json:"value"`
} `json:"state"`
}
es2.Height = es.Height
es2.State.TypeUrl = es.State.TypeUrl
es2.State.Value = es.State.Value
return json.Marshal(es2)
}

type MisbehaviourProxyMessage struct {
PrevStates []struct {
Height clienttypes.Height
Expand All @@ -139,10 +162,24 @@ func (EmptyValidationContext) Validate(time.Time) error {

// TrustingPeriodValidationContext is the commitment context for a commitment that requires the current time to be within the trusting period.
type TrustingPeriodValidationContext struct {
UntrustedHeaderTimestamp time.Time
TrustedStateTimestamp time.Time
TrustingPeriod big.Int
ClockDrift big.Int
UntrustedHeaderTimestamp time.Time `json:"untrusted_header_timestamp"`
TrustedStateTimestamp time.Time `json:"trusted_state_timestamp"`
TrustingPeriod big.Int `json:"trusting_period"`
ClockDrift big.Int `json:"clock_drift"`
}

func (c TrustingPeriodValidationContext) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
UntrustedHeaderTimestamp *big.Int `json:"untrusted_header_timestamp"`
TrustedStateTimestamp *big.Int `json:"trusted_state_timestamp"`
TrustingPeriod *big.Int `json:"trusting_period"`
ClockDrift *big.Int `json:"clock_drift"`
}{
UntrustedHeaderTimestamp: big.NewInt(c.UntrustedHeaderTimestamp.UnixNano()),
TrustedStateTimestamp: big.NewInt(c.TrustedStateTimestamp.UnixNano()),
TrustingPeriod: &c.TrustingPeriod,
ClockDrift: &c.ClockDrift,
})
}

func DecodeTrustingPeriodValidationContext(timestamps, params [32]byte) *TrustingPeriodValidationContext {
Expand Down
24 changes: 22 additions & 2 deletions relay/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package relay

import (
"context"
"encoding/json"
"fmt"

"github.com/hyperledger-labs/yui-relayer/config"
"github.com/hyperledger-labs/yui-relayer/core"
Expand Down Expand Up @@ -110,7 +112,16 @@ func createELCCmd(ctx *config.Context) *cobra.Command {
target = c[dst]
}
prover := target.Prover.(*Prover)
return prover.doCreateELC(viper.GetUint64(flagHeight))
out, err := prover.doCreateELC(viper.GetUint64(flagHeight))
if err != nil {
return err
}
bz, err := json.Marshal(out)
if err != nil {
return err
}
fmt.Println(string(bz))
return nil
},
}
return heightFlag(srcFlag(cmd))
Expand Down Expand Up @@ -138,7 +149,16 @@ func updateELCCmd(ctx *config.Context) *cobra.Command {
counterparty = c[src]
}
prover := target.Prover.(*Prover)
return prover.doUpdateELC(viper.GetString(flagELCClientID), counterparty)
out, err := prover.doUpdateELC(viper.GetString(flagELCClientID), counterparty)
if err != nil {
return err
}
bz, err := json.Marshal(out)
if err != nil {
return err
}
fmt.Println(string(bz))
return nil
},
}
return elcClientIDFlag(srcFlag(cmd))
Expand Down
22 changes: 11 additions & 11 deletions relay/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"os"
"path/filepath"

"github.com/datachainlab/lcp-go/relay/enclave"
"github.com/hyperledger-labs/yui-relayer/core"
"github.com/hyperledger-labs/yui-relayer/log"
)

const (
Expand All @@ -37,7 +37,7 @@ func (pr *Prover) lastEnclaveKeyInfoFilePath(finalized bool) string {
}
}

func (pr *Prover) loadLastFinalizedEnclaveKey(ctx context.Context) (*enclave.EnclaveKeyInfo, error) {
func (pr *Prover) loadLastFinalizedEnclaveKey(context.Context) (*enclave.EnclaveKeyInfo, error) {
path := pr.lastEnclaveKeyInfoFilePath(true)
bz, err := os.ReadFile(path)
if err != nil {
Expand All @@ -53,7 +53,7 @@ func (pr *Prover) loadLastFinalizedEnclaveKey(ctx context.Context) (*enclave.Enc
return &eki, nil
}

func (pr *Prover) loadLastUnfinalizedEnclaveKey(ctx context.Context) (*enclave.EnclaveKeyInfo, core.MsgID, error) {
func (pr *Prover) loadLastUnfinalizedEnclaveKey(context.Context) (*enclave.EnclaveKeyInfo, core.MsgID, error) {
path := pr.lastEnclaveKeyInfoFilePath(false)
bz, err := os.ReadFile(path)
if err != nil {
Expand All @@ -73,17 +73,17 @@ func (pr *Prover) loadLastUnfinalizedEnclaveKey(ctx context.Context) (*enclave.E
return ueki.Info, unfinalizedMsgID, nil
}

func (pr *Prover) saveFinalizedEnclaveKeyInfo(ctx context.Context, eki *enclave.EnclaveKeyInfo) error {
log.Println("save finalized enclave key info")
func (pr *Prover) saveFinalizedEnclaveKeyInfo(_ context.Context, eki *enclave.EnclaveKeyInfo) error {
log.GetLogger().Info("save finalized enclave key info")
bz, err := json.Marshal(eki)
if err != nil {
return err
}
return os.WriteFile(pr.lastEnclaveKeyInfoFilePath(true), bz, 0600)
}

func (pr *Prover) saveUnfinalizedEnclaveKeyInfo(ctx context.Context, eki *enclave.EnclaveKeyInfo, msgID core.MsgID) error {
log.Println("save unfinalized enclave key info")
func (pr *Prover) saveUnfinalizedEnclaveKeyInfo(_ context.Context, eki *enclave.EnclaveKeyInfo, msgID core.MsgID) error {
log.GetLogger().Info("save unfinalized enclave key info")
msgIDBytes, err := pr.codec.MarshalInterface(msgID)
if err != nil {
return err
Expand All @@ -98,9 +98,9 @@ func (pr *Prover) saveUnfinalizedEnclaveKeyInfo(ctx context.Context, eki *enclav
return os.WriteFile(pr.lastEnclaveKeyInfoFilePath(false), bz, 0600)
}

func (pr *Prover) removeFinalizedEnclaveKeyInfo(ctx context.Context) error {
func (pr *Prover) removeFinalizedEnclaveKeyInfo(context.Context) error {
path := pr.lastEnclaveKeyInfoFilePath(true)
log.Printf("remove finalized enclave key info: %v", path)
log.GetLogger().Info("remove finalized enclave key info", "path", path)
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return nil
Expand All @@ -110,9 +110,9 @@ func (pr *Prover) removeFinalizedEnclaveKeyInfo(ctx context.Context) error {
return os.Remove(path)
}

func (pr *Prover) removeUnfinalizedEnclaveKeyInfo(ctx context.Context) error {
func (pr *Prover) removeUnfinalizedEnclaveKeyInfo(context.Context) error {
path := pr.lastEnclaveKeyInfoFilePath(false)
log.Printf("remove unfinalized enclave key info: %v", path)
log.GetLogger().Info("remove unfinalized enclave key info", "path", path)
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return nil
Expand Down
Loading
Loading