Commit Graph

969 Commits

Author SHA1 Message Date
chirag-parmar 147ad1d199 fix two pass 2024-11-25 02:41:58 +05:30
chirag-parmar c25c24551c optimize using two pass 2024-11-25 02:41:58 +05:30
chirag-parmar ad04a73c1b force expansion of memory by reducing allocation size 2024-11-25 02:41:58 +05:30
chirag-parmar f763270cb1 basic rlp profiler 2024-11-25 02:41:49 +05:30
chirag-parmar 24a871f85d add a profiling test 2024-11-22 00:14:04 +05:30
Jacek Sieka 88e4be4dc4
devp2p: upgrade to v5 (EIP-706) (#760)
* drop support for v4 (obsolete, doesn't work with all clients since
they use chunking and other obsolete v4 features that we're missing or
don't support it at all)
* rework asyncraises
* always store generated p2p macro code (similar to eth2)
* preparation for chronos cancellation support (more to be done here)
* when peer is disconnected, ensure pending handshakes and requests are
notified (instead of waiting for timeout)
* disallow raising from `onPeerDisconnected` - this simplifies
disconnection coordination among async tasks
* introduce several warning logs for protocol breaches - these should be
removed eventually, pending q/a on the rlpx layer in general
* fix snappy compression - the payload without msgId should be
compressed
* remove strict checks on unused fields in RLPx message header (this
matches geth behavior and the spirit of EIP-8)
* add snappy dep
2024-11-08 03:44:04 +01:00
Chirag Parmar 034b7886de
clean up redundant code in eth/rlp/writer.nim (#755)
* cleanup macros

* add test cases and fix counting function

* add check statements

* remove deprecated support for Option

* replace some logic

* remove debug print
2024-11-06 11:46:22 +07:00
Jacek Sieka 1467b145ae
remove unusued rlpx features, tighten hello exchange and some error h… (#759)
* disconnect peers that send non-hello messages during initial hello
step
* fix devp2p protocol version - 4 because we don't implement snappy
(yet) - this is cosmetic since this particular version field is not
actually being used
* fix ack message length checking
* move RLPx transport code to separate module, annotate with asyncraises
* increase max RLPx message size to 16mb, per EIP-706
* make sure both accept/connect timeout after 10s
* aim to log every connection attempt once at debug level
* make capability-id/context-id check more accurate
* disallow random messages before hello
2024-11-05 16:30:41 +01:00
Jacek Sieka ee845a1768
devp2p: drop pre-EIP8 support, fix snappy negotiation (#758)
Support for previous versions was
[removed](7194c847b6)
from geth in 2021 after other clients had migrated - should be safe to
remove here also.

* fix snappy detection - it should use the hello version, not the RLPx
handshake
* simplify generation of auth messages
* pad 100-300 bytes like spec suggests

TODO: error handling is all over the place - will be addressed in a
follow-up PR
2024-11-02 08:15:40 +01:00
Jacek Sieka 719c0dfd56
eth_hash: condition converter deprecation warning on nim version (#756)
The warning gives too many false positives - until things work properly,
locally one can just remove it to find instances where it gets used..

https://github.com/nim-lang/Nim/issues/24241
2024-10-30 09:10:10 +01:00
Jacek Sieka 5d78c6a879
discv4: prefer ipv6 (#751)
This allows bonding with ipv4-mapped nodes above all, which fixes a
bunch of warnings
2024-10-29 10:03:13 +01:00
Csaba Kiraly 30476de038
fix potential infinite loop in randomNodes (#754)
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2024-10-24 17:24:53 +02:00
andri lim 66297c5c0a
Remove obsolete EIP-6110-7002-7251 types, encoding, and checks (#752)
* Remove obsolete EIP-6110-7002-7251 types

* Keep blocks_rlp.nim
2024-10-22 14:00:06 +07:00
Etan Kissling 171531fbf1
Add helper for recovering authority (#750)
For EIP-7702 SetCode transaction, it is necessary to identify the
authority issuing an authorization. Its account's code is set to
proxy to the authorization address if successful.
2024-10-15 21:44:10 +07:00
andri lim b736906dc7
Fix Authorization fields name to v, r, s (#749) 2024-10-15 14:09:16 +00:00
tersec 470baf82bd
update Sepolia and Holesky bootnodes (#747) 2024-10-09 15:23:58 +00:00
tersec e59125acf7
rm Goerli bootnodes (#746)
* rm Goerli bootnodes

* rm tests mention
2024-10-09 10:34:47 +00:00
Miran bb76daa6d9
add missing type, fix typo, meaningful deprecations (#745) 2024-10-08 20:21:16 +02:00
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
Kim De Mey cea821df60
Add times_rlp and headers_rlp modules (#743) 2024-10-04 17:19:59 +02:00
Jacek Sieka 4ea11b9fb9
transaction signing helpers (#742)
Transaction signing is something that happens in a lot of places - this
PR introduces primitives for transaction signing in `transaction_utils`
such that we can use the same logic across web3/eth1/etc for this simple
operation.

`transaction_utils` also contains a few more "spec-derived" helpers for
working with transactions, such as the computation of a contract address
etc that cannot easily be introduced in `transactions` itself without
bringing in dependencies like secp and rlp, so they end up in a separate
module.

Finally, since these modules collect "versions" of these transaction
types across different eips, some tests are moved to follow the same
structure.
2024-10-04 13:46:58 +02:00
Jacek Sieka 84664b0fc0
discv5: migrate to minilru (#741)
As it happens, the two share the exact same interface (even the test
suite removed in this PR passes) - `minilru` has an edge on efficiency
however, avoiding the doubly linked list node allocations etc
2024-10-03 12:34:38 +02:00
Jacek Sieka 5ce3c4557f
prevRandao -> Bytes32 (#740)
This one is a bit of a mess because it has different names and types
across specs :/
2024-10-02 13:00:10 +02:00
Jacek Sieka 70b7519f02
avoid typed return in generic template (#739) 2024-10-02 09:33:22 +02:00
Jacek Sieka 086ac68c86
Change `VersionedHash` to `Hash32` (#738)
This is closer to both the exeuction spec and api
2024-10-01 11:54:01 +02:00
Jacek Sieka 119c910a4e
remove remaining `int` holdouts in rlp (#737)
these were never well defined
2024-09-30 18:32:36 +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 00f5fb1fe0
clean up json serialization (#735)
serialize fewer non-eth types and more eth types - this module is
fraught with issues however since there's no one good "canonical"
encoding to choose - this goes back to the json ser framework lacking
good isolation between projects.
2024-09-30 10:34:47 +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
Jacek Sieka 3d51887c15
move signal ignore out of `eth/common` (#734)
`net/nat` is the only place where it is used and it certainly doesn't
belong in `common`
2024-09-24 11:30:05 +02:00
Miran 410eab5a16
update ci.yml to test Nim 2.2; also test gcc-14 (#730) 2024-09-24 05:23:32 +00:00
Kim De Mey aa1e738a97
Add discv5 constants to know allowed max talkresp message size (#732) 2024-09-19 17:53:11 +02:00
andri lim 4eecab27ef
Implement EIP-7702 Transaction and Receipt (#731)
* Implement EIP-7702 Transaction and Receipt
2024-09-13 13:37:43 +07:00
jangko 59715353db
Fix EIP-7865 types and RLP encoding 2024-09-10 20:31:07 +07:00
tersec 11eafac0f0
handle new UPnP return value (#728) 2024-09-10 05:10:08 +00:00
Kim De Mey f2568a64c0
Fix potential uTP clock drift overflow (#726) 2024-09-03 16:48:24 +02:00
Jordan Hrycaj 92c7bea807
Reassign logging weights in RLPx handler (#725)
why:
  Too much noise, updating sort of guided by
  https://github.com/status-im/nimbus-eth2/blob/unstable/docs/logging.md
2024-08-30 18:00:11 +00:00
Jordan Hrycaj 5ecbcb5886
Using unsigned types for message type and requst IDs (#722)
* Using unsigned types for message type and requst IDs

why:
  Negative values are neither defined for RLP nor in the protocol specs
  which refer to the RLPs (see yellow paper app B clause (199).

* Fix `int` argument (must be `uint`) in fuzzing tests

why:
  Not part of all tests so it slipped through.
2024-08-30 17:27:09 +00:00
Kim De Mey b874e12516
Differentiate log for invalid packet seqnr without reorder buffer and not (#723) 2024-08-29 18:15:26 +02:00
Jordan Hrycaj 98b2a34075
Fix rlpx hello crash caused by rlp decoder (#721)
* Restricting exception catcher

why:
  `CatchableError` is not needed here

* Check data length before converting to `openArray[]`

why:
  Getting the first entry of an `openArray[]` crashes with `IndexDefect`.
  This is particularly annoying when decoding messages in rlpx.

* Added unit test using rlpx message that causes this problem to detect
2024-08-19 11:38:46 +00: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
Jordan Hrycaj 9511502273
Removed obsolete chunked rlpx message protocol extension (#719) 2024-08-13 15:10:47 +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 047de2b788
hash compatibility fix (#717) 2024-08-09 06:23:56 +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 ebfe63b9b6
Convert GasInt to uint64 (#713) 2024-07-06 20:24:14 +07:00
Etan Kissling d8fda55c79
define Electra types and RLP encoding (#711)
Add types for EIP-6110, EIP-7002 and EIP-7251 validator operations.
2024-07-03 13:22:18 +02:00
Etan Kissling b90483e9d2
avoid warnings when processing `GasInt` for RLP (#712)
RLP does not support signed integer values, so we have to convert
`GasInt` to `uint64` when decoding / encoding via RLP.
2024-07-03 13:21:45 +02:00
Miran b80c227f52
simplify .nimble file (#708) 2024-07-01 18:06:10 +02:00
Kim De Mey 8088fe72d7
Update discv5 to use non deprecated ENR calls and simplify code (#710)
And due to avoiding an extra PublicKey.fromRaw call we get a
little performance boost also.
2024-06-27 16:18:21 +02:00