{"record":{"id":"4095d89e36f36179","repo":"ethereum/go-ethereum","slug":"t-invalid-node-v-v","errorCode":null,"errorMessage":"%T: invalid node: %v (%v)","messagePattern":"%T: invalid node: (.+?) \\((.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"trie/trie.go","lineNumber":729,"sourceCode":"\tcase nil:\n\t\treturn false, nil, nil\n\n\tcase hashNode:\n\t\t// We've hit a part of the trie that isn't loaded yet. Load\n\t\t// the node and delete from it. This leaves all child nodes on\n\t\t// the path to the value in the trie.\n\t\trn, err := t.resolveAndTrack(n, prefix)\n\t\tif err != nil {\n\t\t\treturn false, nil, err\n\t\t}\n\t\tdirty, nn, err := t.delete(rn, prefix, key)\n\t\tif !dirty || err != nil {\n\t\t\treturn false, rn, err\n\t\t}\n\t\treturn true, nn, nil\n\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"%T: invalid node: %v (%v)\", n, n, key))\n\t}\n}\n\n// copyNode deep-copies the supplied node along with its children recursively.\nfunc copyNode(n node) node {\n\tswitch n := (n).(type) {\n\tcase nil:\n\t\treturn nil\n\tcase valueNode:\n\t\treturn valueNode(common.CopyBytes(n))\n\n\tcase *shortNode:\n\t\treturn &shortNode{\n\t\t\tflags: n.flags.copy(),\n\t\t\tKey:   common.CopyBytes(n.Key),\n\t\t\tVal:   copyNode(n.Val),\n\t\t}\n\tcase *fullNode:","sourceCodeStart":711,"sourceCodeEnd":747,"githubUrl":"https://github.com/ethereum/go-ethereum/blob/6bb0588ad8e7f922e4ad5580f51265a4097af08f/trie/trie.go#L711-L747","documentation":"This panic fires in Trie.delete when descending the trie to remove a key and encountering a node type outside the supported set (nil, *shortNode, *fullNode, hashNode, valueNode handled above). The format includes the offending key to aid debugging. Like the insert variant, it indicates the trie contains a structurally invalid node, usually from state corruption or misuse.","triggerScenarios":"Calling Trie.Delete (or DeleteWithPath) with a key whose path traverses a child node of unknown type — for example a valueNode occupying an internal (non-leaf) position, which can occur if the trie was assembled from inconsistent node data.","commonSituations":"Pruning/snapshot bugs leaving partially deleted tries; using a trie after its database was modified externally; forged or truncated test fixtures in state-test harnesses; concurrent access races.","solutions":["Capture the key from the panic message and check whether the stored value/node at that path is well-formed RLP","Recreate the trie from the last known-good root and retry the delete","If it reproduces deterministically, dump the path nodes (t.Get each prefix) and file/inspect where the invalid node was introduced","Restore state from a snapshot or resync if on-disk state is corrupted"],"exampleFix":"// before\nt.Delete(key) // panics: '%T: invalid node: %v (%v)'\n\n// after\nfunc safeDelete(t *trie.Trie, key []byte) (err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"trie delete failed for key %x: %v\", key, r)\n        }\n    }()\n    return t.Delete(key)\n}","handlingStrategy":"try-catch","validationCode":"// Confirm the key exists through the read path before mutating\nif _, err := t.Get(key); err != nil {\n    return fmt.Errorf(\"key %x unreadable, refusing delete: %w\", key, err)\n}","typeGuard":"func isTraversable(n node) bool {\n    switch n.(type) {\n    case nil, valueNode, *shortNode, *fullNode, hashNode:\n        return true\n    }\n    return false\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        err = fmt.Errorf(\"delete %x panicked: %v — likely corrupt state at this path\", key, r)\n    }\n}()\nerr = t.Delete(key)","preventionTips":["Route deletes through a wrapper that recovers and reports the key","Keep the trie database attached for the trie's whole lifetime so hashNode children can resolve","If using pathdb, avoid skipping required flatten/commit steps between mutations"],"tags":["trie","mpt","delete","state-corruption","panic"],"backgroundTag":null,"analyzedSha":"6bb0588ad8e7f922e4ad5580f51265a4097af08f","analyzedAt":"2026-08-15T10:06:53.996Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}