fix: check disklayer hash consistency

pull/29991/head
will@2012 3 months ago
parent b97b0b65e1
commit d5e4c6c7f8
  1. 9
      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)

Loading…
Cancel
Save