From 8e6ee2fdb12b92a1c15ea6db0d385a00ff4aa509 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Tue, 10 Dec 2024 11:12:59 +0100 Subject: [PATCH 1/4] chain: reproduce panic --- chain/db_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 chain/db_test.go diff --git a/chain/db_test.go b/chain/db_test.go new file mode 100644 index 0000000..f30f6de --- /dev/null +++ b/chain/db_test.go @@ -0,0 +1,19 @@ +package chain_test + +import ( + "testing" + + "go.sia.tech/core/types" + "go.sia.tech/coreutils/chain" + "go.sia.tech/coreutils/testutil" +) + +func TestGetEmptyBlockID(t *testing.T) { + n, genesisBlock := testutil.V2Network() + store, tipState, err := chain.NewDBStore(chain.NewMemDB(), n, genesisBlock) + if err != nil { + t.Fatal(err) + } + cm := chain.NewManager(store, tipState) + _, _ = cm.Block(types.BlockID{}) +} From 89c491f4000a80516ba40a90ae5835fc0a6aa812 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Tue, 10 Dec 2024 18:20:36 +0100 Subject: [PATCH 2/4] fix test --- chain/db.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/chain/db.go b/chain/db.go index 466acfa..eb78fa9 100644 --- a/chain/db.go +++ b/chain/db.go @@ -295,12 +295,13 @@ func (db *DBStore) putState(cs consensus.State) { func (db *DBStore) getBlock(id types.BlockID) (bh types.BlockHeader, b *types.Block, bs *consensus.V1BlockSupplement, _ bool) { var sb supplementedBlock - ok := db.bucket(bBlocks).get(id[:], &sb) - if sb.Header == nil { + if ok := db.bucket(bBlocks).get(id[:], &sb); !ok { + return types.BlockHeader{}, nil, nil, false + } else if sb.Header == nil { sb.Header = new(types.BlockHeader) *sb.Header = sb.Block.Header() } - return *sb.Header, sb.Block, sb.Supplement, ok + return *sb.Header, sb.Block, sb.Supplement, true } func (db *DBStore) putBlock(bh types.BlockHeader, b *types.Block, bs *consensus.V1BlockSupplement) { From ae5a281dc11997d534b1fa67af70f0feea7a7431 Mon Sep 17 00:00:00 2001 From: "knope-bot[bot]" <152252888+knope-bot[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:22:27 +0000 Subject: [PATCH 3/4] Auto generate changeset --- ...tching_block_with_empty_block_id_from_chainmanager.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .changeset/fix_panic_when_fetching_block_with_empty_block_id_from_chainmanager.md diff --git a/.changeset/fix_panic_when_fetching_block_with_empty_block_id_from_chainmanager.md b/.changeset/fix_panic_when_fetching_block_with_empty_block_id_from_chainmanager.md new file mode 100644 index 0000000..da933da --- /dev/null +++ b/.changeset/fix_panic_when_fetching_block_with_empty_block_id_from_chainmanager.md @@ -0,0 +1,9 @@ +--- +default: patch +--- + +# Fix panic when fetching block with empty block id from ChainManager + +#133 by @ChrisSchinnerl + + From 991effe78fc4776843e8821a9e2989b4c20bcc35 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Tue, 10 Dec 2024 20:54:45 -0800 Subject: [PATCH 4/4] Update fix_panic_when_fetching_block_with_empty_block_id_from_chainmanager.md --- ...en_fetching_block_with_empty_block_id_from_chainmanager.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.changeset/fix_panic_when_fetching_block_with_empty_block_id_from_chainmanager.md b/.changeset/fix_panic_when_fetching_block_with_empty_block_id_from_chainmanager.md index da933da..ba2f304 100644 --- a/.changeset/fix_panic_when_fetching_block_with_empty_block_id_from_chainmanager.md +++ b/.changeset/fix_panic_when_fetching_block_with_empty_block_id_from_chainmanager.md @@ -3,7 +3,3 @@ default: patch --- # Fix panic when fetching block with empty block id from ChainManager - -#133 by @ChrisSchinnerl - -