Commit graph

284 commits

Author SHA1 Message Date
Daniel Liu
ad0eea0f07
refactor(crypto): vendor in golang.org/x/crypto/sha3 #33323 (#2046)
The upstream libray has removed the assembly-based implementation of
keccak. We need to maintain our own library to avoid a peformance
regression.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: lightclient <lightclient@protonmail.com>
2026-02-28 17:23:57 +04:00
Daniel Liu
2515d6c6c5
fix(trie): fix embedded node size validation #33803 (#2047)
The `decodeRef` function used `size > hashLen` to reject oversized
embedded nodes, but this incorrectly allowed nodes of exactly 32 bytes
through. The encoding side (hasher.go, stacktrie.go) consistently uses
`len(enc) < 32` to decide whether to embed a node inline, meaning nodes
of 32+ bytes are always hash-referenced. The error message itself
already stated `want size < 32`, confirming the intended threshold.
Changed `size > hashLen` to `size >= hashLen` in `decodeRef` to align
the decoding validation with the encoding logic, the Yellow Paper spec,
and the surrounding comments.

Co-authored-by: sashass1315 <sashass1315@gmail.com>
2026-02-28 16:59:52 +04:00
Daniel Liu
d754f363e5
core/state: remove account reset operation v2 #29520 (#1934) 2026-02-24 14:17:27 +05:30
Daniel Liu
fabfd1c485
perf(core): track state change set with account address #27815 (#2076) 2026-02-24 13:49:17 +05:30
Daniel Liu
677f923125
refactor(all): track state changes in state db #27349 (#1947) 2026-02-24 10:27:31 +05:30
Daniel Liu
398d9b693d
refactor(core): make signature of ContractCode hash-independent #27209 (#1169) 2026-02-13 09:11:43 +05:30
Daniel Liu
07d3c421f3
fix(trie): no persisted clean trie cache file #27525 (#1170) 2026-02-13 08:48:23 +05:30
Daniel Liu
a51eaa7200
fix(core, trie): revert error removal in (*state.Trie).Commit #27544 (#1168)
* trie, core/state: revert error removal in (*state.Trie).Commit

* Gary's nitpick :)



---------

Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
2026-02-05 11:43:33 +05:30
Daniel Liu
d749d54ea5
feate(core, trie): add UpdateContractCode to the Trie interface #27476 (#1167)
Verkle trees store the code inside the trie. This PR changes the interface to pass the code, as well as the dirty flag to tell the trie package if the code is dirty and needs to be updated. This is a no-op for the MPT and the odr trie.

Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
2026-02-05 11:43:04 +05:30
Daniel Liu
9cf795c908
perf: improve state reader with error handling and committed flag #27428 (#1166)
- Add error returns to Database.Reader() and NodeIterator() methods
- Introduce committed flag to prevent usage of tries after commit
- Update callers to handle new error signatures
- Add MustNodeIterator() helper for backward compatibility

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
2026-02-03 20:55:53 +05:30
Daniel Liu
d12f9803eb
trie: remove parameter 'fromLevel' in Prove #27512 (#1165)
This removes the feature where top nodes of the proof can be elided.
It was intended to be used by the LES server, to save bandwidth
when the client had already fetched parts of the state and only needed
some extra nodes to complete the proof. Alas, it never got implemented
in the client.

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
2026-01-29 11:29:02 +05:30
Daniel Liu
222d180a6b
trie: update func ForEachWithOrder #27496 #27909 (#1163)
Co-authored-by: Dan Laine <daniel.laine@avalabs.org>
Co-authored-by: Felix Lange <fjl@twurst.com>
2026-01-29 11:28:36 +05:30
Daniel Liu
3518be8c8b
core/state: move slot RLP encoding into the MPT implementation #27000 (#1162)
Continuing with a series of PRs to make the Trie interface more generic, this PR moves
the RLP encoding of storage slots inside the StateTrie and light.Trie implementations,
as other types of tries don't use RLP.

Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
2026-01-26 18:04:50 +05:30
Daniel Liu
e40208f3db
trie: new empty trie with types.EmptyRootHash instead of null #27230 (#1160) 2026-01-26 18:04:14 +05:30
Daniel Liu
3d194d4303
all: port boring changes from pbss #27176 (#1158)
* all: port boring changes from pbss

* core, trie: address comments from martin

* trie: minor fixes

* core/rawdb: update comment

* core, eth, tests, trie: address comments

* tests, trie: add extra check when update trie database

* trie/triedb/hashdb: degrade the error to warning

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
2026-01-26 11:21:46 +05:30
Daniel Liu
1b7d4afdd3
trie: add node type common package #27160 (#1150)
* trie: add node type common package

In trie/types package, a few node wrappers are defined, which will be used
in both trie package, trie/snap package, etc. Therefore, a standalone common
package is created to put these stuffs.

* trie: rename trie/types to trie/trienode

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
2026-01-21 10:47:53 +05:30
Daniel Liu
4a7eea65b9
trie: rework trie database #26813 (#1149)
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
2026-01-19 11:23:51 +05:30
Daniel Liu
583338686f
all: expose block number information to statedb #27753 (#1936) 2026-01-16 15:55:04 +05:30
Daniel Liu
6d4670a4ec
core, trie: refactor trie API #26995 (#1147)
In this PR, all TryXXX(e.g. TryGet) APIs of trie are renamed to XXX(e.g. Get) with an error returned.

The original XXX(e.g. Get) APIs are renamed to MustXXX(e.g. MustGet) and does not return any error -- they print a log output. A future PR will change the behaviour to panic on errorrs.

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
2026-01-16 15:51:13 +05:30
Daniel Liu
7684d88d3c
core/state, trie: remove Try prefix in Trie accessors #26975 (#1146)
This change renames StateTrie methods to remove the Try* prefix.

We added the Trie methods with prefix 'Try' a long time ago, working
around the problem that most existing methods of Trie did not return the
database error. This weird naming convention has persisted until now.

Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2026-01-05 15:44:42 +05:30
Daniel Liu
3bb3f80f5b
core/state: add account address to Trie slot accessors #26934 (#1140)
This changes the Trie interface to add the plain account address as a
parameter to all storage-related methods.

After the introduction of the TryAccount* functions, TryGet, TryUpdate and
TryDelete are now only meant to read an account's storage. In their current
form, they assume that an account storage is stored in a separate trie, and
that the hashing of the slot is independent of its account's address.

The proposed structure for a stateless storage breaks these two
assumptions: the hashing of a slot key requires the address and all slots
and accounts are stored in a single trie.

This PR therefore adds an address parameter to the interface. It is ignored
in the MPT version, so this change has no functional impact, however it
will reduce the diff size when merging verkle trees.

Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
2025-12-23 15:39:56 +05:30
Daniel Liu
63783a6b4c
core/state, trie: port changes from PBSS #26763 (#1137)
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
2025-12-22 12:03:56 +05:30
Daniel Liu
b08622248c
trie: add error-checks #26914 (#1138) 2025-12-19 11:47:02 +04:00
Daniel Liu
56ef5f3956
trie: reduce unit test time #26918 (#1139) 2025-12-19 11:46:35 +04:00
Daniel Liu
47501c8834
core/state, trie: remove unused error-return from trie Commit operation #26641 (#1135)
Co-authored-by: Martin Holst Swende <martin@swende.se>
2025-12-08 15:05:11 +05:30
wit liu
ea3a55aef4
all: fix invalid directive syntax for golangci-lint nolint (#1799) 2025-12-08 13:02:54 +05:30
Daniel Liu
8be96e4622
trie: use slices package for sorting #27496 (#1703) 2025-12-07 15:43:53 +05:30
Daniel Liu
940fd2adbd
core, trie: port changes from pbss #26637 (#1127) 2025-12-07 15:38:38 +05:30
Daniel Liu
ec08863ba0
all: use WaigGroup.Go() to simplify code (#1699) 2025-11-29 17:17:08 +05:30
Daniel Liu
3b3aa9b013
core, trie: prepare for path-based trie storage #26603 (#1126)
This PR moves some trie-related db accessor methods to a different file, and also removes the schema type. Instead of the schema type, a string is used to distinguish between hashbased/pathbased db accessors.
This also moves some code from trie package to rawdb package.

This PR is intended to be a no-functionality-change prep PR for #25963 .

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2025-11-18 11:20:00 +05:30
Daniel Liu
d47260ea98
core, trie: clean up trie interface #26388 (#1125)
* all: cleanup trie interface

* eth, trie: address comments

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
2025-11-18 11:19:27 +05:30
Daniel Liu
07328dcec4
core, eth, trie: abstract node scheme #25532 (#1123)
This PR introduces a node scheme abstraction. The interface is only implemented by `hashScheme` at the moment, but will be extended by `pathScheme` very soon.

Apart from that, a few changes are also included which is worth mentioning:

-  port the changes in the stacktrie, tracking the path prefix of nodes during commit
-  use ethdb.Database for constructing trie.Database. This is not necessary right now, but it is required for path-based used to open reverse diff freezer

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
2025-11-17 11:25:08 +05:30
Daniel Liu
a4fbda2924
trie: wrap deletion in case trie.root is nil #26365 (#1124)
This PR fixes an error in trie commit. If the trie.root is nil, it can be two possible scenarios:

-  The trie was empty, and no change happens
-  The trie was non-empty and all nodes are dropped

For the latter one, we should collect the deletions and apply them into database(e.g. in PBSS).

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
2025-11-17 11:24:11 +05:30
Daniel Liu
0c96e76992
trie, XDCx, XDCxlending: not expose db in trie (#1763) 2025-11-15 16:49:47 +05:30
Daniel Liu
eef5242fa3
all: pre-allocate memory for slices and maps, close XFN-148 (#1714) 2025-11-14 20:13:36 +05:30
wit liu
9155d354c9
tracers, consensus/clique: use maps.Clone #29616 (#1755) 2025-11-14 20:00:21 +05:30
Daniel Liu
28a4f25166
cmd, core, eth, trie: track deleted nodes #22225 #25757 (#1120)
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
2025-11-12 13:32:22 +05:30
Daniel Liu
d11e128322
trie: handle more batch commit errors in Database #25674 (#1118)
Co-authored-by: Amir Hossein <77993374+Kamandlou@users.noreply.github.com>
2025-11-12 10:17:58 +05:30
Daniel Liu
58c066f053
all: handle err from func rlp.Encode, close XFN-127 (#1692) 2025-11-03 12:45:19 +05:30
Daniel Liu
22edaacf0d
trie: update comments + err check for preimages #25672 (#1117)
This PR includes minor updates to comments in trie/committer that reference insertion to the db, and adds an err != nil check for the return value of preimages.commit.

Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org>
2025-10-24 16:57:19 +08:00
Daniel Liu
3f0f3af776
trie: check childrens' existence concurrently for snap heal #25694 (#1573)
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2025-10-08 12:24:04 +08:00
Daniel Liu
271687e463
core, trie: remove DiskDB function from trie database #25690 (#1116) 2025-10-08 12:21:56 +08:00
Daniel Liu
0bd353373e
trie: fix unhandled error in test #25628 (#1115)
Co-authored-by: Amir Hossein <77993374+Kamandlou@users.noreply.github.com>
2025-10-08 12:20:53 +08:00
Daniel Liu
1c7e92b56e
trie: better error reporting #25645 (#1114)
Co-authored-by: Martin Holst Swende <martin@swende.se>
2025-10-08 12:18:14 +08:00
Daniel Liu
2563cd13ed
trie: cleanup stateTrie #25640 (#1113)
It's a trivial PR to hide the error log when the trie node is not found in the database. The idea for this change is for all TryXXX functions, the error is already returned and we don't need to fire a log explicitly.

Recently there are a few tickets #25613 #25589 reporting that the trie nodes are missing because of debug.SetHead. The root cause is after resetting, the chain rewinds to a historical point and re-imports the blocks on top.

Since the node is already synced and started to accept transactions previously, these transactions are still kept in the txpool and verified by txpool with a live state. This live state is constructed based on the live trie database, which is changed fast by node referencing and de-referencing.

Unfortunately, when we construct a live state(like the state in txpool), we don't reference the state we have. The blockchain will garbage collect the intermediate version nodes in another thread which leads the broken live state.

The best solution for this is to forcibly obtain a reference for all live states we create and call release function once it's used up. But it might end up with more junks persisted into disk. Will try to find an elegant solution later in the following PR.

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
2025-09-24 07:45:06 +08:00
Daniel Liu
862f18ec58
core/state, trie: fix trie flush order for proper pruning #25581 (#1112)
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2025-09-24 07:44:22 +08:00
wit liu
1a2c8ee180
all: fix govet (#1517)
Co-authored-by: wit <wit765765346@gmail>
2025-09-21 18:55:13 +08:00
Daniel Liu
0b13b19b55
trie: fix some typos #25551 #25648 (#1111) 2025-09-21 18:51:15 +08:00
Daniel Liu
637e732aff
trie: improve node rlp-decoding #25357 (#1109) 2025-09-17 08:42:42 +08:00
Daniel Liu
80159e5854
core/state, trie: add DeleteAccount method #25531 (#1108) 2025-09-13 09:29:51 +08:00