kaspanet / kaspad

Kaspad was the reference full node Kaspa implementation written in Go (golang), now rewritten in Rust: https://github.com/kaspanet/rusty-kaspa
ISC License
457 stars 231 forks source link

Kaspad halting on invalid script data when posting a transaction #1411

Closed aspect closed 3 years ago

aspect commented 3 years ago

We ran into the following issue during debugging. Unfortunately, I lost context as to what caused this... I think this was the absence of the scriptVersion in the script or otherwise an incompatible/bad transaction (we were migrating from the Karpov to the master). Regardless, this caused Kaspad to halt, whereas it should handle this gracefully.

2021-01-12 12:07:54.175 [CRT] TXMP: Exiting: Fatal error in goroutine `gRPCConnection.receiveLoop 10`: runtime error: invalid memory address or nil pointer dereference
2021-01-12 12:07:54.175 [CRT] TXMP: Goroutine stack trace: goroutine 83 [running]:
runtime/debug.Stack(0xc007d10f60, 0xc008409d68, 0x40656a)
        c:/go/src/runtime/debug/stack.go:24 +0xa4
github.com/kaspanet/kaspad/util/panics.GoroutineWrapperFunc.func1(0xcee2fc, 0x1a, 0xc014955080)
        C:/dev/kaspa/wallet/kaspad-master/util/panics/panics.go:30 +0x36
github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver.(*gRPCConnection).connectionLoops(0xc012748d20, 0x0, 0x4ed5fb)
        C:/dev/kaspa/wallet/kaspad-master/infrastructure/network/netadapter/server/grpcserver/connection_loops.go:18 +0xae
github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver.(*gRPCConnection).Start.func1()
        C:/dev/kaspa/wallet/kaspad-master/infrastructure/network/netadapter/server/grpcserver/grpc_connection.go:63 +0x3a
github.com/kaspanet/kaspad/util/panics.handleSpawnedFunction(0xc000096660, 0xc0003dd000, 0x9fe, 0x1000, 0xcf6c32, 0x24, 0xc01257d820)
        C:/dev/kaspa/wallet/kaspad-master/util/panics/panics.go:84 +0x2d3
github.com/kaspanet/kaspad/util/panics.GoroutineWrapperFunc.func1.1(0xc000096660, 0xc0003dd000, 0x9fe, 0x1000, 0xcf6c32, 0x24, 0xc01257d820)
        C:/dev/kaspa/wallet/kaspad-master/util/panics/panics.go:32 +0x6e
created by github.com/kaspanet/kaspad/util/panics.GoroutineWrapperFunc.func1
        C:/dev/kaspa/wallet/kaspad-master/util/panics/panics.go:31 +0x93

2021-01-12 12:07:54.176 [CRT] TXMP: Stack trace: goroutine 42 [running]:
runtime/debug.Stack(0xcf4b8a, 0x22, 0xc01b4f7920)
        c:/go/src/runtime/debug/stack.go:24 +0xa4
github.com/kaspanet/kaspad/util/panics.HandlePanic(0xc000096660, 0xc0129bdf00, 0x1d, 0xc012178000, 0x52a, 0x800)
        C:/dev/kaspa/wallet/kaspad-master/util/panics/panics.go:22 +0x10a
panic(0xbdd520, 0xb02af0)
        c:/go/src/runtime/panic.go:969 +0x174
github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver/protowire.ConvertFromAppMsgRPCScriptPubKeyToRPCScriptPubKey(0x0, 0x2, 0x2, 0xc01243ae50)
        C:/dev/kaspa/wallet/kaspad-master/infrastructure/network/netadapter/server/grpcserver/protowire/rpc_submit_transaction.go:93 +0x2d
github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver/protowire.(*RpcTransaction).toAppMessage(0xc011fa6dc0, 0xbe93a0, 0xbf5660, 0x1)
        C:/dev/kaspa/wallet/kaspad-master/infrastructure/network/netadapter/server/grpcserver/protowire/rpc_submit_transaction.go:65 +0x25f
github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver/protowire.(*KaspadMessage_SubmitTransactionRequest).toAppMessage(0xc01346c110, 0xde95a0, 0xc01346c110, 0x2c362f38, 0xc01346c110)
        C:/dev/kaspa/wallet/kaspad-master/infrastructure/network/netadapter/server/grpcserver/protowire/rpc_submit_transaction.go:10 +0x3d
github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver/protowire.(*KaspadMessage).ToAppMessage(0xc012b3bc40, 0xc012b3bc40, 0x0, 0x0, 0x0)
        C:/dev/kaspa/wallet/kaspad-master/infrastructure/network/netadapter/server/grpcserver/protowire/wire.go:18 +0x6a
github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver.(*gRPCConnection).receiveLoop(0xc012748d20, 0x40bec2, 0x10)
        C:/dev/kaspa/wallet/kaspad-master/infrastructure/network/netadapter/server/grpcserver/connection_loops.go:67 +0x84
github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver.(*gRPCConnection).connectionLoops.func1()
        C:/dev/kaspa/wallet/kaspad-master/infrastructure/network/netadapter/server/grpcserver/connection_loops.go:18 +0x3a
github.com/kaspanet/kaspad/util/panics.handleSpawnedFunction(0xc000096660, 0xc012178000, 0x52a, 0x800, 0xcee2fc, 0x1a, 0xc014955080)
        C:/dev/kaspa/wallet/kaspad-master/util/panics/panics.go:84 +0x2d3
github.com/kaspanet/kaspad/util/panics.GoroutineWrapperFunc.func1.1(0xc000096660, 0xc012178000, 0x52a, 0x800, 0xcee2fc, 0x1a, 0xc014955080)
        C:/dev/kaspa/wallet/kaspad-master/util/panics/panics.go:32 +0x6e
created by github.com/kaspanet/kaspad/util/panics.GoroutineWrapperFunc.func1
        C:/dev/kaspa/wallet/kaspad-master/util/panics/panics.go:31 +0x93

Exiting...
elichai commented 3 years ago

Can you give an example transaction that triggers this?