Commit graph

1783 commits

Author SHA1 Message Date
Evgenii Stratonikov
2c5ab95b8a compiler: convert to ByteArray for string variables
Convert to ByteArray when converting variable to `string`, because
underlying byte-slice changes should not affect result string.
2020-06-24 18:59:36 +03:00
Evgenii Stratonikov
1d275ceb65 compiler: distinguish between type conversions and function calls
RN every identifier in call expression is considered to be lambda.
But it also can be type expression, so we need to distinguish between
these cases.
2020-06-24 18:46:32 +03:00
Evgenii Stratonikov
904b2136fc compiler: emit CONVERT opcode for type assertions
Emit CONVERT for converting between different types. NeoVM behavior is
different from that of Go (e.g. assertions of `int` and `uint32` are
equivalent).
2020-06-24 18:00:26 +03:00
Roman Khimov
21cb7d5701
Merge pull request #1078 from nspcc-dev/feature/mempool
network: implement CMDMempool command
2020-06-24 10:49:42 +03:00
Evgenii Stratonikov
57bb2f73de network: implement CMDMempool command
CMDMempool returns hashes of transactions in mempool in chunks.
2020-06-24 10:46:26 +03:00
Roman Khimov
5251607fb7 transaction: s/txid/hash/ for JSON to match C# implementation
It uses `hash` for transactions now, but `txid` for application logs.
2020-06-24 10:43:58 +03:00
Roman Khimov
d81d826bfc core: fix Storage.Get to return Null when there is no value
Match C# implementation and fix state inconsistency at block 249920 of
preview2 testnet. Make our Go Storage.Get return nil and adapt
examples/tests.
2020-06-24 10:43:58 +03:00
Roman Khimov
954c8ff8d6 compiler: support nil checks 2020-06-24 10:43:58 +03:00
Roman Khimov
6f5a42facf smartcontract: correctly encode/decode AnyType
It might get emitted with notifications.
2020-06-24 10:22:21 +03:00
Roman Khimov
7987cdadc0 native: update storage item value after gas distribution
Even if the value is zero, the GAS distribution updates the balance height, so
storage item must be updated too. Fixes the followin on preview2 testnet:
block 74227: value mismatch for key ffffffff1454a6cb279fbcedc66162ad4ad5d1d910202b92743e000000000000000000000005: 1041032104809fd5002103f3210128010000 vs 1041032104809fd50021033f110128010000
2020-06-24 10:22:21 +03:00
Roman Khimov
48fac6f87d native: unify some transfer code 2020-06-24 10:22:21 +03:00
Roman Khimov
fccad11716 native: drop accounts with zero balance
They make no sense. Fixes preview2 testnet state problem:

file BlockStorage_100000/dump-block-70000.json: block 69935: state mismatch for key ffffffff1454a6cb279fbcedc66162ad4ad5d1d910202b92743e000000000000000000000005: Deleted vs Added
2020-06-24 10:22:21 +03:00
Roman Khimov
a77357227a vm: fix caller's script hash returned from VM
Regular CALLs don't update it, only Contract.Call does. Fixes the following
mismatch on preview2 testnet:

file BlockStorage_100000/dump-block-49000.json: block 48644, changes number mismatch: 6 vs 4
2020-06-24 10:22:21 +03:00
Roman Khimov
d5c9449a43 dao: combine GetNextContractID and PutNextContractID
And fix contract create to really update the ID, eliminating this difference
in the storage (preview2 testnet):
file BlockStorage_100000/dump-block-39000.json: block 38043: key mismatch: 0c000000617373657464df4ebe92334d1fc7e64b10f1d1e33942d9905e510000000000000009 vs 00000000617373657464df4ebe92334d1fc7e64b10f1d1e33942d9905e510000000000000009
2020-06-24 10:22:21 +03:00
Roman Khimov
5e56c9db29 native: fix voting accounting in transfers processing
We should modify votes count exactly by the amount of NEO balance change, it
might be negative here.
2020-06-24 10:22:21 +03:00
Roman Khimov
37d44b94e1 native: fix netfee gas redistribution
Preview2 testnet:
file BlockStorage_100000/dump-block-12000.json: block 11562: key mismatch: feffffff1454a6cb279fbcedc66162ad4ad5d1d910202b92743e000000000000000000000005 vs feffffff1431b7e7aea5131f74721e002c6a56b610885813f79e000000000000000000000005

Originally this code was written to run after transactions processing, but
after 0fa4c49735 it works in different manner.
2020-06-24 10:22:21 +03:00
Roman Khimov
d0331bf21b native: simplify votes saving in NEO contract
Follow C# behavior and fix state mismatch at block 11561 of preview2 testnet.
2020-06-24 10:22:21 +03:00
Roman Khimov
e5f05790d5 core: cache standby validators in the Blockchain
They never change, so it makes no sense parsing the keys over and over
again. It also simplifies the interface a little.
2020-06-24 10:22:17 +03:00
Roman Khimov
cd2dca0259 state: fix the way NEO balance is being serialized
Actually, our format is way better, but for preview2 compatibility we need to
use this one.
2020-06-24 10:21:24 +03:00
Roman Khimov
c124d2bcdf core: fix gas generation coefficients to match Neo 3
Follow neo-project/neo#911. Fixes state differences at block 4528 of preview2
testnet compared to C# node.
2020-06-24 10:21:24 +03:00
Roman Khimov
2f8e7e4d33 native: fix getvalidators to match C# implementation
ValidatorsCount is not initialized at block 0 with C# node (the first voter
initializes it) and until that initialization happens the standby validators
list is being returned as is without sorting.

Fixes state mismatch for the key ffffffff0e00000000000000000000000000000001 in
the first blocks.

It also affects tests as now the first validator is different and it receives
the network fees.
2020-06-24 10:21:24 +03:00
Roman Khimov
0fdeafb8f7
Merge pull request #1058 from nspcc-dev/neo3/smartcontract/policy
core: add native policy contract
2020-06-24 09:37:29 +03:00
Anna Shaleva
9f11a55bd6 core: add policy check to mempool
After block was stored it's possible to have new FeePerByte constraint,
so we should remove all transactions which do not meet this requirement.
Also caching of FeePerByte was added in order not to re-verify
transactions each time mempool needs to be updated.
2020-06-24 07:58:09 +03:00
Anna Shaleva
ce402a70d2 core: add policy check to (*Blockchain).verifyTx method
If any of transaction's script hashes for verifying are included into
Policy blocked accounts list, transaction is invalid.
2020-06-24 07:58:09 +03:00
Anna Shaleva
b88863948d rpc: add native policy API to RPC client
part of #904
2020-06-24 07:58:09 +03:00
Anna Shaleva
9097a1a23d smartcontract: update (Parameter).MarshalJSON method
MarshalJSON should be defined on structure (not pointer), as we use
structures to marshal parameters (e.g. in NotificationEvent and
Invoke of RPC result package) and never use pointers for that purpose.

Also added marshalling of nil array into `[]` instead of `null` to
follow C# implementation.
2020-06-24 07:58:09 +03:00
Anna Shaleva
8de0332107 *: use MaxTransactionsPerBlock from Policy native contract
part of #904

1. We now have MaxTransactionsPerBlock set in native Policy contract,
   so this value should be used in (dbft).GetVerified method instead
   of passing it as an argument.
2. Removed (dbft).WithTxPerBlock.
2. DBFT API has changed, so update it's version.
3. Removed MaxTransactionsPerBlock from node configuration, as we
   have it set in native Policy contract.
2020-06-24 07:58:05 +03:00
Anna Shaleva
c2735a4569 core: add cache to native Policy contract
We can cache maxBlockSize, maxTransactionsPerBlock and feePerByte
in order to reduce the number of storage requests.
2020-06-24 07:36:11 +03:00
Anna Shaleva
08cc04c3d5 core: add native policy contract
part of #904
2020-06-24 07:35:07 +03:00
Anna Shaleva
65c1ce4f6a rpc: add GetStorageByID RPC client method
Should be a part of #1077
2020-06-23 17:31:22 +03:00
Evgenii Stratonikov
e54149d547 compiler: do not load map key twice in for-range loop 2020-06-22 13:43:59 +03:00
Evgenii Stratonikov
1847c28b42 compiler: do not load values which will be dropped 2020-06-22 13:43:59 +03:00
Evgenii Stratonikov
72be5412f4 compiler: optimize argument reversing
Do not reverse arguments if there is no more than 1.
2020-06-22 13:43:59 +03:00
Evgenii Stratonikov
3729865860 compiler: reimplement for-range loops without syscalls
System.Enumerator.Next costs 1_000_000 gas which is rather big for a
single iteration. Reimplement this by saving current counters on stack.
This approach will use 2 PICKITEMS (270_000 gas) for maps, which is
still cheaper that *.Next syscall.
2020-06-22 13:43:58 +03:00
Roman Khimov
892812d539 message: fix Verack processsing
Recent 9f42108ef completely broke handshaking.
2020-06-20 00:28:51 +03:00
Roman Khimov
36a65e3847
Merge pull request #1077 from nspcc-dev/neo3/smartcontract/id
core: store smartcontract items by id
2020-06-20 00:12:07 +03:00
Roman Khimov
a2cd2264a8 core: fix HasStorage check in storageGetContext
It was returning nil which is wrong.
2020-06-20 00:04:28 +03:00
Anna Shaleva
f1cdcbc99c core: store smartcontract items by id
closes #1037
2020-06-19 20:48:45 +03:00
Anna Shaleva
c767ac2973 core: fix NEO native contract id
It should be set to -1 as in c# implementation.
2020-06-19 20:44:52 +03:00
Evgenii Stratonikov
505029152f payload: always dereference NullPayload
There is no need in extra indirection level.
2020-06-19 15:02:21 +03:00
Evgenii Stratonikov
9f42108ef2 network: allow NullPayload only for specific commands
CMDFilterClear, CMDGetAddr, CMDMempool all have empty payloads.
2020-06-19 15:01:30 +03:00
Evgenii Stratonikov
a584c5a6a4 native: fix NEP5 contract method prices
Closes #1073.
2020-06-19 12:58:33 +03:00
Evgenii Stratonikov
47f53e612e vm: fix Log and Notify default interop prices 2020-06-19 12:58:33 +03:00
Evgenii Stratonikov
4b31c18316 core: fix Neo.Native.Deploy price 2020-06-19 12:58:33 +03:00
Evgenii Stratonikov
540ac23ca8 core: calculate prices of Neo.Crypt.* opcodes correctly 2020-06-19 12:58:33 +03:00
Evgenii Stratonikov
05dad10e82 native: fix native contract onPersist script
C# implementation uses NEWARRAY for creating arguments.
Don't change our implementation in `emit`, because PACK is cheaper and
this script must not depend on the internal details of `emit` package anyway.
2020-06-19 11:58:38 +03:00
Evgenii Stratonikov
3787a8895e rpc: marshal GasConsumed getapplicationlog as string
Also there is no more decimal point.
2020-06-19 11:38:56 +03:00
Evgenii Stratonikov
6a2161207a smartcontract: rename ByteArray to ByteString in JSON for smartcontract parameters 2020-06-19 11:38:56 +03:00
Evgenii Stratonikov
81adb7ce83 core: set price getter for native contract persist routine 2020-06-19 11:38:56 +03:00
Evgenii Stratonikov
b9e260a704 smartcontract: omit empty value in JSON for Interop/Any parameters 2020-06-19 11:38:56 +03:00