Commit graph

136 commits

Author SHA1 Message Date
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
Anna Shaleva
dc8b2f639a dao: do not remove block executable by conflict record stub
It's possible for transaction to include block hash into Conflicts
attribure. If so, then we must not remove block executable record while
cleaning transation's conflict records.

This commit is a direct consequence of
e6ceee0f230a21c87006a9297636be29c0d8ea47. Ref. #3427.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-05-16 12:13:41 +03:00
Anna Shaleva
2ad4c86712 dao: move conflict record value length to a separate const
Conflicts-related code contains more and more these magic numbers, and
there's no good in it even if all the usages are commented. This
approach produces bugs like #3426.

No functional changes, just a refactoring.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-05-16 12:13:41 +03:00
Anna Shaleva
9a1075d332 dao: fix transaction application log decoding
Conflict record stub has value of 5 bytes length: 1 byte for
storage.ExecTransaction prefix and 4 bytes for the block index LE. This
scheme was implemented in #3138, and this commit should be a part of
this PR.

Also, transaction.DummyVersion is removed since it's unused anymore.

Close #3426. The reason of `failed to locate application log: EOF` error
during genesis AER request is in the following: genesis executable was
overwritten by conflict record stub produced by transaction
0x289c235dcdab8be7426d05f0fbb5e86c619f81481ea136493fa95deee5dbb7cc (ref.
 #3427). As a consequence, an attempt to decode transaction AER was
initited, but conflict record scheme was changed in #3138.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-05-16 12:13:41 +03:00
Anna Shaleva
58a086ea91 core: allow transaction to conflict with block
Transaction
0x289c235dcdab8be7426d05f0fbb5e86c619f81481ea136493fa95deee5dbb7cc is
already on mainnet at block 5272006 and we can't do anything with it.
This transaction has genesis block hash in Conflicts attribute. It leads
to the following consequences:
1. Genesis block executable record is overwritten by conflict record
   stub. Genesis block can't be retrieved anymore. This bug is described
   in #3427.
2. Somehow this transaction has passed verification on NeoGo CN without
   any warnings:
```
Apr 24 16:12:30 kangra neo-go[2453907]: 2024-04-24T16:12:30.865+0300        INFO        initializing dbft        {"height": 5272006, "view": 0, "index": 6, "role": "Backup"}
Apr 24 16:12:31 kangra neo-go[2453907]: 2024-04-24T16:12:31.245+0300        INFO        persisted to disk        {"blocks": 1, "keys": 37, "headerHeight": 5272005, "blockHeight": 5272005, "took": "14.548903ms"}
Apr 24 16:12:34 kangra neo-go[2453907]: 2024-04-24T16:12:34.977+0300        ERROR        can't add SV-signed state root        {"error": "stateroot mismatch at block 5272005: 9d5f95784f26c862d6f889f213aad1e3330611880c02330e88db8802c750aa46 vs d25304d518645df725014897d13bbf023919928e79074abcea48f31cf9f32a25"}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.820+0300        INFO        received PrepareRequest        {"validator": 5, "tx": 1}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.821+0300        INFO        sending PrepareResponse        {"height": 5272006, "view": 0}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.827+0300        INFO        received PrepareResponse        {"validator": 4}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.830+0300        INFO        received PrepareResponse        {"validator": 3}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.875+0300        INFO        received PrepareResponse        {"validator": 2}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.878+0300        INFO        sending Commit        {"height": 5272006, "view": 0}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.879+0300        INFO        received Commit        {"validator": 4}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.881+0300        INFO        received PrepareResponse        {"validator": 0}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.881+0300        INFO        received Commit        {"validator": 3}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.906+0300        INFO        received Commit        {"validator": 0}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.907+0300        INFO        received PrepareResponse        {"validator": 1}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.915+0300        INFO        received Commit        {"validator": 1}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.915+0300        INFO        approving block        {"height": 5272006, "hash": "6b111519537343ce579d04ccad71c43318b12c680d0f374dfcd466aa22643fb6", "tx_count": 1, "merkle": "ccb7dbe5ee5da93f4936a11e48819f616ce8b5fbf0056d42e78babcd5d239c28", "prev": "12ad6cc5d0cd357b9fc9fb0c1a016ba8014d3cdd5a96818598e6a40a1a4a2a21"}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.917+0300        WARN        contract invocation failed        {"tx": "289c235dcdab8be7426d05f0fbb5e86c619f81481ea136493fa95deee5dbb7cc", "block": 5272006, "error": "at instruction 86 (ASSERT): ASSERT failed"}
Apr 24 16:12:45 kangra neo-go[2453907]: 2024-04-24T16:12:45.950+0300        INFO        initializing dbft        {"height": 5272007, "view": 0, "index": 6, "role": "Primary"}
Apr 24 16:12:46 kangra neo-go[2453907]: 2024-04-24T16:12:46.256+0300        INFO        persisted to disk        {"blocks": 1, "keys": 67, "headerHeight": 5272006, "blockHeight": 5272006, "took": "16.576594ms"}
```
   And thus, we must treat this transaction as valid for this behaviour
   to be reproducable.

This commit contains two fixes:
1. Do not overwrite block executable records by conflict record stubs.
   If some transaction conflicts with block, then just skip the conflict
   record stub for this attribute since it's impossible to create
   transaction with the same hash.
2. Do not fail verification for those transactions that have Conflicts
   attribute with block hash inside. This one is controversial, but we
   have to adjust this code to treat already accepted transaction as
   valid.

Close #3427.

The transaction itself:
```
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : {
      "attributes" : [
         {
            "height" : 0,
            "type" : "NotValidBefore"
         },
         {
            "hash" : "0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15",
            "type" : "Conflicts"
         }
      ],
      "blockhash" : "0xb63f6422aa66d4fc4d370f0d682cb11833c471adcc049d57ce4373531915116b",
      "blocktime" : 1713964365700,
      "confirmations" : 108335,
      "hash" : "0x289c235dcdab8be7426d05f0fbb5e86c619f81481ea136493fa95deee5dbb7cc",
      "netfee" : "237904",
      "nonce" : 0,
      "script" : "CxAMFIPvkoyXujYCRmgq9qEfMJQ4wNveDBSD75KMl7o2AkZoKvahHzCUOMDb3hTAHwwIdHJhbnNmZXIMFPVj6kC8KD1NDgXEjqMFs/Kgc0DvQWJ9W1I5",
      "sender" : "NbcGB1tBEGM5MfhNbDAimvpJKzvVjLQ3jW",
      "signers" : [
         {
            "account" : "0x649ca095e38a790d6c15ff78e0c6175099b428ac",
            "scopes" : "None"
         },
         {
            "account" : "0xdedbc03894301fa1f62a68460236ba978c92ef83",
            "scopes" : "None"
         }
      ],
      "size" : 412,
      "sysfee" : "997778",
      "validuntilblock" : 5277629,
      "version" : 0,
      "vmstate" : "FAULT",
      "witnesses" : [
         {
            "invocation" : "DECw8XNuyRg5vPeHxisQXlZ7VYNDxxK4xEm8zwpPyWJSSu+JaRKQxdrlPkXxXj34wc4ZSrZvKICGgPFE0ZHXhLPo",
            "verification" : "DCEC+PI2tRSlp0wGwnjRuQdWdI0tBXNS7SlzSBBHFsaKUsdBVuezJw=="
         },
         {
            "invocation" : "DEAxwi97t+rg9RsccOUzdJTJK7idbR7uUqQp0/0/ob9FbuW/tFius3/FOi82PDZtwdhk7s7KiNM/pU7vZLsgIbM0",
            "verification" : "DCEDbInkzF5llzmgljE4HSMvtrNgPaz73XO5wgVJXLHNLXRBVuezJw=="
         }
      ]
   }
}
```

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-05-16 12:13:41 +03:00
Anna Shaleva
8162e9033d *: replace slice.Copy with bytes.Clone
And refactor some code a bit, don't use bytes.Clone where type-specific
helpers may be used instead.

Close #2907.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-03-05 13:54:10 +03:00
Pavel Karpy
62b710868b *: mention prefix trimming in Seek operations where applicable
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
2023-11-23 18:44:19 +03:00
Anna Shaleva
91c8aa21cc core: fix typo in comment
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-11-02 17:15:34 +03:00
Anna Shaleva
241d5f593e *: use methods of binary.AppendByteOrder where applicable
We often use binary.PutUint*, but almost all these cases have preallocated
buffer of the size that matches exactly the desired one and use a single or
a couple of calls to PutUint*. Thus, I don't think that replacing
binary.PutUint* by AppendUint* will make things better for all these usages.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-10-12 17:59:42 +03:00
Anna Shaleva
32bfed4741 core: improve conflict records storage scheme
Implement the https://github.com/neo-project/neo/issues/2907#issuecomment-1722506014
and port a part of https://github.com/neo-project/neo/pull/2913.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-10-10 17:34:27 +03:00
Roman Khimov
fff7e91709 dao: simplify NewSimple()
We no longer need P2PSigExtension flag here, conflicts attribute is a part
of the normal protocol.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2023-09-04 16:56:59 +03:00
Anna Shaleva
f3c1283ac6 *: move NVB and Conflicts attributes out of extensions
They're a part of the regular protocol now.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2023-09-04 16:39:44 +03:00
Anna Shaleva
ee4b8f883b core: check signers of on-chained conflict during new tx verification
During new transaction verification if there's an on-chain conflicting
transaction, we should check the signers of this conflicting transaction.
If the signers intersect with signers of the incoming transaction, then
the conflict is treated as valid and verification for new incoming
transaction should fail. Otherwise, the conflict is treated as the
malicious attack attempt and will not be taken into account;
verification for the new incoming transaction should continue.

This commint implements the scheme described at
https://github.com/neo-project/neo/pull/2818#issuecomment-1632972055,
thanks to @shargon for digging.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-07-21 17:27:47 +03:00
Roman Khimov
433275265f *: use require.ErrorIs instead of require.True(t, error.Is())
This is just a much better way to do the same thing. Inspired by
nspcc-dev/neofs-sdk-go#407.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2023-05-04 17:03:47 +03:00
ZhangTao1596
d36df15878 ci: fix lint issues (fix #2948) 2023-03-29 11:19:23 +08:00
Roman Khimov
1c4c783c3a core: store magic in the DB version, fix #2847 2023-01-11 12:05:05 +03:00
Roman Khimov
4a626f505e core: drop old STContractID data
We have it in the ContractManagement now.
2022-12-02 10:54:45 +03:00
Roman Khimov
1c38b45074 core: don't always store all hashes in memory
We're paging these hashes, so we need a previous full page and a current one
plus some cache for various requests. Storing 1M of hashes is 32M of memory
and it grows quickly. It also seriously affects node startup time, most of
what it's doing is reading these hashes, the longer the chain the more time it
needs to do that.

Notice that this doesn't change the underlying DB scheme in any way.
2022-11-25 14:30:51 +03:00
Anna Shaleva
d67f0df516 core: reset block headers together with header height info
We need to keep the headers information consistent with header batches
and headers. This comit fixes the bug with failing blockchain
initialization on recovering from state reset interrupted after the
second stage (blocks/txs/AERs removal):
```
anna@kiwi:~/Documents/GitProjects/nspcc-dev/neo-go$ ./bin/neo-go db reset -t --height 83000
2022-11-20T16:28:29.437+0300	INFO	MaxValidUntilBlockIncrement is not set or wrong, using default value	{"MaxValidUntilBlockIncrement": 5760}
2022-11-20T16:28:29.440+0300	INFO	restoring blockchain	{"version": "0.2.6"}
failed to create Blockchain instance: could not initialize blockchain: could not get header 1898cd356a4a2688ed1c6c7ba1fd6ba7d516959d8add3f8dd26232474d4539bd: key not found
```
2022-11-22 11:53:39 +03:00
Anna Shaleva
bd6bb9e9e2 core: allow to reset blockchain state 2022-11-10 18:08:17 +03:00
Roman Khimov
97193cf337 golangci: add predeclared linter
These can be confusing.
2022-09-02 18:36:26 +03:00
Roman Khimov
4f3ffe7290 golangci: enable errorlint and fix everything it found 2022-09-02 18:36:23 +03:00
Roman Khimov
8cd7b93208 limits: new package with storage limits
Packages like core/state or core/mpt shouldn't import whole core/storage just
to get some constant value, it's not a good dependency.
2022-07-08 23:30:30 +03:00
Roman Khimov
9a06995460 bigint: don't allocate in ToPreallocatedBytes
Turns out, it's almost always allocating because we're mostly dealing with
small integers while the buffer size is calculated in 8-byte chunks here, so
preallocated buffer is always insufficient.

name                   old time/op    new time/op    delta
ToPreallocatedBytes-8    28.5ns ± 7%    19.7ns ± 5%   -30.72%  (p=0.000 n=10+10)

name                   old alloc/op   new alloc/op   delta
ToPreallocatedBytes-8     16.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)

name                   old allocs/op  new allocs/op  delta
ToPreallocatedBytes-8      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)

Fix StorageItem reuse at the same time. We don't copy when getting values from
the storage, but we don when we're putting them, so buffer reuse could corrupt
old values.
2022-06-02 15:38:39 +03:00
Roman Khimov
c3d989ebda stackitem: reusable serialization context
We serialize items a lot and this allows to avoid a number of allocations.
2022-06-02 15:38:39 +03:00
Anna Shaleva
a427411a57 core: fix race during native cache persist
Fixes the following race:
```
2022-05-06T06:51:33.3980029Z WARNING: DATA RACE
2022-05-06T06:51:33.3980178Z Read at 0x00c0007e02a0 by goroutine 96:
2022-05-06T06:51:33.3980338Z   runtime.mapaccess2_fast32()
2022-05-06T06:51:33.3980863Z       /opt/hostedtoolcache/go/1.17.9/x64/src/runtime/map_fast32.go:52 +0x0
2022-05-06T06:51:33.3981249Z   github.com/nspcc-dev/neo-go/pkg/core/dao.(*Simple).getCache()
2022-05-06T06:51:33.3982707Z       /home/runner/work/neo-go/neo-go/pkg/core/dao/dao.go:905 +0x64
2022-05-06T06:51:33.3983443Z   github.com/nspcc-dev/neo-go/pkg/core/dao.(*Simple).GetROCache()
2022-05-06T06:51:33.3983900Z       /home/runner/work/neo-go/neo-go/pkg/core/dao/dao.go:889 +0xd4
2022-05-06T06:51:33.3984231Z   github.com/nspcc-dev/neo-go/pkg/core/dao.(*Simple).getCache()
2022-05-06T06:51:33.3984869Z       /home/runner/work/neo-go/neo-go/pkg/core/dao/dao.go:913 +0x196
2022-05-06T06:51:33.3985254Z   github.com/nspcc-dev/neo-go/pkg/core/dao.(*Simple).GetROCache()
2022-05-06T06:51:33.3985756Z       /home/runner/work/neo-go/neo-go/pkg/core/dao/dao.go:889 +0xd4
2022-05-06T06:51:33.3986167Z   github.com/nspcc-dev/neo-go/pkg/core/native.(*Policy).isBlockedInternal()
2022-05-06T06:51:33.3986824Z       /home/runner/work/neo-go/neo-go/pkg/core/native/policy.go:258 +0x6a
2022-05-06T06:51:33.3987264Z   github.com/nspcc-dev/neo-go/pkg/core/native.(*Policy).IsBlocked()
2022-05-06T06:51:33.3987743Z       /home/runner/work/neo-go/neo-go/pkg/core/native/policy.go:250 +0x2f7
2022-05-06T06:51:33.3988155Z   github.com/nspcc-dev/neo-go/pkg/core/native.(*NEO).getAllCandidatesCall.func1()
2022-05-06T06:51:33.3988645Z       /home/runner/work/neo-go/neo-go/pkg/core/native/native_neo.go:948 +0x109
2022-05-06T06:51:33.3989053Z   github.com/nspcc-dev/neo-go/pkg/core/native.(*NEO).getAllCandidatesCall.func2()
2022-05-06T06:51:33.3989550Z       /home/runner/work/neo-go/neo-go/pkg/core/native/native_neo.go:959 +0x137
2022-05-06T06:51:33.3989561Z
2022-05-06T06:51:33.3989735Z Previous write at 0x00c0007e02a0 by goroutine 40:
2022-05-06T06:51:33.3989891Z   runtime.mapassign_fast32()
2022-05-06T06:51:33.3990260Z       /opt/hostedtoolcache/go/1.17.9/x64/src/runtime/map_fast32.go:92 +0x0
2022-05-06T06:51:33.3990640Z   github.com/nspcc-dev/neo-go/pkg/core/dao.(*Simple).persistNativeCache()
2022-05-06T06:51:33.3991084Z       /home/runner/work/neo-go/neo-go/pkg/core/dao/dao.go:876 +0x12d
2022-05-06T06:51:33.3991411Z   github.com/nspcc-dev/neo-go/pkg/core/dao.(*Simple).Persist()
2022-05-06T06:51:33.3991852Z       /home/runner/work/neo-go/neo-go/pkg/core/dao/dao.go:850 +0x1d4
2022-05-06T06:51:33.3992186Z   github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).runPersist()
2022-05-06T06:51:33.3992650Z       /home/runner/work/neo-go/neo-go/pkg/core/blockchain.go:1285 +0x28a
2022-05-06T06:51:33.3992971Z   github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).storeBlock()
2022-05-06T06:51:33.3993845Z       /home/runner/work/neo-go/neo-go/pkg/core/blockchain.go:1143 +0x1b9c
2022-05-06T06:51:33.3994241Z   github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).AddBlock()
2022-05-06T06:51:33.3994707Z       /home/runner/work/neo-go/neo-go/pkg/core/blockchain.go:910 +0x791
2022-05-06T06:51:33.3995053Z   github.com/nspcc-dev/neo-go/pkg/neotest.(*Executor).AddNewBlock()
2022-05-06T06:51:33.3995492Z       /home/runner/work/neo-go/neo-go/pkg/neotest/basic.go:334 +0xa7
2022-05-06T06:51:33.3995842Z   github.com/nspcc-dev/neo-go/pkg/neotest.(*Executor).InvokeScript()
2022-05-06T06:51:33.3996288Z       /home/runner/work/neo-go/neo-go/pkg/neotest/basic.go:178 +0x169
2022-05-06T06:51:33.3996725Z   github.com/nspcc-dev/neo-go/pkg/core/native/native_test_test.TestNEO_GetCandidates.func2()
2022-05-06T06:51:33.3997253Z       /home/runner/work/neo-go/neo-go/pkg/core/native/native_test/neo_test.go:549 +0x4cb
2022-05-06T06:51:33.3997672Z   github.com/nspcc-dev/neo-go/pkg/core/native/native_test_test.TestNEO_GetCandidates()
2022-05-06T06:51:33.3998404Z       /home/runner/work/neo-go/neo-go/pkg/core/native/native_test/neo_test.go:574 +0x2103
2022-05-06T06:51:33.3998751Z   github.com/nspcc-dev/neo-go/pkg/neotest.(*Executor).AddNewBlock()
2022-05-06T06:51:33.3999193Z       /home/runner/work/neo-go/neo-go/pkg/neotest/basic.go:334 +0xa7
2022-05-06T06:51:33.3999541Z   github.com/nspcc-dev/neo-go/pkg/neotest.(*Executor).InvokeScript()
2022-05-06T06:51:33.3999988Z       /home/runner/work/neo-go/neo-go/pkg/neotest/basic.go:178 +0x169
2022-05-06T06:51:33.4000305Z   github.com/nspcc-dev/neo-go/pkg/neotest.AddSystemFee()
2022-05-06T06:51:33.4000733Z       /home/runner/work/neo-go/neo-go/pkg/neotest/basic.go:291 +0x85
2022-05-06T06:51:33.4001062Z   github.com/nspcc-dev/neo-go/pkg/neotest.(*Executor).SignTx()
2022-05-06T06:51:33.4001509Z       /home/runner/work/neo-go/neo-go/pkg/neotest/basic.go:111 +0x109
2022-05-06T06:51:33.4001885Z   github.com/nspcc-dev/neo-go/pkg/neotest.(*Executor).PrepareInvocation()
2022-05-06T06:51:33.4002435Z       /home/runner/work/neo-go/neo-go/pkg/neotest/basic.go:191 +0x1b2
2022-05-06T06:51:33.4002808Z   github.com/nspcc-dev/neo-go/pkg/neotest.(*Executor).InvokeScript()
2022-05-06T06:51:33.4003249Z       /home/runner/work/neo-go/neo-go/pkg/neotest/basic.go:177 +0xed
2022-05-06T06:51:33.4003685Z   github.com/nspcc-dev/neo-go/pkg/core/native/native_test_test.TestNEO_GetCandidates.func2()
2022-05-06T06:51:33.4004216Z       /home/runner/work/neo-go/neo-go/pkg/core/native/native_test/neo_test.go:549 +0x4cb
2022-05-06T06:51:33.4004634Z   github.com/nspcc-dev/neo-go/pkg/core/native/native_test_test.TestNEO_GetCandidates()
2022-05-06T06:51:33.4005165Z       /home/runner/work/neo-go/neo-go/pkg/core/native/native_test/neo_test.go:558 +0x1bbb
2022-05-06T06:51:33.4005298Z   testing.tRunner()
2022-05-06T06:51:33.4005674Z       /opt/hostedtoolcache/go/1.17.9/x64/src/testing/testing.go:1259 +0x22f
2022-05-06T06:51:33.4005916Z   testing.(*T).Run·dwrap·21()
2022-05-06T06:51:33.4006298Z       /opt/hostedtoolcache/go/1.17.9/x64/src/testing/testing.go:1306 +0x47
...
```
2022-05-06 13:46:17 +03:00
Elizaveta Chichindaeva
28908aa3cf [#2442] English Check
Signed-off-by: Elizaveta Chichindaeva <elizaveta@nspcc.ru>
2022-05-04 19:48:27 +03:00
Anna Shaleva
a6a0c1eb12 core: avoid lock copy in private DAO constructor
Fix the following linter warning:
```
pkg/core/dao/dao.go:101:7  govet  copylocks: assignment copies lock value to *d: github.com/nspcc-dev/neo-go/pkg/core/dao.Simple contains sync.RWMutex
```
2022-04-29 16:10:04 +03:00
Anna Shaleva
8d2d48f360 core: move native cache from MemCachedStore to DAO 2022-04-29 16:10:04 +03:00
Anna Shaleva
4254407a9b dao: add GetTxExecResult method 2022-04-05 10:36:50 +03:00
Anna Shaleva
18c5f638b9 dao: adjust usages of Internal DB inconsistency error 2022-04-04 19:16:58 +03:00
Anna Shaleva
6343720adf dao: return ErrKeyNotFound from GetAppExecResults for dummy txs
Otherwise decoding error may be returned which can be misleading.
2022-04-04 12:49:52 +03:00
Roman Khimov
c12a3b71d4 dao: drop GetStorageItems* APIs
They're just adding another useless caching layer to the Seek.
2022-03-31 19:18:51 +03:00
Roman Khimov
5616585697 block/dao: simplify trimming, avoid allocations
The only user of (*Block).Trim() is in DAO and it already has a nice buffer
usually, so creating another one makes no sense. It also simplifies error
handling a lot.
2022-03-18 10:49:25 +03:00
Anna Shaleva
9adcefc2ef core: gracefully wrap Seek error if failed to retrieve header hases 2022-02-28 18:49:18 +03:00
Roman Khimov
7d6f087337 storage: drop (KeyPrefix).Bytes() API
It allocates and most of the time we can avoid that.
2022-02-18 15:19:57 +03:00
Roman Khimov
7223caf369 dao: improve PutCurrentHeader logic
Move serialization out of the core.
2022-02-18 15:05:25 +03:00
Roman Khimov
d2db58d748 dao: move header hash store logic out of the core
Which allows for more efficient buffer use along the way.
2022-02-18 14:54:05 +03:00
Roman Khimov
de2579ec07 dao: put contract IDs into keys using big endianness
We don't have a need to iterate over them at the moment, but since we're
changing the DB format in the next release anyway let's add this ability also,
just in case.
2022-02-18 14:38:51 +03:00
Roman Khimov
600da6909c storage: put uint32 into keys using in big endianness
Which allows to iterate over the contents easily.
2022-02-18 14:35:17 +03:00
Roman Khimov
1ca918e631 dao: delay buffer creation until it's needed
Verification contexts don't ever touch the storage, so these allocations can
be avoided for them.
2022-02-18 14:24:45 +03:00
Roman Khimov
e864768c88 dao: simplify NewPrivate 2022-02-18 14:18:56 +03:00
Roman Khimov
b60d4ff191 dao: deduplicate header->KV conversion 2022-02-18 14:12:44 +03:00
Roman Khimov
d8cf879499 dao: deduplicate DeleteBlock, no functional changes 2022-02-18 14:12:44 +03:00
Roman Khimov
f80680187e storage: expose private storage map for more efficient MPT batch
It couldn't be done previously with two maps and mixed storage, but now all of
the storage changes are located in a single map, so it's trivial to do exact
slice allocations and avoid string->[]byte conversions.
2022-02-17 23:41:10 +03:00
Roman Khimov
7dc8fc443f dao: simplify buffer management for private DAO
Private DAO is only used in a single thread which means we can safely reuse
key/data buffers most of the time and handle it all in DAO.

Doesn't affect any benchmarks.
2022-02-17 22:27:39 +03:00
Roman Khimov
9bfb3357f2 storage: add "private" mode to MemCachedStore
Most of the time we don't need locking on the higher-level stores and we drop
them after Persist, so that's what private MemCachedStore is for.

It doesn't improve things in any noticeable way, some ~1% can be observed in
neo-bench under various loads and even less than that in chain processing. But
it seems to be a bit better anyway (less allocations, less locks).
2022-02-17 22:27:39 +03:00
Roman Khimov
aefb26255a dao: drop DAO interface
It's a remnant from the days when we had Simple and Cached DAO
implementations, now it makes zero sense.
2022-02-16 18:24:20 +03:00
Roman Khimov
9d2ef775cf storage: simplify (*MemCachedStore).Put/Delete interface
They never return errors, so their interface should reflect that. This allows
to remove quite a lot of useless and never tested code.

Notice that Get still does return an error. It can be made not to do that, but
usually we need to differentiate between successful/unsuccessful accesses
anyway, so this doesn't help much.
2022-02-16 18:24:20 +03:00
Roman Khimov
017795c9c1 storage: completely remove MemoryBatch
If you need something like that, just wrap another MemCachedStore layer around
it.
2022-02-16 16:13:12 +03:00