Anna Shaleva
8142caaf8b
protocol: implement getblockdata p2p command
...
closes #891
2020-05-22 19:16:49 +03:00
Roman Khimov
d12d198eed
Merge pull request #983 from nspcc-dev/neo3/protocol/getblocks
...
protocol: refactor getblocks payload
2020-05-22 17:46:54 +03:00
Anna Shaleva
2f6a3e9af5
protocol: refactor getblocks payload
...
closes #890
2020-05-22 17:33:59 +03:00
Evgenii Stratonikov
d26758dd31
vm/tests: restore NEO3 JSON tests
...
The only skipped RN are ROT.json (see #927 ) and MEMCPY.json (not a valid
JSON).
2020-05-22 14:17:15 +03:00
Evgenii Stratonikov
673e6c84d1
vm/tests: preserve order when decoding Map item.
...
When using Go's `map` for decoding, order can change from time to time,
while we may want to check it too. Use custom decoder for saving items
in order.
2020-05-22 14:17:15 +03:00
Evgenii Stratonikov
9dca2288ba
vm: make LEFT fail if count is too big
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
22791272bf
vm/tests: compare static slot contents in JSON tests
...
Make use of "staticFields" test field to compare vm static slots.
Also remove altStack because it is doesn't exist.
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
16bf72f9cc
vm/tests: do not load empty script
...
In case we load a zero-length script, VM should end in HALT state.
https://github.com/neo-project/neo-vm/blob/master/tests/neo-vm.Tests/Tests/Others/OtherCases.json#L22
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
86c4f1abc5
vm: do not use State as a mask
...
In NEO2 state could be used as a mask, but now it contains only a single
value.
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
063c29636b
vm: fail if NEWSTRUCT/NEWARRAY argument is not an integer
...
NEO3 VM does not support creating new Array from a Struct.
For this purpose CONVERT opcode is used.
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
1a0290edc6
vm: copy slice when converting between Array<->Struct
...
Related #437 . Becase in NEO3 NEWSTRUCT/NEWARRAY accept only an integer
change tests too.
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
781def735d
vm: use Null item as a default value for Array/Struct elements
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
f4fa712440
vm: make PUSH0 emit Integer
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
820b050b18
vm/tests: make test interop push non-nil InteropItem
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
a44acd25bb
vm/tests: restore JSON tests parsing
...
Make sure we support new test format. Tests itself will be restored
later.
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
61b1722745
opcode: swap ROT and OLDPUSH1
...
Because of how stringer generates String() method, the first of them
will be used as the result.
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
646c247b31
vm/tests: unmarshal Map keys properly in JSON tests
2020-05-22 14:16:31 +03:00
Evgenii Stratonikov
128a99dec2
vm/tests: unmarshal action in JSON tests properly
2020-05-22 13:36:11 +03:00
Evgenii Stratonikov
7ddb23abe3
vm/tests: unmarshal stack items in JSON tests properly
...
New item types were added in NEO3 and they can be capitalized or not.
2020-05-22 13:36:11 +03:00
Evgenii Stratonikov
e71cc04c70
vm/tests: unmarshal VM state in JSON tests properly
2020-05-22 13:36:11 +03:00
Evgenii Stratonikov
0c7b163280
vm/tests: unmarshal script in JSON tests properly
...
Script is no specified via stringified opcodes and their arguments.
2020-05-22 13:36:11 +03:00
Evgenii Stratonikov
1100f629df
opcode: implement FromString()
2020-05-22 13:36:11 +03:00
Evgenii Stratonikov
e53055a560
opcode: use underscored names in String()
2020-05-22 13:36:11 +03:00
Evgenii Stratonikov
3917b4b4e4
vm: update stack size in SETITEM properly
2020-05-21 18:00:51 +03:00
Anna Shaleva
64a2fb63e1
protocol: move magic exchange to version payload
...
closes #889
2020-05-21 14:23:41 +03:00
Anna Shaleva
3bcc56bdcf
protocol: switch to binary MessageCommand
...
closes #888
2020-05-21 13:57:49 +03:00
Evgenii Stratonikov
8cf7871c26
compiler: support nested slice element assignment
2020-05-21 08:30:32 +03:00
Evgenii Stratonikov
5b0e73ddf0
compiler: initialize struct fields explicitly
...
By default VM initializes every field of a new struct to a Boolean.
If field contains another struct, we need to initialize it to default
value explicitly. This commit sets default values for uninitialized
field.
2020-05-21 08:30:32 +03:00
Evgenii Stratonikov
051e3608ff
compiler: support nested struct fielid assignment
2020-05-21 08:30:32 +03:00
Evgenii Stratonikov
1e40f9dac0
compiler: support nested struct reading
2020-05-21 08:30:31 +03:00
Anna Shaleva
9f2cb1726b
core: add witness check to nep5 transfer method
...
We have to check, whether transaction's sender is authorised to transfer
nep5 assets.
2020-05-20 23:34:27 +03:00
Anna Shaleva
1afd630169
core: add senders' fees monitor to mempool
...
In order to simplify maintainance of overall current senders` fees
in the mempool we are to keep them in a separate map.
2020-05-20 23:34:25 +03:00
Anna Shaleva
c3e08afe34
util: fixed typo in method description
2020-05-20 23:26:51 +03:00
Anna Shaleva
7acf5b2841
core: add SystemFee and NetworkFee to transaction
...
closes #831
2020-05-20 23:26:48 +03:00
Anna Shaleva
fc3acdc80c
core: add native contracts' hashes getters
2020-05-20 23:16:04 +03:00
Anna Shaleva
6b2f4efdd4
core: fix bug in nep5TokenNative.addTokens method
...
Sometimes we want to add negative amount (e.g. when burning tokens).
2020-05-20 23:16:04 +03:00
Anna Shaleva
c7a040ff81
core: fix bug with native contracts methods initialisation
...
`NewNEO()` and `NewGAS()` methods are trying to initialise
both `onPersist` and `incBalance` methods of NEO and GAS AFTER
nep5TokenNative is set to the VALUE of created nep5 token.
In this situation an attemmpt to call the corresponding native contracts
methods (e.g. transfer native GAS) leads to contract invocation failure,
as far as `nep5TokenNative.incBalance` method is nil.
Fixed this by initializing both `onPersist` and `incBalance` methods
before getting the value of nep5 contract.
2020-05-20 23:16:04 +03:00
Anna Shaleva
4ebac5a069
core: fix bug in nep5 notifications handling
...
Native contracts deployment creates `Transfer` notifications and adds
them into interop context. However, these notifications were not stored
for two reasons:
1. typo in `Transfer` (so these notifications were not recognised during
processing of the invocation tx in (*Blockchain).storeBlock(...) method)
2. these notifications have `from` adress setted to null, so conversion
to []byte fails. Same thing could happen with `to`.
Related C# issue: https://github.com/neo-project/neo/issues/1646
For now, made both `transfer` and `Transfer` valid.
2020-05-20 23:16:04 +03:00
Anna Shaleva
45b8bdb51c
core: fix bug in consensus
...
We should set MerkleRoot in approving block irrespective to
transactions presented in the block.
2020-05-20 23:16:04 +03:00
Evgenii Stratonikov
22067d400d
rpc: update testchain
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
1a4a0c154b
compiler: support var-declaration of byte slices
...
Related #801 .
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
3a4ed7dfe8
compiler: emit Buffer for byte slices
...
All byte slices are mutable so buffer is a right stack item.
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
b4f1142149
compiler: emit byte constants properly
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
98c508d361
vm: implement MEMCPY opcode
...
MEMCPY copies byte-slice to a destination buffer.
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
a5f6e0e53d
vm: implement NEWBUFFER opcode
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
a3a3a77431
vm: make slice opcodes emit Buffer
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
c3f7832f3b
vm: implement Buffer stack item
...
Buffer is a stack item type introduced in NEO3
which represents mutable byte-array.
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
ee9adcdc5c
vm: check ByteArray size before converting to Integer
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
8f5f6fba07
vm: copy slice in (*ByteArrayItem).TryBytes()
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
1b105a9f1d
compiler: allow using OP= with struct fields and slice elements
...
Do it in a generic way, there is no need in restricting to only
variables.
Port of #954 .
2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
fdb217ec81
compiler: process _ as a special variable
...
It is more convenient to drop values inside `emitStoreVar` because this
makes other code has less special cases.
2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
3926456d86
compiler: add test for iterating over map with range
2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
d0735257ce
compiler: support range loops with value variables
...
Closes #958 .
2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
b126056f04
compiler: use iterators in range loops
...
It is simpler than having some counters on stack and will help us to
support maps in future.
2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
34a4c15932
compiler: support byte slice declaration
2020-05-20 11:10:02 +03:00
Evgenii Stratonikov
582469028b
compiler: emit default values in a generic way
2020-05-20 11:10:01 +03:00
Evgenii Stratonikov
2cc58c3c9e
compiler: allow to declare multiple compound types in a var decl
2020-05-19 16:57:02 +03:00
Evgenii Stratonikov
b4bad11699
compiler: count the number of variables correctly
2020-05-19 16:47:43 +03:00
Evgenii Stratonikov
0629479560
compiler: support non-struct methods
...
There is no need to restrict ourselves just to structs.
2020-05-19 16:40:26 +03:00
Evgenii Stratonikov
87f6ba34db
compiler: process index expresstions in a generic way
...
All type errors such as string index in slice will be catched during parse phase.
2020-05-19 16:40:26 +03:00
Evgenii Stratonikov
aeaa4a8210
compiler: process bool literals in a generic way
2020-05-19 16:40:26 +03:00
Evgenii Stratonikov
70d0ff869d
compiler: refactor typeinfo functions
2020-05-19 16:40:26 +03:00
Evgenii Stratonikov
89b5e92b83
compiler: add tests for function literal
...
Add test forgotten in #934 .
2020-05-12 16:23:09 +03:00
Evgenii Stratonikov
e21015233b
compiler: implement shadowing of global variables
...
Before introducing slots it was hard to change global variables
preserving changes across multiple function calls.
This commit implements such possibility.
Closes #638 .
2020-05-12 16:23:09 +03:00
Evgenii Stratonikov
0cb6dc47e4
vm: implement slot-related opcodes
...
1. Slot is a new mechanism for storing variables during execution
which is more convenient than alt.stack. This commit implements
support for slot opcodes in both vm and compiler.
2. Remove old alt.stack opcodes.
3. Do not process globals at the start of every function, but instead
load them single time at main.
2020-05-12 16:23:08 +03:00
Evgenii Stratonikov
a6271f6bf2
vm: reorder splice opcodes
2020-05-12 16:15:35 +03:00
Evgenii Stratonikov
2cec088f08
vm: add reference counter to slots
2020-05-12 16:15:14 +03:00
Evgenii Stratonikov
af2abedd86
vm: implement reference counter
...
It is convenient to have all reference-counting logic
in a separate struct.
2020-05-12 16:15:14 +03:00
Evgenii Stratonikov
81cbf183af
vm: implement storage slots
2020-05-12 16:15:14 +03:00
Evgenii Stratonikov
75fb3af48f
compiler: add basic support for function literals
...
Implement basic support for function literals.
Nested function literals and variables from closure are not supported for now.
2020-05-12 12:56:52 +03:00
Evgenii Stratonikov
1d3fb3d6f5
vm: implement PUSHA/CALLA opcodes
2020-05-12 12:56:51 +03:00
Evgenii Stratonikov
7fcd537b09
vm: implement Pointer stack item
...
Pointer is a generic address type in VM.
It is used for calling lambda-expressions.
2020-05-12 12:55:31 +03:00
Roman Khimov
b83ee77698
Merge pull request #938 from nspcc-dev/fix/appcall
...
vm: remove APPCALL, TAILCALL
2020-05-08 13:11:02 +03:00
Evgenii Stratonikov
c0147c76ac
emit: remove tailCall argument from AppCall
...
There is no TAILCALL opcode in NEO3.
2020-05-07 14:59:01 +03:00
Evgenii Stratonikov
73c82584a3
vm,compiler: replace APPCALL with System.Contract.Call
...
Contract calls are performed via syscall System.Contract.Call
in NEO3. This implements this in compiler and removes APPCALL from the
VM.
2020-05-07 14:52:03 +03:00
Evgenii Stratonikov
ec900c7ff7
core: implement System.Contract.Call interop
2020-05-07 14:39:06 +03:00
Evgenii Stratonikov
301c1b7601
native: save native contract state on deploy
2020-05-07 14:03:14 +03:00
Evgenii Stratonikov
f9f3192b48
vm: move RET and SYSCALL opcodes
2020-05-07 13:23:05 +03:00
Evgenii Stratonikov
7ac15a7557
compiler: support implicit type in function arguments
...
Go supports declaring multiple arguments of the same type without
duplicating type name. Now we support this too.
2020-05-07 11:33:09 +03:00
Evgenii Stratonikov
b0a89e8a1a
compiler: support named returns
2020-05-06 18:22:52 +03:00
Evgenii Stratonikov
156a2eddc5
compiler: support using return
in some branches
...
When `return` is used in one codepath, but not the other,
we do not clean altstack properly. This commit fixes it.
2020-05-06 18:22:52 +03:00
Evgenii Stratonikov
770cff8b91
compiler: allow to use return
with no arguments
2020-05-06 18:22:52 +03:00
Evgenii Stratonikov
5ab4b9284b
core: remove unused function from tests
2020-05-06 16:00:16 +03:00
Evgenii Stratonikov
977c431bf1
vm: implement ASSERT/ABORT opcodes
...
Rename THROWIFNOT to ASSERT, add ABORT opcode.
ABORT cannot be caught, but the implementation should be postponed until
exception handling is implemented.
2020-05-06 15:54:19 +03:00
Roman Khimov
963a70d54a
Merge pull request #926 from nspcc-dev/feature/stack
...
Implement NEO3 VM stack opcodes
2020-05-06 14:51:04 +03:00
Roman Khimov
7287c01bd0
rpc/server: rework submitblock empty test
...
The original intention here was to check for server reaction in presence of
validation errors (response.ErrValidationFailed) and it was very easy to make
validation fail for block without transactions in Neo 2. But in Neo 3
transactionless blocks are perfectly valid (see
29d321b5e1
) which broke this test even though we
didn't see it until websocket addition (which required
8cec6694ae
to make this test work initially).
So make a valid block and then spoil its verification script.
2020-05-06 14:20:35 +03:00
Roman Khimov
fd72f0635e
rpc/server: prevent test panicing in checkErrGetResult()
...
If we expect some resp.Error, then check for it explicitly.
2020-05-06 13:11:12 +03:00
Evgenii Stratonikov
dd20320615
vm: remove XSWAP/XTUCK opcodes
...
Regenerate RPC testchain as these were used in compiler.
2020-05-06 13:05:22 +03:00
Evgenii Stratonikov
d18199ce42
vm: implement REVERSE* opcodes
...
Use new opcodes in the compiler instead of XSWAP/ROLL.
2020-05-06 13:03:49 +03:00
Evgenii Stratonikov
c8a1188ee1
vm: implement CLEAR opcode
2020-05-06 13:02:57 +03:00
Evgenii Stratonikov
525527f750
vm: reorder stack opcodes
...
Leave *ALTSTACK opcodes for now as they are needed in compiler while
slot opcodes are not yet here.
2020-05-06 13:02:14 +03:00
Evgenii Stratonikov
115919aaf7
vm: process OLDPUSH1 at the context level
...
The only usecase for this opcode is single-byte verification scripts.
2020-05-06 13:00:00 +03:00
Roman Khimov
b04c8623c5
Merge pull request #925 from nspcc-dev/rpc-over-websocket
...
RPC over websocket
2020-05-06 12:52:58 +03:00
Roman Khimov
ec6ade4c9b
Merge pull request #920 from nspcc-dev/neo3/transaction/cosigners
...
core: implement cosigners mechanism
2020-05-04 17:15:07 +03:00
Roman Khimov
3de48d7d90
rpc/client: add minimalistic websocket client
2020-05-04 16:54:35 +03:00
Roman Khimov
a458a17748
rpc/client: separate out http-related functionality
2020-05-04 16:54:35 +03:00
Roman Khimov
6d202ad4c5
rpc/client: drop Version from Options
...
It makes no sense at all, it's a JSON-RPC version.
2020-05-04 16:54:35 +03:00
Roman Khimov
19397ec4a8
rpc/client: fix some comments
2020-05-04 16:54:35 +03:00
Roman Khimov
20d477cbd8
client: remove Balancer getter/setter, make it an Option
...
Keep it internal to the client instance, it makes no sense exposing it to the
outside user.
2020-05-04 16:54:35 +03:00
Roman Khimov
315aabde56
client: make http.Client internal to the Client
...
Exposing it the outside users is strange, so incapsulate it completely.
Fix DialTimeout setting along the way, handle negative timeouts as invalid.
2020-05-04 16:54:35 +03:00