Commit graph

81 commits

Author SHA1 Message Date
Evgenii Stratonikov
c9d5f8b89c rpc: cover stack_param with more tests
Use require/assert instead of builtin facilities.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2019-11-22 13:20:15 +03:00
Evgenii Stratonikov
0f9024d177 rpc: make client default values constants
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2019-11-22 12:57:10 +03:00
Evgenii Stratonikov
3afcd784f0 rpc: refactor tests
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2019-11-22 12:57:07 +03:00
Evgenii Stratonikov
d5fa31cecd rpc: trim spaces in tests once
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2019-11-22 12:57:03 +03:00
Evgenii Stratonikov
c8987eda32 rpc: add array param type and tests
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2019-11-22 12:56:58 +03:00
Evgenii Stratonikov
7331127556 rpc: make parameter type an enum
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2019-11-22 12:56:49 +03:00
Roman Khimov
5841d3931e rpc: implement getunspents method, fix #473 2019-11-18 11:30:09 +03:00
Roman Khimov
1a5731e005 core: rework balance accounting
Store all unspents instead of balance values. Bump store version as this is an
incompatible change.
2019-11-15 22:05:09 +03:00
Roman Khimov
b05754deac core: add Close() to blockchainer, implement it to properly close chain
Before it the deferred function in Run() was actually never able to properly
close the Store, so we weren't synching the latest state to the disk.
2019-11-08 12:19:54 +03:00
Vsevolod Brekelov
11ce73af28 server: add log-path and address configuration
- LogPath can be configured through config
- node,rpc and monitoring address can be configured thought command line
or config
2019-11-06 15:58:54 +03:00
Roman Khimov
e859e03240 network: split Peer's NetAddr into RemoteAddr and PeerAddr
As they are different things used for different purposes.
2019-11-06 15:26:24 +03:00
Roman Khimov
de2eeb4671 rpc: add one to the block height for the getblockcount response
There is a difference in interpretation of what a block count is. neo-go nodes
currently respond to this request with the latest block number which is the
same number that neoscan.io shows. However, C# nodes deliberately do add one
to this number when answering to the getblockcount request to account for the
genesis block number 0.

This patch makes us consistent with C# nodes wrt to getblockcount behaviour.
2019-11-01 20:13:00 +03:00
Roman Khimov
70e4529848 rpc: add 0x prefix to the getbestblockhash answer
For consistency with C# nodes that do add it to their answers.
2019-11-01 20:12:44 +03:00
Roman Khimov
b46dd295bc rpc: add CORS workaround for RPC
This one enables our RPC to be called from the browser if there is a
need. It's insecure and not standards-compliant, thus this behaviour is
configurable is not enabled by default. It makes our node with this workaround
enabled compatible with neo-mon monitoring.

Originally debugged by @anatoly-bogatyrev in #464.
2019-11-01 13:39:47 +03:00
Roman Khimov
2f6e678a19
Merge pull request #463 from nspcc-dev/smartcontract-fixes
Smartcontract RPC fixes
2019-10-29 20:54:46 +03:00
Vsevolod Brekelov
d374175170 monitoring: add prometheus monitoring
add init metrics service which uses prometheus;
add configuration for metrics service;
add monitoring metrics for blockchain,rpc,server;
2019-10-29 20:51:17 +03:00
Roman Khimov
ebc1ba4f38 rpc/core: implement invokescript method, fix #348
Extend Blockchainer with one more method to spawn a VM for test runs and use
it to run scripts. Gas consumption is not counted or limited in any way at the
moment (see #424).
2019-10-29 18:31:39 +03:00
Roman Khimov
3d6cf3a647 rpc: drop useless cases from server
Let them be handled by `default` statement returning a proper error instead of
plaintext message.
2019-10-29 16:48:14 +03:00
Roman Khimov
1250bf9579
Merge pull request #443 from nspcc-dev/spellcheck
spellcheck and comments fix
2019-10-22 18:01:40 +03:00
Vsevolod Brekelov
8ee421db14 fix spelling and godoc comments 2019-10-22 17:56:03 +03:00
Vsevolod Brekelov
31212676f2 rpc: swap fmt to log for response handling 2019-10-17 18:23:49 +03:00
Roman Khimov
a6610ba082 core: verify blocks, fix #12
This adds the following verifications:
 * merkleroot check
 * index check
 * timestamp check
 * witnesses verification

VerifyWitnesses is also renamed to verifyTxWitnesses here to not confuse it
with verifyBlockWitnesse and to hide it from external access (no users at the
moment).
2019-10-15 18:58:17 +03:00
Roman Khimov
258f397b9a core: append transactions to the block in GetBlock()
We want to get a full block, so it has to have transactions
inside. Unfortunately our tests were used to this wrong behavior and utilized
completely bogus transactions without data that couldn't be persisted, so fix
that also.
2019-10-15 12:56:25 +03:00
Roman Khimov
920d7c610c core: remove blockCache, use MemoryStore, redesign persist()
Commit 578ac414d4 was wrong in that it saved
only a part of the block, so depending on how you use blockchain, you may
still see that the block was not really processed properly. To really fix it
this commit introduces intermediate storage layer in form of memStore, which
actually is a MemoryStore that supports full Store API (thus easily fitting
into the existing code) and one extension that allows it to flush its data to
some other Store.

It also changes AddBlock() semantics in that it only accepts now successive
blocks, but when it does it guarantees that they're properly added into the
Blockchain and can be referred to in any way. Pending block queing is now
moved into the server (see 8c0c055ac657813fe3ed10257bce199e9527d5ed).

So the only thing done with persist() now is just a move from memStore to
Store which probably should've always been the case (notice also that
previously headers and some other metadata was written into the Store
bypassing caching/batching mechanism thus leading to some inefficiency).
2019-09-27 15:42:35 +03:00
Roman Khimov
578ac414d4 core: make unpersisted blocks/txs available in Blockchain
This changes the Blockchain to also return unpersisted (theoretically, verified
in the AddBlock!) blocks and transactions, making Add/Get interfaces
symmetrical. It allows to turn Persist into internal method again and makes it
possible to enable transaction check in GetBlock(), thus fixing #366.
2019-09-25 17:46:28 +03:00
Roman Khimov
2daff0957a rpc: check for error responses in tests
sendrawtransaction_negative was actually wrong in trying to get
SendTXResponse, it received an error.
2019-09-24 18:47:23 +03:00
Roman Khimov
5cddfe071b
Merge pull request #403 from nspcc-dev/fix_rpctest
Fix rpctest, fix #353, fix #305.
2019-09-18 23:14:37 +03:00
Vsevolod Brekelov
100fee164b unitTest: reworked RPC unit test
earlier we had an issue with failing test in #353 and other one #305.
Reworked these test to have in-memory database. This led to multiple
changes: made some functions like Hash and Persist public(otherwise
it's not possible to control state of the blockchain); removed
unit_tests storage package which was used mainly for leveldb in unit
tests.
I see these tests not really good since they look like e2e tests and
as for me should be run in separate step against dockerized env or
in case we want to check rpc handler we might want to rework it in order
to have interface for proper unit tests.
As for me this patchset at least makes as safe with not removing totally
previous tests and at the same time CircleCI will be happy now.
2019-09-18 18:21:16 +03:00
Roman Khimov
c68a254eba
Merge pull request #404 from nspcc-dev/move-user-docs
Move user docs, fix #339.
2019-09-18 12:50:06 +03:00
Roman Khimov
9441c5e77b rpc: split README into developer and user parts
Most of the document is written for developers and thus belongs to
godoc. User-related document is now moved to docs as per #339.
2019-09-18 12:10:12 +03:00
Vsevolod Brekelov
adc880d323 blockchain: server runs goroutine instead of blockchain init
rework initBlockChain in order to have controllable way of running
blockchain;
remove context from initBlockChain func;
2019-09-17 15:27:40 +03:00
Roman Khimov
d1a4e43c48 io: redo Serializable to return errors in BinReader/BinWriter
Further simplifies error handling.
2019-09-17 13:21:52 +03:00
Roman Khimov
e299a44983 io: drop Size() method from Serializable and associated
It's no longer needed after the io.GetVarSize() improvement. It's duplicating
a lot of EncodeBinary() logic also.
2019-09-17 13:21:45 +03:00
Roman Khimov
5bf00db2c9 io: move BinReader/BinWriter there, redo Serializable with it
The logic here is that we'll have all binary encoding/decoding done via our io
package, which simplifies error handling. This functionality doesn't belong to
util, so it's moved.

This also expands BufBinWriter with Reset() method to fit the needs of core
package.
2019-09-16 23:39:51 +03:00
Vsevolod Brekelov
264dfef370 storage: close function
add close function to storage interface
add common defer function call which will close db connection
remove context as soon as it's not needed anymore
updated unit tests
2019-09-16 18:52:47 +03:00
Roman Khimov
4d7456903b
Merge pull request #377 from nspcc-dev/config_for_db
storage: support of Redis and configuration for DB

Closes #336.
2019-09-10 17:46:31 +03:00
Vsevolod Brekelov
4f680703a4 storage: multiple DB support and Redis support
add config which closes #336
add redis db support
2019-09-10 17:22:21 +03:00
Roman Khimov
8d9bc83214 util: drop Endpoint structure, fix #321
I think it's useless, buggy and hides parsing errors for no good reason.
2019-09-09 17:54:38 +03:00
Roman Khimov
fabd11699a *: gofmt -s
Appy gofmt for all the source tree.
2019-09-09 12:02:24 +03:00
Roman Khimov
2c3e92923f keys: simplify error handling for PublicKey() and associated
PublicKey() for PrivateKey now just can't fail and it makes no sense to return
an error from it. There is a lot of associated functionality for which this
also is true, so adjust it accordingly and simplify a lot of code.
2019-09-05 12:34:12 +03:00
Roman Khimov
2c2f91564f rpc: comment out getBlock and getRawTransaction
After the 8388f4a55e Golint quickly pointed that
these are unused, so comment 'em out for now.
2019-09-03 18:25:19 +03:00
Roman Khimov
8388f4a55e rpc: unexport methods returning internal structures
Golint:
pkg/rpc/rpc.go:15:67: exported method GetBlock returns unexported type *rpc.response, which can be annoying to use
pkg/rpc/rpc.go:82:64: exported method GetRawTransaction returns unexported type *rpc.response, which can be annoying to use
pkg/rpc/rpc.go:97:52: exported method SendRawTransaction returns unexported type *rpc.response, which can be annoying to use

Refs. #213.
2019-09-03 18:16:48 +03:00
Roman Khimov
1fd5e5928c rpc: fix bad name spellings noted by golint
pkg/rpc/neoScanBalanceGetter.go:54:56: method parameter assetIdUint should be assetIDUint
pkg/rpc/neoScanBalanceGetter.go:62:3: var assetId should be assetID
pkg/rpc/server_test.go:27:5: var testRpcCases should be testRPCCases
pkg/rpc/txTypes.go:19:3: struct field assetId should be assetID
pkg/rpc/txTypes.go:39:35: interface method parameter assetId should be assetID
pkg/rpc/types.go:115:2: struct field TxId should be TxID

Refs. #213.
2019-09-03 18:16:48 +03:00
Roman Khimov
a9b9c9226d *: add/fix godoc comments to satisfy golint
Fixes things like:
 * exported type/method/function X should have comment or be unexported
 * comment on exported type/method/function X should be of the form "X ..."
   (with optional leading article)

Refs. #213.
2019-09-03 17:57:51 +03:00
Roman Khimov
8ececdc9a7 transaction: fix invocation decoding for different versions
Quick fix similar to abc5833853 + uncomment the
test case for it.

Closes #173.
2019-08-30 11:41:10 +03:00
Roman Khimov
b77e533d13 crypto/wallet: move public/private key into the new keys package
And drop associated _pkg.dev remnants (refs. #307).

Original `dev` branch had two separate packages for public and private keys,
but those are so intertwined (`TestHelper` subpackage is a proof) that it's
better unite them and all associated code (like WIF and NEP-2) in one
package. This patch also:
 * creates internal `keytestcases` package to share things with wallet (maybe
   it'll be changed in some future)
 * ports some tests from `dev`
 * ports Verify() method for public key from `dev`
 * expands TestPrivateKey() with public key check
2019-08-27 17:45:51 +03:00
Roman Khimov
c67217159f fixed8: remove trailing zeroes from string representation
Add some testcases from `dev` branch (with less than zero case added) and
remove useless trailing zeroes from the resulting string.
2019-08-26 13:32:19 +03:00
Roman Khimov
d5d570f793 uint256: add Reverse(), change String() to be BE
This one makes a little more obvious that we're operating with LE
representations mostly. Refs. #307. See #314 also.
2019-08-26 13:32:19 +03:00
dauTT
095653af23 Implement rpc server method: sendrawtransaction (#174)
* Added new config attributes: 'SecondsPerBlock','LowPriorityThreshold'

* Added new files:

* Added new method: CompareTo

* Fixed empty Slice case

* Added new methods: LessThan, GreaterThan, Equal, CompareTo

* Added new method: InputIntersection

* Added MaxTransactionSize, GroupOutputByAssetID

* Added ned method: ScriptHash

* Added new method: IsDoubleSpend

* Refactor blockchainer, Added Feer interface, Verify and GetMemPool method

* 1) Added MemPool
2) Added new methods to satisfy the blockchainer interface: IsLowPriority, Verify, GetMemPool

* Added new methods: RelayTxn, RelayDirectly

* Fixed tests

* Implemented RPC server method sendrawtransaction

* Refactor getrawtransaction, sendrawtransaction in separate methods

* Moved 'secondsPerBlock' to config file

* Implemented Kim suggestions:
1) Fixed data race issues
2) refactor Verify method
3) Get rid of unused InputIntersection  method due to refactoring Verify method
4) Fixed bug in https://github.com/CityOfZion/neo-go/pull/174#discussion_r264108135
5) minor simplications of the code

* Fixed minor issues related to

1) space
2) getter methods do not need pointer on the receiver
3) error message
4) refactoring  CompareTo method in uint256.go

* Fixed small issues

* Use sync.RWMutex instead of sync.Mutex

* Refined (R)Lock/(R)Unlock

* return error instead of bool in Verify methods
2019-03-20 12:30:05 +00:00
Evgeniy Kulikov
a5e85d69de Replace assertion for rpc/server_test.go (#156)
fix #155
fix circle-ci
2019-02-22 08:47:02 +01:00