Commit graph

2379 commits

Author SHA1 Message Date
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
43b3e15330 native: send GAS to a committee member on persist 2020-09-23 14:42:12 +03:00
Evgenii Stratonikov
5a38208361 native: implement NEO.Get/SetMaxGasPerBlock() 2020-09-23 14:12:42 +03:00
Evgenii Stratonikov
7d90d79ae6 core: update claimable GAS calculation 2020-09-23 14:12:42 +03:00
Roman Khimov
1ff1cd797e
Merge pull request #1419 from nspcc-dev/port-from-2.x
Port from 2.x
2020-09-22 21:56:29 +03:00
Roman Khimov
41af738c1b state: drop (*NEP5TransferLog).DecodeBinaryReturnCount
It's no longer needed.
2020-09-22 19:21:12 +03:00
Roman Khimov
b958b5c9af rpc/client: update GetNEP5Transfers call 2020-09-22 16:55:20 +03:00
Roman Khimov
6b7ca0ce3f rpc/server: limit the maximum number of elements for get*transfers 2020-09-22 16:45:01 +03:00
Roman Khimov
970de84130 rpc: add paging to getnep5transfers call
And add some tests.
2020-09-22 16:40:29 +03:00
Evgenii Stratonikov
3bba853c3e rpc/client: use standard errors package in tests 2020-09-22 11:28:27 +03:00
Roman Khimov
c50ff7f20e rpc/server: refactor parameter parsing for getnep5transfers 2020-09-21 22:38:59 +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
Roman Khimov
ff11a5f990 state: use more efficient encoding for amount
It's variable-length anyway, so wasting 8 bytes for what typically is 1 byte
makes no sense.
2020-09-21 21:51:33 +03:00
Roman Khimov
806b89db76 state: store the length of NEP5TransferLog in the first byte
We lose `size` field after serialization/deserialization which can lead to
adding more than NEP5TransferBatchSize elements into the NEP5TransferLog.
2020-09-21 21:51:11 +03:00
Roman Khimov
6902003044 rpc/server: add limit to get*transfers calls
Return only N transfers requested.
2020-09-21 18:03:59 +03:00
Evgenii Stratonikov
fc77f8b5b2 consensus: exit if wrong password is provided in configuration 2020-09-21 17:56:25 +03:00
Roman Khimov
0c264b1486 mpt: fix comment typo 2020-09-21 17:54:11 +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
a439941a71
Merge pull request #1407 from nspcc-dev/core/oracleattr
Implement OracleResponse transaction attribute
2020-09-21 12:55:10 +03:00
Roman Khimov
15b621f0f3 consensus: wait goroutine to finish on Shutdown
Fixes:
panic: assignment to entry in nil map

goroutine 227 [running]:
github.com/nspcc-dev/neo-go/pkg/core/storage.(*MemoryStore).put(...)
        /home/rik/dev/neo-go/pkg/core/storage/memory_store.go:53
github.com/nspcc-dev/neo-go/pkg/core/storage.(*MemoryStore).PutBatch(0xc00035f580, 0x110a680, 0xc000336750, 0x0, 0x0)
        /home/rik/dev/neo-go/pkg/core/storage/memory_store.go:93 +0x286
github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).addHeaders(0xc0000a2340, 0xc0001be301, 0xc00036d428, 0x1, 0x1, 0x0, 0x0)
        /home/rik/dev/neo-go/pkg/core/blockchain.go:516 +0xd5a
github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).AddBlock(0xc0000a2340, 0xc0000bc2c0, 0x0, 0x0)
        /home/rik/dev/neo-go/pkg/core/blockchain.go:407 +0x9ca
github.com/nspcc-dev/neo-go/pkg/consensus.(*service).processBlock(0xc000152160, 0x1122320, 0xc0000bc2c0)
        /home/rik/dev/neo-go/pkg/consensus/consensus.go:440 +0xbf
github.com/nspcc-dev/dbft.(*DBFT).checkCommit(0xc0000d3400)
        /home/rik/go/pkg/mod/github.com/nspcc-dev/dbft@v0.0.0-20200911152629-be965ee4d449/check.go:71 +0x918
github.com/nspcc-dev/dbft.(*DBFT).checkPrepare(0xc0000d3400)
        /home/rik/go/pkg/mod/github.com/nspcc-dev/dbft@v0.0.0-20200911152629-be965ee4d449/check.go:36 +0x465
github.com/nspcc-dev/dbft.(*DBFT).sendPrepareRequest(0xc0000d3400)
        /home/rik/go/pkg/mod/github.com/nspcc-dev/dbft@v0.0.0-20200911152629-be965ee4d449/send.go:42 +0x2f8
github.com/nspcc-dev/dbft.(*DBFT).start(0xc0000d3400)
        /home/rik/go/pkg/mod/github.com/nspcc-dev/dbft@v0.0.0-20200911152629-be965ee4d449/dbft.go:269 +0x26f
github.com/nspcc-dev/dbft.(*DBFT).Start(0xc0000d3400)
        /home/rik/go/pkg/mod/github.com/nspcc-dev/dbft@v0.0.0-20200911152629-be965ee4d449/dbft.go:82 +0x59
github.com/nspcc-dev/neo-go/pkg/consensus.(*service).Start(0xc000152160)
        /home/rik/dev/neo-go/pkg/consensus/consensus.go:191 +0x56
github.com/nspcc-dev/neo-go/pkg/network.(*Server).tryStartConsensus(0xc000235040)
        /home/rik/dev/neo-go/pkg/network/server.go:311 +0xda
github.com/nspcc-dev/neo-go/pkg/network.(*Server).Start(0xc000235040, 0xc0000faba0)
        /home/rik/dev/neo-go/pkg/network/server.go:173 +0x202
created by github.com/nspcc-dev/neo-go/cli.newTestChain
        /home/rik/dev/neo-go/cli/executor_test.go:77 +0x47d
FAIL    github.com/nspcc-dev/neo-go/cli 14.479s
2020-09-19 21:49:05 +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
Evgenii Stratonikov
e0f406fd3a rpc/client: add constant to ValidUntilBlock
There are 2 problems:
1. `getvalidators` RPC can return empty list.
2. `+1` in single node can be too resrictive.
Proper solution for (1) may require requesting
standby validators. Here we add constant
to fix occasional test failures.
2020-09-18 12:07:02 +03:00
Evgenii Stratonikov
914b12af44 network: fix datarace in TCPTransport 2020-09-18 12:07:02 +03:00
Evgenii Stratonikov
40a24bad64 cli: add tests for wallet import-deployed
Fix bugs with import, allow to sign tx with contract.
2020-09-18 12:07:02 +03:00
Evgenii Stratonikov
282b55494b consensus: allow to shutdown service 2020-09-18 12:07:01 +03:00
Evgenii Stratonikov
758a88a813 rpc: exit from Start after Listener is running
If port is dynamically allocated, `(*Server).Addr` will contain
0 port. This commit executes listener before exiting from `Start()`
and sets Addr to the actual address.
2020-09-18 12:05:31 +03:00
Roman Khimov
af6a6f5f30 consensus: fix potential system deadlock
There is a notification pushed into the channel when block is being added,
that notification is read by special goroutine that then forwards it to all
subscribers to that particular event. Consensus goroutine is one of that
subscribers, so for the system to properly function it has to read these
events, but at the same time it can generate new blocks inside, so in some
cases it can generate two blocks without ever reading from the subscription
channel and this will lead to a deadlock.

To avoid that we need to check subscription channel for events on every loop.
2020-09-18 10:21:47 +03:00
Roman Khimov
1dc93216ee
Merge pull request #1408 from nspcc-dev/header-hash-list
Header hash list optimization
2020-09-16 17:52:44 +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
Evgenii Stratonikov
1625689316 transaction: implement OracleResponse attribute 2020-09-16 14:50:31 +03:00
Roman Khimov
5f22bdfecf
Merge pull request #1375 from nspcc-dev/compiler/types
Smartcontract types definition in interops
2020-09-16 14:43:50 +03:00
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
Evgenii Stratonikov
06b29e409c transaction: remove Attribute.Data field 2020-09-16 13:39:53 +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