Commit graph

4874 commits

Author SHA1 Message Date
Roman Khimov
6f7fed344b rpcclient: add Internal client for direct RPC server calls
It has a special `requestF` and a special initialization function, but other
than that it's an absolutely regular WSClient. Can be used to call, can be
used to subscribe. Fixes #2909.
2023-02-16 23:49:58 +03:00
Roman Khimov
a55a01d456 rpcsrv: provide RegisterLocal for local clients
This allows to call RPC server more effectively in the same process (bypassing
TCP/HTTP). Refs. #2909.
2023-02-16 23:49:58 +03:00
Roman Khimov
e496084bee params: add FromAny function
Creating RPC server parameters from any data can be useful. Refs. #2909.
2023-02-15 16:46:59 +03:00
Anna Shaleva
25ed5fcd60 vm: allow custom limit duing Map\Array\Struct deserialization 2023-02-08 10:58:55 +03:00
Anna Shaleva
15fa65d30f vm: export stackitem's deserContext 2023-02-08 10:58:54 +03:00
Anna Shaleva
51a28fac8d rpcclient: adjust new subscriptions API doc
Add a warning about consequences of unproper notifications reading.
Ref. https://github.com/morphbits/neofs-cdn-edge-manager/pull/88#discussion_r1088007680.
2023-01-30 14:36:11 +03:00
Leonard Lyubich
d09158161e services/rpcsrv: Strengthen Server error channel's type
According to docs, `Server` uses provided error channel only to write
encountered error to it. In this case, there is no need to accept rw
channel to create `Server` instance. Strengthening the type to
write-only will allow the caller to ensure control of reading errors
from the provided channel.

The change is backward compatible since any `chan` is `chan<-`.

Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
2023-01-23 10:33:46 +03:00
Leonard Lyubich
cbdc6ba469 rpcclient/actor: Document RPCActor.CalculateNetworkFee method
`Actor.MakeUnsignedUncheckedRun` method imposes restriction to
`CalculateNetworkFee` method's implementations: `Hash` or `Size` methods
must not be called on the pointer to the given transaction.

Add docs to adjust described requirement.

Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
2023-01-17 21:28:20 +03:00
Anna Shaleva
28927228f0 *: adjust subscription-related doc
Add a warning about received events modification where applicable.
2023-01-17 17:11:19 +03:00
Roman Khimov
40ef567527
Merge pull request #2872 from nspcc-dev/fix-missing-exception-in-applog
state: always marshal applog exception into JSON, fix #2869
2023-01-12 12:49:00 +07:00
Roman Khimov
babc44bfb3
Merge pull request #2871 from nspcc-dev/fix-shadowed-infinite-loop
Fix shadowed infinite loop
2023-01-12 12:48:39 +07:00
Roman Khimov
9a6fa84f70
Merge pull request #2867 from nspcc-dev/store-magic-in-db
core: store magic in the DB version, fix #2847
2023-01-11 20:42:00 +07:00
Roman Khimov
4e23695441
Merge pull request #2866 from nspcc-dev/findstates-ret-nothing
Fix findstates response difference
2023-01-11 20:41:10 +07:00
Roman Khimov
817f64f9fe state: always marshal applog exception into JSON, fix #2869
Fortunately, this is backwards-compatible in any direction. See
98b5e2b353 also.
2023-01-11 16:36:41 +03:00
Roman Khimov
8305389852 compiler: don't panic, return error for strange range loops
See #2870.
2023-01-11 16:21:40 +03:00
Roman Khimov
92acc71c80 compiler: create new locals for range loops when needed, fix #2855 2023-01-11 15:49:10 +03:00
Roman Khimov
1c4c783c3a core: store magic in the DB version, fix #2847 2023-01-11 12:05:05 +03:00
Roman Khimov
e780037cb4 rpcsrv: use valid stateroot hash in failing tests
Just in case.
2023-01-11 11:23:47 +03:00
Roman Khimov
9718602ce3 rpcsrv: return empty set from findstates when there is no data
Fix #2863.
2023-01-11 11:21:58 +03:00
Roman Khimov
584675ec23 state: optimize NEP17Transfer struct
We have both from and to here, so technically we can either drop the neg/neg
trick from the processTokenTransfer() or drop one field from the structure
(the other side is a part of the key). Drop the field since this can make the
DB a bit more compact. Change Amount to be a pointer along the way since
that's the "native" thing for big.Int, we've used non-pointer field
specifically to avoid Neg/Neg problems, but it looks like this is not
necessary.

This structure is only used by the RPC server and I doubt anyone uses it via
the *Blockchain.
2023-01-10 22:51:45 +03:00
Roman Khimov
dfd4f6978f bigint: don't reallocate big.Int in ToBytes(), fix #2864
In some cases n.Add() can reuse the []Word buffer and n.Sub() reallocate it
away. If that happens, we're out of luck with 0.99.0+ versions (since
3945e81857). I'm not sure why it does that, bit
width doesn't change in most of the cases and even if it does, we still have
enough of it in cap() to hold the old Abs() value (when we have a negative
value we in fact decreate its Abs() first and increase it back
afterwards). Still, that's what we have.

So when we have processTokenTransfer() doing Neg/Neg in-place its value is not
affected, but the original []Word bits that are reused by amount value are
(they're shared initially, Amount: *amount).

name                   old time/op    new time/op    delta
ToPreallocatedBytes-8    65.8ns ± 2%    45.6ns ± 2%  -30.73%  (p=0.008 n=5+5)

name                   old alloc/op   new alloc/op   delta
ToPreallocatedBytes-8     0.00B          0.00B          ~     (all equal)

name                   old allocs/op  new allocs/op  delta
ToPreallocatedBytes-8      0.00           0.00          ~     (all equal)
2023-01-10 22:51:45 +03:00
Roman Khimov
4e6ce9c3e6
Merge pull request #2846 from nspcc-dev/fix-getblockbyindex-req
network: do not allow to request invalid block count
2022-12-29 04:04:01 +07:00
Anna Shaleva
9b364aa7ee network: do not allow to request invalid block count
The problem is in peer disconnection due to invalid GetBlockByIndex
payload (the logs are from some patched neo-go version):
```
дек 15 16:02:39 glagoli neo-go[928530]: 2022-12-15T16:02:39.490Z        INFO        new peer connected        {"addr": "10.78.69.115:50846", "peerCount": 3}
дек 15 16:02:39 glagoli neo-go[928530]: 2022-12-15T16:02:39.490Z        WARN        peer disconnected        {"addr": "10.78.69.115:50846", "error": "invalid block count", "peerCount": 2}
дек 15 16:02:39 glagoli neo-go[928530]: 2022-12-15T16:02:39.490Z        INFO        started protocol        {"addr": "10.78.69.115:50846", "userAgent": "/NEO-GO:1.0.0/", "startHeight": 0, "id": 1339571820}
дек 15 16:02:39 glagoli neo-go[928530]: 2022-12-15T16:02:39.491Z        INFO        new peer connected        {"addr": "10.78.69.115:50856", "peerCount": 3}
дек 15 16:02:39 glagoli neo-go[928530]: 2022-12-15T16:02:39.492Z        WARN        peer disconnected        {"addr": "10.78.69.115:50856", "error": "invalid block count", "peerCount": 2}
дек 15 16:02:39 glagoli neo-go[928530]: 2022-12-15T16:02:39.492Z        INFO        started protocol        {"addr": "10.78.69.115:50856", "userAgent": "/NEO-GO:1.0.0/", "startHeight": 0, "id": 1339571820}
дек 15 16:02:39 glagoli neo-go[928530]: 2022-12-15T16:02:39.492Z        INFO        new peer connected        {"addr": "10.78.69.115:50858", "peerCount": 3}
дек 15 16:02:39 glagoli neo-go[928530]: 2022-12-15T16:02:39.493Z        INFO        started protocol        {"addr": "10.78.69.115:50858", "userAgent": "/NEO-GO:1.0.0/", "startHeight": 0, "id": 1339571820}
дек 15 16:02:39 glagoli neo-go[928530]: 2022-12-15T16:02:39.493Z        WARN        peer disconnected        {"addr": "10.78.69.115:50858", "error": "invalid block count", "peerCount": 2}
дек 15 16:02:39 glagoli neo-go[928530]: 2022-12-15T16:02:39.494Z        INFO        new peer connected        {"addr": "10.78.69.115:50874", "peerCount": 3}
дек 15 16:02:39 glagoli neo-go[928530]: 2022-12-15T16:02:39.494Z        INFO        started protocol        {"addr": "10.78.69.115:50874", "userAgent": "/NEO-GO:1.0.0/", "startHeight": 0, "id": 1339571820}
дек 15 16:02:39 glagoli neo-go[928530]: 2022-12-15T16:02:39.494Z        WARN        peer disconnected        {"addr": "10.78.69.115:50874", "error": "invalid block count", "peerCount": 2}
```

GetBlockByIndex payload can't be decoded, and the only possible cause
is zero (or <-1, but it's probably not the case) block count requested.

Error is improved as far.
2022-12-28 13:04:56 +03:00
Anna Shaleva
c0a453a53b network: adjust requestBlocs logic
If the lastQueued block index is the same as the one we'd like to
request in payload, then we need to increment the payload's count.
2022-12-28 12:50:30 +03:00
Evgeniy Stratonikov
db977ce38d vm: add fuzz test for ParseMultiSigContract
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2022-12-28 11:50:15 +03:00
Evgeniy Stratonikov
affe1ecb4f encoding: add bigint fuzz test
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2022-12-28 11:50:13 +03:00
Roman Khimov
3339824fe9 native: simplify code somewhat, get Metadata() only once 2022-12-16 23:48:04 +03:00
Roman Khimov
5d478b5514 native: add old management deploy/update call flags to Aspidochelone
d5a9af5860 is incompatible with the NeoFS
mainnet sidechain, so we add the old logic to the pre-Aspidochelone
behaviour. Changing flags at newMethodAndPrice() is a bit less convenient
unfortunately because this will affect interop validity checks, so let's have
this kludge here.
2022-12-16 23:45:47 +03:00
Roman Khimov
3e714a348e
Merge pull request #2842 from nspcc-dev/stringer
*: use zap.Stringer instead of zap.String where it can be used
2022-12-13 22:12:18 +07:00
Roman Khimov
e79dec15f9 *: use zap.Stringer instead of zap.String where it can be used
It's a bit more efficient in case we're not logging the message (mostly for
debug), makes the code somewhat simpler as well.
2022-12-13 12:44:54 +03:00
Roman Khimov
c1afaf8ea8 rpcsrv: use more robust NEP-11 divisibility check
It's more heavyweight at the same time, but should be OK for the
purpose. Inspired by https://github.com/neo-project/neo-modules/issues/754#issuecomment-1345176986
2022-12-10 11:45:43 +03:00
Roman Khimov
3ce1fc41a4 config: fix the default P2P ping settings
54c2aa8582 broke them, they're in seconds and we
have a 90s timeout.
2022-12-07 21:29:40 +03:00
Roman Khimov
0d65071abc config: use string type for Port
6b4dd5703e made it to be a uint16 which was
somewhat important for RPC, but now it's irrelevant and the fact that it was a
string in some cases may lead to errors like these:

  failed to unmarshal config YAML: yaml: unmarshal errors:
    line 48: cannot unmarshal !!str `20011` into uint16
    line 52: cannot unmarshal !!str `40001` into uint16

So for maximum backwards compatibility we better have string here and
eventually it'll be deleted anyway.
2022-12-07 21:21:05 +03:00
Roman Khimov
4e7cee4e12 config: replace VerifyBlocks with SkipBlockVerification
It directly affects node security and the default here MUST BE the safe choice
which is to do the verification. Otherwise it's just dangerous, absent any
VerifyBlocks configuration we'll get an insecure node. This option is not
supposed to be frequently used and it doesn't affect the ability to process
blocks, so breaking compatibility (in a safe manner) should be OK here.
2022-12-07 17:35:56 +03:00
Roman Khimov
7589733017 config: add a special Blockchain type to configure Blockchain
And include some node-specific configurations there with backwards
compatibility. Note that in the future we'll remove Ledger's
fields from the ProtocolConfiguration and it'll be possible to access them in
Blockchain directly (not via .Ledger).

The other option tried was using two configuration types separately, but that
incurs more changes to the codebase, single structure that behaves almost like
the old one is better for backwards compatibility.

Fixes #2676.
2022-12-07 17:35:53 +03:00
Roman Khimov
199a6de737 Merge pull request #2838 from nspcc-dev/neo-misuse
*: fix Neo and NeoGo misuses
2022-12-07 21:34:27 +07:00
Anna Shaleva
2d6db6f5c4 vm: adjust stale comment 2022-12-07 17:30:02 +03:00
Anna Shaleva
82221b0ca7 *: fix Neo and NeoGo misuses 2022-12-07 17:29:09 +03:00
Roman Khimov
b1f1405f42
Merge pull request #2836 from nspcc-dev/fix-subs
rpcclient: fix filtered naive subscriptions receiver
2022-12-07 21:17:07 +07:00
Anna Shaleva
2c0844221a rpcclient: fix filtered naive subscriptions receiver
We should return the filter itself instead of pointer.
2022-12-07 16:56:16 +03:00
Roman Khimov
c4d519f549
Merge pull request #2837 from nspcc-dev/350-compat
native: make management compatible with C# node 3.5.0
2022-12-07 20:19:04 +07:00
Roman Khimov
236e633ee4 native: make management compatible with C# node 3.5.0
It doesn't store id->hash mappings for native contracts. We need blockchain's
GetContractScriptHash to serve both anyway, so it was changed a bit. The only
other direct user of native.GetContractScriptHash is the VM CLI, but I doubt
anyone will use it for native contracts (they have ~zero VM code anyway).
2022-12-07 15:13:17 +03:00
Roman Khimov
883c6c5286 config: add Consensus subsection for dBFT config, fix #2677
Old UnlockWallet is still supported and works just fine.
2022-12-07 13:20:21 +03:00
Roman Khimov
730849a1cd config: move common part of notary/state into InternalService 2022-12-07 13:18:50 +03:00
Roman Khimov
90a85259a8
Merge pull request #2827 from nspcc-dev/multiaddr
network: support multiple bind addresses
2022-12-07 17:15:56 +07:00
Anna Shaleva
54c2aa8582 config: move P2P options to a separate config section
And convert time-related settings to a Duration format along the way.
2022-12-07 13:06:05 +03:00
Anna Shaleva
9cf6cc61f4 network: allow multiple bind addresses for server
And replace Transporter.Address() with Transporter.HostPort() along the way.
2022-12-07 13:06:03 +03:00
Anna Shaleva
9087854b1e services: allow multiple listen addresses for simple services
And deprecate the old way of Address/Port configuration for these services.
2022-12-07 11:23:01 +03:00
Roman Khimov
cad0fab704
Merge pull request #2828 from nspcc-dev/rpcwrapper-structures
Handle structures in the RPC wrapper generator
2022-12-06 21:40:16 +07:00
Anna Shaleva
6b4dd5703e config: unify BasicService config within existing services
There are no changes visible from the user side (at least for those
users who doesn't put Prometheus's or pprof's port in quotes), just
internal refactoring. From now and on, BasicService configuration is
used by RPC server config, TLS for RPC server, pprof and Prometheus.
2022-12-06 16:35:09 +03:00