Commit graph

631 commits

Author SHA1 Message Date
Vsevolod Brekelov
100fee164b unitTest: reworked RPC unit test
earlier we had an issue with failing test in #353 and other one #305.
Reworked these test to have in-memory database. This led to multiple
changes: made some functions like Hash and Persist public(otherwise
it's not possible to control state of the blockchain); removed
unit_tests storage package which was used mainly for leveldb in unit
tests.
I see these tests not really good since they look like e2e tests and
as for me should be run in separate step against dockerized env or
in case we want to check rpc handler we might want to rework it in order
to have interface for proper unit tests.
As for me this patchset at least makes as safe with not removing totally
previous tests and at the same time CircleCI will be happy now.
2019-09-18 18:21:16 +03:00
Vsevolod Brekelov
55dfc0bbbc storage: add seek implementation
during testing found missing Seek() implementation for inmemorydb
2019-09-18 18:20:41 +03:00
Vsevolod
8e75674f30
Merge pull request #401 from nspcc-dev/refactor_bc_run
blockchain: server runs goroutine instead of blockchain init
2019-09-17 16:26:06 +03:00
Roman Khimov
7b4daed990
Merge pull request #402 from nspcc-dev/tiny-technical-corrections
This one updates go.mod/go.sum (as any build at the moment gives changes
to these files) and makes some source code files non-executable.
2019-09-17 15:52:48 +03:00
Roman Khimov
bd1f70366a crypto: change files mode to 644 (some *.go had exec flags set) 2019-09-17 15:34:00 +03:00
Roman Khimov
aa0c765be9 go.mod/sum: update and tidy 2019-09-17 15:31:59 +03:00
Vsevolod Brekelov
adc880d323 blockchain: server runs goroutine instead of blockchain init
rework initBlockChain in order to have controllable way of running
blockchain;
remove context from initBlockChain func;
2019-09-17 15:27:40 +03:00
Roman Khimov
39a024eb03
Merge pull request #400 from nspcc-dev/move-rw-to-io
Move BinReader/BinWriter to io and simplify things

BinReader and BinWriter don't belong to util, actually util shouldn't
exist at all. Moving them to io and using them for all encoding/decoding
purposes allows to simplify a lot of code, especially in the error
handling space. These interfaces are designed to absorb errors until
someone can do something meaningful with them (usually that's the top
caller of encode/decode functions) and our current use of them is
inconsistent.

This patchset moves BinReader/BinWriter and size calculations (that
are mostly about Serializable things) to io package and makes all the
other code use them for encoding/decoding purposes.
2019-09-17 15:08:15 +03:00
Roman Khimov
5bca4d2313 io: expand panic tests to reach 100% coverage 2019-09-17 13:23:24 +03:00
Roman Khimov
96618015cd network: implement EncodeBinary() for MerkleBlock 2019-09-17 13:21:52 +03:00
Roman Khimov
d1a4e43c48 io: redo Serializable to return errors in BinReader/BinWriter
Further simplifies error handling.
2019-09-17 13:21:52 +03:00
Roman Khimov
0bb8950f89 make TXer and Payload implement Serializable
Both are duplicating Serializable at the moment, but let's keep them for the
future.
2019-09-17 13:21:52 +03:00
Roman Khimov
e299a44983 io: drop Size() method from Serializable and associated
It's no longer needed after the io.GetVarSize() improvement. It's duplicating
a lot of EncodeBinary() logic also.
2019-09-17 13:21:45 +03:00
Roman Khimov
56c72b5c67 io: redo GetVarSize for Serializable things
Use writes to a fake io.Writer that counts the bytes. Allows us to kill Size()
methods as useless and duplicating lots of functionality.
2019-09-16 23:39:54 +03:00
Roman Khimov
0da9fe6946 io: move size calculator there
It's mostly used for Serializable and in other cases where one needs to
estimate binary-encoded size of the stucture. This also simplifies future
removal of the Size() from Serializable.
2019-09-16 23:39:54 +03:00
Roman Khimov
5bf00db2c9 io: move BinReader/BinWriter there, redo Serializable with it
The logic here is that we'll have all binary encoding/decoding done via our io
package, which simplifies error handling. This functionality doesn't belong to
util, so it's moved.

This also expands BufBinWriter with Reset() method to fit the needs of core
package.
2019-09-16 23:39:51 +03:00
Roman Khimov
f01354b5bd core: make TestHeaderEncodeDecode use assert for field comparisons 2019-09-16 23:38:48 +03:00
Roman Khimov
031a260cb1 util: add tests for BinaryReader/BinaryWriter
100% coverage.
2019-09-16 23:38:48 +03:00
Roman Khimov
72fc880182 util: remove bogus check from BinWriter.WriteVarUint()
val is uint64, it can't be less than zero by definition.
2019-09-16 23:38:48 +03:00
Roman Khimov
aacf58c9ab util: add 'constructors' for BinReader/BinWriter
And an additional BufBinWriter to ease buffer management.
2019-09-16 23:38:48 +03:00
Roman Khimov
0838948540
Merge pull request #394 from nspcc-dev/fix/json-tests-bugs
VM: fix some bugs from neo-vm JSON tests
2019-09-16 19:46:12 +03:00
Roman Khimov
c98a626871
Merge pull request #399 from nspcc-dev/refactor_store
storage: refactor store, add Close()
2019-09-16 18:59:34 +03:00
Vsevolod Brekelov
264dfef370 storage: close function
add close function to storage interface
add common defer function call which will close db connection
remove context as soon as it's not needed anymore
updated unit tests
2019-09-16 18:52:47 +03:00
Roman Khimov
adba9e11ee
Merge pull request #396 from nspcc-dev/network-reconnections-and-fixes
This one fixes #390 and some connected problems. After this patchset the node reconnects to some other nodes if anything goes wrong and it better senses when something goes wrong. It also fixes some block handling problems based on the testnet connection experience.
2019-09-16 16:57:10 +03:00
Roman Khimov
b9ff4d929c network: add getaddr message handling
Respond with known good addresses.
2019-09-16 16:32:04 +03:00
Roman Khimov
b2530a4c93 network: be more specific on port mismatch error 2019-09-16 16:32:04 +03:00
Roman Khimov
773ccc2b92 network: allow discoverer to reuse addresses
...and don't try to connect to the nodes we're already connected to.

Before this change we had a problem of discoverer throwing away good valid
addresses just because they are already known which lead to pool draining over
time (as address reuse was basically forbidden and getaddr may not get enough
new nodes).
2019-09-16 16:32:04 +03:00
Roman Khimov
46dc141c6c network: enlarge address request queue
Queuing one message is not reliable enough, the peer that gets it can fail to
actually make a request, so make this queue a bit deeper to have a higher
chance of success.
2019-09-16 16:32:04 +03:00
Roman Khimov
d3bb8ddf8f network: handle errors and connection close more correctly
This makes writer side handle errors properly and fixes communication between
reader and writer goroutine to always correctly unregister the peer. This is
especially important for the case where error occurs before handshake
completes as in this case we don't even have goroutine in startProtocol()
running.
2019-09-16 16:32:04 +03:00
Roman Khimov
76c7cff67f network: make node strictly follow handshake procedure
Don't accept other messages before handshake is completed, check handshake
message sequence.
2019-09-16 16:32:04 +03:00
Roman Khimov
c6487423ae network: close connection on disconnect
If it's already closed, this won't hurt, but in the case of logical error it
saves us from leaking this connection (and potentially, peer).
2019-09-16 16:26:30 +03:00
Roman Khimov
90e13debe4 network: implement getaddr sends and addr receival
Request new addresses if we're short on known addresses pool size.
2019-09-16 16:26:30 +03:00
Roman Khimov
2a49e68d77 network: start worker goroutine for every connection attempts
Prevents blocking on write to workCh which can be dangerous for the server.
2019-09-16 16:26:30 +03:00
Roman Khimov
b4e284f301 discovery: make pool management more reliable
Just drop excessive addresses, otherwise we can block for no good reason.
2019-09-16 16:26:30 +03:00
Roman Khimov
85f19936dd network: implement connection retries
It's worth to try a bit more than once.
2019-09-16 16:26:30 +03:00
Roman Khimov
be6c905e5d network: use and improve discovery mechanism for reconnections
This makes our node reconnect to other nodes if connection drops for some
reason. Fixes #390.
2019-09-16 16:26:30 +03:00
Roman Khimov
b263c97bbb core: add some mechanism to drop bad blocks from cache
If we can't persist anything from our cache there is something wrong with
it. Try to remediate some possible problems.
2019-09-16 16:26:30 +03:00
Evgenii Stratonikov
d2ccc3b017 vm: make REVERSE consume an item from stack 2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
fd264cb06f vm: make REVERSE work with structs
Also add more tests.
Extend `Array` method of `Element` to work with `StructItem`.
2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
f0426ac2d5 vm: do nothing if SHL/SHR by 0 2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
9eca5ee317 vm: convert SIZE argument to bytearray 2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
9780889239 vm: make NEWARRAY/NEWSTRUCT accept bytearray 2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
09e197eaf3 vm: make PUSH0 create empty bytearray
Also make tests expect []byte{} instead of 0.
2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
66501f9ef9 vm: make REMOVE consume array from stack 2019-09-16 15:50:14 +03:00
Evgenii Stratonikov
71cfd14b92 vm: create an array of false items in NEWARRAY/NEWSTRUCT 2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
bafdb916a0 vm: make PICKITEM accept bytearrays 2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
1881adabb9 vm: fail if NIP has not enough arguments 2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
6e4014547d vm: fail if DROP has no argument 2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
729b7a0b24 vm: fail if ROT has not enough arguments 2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
cf7fbb80ba vm: fail if EQUAL has not enough arguments 2019-09-16 15:24:58 +03:00