Commit graph

839 commits

Author SHA1 Message Date
Roman Khimov
4ae18e8ffc block: check for Transaction length before messing with txes
Fixes panic two lines below. Blocks without transactions are invalid by
definition, so there is a need to adjust tests accordingly.
2019-10-01 13:41:26 +03:00
Roman Khimov
c3591d8897 vm: fix CHECKMULTISIG to comply with NEO VM implementation
Testing with testnet quickly revealed that our code has an issue when the key
count doesn't equal signature count, fix it and add some comments.
2019-10-01 13:41:26 +03:00
Roman Khimov
fac778d3dd
Merge pull request #414 from nspcc-dev/persistence-rewamp
What started as an attempt to fix #366 ended up being quite substantial refactoring of the Blockchain->Store and Server->Blockchain interactions. As usually, some additional problems were noted and fixed along the way. It also accidentally fixes #410.
2019-09-27 17:55:43 +03:00
Roman Khimov
7779ad6c28 storage: always return ErrKeyNotFound when key is not found
It was true for MemoryStore and BoltDB, but not for LevelDB and Redis.
2019-09-27 15:42:36 +03:00
Roman Khimov
5ff1399d54 storage: unexport MemoryStore mutex
It shouldn't be available from outside.
2019-09-27 15:42:36 +03:00
Roman Khimov
9617a6f9e9 network: fix requestBlocks() for (headers == blocks + 1)
In the very specific case when the list of headers received is exactly one
block ahead of the chain of full blocks requestBlocks() failed to generate
request to get the next full block.
2019-09-27 15:42:35 +03:00
Roman Khimov
3c40a53c4d core: no need to Close() Blockchain in tests
It's a Store method actually and for every Blockchain that uses Run() the
Close() will be handled automatically on exit because of context magic.
2019-09-27 15:42:35 +03:00
Roman Khimov
0dbdbb9c2a storage: remove RedisBatch in favor of MemoryBatch
They're also almost the same.
2019-09-27 15:42:35 +03:00
Roman Khimov
af557cea19 storage: deduplicate BoltDBBatch/MemoryBatch
BoltDB doesn't have internal batching mechanism, thus we have a substitute for
it, but this substitute is absolutely identical to MemoryBatch, so it's better
to unify them and import ac5d2f94d3 fix into the
MemoryBatch.
2019-09-27 15:42:35 +03:00
Roman Khimov
8bf37f45fc storage: remove impossible error branch from MemoryStore
MemoryStore is always successful, so this branch makes no sense.
2019-09-27 15:42:35 +03:00
Roman Khimov
4a732d97ac storage: add comments about errors from MemoryStore
It never returns errors for some operations and this knowledge can be used by
other code.
2019-09-27 15:42:35 +03:00
Roman Khimov
920d7c610c core: remove blockCache, use MemoryStore, redesign persist()
Commit 578ac414d4 was wrong in that it saved
only a part of the block, so depending on how you use blockchain, you may
still see that the block was not really processed properly. To really fix it
this commit introduces intermediate storage layer in form of memStore, which
actually is a MemoryStore that supports full Store API (thus easily fitting
into the existing code) and one extension that allows it to flush its data to
some other Store.

It also changes AddBlock() semantics in that it only accepts now successive
blocks, but when it does it guarantees that they're properly added into the
Blockchain and can be referred to in any way. Pending block queing is now
moved into the server (see 8c0c055ac657813fe3ed10257bce199e9527d5ed).

So the only thing done with persist() now is just a move from memStore to
Store which probably should've always been the case (notice also that
previously headers and some other metadata was written into the Store
bypassing caching/batching mechanism thus leading to some inefficiency).
2019-09-27 15:42:35 +03:00
Roman Khimov
c531dc0bde network: add block queue
This one will replace blockCache in Blockchain itself as it can and should be
external from it. The idea is that we only feed successive blocks into the
Blockchain and it only stores valid proper Blockchain and nothing else.
2019-09-27 13:00:09 +03:00
Roman Khimov
ab8d9c59d6
Merge pull request #412 from nspcc-dev/feature/map
VM: implement maps, closes #359.
2019-09-25 19:00:26 +03:00
Evgenii Stratonikov
c7c4291774 vm: simplify APPEND implementation a bit 2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
13d7770c68 vm: support Map in ARRAYSIZE
Also make logic the same as in reference implementation
and add tests.
2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
c66f493017 vm: compare Map by reference in EQUAL 2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
c0be2b2a99 vm: support Map in REMOVE 2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
8b6bddca3c vm: support Map in PICKITEM and SETITEM 2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
d7bb50c609 vm: implement VALUES opcode 2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
2da64267b0 vm: implement KEYS opcode 2019-09-25 17:53:34 +03:00
Roman Khimov
903173c991 core: fix deadlock in headers list init
This probably is a problem since adc880d323,
because AddHeaders() uses headersOp channel and its reader is only ran in
Run().
2019-09-25 17:52:46 +03:00
Roman Khimov
578ac414d4 core: make unpersisted blocks/txs available in Blockchain
This changes the Blockchain to also return unpersisted (theoretically, verified
in the AddBlock!) blocks and transactions, making Add/Get interfaces
symmetrical. It allows to turn Persist into internal method again and makes it
possible to enable transaction check in GetBlock(), thus fixing #366.
2019-09-25 17:46:28 +03:00
Evgenii Stratonikov
0fb4bb05cf vm: implement HASKEY opcode 2019-09-25 12:08:41 +03:00
Roman Khimov
c101754c51
Merge pull request #413 from nspcc-dev/rpc-tests-error-handling
rpc: check for error responses in tests
2019-09-24 20:49:16 +03:00
Roman Khimov
2daff0957a rpc: check for error responses in tests
sendrawtransaction_negative was actually wrong in trying to get
SendTXResponse, it received an error.
2019-09-24 18:47:23 +03:00
Evgenii Stratonikov
df18da0ac9 vm: implement NEWMAP opcode 2019-09-24 17:06:17 +03:00
Roman Khimov
dac1f9367c
Merge pull request #411 from nspcc-dev/verifywitnesses-logic
Fixes #269, #368. Tested by RPC sendrawtransaction test.
2019-09-24 14:43:26 +03:00
Roman Khimov
8a457ef540 transaction: add a check for createHash() invocation
It should work in general.
2019-09-24 13:01:54 +03:00
Roman Khimov
679e01bd0f core: implement witness verification logic
Fix #368.
2019-09-24 13:01:54 +03:00
Roman Khimov
ca9c9be71f vm: add CHECKSIG/VERIFY/CHECKMULTISIG implementations
Fix #269.
2019-09-24 13:01:54 +03:00
Roman Khimov
3bbeb2476e vm: introduce HasFailed() method and use it where appropriate
It's gonna be used by external modules.
2019-09-23 20:19:07 +03:00
Roman Khimov
317dc6c5ed
Merge pull request #406 from nspcc-dev/fix/fail-on-first-error
VM: do not pop too many items from stack

JSON tests in neo-vm check stack state even in case of failure.
There are 2 corrections need to be done:

    Pop items in EQUAL one-by-one.
    Do not pop anything from stack in OVER.

I have also implemented operand restriction for SHL/SHR.
2019-09-23 17:54:08 +03:00
Evgenii Stratonikov
3c53beca82 vm: restrict SHL/SHR arguments to -256..256
Also unify SHL/SHR implementation.
2019-09-23 15:13:10 +03:00
Evgenii Stratonikov
4a8be486f0 vm: do not pop items in OVER 2019-09-23 14:54:59 +03:00
Evgenii Stratonikov
7cd69ea8e2 vm: truncate length in SUBSTR
Also fail on first error, without changing the stack.
2019-09-23 14:54:59 +03:00
Roman Khimov
2f9e7ca037
Merge pull request #405 from nspcc-dev/fix/array-reference-type
VM: compare Array by reference and clone structs on append
2019-09-23 14:54:32 +03:00
Evgenii Stratonikov
a88a8e13fc vm: compare Array by reference in EQUAL 2019-09-23 13:25:59 +03:00
Evgenii Stratonikov
99f1d761ca vm: clone Struct on APPEND 2019-09-23 13:25:59 +03:00
Roman Khimov
facf34e821
Merge pull request #409 from nspcc-dev/bolt-sigsegv-logging-fixes
Bolt Put(), sigsegv and logging fixes
2019-09-23 12:56:41 +03:00
Roman Khimov
ac5d2f94d3 storage: fix BoltDB batched Put()
It must copy both the value and the key because they can be reused for other
purposes between Put() and PutBatch(). This actually happens with values in
headers processing, leading to wrong data being written into the DB.

Extend the batch test to check for that.
2019-09-23 09:27:18 +03:00
Roman Khimov
5a0f08f2c0 network: fix SIGSEGV on unknown message acceptance
For example, at the moment our node can't handle `consensus` message, so when
it received it before the patch it just crashed because of uninitialized `p`.
2019-09-22 20:09:55 +03:00
Roman Khimov
4b4bac675b core: don't print persisting errors twice
As they're already printed in the calling goroutine. And they're alse not
always useful when printed by Persist().
2019-09-22 20:08:15 +03:00
Roman Khimov
102c926ef3 core: don't print useless persist messages with nil errors
Errors should be printed only when there are errors.
2019-09-22 20:07:49 +03:00
Vsevolod
b15d9d1c36
Merge pull request #408 from nspcc-dev/unexport-things-from-io
Unexport things from io
2019-09-20 21:24:48 +03:00
Roman Khimov
f69adc59ad io: drop getVarStringSize() completely
After unexport this doesn't make much sense at all as it has just one user.
2019-09-20 20:01:56 +03:00
Roman Khimov
d01b7740e2 io: improve GetVarSize() documentation 2019-09-20 20:00:45 +03:00
Roman Khimov
6dd37dd076 io: unexport getVarIntSize and getVarStringSize
All external users should just use GetVarSize().
2019-09-20 19:08:58 +03:00
Roman Khimov
5e103c7539 CHANGELOG: add one, declare 0.50.0 released 2019-09-19 18:06:42 +03:00
Roman Khimov
5cddfe071b
Merge pull request #403 from nspcc-dev/fix_rpctest
Fix rpctest, fix #353, fix #305.
2019-09-18 23:14:37 +03:00