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
462 stars 233 forks source link

KaspaD crashes on `getBlocks` RPC with empty `lowHash` #1883

Open cbytensky opened 2 years ago

cbytensky commented 2 years ago

How to reproduce:

./kaspactl --json '{"getBlocksRequest":{"lowHash":"", "includeBlocks": true, "includeTransactions": false}}'

KaspaD v0.11.8.

cbytensky commented 2 years ago

Full log:

2021-12-13 14:27:12.213 [INF] TXMP: RPC Incoming connection from [::1]:35774
2021-12-13 14:27:12.216 [CRT] RPCS: Exiting: Fatal error in goroutine `routerInitializer-handleIncomingMessages 4`: block 58c2d4199e21f910d1571d114969cecef48f09f934d42ccb6a281a15868f2999 does not exist
github.com/kaspanet/kaspad/domain/consensus.(*consensus).validateBlockHashExists
        /daglabs/go/src/github.com/kaspanet/kaspad/domain/consensus/consensus.go:661
github.com/kaspanet/kaspad/domain/consensus.(*consensus).GetHashesBetween
        /daglabs/go/src/github.com/kaspanet/kaspad/domain/consensus/consensus.go:339
github.com/kaspanet/kaspad/app/rpc/rpchandlers.HandleGetBlocks
        /daglabs/go/src/github.com/kaspanet/kaspad/app/rpc/rpchandlers/get_blocks.go:56
github.com/kaspanet/kaspad/app/rpc.(*Manager).handleIncomingMessages
        /daglabs/go/src/github.com/kaspanet/kaspad/app/rpc/rpc.go:81
github.com/kaspanet/kaspad/app/rpc.(*Manager).routerInitializer.func1
        /daglabs/go/src/github.com/kaspanet/kaspad/app/rpc/rpc.go:65
github.com/kaspanet/kaspad/util/panics.handleSpawnedFunction
        /daglabs/go/src/github.com/kaspanet/kaspad/util/panics/panics.go:83
github.com/kaspanet/kaspad/util/panics.GoroutineWrapperFunc.func1.1
        /daglabs/go/src/github.com/kaspanet/kaspad/util/panics/panics.go:32
runtime.goexit
        /usr/lib/go/src/runtime/asm_amd64.s:1581
2021-12-13 14:27:12.216 [CRT] RPCS: Goroutine stack trace: goroutine 54 [running]:
runtime/debug.Stack()
        /usr/lib/go/src/runtime/debug/stack.go:24 +0x65
github.com/kaspanet/kaspad/util/panics.GoroutineWrapperFunc.func1({0xbdd48f, 0x28}, 0xc037225e60)
        /daglabs/go/src/github.com/kaspanet/kaspad/util/panics/panics.go:30 +0x35
github.com/kaspanet/kaspad/app/rpc.(*Manager).routerInitializer(0xc019b7fbd0, 0xc037225d70, 0xc037225e00)
        /daglabs/go/src/github.com/kaspanet/kaspad/app/rpc/rpc.go:62 +0x222
github.com/kaspanet/kaspad/infrastructure/network/netadapter.newNetConnection({0xcca888, 0xc035754a80}, 0xc04671b530)
        /daglabs/go/src/github.com/kaspanet/kaspad/infrastructure/network/netadapter/netconnection.go:41 +0x1bd
github.com/kaspanet/kaspad/infrastructure/network/netadapter.(*NetAdapter).onRPCConnectedHandler(0x68, {0xcca888, 0xc035754a80})
        /daglabs/go/src/github.com/kaspanet/kaspad/infrastructure/network/netadapter/netadapter.go:151 +0x30
github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver.(*gRPCServer).handleInboundConnection(0xc0000dca50, {0xcbd080, 0xc037225d40}, {0x7f72d1ee5438, 0xc01a126d60})
        /daglabs/go/src/github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver/grpc_server.go:113 +0x18b
github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver.(*rpcServer).MessageStream(0xc0000dca50, {0xcca990, 0xc01a126d60})
        /daglabs/go/src/github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver/rpcserver.go:31 +0x125
github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver/protowire._RPC_MessageStream_Handler({0xb67d40, 0xc0000dca50}, {0xcc4a08, 0xc0001583c0})
        /daglabs/go/src/github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver/protowire/messages_grpc.pb.go:210 +0x9f
google.golang.org/grpc.(*Server).processStreamingRPC(0xc000496540, {0xccacb0, 0xc000397380}, 0xc00011a360, 0xc028230300, 0x117a160, 0x0)
        /daglabs/go/pkg/mod/google.golang.org/grpc@v1.38.0/server.go:1533 +0xcdb
google.golang.org/grpc.(*Server).handleStream(0xc000496540, {0xccacb0, 0xc000397380}, 0xc00011a360, 0x0)
        /daglabs/go/pkg/mod/google.golang.org/grpc@v1.38.0/server.go:1613 +0x9e5
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        /daglabs/go/pkg/mod/google.golang.org/grpc@v1.38.0/server.go:934 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        /daglabs/go/pkg/mod/google.golang.org/grpc@v1.38.0/server.go:932 +0x294

2021-12-13 14:27:12.216 [CRT] RPCS: Stack trace: goroutine 55 [running]:
runtime/debug.Stack()
        /usr/lib/go/src/runtime/debug/stack.go:24 +0x65
github.com/kaspanet/kaspad/util/panics.HandlePanic(0xc0467602a0, {0xc0573fc000, 0x2a}, {0xc01a12e000, 0x97f, 0x1000})
        /daglabs/go/src/github.com/kaspanet/kaspad/util/panics/panics.go:22 +0xfd
panic({0xaf4b60, 0xc0468177e8})
        /usr/lib/go/src/runtime/panic.go:1038 +0x215
github.com/kaspanet/kaspad/app/rpc.(*Manager).handleError(0xc019b7fbd0, {0xcab600, 0xc0468177e8}, 0xc037225e00)
        /daglabs/go/src/github.com/kaspanet/kaspad/app/rpc/rpc.go:101 +0x109
github.com/kaspanet/kaspad/app/rpc.(*Manager).routerInitializer.func1()
        /daglabs/go/src/github.com/kaspanet/kaspad/app/rpc/rpc.go:66 +0x9a
github.com/kaspanet/kaspad/util/panics.handleSpawnedFunction(0xc00017d770, {0xc01a12e000, 0x97f, 0x1000}, {0xbdd48f, 0xc0573e0040}, 0xc037225e60)
        /daglabs/go/src/github.com/kaspanet/kaspad/util/panics/panics.go:83 +0x297
github.com/kaspanet/kaspad/util/panics.GoroutineWrapperFunc.func1.1()
        /daglabs/go/src/github.com/kaspanet/kaspad/util/panics/panics.go:32 +0x35
created by github.com/kaspanet/kaspad/util/panics.GoroutineWrapperFunc.func1
        /daglabs/go/src/github.com/kaspanet/kaspad/util/panics/panics.go:31 +0xfd
michaelsutton commented 2 years ago

Summary of conversation with @someone235 :

It seems that the default hash if lowHash is an empty string was genesis and genesis is no longer in the DB. So we have two things to fix in kaspad:

  1. avoid crashing for an error coming from RPC call by working more safely
  2. change default to pruning point