Commit graph

204 commits

Author SHA1 Message Date
Ekaterina Pavlova
cf2e6296b7 *: fix linter gofmt errors
```
pkg/vm/stackitem/json_test.go:11                   gofmt       File is
not `gofmt`-ed with `-s` `-r 'interface{} -> any'`
pkg/core/native/native_test/cryptolib_test.go:471  gofmt       File is
not `gofmt`-ed with `-s` `-r 'interface{} -> any'`
pkg/rpcclient/nns/contract_test.go:585             gofmt       File is
not `gofmt`-ed with `-s` `-r 'interface{} -> any'`

```

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
2024-09-26 13:29:04 +03:00
Roman Khimov
1b83dc2476 *: improve for loop syntax
Mostly it's about Go 1.22+ syntax with ranging over integers, but it also
prefers ranging over slices where possible (it makes code a little better to
read).

Notice that we have a number of dangerous loops where slices are mutated
during loop execution, many of these can't be converted since we need proper
length evalutation at every iteration.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-30 21:45:18 +03:00
Roman Khimov
6d4ebdcef3 *: return errors.ErrUnsupported where appropriate
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 12:51:12 +03:00
Roman Khimov
a1a7e3d708 *: use slices package for sorting and searching
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 12:29:44 +03:00
Roman Khimov
de665b5567 *: use slices.Sort() where appropriate
It's always faster for simple types.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
1c1d77c9b8 *: make use of min/max where appropriate
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-23 22:11:29 +03:00
Anna Shaleva
42555668da rpcclient: add Waiter.Config
Include Waiter.PollConfig into Waiter.Config and use extended Waiter
configuration where needed.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-08-20 10:13:20 +03:00
Anna Shaleva
92c6361be8 rpcclient: integrate customizable Waiter with Actor
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-08-20 10:13:20 +03:00
Anna Shaleva
027d726b65 rpcclient: allow to tune PollingBased waiter
Some clients need more flexible awaiting options (e.g. for short-blocks
networks). The default behaviour is not changed, all exported APIs are
compatible. Ref. https://github.com/nspcc-dev/neofs-node/issues/2864.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-08-20 10:13:19 +03:00
Anna Shaleva
3e3991cef8 rpcclient: remove default PolingBased poll interval
pollTime is never 0 since MillisecondsPerBlock protocol configuration value
is present in `getversion` RPC response since 0.97.3 release. We don't have such
old RPC servers in the network anymore, thus this fallback code may be
safely removed.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-08-20 10:10:59 +03:00
Anna Shaleva
c06543cf50 *: fix linter issues
Linter is updated up to v1.60.1, the following issue is fixed:
```
predeclared  variable max has same name as predeclared identifier
```

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-08-14 12:36:15 +03:00
Ekaterina Pavlova
9fb6d3266e rpcsrv: add seedlist and standbycommittee to getversion
Port neo-project/neo#3443.

Close #3538

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
2024-08-09 12:53:31 +03:00
Pavel Karpy
9fadfef0d7 rpcclient/WS: do not deadlock on connection loss
`makeWsRequest` creates a channel for response and waits for it. If between
creating the channel and starting the reading `select` connection is lost
(`writerDone` channel is closed), nothing reads from the channel and a
deadlock appears. Looking at "done" channels when transferring RPC data
solves the issue. Closes #3530.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
2024-07-29 17:39:11 +03:00
Roman Khimov
c6ed92a169
Merge pull request #3532 from nspcc-dev/fix/ws-client-subscription-panic
rpcclient/WS: fix data race on concurrent (un)subscription
2024-07-26 19:29:38 +03:00
Pavel Karpy
d6eaf6efc2 rpcclient/WS: fix data race on concurrent (un)subscription
Every client's (Un)Subscription call does two things: an RPC call and a
subscription map lock (two of maps currently). If we imagine that there is
one routine that tries to subscribe (A) and one routine that tries to
unsubscribe (B), the following sequence can happen:

0. Current number of subscriptions is X
1. B does an RPC and makes number of subscriptions X-1
2. A does an RPC and makes number of subscriptions X again
3. A holds subscription locks and rewrites client's subscription state
   (subscription with ID X now points to a different channel; channel that
   was registered by B is lost and is not related to any real subscription
   but is still included in the `receivers` map)
4. B holds subscription locks and drops subscription X (first, it is an
   error and we have just lost a subscription that we think was made
   successfully second, we have lost a channel in the `receivers` map, and
   no corresponding subscription points to it)
5. X subscription is received by the WS client (in practice it is a new
   block, 100ms, quite often to be sure this issue happens every hour), we
   range through the receivers, see no corresponding subscription, and
   panic.

Closes #3093.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
2024-07-26 18:19:50 +03:00
Anna Shaleva
ce1edda3f2
Merge pull request #3481 from EdgeDLT/getPeerHeights
Extend getpeers RPC method to provide useragent and last known height
2024-06-28 11:07:09 +03:00
edgedlt
ba4ebbd107 rpcclient: fix getpeers test
Signed-off-by: edgedlt <edgedlt@protonmail.com>
2024-06-27 14:00:08 +01:00
edgedlt
aab2620548 neorpc: extend getpeers method
Signed-off-by: edgedlt <edgedlt@protonmail.com>
2024-06-27 10:41:59 +01:00
Anna Shaleva
d9d9d00775
Merge pull request #3492 from nspcc-dev/actor-signers
invoker: add Signers() API
2024-06-21 23:30:45 +03:00
Roman Khimov
cc3f528eb6 actor: add SignerAccounts() API
Allow to retrieve the list easily.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-06-21 18:45:15 +03:00
Roman Khimov
8336b1b518 invoker: add Signers() API
Signers are very important for notary checks and keeping/passing an additional
copy of them is very inconvenient. Exposing them from invoker makes them
available in actors too.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-06-21 18:45:15 +03:00
Roman Khimov
a327a82085 actor: add a new WaitSuccess API
Most of the time people are interested in successful executions. Unfortunately,
unwrap package can't help here because of a different result structure (some
interface abstract can help, but it's still mostly stack-oriented and sessions
can be a problem), so this additional interface is needed.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-06-21 18:39:02 +03:00
Anna Shaleva
2d4993a837
Merge pull request #3438 from nspcc-dev/unwrap-fault-exception
unwrap: implement Exception type for better exception handling
2024-05-17 10:24:26 +03:00
Roman Khimov
b1bb12df48 state: drop NativeContract, fix #3430
This unifies getnativecontracts RPC API with regular contracts.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-05-16 18:46:46 +03:00
Roman Khimov
f4731eab91 unwrap: implement Exception type for better exception handling
Fix #3130. "Exception" is used for name since it's shorter and that's the name
used in JSON. "VMFault" was also considered as well as "FaultException"
(which mirrors result.Invoke).

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-05-15 23:00:27 +03:00
Anna Shaleva
0aecddea10 native: autogenerate nativehashes package
Ref.
https://github.com/nspcc-dev/neo-go/pull/3402#discussion_r1577879141.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-05-14 09:39:53 +03:00
Anna Shaleva
ec6fc54bc6 *: use nativehashes package where possible
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-04-25 13:26:54 +03:00
Ekaterina Pavlova
686c77aeea rpcsrv: add SessionEnabled, MaxIteratorResultItems to getversion
Extend getversion RPC response with RPC server settings (SessionEnabled,
MaxIteratorResultItems).Port neo-project/neo-modules#878.

Close #3276

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
2024-04-03 22:42:14 +03:00
Roman Khimov
be1b97d04e
Merge pull request #3392 from nspcc-dev/adjust-deadlines
*: adjust WS connection RW deadlines
2024-04-03 14:50:14 +03:00
Anna Shaleva
182762af5a rpcclient: make default Notary actor options customizable
This commit allows to override only MainModifier omitting overriding
MainCheckerModifier.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-04-02 18:56:43 +03:00
Anna Shaleva
b947d09552 *: adjust WS connection RW deadlines
Yet another attempt to close #3378.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-04-02 10:31:38 +03:00
Ekaterina Pavlova
e0328cc1f8 native: add getCommitteeAddress method
Port neo-project/neo#3154.

Close #3334

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
2024-03-22 16:46:59 +03:00
Ekaterina Pavlova
270515de6a native: add committee change events
Port neo-project/neo#3158.

Close #3326

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
2024-03-19 23:00:06 +03:00
Evgenii Stratonikov
1a3a494459 rpcclient: return FaultException in checkResOk if any
FaultException can be non-empty even in Halt state when there were
problems with stack marshaling to JSON.

Signed-off-by: Evgenii Stratonikov <fyfyrchik@runbox.com>
2024-03-19 18:39:02 +03:00
Ekaterina Pavlova
0016b6b630 rpc: add synchronisation for httptest.Server in tests
Add waiting for startSending to ensure that the client is ready before
the server starts sending messages.

Close #3005
Close #3312

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
2024-03-13 11:41:43 +03:00
Ekaterina Pavlova
ee39b5ca18 rpcsrv: add close of http server in tests
The HTTP server should be closed at the end of the test.

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
2024-03-06 01:17:59 +03:00
Anna Shaleva
0c6627f13d *: use multierror wrapping where possible
Revert 5f6c01336c, remove all multierror
related nolint comments and use multierror wrapping instead.

Close #2906.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-03-05 13:54:10 +03:00
Roman Khimov
9d3258495f rpcclient: use better RPC endpoint for example
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-02-26 23:18:45 +03:00
Roman Khimov
e09fc00188 rpcclient: fix address used in doc
This one doesn't really work now, it's Legacy. Replace with something N3-ish.

Thanks @lock9 for reporting.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-02-26 22:18:32 +03:00
Ekaterina Pavlova
000109bfd1 smartcontract: update nns wrapper
Added missing function from smart-contract manifest.

Close #2732

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
2024-01-26 18:30:17 +03:00
Anna Shaleva
161b83fd7f rpcclient: ensure nns.RecordType can be passed as a parameter to invoker
Implement smartcontract.Convertible for nns.RecordType.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-01-25 17:04:21 +03:00
Anna Shaleva
f5b1bd3978 waiter: adopt headers subscription for WS-based tx awaiting
Try to subscribe for headers firstly, and then if RPC server doesn't
have this ability, fallback to block subscriptions to manage transaction
awaiting.

Close #3260.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-12-29 16:00:56 +03:00
Anna Shaleva
7c9b1d05d2 rpcclient: refactor waiter package naming
Adjust names of all used structures, no need to duplicate `Waiter` everywhere,
we already in the `waiter` package. Also, adjust comments to Actor so that links
to Waiter are properly described in docs.

Ref. #3265.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-12-29 15:22:50 +03:00
Anna Shaleva
1ca7b0bbeb
Merge pull request #3265 from nspcc-dev/cli_await
cli: add await flag for operations with transactions
2023-12-29 17:22:23 +05:00
Evgenii Stratonikov
78050e8b2c unwrap: Add test for HALT state with an empty stack
Missing piece for perfect coverage. Check that an error is returned an
no panic occurs.

Signed-off-by: Evgenii Stratonikov <fyfyrchik@runbox.com>
2023-12-29 10:50:46 +03:00
Evgenii Stratonikov
402a73b7f3 unwrap: Add ArrayAndSessionIterator(), close #3272
It can be used to work with the results of
CreateCallAndPrefetchIteratorScript() execution. The first item must be
an array and the optional second item must be an iterator, containing
remaining elements.

Signed-off-by: Evgenii Stratonikov <fyfyrchik@runbox.com>
2023-12-29 10:50:39 +03:00
Ekaterina Pavlova
4c6dca876c rpcclient: move Waiter to a separate package
There are use-cases when not only Actor, but also Invoker and even
simple RPC client must wait (e.g. sendtx or dumptx CLI commands). Actor
requires optional signers in constructor, and it's not always
appropriate to create Actor only to be able to use Waiter, sometimes
it's needed to use only Waiter without Actor.

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
2023-12-28 15:30:15 +03:00
Ekaterina Pavlova
28f1beff64 rpcclient: export NewWaiter function
Change first argument of NewWaiter to be able to directly accept RPC
Client and export for external usage.

Refs #3244.

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
2023-12-28 15:30:15 +03:00
Ekaterina Pavlova
cc06674253 neorpc: add WS notification filter IsValid functionality
Additional check of filters parameters added for filter validation.

Closes #3241.

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
2023-12-28 11:08:46 +03:00
Ekaterina Pavlova
275e814271 rpc: change the type of BlockFilter.Primary from int to byte
BlockFilter has PrinaryIndex of int type while block.Block structure
itself has PrimaryIndex of byte. It's needed to prevent changing
filters field type and all associated subscriptions logic on
server side.

Refs #3241.

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
2023-12-25 18:24:06 +03:00