neoneo-go/pkg
Roman Khimov e80c60a3b9 network: rework broadcast logic
We have a number of queues for different purposes:
 * regular broadcast queue
 * direct p2p queue
 * high-priority queue

And two basic egress scenarios:
 * direct p2p messages (replies to requests in Server's handle* methods)
 * broadcasted messages

Low priority broadcasted messages:
 * transaction inventories
 * block inventories
 * notary inventories
 * non-consensus extensibles

High-priority broadcasted messages:
 * consensus extensibles
 * getdata transaction requests from consensus process
 * getaddr requests

P2P messages are a bit more complicated, most of the time they use p2p queue,
but extensible message requests/replies use HP queue.

Server's handle* code is run from Peer's handleIncoming, every peer has this
thread that handles incoming messages. When working with the peer it's
important to reply to requests and blocking this thread until we send (queue)
a reply is fine, if the peer is slow we just won't get anything new from
it. The queue used is irrelevant wrt this issue.

Broadcasted messages are radically different, we want them to be delivered to
many peers, but we don't care about specific ones. If it's delivered to 2/3 of
the peers we're fine, if it's delivered to more of them --- it's not an
issue. But doing this fairly is not an easy thing, current code tries performing
unblocked sends and if this doesn't yield enough results it then blocks (but
has a timeout, we can't wait indefinitely). But it does so in sequential
manner, once the peer is chosen the code will wait for it (and only it) until
timeout happens.

What can be done instead is an attempt to push the message to all of the peers
simultaneously (or close to that). If they all deliver --- OK, if some block
and wait then we can wait until _any_ of them pushes the message through (or
global timeout happens, we still can't wait forever). If we have enough
deliveries then we can cancel pending ones and it's again not an error if
these canceled threads still do their job.

This makes the system more dynamic and adds some substantial processing
overhead, but it's a networking code, any of this overhead is much lower than
the actual packet delivery time. It also allows to spread the load more
fairly, if there is any spare queue it'll get the packet and release the
broadcaster. On the next broadcast iteration another peer is more likely to be
chosen just because it didn't get a message previously (and had some time to
deliver already queued messages).

It works perfectly in tests, with optimal networking conditions we have much
better block times and TPS increases by 5-25%% depending on the scenario.

I'd go as far as to say that it fixes the original problem of #2678, because
in this particular scenario we have empty queues in ~100% of the cases and
this new logic will likely lead to 100% fan out in this case (cancelation just
won't happen fast enough). But when the load grows and there is some waiting
in the queue it will optimize out the slowest links.
2022-10-11 18:42:40 +03:00
..
compiler smartcontract: define parameter lengths as constants and use them 2022-10-05 10:46:21 +03:00
config cli: also check new ApplicationConfiguration for consistency 2022-07-27 12:30:08 +03:00
consensus *: use uint*Size and SignatureLen constants where appropriate 2022-10-05 10:45:52 +03:00
core core: close BoltDB on failed root bucket creation 2022-10-10 10:12:34 +03:00
crypto *: use uint*Size and SignatureLen constants where appropriate 2022-10-05 10:45:52 +03:00
encoding fixedn: add a test for empty string 2022-08-19 21:52:43 +03:00
interop interop: refactor address.FromHash160 code 2022-09-27 15:32:57 +03:00
io [#2442] English Check 2022-05-04 19:48:27 +03:00
neorpc golangci: add predeclared linter 2022-09-02 18:36:26 +03:00
neotest core, rpc: move getFakeNextBlock to Blockchain 2022-10-07 15:56:34 +03:00
network network: rework broadcast logic 2022-10-11 18:42:40 +03:00
rpcclient *: use uint*Size and SignatureLen constants where appropriate 2022-10-05 10:45:52 +03:00
services services: adjust RPC server's getHistoricParams 2022-10-07 16:06:12 +03:00
smartcontract smartcontract: fix underlying PublicKey parameter value 2022-10-11 13:50:32 +03:00
util slice: add Clean microfunction 2022-09-02 14:44:32 +03:00
vm vm: remove default syscall handler 2022-10-07 15:56:34 +03:00
wallet Merge pull request #2725 from nspcc-dev/move-cli-tests 2022-10-06 13:43:39 +07:00