ethermint icon indicating copy to clipboard operation
ethermint copied to clipboard

Calling String() on *MsgEthereumTx panics

Open danburck opened this issue 3 years ago • 2 comments

Steps to reproduce:

In the x/evm module, package types

  1. create message msg := NewTxContract(nil, 0, nil, 100000, nil, nil, nil, []byte("test"), nil)
  2. call String() on the message

Expected behavior: returns string

Actual behavior: panics with following log:

--- FAIL: TestMsgsTestSuite (0.00s)
    --- FAIL: TestMsgsTestSuite/TestMsgEthereumTx_String (0.00s)
        /Users/danielburckhardt/code/tharsis/ethermint/x/evm/types/suite.go:63: test panicked: reflect.Value.Interface: cannot return value obtained from unexported field or method
            goroutine 123 [running]:
            runtime/debug.Stack()
            	/usr/local/Cellar/go/1.17.1/libexec/src/runtime/debug/stack.go:24 +0x65
            github.com/stretchr/testify/suite.failOnPanic(0xc0011df6c0)
            	/Users/danielburckhardt/go/pkg/mod/github.com/stretchr/[email protected]/suite/suite.go:63 +0x3e
            panic({0x50469a0, 0x56807a0})
            	/usr/local/Cellar/go/1.17.1/libexec/src/runtime/panic.go:1038 +0x215
            reflect.valueInterface({0x507a2e0, 0xc00122fd88, 0xa}, 0xaf)
            	/usr/local/Cellar/go/1.17.1/libexec/src/reflect/value.go:1362 +0xd9
            reflect.Value.Interface(...)
            	/usr/local/Cellar/go/1.17.1/libexec/src/reflect/value.go:1351
            github.com/gogo/protobuf/proto.(*TextMarshaler).writeAny(0x0, 0xc00124c8c0, {0x507a2e0, 0xc00122fd88, 0x56f1250}, 0xc000eb8c00)
            	/Users/danielburckhardt/go/pkg/mod/github.com/regen-network/[email protected]/proto/text.go:615 +0xa38
            github.com/gogo/protobuf/proto.(*TextMarshaler).writeStruct(0x619cec4, 0xc00124c8c0, {0x51a62e0, 0xc00122fd40, 0x5098360})
            	/Users/danielburckhardt/go/pkg/mod/github.com/regen-network/[email protected]/proto/text.go:453 +0x8cd
            github.com/gogo/protobuf/proto.(*TextMarshaler).writeAny(0x5048fde, 0xc00124c8c0, {0x5218940, 0xc001242930, 0x56f1250}, 0xc000eb8600)
            	/Users/danielburckhardt/go/pkg/mod/github.com/regen-network/[email protected]/proto/text.go:606 +0x8c5
            github.com/gogo/protobuf/proto.(*TextMarshaler).writeStruct(0x619cec4, 0xc00124c8c0, {0x51cc7a0, 0xc001242930, 0x100000000000320})
            	/Users/danielburckhardt/go/pkg/mod/github.com/regen-network/[email protected]/proto/text.go:453 +0x8cd
            github.com/gogo/protobuf/proto.(*TextMarshaler).Marshal(0x619cec4, {0x5696800, 0xc001242960}, {0x56b21a8, 0xc001242930})
            	/Users/danielburckhardt/go/pkg/mod/github.com/regen-network/[email protected]/proto/text.go:896 +0x367
            github.com/gogo/protobuf/proto.(*TextMarshaler).Text(0xc001240788, {0x56b21a8, 0xc001242930})
            	/Users/danielburckhardt/go/pkg/mod/github.com/regen-network/[email protected]/proto/text.go:908 +0x56
            github.com/gogo/protobuf/proto.CompactTextString(...)
            	/Users/danielburckhardt/go/pkg/mod/github.com/regen-network/[email protected]/proto/text.go:930
            github.com/tharsis/ethermint/x/evm/types.(*MsgEthereumTx).String(...)
            	/Users/danielburckhardt/code/tharsis/ethermint/x/evm/types/tx.pb.go:50
            github.com/tharsis/ethermint/x/evm/types.(*MsgsTestSuite).TestMsgEthereumTx_String(0xc0011b7ec0)
            	/Users/danielburckhardt/code/tharsis/ethermint/x/evm/types/msg_test.go:190 +0xa5
            reflect.Value.call({0xc00120be00, 0xc0011d2e20, 0xa239352a}, {0x5245a97, 0x4}, {0xc001179e70, 0x1, 0xc001179d80})
            	/usr/local/Cellar/go/1.17.1/libexec/src/reflect/value.go:543 +0x814
            reflect.Value.Call({0xc00120be00, 0xc0011d2e20, 0xc0011b7ec0}, {0xc001179e70, 0x1, 0x1})
            	/usr/local/Cellar/go/1.17.1/libexec/src/reflect/value.go:339 +0xc5
            github.com/stretchr/testify/suite.Run.func1(0xc0011df6c0)
            	/Users/danielburckhardt/go/pkg/mod/github.com/stretchr/[email protected]/suite/suite.go:158 +0x4b6
            testing.tRunner(0xc0011df6c0, 0xc00014da70)
            	/usr/local/Cellar/go/1.17.1/libexec/src/testing/testing.go:1259 +0x102
            created by testing.(*T).Run
            	/usr/local/Cellar/go/1.17.1/libexec/src/testing/testing.go:1306 +0x35a

danburck avatar Oct 07 '21 09:10 danburck

wondering if we should create a custom String() that casts the message to *ethtypes.Transaction and then calls String on that one

func (msg *MsgEthereumTx) String() string {
    tx := msg.AsTransaction()
    return tx.String()
}

fedekunze avatar Oct 07 '21 09:10 fedekunze

reflect.Value.Interface: cannot return value obtained from unexported field or method

Seems like this may be the same issue where the type is set. https://github.com/gogo/protobuf/issues/693

They solved it by clearing the TypeMeta. https://github.com/cockroachdb/cockroach/pull/49756/commits/ec0d8942ada6fb37951ecc7726d8f2a78c2b4573

func (t *T) DebugString() string {
	if t.Family() == ArrayFamily && t.ArrayContents().UserDefined() {
		// In the case that this type is an array that contains a user defined
		// type, the introspection that protobuf performs to generate a string
		// representation will panic if the UserDefinedTypeMetadata field of the
		// type is populated. It seems to not understand that fields in the element
		// T could be not generated by proto, and panics trying to operate on the
		// TypeMeta field of the T. To get around this, we just deep copy the T and
		// zero out the type metadata to placate proto. See the following issue for
		// details: https://github.com/gogo/protobuf/issues/693.
		internalTypeCopy := protoutil.Clone(&t.InternalType).(*InternalType)
		internalTypeCopy.ArrayContents.TypeMeta = UserDefinedTypeMetadata{}
		return internalTypeCopy.String()
	}
	return t.InternalType.String()
}

twocs avatar Oct 10 '21 01:10 twocs

This issue is stale because it has been open 45 days with no activity. Remove Status: Stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Sep 30 '22 00:09 github-actions[bot]