Commit graph

7939 commits

Author SHA1 Message Date
Roman Khimov
7c356163e2 go.mod: upgrade github.com/consensys/gnark-crypto to v0.13.0
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-09-04 10:49:58 +03:00
Roman Khimov
d47fe392fb
Merge pull request #3567 from nspcc-dev/go-1.22
Go 1.22
2024-09-02 22:32:40 +03:00
Roman Khimov
565f8cfb7a *: fix copyloopvar warnings
Go 1.22+ allows to drop these:

  The copy of the 'for' variable "i" can be deleted (Go 1.22+) (copyloopvar)

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-30 22:02:57 +03:00
Roman Khimov
74cf5cbeae vm: drop *vm.VM parameter of CheckMultisigPar()
It's unused. Maybe we can move it out of VM completely decoupling VM from
crypto.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-30 21:48:27 +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
133cd1dcf8 rpcbinding: use slices.Delete* for element filtering
It's a bit easier this way, loops that change slices aren't fun.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-30 21:35:27 +03:00
Roman Khimov
0fec17d7c0 bqueue: simplify queue flush on Discard()
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-30 21:30:00 +03:00
Roman Khimov
8f45d57612 *: stop using math/rand
Mostly this switches to math/rand/v2, but sometimes randomness is not really needed.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-30 17:00:11 +03:00
Roman Khimov
a50723ff72 *: use cmp.Or where appropriate
It's slightly less efficient (all comparisons are always made), but for
strings/ints it's negligible performance difference, while the code looks a
tiny bit better.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-30 17:00:11 +03:00
Roman Khimov
357bc76882 *: use slices.Concat where appropriate
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-30 17:00:11 +03:00
Roman Khimov
d5b7fc54e7 manifest: deduplicate test logic a bit with slices.Concat
LIkely it's more readable this way.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-30 17:00:11 +03:00
Roman Khimov
dfcff64acb go.mod: update to Go 1.22+
This also changes workflows to test 1.22 and 1.23 only (refs. https://github.com/nspcc-dev/.github/issues/30).
Fixes #3310.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-30 17:00:11 +03:00
Anna Shaleva
ff979e7ad2
Merge pull request #3563 from nspcc-dev/go-1.21
Go 1.21
2024-08-30 16:24:11 +05:00
Roman Khimov
8bececb511 go.mod: update github.com/consensys/gnark to v0.10.0
Fixes a security issue, https://github.com/Consensys/gnark/issues/897

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 15:40:49 +03:00
Roman Khimov
c07604fbf3 notary: simplify key presence check with slices
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 12:51:12 +03:00
Roman Khimov
8925b42250 golangci.yml: replace outdated linter
level=warning msg="The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar."

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 12:51:12 +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
97506fb48d keys: rework nep-2/wif encoding without bytes.Buffer
It doesn't make any sense here and the length check was just a dead code.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 12:29:44 +03:00
Roman Khimov
9bc67f9da6 keys: mute elliptic.Marshal deprecation warning
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 12:29:44 +03:00
Roman Khimov
b4e4567c2b *: don't use CompareTo name for three-way comparison functions
"Compare" is almost a standard one now, although math/big uses Cmp for historic
reasons (keys.PublicKey does so too). This also fixes Fixed8 since int64 to int
conversion is lossy.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 12:29:44 +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
6581bd47fc interop: simplify code with slices.Insert
It's not performance-critical for sure.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 12:29:44 +03:00
Roman Khimov
a0553f740d statesync: simplify Pool management code
* use slices.BinarySearchFunc with its boolean status
* use slices.Insert/slices.Delete, tnis can be a little less efficient, but it
  frees the memory faster and this code is more I/O (networking) bound to care
  about 1-3%

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 12:29:44 +03:00
Roman Khimov
5431b31d84 core: fix extensible sender check
Looks like it was wrong since 9592f3e052 because
sort.Search can return an index that is not equal to the target.
slices.BinarySearchFunc can do that too, but it also return a very convenient
boolean status that can be used.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 12:29:44 +03:00
Roman Khimov
74acfe5288 network: rework insertion into sorting in tryInitStateSync
Overall this'd be less operations and less allocations.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 12:29:44 +03:00
Roman Khimov
49438798b5 manifest: deduplicate duplicate-checking code
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
db820cb0dc manifest: rework method duplicate check
Don't use an additional type, it's inconvenient and this method is not
performance-critical.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
7f1690a840 manifest: use slices.SortFunc, deduplicate PermissionDesc code
Simplify Less and Equals, fix Equals as well for PermissionWildcard (it was
reporting false erroneously).

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
e0cf47e6d0 consensus: don't do useless key sorting
They're already sorted out of smartcontract.CreateMultiSigRedeemScript().

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
32e3310205 smartcontract: improve CreateMultiSigRedeemScript documentation
It was always like that, but this important aspect was never documented.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +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
d40ccb3e57 util: add Compare to Uint160
It's useful for slices-based sorting/finding.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
dda3d8b284 mempool: add some comments on potential slices.* use
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
a30792dbb6 *: use slices.Index/slices.Contains where appropriate
This doesn't touch performance-sensitive parts, but simplifies a lot of code.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
9cce148d83 *: use maps.Equal/slices.Equal where appropriate
Testing for equality has never been easier.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
93ecd61079 stackitem: microoptimize memory management of Make()
Preallocate as much as needed.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
e8a86e617b transaction: microoptimize multiattribute check
We can't have more than 256 attribute types, so allocate and use 32 bytes
instead of a whole map.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
f15a163cdf rpcsrv: deduplicate RunForErrors code
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
d22bdd8369 rpcsrv: microoptimize result allocation
We know the size.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
aefd0da181 payload: deduplicate test code slightly
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-24 22:41:48 +03:00
Roman Khimov
35d5495d39 wallet: simplify signature handling
Don't use an additional buffer, drop one branch.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-24 22:41:48 +03:00
Roman Khimov
9e112fc024 *: use slices.Clone instead of make/copy
It's much easier this way.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-24 22:41:48 +03:00
Roman Khimov
7243754a0d *: drop open-coded slice reversing
Less code, same performance.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-24 22:41:48 +03:00
Roman Khimov
c7b623cc38 *: drop pkg/util/slice, use slices.Reverse
This also removes bigint.FromBytesUnsigned(), it's not used very often and
it's somewhat misleading in the bigint package (which is supposed to use a
very specific enconding).

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-24 22:41:48 +03:00
Roman Khimov
963e22ea95 *: replace slice.Clean() with clear()
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-24 22:41:48 +03:00
Roman Khimov
d9ee31fb52 *: use clear() to clear maps
Supposedly more efficient since we can avoid some memory management dances.

Memory pool agrees:

goos: linux
goarch: amd64
pkg: github.com/nspcc-dev/neo-go/pkg/core/mempool
cpu: AMD Ryzen 7 PRO 7840U w/ Radeon 780M Graphics
                       │  pool.old   │              pool.new               │
                       │   sec/op    │   sec/op     vs base                │
Pool/one,_incr_fee-16    12.44m ± 1%   12.51m ± 1%   +0.55% (p=0.029 n=10)
Pool/many,_same_fee-16   4.960m ± 2%   3.100m ± 1%  -37.50% (p=0.000 n=10)
Pool/many,_incr_fee-16   16.03m ± 2%   14.11m ± 1%  -12.00% (p=0.000 n=10)
Pool/one,_same_fee-16                  1.742m ± 1%
geomean                  9.964m        5.556m       -17.92%

                       │    pool.old     │                pool.new                │
                       │      B/op       │      B/op       vs base                │
Pool/one,_incr_fee-16     8.117Ki ± 120%   7.101Ki ± 128%  -12.52% (p=0.022 n=10)
Pool/many,_same_fee-16   3941.2Ki ±   0%   805.4Ki ±   0%  -79.56% (p=0.000 n=10)
Pool/many,_incr_fee-16   3936.2Ki ±   0%   829.8Ki ±   0%  -78.92% (p=0.000 n=10)
Pool/one,_same_fee-16                      12.98Ki ±  10%
geomean                   501.2Ki          88.59Ki         -66.47%

                       │   pool.old   │               pool.new               │
                       │  allocs/op   │  allocs/op    vs base                │
Pool/one,_incr_fee-16     28.00 ± 21%    24.00 ± 21%  -14.29% (p=0.002 n=10)
Pool/many,_same_fee-16   40.38k ±  0%   40.03k ±  0%   -0.86% (p=0.000 n=10)
Pool/many,_incr_fee-16   40.38k ±  0%   40.04k ±  0%   -0.85% (p=0.000 n=10)
Pool/one,_same_fee-16                    23.00 ±  4%
geomean                  3.574k          969.8         -5.55%

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-24 22:41:48 +03:00
Roman Khimov
c2a374541f mempool: add a simple benchmark
Can't believe we never had any in code.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-24 22:41:05 +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
Roman Khimov
f21edef43b *: bump min Go to 1.21, use 1.23 by default
Fixes #3089.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-23 19:11:06 +03:00
Anna Shaleva
dc6c195637
Merge pull request #3462 from NeoGoBros/add-coverage-support
Add initial coverage support to neotest
2024-08-21 11:40:16 +03:00