Commit Graph

47 Commits

Author SHA1 Message Date
Jacek Sieka 00c91a1dca
Ordered trie for computing roots (#744)
Root encoding is on the hot path for block verification both in the
consensus (when syncing) and execution clients and oddly consititutes a
significant part of resource usage even though it is not that much work.

While the trie code is capable of producing a transaction root and
similar feats, it turns out that it is quite inefficient - even for
small work loads.

This PR brings in a helper for the specific use case of building tries
of lists of values whose key is the RLP-encoded index of the item.

As it happens, such keys follow a particular structure where items end
up "almost" sorted, with the exception for the item at index 0 which
gets encoded as `[0x80]`, ie the empty list, thus moving it to a new
location.

Armed with this knowledge and the understanding that inserting ordered
items into a trie easily can be done with a simple recursion, this PR
brings a ~100x improvement in CPU usage (360ms vs 33s) and a ~50x
reduction in memory usage (70mb vs >3gb!) for the simple test of
encoding 1000000 keys.

In part, the memory usage reduction is due to a trick where the hash of
the item is computed as the item is being added instead of storing it in
the value.

There are further reductions possible such as maintaining a hasher per
level instead of storing hash values as well as using a direct-to-hash
rlp encoder.
2024-10-08 20:02:58 +02:00
Jacek Sieka b49df0a71a
remove binary tries (#736)
Binary tries were an early research idea but are no longer part of any
plausible etheruem roadmap, hence we remove them.
2024-09-30 12:59:16 +02:00
Jacek Sieka 6bd6bae86c
Align core types with execution spec (#733)
Since these types were written, we've gained an executable spec:

https://github.com/ethereum/execution-specs

This PR aligns some of the types we use with this spec to simplify
comparisons and cross-referencing.

Using a `distinct` type is a tradeoff between nim ergonomics, type
safety and the ability to work around nim quirks and stdlib weaknesses.

In particular, it allows us to overload common functions such as `hash`
with correct and performant versions as well as maintain control over
string conversions etc at the cost of a little bit of ceremony when
instantiating them.

Apart from distinct byte types, `Hash32`, is introduced in lieu of the
existing `Hash256`, again aligning this commonly used type with the spec
which picks bytes rather than bits in the name.
2024-09-29 10:52:19 +02:00
Etan Kissling cc6d88962e
Treat putting empty data in hexary trie as deleting data (#720)
Other implementations of MPT delete entries when attempting to put empty
value, because empty value cannot exist in RLP. We should match the
behaviour.

- https://github.com/ethereum/py-trie/pull/109

Also cross-checked with Geth and Ethereumjs implementations.
2024-08-14 23:48:39 +00:00
Jacek Sieka 56f72c7a66
Revert speedups (#718)
* Revert "hash compatibility fix (#717)"

This reverts commit 047de2b788.

* Revert "port eth2_digest speedups to eth_hash (#716)"

This reverts commit 864d54467e.
2024-08-09 07:20:35 +02:00
Jacek Sieka 864d54467e
port eth2_digest speedups to eth_hash (#716)
* port eth2_digest speedups to eth_hash

* faster comparison
* `hash` integration
* lower-case printing
2024-08-08 05:44:15 +00:00
andri lim 4cccf25af7
Reduce compiler warnings related to rlp encode int (#699) 2024-06-12 09:29:18 +07:00
Jacek Sieka 0e83cfda97
results: use standalone repo (#687) 2024-05-30 14:46:57 +02:00
Jacek Sieka 50b3d0193c
Revert missing hexary trie node work (#686)
* Revert "In the incomplete-db node-existence check, don't use contains. (#603)"

This reverts commit 4b818e8307.

* Revert "Some changes to make hexary.nim better able to handle incomplete DBs (#602)"

This reverts commit f5dd26eac0.

* Revert "Added maybeGet, for working with incomplete DBs. (#595)"

This reverts commit 4754543605.
2024-05-28 10:05:57 +02:00
Jacek Sieka 0addffcc6c
binary tries: remove (#684)
not used anywhere
2024-05-26 09:57:59 +02:00
tersec c608426d03
add/change Deneb fields per https://github.com/ethereum/execution-apis/pull/417 (#616) 2023-06-03 18:47:55 +00:00
Jacek Sieka 6e5ee490c2
avoid ptr_arith (#608) 2023-05-11 07:39:21 +00:00
Kim De Mey d57a1094b1
Remove all Defect raises to avoid unnecessary warnings (#607)
As this module dropped support for Nim versions < 1.6, all Defect
raises can be removed to avoid unnecessary warnings
2023-05-10 15:50:04 +02:00
tersec 7564b21ade
support only Nim 1.6+ (#606) 2023-05-09 20:19:44 +00:00
Adam Spitz 4b818e8307
In the incomplete-db node-existence check, don't use contains. (#603)
* In the incomplete-db node-existence check, don't use contains.

(Using contains led to a problem with CaptureDB.)

* In the incomplete-db check, just checking len > 0 isn't right.

* Oh, I needed the AssertionDefect thing too.

* Need this when compiling under older versions of Nim.

* Sometimes we want missing nodes to be errors, sometimes not.
2023-04-28 12:04:33 -04:00
Adam Spitz f5dd26eac0
Some changes to make hexary.nim better able to handle incomplete DBs (#602)
* Added maybeGet, for working with incomplete DBs.

* Made trie.del throw an exception if it encounters a missing node.
2023-04-21 07:59:15 -04:00
Adam Spitz 4754543605
Added maybeGet, for working with incomplete DBs. (#595) 2023-04-03 13:01:25 -04:00
Adam Spitz 71b148a5b0
Propagating the del-returns-a-bool change through the trie DB code. (#578)
See here:
8f0ae55353
2023-01-17 16:39:28 -05:00
Justin Traglia e7d3de6ebf
Fix some typos (#557) 2022-11-16 17:44:00 +01:00
KonradStaniec 059d319c16
Safer mpt proof verification (#536)
* Safer mpt proof verification
2022-09-14 19:02:05 +02:00
Jacek Sieka d31abca010
clean up eth_types (#531)
`eth_types` is being imported from many projects and ends up causing
long build times due to its extensive import lists - this PR starts
cleaning some of that up by moving the chain DB and RLP to their own
modules.

this PR also moves `keccakHash` to its own module and uses it in many
places.
2022-09-02 16:57:52 +02:00
Kim De Mey 2c236f6495
Style fixes according to --styleCheck:usages (#452)
Currently only setting `--styleCheck:hint` as there are some
dependency fixes required and the compiler seems to trip over the
findnode MessageKind, findnode Message field and the findNode
proc. Also over protocol.Protocol usage.
2021-12-20 13:14:50 +01:00
KonradStaniec aa3fbbd95d
Add proof verification to public api (#390) 2021-08-12 16:15:02 +02:00
Kim De Mey d05cb5d3bd
Fix raw Exceptions in hexary caused by forward declarations (#349)
* Fix raw Exceptions in hexary caused by forward declarations

* Fix raw Exceptions in trie/db caused by forward declarations

* And now we can remove those db Proc CatchableError raises
2021-05-11 17:32:47 +02:00
Kim De Mey 762415319c
Add build_dcli target and add it to CI (#344)
* Add build_dcli target and add it to CI

* Fix local imports for dcli

* And use local imports for all other files too

* Use local imports in tests and rlpx protocols
2021-04-06 13:33:24 +02:00
Jacek Sieka 205b57fe71
port kvstore from nim-beacon-chain (#230)
* port kvstore from nim-beacon-chain
* remove old database backends
* use kvstore in trie database
* add sqlite dep
* avoid template param double evaluation
* clean up heterogenous lookup todo
2020-04-27 15:16:11 +02:00
Jacek Sieka fd6caa0fdc
Rlp experimental (#227)
* rlp: remove experimental features

* avoid range library

* trie: avoid reference-unsafe bitrange type
2020-04-20 20:14:39 +02:00
Jacek Sieka 1646d78d83
cleanups (#226) 2020-04-18 10:17:59 +02:00
Jacek Sieka e9b25b5309
Result rocks (#225)
* rocksdb: update
2020-04-18 07:21:13 +02:00
tersec 56f312c69b
port TODOs from nim-beacon-chain lmdb implementation (#197) 2020-03-14 11:34:33 +01:00
kdeme b951ec45dc
Address review comments from Enterlist PR 2020-03-01 11:46:38 +01:00
Zahary Karadjov e89e59aa59
`enterList` now returns a bool 2020-02-27 20:09:05 +02:00
Ștefan Talpalaru f4712aaf74
rename safeEnterList() to enterList()
in order to avoid unhandled exceptions due to malformed data received
over the network
2020-02-25 16:10:09 +01:00
Zahary Karadjov cca931d0b5
Reduce the use of the general Exception type and improve the exception tarcking in protocol.receive 2020-02-18 00:47:13 +02:00
Zahary Karadjov d70bb85392 Review all exceptions and classify them as Defects and Errors 2020-02-06 16:32:00 +01:00
andri lim e0e49b1711 implement hexary trie replicate iterator 2019-12-11 11:50:45 +02:00
andri lim 146eeddd65 add trie/db.nim 2019-12-03 01:41:57 +02:00
kdeme 44400ee549 Fix nim v1.0.2 compile issues 2019-10-29 14:44:26 +02:00
kdeme 5389884ecf
Add max open files limit of 512 to rocksdb init 2019-07-18 21:15:35 +02:00
Jacek Sieka 75c7c62651
std_shims -> stew 2019-07-07 11:56:01 +02:00
andri lim 2d75751960 add readonly option to lmdb and rocksdb backend 2019-04-01 11:29:39 +03:00
Ștefan Talpalaru 9146e8e2f0
assert() -> doAssert() 2019-03-13 23:15:26 +01:00
andri lim daafd991d5 address cheatfate comments 2019-02-18 13:14:43 +02:00
andri lim c36b3e54cc change TransactionFlags to TransactionState 2019-02-18 13:14:43 +02:00
andri lim 96f29a971d more robust dbtx dispose 2019-02-18 13:14:43 +02:00
Ștefan Talpalaru 95b93eb5aa convert zeroBytesRange and zeroNibblesRange into threadvars
fixes https://github.com/status-im/nim-eth/issues/6
2019-02-15 16:33:40 +02:00
Yuriy Glukhov 32998f0dc1 Moved rlp and trie to eth 2019-02-05 14:01:10 +02:00