Commit graph

1143 commits

Author SHA1 Message Date
Roman Khimov
77624a8847 network: add Close() to discoverer, shut it down on exit 2020-02-28 16:22:04 +03:00
Evgenii Stratonikov
624a14f730 rpc: rename (*Client).SendToAddress to TransferAsset
SendToAddress name is similar to the `sendtoaddress` RPC call,
this can cause confusion.

Closes #686.
2020-02-28 14:16:39 +03:00
Roman Khimov
3e2b490025 mempool: rework inputs verification, check Claim txes
Use more efficient check for Input and also check Claims to avoid double
claiming.
2020-02-27 13:43:35 +03:00
Roman Khimov
f329de73e8 mempool: fix Remove bug (dropping wrong tx!)
Uncovered by TestMemPoolAddRemoveWithInputsAndClaims (to be added later)
2020-02-27 13:43:35 +03:00
Roman Khimov
7d59fa0066
Merge pull request #696 from nspcc-dev/tx-verification-fixes
Claim and enrollment TX verification fixes
2020-02-27 12:45:36 +03:00
Roman Khimov
00d199ed85 core: fix NetworkFee calculation
Add doesn't change the variable state. Thanks to GolangCI for catching this.
2020-02-27 12:32:56 +03:00
Roman Khimov
7bea6e043e core: add double claim verification check 2020-02-27 12:32:56 +03:00
Roman Khimov
29586f2aa7 core: add duplicate Claim verification check
Refactor HaveInputsDuplicate() out of the core and Blockchain, it doesn't
depend on the Blockchain state. Make it more efficient.
2020-02-27 12:32:56 +03:00
Roman Khimov
9b1ad40273 core: drop GetScriptHashesForVerifyingClaim, fix Claim's ScriptHash getter
Claim transactions should _add_ claims scripthashes to the standard list, not
replace them. And this code is actually very reusable.
2020-02-27 12:32:56 +03:00
Roman Khimov
9f7018503a core/transaction: use new transaction.InOut for References
We don't need a map here, use simpler structures.
2020-02-27 12:00:03 +03:00
Roman Khimov
80de208a68 transaction: unbind GroupInputsByPrevHash from Transaction
Which allows to use it for ClaimTX. Make it also a bit more efficient as maps
are expensive.
2020-02-27 12:00:03 +03:00
Roman Khimov
71a18b1727
Merge pull request #688 from nspcc-dev/fix/jmplabels
compiler: use uint16 for labels
2020-02-27 00:28:46 +03:00
Roman Khimov
b1b184f77f
Merge pull request #692 from nspcc-dev/persist-timer-fix
core: reschedule the next persist in a second from previous one
2020-02-26 10:34:40 +03:00
Roman Khimov
2f2a4afe21
Merge pull request #693 from nspcc-dev/memorystore-seek-lock
storage: add locking into (*MemoryStore).Seek
2020-02-26 10:15:40 +03:00
Roman Khimov
c258adb532 core: move spent coin management out of the inner storeBlock loop
prevHash == input.PrevHash, so make less DB accesses and more real work. Fix
some bugs along the way:
 * spentCoins structure may already be present in the DB when persisting TX,
   there is nothing wrong with that and we shouldn't overwrite it
 * it's only used for NEO and only to check for claim validity. Thus, when
   processing claim tx the corresponding spentCoins should always be present
   in the DB
2020-02-25 17:21:09 +03:00
Roman Khimov
36c6b6af14 core: put unspents get/put one loop above in storeBlock
Everywhere in this code prevHash == input.PrevHash, thus we can easily move
some common code out of the loop saving on DB accesses and
serialization/deserialization.
2020-02-24 18:53:10 +03:00
Roman Khimov
5c9681508b transaction: strip off a layer of redirection from ClaimTX.Claims
We don't need a pointer here and this change makes this field compatible with
Transaction.Inputs which is useful in many scenarios.
2020-02-24 18:22:27 +03:00
Roman Khimov
ed9e9e8590 storage: add locking into (*MemoryStore).Seek
It was missing there.
2020-02-24 17:51:50 +03:00
Roman Khimov
b49808b766 core: reschedule the next persist in a second from previous one
It makes little sense queueing up several persistence goroutines (or actually
even running them concurrently).
2020-02-24 17:17:25 +03:00
Roman Khimov
e2116e4c3f network: don't deadlock on connection overflow
(*Peer).Disconnect send an unregister signal to this goroutine, so invoking it
from here is not a good idea, run it asynchronously.
2020-02-24 15:56:49 +03:00
Roman Khimov
d5e6028c13 core: add validator public key into the list of hashes to verify
That should be done for Enrollment transactions.
2020-02-21 20:04:16 +03:00
Anna Shaleva
76a0a6e7e8 rpc: implement getblocksysfee RPC
Closes #341
2020-02-21 18:45:52 +03:00
Evgenii Stratonikov
177b725dc1 compiler: make writeJumps return error for bad jumps
The script is invalid anyway so it is better to notify user.
2020-02-21 17:45:45 +03:00
Evgenii Stratonikov
5e229d84d4 compiler: use uint16 for label numbers
As noted in #687 this will make compiler a bit more predictable.
2020-02-21 17:45:45 +03:00
Roman Khimov
8da20055d6 rpc: drop duplicating structures used in tests
We have proper results now, so use those. The only left is Invoke, but that
depends on another issue at the moment.
2020-02-21 15:23:11 +03:00
Roman Khimov
6a3be6081c smartcontract: support "ByteArray" string for ByteArrayType
We actually do emit it ourselves in String()
2020-02-21 15:23:11 +03:00
Roman Khimov
3fa9de764b rpc/client: only return the Result from calls, handle Error internally
Adjust structures accordingly and throw away most of them, they're useless.
2020-02-21 15:23:11 +03:00
Roman Khimov
28a26d2cae rpc/client: look into data first, then HTTP error code
In case of error our own server responds with an HTTP error and proper
JSON-RPC error in the body, so look there first as it has more specific data.
2020-02-21 15:12:04 +03:00
Roman Khimov
877b987ecf rpc: omitempty some fields in TransactionOutputRaw
These might be undefined for mempool transactions, thus they should be defined
as omitempty.
2020-02-21 15:12:04 +03:00
Roman Khimov
bba8ac15ff rpc: introduce proper type for sendrawtransaction, drop useless types
sendrawtransaction just returns a bool, sendtoaddress returns a proper
transaction and that should be the same as the one we have in
TransactionOutputRaw.
2020-02-21 15:12:04 +03:00
Roman Khimov
465476201c rpc/response: drop duplicating AccountState structure 2020-02-21 15:12:04 +03:00
Evgenii Stratonikov
b50704fd3b rpc: move server-related code to a separate package 2020-02-21 15:12:04 +03:00
Evgenii Stratonikov
d24c6d1d9e rpc: move client-related code to a separate package
This includes Client struct with RPC methods and
BalanceGetter implementation with NeoSCAN.
2020-02-21 15:12:04 +03:00
Evgenii Stratonikov
b6bc4e580a rpc: move functions for Tx building in request package/ 2020-02-21 15:12:04 +03:00
Evgenii Stratonikov
98a1e2170a rpc: move ContractDetails to request/ package 2020-02-21 15:12:04 +03:00
Evgenii Stratonikov
63751a6e6b rpc: merge neoscan-related definitions into one file
It will make refactoring easier.
2020-02-21 15:12:04 +03:00
Roman Khimov
f330f2f40b rpc: separate out request and response structures
Mostly as is, no real effort done yet to optimize them, so there are still a
lot of duplicates there, but at least we sort them out into different smaller
packages.
2020-02-21 15:12:04 +03:00
Roman Khimov
69e1ad512f rpc: move result package into response
`response` is to be populated soon.
2020-02-21 15:12:04 +03:00
Roman Khimov
1801e545a0 rpc: remove wrappers package, move things to result
These are all RPC call results, `wrappers` package doesn't make much sense to
me.
2020-02-21 15:12:04 +03:00
Roman Khimov
b8f7ab8e6a rpc: move Invoke to result package
It's just a data.
2020-02-21 15:12:04 +03:00
Roman Khimov
c189062f40 rpc: move ValidateAddress to the result package
Because it is a result of the RPC call.
2020-02-21 15:12:04 +03:00
Roman Khimov
bfa2d54e16 rpc: move validateAddress() function from wrappers into server
It's a server implementation detail, it has nothing to do with the data format
itself. It also makes no sense exporing it.
2020-02-21 15:12:04 +03:00
Roman Khimov
72a62f1292 result: add trivial test for peers management functions 2020-02-21 15:12:04 +03:00
Roman Khimov
723b33e108 network: implement unconnected/bad peers getters
Which allows node to respond to `getpeers` RPC request correctly.
2020-02-21 15:12:03 +03:00
Roman Khimov
d92e193e63 rpc/network: refactor getpeers logic
Deduplicate and simplify code.
2020-02-21 15:12:03 +03:00
Roman Khimov
336a94456f rpc: make blockHeightFromParam a pointer method
Makes no sense copying Server here.
2020-02-21 15:12:03 +03:00
Roman Khimov
f345db58ab
Merge pull request #678 from nspcc-dev/feature/breakfor
compiler: support break statement in for loops and switch statements

Closes #677.
Implements 4-th point from #628.
2020-02-21 12:22:16 +03:00
Evgenii Stratonikov
da89f18999 compiler: support break and continue in range loops 2020-02-21 12:03:37 +03:00
Evgenii Stratonikov
ccb53414f2 compiler: support break in switch statements 2020-02-21 12:03:37 +03:00
Evgenii Stratonikov
03dc6f7cbb compiler: support continue statement in for loops 2020-02-21 12:03:36 +03:00
Evgenii Stratonikov
fa2edc46e0 compiler: support break statement in for loops 2020-02-21 11:38:23 +03:00
Evgenii Stratonikov
25ffb56982 wallet: support creating multisig accounts
(*Account).ConvertMultisig() will convert an existing account
into a multisig one.
2020-02-21 11:19:35 +03:00
Evgenii Stratonikov
5a727cabf8 wallet: add signature check contracts to new accounts 2020-02-21 10:45:57 +03:00
Evgenii Stratonikov
eacea8bff5 smartcontract: implement json.Unmarshaler for ParamType 2020-02-20 15:52:08 +03:00
Evgenii Stratonikov
ea30122a09 wallet: rewrite file on save
When we are opening a file, it is expected that
it will be rewritten, not appended to a already existing wallet.
2020-02-20 15:52:08 +03:00
Evgenii Stratonikov
ad6fa2aea9 wallet: set WIF and public key on account decrypt
They are set during account creation and open+decrypt is
expected to put account in the same state.
2020-02-20 15:52:08 +03:00
Evgenii Stratonikov
d837eb3761 wallet: allow to create accounts from encrypted WIFs 2020-02-20 15:52:08 +03:00
Roman Khimov
a903147b60 keys: rename Signature to GetScriptHash, make it return Uint160
Signature itself wasn't used at all and its name is very misleading, Uint160
script hash is way more useful.
2020-02-19 12:19:03 +03:00
Roman Khimov
eb11e5fb11 core: implement basic policying support, fix #370
Implement mempool and consensus block creation policies, almost the same as
SimplePolicy plugin for C# node provides with two caveats:
 * HighPriorityTxType is not configured and hardcoded to ClaimType
 * BlockedAccounts are not supported

Other than that it allows us to run successfuly as testnet CN, previously our
proposals were rejected because we were proposing blocks with oversized
transactions (that are rejected by PoolTx() now).

Mainnet and testnet configuration files are updated accordingly, but privnet
is left as is with no limits.

Configuration is currently attached to the Blockchain and so is the code that
does policying, it may be moved somewhere in the future, but it works for
now.
2020-02-19 12:19:02 +03:00
Roman Khimov
22f5667530 mempool: return fee along with tx when requesting tx
Users of GetVerifiedTransactions() don't want to recalculate tx fee and it's
nice to have it returned from TryGetValue() also sometimes.
2020-02-19 12:19:02 +03:00
Roman Khimov
06daeb44f3 core: make IsLowPriority work with pre-calculated fee
Don't recalculate it again and again.
2020-02-19 12:19:02 +03:00
Roman Khimov
37c48b00b4 consensus/network: reinit dbft after block addition
Don't stall on some height if everyone else have moved up already. Fix #673.
2020-02-19 12:19:02 +03:00
Roman Khimov
c5d54e9992 network: introduce (*Server).IsInSync, start consensus in synced state
We define synchronized state as a combination of minimum number of peers and
chain height being not behind of more than 2/3 of these peers.
2020-02-19 12:13:27 +03:00
Roman Khimov
a2616cfafe consensus: correctly generate miner TX outputs based on net fee 2020-02-19 12:13:27 +03:00
Roman Khimov
17d1b1a2ae wallet: implement GetChangeAddress()
To select the default address to send tokens to.
2020-02-19 12:13:27 +03:00
Roman Khimov
a4294f4b5f core: export UtilityTokenID and GoverningTokenID
Both are very useful outside of the core, this change also makes respective
transactions initialize with the package as they don't depend on any kind of
input and it makes no sense recreating them again and again on every use.
2020-02-19 12:13:27 +03:00
Roman Khimov
b41a5239c6 core: always sort the result of GetValidators
It wasn't sorted when all validators were elected. There is also no need to do
`Unique()` on the result because validators are distinguished by the key, so
no two registered validators can have the same key.
2020-02-18 20:36:22 +03:00
Evgenii Stratonikov
ee8514d88b consensus: provide message type and view inside RecoveryMessage
PrepareRequest inside RecoveryMessage should contain both
message type and view.
2020-02-18 15:25:29 +03:00
Evgenii Stratonikov
9b82bbaa8a rpc: implement getstorage RPC 2020-02-18 11:59:31 +03:00
Evgenii Stratonikov
a2f012e589 core: deploy new smart-contract in test blocks
Also put smart-contract sources in testdata and
add invocation TX with APPCALL and storage.Put.
2020-02-18 11:59:28 +03:00
Anna Shaleva
2b9e63c511 core: add func to generate RPC test data
newRPCTestChain function generates test chain "testblocks.acc" for RPC
tests
2020-02-17 23:54:25 +03:00
Anna Shaleva
c99b42f738 rpc: add tests for getcontractstate RPC 2020-02-17 23:54:25 +03:00
Anna Shaleva
3c63ef3dc3 rpc: implement getcontractstate RPC 2020-02-17 23:54:25 +03:00
Anna Shaleva
b8715ddf11 rpc: refactor code of NewAccountState function
Simplified reversing of scriptHash
2020-02-17 23:52:20 +03:00
Anna Shaleva
f310145612 rpc: fix getrawtransaction error returncode
Changed returncode of getrowtransaction method in case when transaction
with specified hash does not exists. Now it returns error with code -100
instead of -32602 (as in c# node)
2020-02-17 23:52:20 +03:00
Anna Shaleva
5dca765bd1 rpc: add custom error with code -100
Fixed getassetstate method: it should return error with code -100 when
asset with specified id is not found (as in c# node).
2020-02-17 23:52:20 +03:00
Evgenii Stratonikov
7ee10ecea5 rpc: implement gettxout RPC 2020-02-17 11:58:18 +03:00
Roman Khimov
dfb38e1da1
Merge pull request #649 from nspcc-dev/feature/dump_storage
cli: add possibility to dump storage changes on restore
2020-02-16 23:50:31 +03:00
Roman Khimov
d16121c10a
Merge pull request #654 from nspcc-dev/feat/subslice
compiler: support sub-slicing
2020-02-16 23:49:53 +03:00
Roman Khimov
4a4cd6416c
Merge pull request #658 from nspcc-dev/feature/range
compiler: support for-range loops
2020-02-16 23:49:30 +03:00
Roman Khimov
b5453ad24f
Merge pull request #672 from nspcc-dev/fix-sigsegv-on-reference-check
core: deal with bad transaction Inputs
2020-02-14 13:23:42 +03:00
Roman Khimov
0fceaf12d2 core: deal with bad transaction Inputs
They may not really have a reference. Fixes #671.
2020-02-14 09:42:10 +03:00
Roman Khimov
992ccc0b26
Merge pull request #664 from nspcc-dev/sort-validator-keys
core: sort GetValidators() result
2020-02-13 21:46:26 +03:00
Evgeniy Kulikov
8d410a6659
Add JSON tags for RPC response types
- Attribute should have 2 fields (usage, data)
- VOut should have 4 (5) fields (asset, value, address, n)
- Script should have 2 fields (invocation, verification)
2020-02-13 19:06:54 +03:00
Roman Khimov
d8a8dc94b4
Merge pull request #657 from nspcc-dev/fix/struct_fields
compiler: support initializing struct fields from a variable
2020-02-13 17:54:01 +03:00
Roman Khimov
d4cd134aef core: sort GetValidators() result
As C# node does it. Technically it's only needed for consensus and could be
implemented in the appropriate package, but for better compatibility with C#
node we're better returning it sorted right here.
2020-02-13 17:07:27 +03:00
Roman Khimov
d1a2296939 network: change the disconnect procedure
We can still lock the (*Server).run with dead peers:

Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: goroutine 40 [select, 871 minutes]:
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).putPacketIntoQueue(0xc030ab5320, 0xc02f251f20, 0xc00af0dcc0, 0x18, 0x40, 0x100000000000000, 0xffffffffffffffff)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:82 +0xf4
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).EnqueueHPPacket(0xc030ab5320, 0xc00af0dcc0, 0x18, 0x40, 0x1367240, 0xc03090ef98)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:124 +0x52
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*Server).iteratePeersWithSendMsg(0xc0000ca000, 0xc00af35800, 0xcb2a58, 0x0)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:720 +0x12a
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*Server).broadcastHPMessage(...)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:731
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*Server).run(0xc0000ca000)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:203 +0xee4
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*Server).Start(0xc0000ca000, 0xc000072ba0)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:173 +0x2ec
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: created by github.com/CityOfZion/neo-go/cli/server.startServer
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/cli/server/server.go:331 +0x476
...
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: goroutine 2199 [chan send, 870 minutes]:
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).Disconnect.func1()
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:366 +0x85
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: sync.(*Once).Do(0xc030ab403c, 0xc02f262788)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/usr/local/go/src/sync/once.go:44 +0xb3
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).Disconnect(0xc030ab4000, 0xd92440, 0xc000065a00)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:365 +0x6d
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).SendPing.func1()
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:394 +0x42
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: created by time.goFunc
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/usr/local/go/src/time/sleep.go:169 +0x44
...
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: goroutine 3448 [chan send, 854 minutes]:
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).handleConn(0xc01ed203f0)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:143 +0x6c
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: created by github.com/CityOfZion/neo-go/pkg/network.(*TCPTransport).Accept
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_transport.go:62 +0x44c
...

The problem is that the select in putPacketIntoQueue() only works the way it
was intended to after the `close(p.done)`, but that happens only after
successful unregistration request send. Thus, do disconnects the other way
around, first unblock queueing and exit goroutines, then destroy the
connection (if it wasn't previously destroyed) and only after that signal to
the Server.
2020-02-13 16:24:46 +03:00
Roman Khimov
ef870d0c9d
Merge pull request #661 from nspcc-dev/make-voting-system-work
Make voting system work
2020-02-13 15:16:29 +03:00
Roman Khimov
26af9200b0 core: refactor voting processing, fix pending tx subtractions
Deduplicate code and add missing token check for subtractions that are being
done in GetValidators() for pending transactions.
2020-02-13 13:07:34 +03:00
Roman Khimov
c8a248596e core: introduce ValidatorsCount, make a proper count
We were completely lacking ValidatorsCount that is supposed to track the
number of votes with particular count of consensus nodes which in theory can
change the number of active consensus nodes (if it ever to exceed the number
of standby validators), so we were not producing the right count and based on
that not giving the right set of validators.

Fixes #512.
2020-02-13 13:07:34 +03:00
Roman Khimov
357b675090 core: don't choose duplicating standby validators
We may already have chosen some of standby validators, so don't repeat.
2020-02-13 13:07:34 +03:00
Roman Khimov
f9c6a0d77c core: make voting choose the best validators
They need to be sorted in order for voting system to work.
2020-02-13 13:07:34 +03:00
Roman Khimov
2ff7ceb8cf core: properly update validator votes for Account descriptor
ValidatorsCount is not implemented yet, but we need to update validators
properly, adding account's vote to their votes count.
2020-02-13 13:07:34 +03:00
Roman Khimov
8310b76d28 core: properly save votes when processing Account descriptor
They were ignored basically.
2020-02-13 13:07:34 +03:00
Roman Khimov
807309a0de core/state: only drop unregistered non-voted validators
Simple as that: UnregisteredAndHasNoVotes != !RegisteredAndHasVotes

Registered validators should stay in the DB, we might be in the process of
updating votes for them and that starts with subtraction.
2020-02-13 13:07:34 +03:00
Evgeniy Kulikov
64e325d9af
Update tests for getblock action
- replace `GetBlockResponse.Result` with `wrappers.Block`
- update `getblock` checker and add more assets
2020-02-12 21:58:43 +03:00
Roman Khimov
32a064aa31 keys: add Cmp method to PublicKey
It can be used by code that doesn't operate with PublicKeys, but still needs
to be able to compare keys for some purposes.
2020-02-12 21:27:40 +03:00
Roman Khimov
38d0efc96c core: fix Registered state descriptor processing
It has simple boolean value encoded, no `strconv` needed (it actually chokes
on such input).
2020-02-12 21:27:40 +03:00
Roman Khimov
141553da4c keys: fix PublicKeys decoding
It changes the slice, thus it has to work via a pointer.
2020-02-12 21:23:28 +03:00
Roman Khimov
803fb39bb0 transaction: fix wrong state descriptor serdes
Wrong field order.
2020-02-12 21:23:28 +03:00
Evgeniy Kulikov
41ebf12eb3
Update getblock RPC action response 2020-02-12 19:43:51 +03:00
Evgenii Stratonikov
0a894db7f8 storage: add Exists flag to KeyValue in batch
Set Exists flag if an item with the specified key was already
present in storage before persisting.
2020-02-12 12:16:31 +03:00
Evgenii Stratonikov
b1d9e1132d cli: dump storage changes into JSON files 2020-02-12 12:16:31 +03:00
Evgenii Stratonikov
fb9af98179 storage: implement GetBatch() to view storage changes
GetBatch returns changes to be persisted.
2020-02-12 12:16:31 +03:00
Evgenii Stratonikov
8ea3ef0b62 compiler: process empty []byte{} literals as ByteArrays
It is wrong to count an empty byte slice as an Array.
2020-02-12 12:16:15 +03:00
Evgenii Stratonikov
32bce30777 compiler: support sub-slicing 2020-02-12 12:16:15 +03:00
Evgenii Stratonikov
310f7449d7 compiler: support for-range loops 2020-02-12 12:16:04 +03:00
Evgenii Stratonikov
ae03560589 compiler: support initializing struct fields from a variable
While initializing a struct, it is a top item on ALTSTACK.
This means that if we need to load a local variable,
DUPFROMALTSTACK won't longer push an array of locals on stack
but rather a currently initializing struct.

Closes #656.
2020-02-12 12:15:54 +03:00
Evgenii Stratonikov
3e84f2bdf8 compiler: rewrite jump targets properly
Old implementation could view 0x62 byte in
a script as a JMP instruction irregardless of whether it is
a real opcode or a part of a parameter of another instruction.
In this commit instructions are decoded together with parameters
during jump label rewriting.
2020-02-12 10:58:53 +03:00
Roman Khimov
d3badc3f97 consensus: log more like neo-cli, update dbft 2020-02-11 18:02:13 +03:00
Roman Khimov
38de2af073
Merge pull request #655 from nspcc-dev/fix-mempool-deadlock-on-reverification
core: get transactions from dao when mempool should not be used
2020-02-11 13:34:23 +03:00
Roman Khimov
292051d8df core: get transactions from dao when mempool should not be used
All of these places deal strictly with the chain and shouldn't ever be
bothered with mempool. It also fixes a deadlock on reverification of
non-standard tx:

1 @ 0x42f62f 0x43fbe9 0x43fbbf 0x43f95d 0x967059 0x966f66 0x972c7c 0x974e13 0x97a5d9 0x97bdf0 0x976147 0x966cc0 0x970f70 0x96c8cb 0x9ba858 0x45ca51
	0x43f95c	sync.runtime_SemacquireMutex+0x3c							/usr/local/go/src/runtime/sema.go:71
	0x967058	sync.(*RWMutex).RLock+0x128								/usr/local/go/src/sync/rwmutex.go:50
	0x966f65	github.com/CityOfZion/neo-go/pkg/core/mempool.(*Pool).TryGetValue+0x35			/go/src/github.com/CityOfZion/neo-go/pkg/core/mempool/mem_pool.go:229
	0x972c7b	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).GetTransaction+0x4b			/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:782
	0x974e12	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).References+0x132			/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:944
	0x97a5d8	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).GetScriptHashesForVerifying+0x58	/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:1410
	0x97bdef	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).verifyTxWitnesses+0x4f		/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:1545
	0x976146	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).isTxStillRelevant+0x216		/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:1067
	0x966cbf	github.com/CityOfZion/neo-go/pkg/core/mempool.(*Pool).RemoveStale+0xff			/go/src/github.com/CityOfZion/neo-go/pkg/core/mempool/mem_pool.go:208
	0x970f6f	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).storeBlock+0x2ecf			/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:614
	0x96c8ca	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).AddBlock+0xea			/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:308
	0x9ba857	github.com/CityOfZion/neo-go/pkg/network.(*blockQueue).run+0x157			/go/src/github.com/CityOfZion/neo-go/pkg/network/blockqueue.go:48
2020-02-10 18:53:22 +03:00
Roman Khimov
0461827fa3
Merge pull request #653 from nspcc-dev/fix-net-locks-and-leaks
network: fix networking stalls caused by stale peers
2020-02-10 18:51:56 +03:00
Roman Khimov
f7749cea67
Merge pull request #652 from nspcc-dev/Fix_FreeGasLimit
core: fix FreeGasLimit constraint
2020-02-10 18:49:09 +03:00
Roman Khimov
7ee8f9c5d8 network: fix networking stalls caused by stale peers
We can leak sending goroutines and stall broadcasts because of already gone
peers that happened to be cached by some s.Peers() user (more than 800 of
these can be seen in nodoka log along with (*Server).run blocking on
CMDGetAddr send):

Feb 10 16:35:15 nodoka neo-go[1563]: goroutine 41 [chan send, 3320 minutes]:
Feb 10 16:35:15 nodoka neo-go[1563]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).putPacketIntoQueue(...)
Feb 10 16:35:15 nodoka neo-go[1563]:         /go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:81
Feb 10 16:35:15 nodoka neo-go[1563]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).EnqueueHPPacket(0xc0083d57a0, 0xc017206100, 0x18, 0x40, 0x136a240, 0xc018ef9720)
Feb 10 16:35:15 nodoka neo-go[1563]:         /go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:119 +0x98
Feb 10 16:35:15 nodoka neo-go[1563]: github.com/CityOfZion/neo-go/pkg/network.(*Server).iteratePeersWithSendMsg(0xc0000ca000, 0xc0001848a0, 0xcb4550, 0x0)
Feb 10 16:35:15 nodoka neo-go[1563]:         /go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:720 +0x12a
Feb 10 16:35:15 nodoka neo-go[1563]: github.com/CityOfZion/neo-go/pkg/network.(*Server).broadcastHPMessage(...)
Feb 10 16:35:15 nodoka neo-go[1563]:         /go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:731
Feb 10 16:35:15 nodoka neo-go[1563]: github.com/CityOfZion/neo-go/pkg/network.(*Server).run(0xc0000ca000)
Feb 10 16:35:15 nodoka neo-go[1563]:         /go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:203 +0xee4
Feb 10 16:35:15 nodoka neo-go[1563]: github.com/CityOfZion/neo-go/pkg/network.(*Server).Start(0xc0000ca000, 0xc000072c60)
Feb 10 16:35:15 nodoka neo-go[1563]:         /go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:173 +0x2ec
Feb 10 16:35:15 nodoka neo-go[1563]: created by github.com/CityOfZion/neo-go/cli/server.startServer
Feb 10 16:35:15 nodoka neo-go[1563]:         /go/src/github.com/CityOfZion/neo-go/cli/server/server.go:331 +0x476
2020-02-10 18:47:52 +03:00
Anna Shaleva
9b03f968b1 core: fixe FreeGasLimit constraint
Lack of FreeGasLimit in privnet leads to gas limit exceeding in case of transactions with small amount of GAS to be used for invoke operation (< real cost of the transaction). Solution: Fixed constraint in case when FreeGasLimit == 0. So now we are able to perform transactions in privnet with FreeGasLimit = 0 for free.
2020-02-10 18:07:19 +03:00
Evgenii Stratonikov
895a8d9ebc compiler: reverse args in AppCall
Invoked contract is expecting first argument to be on top of the stack.
Change test to use non-commutative operation to catch this behaviour.
2020-02-10 10:53:58 +03:00
Evgenii Stratonikov
52d8d58593 compiler,interop: make AppCall accept varargs 2020-02-10 10:51:29 +03:00
Evgenii Stratonikov
1fc64d515f compiler: abstract out emitReverse
Extract logic of reversing top n items of the stack
in a separate function.
2020-02-10 10:43:31 +03:00
Roman Khimov
268cad5c06
Merge pull request #548 from nspcc-dev/feature/multisig
vm: implement parallel algorithm for CHECKMULTISIG
2020-02-08 16:10:34 +03:00
Roman Khimov
9b9adb28c1
Merge pull request #642 from nspcc-dev/feature/emit
vm, compiler: move Emit* functions to a separate package

Closes #449, #534.
2020-02-08 15:56:48 +03:00
Roman Khimov
c896e2b731 network: fix minor gofmt issues (spotted by goreportcard) 2020-02-08 15:53:08 +03:00
Roman Khimov
7ccf7974b6 core: substitute bad notifications with error messages
Tesnet sync failed with:
Feb 07 00:04:19 nodoka neo-go[1747]: 2020-02-07T00:04:19.838+0300        WARN        blockQueue: failed adding block into the blockchain        {"error": "failed to store notifications: not supported", "blockHeight": 713984, "nextIndex": 713985}

because some (not so) smart contract emitted a notification with an
InteropItem inside.
2020-02-07 15:34:59 +03:00
Roman Khimov
b805b1a71b vm: make SerializeItem/DeserializeItem public APIs
They're useful as wrappers around EncodeBinaryStackItem/DecodeBinaryStackItem.
2020-02-07 15:34:59 +03:00
Roman Khimov
7e7ce7f19f vm: rephrase serialization errors
Seeing some
    blockQueue: failed adding block into the blockchain        {"error": "failed to store notifications: not supported", "blockHeight": 713984, "nextIndex": 713985}
in logs is not very helpful.
2020-02-07 11:53:53 +03:00
Evgenii Stratonikov
a8dc704197 emit: add tests for Int 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
6fd3f0fa48 emit: add tests for Bytes 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
5e992d8cdd emit: add tests for Syscall, Jmp 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
dbc41b3044 compiler: replace emit* instructions with those from emit/ package 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
8243a8b3a7 emit: use io.BinWriter instead of bytes.Buffer 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
698c647f07 emit: refactor tests
Add structure and call Bytes() method on buffer once.
2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
1400ecfdde emit: fix Int to serialize integers in correct format
Related #605, #623.
2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
c821e1c4c8 vm: move IntToBytes and BytesToInt to emit package 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
4d8a3a359b vm: move Emit* functions to a separate package
Also strip 'Emit' prefix because 'emit' is now
in the package name.
2020-02-06 18:45:37 +03:00
Roman Khimov
ab14a4619d
Merge pull request #647 from nspcc-dev/fix-mempool-and-chain-locking
Fix mempool and chain locking

This allows us easily make 1000 Tx/s in 4-nodes privnet, fixes potential
double spends and improves mempool testing coverage.
2020-02-06 18:43:29 +03:00
Evgenii Stratonikov
9204b95d5b core: fix GAS price definitions 2020-02-06 18:19:08 +03:00
Roman Khimov
7445655437 consensus: switch test to using the new PoolTx API
Fixes GolangCI:
  Error return value of
  (*github.com/CityOfZion/neo-go/pkg/core/mempool.Pool).Add is not checked
  (from errcheck)

and allows us to almost completely forget about mempool here.
2020-02-06 17:50:11 +03:00
Roman Khimov
18695e660b mempool: drop RemoveOverCapacity(), handle it right in the Add()
Simplifies things a lot and removes useless code.
2020-02-06 17:50:11 +03:00
Roman Khimov
684cbf5bac mempool: make it almost 100% test-covered 2020-02-06 17:50:11 +03:00
Roman Khimov
6672f4b26f mempool: iterate over slice in GetVerifiedTransactions()
It's more efficient and keeps transactions sorted by priority.
2020-02-06 16:59:20 +03:00
Roman Khimov
e97396e56c mempool: test addition of conflicting tx to the pool 2020-02-06 15:57:20 +03:00
Roman Khimov
1133bbe584 mempool: remove unverified transactions pool
Our mempool only contains valid verified transactions all the time, it never
has any unverified ones. Unverified pool made some sense for quick unverifying
after the new block acceptance (and gradual background reverification), but
reverification needs some non-trivial locking between blockchain and mempool
and internal mempool state locking (reverifying tx and moving it between
unverified and verified pools must be atomic). But our current reverification
is fast enough (and has all the appropriate locks), so bothering with
unverified pool makes little sense.
2020-02-06 15:45:16 +03:00
Roman Khimov
b675903f52 mempool/core: redesign mempool dances on block acceptance
We not only need to remove transactions stored in the block, but also
invalidate some potential double spends caused by these transactions. Usually
new block contains a substantial number of transactions from the pool, so it's
easier to make one pass over it only keeping valid items rather than remove
them one by one and make an additional pass to recheck inputs/witnesses.
2020-02-06 15:45:16 +03:00
Roman Khimov
b567ce86ac mempool: implement insertion to sorted slice
Which is way faster than sort.Sort'ing things all the time.
2020-02-06 15:44:18 +03:00
Roman Khimov
35183b6dba mempool: reverse the order of sorted slice
Chopping off the last element of the slice if way easier than doing it with
the first one.
2020-02-06 15:44:16 +03:00
Roman Khimov
794027a90b mempool: use one slice for both priorities
It doesn't harm as we have transactions naturally ordered by fee anyway and it
makes managing them a little easier. This also makes slices store item itself
instead of pointers to it which reduces the pressure on the memory subsystem.
2020-02-06 15:43:45 +03:00
Roman Khimov
325bea3fa9 mempool: cache Feer invocation results in the item
They shouldn't depend on the chain state and for the same transaction they
should always produce the same result. Thus, it makes no sense recalculating
them over and over again.
2020-02-06 15:41:56 +03:00
Roman Khimov
e01bfeeb4d mempool: remove lock indirection from the Pool
After the f0bb886be3 with all methods of Pool
being pointer-based it makes no sense having this lock as a pointer.
2020-02-06 15:41:56 +03:00
Roman Khimov
a928ad9cfa mempool: make item an internal thing of mempool package
Nobody outside should care about these details, mempool operates on
transactions and that's it.
2020-02-06 15:41:56 +03:00
Roman Khimov
f0e3a31bc8 mempool: fix appending to sorted pools
Appending and not changing the real Items is utterly wrong.
2020-02-06 15:41:56 +03:00