Commit graph

382 commits

Author SHA1 Message Date
Roman Khimov
c3c88a57cd
Merge pull request #1281 from nspcc-dev/drop-go-1.12-and-fix-some-things
Drop go 1.12 and fix some things
2020-08-07 13:34:54 +03:00
Roman Khimov
791c983304 core: drop GetScriptHashesForVerifying
It no longer depends on blockchain state and there can't ever be an error, in
fact we can always iterate over signers, so copying these hashes doesn't make
much sense at all as well as sorting arrays in verifyTxWitnesses (witnesses
order must match signers order).
2020-08-07 12:21:52 +03:00
Roman Khimov
0e2784cd2c always wrap errors when creating new ones with fmt.Errorf()
It doesn't really change anything in most of the cases, but it's a useful
habit anyway.

Fix #350.
2020-08-07 12:21:52 +03:00
Roman Khimov
205f52c563 core: use error wrapping to provide more details 2020-08-07 12:21:52 +03:00
Roman Khimov
5ef08f60ae remove github.com/pkg/errors from dependencies
It's not needed any more with Go 1.13 as we have wrapping/unwrapping in base
packages. All errors.Wrap calls are replaced with fmt.Errorf, some strings are
improved along the way.
2020-08-07 12:21:52 +03:00
Evgenii Stratonikov
27169d140f core: implement (*Blockchain).GetStandByCommitee() 2020-08-06 20:39:13 +03:00
Anna Shaleva
6c8accf18c core, network: request blocks instead of headers
Closes #1192

1. We now have CMDGetBlockByIndex, so there's no need to request headers
   first when we can just ask for blocks.
2. We don't ask for headers (i.e. we don't send CMDGetHeaders),
   consequently, we shouldn't react on CMDHeaders.
3. But we still keep on reacting on CMDGetHeaders command as
   there could be a node which needs headers.
2020-08-04 17:52:34 +03:00
Anna Shaleva
f6f3863e0e network: allow to GetHeaders by index
Use GetBlockByIndex payload for GetHeaders command instead of GetBlocks
payload.
2020-08-04 17:52:34 +03:00
Anna Shaleva
7b1c305000 network: fix handleGetBlockByIndexCmd method
It returned an error in case if block wasn't found (it might be when our
chain is lower). Fixed. It also should return all requested blocks, not
the first one.
2020-08-04 17:52:34 +03:00
Anna Shaleva
0b0591fc34 network: allow to use -1 to specify GetBlockByIndex.Count 2020-08-04 17:52:34 +03:00
Anna Shaleva
0b856033b0 network: use MaxHeadersAllowed to restrict GetBlockByIndex 2020-08-04 17:52:34 +03:00
Anna Shaleva
737ba700e9 network: rename GetBlockData command
GetBlockData -> GetBlockByIndex
2020-08-04 17:52:34 +03:00
Roman Khimov
62f5aa8eb4
Merge pull request #1254 from nspcc-dev/native/policy/maxblocksystemfee
core, consensus: add maxBlockSystemFee to native Policy
2020-08-04 13:13:06 +03:00
Anna Shaleva
db65ed04d9 consensus: apply policy during verifyBlock
To follow C# implementation we should also check proposed block on
policy matching.
2020-08-04 10:59:09 +03:00
Roman Khimov
1f46f73d12 network: handle length mismatch in decompression routine
It's a protocol level error when uncompressed payload size doesn't match the
one specified in the header.
2020-08-03 22:38:55 +03:00
fyrchik
babd84ec10
Merge pull request #1243 from nspcc-dev/protocol/uncompressed_payload_size
network: add uncompressed payload size
2020-07-31 10:03:55 +03:00
fyrchik
e4fc655115
Merge pull request #1239 from nspcc-dev/store_nep5_with_id
core: store contract IDs instead of hashes for NEP5Balances and Transfers
2020-07-30 12:56:19 +03:00
Anna Shaleva
2574b65b74 network: add uncompressed payload size
Closes #1212
2020-07-30 12:47:42 +03:00
Evgenii Stratonikov
0e29382035 core: update MPT during block processing
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Anna Shaleva
dbd460d883 core: retrieve contract hash by ID
We'll need this ability further to retrieve contracts hashes for Nep5Balances.
2020-07-29 15:14:24 +03:00
Roman Khimov
432cef59f4 network: copy peers for Shutdown iteration
We can't lock them (or there will be a deadlock), but we need to fix this:

fatal error: concurrent map iteration and map write

goroutine 1 [running]:
runtime.throw(0xdec086, 0x26)
        /usr/lib64/go/1.12/src/runtime/panic.go:617 +0x72 fp=0xc02fec2bf8 sp=0xc02fec2bc8 pc=0x42d932
runtime.mapiternext(0xc02fec2d40)
        /usr/lib64/go/1.12/src/runtime/map.go:860 +0x597 fp=0xc02fec2c80 sp=0xc02fec2bf8 pc=0x40efe7
github.com/nspcc-dev/neo-go/pkg/network.(*Server).Shutdown(0xc0000fc160)
        /home/rik/dev/neo-go2/pkg/network/server.go:194 +0x238 fp=0xc02fec2db0 sp=0xc02fec2c80 pc=0xa89da8
github.com/nspcc-dev/neo-go/cli/server.startServer(0xc0000fcc60, 0x0, 0x0)
        /home/rik/dev/neo-go2/cli/server/server.go:399 +0x7a9 fp=0xc02fec3820 sp=0xc02fec2db0 pc=0xae2079
...
2020-07-17 19:03:12 +03:00
Anna Shaleva
db5b42b601 network: update CMDUncknown
Closes #1135
2020-07-16 06:58:55 +03:00
Roman Khimov
7eef895061 consensus: use GetNextBlockValidators where appropriate
GetValidators without parameter is called upon DBFT initialization and it
should receive validators for the next block (that will create it),
parameterized GetValidators is used for NextConsensus calculation where we
need a list for the current state of the chain.
2020-07-11 19:54:50 +03:00
Anna Shaleva
abe3c94b95 core: use big.Int to store NEP5 balances
closes #1133
2020-07-09 13:26:39 +03:00
Roman Khimov
08c516014f
Merge pull request #1132 from nspcc-dev/neo3/rpc/fixed8_marshalling
*: switch from Fixed8 to int64
2020-06-29 21:44:40 +03:00
Anna Shaleva
0aaaf7f787 *: switch from fixed8 to int64 in (Blockchain).CalculateClaimable 2020-06-29 21:40:54 +03:00
Anna Shaleva
73b630db9b *: switch from fixed8 to int64
Follow C# implementation, we have to marshall JSON Fixed8 fields without
taking into account decimals.
2020-06-29 21:39:27 +03:00
Roman Khimov
372dd71708
Merge pull request #1108 from nspcc-dev/neo3/compiler/nef
compiler: support *.nef and *.manifest.json generation
2020-06-29 20:55:47 +03:00
Anna Shaleva
6b8957243a *: move wallet config from wallet to config package
In order to avoid dependency cycle at the next commits:

	imports github.com/nspcc-dev/neo-go/pkg/config
	imports github.com/nspcc-dev/neo-go/pkg/wallet
	imports github.com/nspcc-dev/neo-go/pkg/vm
	imports github.com/nspcc-dev/neo-go/pkg/smartcontract/nef
	imports github.com/nspcc-dev/neo-go/pkg/config
2020-06-29 09:15:29 +03:00
Evgenii Stratonikov
857ced8230 consensus: add network magic to hash data
Consensus payload's hash now depends on the network node is operating
in.
2020-06-26 18:41:04 +03:00
Roman Khimov
21cb7d5701
Merge pull request #1078 from nspcc-dev/feature/mempool
network: implement CMDMempool command
2020-06-24 10:49:42 +03:00
Evgenii Stratonikov
57bb2f73de network: implement CMDMempool command
CMDMempool returns hashes of transactions in mempool in chunks.
2020-06-24 10:46:26 +03:00
Roman Khimov
e5f05790d5 core: cache standby validators in the Blockchain
They never change, so it makes no sense parsing the keys over and over
again. It also simplifies the interface a little.
2020-06-24 10:22:17 +03:00
Anna Shaleva
08cc04c3d5 core: add native policy contract
part of #904
2020-06-24 07:35:07 +03:00
Roman Khimov
892812d539 message: fix Verack processsing
Recent 9f42108ef completely broke handshaking.
2020-06-20 00:28:51 +03:00
Roman Khimov
36a65e3847
Merge pull request #1077 from nspcc-dev/neo3/smartcontract/id
core: store smartcontract items by id
2020-06-20 00:12:07 +03:00
Anna Shaleva
f1cdcbc99c core: store smartcontract items by id
closes #1037
2020-06-19 20:48:45 +03:00
Evgenii Stratonikov
505029152f payload: always dereference NullPayload
There is no need in extra indirection level.
2020-06-19 15:02:21 +03:00
Evgenii Stratonikov
9f42108ef2 network: allow NullPayload only for specific commands
CMDFilterClear, CMDGetAddr, CMDMempool all have empty payloads.
2020-06-19 15:01:30 +03:00
Roman Khimov
93b0011988
Merge pull request #1069 from nspcc-dev/addr-locking-and-other-fixes
Addr, locking and other fixes
2020-06-18 23:29:19 +03:00
Evgenii Stratonikov
5354352d63 core: remove transaction priority
There is no such thing as high/low priority transactions, as there are
no free transactions anymore and they are ordered by fees contained
in transaction itself.

Closes #1063.
2020-06-18 22:44:10 +03:00
Roman Khimov
bbe174ee4a network: fix inverted logic of address addition to the pool
Fix #1066.
2020-06-18 21:34:45 +03:00
Roman Khimov
b483c38593 block/transaction: add network magic into the hash
We make it explicit in the appropriate Block/Transaction structures, not via a
singleton as C# node does. I think this approach has a bit more potential and
allows better packages reuse for different purposes.
2020-06-18 12:39:50 +03:00
Roman Khimov
dde0763840 network: fix compression handling functions
Turns out, Neo uses block compression and not a streaming lz4 format. And it
doesn't contain uncompressed payload size which makes guessing it somewhat
suboptimal.
2020-06-18 12:12:43 +03:00
Roman Khimov
8388e509df network: don't allocate memory for messages larger than PayloadMaxSize 2020-06-18 12:12:31 +03:00
Roman Khimov
39fd799992 network: fix Compress flag, it's the first bit (index 0) 2020-06-18 12:12:17 +03:00
Roman Khimov
26f11a52d9 config: move NetMode into its own micropackage
It's going to be used a bit more and pulling whole config just for one type is
a bit wrong.
2020-06-18 12:09:57 +03:00
Anna Shaleva
d5355acfa9 rpc: update RPC server invoke* calls
part of #1036
2020-06-11 19:34:13 +03:00
Anna Shaleva
3418e4f7f4 rpc: update getversion RPC-call
closes #1035
2020-06-10 10:47:11 +03:00
Roman Khimov
63f4f34659 mempool: drop TxWithFee type
All the fees are in transaction, this makes no sense.
2020-06-05 19:21:40 +03:00
Roman Khimov
a986e2a064 *: drop support for old on-chain assets
You no longer can transfer them, so creating/renewing/storing doesn't make
much sense.
2020-06-05 19:21:37 +03:00
Roman Khimov
709146f295 transaction: drop Inputs and Outputs, forget UTXO 2020-06-05 19:20:16 +03:00
Roman Khimov
3d18f09def core: fix CalculateClaimable for NEP5 NEO
It's not stored as Fixed8, so calculations need to be adjusted for that.
2020-06-05 19:20:16 +03:00
Roman Khimov
39dfebccc4 core: no longer treat sysfee as claimable
As it's not on Neo 3, it just gets burned and that's it. Only network fee is
being redistributed to CNs.
2020-06-05 19:20:16 +03:00
Roman Khimov
50ed4c5967 core: don't return an error from CalculateClaimable
As it never returns one.
2020-06-05 19:20:16 +03:00
Roman Khimov
657bb7575e rpc: change getunclaimed to getunclaimedgas
getunclaimed doesn't exist on Neo 3 and getunclaimedgas works for NEP5 GAS.
2020-06-05 19:20:16 +03:00
Roman Khimov
eec462b00c network: fix Inv types for Neo 3
They actually use the same types as for messages. Fixes
2020-05-29T00:06:17.593+0300    WARN    peer disconnected       {"addr": "168.62.167.190:20333", "reason": "handling CMDInv message: invalid inventory type", "peerCount": 3}
2020-05-29 15:02:20 +03:00
Roman Khimov
56b24bf83e capability: prevent panic on wrong capabilities receival
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xad7b95]

goroutine 134 [running]:
github.com/nspcc-dev/neo-go/pkg/network/capability.(*Capability).DecodeBinary(0xc00024a300, 0xc00015c900)
        /home/rik/dev/neo-go/pkg/network/capability/capability.go:69 +0x85
github.com/nspcc-dev/neo-go/pkg/io.(*BinReader).ReadArray(0xc00015c900, 0xd54880, 0xc00018ecd8, 0xc00071fbe0, 0x1, 0x1)
        /home/rik/dev/neo-go/pkg/io/binaryReader.go:141 +0x22f
github.com/nspcc-dev/neo-go/pkg/network/capability.(*Capabilities).DecodeBinary(0xc00018ecd8, 0xc00015c900)
        /home/rik/dev/neo-go/pkg/network/capability/capability.go:17 +0x6d
github.com/nspcc-dev/neo-go/pkg/network/payload.(*AddressAndTime).DecodeBinary(0xc00018ecc0, 0xc00015c900)
        /home/rik/dev/neo-go/pkg/network/payload/address.go:34 +0x59
github.com/nspcc-dev/neo-go/pkg/io.(*BinReader).ReadArray(0xc00015c900, 0xcb9e00, 0xc00024a2a0, 0x0, 0x0, 0x0)
        /home/rik/dev/neo-go/pkg/io/binaryReader.go:141 +0x22f
github.com/nspcc-dev/neo-go/pkg/network/payload.(*AddressList).DecodeBinary(0xc00024a2a0, 0xc00015c900)
        /home/rik/dev/neo-go/pkg/network/payload/address.go:78 +0x54
github.com/nspcc-dev/neo-go/pkg/network.(*Message).decodePayload(0xc000277890, 0xc000292020, 0xc0003da000)
        /home/rik/dev/neo-go/pkg/network/message.go:158 +0x31a
github.com/nspcc-dev/neo-go/pkg/network.(*Message).Decode(0xc000277890, 0xc00071ff48, 0xc00036e090, 0xc000276e40)
        /home/rik/dev/neo-go/pkg/network/message.go:114 +0x19b
github.com/nspcc-dev/neo-go/pkg/network.(*TCPPeer).handleConn(0xc00036e090)
        /home/rik/dev/neo-go/pkg/network/tcp_peer.go:154 +0x244
created by github.com/nspcc-dev/neo-go/pkg/network.(*TCPTransport).Dial
        /home/rik/dev/neo-go/pkg/network/tcp_transport.go:40 +0x1ad
2020-05-29 00:11:54 +03:00
Anna Shaleva
1dffe0bea9 network: remove outdated fields
After #980 there were outdated fields present in message test.
2020-05-27 19:32:50 +03:00
Roman Khimov
a446821753
Merge pull request #980 from nspcc-dev/neo3/protocol/version_payload_optimisation
protocol: add node capabilities
2020-05-27 19:13:00 +03:00
Anna Shaleva
7547a3efe1 network: minor code refactoring
We need to handle IPv6 addresses correctly and net.JoinHostPort takes it
into account.
2020-05-27 19:04:09 +03:00
Anna Shaleva
8c5c248e79 protocol: add capabilities to address payload
Part of #871
2020-05-27 19:02:25 +03:00
Anna Shaleva
c590cc02f4 protocol: add capabilities to version payload
closes #871
2020-05-27 19:01:14 +03:00
Roman Khimov
5733573d2e
Merge pull request #987 from nspcc-dev/neo3/protocol/compression
protocol: add payload compression
2020-05-26 23:31:17 +03:00
Anna Shaleva
0cbd7823ab protocol: add payload compression
closes #872
2020-05-26 22:19:10 +03:00
Roman Khimov
b7d2b659b4 network: get blocks directly from the chain for rebroadcasting
Simplify network<->consensus relations, also broadcast blocks received by
other means like RPC.
2020-05-25 00:27:39 +03:00
Roman Khimov
462022bbdd consensus: remove OnNewBlock(), use Blockchain subscription
Get new blocks directly from the Blockchain. It may lead to some duplications
(as we'll also receive our own blocks), but at the same time it's more
correct, because technically we can also get blocks via other means besides
network server like RPC (submitblock call). And it simplifies network server
at the same time.
2020-05-25 00:27:39 +03:00
Roman Khimov
3ca71d5e8d core: add Blockchain event subscription mechanism
A deep internal part of #895. Blockchainer interface is also extended for
various uses of these methods.
2020-05-25 00:27:39 +03:00
Roman Khimov
bd98940a54
Merge pull request #982 from nspcc-dev/neo3/protocol/getblockdata
protocol: implement getblockdata p2p command
2020-05-22 19:28:42 +03:00
Anna Shaleva
8142caaf8b protocol: implement getblockdata p2p command
closes #891
2020-05-22 19:16:49 +03:00
Anna Shaleva
2f6a3e9af5 protocol: refactor getblocks payload
closes #890
2020-05-22 17:33:59 +03:00
Anna Shaleva
64a2fb63e1 protocol: move magic exchange to version payload
closes #889
2020-05-21 14:23:41 +03:00
Anna Shaleva
3bcc56bdcf protocol: switch to binary MessageCommand
closes #888
2020-05-21 13:57:49 +03:00
Anna Shaleva
1afd630169 core: add senders' fees monitor to mempool
In order to simplify maintainance of overall current senders` fees
in the mempool we are to keep them in a separate map.
2020-05-20 23:34:25 +03:00
Anna Shaleva
7acf5b2841 core: add SystemFee and NetworkFee to transaction
closes #831
2020-05-20 23:26:48 +03:00
Anna Shaleva
29d321b5e1 *: drop miner transaction
1. Completely remove miner transaction

2. Change validation rule for block: block without transactions is
valid.
2020-04-27 17:57:37 +03:00
Anna Shaleva
aa554f0a9a core: update block timestamp format
Changed block.Timestamp from uint32 to uint64
2020-04-27 17:56:44 +03:00
Roman Khimov
b83e84ca08 core: switch to the new voting system (via native NEO contract)
It has all the methods required now, so you can register, vote and get
voting results. Fixes #865.
2020-04-27 16:06:50 +03:00
Evgenii Stratonikov
c508a36827 core,network: shutdown services in tests properly 2020-04-22 17:53:59 +03:00
Roman Khimov
9a67bfac0b network: drop checksums from messages
Follow neo-project/neo#710 changes.
2020-04-19 23:40:31 +03:00
Evgenii Stratonikov
8a2130f5b6 core: extend Blockchainer with GetStandByValidators()
A list of standby validators can be needed in native contracts.
2020-04-16 15:54:58 +03:00
Evgenii Stratonikov
a7c19d445b core: move Blockchainer interface to a separate package 2020-04-11 10:56:36 +03:00
Roman Khimov
5f09381cf4 core: wrap cached dao properly, don't miss cached data
Fixes #817 where invoked contract missed updated account information because
it got it one layer below cachedDao used to process the block.
2020-04-03 10:15:11 +03:00
Roman Khimov
9b5dab57e8
Merge pull request #810 from nspcc-dev/refactor/config
config: move config.go out of config
2020-04-01 10:29:57 +03:00
Anna Shaleva
5a984fdf88 config: move config.go out of config/
closes #423
2020-03-31 17:55:59 +03:00
Evgenii Stratonikov
9abda40171 testserdes: implement helpers for encode/decode routines
Frequently one needs to check if struct serializes/deserializes
properly. This commit implements helpers for such cases including:
1. JSON
2. io.Serializable interface
2020-03-27 10:27:46 +03:00
Evgenii Stratonikov
df2598c8dc core: store NEP5 balances separately
There is no need to take and unmarshal an account structure only
to get it's NEP5 balances.
2020-03-12 12:58:28 +03:00
Roman Khimov
5f1868af28
Merge pull request #743 from nspcc-dev/optimize-some-db-accesses
Optimize some db accesses
2020-03-11 17:33:36 +03:00
Roman Khimov
377fb382aa core: move (un)SpentCoin structs into the state package
As they're all about the state.
2020-03-11 12:22:52 +03:00
Evgenii Stratonikov
b7dee156e2 network: fix a deadlock in DefaultDiscovery
Why a deadlock can occur:
1. (*DefaultDiscovery).run() has a for loop over requestCh channel.
2. (*DefaultDiscovery).RequestRemote() send to this channel while
    holding a mutex.
3. (*DefaultDiscovery).RegisterBadAddr() tries to take mutex for write.
4. Second select-case can't take mutex for read because of (3).
2020-03-10 15:40:23 +03:00
Anna Shaleva
456a2d55fd rpc: implement getvalidators
closes #714
2020-03-07 18:05:40 +03:00
Roman Khimov
fbdc60b731
Merge pull request #723 from nspcc-dev/feature/nep5
core,rpc: implement NEP5-related logic
2020-03-05 18:33:58 +03:00
Evgenii Stratonikov
95a8fa234f rpc: implement getnep5transfers RPC 2020-03-05 18:22:40 +03:00
Roman Khimov
31948ee4a7 network: add a nil check in (*TCPTransport).Close, prevent panic
You have to try to trigger that, but in the event of server shutdown before it
actually started listening Close will easily panic like this:

2020-03-05T11:48:08.660+0300    INFO    node started    {"blockHeight": 6458, "headerHeight": 15605}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x9d5f0a]

goroutine 1 [running]:
github.com/nspcc-dev/neo-go/pkg/network.(*TCPTransport).Close(0xc000fd7050)
        /home/rik/dev/neo-go/pkg/network/tcp_transport.go:78 +0x2a
github.com/nspcc-dev/neo-go/pkg/network.(*Server).Shutdown(0xc000182280)
        /home/rik/dev/neo-go/pkg/network/server.go:190 +0x189
github.com/nspcc-dev/neo-go/cli/server.startServer(0xc000200160, 0x0, 0x0)
        /home/rik/dev/neo-go/cli/server/server.go:367 +0x79e
github.com/urfave/cli.HandleAction(0xb84860, 0xccf240, 0xc000200160, 0xc0001c4500, 0x0)
        /home/rik/dev/neo-go/vendor/github.com/urfave/cli/app.go:490 +0xc8
github.com/urfave/cli.Command.Run(0xc9a160, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0xca407f, 0x10, 0x0, ...)
        /home/rik/dev/neo-go/vendor/github.com/urfave/cli/command.go:210 +0x996
github.com/urfave/cli.(*App).Run(0xc0001d64e0, 0xc0000ca000, 0x3, 0x3, 0x0, 0x0)
        /home/rik/dev/neo-go/vendor/github.com/urfave/cli/app.go:255 +0x6af
main.main()
        /home/rik/dev/neo-go/cli/main.go:25 +0x505
2020-03-05 11:53:26 +03:00
Roman Khimov
e41d434a49 *: move all packages from CityOfZion to nspcc-dev 2020-03-03 17:21:42 +03:00
Evgenii Stratonikov
7095ec6c51 core: implement (*Blockchain).CalculateClaimable
Calculating amount of GAS that can be claimed is required
for getclaimable RPC.
2020-03-02 18:00:00 +03:00
Roman Khimov
252a9f2f31
Merge pull request #690 from nspcc-dev/feature/getapplicationlog
rpc: implement getapplicationlog RPC
2020-03-02 17:41:32 +03:00
Anna Shaleva
ff4384d7ff rpc: implement getapplicationlog RPC
Closes #500
2020-03-02 17:25:27 +03:00
Evgenii Stratonikov
a3dacd3b74 tests: replace t.Fatal with require where possible
This makes tests less verbose and unifies the style
they are written in.
2020-03-02 17:22:27 +03:00
Evgenii Stratonikov
0ef7a76e84 network: batch transactions on broadcast 2020-03-02 10:37:27 +03:00