Commit graph

393 commits

Author SHA1 Message Date
Anna Shaleva
15a939b1da rpc: allow to getcontractstate by address, id or name
close #1423
2020-11-03 17:23:49 +03:00
Roman Khimov
eaa260474f trigger/core: split System trigger into OnPerist and PostPersist
Follow neo-project/neo#2022.
2020-10-29 19:17:07 +03:00
Roman Khimov
044786b995 core: use Application trigger in CalculateClaimable()
It doesn't need a System one.
2020-10-29 19:17:07 +03:00
Anna Shaleva
ec63d5c456 core: add conflicts attribute
Close #1491
2020-10-29 10:57:31 +03:00
Anna Shaleva
95630b72e8 core: verify transaction attributes before adding it into mempool
Attributes check should be done before adding transaction to
the pool, otherwise there might be a case when transaction with invalid
attributes is in the pool.
2020-10-23 11:05:03 +03:00
Anna Shaleva
09b8b8de73 core: reserve attributes range for experimantal purposes 2020-10-23 11:04:59 +03:00
Anna Shaleva
368ff820b3 core: add NotValidBefore transaction attribute
Close #1490
2020-10-23 11:02:46 +03:00
Evgenii Stratonikov
aee02ff2e3 core: allow to invoke verify of native contracts 2020-10-14 11:44:27 +03:00
Roman Khimov
a154481860 core: drop stale transactions from the mempool
They're no longer valid if `ValidUntilBlock == curheight`.
2020-10-12 14:58:40 +03:00
Roman Khimov
8c2fd91c5c
Merge pull request #1462 from nspcc-dev/rpc/exceptions
rpc, core: add FaultException to AppExecResult and Invoke* results
2020-10-08 16:20:38 +03:00
Anna Shaleva
0f71088246 core: add FaultException to AppExecResult 2020-10-08 16:12:19 +03:00
Anna Shaleva
9fe2b04db9 core: add cache to Policy blocked accounts
Close #1441
2020-10-08 13:47:21 +03:00
Roman Khimov
8e146d19b3
Merge pull request #1447 from nspcc-dev/core/fix_neo_cache
core: fix cache for (NEO).nextValidators and (NEO).committee
2020-10-02 17:09:43 +03:00
Anna Shaleva
eccf639803 core: add InitializeCache method to NEO native contracts
There might be a case when cached contract values store nil (e.g.
after restoring chain from dump). We should always initialize cached
values irrespective to the (NEO).Initialize method.

This commit fixes a bug introduced in 83e94d3
when 4-nodes privnet is failing after restoring from dump:
```
$ docker logs neo_go_node_one
=> Try to restore blocks before running node
2020-09-30T11:55:49.122Z	INFO	no storage version found! creating genesis block
2020-09-30T11:55:49.124Z	INFO	service hasn't started since it's disabled	{"service": "Pprof"}
2020-09-30T11:55:49.124Z	INFO	service hasn't started since it's disabled	{"service": "Prometheus"}
2020-09-30T11:55:49.124Z	INFO	skipped genesis block	{"hash": "3792eaa22c196399a114666fd491c4b9ac52491d9abb1f633a8036a8ac81e4db"}
2020-09-30T11:55:49.141Z	INFO	shutting down service	{"service": "Pprof", "endpoint": ":30001"}
2020-09-30T11:55:49.141Z	INFO	shutting down service	{"service": "Prometheus", "endpoint": ":40001"}
2020-09-30T11:55:49.141Z	INFO	blockchain persist completed	{"persistedBlocks": 3, "persistedKeys": 146, "headerHeight": 3, "blockHeight": 3, "took": "324.27µs"}
2020-09-30T11:55:49.150Z	INFO	restoring blockchain	{"version": "0.1.0"}
2020-09-30T11:55:49.150Z	INFO	service hasn't started since it's disabled	{"service": "Prometheus"}
2020-09-30T11:55:49.151Z	INFO	service hasn't started since it's disabled	{"service": "Pprof"}
2020-09-30T11:55:49.443Z	INFO	starting rpc-server	{"endpoint": ":30333"}
2020-09-30T11:55:49.443Z	INFO	node started	{"blockHeight": 3, "headerHeight": 3}

    _   ____________        __________
   / | / / ____/ __ \      / ____/ __ \
  /  |/ / __/ / / / /_____/ / __/ / / /
 / /|  / /___/ /_/ /_____/ /_/ / /_/ /
/_/ |_/_____/\____/      \____/\____/

/NEO-GO:/

2020-09-30T11:55:49.444Z	INFO	new peer connected	{"addr": "172.23.0.5:39638", "peerCount": 1}
2020-09-30T11:55:49.444Z	INFO	new peer connected	{"addr": "172.23.0.5:20333", "peerCount": 2}
2020-09-30T11:55:49.444Z	WARN	peer disconnected	{"addr": "172.23.0.5:20333", "reason": "identical node id", "peerCount": 1}
2020-09-30T11:55:49.445Z	WARN	peer disconnected	{"addr": "172.23.0.5:39638", "reason": "identical node id", "peerCount": 0}
2020-09-30T11:55:49.445Z	INFO	new peer connected	{"addr": "172.23.0.3:20335", "peerCount": 1}
2020-09-30T11:55:49.445Z	INFO	new peer connected	{"addr": "172.23.0.2:20334", "peerCount": 2}
2020-09-30T11:55:49.445Z	INFO	started protocol	{"addr": "172.23.0.3:20335", "userAgent": "/NEO-GO:/", "startHeight": 3, "id": 1339919829}
2020-09-30T11:55:49.445Z	INFO	new peer connected	{"addr": "172.23.0.4:20336", "peerCount": 3}
2020-09-30T11:55:49.445Z	INFO	started protocol	{"addr": "172.23.0.4:20336", "userAgent": "/NEO-GO:/", "startHeight": 3, "id": 4036722359}
2020-09-30T11:55:49.445Z	INFO	node reached synchronized state, starting consensus
2020-09-30T11:55:49.445Z	INFO	started protocol	{"addr": "172.23.0.2:20334", "userAgent": "/NEO-GO:/", "startHeight": 3, "id": 1557367037}
panic: runtime error: integer divide by zero

goroutine 132 [running]:
github.com/nspcc-dev/dbft.(*Context).GetPrimaryIndex(...)
	github.com/nspcc-dev/dbft@v0.0.0-20200925163137-8f3b9ab3b720/context.go:83
github.com/nspcc-dev/dbft.(*Context).reset(0xc0000e0780, 0x0)
	github.com/nspcc-dev/dbft@v0.0.0-20200925163137-8f3b9ab3b720/context.go:208 +0x64b
github.com/nspcc-dev/dbft.(*DBFT).InitializeConsensus(0xc0000e0780, 0x964800)
	github.com/nspcc-dev/dbft@v0.0.0-20200925163137-8f3b9ab3b720/dbft.go:87 +0x51
github.com/nspcc-dev/dbft.(*DBFT).Start(0xc0000e0780)
	github.com/nspcc-dev/dbft@v0.0.0-20200925163137-8f3b9ab3b720/dbft.go:81 +0x4b
github.com/nspcc-dev/neo-go/pkg/consensus.(*service).Start(0xc0001a2160)
	github.com/nspcc-dev/neo-go/pkg/consensus/consensus.go:206 +0x56
github.com/nspcc-dev/neo-go/pkg/network.(*Server).tryStartConsensus(0xc0000ec500)
	github.com/nspcc-dev/neo-go/pkg/network/server.go:311 +0xda
github.com/nspcc-dev/neo-go/pkg/network.(*Server).handleMessage(0xc0000ec500, 0x104d800, 0xc000222090, 0xc0000a6f10, 0x0, 0x0)
	github.com/nspcc-dev/neo-go/pkg/network/server.go:781 +0xa7a
github.com/nspcc-dev/neo-go/pkg/network.(*TCPPeer).handleConn(0xc000222090)
	github.com/nspcc-dev/neo-go/pkg/network/tcp_peer.go:162 +0x2e7
created by github.com/nspcc-dev/neo-go/pkg/network.(*TCPTransport).Dial
	github.com/nspcc-dev/neo-go/pkg/network/tcp_transport.go:40 +0x1ac
```
2020-10-02 17:03:06 +03:00
Roman Khimov
b5d138b150
Merge pull request #1451 from nspcc-dev/native/designative
native: implement Designate contract
2020-10-02 16:09:33 +03:00
Evgenii Stratonikov
c468c02ef5 native: implement Designate contract 2020-10-02 11:03:25 +03:00
Roman Khimov
991089593f
Merge pull request #1450 from nspcc-dev/fix/witnessscope
transaction: rename FeeOnly to None
2020-10-01 16:46:07 +03:00
Evgenii Stratonikov
fa09b9af7b transaction: rename FeeOnly to None
Follow missed change from neo-project/neo#1816 .
`None` may be used for any signer. Currently it is used
for sender to only pay fees, or to sign tx attributes.
2020-10-01 15:28:19 +03:00
Anna Shaleva
e34e367a7b core: take into account size fee during verifyTxWitnesses
GasLimit for transaction scripts verification should not include fee for
transaction size.
2020-09-30 21:40:04 +03:00
Anna Shaleva
a2bfd16136 core: take into account gasConsumed during tx witnesses verification
We should pay attention to the previously consumed gas during tx
witnesses verification.
2020-09-29 17:43:35 +03:00
Evgenii Stratonikov
e91d13c615 core: implement oracle tx verification 2020-09-25 17:34:11 +03:00
Evgenii Stratonikov
bd1790bddf native: cache oracle nodes 2020-09-25 17:34:11 +03:00
Evgenii Stratonikov
ef7c0dbd78 core: use GetCommitteeAddress to get committee address 2020-09-25 17:02:31 +03:00
Evgenii Stratonikov
c5cdaae87a native: support postPersist method
It should be called for NEO contract to distribute
committee bounties.
2020-09-23 14:47:09 +03:00
Evgenii Stratonikov
81a11c629a native: remove getValidators method
Follow https://github.com/neo-project/neo/pull/1920 .
2020-09-23 14:42:13 +03:00
Evgenii Stratonikov
83e94d3bbc native: cache committee members 2020-09-23 14:42:13 +03:00
Evgenii Stratonikov
7d90d79ae6 core: update claimable GAS calculation 2020-09-23 14:12:42 +03:00
Roman Khimov
e4b52d3947 core/rpc: add continue flag to iterating functions
Most of the time we don't need to get all transfers from the DB and
deserialize them.
2020-09-21 22:23:34 +03:00
Roman Khimov
373c669c6a core/state: reverse the order of ForEachTransfer
When using limits we're usually concerned about the most recent
transfers. Returning 3 transfers from the middle of the chain isn't very
helpful.
2020-09-21 22:05:15 +03:00
Anna Shaleva
770c8d774c core, rpc: add GetCommittee method
Closes #1414
2020-09-21 15:56:25 +03:00
Anna Shaleva
c6f099294b core: do not marshal block hash in application log
Closes #1388
2020-09-21 14:08:15 +03:00
Roman Khimov
1608fbff87
Merge pull request #1378 from nspcc-dev/tests/cli
Implement tests for CLI
2020-09-19 17:02:34 +03:00
Evgenii Stratonikov
bff67c921a core: wrap dao in GetTestVM
MPT must not be shared to the test VM.
Fix DATA RACE between `Collapse()` and RPC calls.
2020-09-18 12:07:02 +03:00
Roman Khimov
61ad82160b core: remove named return variable from addHeaders() 2020-09-16 17:45:12 +03:00
Roman Khimov
6bffa811d4 core: remove (*block.Block) checks for topBlock
If it's non-nil, it has *block.Block inside. If it doesn't --- tell everyone
about it with a nice panic message.
2020-09-16 17:40:27 +03:00
Roman Khimov
33ea179f6e core: remove forward index check from addHeaders()
It can't ever happen. We're guaranteed to have a consistent chain of headers
(we're verifying them above, if we're not verifying --- it's not our fault)
that starts at HeaderHeight that was actual when we were asking for it
previously. HeaderHeight can only move forward, so if that happened that would
be filtered out by the condition below and the first one can't happen. Though
to be absolutely sure change the second check to only pass "+1" headers (which
is what we want).
2020-09-16 16:33:42 +03:00
Roman Khimov
7cbb660082 core: rework headerList
It's a contention point as all accesses to it are serialized and they compete
with persisting logic at the same time.
2020-09-16 16:30:40 +03:00
Roman Khimov
ce09c82b25 block: remove Verify()
It's used in two places now:
 * Blockchain.AddBlock()
   This one does transaction duplication check of its own, doing it in
   Verify() is just a waste of time. Merkle tree root hash value check is
   still relevant though
 * Block.DecodeBinary()
   We're decoding blocks for the following purposes:
     - on restore from dump
       The block will be added to the chain via AddBlock() and that will do a
       full check of it (if configured to do so)
     - on retrieving the block from the DB (DAO)
       We trust the DB, if it's gone wild, this check won't really help
     - on receiving the block via P2P
       It's gonna be put into block queue and then end up in AddBlock() which
       will check it
     - on receiving the block via RPC (submitblock)
       It is to be passed into AddBlock()
     - on receiving the block via RPC in a client
       That's the only problematic case probably, but RPC client has to trust
       the server and it can check for the signature if it really
       cares. Or a separate in-client check might be added.

As we can see nothing really requires this verification to be done the way it
is now, AddBlock can just have a Merkle check and DecodeBinary can do fine
without it at all.
2020-09-16 12:50:13 +03:00
Roman Khimov
2e876b5593 block: remove Base.Verify()
It's a no-op and there is nothing we can do about it, header contents could
only be checked against chain state, there is nothing to check for internal
consistency.
2020-09-16 12:50:13 +03:00
Roman Khimov
19c69618c5 transaction: cache tx size, don't serialize it over and over again 2020-09-11 18:55:19 +03:00
Roman Khimov
7310e748e3 core: reuse mempool from AddBlock() for bc.isTxStillRelevant()
It's already there most of the time and creating another slice is just a waste
of time. Checking for presence with map is also a little faster.
2020-09-10 15:02:03 +03:00
Roman Khimov
26339c75dc vm/core: drop old key caching system
Obsoleted by f5f58a7e91.
2020-09-10 14:43:24 +03:00
Roman Khimov
a2d9b89964 dao: reuse buffers when storing blocks, txes and aers
Reduce memory allocation pressure.
2020-09-09 20:46:31 +03:00
Evgenii Stratonikov
2661ebd295 transaction: add HighPriority attribute
HighPriority attributes specifies that transaction was
signed by a committee.
2020-08-23 09:39:46 +03:00
Roman Khimov
e5813ae8cd
Merge pull request #1346 from nspcc-dev/string-tryboolean
Fail converting long strings to boolean
2020-08-22 17:04:11 +03:00
Evgenii Stratonikov
7e34072519 core: implement (*Blockchain).VerifyWitness
`ScriptFromWitness` is no longer useful, because we support
contract verification.
2020-08-22 12:45:20 +03:00
Roman Khimov
a7670303e8 stackitem: change Bool() to TryBool(), prepare for its failures 2020-08-21 20:55:20 +03:00
Roman Khimov
55b2cbb74d core: refactor and improve verification and pooling
Now we have VerifyTx() and PoolTx() APIs that either verify transaction in
isolation or verify it against the mempool (either the primary one or the one
given) and then add it there. There is no possibility to check against the
mempool, but not add a transaction to it, but I doubt we really need it.

It allows to remove some duplication between old PoolTx and verifyTx where
they both tried to check transaction against mempool (verifying first and then
adding it). It also saves us utility token balance check because it's done by
the mempool anyway and we no longer need to do that explicitly in verifyTx.

It makes AddBlock() and verifyBlock() transaction's checks more correct,
because previously they could miss that even though sender S has enough
balance to pay for A, B or C, he can't pay for all of them.

Caveats:
 * consensus is running concurrently to other processes, so things could
   change while verifyBlock() is iterating over transactions, this will be
   mitigated in subsequent commits

Improves TPS value for single node by at least 11%.

Fixes #667, fixes #668.
2020-08-20 18:50:18 +03:00
Roman Khimov
e998c102ca mempool: rename NewMemPool into New
"mempool" is a package name already.
2020-08-20 18:50:18 +03:00
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