Commit Graph

804 Commits

Author SHA1 Message Date
KonradStaniec dff9040cc1
Fix bug when reading till eof (#483) 2022-03-03 22:38:13 +01:00
jangko 6c4d04562d
add bootnodes test 2022-02-27 11:53:11 +07:00
jangko 622e6489d8
EIP-4399 changes: random -> prevRandao 2022-02-27 11:40:15 +07:00
jangko 63add129b8
replace two bootnodes
see https://github.com/ethereum/go-ethereum/pull/24432/files
and https://github.com/status-im/nimbus-eth1/issues/978
2022-02-27 10:17:56 +07:00
KonradStaniec 8ef6b13b1b
Add event loop to socket (#475)
- add eventLoop to control all incoming events
- change semantic of write to asynchronously block only when send buffer is full, and not when bytes do not fit into send window
- change handling of receive buffer, to start dropping packets if the reorder buffer and receive buffer are full. Old behaviour was to async block unless there is space which could lead to resource exhaustion attacks
2022-02-24 18:22:44 +01:00
Zahary Karadjov f947827c70
Debug logs providing info for the initial discoveryv5 configuration 2022-02-18 17:42:37 +02:00
KonradStaniec 779d767b02
Add more tests stressing conccurent reading and writing on utp socket (#474)
* Add more tests stressing concurrent reading and writing

* Fix bug when remote window dropped below packet size
2022-02-10 08:05:44 +01:00
Kim De Mey 05ef9a8e00
More --styleCheck fixes for discoveryv5 and eth/common (#473) 2022-02-03 15:51:08 +01:00
Kim De Mey 41edd4a3f2
Add DiscoveryConfig to tune routing table ip limits and bitPerHops (#471) 2022-02-02 15:29:45 +01:00
jangko cf95b688e6
EIP-4399 preparation
From EIP-4399 spec:

Renaming

The mixHash field SHOULD further be renamed to random.

...
2022-02-01 13:41:50 +07:00
Daniel Kaiser eb6fd2a7b6
minor fix in discv5 docu (#470)
Just fixing a test cmd line.
2022-01-31 17:16:15 +01:00
Jacek Sieka ce4acc168c
kvstore: simplified stmt exec iterator (#467) 2022-01-28 15:23:41 +02:00
KonradStaniec 5791afccc3
Implement fast resend logic for selective acks (#468)
* Implement fast resend logic for selective acks
2022-01-27 11:07:40 +01:00
KonradStaniec 7afd44d33e
Implement fast resend logic (#466) 2022-01-26 09:49:34 +01:00
KonradStaniec 9a7b1afe9b
Add custom talkreq implementation (#464)
* Add custom talkreq implementation to utp over discv5
2022-01-24 11:58:35 +01:00
KonradStaniec 4e2b340af6
Fix sudden window drop bug (#465)
Fixes problem which caused drop of maxWindow to the size of
only one packet in case of only one packet hitting timeout.
2022-01-21 14:48:01 +01:00
KonradStaniec 45348e7664
Add more logs to utp (#463)
* Add more logs to utp

* Change initial timeout for inc socket to positive value
2022-01-20 13:20:30 +01:00
KonradStaniec b2dab4be08
Re-send acks for old duplicated packets (#462)
* Re-send acks for old duplicated packets
2022-01-20 09:22:53 +01:00
Kim De Mey 26ab9b078e
Minor adjustments in utp_discv5_protocol (#459)
- Move SocketConfig parameter location
- Reuse rng from disc5 protocol
- add exports
- Some whitespace clean-up
2022-01-10 13:49:36 +01:00
KonradStaniec 0f18272315
Test vectors upt decoding/encoding (#458) 2022-01-07 10:38:36 +01:00
KonradStaniec fcb0ff521c
Improve logging in uTP (#457)
* Improve logging
2022-01-07 10:38:19 +01:00
KonradStaniec 9c8e9d9f64
Handle selective acks (#456)
* Handle selective acks
2022-01-04 09:52:38 +01:00
KonradStaniec 664072fff7
Minor improvements from pr comments (#455) 2021-12-28 08:08:05 +01:00
Kim De Mey 42e257796f
Add discoveryv5 session metrics (#454) 2021-12-21 15:09:46 +01:00
Kim De Mey 8b7d41f596
Don't use exceptions for enr get call (#453)
The ENR code used to be solely exception based, and these
exceptions where a left-over of that. They are useless as later
calls use Result anyhow.

Additionally, they cause quite the performance loss because they
are used in the "common path" for the toTypedRecord call, e.g.
when reading the fields of ip6, tcp6 and udp6.
2021-12-21 15:09:32 +01: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 0cfe7df817
Handle packets with selective acks (#451)
* Handle packets with selective acks
2021-12-15 13:35:17 +01:00
Etan Kissling 5655bd035c
Merge pull request #450 from etan-status/reject-whoareyou-len
reject WHOAREYOU packets with non-empty message
2021-12-14 16:22:25 +01:00
Ștefan Talpalaru 452f92200c
CI: cleanup 2021-12-14 03:24:11 +01:00
Ștefan Talpalaru 2088d7568d
CI: test with multiple Nim version (#429)
* CI: test with multiple Nim version

* clean up the testing tree a little

* replace "unittest" with "unittest2"
2021-12-11 19:12:55 +01:00
Etan Kissling 45387ad4d2
reject WHOAREYOU packets with non-empty message
This changes the `discv5` parser to reject malformed WHOAREYOU packets
that have a non-0 message length. The extra data used to be ignored.
The `message` part of WHOAREYOU packets is always empty.
See https://github.com/ethereum/devp2p/blob/master/discv5/discv5-wire.md
2021-12-11 15:55:14 +01:00
Etan Kissling fb7ea69eb4
Merge pull request #449 from etan-status/encryptgcm-type
more specific type check in `encryptGCM`
2021-12-11 14:50:35 +01:00
Etan Kissling 172dad7968
more specific type check in `encryptGCM`
Narrowed the type of `encryptGCM`'s `key` parameter from
`openarray[byte]` to `AesKey`, same as already used for `decryptGCM`.
2021-12-11 12:41:18 +01:00
Etan Kissling 923fc428f2
Merge pull request #447 from etan-status/rm-ssz
remove outdated and incorrect SSZ code
2021-12-10 16:57:31 +01:00
KonradStaniec b56e19a590
Improve handling of timestamps (#446)
* Improve handling of timestamps
2021-12-10 16:28:00 +01:00
Etan Kissling 3ce2d9a58e
remove outdated and incorrect SSZ code
This removes the outdated copy of the SSZ code. It became incorrect
over time (e.g., empty SSZ list elements), and is no longer in use by
GitHub projects: https://github.com/search?q=extension%3Anim+eth%2Fssz

The canonical SSZ implementation resides at `nim-ssz-serialization`.
Compared to `nim-eth`, these changes were made meanwhile:
- `bitseqs` was extended with JSON serialization support,
  and with the new functions `isZero` and `countOnes`.
- `bytes_reader` was renamed to `codec`, extended with a few additional
  SSZ type conversions as well as support for `SingleMemberUnion`.
- The simplified merkle tree implementation in `merkle_tree.nim`
  was removed. It was not used by other projects.
- `merkleization` was extended with support for `HashArray`, `HashList`
  and `SingleMemberUnion`. The `isValidProof` functionality has been
  moved to `nimbus-eth2` and replaced with the EF defined function
  `is_valid_merkle_branch`. The test was also moved to `nimbus-eth2`.
  There are no other GitHub projects using `isValidProof`:
  https://github.com/search?q=extension%3Anim+isValidProof
  Furthermore, a definition for `GeneralizedIndex` was added.
- `ssz_serialization` was moved one directory up, and improved with
  bug fixes and `HashArray`, `HashList` and `SingleMemberUnion` support.
- `types` was extended with JSON serialization and new type support for
  `Uint128`, `Uint256`, `HashArray`, `HashList` and `SingleMemberUnion`.
  There is also a new `getBit` function for `BitList`.
2021-12-10 15:51:22 +01:00
Kim De Mey 41d2d3c991
Utp top level raises & some clean-up (#445)
* Add few missing top level raises Defect in uTP

- Add top level {.push raises: [Defect].}
- remove some local raises, including some unneeded
CatchableErrors.
- Don't export messageHandler (avoiding annoying naming collisions)
- export utp_router as those connection callbacks are in the API

* Add some missing copyright clauses

* Some ident and max line length cleanup

* Rename utp_discv5_protocol.nim to be more consistent
2021-12-10 11:12:24 +01:00
KonradStaniec 09959d2a3f
Update timestamp and ackNr on packet resend (#444)
* Update timestamp and ackNr on packet resend
2021-12-10 10:18:00 +01:00
KonradStaniec b4066a5688
Ledbat congestion control (#443)
* Return delay to remote peer

* Initial ledbat window calculation

* Add tests for window grow and decay

* Add delay histograms

* Add calculation of clock drift
2021-12-09 10:52:21 +01:00
Kim De Mey ae0920d40d
Remove hashData usage on objects (#441)
* Remove hashData usage on objects

* Add hash func for NodeId to avoid using the one of stint
2021-12-06 15:24:07 +01:00
tersec 307b4e51b4
Point to current name of Ethereum consensus specs repo (#442) 2021-12-06 09:08:51 +01:00
KonradStaniec e7bc10ab00
Add config for max snd buffer size (#440)
* Add config for max snd buffer size
2021-12-02 16:51:44 +01:00
KonradStaniec 3c8915cae1
Track send buffer and properly handle back pressoure when window is to small to process data (#437)
* Add separate datastructure to keep track of window

* Asynchronously block write until until new space in snd buffer

* Introduce write loop

* Properly handle write cancellation

* Proper handling of sending fin packet

* Reset remote window after configured amount of time
2021-12-02 15:46:18 +01:00
Kim De Mey 6e21b32f0d
Allow a node to self resolve (#439) 2021-12-02 11:10:26 +01:00
Jamie Lokier 6a8d49e4c0 Security/RLPx: Fix crash when peer sends out of bounds message id
Closes [nimbus-eth1#767](https://github.com/status-im/nimbus-eth1/issues/767).

Crashes occur when certain invalid RLPx messages are received from a peer.
Specifically, `msgId` out of range.  Because any peer can easily trigger this
crash, we'd consider it a DOS vulnerability if Nimbus-eth1 was in general use.

We noticed when syncing to Goerli, there were some rare crashes with this
exception.  It turned out one peer with custom code, perhaps malfunctioning,
was sending these messages if we were unlucky enough to connect to it.

`invokeThunk` is called from `dispatchMessages` and checks the range of
`msgId`.  It correctly recognise that it's out of range, raises and exception
and produces a message.  Job done.

Except the code in `dispatchMessage` treats all that as a warning instead of
error, and continues to process the message.  A bit lower down, `msgId` is used
again without a range check.

The trivial fix is to check array bounds before access.

--

ps. Here's the stack trace ("reraised" sections hidden):

```
WRN 2021-11-08 21:29:33.238+00:00 Error while handling RLPx message          topics="rlpx" tid=2003472 file=rlpx.nim:607 peer=Node[<IP>:45456] msg=45 err="RLPx message with an invalid id 45 on a connection supporting eth,snap"
/home/jamie/Status/nimbus-eth1/nimbus/p2p/chain/chain_desc.nim(437) main
/home/jamie/Status/nimbus-eth1/nimbus/p2p/chain/chain_desc.nim(430) NimMain
/home/jamie/Status/nimbus-eth1/nimbus/nimbus.nim(258) process
/home/jamie/Status/nimbus-eth1/vendor/nim-chronos/chronos/asyncloop.nim(279) poll
/home/jamie/Status/nimbus-eth1/vendor/nim-chronos/chronos/asyncmacro2.nim(74) colonanonymous
/home/jamie/Status/nimbus-eth1/vendor/nim-eth/eth/p2p/rlpx.nim(1218) rlpxAccept
/home/jamie/Status/nimbus-eth1/vendor/nim-chronos/chronos/asyncmacro2.nim(101) postHelloSteps
/home/jamie/Status/nimbus-eth1/vendor/nim-chronos/chronos/asyncmacro2.nim(74) colonanonymous
/home/jamie/Status/nimbus-eth1/vendor/nim-eth/eth/p2p/rlpx.nim(985) postHelloSteps
/home/jamie/Status/nimbus-eth1/vendor/nim-chronos/chronos/asyncmacro2.nim(101) dispatchMessages
/home/jamie/Status/nimbus-eth1/vendor/nim-chronos/chronos/asyncmacro2.nim(77) colonanonymous
/home/jamie/Status/nimbus-eth1/vendor/nim-eth/eth/p2p/rlpx.nim(614) dispatchMessages
/home/jamie/Status/nimbus-eth1/vendor/nimbus-build-system/vendor/Nim/lib/system/chcks.nim(23) raiseIndexError2
/home/jamie/Status/nimbus-eth1/vendor/nimbus-build-system/vendor/Nim/lib/system/fatal.nim(49) sysFatal
[[reraised from: ... ]]
[[reraised from: ... ]]
[[reraised from: ... ]]
[[reraised from: ... ]]
Error: unhandled exception: index 45 not in 0 .. 40 [IndexError]
```

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-11-30 20:03:01 +02:00
Kim De Mey ae0574fe61
Adjust logging when node is not reachable but enrAutoUpdate is on (#436)
Separate the logging when the node is not reachable and
enrAutoUpdate is on or off to avoid confusion whether or not the
node might still become reachable.
2021-11-29 22:13:08 +01:00
Jacek Sieka 2baa4c02a1
avoid allocation in `hash(ValidIpAddress)` (#433)
* avoid allocation in `hash(ValidIpAddress)`

While casually browsing the profiler output, to my great surprise I
found that an allocating string conversion function (gasp!) in the hash
function for ip addresses - this PR carefully excises this evil
construct from the codebase.

* bump nim version
2021-11-29 20:58:45 +01:00
KonradStaniec 139c6fa2a8
Track current bytes in flight (#434) 2021-11-24 17:49:13 +01:00
Kim De Mey 84f755d792
Revert the useless async change for queryRandom (#432) 2021-11-22 23:14:37 +01:00
Kim De Mey 086162183c
Make queryRandom async and add exports (#431)
queryRandom was currently only async for the `enrField` version.
However the basic queryRandom is also exported and thus gets
changed so it can be properly used as async proc.

Also added exports for the modules of which objects are used in
the discovery public API.
2021-11-22 19:45:38 +01:00