Commit graph

612 commits

Author SHA1 Message Date
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
Evgenii Stratonikov
d257044298 vm: fail if XTUCK argument is 0 2019-09-16 15:24:58 +03:00
Roman Khimov
b21a220712
Merge pull request #381 from nspcc-dev/add_boltd
storage: add boltdb support, closes #335.
2019-09-14 13:00:52 +03:00
Vsevolod Brekelov
2cabd5b274 storage: add boltDB unit tests 2019-09-14 10:29:08 +03:00
Vsevolod Brekelov
bfe5fd538e storage: add boltDB support
closes #335
2019-09-14 10:28:43 +03:00
Roman Khimov
cd3d22d150
Merge pull request #395 from nspcc-dev/fix/append-codegen
VM: fix codegen for APPEND

After changes in #391 some tests started to fail. This PR fixes codegen for APPEND.
2019-09-13 18:32:55 +03:00
Evgenii Stratonikov
56ec097d76 vm: fix codegen for APPEND 2019-09-13 11:24:21 +03:00
Roman Khimov
521a707e33 core: don't print contracts in persistBlock()
Yeah, this really needs more love, but for now just don't spit 'em out on the
screen, please.
2019-09-12 16:12:12 +03:00
Roman Khimov
d0ffd165fd
Merge pull request #393 from nspcc-dev/assorted-db-handling-fixes-and-optimizations
Assorted db handling fixes and optimizations based on the testnet
connection experience.
2019-09-11 22:31:19 +03:00
Roman Khimov
4395cea344 storage: fix reading overlapping hash blocks from the DB
In the unlikely event of overlapping hash block written to the DB we might end
up with wrong hash list. That happened to me for some reason when synching
with the testnet leading to the following keys with respective values:
  150000 -> 2000 hashes
  152000 -> 2000 hashes
  153999 -> 2000 hashes

Reading it hashes number 153999 and 154000 got the same values and the chain
couldn't sync correctly.
2019-09-11 20:33:41 +03:00
Roman Khimov
4f60fd3e8e core: optimize persist() for the case when no next block found
If there is no next block in the cache, looping through the whole cache won't
help.
2019-09-11 20:32:30 +03:00
Roman Khimov
7812fb28ea core: optimize blockchain init with existing DB
There is no need to generate genesis block (it's already in the DB) and we can
add all hashes at once without iterating over them.
2019-09-11 20:28:49 +03:00
Roman Khimov
6855e4e07a
Merge pull request #392 from nspcc-dev/fix/bug-append
VM: APPEND should push no value on stack. Fixes #391.
2019-09-11 19:02:05 +03:00
Evgenii Stratonikov
68c6c93980 vm: do not allow APPEND to operate on bytearray 2019-09-11 17:17:37 +03:00
Evgenii Stratonikov
723dcc6e25 vm: make APPEND push no value on stack 2019-09-11 17:17:34 +03:00
Roman Khimov
6f7e565b45
Merge pull request #389 from nspcc-dev/update-config-seeds
config: update mainnet and testnet seed lists
2019-09-11 15:15:06 +03:00
Roman Khimov
9281348846 config: update mainnet and testnet seed lists
Sync with neo-cli (master-2.x) branch.
2019-09-11 15:10:02 +03:00
Roman Khimov
794d375bfd
Merge pull request #388 from nspcc-dev/substr-left-indexes
VM: harden substr/left/right against bad indexes and improve
PUSHDATA along the way. Fixes #387.
2019-09-11 14:52:48 +03:00
Roman Khimov
8311bda355 vm: harden LEFT and RIGHT implementations against negative indexes 2019-09-11 14:51:04 +03:00
Roman Khimov
17f3a21e27 vm: harden SUBSTR implementation against bad index/offset values
The upper index bound for slices is capacity, not length. Check for negative
values also. Fixes #387.
2019-09-11 14:37:41 +03:00