Commit graph

2336 commits

Author SHA1 Message Date
Roman Khimov
6f3aff76a4
Merge pull request #1405 from nspcc-dev/rework-block-verifications
Rework block verifications a bit
2020-09-16 14:27:24 +03:00
Roman Khimov
93be4bbeee rpc/server: fix "websocket: bad handshake" during testing
I think it's caused by connection limits server-side, we never close
connection on the client.
2020-09-16 12:51:59 +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
d2b37adf95
Merge pull request #1403 from nspcc-dev/merkle-memory-optimization
hash: introduce memory-optimized merkle root hash calculation routine
2020-09-16 12:48:33 +03:00
Roman Khimov
d52e79668b hash: introduce memory-optimized merkle root hash calculation routine
NewMerkleTree is a memory hog, we can do better than that:

BenchmarkMerkle/NewMerkleTree-8                       13          88434670 ns/op        20828207 B/op     300035 allocs/op
BenchmarkMerkle/CalcMerkleRoot-8                      15          69264150 ns/op               0 B/op          0 allocs/op
2020-09-15 18:38:15 +03:00
Evgenii Stratonikov
bcc11cbd74 compiler: support removing slice elements
Go-way of removing elements from slice is via `append` builtin.
There is a separate opcode for removing elements from
Arrays, which is cheaper and supported in this commit.
2020-09-15 16:33:43 +03:00
Evgenii Stratonikov
78948ef7af compiler: emit error for non-byte subslices
They are not supported for now, as VM has only
`SUBSTR` opcode for Buffers (`[]byte` in Go).
2020-09-15 16:21:44 +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
a6a1df4e0d consensus: update dbft, use new timer 2020-09-11 18:55:07 +03:00
Roman Khimov
83fc38ae3a mempool: don't create new big.Int in tryAddSendersFee() if possible
Do a little less allocations.
2020-09-10 15:35:19 +03:00
Roman Khimov
fc7ea6217d mempool: avoid reassigning utilityBalanceAndFees value
It's not needed, we're either creating a new one and assigning it 6 lines
above or we're changing already existing big.Int via a pointer, so no update
is needed.
2020-09-10 15:20:04 +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
120c4d4406 network: don't compress Inventory messages
They're not really compressable.
2020-09-09 20:46:31 +03:00
Roman Khimov
9c5ef8d234 dbft: rev up, pick performance improvements 2020-09-09 20:46:31 +03:00
Roman Khimov
b78bc7f097 network: fix tx requests, we can't ask more than 500 txes at once 2020-09-09 20:46:31 +03:00
Roman Khimov
fe1f1d19be mempool: store only pointer in the verifiedMap
It's only used for presence checks, there is no need for metadata here.
2020-09-09 20:46:31 +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
Roman Khimov
097b2b8e78 network: fail fast in iteratePeersWithSendMsg
This easily saves us some allocations for single node.
2020-09-09 20:46:31 +03:00
Roman Khimov
af17bbfeab rpc/server: encode answers more efficiently
We're at the point where even this code can clearly be seen in profiles. We
can save on some buffers (and CPU cycles) by encoding the answer once.

Another ~2% TPS for single node.
2020-09-09 20:46:31 +03:00
Roman Khimov
9187e2ab25 rpc/response: drop unused GetRawTx type 2020-09-09 20:46:31 +03:00
Roman Khimov
9591d64e53 mempool: don't sort items by hash
There is nothing requiring us to do so. It also is bad because it allows for
new transaction to replace some already existing one with the same fee
parameters just because it has "better" hash.

But the other thing is that for transactions with equal fees it's always
better for us to append them to the end of the list, instead of inserting them
in the middle, so this change allows to reduce slice item movements and gain
some 6-7% increase for single-node TPS.
2020-09-09 20:46:31 +03:00
Roman Khimov
5df726db68 mempool: replace timeStamp with blockStamp
Time is not really relevant for us here and we don't use this timestamp in any
way. Yet it occupies 24 bytes and we do two clock_gettime calls to get it.

Replace it with blockStamp which is going to be used in the future for
transaction retransmissions.

It allows to improve single-node TPS by another 3%.
2020-09-09 20:46:31 +03:00
Roman Khimov
bc31ab3d2c storage: add bloom filter to leveldb
We're constantly checking for transactions there and most of the time this
check is not successful (meaning that the transaction in question is
new). Bloom filter easily reduces the need to search over the DB in 99% of
these cases and gives some 13% increase in single-node TPS.
2020-09-09 20:46:31 +03:00
Roman Khimov
f5f58a7e91 keys: add simple LRU key cache for 1024 elements
The cost of Y calculation from X is comparable with signature check, so it
reduces witness check overhead by ~30% for cached keys and gives ~5% overall
boost in TPS.
2020-09-09 20:46:31 +03:00
Roman Khimov
0ea8c8ba67 mempool: drop a level of indirection
`item` is so small that it makes no sense bothering memory allocator with
every instance of it.
2020-09-09 20:46:31 +03:00
Roman Khimov
53c014a0bb crypto/consensus: sign hashes and cache them for consensus payloads
Avoid serializing payload again and again for various purposes. To sign it, we
only need a hash.

Some 2.4% gain in TPS could be achieved with this.
2020-09-09 20:46:31 +03:00
Roman Khimov
49e9c1aa0f
Merge pull request #1387 from nspcc-dev/rpc/notifications_state_serialisation
rpc: replace result.ApplicationLog with state.AppExecResult
2020-09-07 17:48:08 +03:00
Roman Khimov
cf322cd9f4
Merge pull request #1391 from nspcc-dev/compiler/const
Small compiler improvements
2020-09-07 17:46:41 +03:00
Anna Shaleva
27348973c3 rpc: fix JSON marshalling for Invoke result
We should return a quote string as JSON value in case of recursive
reference, otherwise json.Marshal returns an error.
2020-09-07 13:57:45 +03:00
Anna Shaleva
acacac1b24 rpc: use state.AppExecResult for ApplicationLog marshalling
Closes #1371
2020-09-07 13:38:32 +03:00
Anna Shaleva
34df5d5949 smartcontract: update trigger.Type stringer
We have to explicitly specify the type of `All` trigger type for proper
automatic generation of string representation.
2020-09-07 11:13:58 +03:00
Evgenii Stratonikov
7483e3b054 compiler: support delete() builtin 2020-09-06 15:49:41 +03:00
Evgenii Stratonikov
18369c489e compiler: do not allocate slotes for unused "_" vars 2020-09-06 15:27:46 +03:00
Evgenii Stratonikov
0b44a43043 compiler: do not allocate static slot for constants
Their value is known at compile time.
2020-09-06 15:20:17 +03:00
Evgenii Stratonikov
230700ee81 core: do not persist Policy contract
It has nothing to persist.
2020-09-05 10:54:47 +03:00
Roman Khimov
18204ec21a
Merge pull request #1383 from nspcc-dev/compiler/switchtag
compiler: fix a bug with type conversion in switch
2020-09-03 14:40:17 +03:00
Roman Khimov
cf15ca30f5
Merge pull request #1382 from nspcc-dev/compiler/manifest_methods_fix
compiler: do not convert methods to manifest methods
2020-09-03 14:39:51 +03:00
Anna Shaleva
70a58b6522 compiler: do not convert methods to manifest methods
Close #1381
2020-09-02 22:41:54 +03:00
Anna Shaleva
058da7c2bd compiler: getFuncNameFromDecl for methods on pointers
Declaration has *ast.StarExpr type in case of method on pointer.
2020-09-02 22:41:54 +03:00
Evgenii Stratonikov
98ca17aab8 network: restrict block queue size
Close #1374.
2020-09-02 17:04:49 +03:00
Evgenii Stratonikov
74dda0ac66 compiler: allow to use type conversion in range 2020-09-02 15:35:20 +03:00
Evgenii Stratonikov
3af7ce8c6b compiler: allow to use copy() return value 2020-09-02 15:29:59 +03:00
Evgenii Stratonikov
3d8c7af66c compiler: handle void call to recover()
Other builtins such as `len` and `make` can be ignored,
because not-assigning `make` result is catched by parser.
2020-09-02 15:20:43 +03:00
Evgenii Stratonikov
7d61a567d5 compiler: fix a bug with type conversion in switch
It was incorrectly parsed as void call.
2020-09-02 14:48:19 +03:00
Evgenii Stratonikov
1788cf02a1 core: fix VerifyTX test
HighPriority attribute was lost during intermediate code changes.
2020-08-27 18:40:37 +03:00
Evgenii Stratonikov
dce456f77f native: fix a bug in GetCommitteeMembers
Return standby committee instead of validators.
2020-08-27 18:40:37 +03:00
Evgenii Stratonikov
b0c051b817 internal: extend committee for unit tests
Committee should differ from the set of validators, to catch
possible bugs during testing.
2020-08-27 18:40:36 +03:00
Roman Khimov
3468f97836
Merge pull request #1343 from nspcc-dev/compiler/recover
Support `defer` statement
2020-08-27 17:33:12 +03:00