From 26fb93513db9431bc2fa0db27e4ce5429d50d0f2 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Thu, 20 Nov 2025 15:40:52 +0800 Subject: [PATCH] eth: fix trie DB reference dereferenced in traceChain, close XFN-85 #1731 --- eth/api_tracer.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/eth/api_tracer.go b/eth/api_tracer.go index a65d3d39c4..566884a50d 100644 --- a/eth/api_tracer.go +++ b/eth/api_tracer.go @@ -356,12 +356,16 @@ func (api *PrivateDebugAPI) traceChain(ctx context.Context, start, end *types.Bl break } // Reference the trie twice, once for us, once for the trancer - database.TrieDB().Reference(root, common.Hash{}) - if number >= origin { + if number < end.NumberU64() { // Skip the last iteration database.TrieDB().Reference(root, common.Hash{}) + if number >= origin { + database.TrieDB().Reference(root, common.Hash{}) + } } // Dereference all past tries we ourselves are done working with - database.TrieDB().Dereference(proot) + if proot != (common.Hash{}) { // Skip the first iteration + database.TrieDB().Dereference(proot) + } proot = root } }()