Commit graph

408 commits

Author SHA1 Message Date
Roman Khimov
782ca64d92 vm: accept uint16 in makeStackItem() 2019-10-15 12:56:25 +03:00
Roman Khimov
78861485b6 storage: simplify MemoryBatch
It's used a lot and it looks a lot like MemoryStore, it just needs not to
return errors from Put and Delete, so make it use MemoryStore internally with
adjusted interface.
2019-10-15 12:56:25 +03:00
Roman Khimov
13bf2618ef storage: improve PutBatch for MemoryStore
Make it look more like a real transaction, put/delete things with a single
lock. Make a copy of value in Put also, just for safety purposes, no one knows
how this value slice can be used after the Put.
2019-10-15 12:56:25 +03:00
Roman Khimov
3ada92944a storage: drop Len from the Batch interface
It's almost meaningless now and we can easily live without it.
2019-10-15 12:56:25 +03:00
Roman Khimov
e111892653 storage: redo DB testing
Make generic tests for all Store implementations, deduplicate tests. Implement
Delete() tests, test Seek() better, add LevelDB tests (finally!).
2019-10-15 12:56:25 +03:00
Roman Khimov
48b6a427cf storage: add Delete method for Batch and Store
It's gonna be used by Storage and Contract interops, both can delete their
data.
2019-10-07 19:40:11 +03:00
Roman Khimov
add9368e9d storage: use strings as keys for memory batch
Using pointers is just plain wrong here, because the batch can be updated with
newer values for the same keys.

Fixes Seek() to use HasPrefix also because this is the intended behavior.
2019-10-07 17:05:53 +03:00
Roman Khimov
dca332f333 vm: use new Context.Next() to properly dump programs
Fix #295, deduplicate code and add `inspect` parameter to the vm command to
dump AVMs (`contract inspect` works with Go code).
2019-10-04 16:13:39 +03:00
Roman Khimov
53a3b18652 vm: completely separate instruction read and execution phases
Make Context.Next() return both opcode and instruction parameter if any. This
simplifies some code and needed to deal with #295.
2019-10-04 16:13:39 +03:00
Roman Khimov
1bf232ad50 vm: introduce TryBool() for Element and use it in VerifyWitnesses
Script can return non-bool results that can still be converted to bool
according to the usual VM rules. Unfortunately Bool() panics if this
conversion fails which is OK for things done in vm.execute(), but certainly
not for VerifyWitnesses(), thus there is a need for TryBool() that will just
return an error in this case.
2019-10-04 16:13:39 +03:00
Roman Khimov
8441b31b4b vm: accept uint32 in makeStackItem()
Interop services routinely push such things (block index, blockchain height)
onto the stack.
2019-10-04 16:13:39 +03:00
Roman Khimov
d62a367900 vm: add Value() method to Element
It gives access to the internal value's Value() which is essential for interop
functions that need to get something from InteropItems. And it also simplifies
some already existing code along the way.
2019-10-04 16:13:39 +03:00
Roman Khimov
0c963875af vm: check for fault flag first in Run()
Switch cases are evaluated sequentially and the fault case is top-priority to
handle.
2019-10-04 16:13:39 +03:00
Roman Khimov
705c7f106f vm: don't panic if there is no result in PopResult()
This function is intended to be ran outside of the execute's panic recovery
mechanism, so it shouldn't panic if there is no result.
2019-10-04 16:13:39 +03:00
Roman Khimov
a357d99624 vm: introduce MaxArraySize constant
This is both for #373 and for interop functions that have to check some
inputs.
2019-10-04 16:13:39 +03:00
Roman Khimov
cfa0c13322 vm: add InteropItem type for interop data
This is an opaque data item that is to be used by the interop functions.
2019-10-04 16:13:39 +03:00
Roman Khimov
da2156f955 vm: add batched RegisterInteropFuncs 2019-10-04 16:13:39 +03:00
Roman Khimov
26e3b6abbe vm: extend interops to contain price
The same way C# node does.
2019-10-04 16:13:39 +03:00
Roman Khimov
ceca9cdb67 core/vm: implement contract storage and script retrieval
Fixes script invocations via the APPCALL instruction. Adjust contract state
field types accordingly.
2019-10-04 16:13:39 +03:00
Roman Khimov
b7c1efe7e3 core: fix References() result key type
If the block references two ouputs in some other transaction the code failed
to verify it because of key collision. C# code implements it properly by using
full CoinReference type as a key, so let's do it in a similar fashion.
2019-10-01 13:41:26 +03:00
Roman Khimov
8537700b7b core: sort hashes and witnesses in VerifyWitnesses()
Fixes failure to verify some multi-witnesses transactions in Testnet chain. C#
code contains similar logic.
2019-10-01 13:41:26 +03:00
Roman Khimov
dd0dd2d031 core: add claim-specific GetScriptHashesForVerifying()
Claim transactions have different logic in C# node, so we need to
implement it too. It's not the most elegant way to fix it, but let's make it
work first and then refactor if and where needed. Fixes verification of Claim
transactions.
2019-10-01 13:41:26 +03:00
Roman Khimov
854fb187a3 core: verify transactions in AddBlock() 2019-10-01 13:41:26 +03:00
Roman Khimov
1095abb04c core: fix default asset expiration to match C# code
Fixes bogus verification failures for non-native assets.
2019-10-01 13:41:26 +03:00
Roman Khimov
832c56f97d core: fix DutyFlag check in GetScriptHashesForVerifying()
It's a flag (used by Share and Invoice asset types), so it should be checked
like a flag, the same way C# node does.
2019-10-01 13:41:26 +03:00
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
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