Commit graph

612 commits

Author SHA1 Message Date
Roman Khimov
826a29cc98 rpc: implement client-side getunspents 2019-11-20 16:12:40 +03:00
Roman Khimov
29882b076c rpc: remove duplicating definition of UTXO
Port sorting methods to core.
2019-11-19 17:35:04 +03:00
Roman Khimov
d2bdae99e4
Merge pull request #492 from nspcc-dev/feature/interop_neo_tests1
core: add unit tests for interops_neo
2019-11-18 19:39:05 +03:00
Vsevolod Brekelov
d57b6e1091 core: add unit tests for interops_neo 2019-11-18 19:31:27 +03:00
Roman Khimov
5076704019
Merge pull request #502 from nspcc-dev/docker-compose-environment-for-neo-go
Create docker-compose environment
2019-11-18 17:21:11 +03:00
Evgeniy Kulikov
2f8b11dabf
reformat code at pkg/network/metrics/metrics.go 2019-11-18 17:17:21 +03:00
Evgeniy Kulikov
0a56d3ddbc
network: generate randomized server id
math/rand might generate same id's on one environment, so.. use crypto/rand for generation id's
2019-11-18 17:17:21 +03:00
Roman Khimov
53f666bc13
Merge pull request #504 from nspcc-dev/getunspents
Implement getunspents RPC API
2019-11-18 13:45:33 +03:00
Roman Khimov
5841d3931e rpc: implement getunspents method, fix #473 2019-11-18 11:30:09 +03:00
Evgenii Stratonikov
e3098ed0f8 network: write messages atomically
Right now message can be written in several Write's so
concurrent calls of writeMsg() can in theory interleave.
This commit fixes it.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2019-11-18 09:31:00 +03:00
Evgenii Stratonikov
f65545023d io: restrict ReadArray max array size 2019-11-15 22:39:21 +03:00
Roman Khimov
e4868cd429 core: implement EncodeBinary on value
Fixes panic:
panic: core.NotificationEvent does not have EncodeBinary(*BinWriter)

goroutine 97 [running]:
github.com/CityOfZion/neo-go/pkg/io.(*BinWriter).WriteArray(0xc004f7dda0, 0xabf820, 0xc004f7ddc0)
        /home/rik/dev/neo-go/pkg/io/binaryWriter.go:45 +0x4b7
github.com/CityOfZion/neo-go/pkg/core.(*AppExecResult).EncodeBinary(0xc000635498, 0xc004f7dda0)
        /home/rik/dev/neo-go/pkg/core/notification_event.go:73 +0x9c
github.com/CityOfZion/neo-go/pkg/core.putAppExecResultIntoStore(0xcf0020, 0xc001aafec0, 0xc000635498, 0xc004f81940, 0x40)
        /home/rik/dev/neo-go/pkg/core/notification_event.go:33 +0xab
github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).storeBlock(0xc000118000, 0xc006f89ea0, 0xc006f89ea0, 0x0)
        /home/rik/dev/neo-go/pkg/core/blockchain.go:534 +0x2539
github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).AddBlock(0xc000118000, 0xc006f89ea0, 0xc004f368b0, 0x1)
        /home/rik/dev/neo-go/pkg/core/blockchain.go:256 +0x91
github.com/CityOfZion/neo-go/pkg/network.(*blockQueue).run(0xc0048f4b80)
        /home/rik/dev/neo-go/pkg/network/blockqueue.go:39 +0x14c
created by github.com/CityOfZion/neo-go/pkg/network.(*Server).Start
        /home/rik/dev/neo-go/pkg/network/server.go:133 +0x272
2019-11-15 22:05:09 +03:00
Roman Khimov
1a5731e005 core: rework balance accounting
Store all unspents instead of balance values. Bump store version as this is an
incompatible change.
2019-11-15 22:05:09 +03:00
Roman Khimov
a16c2c3825 core: add NEP5 transfer tracking stub
See #498.
2019-11-15 18:04:59 +03:00
Roman Khimov
01082a8988 core: fix nondeterministic txGetReferences() behavior
Ranging over map is nondeterministic and contracts may be unprepared for
that. Fixes #454.
2019-11-15 18:04:59 +03:00
Roman Khimov
5e8122bfac core: add contract hash into the error output for checkStorageContext()
Makes debugging things easier.
2019-11-15 18:04:59 +03:00
Roman Khimov
64e20508e0 vm: use hex for ByteArray JSON marshallization
It's way more convenient for different purposes.
2019-11-15 18:04:59 +03:00
Roman Khimov
5ce269c035 core: change notify implementation to save notifications
Fixes #453 and makes it possible to refer to these notifications later.
2019-11-15 18:04:59 +03:00
Evgenii Stratonikov
7080b78a6b vm: fix a bug in collection serialize
When encountering already seen stack item we should fail
only if it is a collection. Duplicate Integers or ByteArrays are ok
because they can't lead to recursion.
2019-11-15 12:48:00 +03:00
Evgenii Stratonikov
1a08ad19aa sc: implement io.Serializable for ParamType 2019-11-14 14:20:38 +03:00
Evgenii Stratonikov
2be18f91df util: implement io.Serializable for Uint256 2019-11-14 14:20:38 +03:00
Evgenii Stratonikov
b16e56a47b io: refactor BinReader.ReadArray()
Make it accept arbitrary slice pointer.
2019-11-14 14:19:58 +03:00
Evgenii Stratonikov
085ca7b770 network: implement Consensus payloads 2019-11-13 17:27:25 +03:00
Evgenii Stratonikov
ad9091d13d io: implement generic array (de-)serialization
It is done through reflection and panics
in every unexpected situation.
2019-11-13 17:27:23 +03:00
Evgenii Stratonikov
61fdd5cde5 util: make Uint256Size public 2019-11-13 17:09:55 +03:00
Roman Khimov
394346fc26 core: add proper claim transactions processing 2019-11-11 15:35:57 +03:00
Roman Khimov
b05754deac core: add Close() to blockchainer, implement it to properly close chain
Before it the deferred function in Run() was actually never able to properly
close the Store, so we weren't synching the latest state to the disk.
2019-11-08 12:19:54 +03:00
Evgenii Stratonikov
816d78b5ee vm: redefine SHL/SHR limits based on integer size 2019-11-07 12:50:11 +03:00
Evgenii Stratonikov
439cd72294 vm: restrict BigInteger item size 2019-11-07 12:34:27 +03:00
Vsevolod
f686069f37
Merge pull request #481 from nspcc-dev/core-fix-init-corner-cases
Fix init corner cases
2019-11-06 18:36:40 +03:00
Vsevolod
11b372b45d
Merge pull request #480 from nspcc-dev/handshake-wait-for-version
network: wait for both Version messages before ACKing
2019-11-06 18:33:20 +03:00
Roman Khimov
c567307748 core: fix potential issue with header list init
If we're to receive some 500 headers (less than `headerBatchCount`) and quit
before receiving more of them we end up with clean `bc.headerList` that will
be inited going backwards to the `targetHash`, but code path doesn't add add
the `targetHash` itself which it should do in this particular case, otherwise
we end with no genesis block hash in the list.
2019-11-06 18:13:45 +03:00
Roman Khimov
d7f747fa9a network: wait for both Version messages before ACKing
Otherwise the node might crash in `startProtocol` because of missing Version
field in the peer. And it also keeps the sequence correct, Version MUST be
sent first and ACKs can only follow it.
2019-11-06 18:05:50 +03:00
Roman Khimov
b5199625cd core: init genesis block header if there are no other headers in DB
Fixes crash when restarted after the DB initialization and no blocks written
into the DB.
2019-11-06 17:58:19 +03:00
Roman Khimov
c16c2bf102 core: store current header reference on clean init
Missing it the following line could fail on subsequent restarts:

        currHeaderHeight, currHeaderHash, err := storage.CurrentHeaderHeight(bc.store)

if the node was stopped before any headers had been received.
2019-11-06 17:56:06 +03:00
Roman Khimov
c062a8e288
Merge pull request #470 from nspcc-dev/config_updates_460
config: use logpath and address for server/rpc/monitoring, fix #460.
2019-11-06 17:30:01 +03:00
Vsevolod Brekelov
d799c98cfe io: move common function and add unit tests for it 2019-11-06 17:12:33 +03:00
Roman Khimov
aeef395c45
Merge pull request #476 from nspcc-dev/feature/neoUT
VM: Use JSON-based tests from neoVM

After the implementation of stack limits nothing is needed for us to pass reference JSON tests :)
The only thing that differs --- we do not compare stack in case of FAULT (which matches NEO 3 behavior).
Also two commits were reverted to match 2.x VM behavior.
2019-11-06 16:42:06 +03:00
Evgenii Stratonikov
6c002297cd vm: implement json tests from neoVM
Add neo-vm submodule @master2.x .
Closes #196.
2019-11-06 16:22:56 +03:00
Roman Khimov
9f7625d699 core: don't do useless DB reads if nothing was persisted 2019-11-06 16:10:37 +03:00
Roman Khimov
90d4299f0b core: gofmt blockchain.go 2019-11-06 16:09:45 +03:00
Vsevolod Brekelov
11ce73af28 server: add log-path and address configuration
- LogPath can be configured through config
- node,rpc and monitoring address can be configured thought command line
or config
2019-11-06 15:58:54 +03:00
Roman Khimov
79d0c7446a
Merge pull request #478 from nspcc-dev/handshake-and-peers-fix
Fixes #458, MaxPeers handling and some other related things.
2019-11-06 15:42:02 +03:00
Roman Khimov
7cf9a40468 network: fix MaxPeers, introduce AttemptConnPeers
Our node didn't respect the MaxPeers setting, fix it with a drop of random
connection when this limit is reached (to give a chance for newcomers to
communicate), but also introduce AttemptConnPeers setting to tune the number
of attempted connections.

This also raises the default MaxPeers for testnet/mainnet to 100, because
neo-go nodes love making friends.
2019-11-06 15:29:58 +03:00
Roman Khimov
31954bb20c network: disallow double connections to the same peer
Makes no sense and C# node does it too.
2019-11-06 15:29:58 +03:00
Roman Khimov
d5a7ad2c47 network: fix data race in server peers map access 2019-11-06 15:29:58 +03:00
Roman Khimov
ec76ed23a5 network: rework peer handshaking, fix #458
This allows to start handshaking from both client and server (mainnet/testnet
nodes were seen to not care about string ordering for it), but still maintains
some sane checks in the process. It also makes functions thread-safe because
we have two goroutines servicing read and write side of the Peer connection,
so they can clash on access to the struct fields.

Add a test for it also.
2019-11-06 15:29:58 +03:00
Roman Khimov
e859e03240 network: split Peer's NetAddr into RemoteAddr and PeerAddr
As they are different things used for different purposes.
2019-11-06 15:26:24 +03:00
Roman Khimov
0296184da9
Merge pull request #475 from nspcc-dev/unitTests_wallet
Improve wallet unit testing.
2019-11-06 15:24:10 +03:00
Vsevolod Brekelov
75104a4a34 wallet: add unit tests 2019-11-06 13:15:47 +03:00
Evgenii Stratonikov
7d40d2f71e vm: make StepOut/StepOver match original VM behavior 2019-11-06 12:25:04 +03:00
Evgenii Stratonikov
9ebb793009 vm: revert SUBSTR offset behavior to NEO 2.x 2019-11-06 12:15:55 +03:00
Evgenii Stratonikov
4c688355bc vm: revert bool -> []byte conversion to NEO 2.x 2019-11-06 12:15:48 +03:00
067d9655bf vm: restrict total stack item count 2019-11-06 11:03:43 +03:00
ed758458d5 vm: implement serialization interops in core package 2019-11-05 17:10:52 +03:00
412582dc78 vm: add more serialization tests 2019-11-05 17:04:14 +03:00
59f9c2bddc vm: implement Array and Struct item serialization 2019-11-05 16:58:09 +03:00
e1d019e087 vm: implement Map item serialization 2019-11-05 16:57:48 +03:00
cd690803cf vm: implement BigInteger item serialization 2019-11-05 15:15:43 +03:00
25f77257ce vm: implement Boolean and ByteArray item serialization 2019-11-05 15:15:39 +03:00
Roman Khimov
de2eeb4671 rpc: add one to the block height for the getblockcount response
There is a difference in interpretation of what a block count is. neo-go nodes
currently respond to this request with the latest block number which is the
same number that neoscan.io shows. However, C# nodes deliberately do add one
to this number when answering to the getblockcount request to account for the
genesis block number 0.

This patch makes us consistent with C# nodes wrt to getblockcount behaviour.
2019-11-01 20:13:00 +03:00
Roman Khimov
70e4529848 rpc: add 0x prefix to the getbestblockhash answer
For consistency with C# nodes that do add it to their answers.
2019-11-01 20:12:44 +03:00
Roman Khimov
e9f8b25776 network: add default MinPeers
If there is nothing specified in the configuration, set it to some reasonable
value.
2019-11-01 13:39:47 +03:00
Roman Khimov
b46dd295bc rpc: add CORS workaround for RPC
This one enables our RPC to be called from the browser if there is a
need. It's insecure and not standards-compliant, thus this behaviour is
configurable is not enabled by default. It makes our node with this workaround
enabled compatible with neo-mon monitoring.

Originally debugged by @anatoly-bogatyrev in #464.
2019-11-01 13:39:47 +03:00
Roman Khimov
b12a68994d network: make minpeers configurable
Without it node in privnet tries to reconnect to four existing nodes
indefinitely for no good reason.
2019-10-31 15:10:00 +03:00
Roman Khimov
2f6e678a19
Merge pull request #463 from nspcc-dev/smartcontract-fixes
Smartcontract RPC fixes
2019-10-29 20:54:46 +03:00
Roman Khimov
6d1a09183b
Merge pull request #455 from nspcc-dev/prometheus_441
add prometheus monitoring, fix #441
2019-10-29 20:54:29 +03:00
Vsevolod Brekelov
d374175170 monitoring: add prometheus monitoring
add init metrics service which uses prometheus;
add configuration for metrics service;
add monitoring metrics for blockchain,rpc,server;
2019-10-29 20:51:17 +03:00
Roman Khimov
ebc1ba4f38 rpc/core: implement invokescript method, fix #348
Extend Blockchainer with one more method to spawn a VM for test runs and use
it to run scripts. Gas consumption is not counted or limited in any way at the
moment (see #424).
2019-10-29 18:31:39 +03:00
Roman Khimov
94776b8a1f vm: add MarshalJSON to the Stack
To easily dump it in a known format.
2019-10-29 18:26:59 +03:00
Roman Khimov
47f66dfbf3 vm: add State() method to get a state description 2019-10-29 18:26:04 +03:00
Roman Khimov
a568740f56 core: deduplicate a part of VM setup into spawnVMWithInterops() 2019-10-29 17:10:50 +03:00
Roman Khimov
3d6cf3a647 rpc: drop useless cases from server
Let them be handled by `default` statement returning a proper error instead of
plaintext message.
2019-10-29 16:48:14 +03:00
c7f0b7bd68 vm: restrict max invocation stack size 2019-10-29 15:09:17 +03:00
Roman Khimov
579aa31ddd compiler: drop useless options parameter to Compile()
It's not used in any way there.
2019-10-29 13:02:54 +03:00
Roman Khimov
e319c6c638 cli: move avm inspect from vm to contract command
Make inspect work with avms by default and with go files if told so. In the
end this makes our CLI interface more consistent and usable. Drop useless
CompileAndInspect() compiler method along the way.
2019-10-29 12:56:44 +03:00
Roman Khimov
ae7687422c vm: clear state in Load()
Make VM usable after the first run.
2019-10-29 12:53:09 +03:00
Roman Khimov
006337b1f8 network: rework discovery with rwmutex, add test
Keeping run() as the owner of all maps would mean adding at least three more
channels to keep address getters with thread-safety. But then there also is a
race between requestToWork() and run() which is way harder to solve with
channels because there are lots of possibilities for deadlocks. So rework all
of this with good old mutexes.

While at it, fix `requestCh` handling in the inner select of run, it will waste
one loop to handle it, so we should add one to the `requested`.

Fixes #445.
2019-10-28 13:37:27 +03:00
Roman Khimov
77a50d6dc6 network: remove useless checks in discovery
These are useless.
2019-10-27 16:11:32 +03:00
Roman Khimov
a48e297252
Merge pull request #451 from nspcc-dev/call-isolation
vm: implement stack isolation opcodes, fix #192
2019-10-25 18:27:08 +03:00
Roman Khimov
f0cffe0d3f vm: implement stack isolation opcodes, fix #192
No tests yet.
2019-10-25 18:25:12 +03:00
Roman Khimov
99bbad331d core: add issue tx processing
Count available asset quantity, match C# code.
2019-10-25 17:20:12 +03:00
Roman Khimov
2611e9ab5c smartcontract: fix PropertyState definitions
Wrong bits were used to represent flags which is important for contracts
created via interop. Fixes contracts failing to store things:

WARN[16278] contract invocation failed                    block=3773025 err="error encountered at instruction 3435 (SYSCALL): failed to invoke syscall: contract c9d870d7857e956d82290d5df19de3133c107815 can't have storage" tx=fa695eea240b7b4dbb6f42ea6335447a764d8b629c40b7812ea3bca16b1f098d
WARN[16278] contract invocation failed                    block=3773025 err="error encountered at instruction 1279 (SYSCALL): failed to invoke syscall: contract 97210e7c98582151ceb37f9748c9a1d27d9ae6fd can't have storage" tx=0144d84038149fa0cf1f7912f7d5854fa5f3670f5b4217789c1441f9fd52d27b
2019-10-25 11:05:58 +03:00
Roman Khimov
9ff55ac02c network: move inventory semantic check into common code
As per @volekerb suggestion.
2019-10-24 13:12:02 +03:00
Roman Khimov
45cac07643 core: remove transactions from MemPool when they're stored in block
Extend MemPool with Remove() and use it. Fixes #446.
2019-10-24 13:12:02 +03:00
Roman Khimov
184d8a0180 core: fix missing unlock in MemPool TryAdd()
Fixes deadlock on subsequent MemPool operations.
2019-10-24 13:12:01 +03:00
Roman Khimov
257ba1c2ad network: implement getdata message handling in server
To properly implement relaying we need to answer these requests from other
nodes.
2019-10-24 13:12:01 +03:00
Roman Khimov
8d0ed9259c transaction: fix invocation TX consistency in NewInvocationTX()
NewInvocationTX() returned a version number one transaction that actually
failed to pass that version down to the invocation data which lead to
serialization/deserialization inconsistency.
2019-10-23 14:50:24 +03:00
Roman Khimov
1250bf9579
Merge pull request #443 from nspcc-dev/spellcheck
spellcheck and comments fix
2019-10-22 18:01:40 +03:00
Vsevolod Brekelov
8ee421db14 fix spelling and godoc comments 2019-10-22 17:56:03 +03:00
Roman Khimov
a9a2a3c711 vm: fix tests failing, follow-up to #426
Deal with input and transitional VM states properly.
2019-10-22 15:20:44 +03:00
Roman Khimov
3cbb699eb7
Merge pull request #426 from nspcc-dev/logger_247
Change fmt.Println to log, close #247.
2019-10-22 14:41:30 +03:00
Roman Khimov
558a25cbd2
Merge pull request #438 from nspcc-dev/fix/437
vm: copy slice in NEWARRAY/NEWSTRUCT

Fixes #437.
2019-10-22 14:36:32 +03:00
Vsevolod Brekelov
e2bfff8666 vm: removed mute mode and pushed logging to upper lvl
VM should be responsible for code execution and in case anyone interested in additional logging or errors they could handle them like we do it iin cli.
2019-10-22 13:44:14 +03:00
Evgenii Stratonikov
b2609786e9 vm: copy slice in NEWARRAY/NEWSTRUCT
When performing NEWARRAY on a Struct or NEWSTRUCT on a Array,
underlying slice needs to be copied, because when it's capacity
doesn't matches it's length, underlying storage will be used
for appends even if it is already pointed at by another slice.
2019-10-22 13:34:35 +03:00
Roman Khimov
f1750d117b
Merge pull request #440 from nspcc-dev/db-dump-restore
DB dump and restore, fixes #436.
2019-10-21 15:42:05 +03:00
Vsevolod Brekelov
f2805541cb vm: fix style and comments 2019-10-21 14:22:17 +03:00
Roman Khimov
07c2105aa5 core: log values from the store in persist()
We're about stored values here, so print those, which avoids blocking in
bc.HeaderHeight() and removes duplication between blockHeight and
persistedHeight. Fixes saving the blockchain on exit (deferred function in
Run() blocked in persist()).

Test modification was required because storeBlocks() doesn't actually save
headers and thus TestGetTransaction started to fail on persist().
2019-10-21 14:18:09 +03:00
Roman Khimov
70407f0c19 core: remove unused context parameter from persist() 2019-10-21 14:18:09 +03:00
Vsevolod Brekelov
063fe5be9d unspentcoinstate: fix branch never executed 2019-10-21 12:40:11 +03:00