Skip to content

[cli] fix crash on requesting non-existing block #680

Merged
olegrok merged 2 commits intomainfrom
cli-fix-block-getter
Mar 27, 2025
Merged

[cli] fix crash on requesting non-existing block #680
olegrok merged 2 commits intomainfrom
cli-fix-block-getter

Conversation

@olegrok
Copy link
Copy Markdown
Contributor

@olegrok olegrok commented Mar 27, 2025

Before this patch simple request could crash CLI:

nil block 0x0004c3c56fde2450c25c9f0501588655be1483e083014f0e6ad4fa617c68432b
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x125a4be]

goroutine 1 [running]:
github.com/NilFoundation/nil/nil/services/rpc/jsonrpc.(*DebugRPCBlock).Decode(0x0)
	github.com/NilFoundation/nil/nil/services/rpc/jsonrpc/types.go:182 +0x3e
github.com/NilFoundation/nil/nil/services/rpc/jsonrpc.(*DebugRPCBlock).DecodeSSZ(0xc000312000?)
	github.com/NilFoundation/nil/nil/services/rpc/jsonrpc/types.go:199 +0x13
github.com/NilFoundation/nil/nil/services/cliservice.(*Service).FetchDebugBlock(0xc00048c460, 0x1, {0x16cada0?, 0xc0004742e0?}, 0x0, 0x0, 0x0)
	github.com/NilFoundation/nil/nil/services/cliservice/block.go:46 +0x7d
github.com/NilFoundation/nil/nil/cmd/nil/internal/block.runCommand(0xc000506300?, {0xc000474f30, 0x1, 0x1a3e358?})
	github.com/NilFoundation/nil/nil/cmd/nil/internal/block/block.go:44 +0xaa
github.com/spf13/cobra.(*Command).execute(0xc00044d508, {0xc000474f00, 0x1, 0x1})
	github.com/spf13/cobra@v1.9.1/command.go:1015 +0xa94
github.com/spf13/cobra.(*Command).ExecuteC(0xc00044c908)
	github.com/spf13/cobra@v1.9.1/command.go:1148 +0x40c
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/cobra@v1.9.1/command.go:1071
main.(*RootCommand).Execute(0xc000482400?)
	github.com/NilFoundation/nil/nil/cmd/nil/main.go:144 +0x16
main.main()
	github.com/NilFoundation/nil/nil/cmd/nil/main.go:120 +0x254

Closes #675

olegrok added 2 commits March 27, 2025 16:03
To be able to undestand is it incoming or outgoing message.
@olegrok olegrok marked this pull request as ready for review March 27, 2025 12:36
@olegrok olegrok requested a review from Un1oR March 27, 2025 13:08
s.Require().NoError(err)

res, err := s.cli.FetchBlock(types.BaseShardId, block.Hash.Hex())
res, err := s.cli.FetchDebugBlock(types.BaseShardId, block.Hash.Hex(), true, false, true)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Damn, how ugly this train of boolean flags looks in WinAPI style 🙈 In C++ we had a rule not to use bool parameters in functions other than trivial setters, but to have an enum with two values. I'm not sure how suitable this is for Go with the absence of enums as such and weak typing 😞

@olegrok olegrok added this pull request to the merge queue Mar 27, 2025
Merged via the queue into main with commit ea468f5 Mar 27, 2025
15 checks passed
@olegrok olegrok deleted the cli-fix-block-getter branch March 27, 2025 19:50
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.

nil block crashes on attempt to request non-existing block

2 participants