Skip to content

Support tracing feature #51

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

Merged
merged 3 commits into from
Jun 4, 2025
Merged

Support tracing feature #51

merged 3 commits into from
Jun 4, 2025

Conversation

abicky
Copy link
Contributor

@abicky abicky commented Apr 18, 2025

This PR adds support for tracing features using tracing bridges, one of which was introduced in hyperledger-labs/yui-relayer#162.
To allow us to try the feature with minimal effort, this PR only focuses on using tracing bridges and logger methods with the Context suffix.

Since the tracing bridge affects code that uses type assertions and type information (%T), so I have verified that there is no remaining code to be updated as follows:

$ git grep '\(\.(\|%T\)'
light-clients/lcp/types/client_state.go:86:	consState, ok := consensusState.(*ConsensusState)
light-clients/lcp/types/client_state.go:88:		return errorsmod.Wrapf(clienttypes.ErrInvalidConsensus, "unexpected consensus state type: expected=%T got=%T", &ConsensusState{}, consensusState)
light-clients/lcp/types/client_state.go:187:	merklePath := path.(commitmenttypes.MerklePath)
light-clients/lcp/types/header.go:23:	switch m := m.(type) {
light-clients/lcp/types/header.go:27:		panic(fmt.Errorf("unexpected message type: %T", m))
light-clients/lcp/types/message.go:332:	p := CommitmentProofs(v[0].(struct {
light-clients/lcp/types/message.go:347:	p := v[0].(struct {
light-clients/lcp/types/message.go:373:	p := v[0].(struct {
light-clients/lcp/types/message.go:432:	p := v[0].(struct {
light-clients/lcp/types/message.go:475:	p := v[0].(struct {
light-clients/lcp/types/message.go:508:	p := v[0].(struct {
light-clients/lcp/types/message.go:523:	p := v[0].(struct {
light-clients/lcp/types/misbehaviour_handle.go:14:	switch msg := msg.(type) {
light-clients/lcp/types/misbehaviour_handle.go:20:		switch m.(type) {
light-clients/lcp/types/store.go:54:	consensusState, ok := consensusStateI.(*ConsensusState)
light-clients/lcp/types/store.go:58:			"invalid consensus type %T, expected %T", consensusState, &ConsensusState{},
light-clients/lcp/types/store.go:138:	store, ok := clientStore.(storeprefix.Store)
light-clients/lcp/types/update.go:42:	switch clientMsg := clientMsg.(type) {
light-clients/lcp/types/update.go:51:		switch pmsg := pmsg.(type) {
light-clients/lcp/types/update.go:57:			return errorsmod.Wrapf(clienttypes.ErrInvalidHeader, "unexpected message type: %T", pmsg)
light-clients/lcp/types/update.go:66:		return errorsmod.Wrapf(clienttypes.ErrInvalidHeader, "unknown client message %T", clientMsg)
light-clients/lcp/types/update.go:341:	switch clientMsg := clientMsg.(type) {
light-clients/lcp/types/update.go:347:		switch pmsg := pmsg.(type) {
light-clients/lcp/types/update.go:351:			panic(errorsmod.Wrapf(clienttypes.ErrInvalidHeader, "unexpected message type: %T", pmsg))
light-clients/lcp/types/update.go:360:		panic(errorsmod.Wrapf(clienttypes.ErrInvalidHeader, "unknown client message %T", clientMsg))
relay/config.go:47:	prover, err := pc.OriginProver.GetCachedValue().(core.ProverConfig).Build(chain)
relay/config.go:83:	switch pc.OperatorsEip712Params.(type) {
relay/config.go:95:	if err := pc.OriginProver.GetCachedValue().(core.ProverConfig).Validate(); err != nil {
relay/config.go:116:		switch zkvmConfig := pc.ZkvmConfig.(type) {
relay/config.go:146:		signerConfig, ok := pc.OperatorSigner.GetCachedValue().(signer.SignerConfig)
relay/config.go:148:			return fmt.Errorf("failed to cast OperatorSigner's config: %T", pc.OperatorSigner.GetCachedValue())
relay/config.go:169:		switch params := pc.OperatorsEip712Params.(type) {
relay/config.go:201:	switch t := pr.config.ZkvmConfig.(type) {
relay/config.pb.go:141:	if x, ok := m.GetZkvmConfig().(*ProverConfig_Risc0ZkvmConfig); ok {
relay/config.pb.go:148:	if x, ok := m.GetOperatorsEip712Params().(*ProverConfig_OperatorsEip712EvmChainParams); ok {
relay/config.pb.go:155:	if x, ok := m.GetOperatorsEip712Params().(*ProverConfig_OperatorsEip712CosmosChainParams); ok {
relay/elc/query.pb.go:204:		return srv.(QueryServer).Client(ctx, in)
relay/elc/query.pb.go:211:		return srv.(QueryServer).Client(ctx, req.(*QueryClientRequest))
relay/elc/tx.pb.go:630:		return srv.(MsgServer).CreateClient(ctx, in)
relay/elc/tx.pb.go:637:		return srv.(MsgServer).CreateClient(ctx, req.(*MsgCreateClient))
relay/elc/tx.pb.go:648:		return srv.(MsgServer).UpdateClient(ctx, in)
relay/elc/tx.pb.go:655:		return srv.(MsgServer).UpdateClient(ctx, req.(*MsgUpdateClient))
relay/elc/tx.pb.go:666:		return srv.(MsgServer).AggregateMessages(ctx, in)
relay/elc/tx.pb.go:673:		return srv.(MsgServer).AggregateMessages(ctx, req.(*MsgAggregateMessages))
relay/elc/tx.pb.go:684:		return srv.(MsgServer).VerifyMembership(ctx, in)
relay/elc/tx.pb.go:691:		return srv.(MsgServer).VerifyMembership(ctx, req.(*MsgVerifyMembership))
relay/elc/tx.pb.go:702:		return srv.(MsgServer).VerifyNonMembership(ctx, in)
relay/elc/tx.pb.go:709:		return srv.(MsgServer).VerifyNonMembership(ctx, req.(*MsgVerifyNonMembership))
relay/enclave/query.go:14:	switch v := eki.KeyInfo.(type) {
relay/enclave/query.go:45:	switch v := eki.KeyInfo.(type) {
relay/enclave/query.pb.go:266:	if x, ok := m.GetKeyInfo().(*EnclaveKeyInfo_Ias); ok {
relay/enclave/query.pb.go:273:	if x, ok := m.GetKeyInfo().(*EnclaveKeyInfo_Dcap); ok {
relay/enclave/query.pb.go:280:	if x, ok := m.GetKeyInfo().(*EnclaveKeyInfo_Zkdcap); ok {
relay/enclave/query.pb.go:520:	if x, ok := m.GetProof().(*ZKVMProof_Risc0); ok {
relay/enclave/query.pb.go:874:		return srv.(QueryServer).EnclaveInfo(ctx, in)
relay/enclave/query.pb.go:881:		return srv.(QueryServer).EnclaveInfo(ctx, req.(*QueryEnclaveInfoRequest))
relay/enclave/query.pb.go:892:		return srv.(QueryServer).AvailableEnclaveKeys(ctx, in)
relay/enclave/query.pb.go:899:		return srv.(QueryServer).AvailableEnclaveKeys(ctx, req.(*QueryAvailableEnclaveKeysRequest))
relay/enclave/query.pb.go:910:		return srv.(QueryServer).EnclaveKey(ctx, in)
relay/enclave/query.pb.go:917:		return srv.(QueryServer).EnclaveKey(ctx, req.(*QueryEnclaveKeyRequest))
relay/lcp.go:264:		switch v := eki.KeyInfo.(type) {
relay/lcp.go:284:			pr.getLogger().WarnContext(ctx, "unexpected eki type", "type", fmt.Sprintf("%T", eki.KeyInfo))
relay/lcp.go:430:	switch v := eki.KeyInfo.(type) {
relay/lcp.go:438:		return nil, fmt.Errorf("registerEnclaveKey: unexpected type: %T", eki.KeyInfo)
relay/lcp.go:478:	clientState, ok := cs.(*lcptypes.ClientState)
relay/lcp.go:480:		return nil, fmt.Errorf("failed to cast client state: %T", cs)
relay/lcp.go:566:	clientState, ok := cs.(*lcptypes.ClientState)
relay/lcp.go:568:		return nil, fmt.Errorf("failed to cast client state: %T", cs)
relay/operator.go:69:	clientState, ok := cs.(*lcptypes.ClientState)
relay/operator.go:71:		return fmt.Errorf("failed to cast client state: %T", cs)
relay/prover.go:64:		signer, err := config.OperatorSigner.GetCachedValue().(signer.SignerConfig).Build()
relay/restore.go:57:	clientState := cs.(*lcptypes.ClientState)
relay/restore.go:58:	consensusState := cons.(*lcptypes.ConsensusState)
sgx/dcap/dcap.go:106:	report, ok := reportBody.(*pcs.SgxReport)
sgx/dcap/dcap.go:108:		return nil, fmt.Errorf("unexpected report body type: %T", reportBody)
sgx/dcap/zkdcap.go:130:		AdvisoryIds:                advisoryIds[0].([]string),
simapp/app.go:533:	app.ICAAuthModule = icaControllerStack.(ibcmock.IBCModule)
simapp/app.go:916:		if moduleWithName, ok := m.(module.HasName); ok {
simapp/app.go:918:			if appModule, ok := moduleWithName.(appmodule.AppModule); ok {
simapp/ibc.go:40:	switch cs := clientState.(type) {
simapp/ibc.go:46:		return fmt.Errorf("unexpected client state type: %T", cs)
simapp/simd/cmd/root.go:337:	homePath, ok := appOpts.Get(flags.FlagHome).(string)
simapp/simd/cmd/root.go:342:	viperAppOpts, ok := appOpts.(*viper.Viper)

⚠️ Breaking changes

This PR modifies the type of the embedded struct within ProvableChain, so modules that depends on type assertions need to use coreutil.UnwrapProver instead.

For example, the following code:

func someFunction(pc *core.ProvableChain) error {
	prover, ok := pc.Prover.(*relay.Prover)
	if !ok {
		return nil, fmt.Errorf("expected prover type is %T, but got %T", &relay.Prover{}, pc.Prover)
	}
	// -- snip --
}

must be updated to:

func someFunction(pc *core.ProvableChain) error {
	prover, err := coreutil.UnwrapProver[*relay.Prover](pc)
	if err != nil {
		return nil, err
	}
	// -- snip --
}

abicky added 2 commits May 29, 2025 13:21
Signed-off-by: Takeshi Arabiki <[email protected]>
Signed-off-by: Takeshi Arabiki <[email protected]>
@abicky abicky marked this pull request as ready for review May 29, 2025 05:35
@abicky abicky requested a review from siburu May 29, 2025 05:57
@abicky abicky self-assigned this May 29, 2025

chain, err := coreutil.UnwrapChain[*tendermint.Chain](c)
if err != nil {
return fmt.Errorf("Chain %q is not a tendermint.Chain", args[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not also print the value of err?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this error message without giving it much thought, mainly to avoid a panic in this case 💦
I have improved the error messages in this commit, along with related updates in hyperledger-labs/yui-relayer#164.

@abicky abicky requested a review from siburu June 3, 2025 09:26
Copy link
Contributor

@siburu siburu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@abicky abicky merged commit f0606a4 into main Jun 4, 2025
1 check passed
@abicky abicky deleted the enable-tracing branch June 4, 2025 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants