Roman Khimov
c7032022f8
core: don't search through the whole DAO in isTxStillRelevant
...
New transactions are added to the chain with blocks. If there is no
transaction X at height N in DAO, it could only be added with block N+1, so
it has to be present there. Therefore we can replace `dao.HasTransaction()`
check with a search through in-block transactions. HasTransaction() is nasty
in that it may add useless load the DB and this code is being run with a big
Blockchain lock held, so we don't want to be delayed here at all.
Improves single-node TPS by ~2%.
2020-08-20 18:50:18 +03:00
Roman Khimov
3a379e4f3e
core: don't reverify mempooled transactions in AddBlock
...
The end effect is almost as if `VerifyTransactions: false` was set in the
config, but without actually compromising the guarantees provided by it.
It almost doubles performance for single-mode benchmarks and makes block
processing smoother (more smaller blocks are being produced).
2020-08-19 15:16:19 +03:00
Roman Khimov
eb8122837e
core: fix failing TestGetTransaction
...
3677cc0e2
ruined it:
TestGetTransaction: blockchain_test.go:413:
Error Trace: blockchain_test.go:413
Error: Not equal:
expected: 467
actual : 399
Test: TestGetTransaction
2020-08-19 13:22:31 +03:00
Roman Khimov
6dffd4967a
Merge pull request #1335 from nspcc-dev/tests/binary
...
Update binary test data
2020-08-19 11:33:47 +03:00
Evgenii Stratonikov
3677cc0e24
core: update GetTransaction test
2020-08-19 09:41:11 +03:00
Evgenii Stratonikov
04bff62d65
transaction: update binary test data
2020-08-18 15:09:30 +03:00
Evgenii Stratonikov
054b77dbde
block: update binary test data
2020-08-18 14:52:30 +03:00
Roman Khimov
52b002e079
Merge pull request #1332 from nspcc-dev/check-for-excessive-verification-results
...
core: verification script must return exactly one value
2020-08-18 12:15:10 +03:00
Anna Shaleva
591f639ad6
core: fix getOnPersistWrapper for native contracts
...
According to manifest, OnPersist.ReturnType is void, so we shouldn't
return anything from it. It's not so important, as we drop this value at
the end of OnPersist invocation.
2020-08-18 09:52:46 +03:00
Roman Khimov
d0c29f52c9
core: verification script must return exactly one value
...
C# node is quite picky as it expects there to be exactly one value returned,
but our testchain actually adds 4 signatures for multisig cases instead of 3
which makes it technically incompatible with C# node.
2020-08-17 22:02:15 +03:00
Roman Khimov
8e619cc671
Merge pull request #1318 from nspcc-dev/fix/verifytests
...
Add tests for `verifyTx` and `verifyHeader`
2020-08-14 17:24:03 +03:00
Roman Khimov
92f37a5d36
Merge pull request #1324 from nspcc-dev/fix-goreportcard-issues
...
Fix goreportcard issues
2020-08-14 14:50:35 +03:00
Evgenii Stratonikov
a796f2b61d
names: implement FromID
...
Allow to convert interop id to it's name.
2020-08-14 14:22:45 +03:00
Evgenii Stratonikov
7854dcfd8f
core: replace interop names with named constants
2020-08-14 14:21:54 +03:00
Evgenii Stratonikov
f3650e20b0
vm: move InteropNameToID to a separate package
2020-08-14 13:54:11 +03:00
Roman Khimov
e7d13e6db2
*: fix misspellings found in Go Report Card
2020-08-14 12:16:24 +03:00
Roman Khimov
f6a308f7f6
*: fix ineffassign where the value should really be used
...
Found with GoReportCard.
2020-08-14 12:08:57 +03:00
Roman Khimov
ec2a2f3fb9
transaction: fix ineffassign GoReportCard issue
...
s is not used purposefuly.
2020-08-14 12:08:16 +03:00
Evgenii Stratonikov
cadebdfc19
core: add tests for (*Blockchain).verifyHashAgainstScript
2020-08-14 09:40:36 +03:00
Evgenii Stratonikov
1eb9a4c6c6
core: allow to use verification contracts
...
In NEO3 we can't just appcall hash, as verification script has no access
to state. Instead we use `verify` method of an arbitrary contract.
2020-08-14 09:40:34 +03:00
Evgenii Stratonikov
7f2a931fb6
core: add tests for (*Blockchain).verifyHeader
2020-08-14 09:37:32 +03:00
Evgenii Stratonikov
e8cf4d96ce
core: add tests for (*Blockchain).verifyTx
2020-08-14 09:37:30 +03:00
Roman Khimov
ca542f11fe
core: drop unused secondsPerBlock() method
2020-08-11 21:37:18 +03:00
Roman Khimov
acc2265169
transaction: attribute type is now type, not usage
2020-08-11 21:10:50 +03:00
Roman Khimov
fb70c82157
transaction: there are no valid attributes defined for preview3
2020-08-11 21:10:12 +03:00
Roman Khimov
b1034d8ed6
state: drop Neo 2 Account and everything related
...
It's substituted with NEP5Balances now.
2020-08-11 20:42:02 +03:00
Roman Khimov
34156ef78d
core: fix (*HeaderHashList).Write comment
2020-08-11 20:33:16 +03:00
Roman Khimov
2354af463a
core: drop some unused HeaderHashList functions
2020-08-11 20:33:16 +03:00
Roman Khimov
08fd6180b2
native: drop validators count structure
...
It's not used since #1252 .
2020-08-11 20:19:55 +03:00
Roman Khimov
c3f7a419a0
Merge pull request #1296 from nspcc-dev/smartcontract/examples
...
examples: update examples
2020-08-11 19:09:13 +03:00
Anna Shaleva
b5494320f9
compiler, cli: support events from .yml config file
...
We currently can't process events in codegen, so we have to provide
them via .yml config file. Do not delete the rest of the code connected
with conversion of MethodDebugInfo.Event into manifest.Event as we have
issue #1038 .
2020-08-11 13:42:06 +03:00
Evgenii Stratonikov
057e1c6e3c
compiler: provide filename to Compile()
2020-08-11 11:10:45 +03:00
Roman Khimov
c16040aecc
native: sort GetValidators result
...
As it's returned sorted now. Fixes state change mismatch for
NextValidators. It also partially reverts
2f8e7e4d33
and significantly changes the test
chain as the fees are no longer being sent to the same account.
2020-08-10 19:49:09 +03:00
Roman Khimov
dba248236c
smartcontract: add CreateDefaultMultiSigRedeemScript
...
And use it where appropriate. Some of our code was just plain wrong (like the
one in GAS contract) and unification is always useful here.
2020-08-10 18:58:11 +03:00
Roman Khimov
fb97ea9458
native: don't register standby validators on initialization
...
C# doesn't do that since neo-project/neo#1762 .
2020-08-10 17:51:46 +03:00
Roman Khimov
f287681fa7
core/native: fix VotersCount zero value encoding
...
Empty byte array is enough to be bigint value of zero. Fixes state differences
with C# node.
2020-08-10 17:07:14 +03:00
Evgenii Stratonikov
bf01599430
vm: check return value on context unload
...
When calling external contracts we expect exactly 1 value to be on
stack. For methods returning nothing, `Null` value is pushed, otherwise
it is an error.`
2020-08-10 11:52:33 +03:00
Roman Khimov
4aeaf05f90
Merge pull request #1289 from nspcc-dev/fix/nep5
...
Port `getnep5transfers` changes to master
2020-08-10 11:11:24 +03:00
Evgenii Stratonikov
14aba7fc80
core: fix failing tests after merge
...
Related f5131491b
.
2020-08-10 09:20:34 +03:00
Roman Khimov
f5131491b7
Merge pull request #1271 from nspcc-dev/core/call_from_native
...
core: contractCall from native contracts
2020-08-07 21:24:50 +03:00
Anna Shaleva
c87e2262c3
core: remove ScriptHashGetter from interop context
...
We have VM inside the context, so don't need ScriptHashGetter anymore.
2020-08-07 20:31:20 +03:00
Anna Shaleva
42736095a1
core: add test to call contract from native
...
Closes #1200
2020-08-07 20:31:16 +03:00
Evgenii Stratonikov
807338f97e
core: do not store NEP5 transfer log in memory
...
Traversing transfer log instead of accumulating and returning it
is faster and takes less memory.
2020-08-07 18:21:06 +03:00
Anna Shaleva
995053f2eb
core: add VM into interop context
2020-08-07 16:15:24 +03:00
Roman Khimov
c3c88a57cd
Merge pull request #1281 from nspcc-dev/drop-go-1.12-and-fix-some-things
...
Drop go 1.12 and fix some things
2020-08-07 13:34:54 +03:00
Roman Khimov
d5a9d80c12
core: refactor out policy check for transaction
...
We were checking blocked accounts twice which is obviously excessive. We also
have our accounts sorted, so we can rely on that in CheckPolicy(). It also
doesn't make much sense to check MaxBlockSystemFee in Blockchain code, policy
contract can handle that.
2020-08-07 12:21:52 +03:00
Roman Khimov
90180c6fb6
native: pass DAO to CheckPolicy(), it doesn't need interop context
...
Simplify things a bit.
2020-08-07 12:21:52 +03:00
Roman Khimov
791c983304
core: drop GetScriptHashesForVerifying
...
It no longer depends on blockchain state and there can't ever be an error, in
fact we can always iterate over signers, so copying these hashes doesn't make
much sense at all as well as sorting arrays in verifyTxWitnesses (witnesses
order must match signers order).
2020-08-07 12:21:52 +03:00
Roman Khimov
c19838ea67
core: use errors.Is in PoolTx
...
Just in case.
2020-08-07 12:21:52 +03:00
Roman Khimov
4c38fae54c
core: fix mempool error check in PoolTx
...
ErrAlreadyExists should be returned for ErrDup, not ErrConflict.
2020-08-07 12:21:52 +03:00
Roman Khimov
0e2784cd2c
always wrap errors when creating new ones with fmt.Errorf()
...
It doesn't really change anything in most of the cases, but it's a useful
habit anyway.
Fix #350 .
2020-08-07 12:21:52 +03:00
Roman Khimov
205f52c563
core: use error wrapping to provide more details
2020-08-07 12:21:52 +03:00
Roman Khimov
5ef08f60ae
remove github.com/pkg/errors from dependencies
...
It's not needed any more with Go 1.13 as we have wrapping/unwrapping in base
packages. All errors.Wrap calls are replaced with fmt.Errorf, some strings are
improved along the way.
2020-08-07 12:21:52 +03:00
Evgenii Stratonikov
bfda60c683
native: add missing witness checks to NEO.(Un)registerCandidate
2020-08-07 09:17:02 +03:00
Evgenii Stratonikov
8af3f05358
native: implement NEO.UnregisterCandidate
method
2020-08-06 20:39:13 +03:00
Evgenii Stratonikov
38a92323c9
native: fill votes when registering unregistered candidate
...
If a candidate was registered, then unregistered and then again
registered, it's votes must not be lost.
2020-08-06 20:39:13 +03:00
Evgenii Stratonikov
27169d140f
core: implement (*Blockchain).GetStandByCommitee()
2020-08-06 20:39:13 +03:00
Evgenii Stratonikov
e5d973d3a4
config: rename StandbyValidators to StandbyCommittee
2020-08-06 20:39:13 +03:00
Evgenii Stratonikov
b14b047c78
native: add tests for delegated voting
2020-08-06 20:39:13 +03:00
Evgenii Stratonikov
9bc731b3b1
native: implement delegated voting
...
Close #867 .
2020-08-06 20:39:13 +03:00
Evgenii Stratonikov
f0b62cdaa6
native: make *totalSupply accept DAO
...
There is no need to provide full interop context.
2020-08-06 14:26:24 +03:00
Evgenii Stratonikov
3e39f0f211
native: rename Validator to Candidate
2020-08-06 14:26:24 +03:00
Roman Khimov
5e53aceb0f
Merge pull request #1277 from nspcc-dev/restrict-verification-call-flags
...
core: restrict verification scripts with CallFlags.None
2020-08-06 13:52:14 +03:00
Roman Khimov
57ee8b80e5
Merge pull request #1246 from nspcc-dev/protocol/getblockbyindex
...
protocol: request blocks by index
2020-08-05 23:21:07 +03:00
Roman Khimov
b7f89b0544
core: restrict verification scripts with CallFlags.None
...
Follow neo-project/neo#1776 . Looks very suspicious to me as it severely limits
verification scripts, but we have to be compatible at this point.
2020-08-05 19:17:48 +03:00
Evgenii Stratonikov
194da64975
core: deepcopy notification in System.Runtime.Notify
...
Make it impossible to change already emitted notifications via
`System.Runtime.GetNotifications`.
2020-08-05 11:19:41 +03:00
Roman Khimov
ef53a45e7a
Merge pull request #1264 from nspcc-dev/smartcontract/manifest/supported_standards
...
smartcontract: add list of supported standards to manifest
2020-08-04 22:17:00 +03:00
Anna Shaleva
7c6cdcbcc9
core: fix bug with policy.MaxVerificationGas
...
In 121c9664b
we should take into account isValid flag of
NativePolicy contract while retrieving MaxVerificationGas native
policy value. Otherwise we won't be able to get MaxVerificationGas
after the node was restarted, because this value is not truly
stored along with the other native policy values.
This commit fixes bug with headers verification after the node
restarting with an existing storage:
```
2020-08-03T12:52:56.158+0300 WARN failed processing headers {"error": "vm failed to execute the script with error: error encountered at instruction 0 (PUSHDATA1): gas limit is exceeded", "errorVerbose": "vm failed to execute the script with error: error encountered at instruction 0 (PUSHDATA1): gas limit is exceeded\ngithub.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).verifyHashAgainstScript\n\t/home/neospcc/Documents/GitProjects/nspcc-dev/neo-go/pkg/core/blockchain.go:1454\ngithub.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).verifyHeaderWitnesses\n\t/home/neospcc/Documents/GitProjects/nspcc-dev/neo-go/pkg/core/blockchain.go:1517\ngithub.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).verifyHeader\n\t/home/neospcc/Documents/GitProjects/nspcc-dev/neo-go/pkg/core/blockchain.go:1175\ngithub.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).addHeaders\n\t/home/neospcc/Documents/GitProjects/nspcc-dev/neo-go/pkg/core/blockchain.go:484\ngithub.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).AddHeaders\n\t/home/neospcc/Documents/GitProjects/nspcc-dev/neo-go/pkg/core/blockchain.go:453\ngithub.com/nspcc-dev/neo-go/pkg/network.(*Server).handleHeadersCmd\n\t/home/neospcc/Documents/GitProjects/nspcc-dev/neo-go/pkg/network/server.go:454\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1373"}
```
2020-08-04 17:52:34 +03:00
Anna Shaleva
ba08a9b6ad
core: move all transaction.Decode checks to separate method
...
We should perform the same checks during UnmarshalJSON.
2020-08-04 17:34:06 +03:00
Anna Shaleva
ead6bdb25e
core: remove unnecessary comment
2020-08-04 17:34:06 +03:00
Anna Shaleva
90825efa16
core: move transaction's sender to cosigners
...
Closes #1184
Ported changes from https://github.com/neo-project/neo/pull/1752
2020-08-04 17:33:50 +03:00
Anna Shaleva
66ceaa6b75
smartcontract: add list of supported standards to manifest
...
Closes #1204
2020-08-04 17:29:44 +03:00
Anna Shaleva
8697582b23
core: add FeeOnly witness scope
2020-08-04 15:08:59 +03:00
Anna Shaleva
75f1c2d6f2
core: add scopes check to cosigners in DecodeBinary
2020-08-04 15:08:59 +03:00
Anna Shaleva
7865bc5925
core: fix native policy tests
...
That was a merge problem.
2020-08-04 15:05:31 +03:00
Roman Khimov
62f5aa8eb4
Merge pull request #1254 from nspcc-dev/native/policy/maxblocksystemfee
...
core, consensus: add maxBlockSystemFee to native Policy
2020-08-04 13:13:06 +03:00
Roman Khimov
fa5ff8dd95
Merge pull request #1242 from nspcc-dev/fix/json
...
Implement lossless stackitem to json conversion
2020-08-04 12:59:47 +03:00
Anna Shaleva
db65ed04d9
consensus: apply policy during verifyBlock
...
To follow C# implementation we should also check proposed block on
policy matching.
2020-08-04 10:59:09 +03:00
Anna Shaleva
4a1c8464f9
core: use maxBlockSize to apply policy to tx set
...
We should also take into account maxBlockSize in
(bc *Blockchain).ApplyPolicyToTxSet
2020-08-04 10:59:09 +03:00
Anna Shaleva
c647f8e4ed
core: add maxBlockSystemFee to native Policy
...
Closes #1195
2020-08-04 10:59:00 +03:00
Roman Khimov
00671deb8f
Merge pull request #1241 from nspcc-dev/fix/string
...
Ensure strings are valid UTF-8 where appropriate
2020-08-03 18:10:27 +03:00
Anna Shaleva
13336f9dba
core: adjust calling flags of native Policy methods
2020-08-03 16:09:10 +03:00
Anna Shaleva
60f9abae40
core: chenge maxBlockSizeKey of native Policy
2020-08-03 16:00:15 +03:00
Evgenii Stratonikov
e5d538ed21
core: use raw stack items in application logs
...
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 16:07:16 +03:00
fyrchik
e4fc655115
Merge pull request #1239 from nspcc-dev/store_nep5_with_id
...
core: store contract IDs instead of hashes for NEP5Balances and Transfers
2020-07-30 12:56:19 +03:00
Roman Khimov
e21c65c59f
core: add state height to prometheus metrics
...
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
5ee3ecf381
core: update verified state root height
...
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
ab802cdd5f
state: implement JSON marshaling for MPT* items
...
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
236438d799
core: do MPT compaction every once in a while
...
We need to compact our in-memory MPT from time to time, otherwise it quickly
fills up all available memory. This raises two obvious quesions --- when to do
that and to what level do that.
As for 'when', I think it's quite easy to use our regular persistence interval
as an anchor (and it also frees up some memory), but we can't do that in the
persistence routine itself because of synchronization issues (adding some
synchronization primitives would add some cost that I'd also like to avoid),
so do it indirectly by comparing persisted and current height in `storeBlock`.
Choosing proper level is another problem, but if we're to roughly estimate one
full branch node to use 1K of memory (usually it's way less than that) then we
can easily store 1K of these nodes and that gives us a depth of 10 for our
trie.
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
58b7e16e0e
core: fix PrevHash calculation for MPTRoot
...
This was differing from C# notion of PrevHash. It's not a previous root, but
rather a hash of the previous serialized MPTRoot structure (that is to be
signed by CNs).
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
caea6d6ca8
mpt: fix extension node cache invalidation
...
It should always be invalidated if something changes in the `next` (below the
extension node).
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
0e29382035
core: update MPT during block processing
...
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
2b53877dff
mpt: don't flush nodes already present in the DB
...
It's just a waste of time.
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
475bf2445a
mpt: restructure nodes a bit, implement serialization and hash cache
...
It drastically reduces the number of allocations and hash calculations.
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
6ca22027d5
mpt: implement (*Trie).Collapse()
...
Because trie size is rather big, it can't be stored in memory.
Thus some form of caching should also be implemented. To avoid
marshaling/unmarshaling of items which are close to root and are used
very frequenly we can save them across the persists.
This commit implements pruning items at the specified depth,
replacing them by hash nodes.
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
f0b85f8af7
mpt: implement JSON marshaling/unmarshaling
...
Because there is no distinct type field in JSONized nodes, distinction
is made via payload itself, thus all unmarshaling is done via
NodeObject.
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
9b328240dd
mpt: implement MPT proof Get and Verify
...
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
dc6741bce7
mpt: implement MPT trie
...
MPT is a trie with a branching factor = 16, i.e. it consists of sequences in
16-element alphabet.
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
3c99393bef
core: simplify System.Contract.Call*
parameter handling
2020-07-30 12:37:32 +03:00
Evgenii Stratonikov
f40aba4cd0
vm: convert items to UTF-8 strings
...
Add `stackitem.ToString` for seamless string conversion.
2020-07-30 12:37:31 +03:00
Anna Shaleva
0dd1730632
core: store NEP5Transfer asset by ID instead of hash
...
To avoid problems with retrieving decimals for migrated contracts.
2020-07-29 15:15:48 +03:00
Anna Shaleva
b9bdab8ec8
core: store nep5balances using contract id
...
Closes #1194
2020-07-29 15:15:48 +03:00
Anna Shaleva
dbd460d883
core: retrieve contract hash by ID
...
We'll need this ability further to retrieve contracts hashes for Nep5Balances.
2020-07-29 15:14:24 +03:00
Evgenii Stratonikov
9a992865b1
interop: add Secp2k to the list of crypto interops
...
Allow to use them during verification.
2020-07-29 13:43:33 +03:00
Evgenii Stratonikov
23a1430395
core: allow to restrict creating callbacks from syscalls
...
Specify DisallowCallback flag if syscall is not allowed to be used in a
callback.
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
99b0397a61
core: implement System.Callback.CreateFromSyscall
interop
...
Allow to create callbacks from syscalls.
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
c54b45e76d
core: implement System.Callback.CreateFromMethod
interop
...
Support creating callbacks from contract methods.
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
f96c217aba
core/tests: refactor getting contract state
...
Get 2 contracts in pair which is useful everytime we need to test
syscall with one contract calling the other.
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
e654d22991
core/tests: introduce loadScript helper
...
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
382a7f5b3e
core: implement System.Callback.*
interops
...
Support creating callbacks from pointers.
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
c09ea04df3
core: add prices for TRY* opcodes
...
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
51ae12e4fd
*: move syscall handling out of VM
...
Remove interop-related structures from the `vm` package.
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Anna Shaleva
4bf88ba6b0
core: decouple native contracts from interop service
...
Closes #1191 .
2020-07-29 10:33:18 +03:00
fyrchik
b187dfe3ce
Merge pull request #1236 from nspcc-dev/rpc/getrawmempool
...
rpc: update `getrawmempool` and `getrawtransaction` RPC-calls
2020-07-29 10:18:51 +03:00
Anna Shaleva
70ef733ce7
core, vm: store VMState as byte instead of string
...
Part of #1183
2020-07-29 10:14:08 +03:00
Evgenii Stratonikov
685d44dbc1
*: support _initialize
method in contracts
...
Invoke `_initialize` method on every call if present.
In NEO3 there is no entrypoint and methods are invoked by offset,
thus `Main` function is no longer required.
We still have special `Main` method in tests to simplify them.
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
466af55dea
vm: isolate stack in LoadScript
...
When calling contract it must be provided with a new stack containing
only it's arguments. The result is then copied back on RET.
Fix #1220 .
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
d2ddf7b7cb
*: support invoking methods by offset
...
Allow to invoke methods by offset:
1. Every invoked contract must have manifest.
2. Check arguments count on invocation.
3. Change AppCall to a regular syscall.
4. Add test suite for `System.Contract.Call`.
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
54d7882acf
core: compiler contract on-the-fly in helper test
...
Generate proper manifest file too.
2020-07-27 13:00:34 +03:00
Evgenii Stratonikov
7d8fead1fd
native: change onPersist return type to Void
2020-07-27 11:08:01 +03:00
Evgenii Stratonikov
e52c39ae7e
manifest: remove EntryPoint from manifest
2020-07-27 11:08:01 +03:00
Roman Khimov
d2c823daa6
Merge pull request #1233 from nspcc-dev/fix/gasverify
...
core: restrict maximum gas allow for verification
2020-07-26 22:40:13 +03:00
Evgenii Stratonikov
121c9664b4
core: restrict maximum gas allow for verification
...
Disallow costly verification methods. We put this limit in policy
contract as it may be a subject to change in future.
In fact this value also overrides gas limit for header verification.
Close #1202 .
2020-07-25 14:33:38 +03:00
Evgenii Stratonikov
8931c9a794
core/interop: increase coverate for crypto interops
2020-07-25 12:16:56 +03:00
Evgenii Stratonikov
83e53fab24
core/test: ensure public key is invalid in test
...
When providing public key as a subslice, it still can be
decoded as a valid key, thus interop will not return an error
but rather push `false` on stack. This test is about providing
invalid key, so ensure this via setting invalid prefix.
2020-07-25 12:01:16 +03:00
Anna Shaleva
8fde41001e
core, vm: remove allowed triggers from syscalls
...
Closes #1205 .
2020-07-23 20:44:39 +03:00
Roman Khimov
d8a1c3de46
Merge pull request #1221 from nspcc-dev/neo3/interop/post-preview2_adjustment3
...
interop: post-preview2 adjustment, part 3
2020-07-23 20:35:53 +03:00
Anna Shaleva
ef8de3b2dc
core: adjust System.Runtime.GetNotifications interop
...
Part of #1055 .
Forgot to add this pretty interop to the list of system interops.
2020-07-23 07:54:51 +03:00
Anna Shaleva
120eff92f7
core: adjust System.Runtime.Notify interop
...
Part of #1198 .
Notification name should be UTF8-encoded.
2020-07-23 07:55:12 +03:00
Anna Shaleva
2c41b7b254
core: adjust System.Runtime.Log interop
...
Part of #1055 and #1198 .
It should check the message length and encoding.
2020-07-23 07:54:51 +03:00
Anna Shaleva
88e003d219
core: adjust System.Runtime.GetTime interop
...
Part of #1055 .
It should have AllowStates flag.
2020-07-23 07:51:24 +03:00
Anna Shaleva
990ef5525c
core: adjust System.Runtime.GasLeft interop
...
Part of #1055 .
In test mode it should return -1.
2020-07-23 07:51:24 +03:00
Anna Shaleva
8fed383523
core: adjust System.Runtime.CheckWitness interop
...
Part of #1055 .
It should have `AllowStates` flag.
Also removed unreachable code: we can't have such situation when
script container is not a transaction in the scope of `CheckWitness`
method because:
1. Blocks have their own implementation of CheckWitness for
internal usage (it's (bc *Blockchain) verifyHeaderWitnesses method).
2. For the outside calls of System.Runtime.CheckWitness interop (e.g.
calls from smart-contract) script container is always a transaction.
2020-07-23 07:51:24 +03:00
Anna Shaleva
459ac34839
core: adjust System.Enumerator.Create interop
...
Part of #1201 .
It should be able to create enumerator from primitive byte-array-like
stack items too.
2020-07-23 07:51:24 +03:00
Anna Shaleva
6e44499cec
core: adjust Neo.Native.Deploy interop
...
Part of #1055 .
It could be that context.Block is nill.
2020-07-22 16:58:32 +03:00
Anna Shaleva
b8d82b49ec
core: add Neo.Crypto.RIPEMD160 interop
...
Closes #1193 .
2020-07-22 16:58:32 +03:00
Anna Shaleva
84bf87df52
core: adjust System.Storage.PutEx interop
...
Part of #1055 .
Added System.Storage.PutEx to compiler. Added StorageFlag in order to
denote whether item is constant or not.
2020-07-22 16:58:23 +03:00
Anna Shaleva
47eadcdf2a
core: adjust System.Storage.Put interop
...
Part of #1055 .
Maximum storage key len has been changed. Also added maximum storage
value len restriction.
2020-07-22 11:05:10 +03:00
Anna Shaleva
b5185d5d1a
core: refactor System.Storage.Get[ReadOnly]Context interops
...
Part of #1055 .
Split methods, as they have a lot of common code. This also fixex nil
error of storageGetReadOnlyContext in case when contract does not have
storage.
2020-07-22 10:51:47 +03:00
Evgenii Stratonikov
3d7fa9de93
*: make Notify interop accept event name
2020-07-20 13:33:32 +03:00
Roman Khimov
ae9658a108
dao: migrate nep5 balances with the contract
...
Fixes #1144 . It's quite simple approach, we just update balance info right
upon contract migration. It will slow down migration transactions, but it
takes about 1-2 seconds to Seek through balances at mainnet's 3.8M, so the
approach should still work good enough. The other idea was to make lazy
updates (maintaining contract migration map), but it's more complicated to
implement (and implies that a balance get might also do a write).
There also is a concern about memory usage, it can give a spike of some tens
of megabytes, but that also is considered to be acceptable.
2020-07-17 19:03:12 +03:00
Roman Khimov
3f2f0be2c2
Merge pull request #1187 from nspcc-dev/neo3/interop/post-preview2_adjustment
...
interop: post-preview2 adjustment
2020-07-17 13:33:29 +03:00
Anna Shaleva
74d2f437f4
core: add System.Binary.Base64Encode(Decode) interops
...
Part of #1055
2020-07-17 12:36:18 +03:00
Anna Shaleva
f31ce9289d
core: add System.Contract.GetCallFlags interop
...
Part of #1055 .
It returns calling flags of the current context.
2020-07-17 12:35:02 +03:00
Anna Shaleva
842feb2533
core: adjust System.Contract.Update interop
...
Part of #1055 .
We should check contract scripthash against the one provided in manifest
and manifest groups. We shouldn't put on stack anything after return.
And ofcourse, we mast not destroy the old contract at the end, as
`contractDestroy` removes all storage items associated with the
old contract ID (which equals to the new contract ID). We just remove
old contract state - it's enough.
2020-07-17 12:33:44 +03:00
Anna Shaleva
fddad0b475
core: adjust System.Contract.Create interop
...
Part of #1055 .
It should check given scripthash against manifest groups and return the
contract state as a struct (not interop interface).
2020-07-17 09:28:52 +03:00
Anna Shaleva
d2ec0fed3d
core: adjust System.Blockchain.GetContract interop
...
Part of #1055 .
It should put on stack an array instead of interop interface.
2020-07-17 09:28:52 +03:00
Anna Shaleva
1a5fb01e61
core: adjust System.Contract.IsStandard interop
...
Part of #1055 .
It should check not only stored contracts, but also interop context
script container in case if it's a transaction.
2020-07-17 08:19:43 +03:00
Anna Shaleva
d2f452c240
core: adjust System.Contract.CallEx interop
...
Part of #1055
2020-07-17 08:19:43 +03:00
Anna Shaleva
74ffde8367
core: adjust System.Blockchain.GetTransactionFromBlock interop
...
To match C# implementation, we should pick all arguments from stack first.
2020-07-17 08:19:43 +03:00
Roman Khimov
38f0432f36
core: remove stale storeBlock comment, fix #365
...
After transaction unification and UTXO removal storeBlock became quite simple
and doesn't require any refactoring any more.
2020-07-16 23:06:17 +03:00
Roman Khimov
acfded7f45
Merge pull request #1180 from nspcc-dev/fix-calling-scripthash-check-in-nep5
...
Add calling scripthash check to native nep5 transfers
2020-07-16 07:29:14 +03:00
Roman Khimov
59be6bcd24
native: add calling script hash to NEP5 transfer witness check
...
Fix transfers from contract's address.
2020-07-15 22:52:35 +03:00
Roman Khimov
d4c3a17883
interop/native: always use proper ScriptHashGetter, fix #924
...
All scripts are run in VM, so it's there to tell us about script hashes
involved and it must be used instead of nep5ScriptHash kludge.
2020-07-15 22:43:30 +03:00
Roman Khimov
f46ed798f0
Merge pull request #1169 from nspcc-dev/neo3/rpc/fields_names_adjustment
...
rpc: adjust RPC calls JSON fields
2020-07-15 18:24:54 +03:00
Anna Shaleva
538616e9f8
rpc: adjust getrawtransaction
RPC-call JSON fields names
...
Part of #1130
2020-07-15 14:44:13 +03:00
Anna Shaleva
a3e306ff78
core: implement Secp256k1 Verify and CheckMultisig interops
...
Closes #918 .
2020-07-14 16:21:34 +03:00
Anna Shaleva
5326fc587a
core: rename Neo.Crypto.CheckMultisig to Neo.Crypto.CheckMultisigWithECDsaSecp256r1
...
Part of #918
2020-07-14 16:19:12 +03:00
Anna Shaleva
17233e1d8e
core: rename Neo.Crypto.Verify to Neo.Crypto.VerifyWithECDsaSecp256r1
...
Part of #918
2020-07-14 16:19:12 +03:00
Roman Khimov
4c23aa1d7c
Merge pull request #1174 from nspcc-dev/neo3/interop/getscriptcontainer
...
core, compiler: return tx from GetScriptContainer interop
2020-07-14 08:58:52 +03:00
Roman Khimov
dafb9eea4d
Merge pull request #1177 from nspcc-dev/no-free-vm-runs
...
No free VM runs
2020-07-14 08:42:13 +03:00
Roman Khimov
db027ad9c5
vm: zero GAS means no GAS, use fee data to properly limit execution
...
We were accepting transactions with zero system fee, but we shouldn't do
that. Also, transaction's verification execution has to be limited by network
fee.
2020-07-14 08:37:29 +03:00
Anna Shaleva
c4f7b06974
core, compiler: return struct from GetScriptContainer interop
...
Closes #1173
2020-07-14 06:04:48 +03:00
Roman Khimov
419d68329c
core: limit GAS available for block verification
2020-07-13 18:24:58 +03:00
Roman Khimov
3134e364b2
core: fix CalculateNetworkFee() for multisig contracts
...
We return m from the vm.ParseMultiSigContract and n is the length of pubs,
invocation script then pushes m signatures for n keys.
2020-07-13 18:05:46 +03:00
Roman Khimov
afc5ee1ded
core: fix ECDSA verifiation price, it's 1000000 and it's defined in crypto
2020-07-13 18:04:50 +03:00
Roman Khimov
579630a3fa
native: don't expose internal slices to the outside world
...
They should be hidden.
2020-07-11 19:54:50 +03:00
Roman Khimov
7eef895061
consensus: use GetNextBlockValidators where appropriate
...
GetValidators without parameter is called upon DBFT initialization and it
should receive validators for the next block (that will create it),
parameterized GetValidators is used for NextConsensus calculation where we
need a list for the current state of the chain.
2020-07-11 19:54:50 +03:00
Roman Khimov
ae497228f0
core: use native NEO GetValidators for bc.GetValidators
...
NextBlockValidators are updated before the new block persist, so we need to
use GetValidators to get the list corresponding to the current state of the
chain.
2020-07-11 19:54:50 +03:00
Roman Khimov
fedcc6b6fc
transaction: drop old attributes
...
They're not supported in Neo 3. Also change data encoding to base64 following
Neo 3 changes.
2020-07-10 20:40:27 +03:00
Anna Shaleva
789ee2d3c1
core: do not update mempool while verifying tx
...
Closes #1168
2020-07-09 20:45:59 +03:00
Anna Shaleva
4be1009def
core: refactor checkBalanceAndUpdate
2020-07-09 18:27:20 +03:00
Anna Shaleva
e81ccb7deb
rpc: adjust getblock
RPC-call JSON fields names
...
Part of #1130
2020-07-09 17:34:53 +03:00
Anna Shaleva
abe3c94b95
core: use big.Int to store NEP5 balances
...
closes #1133
2020-07-09 13:26:39 +03:00
Anna Shaleva
43b28ffa06
core: get rid of NEP5TransferSize
...
Part of #1133
It will help us to use big.Int to store amount of NEP5 tokens. As far as
big.Int doesn't have constant size, we shouldn't use `NEP5TransferSize`
constant anymore.
2020-07-09 13:25:03 +03:00
Evgenii Stratonikov
5787d7775f
transaction: fail creating tx if there is additional data present
2020-07-03 18:03:57 +03:00
Evgenii Stratonikov
27b3054df4
transaction: set feePerByte on tx construction
2020-07-03 17:52:13 +03:00
Evgenii Stratonikov
3097dc60e5
transaction: cache feePerByte
2020-07-03 17:37:01 +03:00
Anna Shaleva
c421805141
core: fixed typo in method description
2020-06-29 21:40:59 +03:00
Anna Shaleva
0aaaf7f787
*: switch from fixed8 to int64 in (Blockchain).CalculateClaimable
2020-06-29 21:40:54 +03:00
Anna Shaleva
73b630db9b
*: switch from fixed8 to int64
...
Follow C# implementation, we have to marshall JSON Fixed8 fields without
taking into account decimals.
2020-06-29 21:39:27 +03:00
Roman Khimov
8ad355b444
Merge pull request #1124 from nspcc-dev/forward-port-from-2.x
...
Forward port from 2.x
2020-06-29 11:52:45 +03:00
Evgenii Stratonikov
f007cca80b
native: hide native contract methods
...
Copy public keys when returning them to the outside and hide unused
`GetValidators` method.
2020-06-29 10:48:37 +03:00
Evgenii Stratonikov
8c18142e8a
keys: implement PublicKeys.Copy()
...
Implement convenient wrapper over explicit allocation and copying.
2020-06-29 10:44:35 +03:00
Evgenii Stratonikov
bbe02ac584
native: store typed nil
in validators cache
...
Fix `error encountered at instruction 0 (SYSCALL): sync/atomic: store of nil value into Value"`.
2020-06-29 10:37:52 +03:00
Roman Khimov
cab437284d
core: fix TestGetClaimable occasional failures
2020-06-27 12:36:43 +03:00
Roman Khimov
efa8ae5be4
core: fix TestSubscriptions occasional failures
...
panic: Log in goroutine after TestSubscriptions has completed
goroutine 1079 [running]:
testing.(*common).logDepth(0xc00057a100, 0xc00039e210, 0xa4, 0x3)
/usr/local/go/src/testing/testing.go:634 +0x51a
testing.(*common).log(...)
/usr/local/go/src/testing/testing.go:614
testing.(*common).Logf(0xc00057a100, 0xe32eaa, 0x2, 0xc0009560e0, 0x1, 0x1)
/usr/local/go/src/testing/testing.go:649 +0x91
go.uber.org/zap/zaptest.testingWriter.Write(0xf64120, 0xc00057a100, 0x0, 0xc0003fe400, 0xa5, 0x400, 0xc000958e40, 0xc0009560d0, 0xc000958e60)
/go/pkg/mod/go.uber.org/zap@v1.10.0/zaptest/logger.go:130 +0x120
go.uber.org/zap/zapcore.(*ioCore).Write(0xc0005cd050, 0x0, 0xbfb54ffc0626aba2, 0x916de700, 0x1485500, 0x0, 0x0, 0xe43fb0, 0x1c, 0x0, ...)
/go/pkg/mod/go.uber.org/zap@v1.10.0/zapcore/core.go:90 +0x1c5
go.uber.org/zap/zapcore.(*CheckedEntry).Write(0xc000102d10, 0xc00039a000, 0x5, 0x5)
/go/pkg/mod/go.uber.org/zap@v1.10.0/zapcore/entry.go:215 +0x1e8
go.uber.org/zap.(*Logger).Info(0xc00035eba0, 0xe43fb0, 0x1c, 0xc00039a000, 0x5, 0x5)
/go/pkg/mod/go.uber.org/zap@v1.10.0/logger.go:187 +0x96
github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).persist(0xc00000cb40, 0xc00017c2c0, 0xbe8a00)
/go/src/github.com/nspcc-dev/neo-go/pkg/core/blockchain.go:839 +0x6c9
github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).Run.func2(0xc00000cb40, 0xc0005c6c30)
/go/src/github.com/nspcc-dev/neo-go/pkg/core/blockchain.go:302 +0x54
created by github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).Run
/go/src/github.com/nspcc-dev/neo-go/pkg/core/blockchain.go:301 +0x25d
FAIL github.com/nspcc-dev/neo-go/pkg/core 2.463s
2020-06-25 19:22:38 +03:00
Evgenii Stratonikov
978b3c96fe
native: cache GetValidators result
2020-06-24 19:42:50 +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
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
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
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
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
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
a584c5a6a4
native: fix NEP5 contract method prices
...
Closes #1073 .
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
81adb7ce83
core: set price getter for native contract persist routine
2020-06-19 11:38:56 +03:00
Roman Khimov
93b0011988
Merge pull request #1069 from nspcc-dev/addr-locking-and-other-fixes
...
Addr, locking and other fixes
2020-06-18 23:29:19 +03:00
Evgenii Stratonikov
e7d8bb92f6
core/tests: extend native contract test
...
Check if native contract's method price is taken into account.
2020-06-18 22:44:10 +03:00
Evgenii Stratonikov
5354352d63
core: remove transaction priority
...
There is no such thing as high/low priority transactions, as there are
no free transactions anymore and they are ordered by fees contained
in transaction itself.
Closes #1063 .
2020-06-18 22:44:10 +03:00
Evgenii Stratonikov
2f724b792c
core: remove config fields related to free transactions
...
In NEO3 every transaction must have some gas attached.
Closes #1064 .
2020-06-18 22:44:08 +03:00
Roman Khimov
1081791c68
core: fix contract manifest unpacking in System.Contract.Create
...
It's just JSON, io.Serializable is only used for DB storage where the length
should be obtained from the stream. Fixes:
2020-06-18T22:14:10.571+0300 WARN contract invocation failed {"tx": "1ffd475a9c246495d6206cb80a9a78e9d14a433ded60cd37aa87d897655606e1", "block": 25893, "error": "error encountered at instruction 3696 (SYSCALL): failed to invoke syscall: invalid character ':' after top-level value"}
2020-06-18 22:38:34 +03:00
Evgenii Stratonikov
84387b2416
core: set gas limit to transaction.SystemFee for all transactions
2020-06-18 22:17:48 +03:00
Roman Khimov
90d3bcbdc3
state: initialize PublicKey before decoding into it, fix #1061
...
These are pointers and decoding into a nil pointer is a bad idea.
2020-06-18 21:59:58 +03:00
Roman Khimov
dd6895b103
native: optimize GAS onPersist for empty blocks
...
There is no need to get a list of validators when there are no transactions in
the block.
2020-06-18 21:51:29 +03:00
Roman Khimov
f0fbb2d8ff
core: prevent panic on forced exit
...
If we're to close the Blockchain while it's storing a block this might happen:
panic: assignment to entry in nil map
goroutine 63 [running]:
github.com/nspcc-dev/neo-go/pkg/core/storage.(*MemoryStore).put(...)
/home/rik/dev/neo-go/pkg/core/storage/memory_store.go:53
github.com/nspcc-dev/neo-go/pkg/core/storage.(*MemCachedStore).Persist(0xc000673a40, 0x0, 0x0, 0x0)
/home/rik/dev/neo-go/pkg/core/storage/memcached_store.go:118 +0x245
github.com/nspcc-dev/neo-go/pkg/core/dao.(*Simple).Persist(0xc003dbdcc0, 0xc003b18900, 0xc002505538, 0xc001c510e0)
/home/rik/dev/neo-go/pkg/core/dao/dao.go:543 +0x2e
github.com/nspcc-dev/neo-go/pkg/core/dao.(*Cached).Persist(0xc003b189c0, 0xc000240000, 0x0, 0x0)
/home/rik/dev/neo-go/pkg/core/dao/cacheddao.go:169 +0x756
github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).storeBlock(0xc0001f4000, 0xc003611040, 0x0, 0x10)
/home/rik/dev/neo-go/pkg/core/blockchain.go:647 +0xfa2
github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).AddBlock(0xc0001f4000, 0xc003611040, 0x0, 0x0)
/home/rik/dev/neo-go/pkg/core/blockchain.go:447 +0xee
github.com/nspcc-dev/neo-go/pkg/network.(*blockQueue).run(0xc0006f4120)
/home/rik/dev/neo-go/pkg/network/blockqueue.go:48 +0x158
created by github.com/nspcc-dev/neo-go/pkg/network.(*Server).Start
/home/rik/dev/neo-go/pkg/network/server.go:179 +0x2b5
2020-06-18 21:35:17 +03:00
Evgenii Stratonikov
8a0b2be285
core: process NEP5 transfers emitted by Native.onPersist
...
All GAS is minted/burnt during `onPersist` call.
2020-06-18 16:38:08 +03:00
Evgenii Stratonikov
3e76b9a9bf
native: fix Transfer event in burn
...
Tokens should subtract, but transfer amount is positive.
2020-06-18 16:19:09 +03:00
Evgenii Stratonikov
295d8fc70e
core: save application logs for native persist
2020-06-18 15:32:27 +03:00
Evgenii Stratonikov
3894b6db9f
native: take into account native contract method prices
...
Burn gas right before function invoke.
2020-06-18 15:32:27 +03:00
Evgenii Stratonikov
031fd93172
native: fix native contract prices
2020-06-18 15:32:27 +03:00
Evgenii Stratonikov
0fa4c49735
core,native: persist native contract via VM
...
After native contracts are deployed, single persist script is created
and executed at the start of every block persisting.
2020-06-18 15:32:27 +03:00
Roman Khimov
b483c38593
block/transaction: add network magic into the hash
...
We make it explicit in the appropriate Block/Transaction structures, not via a
singleton as C# node does. I think this approach has a bit more potential and
allows better packages reuse for different purposes.
2020-06-18 12:39:50 +03:00
Roman Khimov
8fda6a3407
block: fix ConsensusData hashing
...
It's DoubleSha256 as with the rest of the structures.
2020-06-18 12:22:49 +03:00
Roman Khimov
a7cce3f894
smartcontract: use new VerifiableDecodable for ParameterContext
...
And implement it for Transaction, the only user of ParameterContext for
now. Which make correct signing/verifying possible for cases when
serialization for general transmission and signing differ.
2020-06-18 12:12:56 +03:00
Roman Khimov
0002b65238
block: it's not a padding, but a witness count in the base
...
At least that's the interpretation C# codebase has, so be a bit more correct
in error message.
2020-06-18 12:12:00 +03:00
Roman Khimov
b9a66c64e1
block: drop paddings from structures
...
It makes no sense at all storing them in a structure, they're just a part of
encoding/decoding process.
2020-06-18 12:11:41 +03:00
Roman Khimov
26f11a52d9
config: move NetMode into its own micropackage
...
It's going to be used a bit more and pulling whole config just for one type is
a bit wrong.
2020-06-18 12:09:57 +03:00
Roman Khimov
5f276de003
Merge pull request #1057 from nspcc-dev/fix/newaddress
...
Update addresses to NEO3 format
2020-06-17 16:25:32 +03:00
Evgenii Stratonikov
7b4ca57e33
*: change address to the new format
...
NEO3 uses new prefix for address (53 = 0x35), thus string representations as
well as encrypted WIFs should be changed.
2020-06-17 15:58:21 +03:00
Evgenii Stratonikov
3762ebdd08
core: implement System.Runtime.GetInvocationCounter syscall
2020-06-17 11:24:11 +03:00
Evgenii Stratonikov
75e597f880
core: implement System.Runtime.GetNotifications syscall
2020-06-17 11:24:11 +03:00
Evgenii Stratonikov
a4e4439967
core,vm: implement System.Runtime.GasLeft syscall
2020-06-17 11:24:11 +03:00
Evgenii Stratonikov
a7d4fff897
vm: make (*VM).GasLimit public
...
VM is inherently single-threaded and replacing setter/getter methods
with public field simplifies code a bit.
2020-06-16 15:13:20 +03:00
Evgenii Stratonikov
1f97f3abd8
core: adjust prices and flags for System.Runtime.* interops
...
Related #1055 .
2020-06-16 12:30:55 +03:00
Evgenii Stratonikov
ad2a75a500
core: move System.ExecutionEngine.* interops to System.Runtime.*
2020-06-16 12:30:55 +03:00
Evgenii Stratonikov
52a27e9be4
core: implement System.Contract.CreateStandardAccount syscall
2020-06-16 12:12:29 +03:00
Evgenii Stratonikov
5b4f38d717
core: implement System.Contract.IsStandard syscall
2020-06-16 12:12:27 +03:00
Evgenii Stratonikov
b1d2d70c02
core: adjust prices for blockchain/contract syscalls
2020-06-16 12:04:57 +03:00
Evgenii Stratonikov
6339efac11
core: implement System.Json.* interops
2020-06-16 11:35:06 +03:00
Evgenii Stratonikov
aae312d408
core,vm: adjust prices for iterator/enumerator syscalls
...
Closes #1027 .
2020-06-16 11:05:26 +03:00
Evgenii Stratonikov
18066143bd
core,vm: adjust binary (de-)serialization syscalls
...
Related #1027 .
1. Move System.Runtime.(De)serialize to System.Binary.*
2. Rename compiler stubs.
3. Adjust opcode prices.
2020-06-16 11:00:38 +03:00
Roman Khimov
b3507d490d
Merge pull request #1051 from nspcc-dev/neo3/rpc/scopes
...
core: add json marshaller for Cosigner's scopes
2020-06-15 16:13:48 +03:00
Anna Shaleva
3568ab3d6d
core: add json marshaller for Cosigner's scopes
...
Following C# implementation, we should marshal Scopes as a set of
strings instead of single byte.
2020-06-15 13:48:15 +03:00
Evgenii Stratonikov
2e996ea57d
core: adjust System.Storage.*
interop prices
2020-06-15 12:02:28 +03:00
Evgenii Stratonikov
61bba1a39c
core: store precise gas price in interop descriptions
...
In NEO3 sycalls can have prices less than 10^5, we need to store them
precisely. Adjusting actual prices is to be done in the following tasks.
2020-06-15 12:02:28 +03:00
Evgenii Stratonikov
fd2cd291e7
core: calculate opcode prices correctly
2020-06-15 12:02:22 +03:00
Evgenii Stratonikov
8f20a70969
core: calculate a price of System.Storage.Put
correctly
...
It also depends on the item already stored by key.
2020-06-15 12:02:21 +03:00
Roman Khimov
fe31c7ed2d
Merge pull request #1047 from nspcc-dev/neo3/rpc/invoke
...
rpc: update invoke* RPC-calls
2020-06-11 21:39:20 +03:00
Anna Shaleva
9e7fca013e
rpc: update CLI and RPC client invoke* calls
...
part of #1036
2020-06-11 20:32:05 +03:00
Anna Shaleva
d5355acfa9
rpc: update RPC server invoke* calls
...
part of #1036
2020-06-11 19:34:13 +03:00
Evgenii Stratonikov
971ab0646f
core: specify allowed triggers for interops
...
Related #1026 , #1027 , #1028 , #1031 .
2020-06-11 13:16:07 +03:00
Evgenii Stratonikov
b12add5a78
smartcontract: rewrite trigger types for NEO3
2020-06-11 13:16:07 +03:00
Evgenii Stratonikov
a3b876d55c
native: specify call flags for native contract methods
2020-06-11 13:16:07 +03:00
Evgenii Stratonikov
0dd00a49f5
core: specify require call flags in interop description
...
Related #1026 , #1027 , #1028 , #1031 .
2020-06-11 13:16:07 +03:00
Evgenii Stratonikov
bda94c74c3
vm: check calling flags on syscall invocation
2020-06-11 13:16:07 +03:00
Evgenii Stratonikov
55ab7535be
core: optimize contractCallEx
...
Provide script hash upon script load.
2020-06-11 13:06:10 +03:00
Evgenii Stratonikov
a86e1910e1
core: remove unused interops
...
Missed in #1040 .
2020-06-11 10:51:19 +03:00
Evgenii Stratonikov
f8a11f61b6
core: update *.Contract.* interops
...
1. Remove GetScript, IsPayable, GetStorageContext.
2. Revert 82319538
related to GetStorageContext.
3. Rename Migrate to Update.
4. Move remaining to System.Contract.*.
Related #1031 .
2020-06-11 10:50:35 +03:00
Evgenii Stratonikov
c69f8a2fa3
core: check for permission in System.Contract.Call(Ex)
2020-06-11 10:45:25 +03:00
Evgenii Stratonikov
5514b3f52f
smartcontract,vm: remove DynamicInvoke feature
...
It doesn't exist in NEO3.
2020-06-11 10:45:25 +03:00
Evgenii Stratonikov
a03af55732
core: provide monotonically increasing ID for contracts
...
ID is a contract identifier which doesn't change during migration.
It is also used as a part of storage context instead of contract hash.
2020-06-11 10:45:25 +03:00
Evgenii Stratonikov
20616cc97f
interop: perform contract checks in CheckWitness
2020-06-11 10:45:25 +03:00
Evgenii Stratonikov
7256efd1ed
vm: implement (*VM).AddGas
...
Calculating interop prices can be tricky. It is more convenitent to burn
gas inside interops where necessary parameters are popped.
2020-06-11 10:45:25 +03:00
Evgenii Stratonikov
df958caf93
core: add Manifest to state.Contract
2020-06-11 10:45:24 +03:00
Evgenii Stratonikov
425277098c
native: set ContractID for NEO & GAS contracts
2020-06-10 14:23:25 +03:00
Evgenii Stratonikov
38d020d1a2
core: move Neo.Storage.* interops to System.*
2020-06-10 12:13:35 +03:00
Evgenii Stratonikov
0472a0b0b1
core: move Neo.Runtime/Enumerator/Iterator.* interops to System.*
2020-06-10 12:13:35 +03:00
Evgenii Stratonikov
97c6ac7a73
core: move Neo.Blockchain.* syscalls to System.*
2020-06-10 12:13:18 +03:00
Evgenii Stratonikov
3d3fe9398e
core: remove Neo.Header/Witness/Account.* interops
...
They are not present in NEO3.
2020-06-10 12:13:18 +03:00
Anna Shaleva
8b7abd36c9
core: remove Block.GetTransactions, Block.GetTransactionsCount interops
...
Updated System.Blockchain.GetBlock interop replaced the functionality of
the following interops:
System.Block.GetTransactions
System.Block.GetTransactionCount
Neo.Block.GetTransactions
Neo.Block.GetTransactionsCount
2020-06-09 23:24:11 +03:00
Anna Shaleva
7a2d37cf7e
core: update System.Blockchain.GetBlock interop
...
closes #1025
Now we put on stack stackitem.Array instead of Interop, so we're able to
use all available block properties without extra interop getters.
Removed Neo.Blockchain.GetBlock interop as we don't need it anymore.
2020-06-09 23:24:04 +03:00
Anna Shaleva
e2187c0a96
core: remove Block.GetTransaction interops
...
Removed Neo.Block.GetTransaction and System.Block.GetTransaction
interops. These interops were replaced by new
System.Blockchain.GetTransactionFromBlock interop.
2020-06-09 22:54:21 +03:00
Anna Shaleva
d692de5ea4
core: add System.Blockchain.GetTransactionFromBlock interop
2020-06-09 22:54:16 +03:00
Anna Shaleva
1e63ae4b3f
core: update System.Blockchain.GetTransactionHeight interop
...
Update System.Blockchain.GetTransactionHeight and removed
Neo.Blockchain.GetTransactionHeight interop as we don't need it.
2020-06-09 22:04:18 +03:00
Anna Shaleva
53655c5ac2
core: implement new System.Blockchain.GetTransaction interop
...
closes #1023
Now we put on stack stackitem.Array instead of Interop, so we don't
need old transaction-related interops anymore. Removed the following
interops:
System.Transaction.GetHash
Neo.Transaction.GetAttributes
Neo.Transaction.GetHash
Neo.Transaction.GetWitnesses
Neo.Attribute.GetData
Neo.Attribute.GetUsage
Also removed the following duplicated NEO interop:
Neo.Blockchain.GetTransaction
2020-06-09 22:04:13 +03:00
Anna Shaleva
f2e3be6fef
core: remove old AntShares interops
...
We don't need them anymore.
2020-06-09 20:54:00 +03:00
Roman Khimov
795523f5cd
Merge pull request #1013 from nspcc-dev/neo3/vm/stackitem_refactoring
...
vm: move StackItem to a separate package
2020-06-08 15:30:44 +03:00
Anna Shaleva
4bf103ca12
core: update native contract data serialisation format
...
closes #908
2020-06-08 13:29:35 +03:00
Anna Shaleva
7ca2807875
vm/encoding: move bigint from vm to encoding package
2020-06-08 13:27:13 +03:00
Anna Shaleva
783f5ecb01
vm: move StackItem to a separate package
...
closes #912
2020-06-08 13:27:08 +03:00
Evgenii Stratonikov
138385e512
transaction: encode Script in base64
2020-06-08 10:31:51 +03:00
Evgenii Stratonikov
1fa25efa79
transaction: encode witness scripts in base64
2020-06-08 10:23:56 +03:00
Roman Khimov
63f4f34659
mempool: drop TxWithFee type
...
All the fees are in transaction, this makes no sense.
2020-06-05 19:21:40 +03:00
Roman Khimov
a986e2a064
*: drop support for old on-chain assets
...
You no longer can transfer them, so creating/renewing/storing doesn't make
much sense.
2020-06-05 19:21:37 +03:00
Roman Khimov
bf6435eeaa
storage: drop STValidator prefix, it's not used
2020-06-05 19:20:16 +03:00
Roman Khimov
709146f295
transaction: drop Inputs and Outputs, forget UTXO
2020-06-05 19:20:16 +03:00
Roman Khimov
21efccd300
transaction: remove type field, set Version to 0
...
Two changes being done here, because they require a lot of updates to
tests. Now we're back into version 0 and we only have one type of
transaction.
It also removes GetType and GetScript interops, both are obsolete in Neo 3.
2020-06-05 19:20:16 +03:00
Roman Khimov
dfb26f9ab2
block: don't attempt verification if there was a decoding error
2020-06-05 19:20:16 +03:00
Roman Khimov
f63b286c35
core: update genesis block to store timestamp in ms
2020-06-05 19:20:16 +03:00
Roman Khimov
35b30ccfdf
core: drop OLDPUSH1, it's no longer needed
...
Fixes #927 .
2020-06-05 19:20:16 +03:00