Commit Graph

126 Commits

Author SHA1 Message Date
d24a30858e no gogo proto 2018-05-24 00:10:35 -04:00
9b2a8f07a3 [common] Add ASCIITrim 2018-04-23 01:32:18 -07:00
d94e312673 add MarshalJSON and UnmarshalJSON to BitArray (#200)
See CHANGELOG
2018-04-23 00:16:05 -07:00
8fa4211bbd Fixes TestParallelAbort nondeterministic failure #201 (#202) 2018-04-23 00:07:03 -07:00
e328006bfe Jae/fixprefixdb (#199)
* Fix PrefixDB Iterator
* PrefixDB Iterator/ReverseIterator fixes
* Bump version 0.8.2
* Update CHANGELOG.md about DebugDB
* Keep invalid source to be closed
* Use prefixBatch instead of memBatch
2018-04-21 04:25:45 -07:00
a807b5db57 added PrefixEndBytes (#186)
* added PrefixToBytes

* added test

* added comment
2018-04-09 12:51:24 +02:00
2e24b64fc1 Add IsEmpty; Publish 0.8.1 2018-04-05 03:14:53 -07:00
fb7bde9c24 Add cause in Error.Error() 2018-04-04 13:43:19 -07:00
5c3d3f0875 Merge pull request #194 from Tilkal/random-missing-methods
Random missing methods
2018-04-03 23:52:16 +03:00
74486f7f93 Add Int63n() and RandInt63n(). 2018-04-03 16:24:38 +02:00
d66d43d2ea Add Int31n() and RandInt31n(). 2018-04-03 16:23:36 +02:00
f457435199 HexBytes formatting; Make computeHashFromAunts more defensive 2018-04-03 07:02:19 -07:00
b5e6f8a446 Merge pull request #191 from Tilkal/random-float64
Add Float64() and RandFloat64().
2018-04-03 16:15:06 +03:00
f664b020cd Merge pull request #189 from mohanson/patch-2
bug fix: WriteFileAtomic
2018-04-03 16:13:56 +03:00
3375dac049 add Float64() and RandFloat64(). 2018-04-03 14:09:50 +02:00
b221ca0efa refine comments 2018-04-03 19:04:09 +08:00
ee67e34519 Fix lint errors (#190)
* use increment and decrement operators.

* remove unnecessary else branches.

* fix receiver names.

* remove omittable code.

* fix dot imports.
2018-04-03 12:23:28 +02:00
29a8cb8d87 add comments. 2018-04-03 16:51:30 +08:00
2fbd9f15fa bug fix: WriteFileAtomic
Must close file before rename it.
2018-04-03 15:26:47 +08:00
382e99d06e Add IsTypedNil 2018-04-02 01:47:42 -07:00
898216d419 add SplitAndTrim func (#183)
Refs https://github.com/tendermint/tendermint/issues/1380
2018-03-29 12:04:01 +02:00
e9cf47606c Merge panics into errors in Parallel 2018-03-25 00:04:47 +01:00
87c0473730 New Error (#180)
* New Error can capture Stacktrace
* Intelligent ErrorWrap
* Review fixes
2018-03-24 22:19:44 +01:00
d46b9afb79 Simplify WriteFileAtomic
We can make the implementation more robust by adjusting our assumptions
and leverage explicit file modes for syncing. Additionally we going to
assume that we want to clean up and can't really recover if thos
operations (file close and removal) fail.

* utilise file mode for majority of concerns
* improve test coverage by covering more assumptions
* signature parity with ioutil.WriteFile
* always clean up

Replaces #160
2018-03-22 19:36:24 -04:00
97bdad8262 common: NewBitArray never crashes on negatives (#170)
Fixes #169
Fixes https://github.com/tendermint/tendermint/issues/1322

The previous code was very trusting assuming that
rational actors will use this code. However, Byzantine
actors don't care and in the case of the linked issue
negative lengths can be sent to this code unfettered
having been received from a peer.

This code is essentially just a sign change from
`==`
to
`<=`

and we've gutted out that attack by being more defensive.
2018-03-22 19:36:24 -04:00
a86b1d8f75 Merge pull request #171 from tendermint/feature/xla-writefileatomic
Simplify WriteFileAtomic
2018-03-21 05:04:14 +01:00
4e5c655944 Parallel reaps automatically before returning 2018-03-20 23:08:51 +01:00
4caf943f49 Parallel returns a TaskResultSet 2018-03-20 21:43:58 +01:00
db48010e81 Add return parameter to Parallel 2018-03-20 19:58:05 +01:00
bf24f2dcc5 Implement better Parallel (#174)
* Implement better Parallel
2018-03-20 19:24:18 +01:00
bb65f097fd Simplify WriteFileAtomic
We can make the implementation more robust by adjusting our assumptions
and leverage explicit file modes for syncing. Additionally we going to
assume that we want to clean up and can't really recover if thos
operations (file close and removal) fail.

* utilise file mode for majority of concerns
* improve test coverage by covering more assumptions
* signature parity with ioutil.WriteFile
* always clean up

Replaces #160
2018-03-19 09:38:28 +01:00
4b0058dd64 common: remove {Left, Right}PadString (#168)
Fixes #134

Those functions are unused in the whole Tendermint Github
organization plus they were unnecessariy verbose and could
have been concisely replaced with

```go
func RightPadString(s string, totalLength uint) string {
       return fmt.Sprintf("% *s", totalLength, s)
}

func LeftPadString(s string, totalLength uint) string {
       return fmt.Sprintf("% -*s", totalLength, s)
}
```

delete them anyways
2018-03-18 15:19:23 +04:00
b1c9b82531 common: NewBitArray never crashes on negatives (#170)
Fixes #169
Fixes https://github.com/tendermint/tendermint/issues/1322

The previous code was very trusting assuming that
rational actors will use this code. However, Byzantine
actors don't care and in the case of the linked issue
negative lengths can be sent to this code unfettered
having been received from a peer.

This code is essentially just a sign change from
`==`
to
`<=`

and we've gutted out that attack by being more defensive.
2018-03-18 15:17:11 +04:00
3412587036 Fix race condition in random.go 2018-03-18 01:50:15 +01:00
9b9a9e7f8c Add Error Type for switching 2018-03-17 16:32:49 +01:00
99437a96fb Add efficient implementation of fmt and use for errors. 2018-03-17 15:23:22 +01:00
bb875303c2 Add NewErrorWithCause() 2018-03-17 14:44:12 +01:00
de36bfe31c Add TMLibs/Error from Cosmos-SDK/Error 2018-03-17 13:56:39 +01:00
90cd89eab0 Unexpose r.rand (#167) 2018-03-17 05:18:22 -07:00
6d61ca3bb5 New -> NewRand 2018-03-17 12:34:23 +01:00
536c27de8e common/random.go supports seeding and *Rand (#121)
* common/random.go supports seeding and *Rand
* Ensure determinism
2018-03-17 04:28:53 -07:00
d289c9286e Implement NewPrefixDB (#164)
* encodeByteSlice uses uvarint for length instead of varint
* Implemented NewPrefixDB
* Fix flowrate test (#165)
* Complete implementation and fix tests
* Add tests for MemBatch Write[Sync]
2018-03-15 09:43:23 -07:00
26f2ab65f8 Switch to dep from glide (#155) 2018-02-27 16:01:49 +04:00
737c30c19d minor nit 2018-02-12 19:12:24 -05:00
a57340ffb5 add Quit method to Service interface
remove deprecated QuitService
2018-02-12 11:40:42 +04:00
52ce4c20f8 Fix RepeatTimer memory leak (#137)
fix RepeatTimer memory leak (Refs #137)

* test case

* drain channels on reset

Leaking memory:
```
leaktest.go:144: leaktest: leaked goroutine: goroutine 116 [chan send]:
        github.com/tendermint/tmlibs/common.(*RepeatTimer).fireRoutine(0xc42006a410, 0xc4203403c0, 0xc42031b2c0)
                /go/src/github.com/tendermint/tmlibs/common/repeat_timer.go:160 +0x6e
        created by github.com/tendermint/tmlibs/common.(*RepeatTimer).reset
                /go/src/github.com/tendermint/tmlibs/common/repeat_timer.go:196 +0xe9
```

The alternative solution could be draining channels on the client side.

* add one more select instead of draining

thanks to Jae
2018-02-09 13:31:32 +04:00
35bb398b1f Merge pull request #147 from tendermint/reduce-bitArray-fragility
common/BitArray: reduce fragility with methods
2018-02-08 15:31:30 -05:00
763dc21393 common/BitArray: reduce fragility with methods
Fixes https://github.com/tendermint/tmlibs/issues/145
Fixes https://github.com/tendermint/tmlibs/issues/146

The code in here has been fragile when it comes to nil
but these edge cases were never tested, although they've
showed up in the wild and were only noticed because
the reporter actually read the logs otherwise
we'd have never known.

This changes covers some of these cases and adds some tests.
2018-02-06 01:12:24 -08:00
951333ecb0 common: IsHex should be able to handle 0X prefixed strings
IsHex should also successfully decode strings prefixed with
0X instead of only 0x strings.

Also add tests generally for IsHex.
2018-02-02 23:41:24 -07:00
ff230682d1 Fix logical time (#122)
Should fix a nondeterministic bug so...
2018-02-02 12:51:30 +04:00