Commit graph

73 commits

Author SHA1 Message Date
Roman Khimov
54d888ba70 io: add type-specific read/write methods
This seriously improves the serialization/deserialization performance for
several reasons:
 * no time spent in `binary` reflection
 * no memory allocations being made on every read/write
 * uses fast ReadBytes everywhere it's appropriate

It also makes Fixed8 Serializable just for convenience.
2019-12-12 20:19:50 +03:00
Roman Khimov
5b6c5af704 *: implement EncodeBinary with pointer receivers where appropriate
Everywhere except ParamType (which is just a byte), reduce copying things
around for no real reason.
2019-12-09 18:25:15 +03:00
Evgenii Stratonikov
fccb008594 io: implement ReadBytes() 2019-12-09 15:00:15 +03:00
Roman Khimov
e4d821f32d
Merge pull request #546 from nspcc-dev/write-optimizations
Write optimizations
2019-12-06 19:40:38 +03:00
Roman Khimov
844491d365 *: use more efficient WriteBytes where appropriate
Before this patch on block import we could easily be spending more than 6
seconds out of 30 in Uint256 encoding for UnspentBalance, now it's completely
off the radar.
2019-12-06 18:22:21 +03:00
Evgenii Stratonikov
aa20a95181 util: add Uint256DecodeStringBE() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
72fe884faa util: add Uint160DecodeStringLE() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
07e832f046 util: add Uint160DecodeBytesLE() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
09b295d727 util: add Uint160.Reverse() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
9e04e61533 util: make Uint160Size public 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
7179e4ba9f util: add LE suffix to Uint256 methods 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
57efad912c util: add LE suffix to Uint160 methods 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
ab922c1810 util: add missing tests for Uint256 2019-11-25 11:55:26 +03:00
Evgenii Stratonikov
d018dc4e56 util: add missing tests for Uint160 2019-11-25 11:55:26 +03:00
Evgenii Stratonikov
18075bc5c8 util: add missing tests for Fixed8 2019-11-25 11:54:59 +03:00
Evgenii Stratonikov
116d4c656e util: make tests use require 2019-11-25 11:53:49 +03:00
Evgenii Stratonikov
2be18f91df util: implement io.Serializable for Uint256 2019-11-14 14:20:38 +03:00
Evgenii Stratonikov
61fdd5cde5 util: make Uint256Size public 2019-11-13 17:09:55 +03:00
Vsevolod Brekelov
8ee421db14 fix spelling and godoc comments 2019-10-22 17:56:03 +03:00
Vsevolod Brekelov
59e3bd2fa9 codestyle: fix error string should not be capitalized 2019-10-18 18:34:58 +03:00
Roman Khimov
8537700b7b core: sort hashes and witnesses in VerifyWitnesses()
Fixes failure to verify some multi-witnesses transactions in Testnet chain. C#
code contains similar logic.
2019-10-01 13:41:26 +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
0da9fe6946 io: move size calculator there
It's mostly used for Serializable and in other cases where one needs to
estimate binary-encoded size of the stucture. This also simplifies future
removal of the Size() from Serializable.
2019-09-16 23:39:54 +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
Roman Khimov
031a260cb1 util: add tests for BinaryReader/BinaryWriter
100% coverage.
2019-09-16 23:38:48 +03:00
Roman Khimov
72fc880182 util: remove bogus check from BinWriter.WriteVarUint()
val is uint64, it can't be less than zero by definition.
2019-09-16 23:38:48 +03:00
Roman Khimov
aacf58c9ab util: add 'constructors' for BinReader/BinWriter
And an additional BufBinWriter to ease buffer management.
2019-09-16 23:38:48 +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
8c448ab890 util: add some tests to make GetVarSize() fully covered 2019-09-07 10:28:00 +03:00
Roman Khimov
6bfcc615b2 *: fix some misspellings
Found by goreport.
2019-09-03 18:20:05 +03:00
Roman Khimov
7b46f9bb86 util: add error check to Read/WriteVarUint
Fixes possibility of bogus reads/writes. Suggested by @im-kulikov.
2019-08-29 13:26:03 +03:00
Roman Khimov
15311f202b util: drop io, reuse its tests for binaryRW 2019-08-28 19:45:17 +03:00
Roman Khimov
07096a551b util: move strange Read2000Uint256Hashes() into storage
It's the only user of it.
2019-08-28 14:38:57 +03:00
Roman Khimov
672668b9fb util: use more consistent and explicit naming for BR/BW 2019-08-28 13:24:06 +03:00
Roman Khimov
6409cc753c util: move binaryReader/Writer from _pkg.dev
These are useful and nice.
2019-08-28 12:44:23 +03:00
Roman Khimov
ec7e17ffa6 pkg: make use of the new crypto/hash package
Simplifies a lot of code and removes some duplication. Unfortunately I had to
move test_util random functions in same commit to avoid cycle
dependencies. One of these random functions was also used in core/transaction
testing, to simplify things I've just dropped it there and used a static
string (which is nice to have for a test anyway).

There is still sha256 left in wallet (but it needs to pass Hash structure into
the signing function).
2019-08-26 13:32:19 +03:00
Roman Khimov
2fd782eee8 util: drop RandUint32()
I don't see anything useful in it, all the current users of it should just use
plain rand.Uint32() not limiting its output in any way.
2019-08-26 13:32:19 +03:00
Roman Khimov
5c5878968b hask: import package from _pkg.dev, make it compile 2019-08-26 13:32:19 +03:00
Roman Khimov
37be2e215c array: add a test for even num of elements
And drop duplicating code from _pkg.dev.
2019-08-26 13:32:19 +03:00
Roman Khimov
0cde8d962d fixed8: switch to more uniform function naming 2019-08-26 13:32:19 +03:00
Roman Khimov
b0af8b306d fixed8: fix Satoshi() and add a test for it 2019-08-26 13:32:19 +03:00
Roman Khimov
20a4ad99b3 fixed8: add some testcases from dev, split Value functions
Add FloatValue() and rename Value() to Int64Value() for consistency.
2019-08-26 13:32:19 +03:00
Roman Khimov
a861f53733 fixed8: simplify arithmetic functions
I'm not sure they're of any use at all.
2019-08-26 13:32:19 +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
Roman Khimov
c1b1b6fca4 uint160: move ReverseString() from _pkg.dev
With associated test and drop duplicating Uint160 implementation from
_pkg.dev. It doesn't seem to be used in pkg code at the moment, but still it
can be useful. Refs #307.
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
dauTT
19201dcf52 Implemented rpc server method GetRawTransaction (#135)
* Added utility function GetVarSize

* 1) Added Size method: this implied that Fixed8 implements now the serializable interface. 2) Added few arithmetic operation (Add, Sub, div): this will be used to calculated networkfeeand feePerByte. Changed return value of the Value() method to int instead of int64. Modified fixed8_test accordingly.

* Implemented Size or MarshalJSON method.
- Structs accepting the Size method implement the serializable interface.
- Structs accepting the MarshalJSON method implements the customized json marshaller interface.

* Added fee calculation

* Implemented rcp server method GetRawTransaction

* Updated Tests

* Fixed:
1) NewFixed8 will accept as input int64
2) race condition affecting configDeafault, blockchainDefault

* Simplified Size calculation

* 1) Removed global variable blockchainDefault, configDefault
2) Extended Blockchainer interface to include the methods: References, FeePerByte, SystemFee, NetworkFee
3) Deleted fee_test.go, fee.go. Moved corresponding methods to blockchain_test.go and blockchain.go respectively
4) Amended tx_raw_output.go

* Simplified GetVarSize Method

* Replaced ValueAtAndType with ValueWithType

* Cosmetic changes + Added test case getrawtransaction_7

* Clean up Print statement

* Filled up keys

* Aligned verbose logic with the C#-neo implementation

* Implemented @Kim requests
Refactor server_test.go

* Small fixes

* Fixed verbose logic
Added more tests
Cosmetic changes

* Replaced assert.NoError with require.NoError

* Fixed tests by adding context.Background() as argument

* Fixed tests
2019-02-20 18:39:32 +01:00
Evgeniy Kulikov
cdba88b9f2 Code refactoring (#143)
- simplify code
- prealoc slices
- check errors in tests
- regexp Compile replaced with MustCompile
- uint* cannot be negative
2019-02-19 14:22:33 +01:00