Skip to content

Commit

Permalink
core/rawdb: fix double-lock causing hang (#24189) (#575)
Browse files Browse the repository at this point in the history
commit ethereum/go-ethereum@66a908c.

Recursive read-locking is prohibited in RWMutex which can lead to deadlock.
ReadCanonicalHash internally calls ReadAncients which cause recursive
read-locking. This commit reads the block directly from leveldb/pebbledb in case
block is not in ancient without using helper function ReadCanonicalHash.

Co-authored-by: Martin Holst Swende <[email protected]>
Co-authored-by: Felix Lange <[email protected]>
  • Loading branch information
3 people authored Sep 17, 2024
1 parent efbc4f7 commit f2ae2f8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,11 @@ func ReadCanonicalBodyRLP(db ethdb.Reader, number uint64) rlp.RawValue {
if len(data) > 0 {
return nil
}
// Get it by hash from leveldb
data, _ = db.Get(blockBodyKey(number, ReadCanonicalHash(db, number)))
// Block is not in ancients, read from leveldb by hash and number.
// Note: ReadCanonicalHash cannot be used here because it also
// calls ReadAncients internally.
hash, _ := db.Get(headerHashKey(number))
data, _ = db.Get(blockBodyKey(number, common.BytesToHash(hash)))
return nil
})
return data
Expand Down

0 comments on commit f2ae2f8

Please sign in to comment.