From 880a6a2e34fde934eff93b306680a6a398f89572 Mon Sep 17 00:00:00 2001 From: piux2 <90544084+piux2@users.noreply.github.com> Date: Tue, 10 Oct 2023 15:01:09 -0700 Subject: [PATCH] chore: stop recursive loop in TypeInfo error print MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the second issue in #1197 - Before fix, if a Amino type was not imported as registered Amino package, we got stack overflow runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc02050c458 stack=[0xc02050c000, 0xc04050c000]
fatal error: stack overflow - After fix, if a Amino type was not imported as registered Amino package, we could print the message to verify what has been imported for debugging purpose Error: unable to unmarshal with amino, unmarshal to std.Tx failed after 17 bytes (error reading slice contents: unrecognized concrete type full name vm.m_call of map[abci.BlockParams:TypeInfo{Type:abci.BlockParams,Registered:true,PointerPreferred:false,TypeURL:"/abci.BlockParams",ReprType:,Fields:[]amino.FieldInfo{amino.FieldInfo{Type:(*reflect.rtype)(0x104cfc920), TypeInfo:(*amino.TypeInfo)(0x1400011c6e0), Name:"MaxTxBytes", Index:0, ........ --- tm2/pkg/amino/codec.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tm2/pkg/amino/codec.go b/tm2/pkg/amino/codec.go index 602c7090d91..5aaeffb70f1 100644 --- a/tm2/pkg/amino/codec.go +++ b/tm2/pkg/amino/codec.go @@ -129,7 +129,7 @@ func (info *TypeInfo) String() string { buf.Write([]byte(fmt.Sprintf("ReprType:\"%v\",", info.ReprType))) } if info.Type.Kind() == reflect.Struct { - buf.Write([]byte(fmt.Sprintf("Fields:%v,", info.Fields))) + buf.Write([]byte(fmt.Sprintf("Fields:%#v,", info.Fields))) } buf.Write([]byte("}")) return buf.String() @@ -532,7 +532,11 @@ func (cdc *Codec) getTypeInfoFromFullnameRLock(fullname string, fopts FieldOptio info, ok := cdc.fullnameToTypeInfo[fullname] if !ok { - err = fmt.Errorf("amino: unrecognized concrete type full name %s", fullname) + if printLog { + err = fmt.Printf("unrecognized concrete type full name %s of %v", fullname, cdc.fullnameToTypeInfo) + }else{ + err = fmt.Errorf("amino: unrecognized concrete type full name %s", fullname) + } cdc.mtx.RUnlock() return }