792 Commits

Author SHA1 Message Date
Etan Kissling
33f548186d
allow ElemType(XXX) on inputs not called T (#414)
Currently, `ElemType` can only be called on `List` types when they are
first assigned to a variable called `T`. The template has been adjusted
so that different variable names may be used. The template can now also
be applied to in-line computed types, e.g., `ElemType(typeof(x))`.
2021-10-21 09:43:42 +02:00
Etan Kissling
004ea06b80
fix big-endian merkleization for UintN arrays (#412)
UintN arrays were incorrectly merkleized on big-endian. This was fixed
by making sure to use the correct buffer to store the final chunk.
2021-10-21 09:43:14 +02:00
Etan Kissling
3d78c66119
fix compile error due to cyrillic T (#411)
There was a cyrillic T in some big-endian specific code that broke the
compilation on such platforms. This replaces that T with an ASCII T to
fix the build.
2021-10-20 14:21:06 +02:00
Etan Kissling
6272eaa6cd
fix markleizer typo (-> merkleizer) (#410)
Fix for a typo in a variable name.
2021-10-20 14:20:58 +02:00
Kim De Mey
9a1bb5e125
Make ENR $ call print the IP address prettier (#409) 2021-10-19 14:13:09 +02:00
KonradStaniec
88795c6477
Add sending and receiving data procedures (#407)
* Add sending and receiving data procedures
2021-10-19 13:36:57 +02:00
Kim De Mey
f101c83626
Enr rlp lists (#408)
* Don't fail ENR decoding when value is an RLP list

* Store RLP raw list in the ENR field pair instead

* Add ENR kList FieldKind so lists can be treated differently

Treated differently now when printing out the ENR, mentioning
that it is a raw RLP list
2021-10-19 09:26:14 +02:00
KonradStaniec
6fbf129ba9
Add initial handling of acks (#406)
* Add initial handling of acks

Add implemetaion of circular buffer based on reference implementation
Add way to test number of packet in flight
Add acking of initial syn packet
2021-10-15 13:38:51 +02:00
KonradStaniec
7ae287ad1b
Add rudimentary connect function (#405)
* Add rudimentary connect function
2021-10-11 14:16:06 +02:00
Kim De Mey
5125a438db
Make the custom distances call somewhat more accessible (#404)
And make the naming more consistent
2021-10-07 16:03:12 +02:00
KonradStaniec
32ef1b7f4f
Improve serialization implementation (#403) 2021-10-06 11:36:37 +02:00
Kim De Mey
1babe38226
Allow for tcp/udp ports to always be configured (#402)
* Allow for tcp/udp ports to always be configured

- Allow for an ENR to be build with tcp and udp ports also when
no IP address is provided
- In the address set-up always provide best efforttcp and udp ports
also when configuration of external ip (and/or ports) fails.
2021-09-29 18:50:23 +02:00
Zahary Karadjov
5327565f95
Add accessor for the discv5 listening address (Protocol.bindAddress) 2021-09-29 01:43:00 +03:00
KonradStaniec
9f2f101070
Add initial skeleton of utp protocol (#397)
* Add initial impl of utp over udp

* Add more comments

* Add licenses and push declarations

* Add tests to nimble task

* Pr comments

Use better random generator
Raise assert error in case of buffer io exception
2021-09-13 14:54:06 +02:00
KonradStaniec
a95b205cf7
Modify nodes verification (#398)
* Modify nodes verification

* Move nodes verification to separate module

By moving verification to separate module it can be re-used
in different contexts not only in discoveryv5.
2021-09-13 14:20:26 +02:00
KonradStaniec
e219547d64
Fix lookupDistances function and make it public (#399) 2021-09-10 17:26:22 +02:00
Kim De Mey
df6020832b
Build fuzzing tests in CI and fix current fuzzing tests (#396)
* Build fuzzing tests in CI and fix current fuzzing tests

* Build fuzzing tests separately (fix Windows CI)
2021-09-07 16:00:01 +02:00
Kim De Mey
bea1f1c6a1
Clean-up routing table object constructions (#395) 2021-09-07 11:56:16 +02:00
KonradStaniec
c078f85e48
Expose id and address of talkreq sender (#393) 2021-09-07 10:49:18 +02:00
KonradStaniec
bfadcfbfaf
Make Routing table distance function configurable (#392) 2021-09-02 14:00:36 +02:00
KonradStaniec
aa3fbbd95d
Add proof verification to public api (#390) 2021-08-12 16:15:02 +02:00
Jamie Lokier
83e5638212 Add option to connectToNetwork return without waiting for peers
The new sync code wants to start without waiting.  We can `discard` the async
result but there is no need for a background task polling and running a timer
for no clear benefit.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-10 14:09:57 +03:00
Jamie Lokier
9a28ed7ef5 RLPx: Protocol names have never been limited to 3 characters
Don't treat 3 characters as special in `cmp`.  `cmp` for `ProtocolInfo` was
wrong because it ignored all characters after the first 3.

In the wild we have seen protocol names longer than 3 characters.  `snap`,
`hive`, `istanbul`, `bzzeth`, `bzz-stream`, `bzz-retrieve`, `dbix`, `opera`,
`pchain`, `pchain_child_0`, `sero`, `smilobft`, `spock`.

There was never a 3 character limit in the [specification]
(https://github.com/ethereum/devp2p/blob/master/rlpx.md).

It always said "short ASCII name", until recently on 2021-02-25 it was changed
to an 8 characters limit.

Also `pi.nameStr` can be removed.  Nothing uses it, and it has the same actual
effect as just copying the string `pi.name`.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-10 14:08:35 +03:00
Jamie Lokier
5234e30f8b Remove {.rlpInline.} which was never really implemented
For a long time this caused invalid RLP parsing of `NewBlock` messages in the
`eth` protocol.

The `rlpInline` pragma was accepted but had no effect.  We could implemented
it, but it doesn't seem worth doing, with tests etc, as there's only one user
which has been fixed another way.

With `NewBlock`, whenever a peer sent us `NewBlock`, we'd get an RLP decoding
error, and disconnected the peer thinking it was the peer's error.

These messages are sent often by good peers, so whenever we connected to a
really good peer, we'd end up disconnecting within a minute due to this.  This
went unnoticed for years, as we stayed connected to old peers which have no new
blocks, and we weren't looking at peer quality, disconnect reasons or real-time
blockchain updates anyway.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-10 14:08:35 +03:00
KonradStaniec
50c0c5f123
Add helpers to generate merkle proofs (#381) 2021-08-09 12:17:21 +02:00
Kim De Mey
9bc4fa366a
Let talkreq directly return the seq[byte] for easier API (#384) 2021-07-30 16:04:14 +02:00
Kim De Mey
dd02d1be23
Remove unused lastUpdated from buckets (#382) 2021-07-29 21:58:10 +02:00
Jamie Lokier
04ff8e460f Fix RLP serialisation of seq[Transaction] used in eth protocol
1. Generalises the special cases for serialising RLP `seq[Transaction]`.
   Previously it only used the special case inside `BlockBody` and `EthBlock`.
   Now it uses it for all `seq[Transaction]` regardless of what objects they
   are parts of, or no object at all.  `openArray[Transaction]` is also
   included, as this was found to be necessary to match in some places.

2. Bug fix parsing `Transaction`: Always read the first byte to get the
   transaction type instead of parsing an RLP `int`.  This way invalid or
   adversarial input gives a correct error (i.e. invalid type code).

   When it was read with `rlp.read(int)`, those inputs gave many crazy
   messages (e.g. "too large to fit in memory").  In the specification it's a
   byte.  (Technically the input is not RLP and we shouldn't be using the RLP
   parser anyway to parse standalone transaction objects).

3. Bug fix parsing `Transaction`: If a typed transaction is detected in
   `seq[Transaction]`, the previous code removed the RLP (blob) wrapper, then
   passed the contents to `read(Transaction)`.  That meant a blob-wrapped
   legacy transaction would be accepted.  This is incorrect.  The new code
   passes the contents to the typed transaction decoder, which correctly
   rejects a wrapped legacy transaction as having invalid type.

Change 1 has a large, practical effect on `eth/65` syncing with peers.

Serialisation of `eth` message types `Transactions` and `PooledTransactions`
have been broken since the introduction of typed transactions (EIP-2718), as
used in Berlin/London forks.  (The special case for `seq[Transaction]` inside
`BlockBody` only fixed message type `BlockBodies`.)

Due to this, whenever a peer sent us a `Transactions` message, we had an RLP
decoding error processing it, and disconnected the peer thinking it was the
peer's error.

These messages are sent often by good peers, so whenever we connected to a
really good peer, we'd end up disconnecting from it within a few tens of
seconds due to this.

This didn't get noticed before updating to `eth/65`, because with old protocols
we tend to only connect to old peers, which may be out of date themselves and
have no typed transactions.  Also, we didn't really investigate occasional
disconnects before, we assumed they're just part of P2P life.

The root cause is the RLP serialisation of individual `Transaction` is meant to
be subtly different from arrays/sequences of `Transaction` objects in network
messages.  RFC-2976 covers this but it's quite subtle:

- Individual transactions are encoded and stored as either `RLP([fields..])`
  for legacy transactions, or `Type || RLP([fields..])`.  Both of these
  encodings are byte sequences.  The part after `Type` doesn't have to be
  RLP in theory, but all types so far use RLP.  EIP-2718 covers this.

- In arrays (sequences), transactions are encoded as either `RLP([fields..])`
  for legacy transactions, or `RLP(Type || RLP([fields..]))` for all typed
  transactions to date.  Spot the extra `RLP(..)` blob encoding, to make it
  valid RLP inside a larger RLP.  EIP-2976 covers this, "Typed Transactions
  over Gossip", although it's not very clear about the blob encoding.

In practice the extra `RLP(..)` applies to all arrays/sequences of transactions
that are to be RLP-encoded as a list.  In principle, it should be all
aggregates (object fields etc.), but it's enough for us to enable it for all
arrays/sequences, as this is what's used in the protocol and EIP-2976.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-07-29 15:37:11 +03:00
KonradStaniec
e3fba48f0f
add merkle proof verification (#379)
* add merkle proof verification

* remove redundant buffer

* simplify verification function
2021-07-23 13:40:47 +02:00
KonradStaniec
20ad6504b7
Add merkleization tests (#378)
* Add merkleization tests

* Fix typo in build file

* add test prefix
2021-07-21 09:24:07 +02:00
KonradStaniec
44fee391f4
Port merkleization off ssz (#376) 2021-07-19 15:58:09 +02:00
Kim De Mey
a8d11dd30b
Add top level push raises Defect to p2p code (#374) 2021-07-16 21:44:30 +02:00
Kim De Mey
2557fd35c6
Use aesKeySize const for aes key instead if ivSize (same values) (#375) 2021-07-16 14:55:52 +02:00
Kim De Mey
eb0908e33f
Push raises Defect to rlpx and accompanying changes (#373) 2021-07-14 10:35:35 +02:00
Kim De Mey
79911ed5d8
Log distance to uint16 and add public neighbours calls (#371)
* Use uint16 instead of uint32 for discv5 log distance

* Make neighboursAtDistances and neighbours calls available
2021-07-13 10:05:46 +02:00
Kim De Mey
41127eaee8
Remove portal wire code which was moved to nimbus-eth1 repo (#370) 2021-07-09 22:14:31 +02:00
Ștefan Talpalaru
2dfd352fd0 metrics: initialise lock for custom collector 2021-07-06 17:46:23 +03:00
jangko
a10d301085
implement EIP-1559 Transaction and BlockHeader 2021-06-27 20:12:47 +07:00
kdeme
1c400e3f0e
Improve Portal message tracing 2021-06-09 14:57:35 +02:00
kdeme
880b753ad2
Add Portal wire readme doc 2021-06-09 14:57:35 +02:00
kdeme
e2e30247bf
Add implementation of Portal wire protocol 2021-06-09 14:57:30 +02:00
Kim De Mey
d18ebaa570
Slightly improved logging traces for error on message responses (#364) 2021-06-09 14:55:00 +02:00
Jacek Sieka
3514ee6484
sqlite: quick exec with result (#361) 2021-05-27 11:31:34 +02:00
Jacek Sieka
68e6aadc29 sqlite3: support option type
.. and any integer when writing but don't support int32 on reads -
internally sqlite will truncate on overflow which isn't nice.
2021-05-26 13:32:31 +03:00
Jacek Sieka
2a292cfb62
sqlite: fix readonly mode (#359)
* sqlite: fix readonly mode

* document kvstore versions
2021-05-25 20:57:28 +02:00
Kim De Mey
8abe6b7144
Add support for discv5 talk protocols (#357) 2021-05-20 09:49:46 +02:00
Jacek Sieka
1995afb87e
kvstore fixes (#350)
Storing large blobs in a "WITHOUT ROWID" table turns out to be extremely
slow when the tree must be rebalanced.

* Split out keystore capability into separate interface, making each
keystore a separate instance
* Disable "WITHOUT ROWID" optimization by default
* Implement prefix lookup that allows iterating over all values with a
certain prefix in their key
2021-05-17 15:55:57 +02:00
jangko
ea8530f6a0
EIP-2718: fixes BlockBody rlp encoding 2021-05-17 10:07:05 +07:00
jangko
d0eb2de328
eip2718: protect against malformed rlp in tx sequence decoder 2021-05-16 19:15:48 +07:00
jangko
ef49a6f50a
fixes EIP2718/EIP2930 misinterpretation
the new Tx format (txType || txPayload) needs envelope
encoding at EthBlock level, not at the Tx level itself.
2021-05-16 12:10:09 +07:00