From d5e4c6c7f81530e88a383f568958ceae7f1103f3 Mon Sep 17 00:00:00 2001 From: "will@2012" Date: Thu, 13 Jun 2024 21:04:12 +0800 Subject: [PATCH] fix: check disklayer hash consistency --- triedb/pathdb/difflayer.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/triedb/pathdb/difflayer.go b/triedb/pathdb/difflayer.go index 5d09c840c4..48bc0e8cc9 100644 --- a/triedb/pathdb/difflayer.go +++ b/triedb/pathdb/difflayer.go @@ -233,17 +233,18 @@ func (dl *diffLayer) node(owner common.Hash, path []byte, hash common.Hash, dept diffHashCacheMissMeter.Mark(1) persistLayer := dl.originDiskLayer() if persistLayer != nil { - blob, bhash, nloc, err := persistLayer.node(owner, path, hash, depth+1) - if err != nil { + blob, rhash, nloc, err := persistLayer.node(owner, path, hash, depth+1) + if err != nil || rhash != hash { // This is a bad case with a very low probability. // r/w the difflayer cache and r/w the disklayer are not in the same lock, // so in extreme cases, both reading the difflayer cache and reading the disklayer may fail, eg, disklayer is stale. // In this case, fallback to the original 128-layer recursive difflayer query path. diffHashCacheSlowPathMeter.Mark(1) - log.Debug("Retry difflayer due to query origin failed", "owner", owner, "path", path, "hash", hash.String(), "error", err) + log.Debug("Retry difflayer due to query origin failed", + "owner", owner, "path", path, "query_hash", hash.String(), "return_hash", rhash.String(), "error", err) return dl.intervalNode(owner, path, hash, 0) } else { // This is the fastpath. - return blob, bhash, nloc, nil + return blob, rhash, nloc, nil } } diffHashCacheSlowPathMeter.Mark(1)