From db2a8280567866815bdc216eab82dadafe42033c Mon Sep 17 00:00:00 2001 From: Marko Date: Thu, 18 Jul 2019 11:14:40 +0200 Subject: [PATCH] Remove all cmn from tendermint in IavlStore (#157) * Remove all cmn fromtendermint in IavlStore - Remove all instances of cmn in iavl store Signed-off-by: Marko Baricevic * lint error * change log pending * change to Errorf * use tm-cmn * change db to tm-cmn db * gofmt * changelog change * pr comment changes --- .golangci.yml | 1 - CHANGELOG_PENDING.md | 2 + basic_test.go | 2 +- benchmarks/bench_test.go | 2 +- cmd/iaviewer/main.go | 2 +- doc.go | 2 +- go.mod | 24 ++------ go.sum | 126 ++++++++++++++++++++++++++++++++------- immutable_tree.go | 2 +- mutable_tree.go | 17 +++--- node.go | 53 ++++++++-------- nodedb.go | 2 +- proof.go | 6 +- proof_iavl_absence.go | 13 ++-- proof_iavl_value.go | 13 ++-- proof_path.go | 8 +-- proof_range.go | 47 ++++++++------- proof_test.go | 7 ++- testutils_test.go | 8 +-- tree_dotgraph_test.go | 2 +- tree_fuzz_test.go | 9 +-- tree_test.go | 37 ++++++------ version.go | 2 +- with_gcc_test.go | 2 +- 24 files changed, 234 insertions(+), 155 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 17ac61a88..dfe27dcd3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -29,7 +29,6 @@ linters: - gochecknoinits - scopelint - stylecheck - # linters-settings: # govet: # check-shadowing: true diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 3dea092ac..24d60b415 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -7,3 +7,5 @@ Special thanks to external contributors on this release: ### BREAKING CHANGES ### IMPROVEMENTS + +- [/#46](https://github.com/tendermint/iavl/issues/46) Removal of all instances of cmn from tendermint in Ival repo diff --git a/basic_test.go b/basic_test.go index 263a04a7a..fc1792af8 100644 --- a/basic_test.go +++ b/basic_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/libs/db" + "github.com/tendermint/tm-cmn/db" ) func TestBasic(t *testing.T) { diff --git a/benchmarks/bench_test.go b/benchmarks/bench_test.go index 5a43a5dd5..fa8fadcd5 100644 --- a/benchmarks/bench_test.go +++ b/benchmarks/bench_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/tendermint/iavl" - db "github.com/tendermint/tendermint/libs/db" + db "github.com/tendermint/tm-cmn/db" ) const historySize = 20 diff --git a/cmd/iaviewer/main.go b/cmd/iaviewer/main.go index a7a021a8b..afce5d00b 100644 --- a/cmd/iaviewer/main.go +++ b/cmd/iaviewer/main.go @@ -10,7 +10,7 @@ import ( "strings" "github.com/tendermint/iavl" - dbm "github.com/tendermint/tendermint/libs/db" + dbm "github.com/tendermint/tm-cmn/db" ) // TODO: make this configurable? diff --git a/doc.go b/doc.go index 7751bccad..caa4f33a5 100644 --- a/doc.go +++ b/doc.go @@ -5,7 +5,7 @@ // Basic usage of MutableTree. // // import "github.com/tendermint/iavl" -// import "github.com/tendermint/tendermint/libs/db" +// import "github.com/tendermint/tm-cmn/db" // ... // // tree := iavl.NewMutableTree(db.NewMemDB(), 128) diff --git a/go.mod b/go.mod index bfb6b5e8b..c7d712fcf 100644 --- a/go.mod +++ b/go.mod @@ -3,24 +3,10 @@ module github.com/tendermint/iavl go 1.12 require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/etcd-io/bbolt v1.3.3 // indirect - github.com/go-kit/kit v0.6.0 // indirect - github.com/go-logfmt/logfmt v0.4.0 // indirect - github.com/go-stack/stack v1.8.0 // indirect - github.com/gogo/protobuf v1.1.1 // indirect - github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect - github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect - github.com/jmhodges/levigo v0.0.0-20161115193449-c42d9e0ca023 // indirect - github.com/onsi/ginkgo v1.7.0 // indirect - github.com/onsi/gomega v1.4.3 // indirect - github.com/pkg/errors v0.8.0 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v1.2.2 - github.com/syndtr/goleveldb v0.0.0-20181105012736-f9080354173f // indirect + github.com/pkg/errors v0.8.1 + github.com/stretchr/testify v1.3.0 github.com/tendermint/go-amino v0.14.1 - github.com/tendermint/tendermint v0.31.7 - go.etcd.io/bbolt v1.3.3 // indirect - golang.org/x/crypto v0.0.0-20181126093934-9eb0be3963ea - golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 // indirect + github.com/tendermint/tendermint v0.32.1 + github.com/tendermint/tm-cmn v0.0.0-20190716080004-dfcde30d5acb + golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a ) diff --git a/go.sum b/go.sum index 7402f326f..5f682020a 100644 --- a/go.sum +++ b/go.sum @@ -1,59 +1,144 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= +github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/btcsuite/btcd v0.0.0-20190115013929-ed77733ec07d/go.mod h1:d3C0AkH6BRcvO8T0UEPu53cnw4IbV63x1bEjildYhO0= +github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= +github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= +github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= +github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= +github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/etcd-io/bbolt v1.3.2/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= +github.com/fortytw2/leaktest v1.2.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-kit/kit v0.6.0 h1:wTifptAGIyIuir4bRyN4h7+kAa2a4eepLYVmRe5qqQ8= github.com/go-kit/kit v0.6.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA= -github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-logfmt/logfmt v0.3.0 h1:8HUsc87TaSWLKwrnumgC8/YconD2fJQsRJAsWaPg2ic= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1 h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= -github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck= -github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= +github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk= +github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/jmhodges/levigo v0.0.0-20161115193449-c42d9e0ca023 h1:y5P5G9cANJZt3MXlMrgELo5mNLZPXH8aGFFFG7IzPU0= -github.com/jmhodges/levigo v0.0.0-20161115193449-c42d9e0ca023/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U= +github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ= +github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/common v0.0.0-20181020173914-7e9e6cabbd39/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/rcrowley/go-metrics v0.0.0-20180503174638-e2704e165165/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.1/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/viper v1.0.0/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/syndtr/goleveldb v0.0.0-20181105012736-f9080354173f h1:EEVjSRihF8NIbfyCcErpSpNHEKrY3s8EAwqiPENZZn8= -github.com/syndtr/goleveldb v0.0.0-20181105012736-f9080354173f/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965 h1:1oFLiOyVl+W7bnBzGhf7BbIv9loSFQcieWWYIjLqcAw= +github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= github.com/tendermint/go-amino v0.14.1 h1:o2WudxNfdLNBwMyl2dqOJxiro5rfrEaU0Ugs6offJMk= github.com/tendermint/go-amino v0.14.1/go.mod h1:i/UKE5Uocn+argJJBb12qTZsCDBcAYMbR92AaJVmKso= -github.com/tendermint/tendermint v0.31.7 h1:2xhlEqmrvm+wJxgPTFpUHb0wgT9KFyi3n3FVG+dOlKU= -github.com/tendermint/tendermint v0.31.7/go.mod h1:ymcPyWblXCplCPQjbOYbrF1fWnpslATMVqiGgWbZrlc= +github.com/tendermint/tendermint v0.32.1 h1:J8ddXMbCmG6GZjdCl/N1wgdXDU9uO91J2Y5CA9xYfGo= +github.com/tendermint/tendermint v0.32.1/go.mod h1:jmPDAKuNkev9793/ivn/fTBnfpA9mGBww8MPRNPNxnU= +github.com/tendermint/tm-cmn v0.0.0-20190716080004-dfcde30d5acb h1:t/HdvqJc9e1iJDl+hf8wQKfOo40aen+Rkqh4AwEaNsI= +github.com/tendermint/tm-cmn v0.0.0-20190716080004-dfcde30d5acb/go.mod h1:SLI3Mc+gRrorRsAXJArnHz4xmAdJT8O7Ns0NL4HslXE= go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -golang.org/x/crypto v0.0.0-20181126093934-9eb0be3963ea h1:9OCwXt/HPCOVFs9n4ESYfUd7csy/84vHIldk1riwNtQ= -golang.org/x/crypto v0.0.0-20181126093934-9eb0be3963ea/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a h1:YX8ljsm6wXlHZO+aRz9Exqr0evNhKRNe5K/gi+zKh4U= +golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20181029155118-b69ba1387ce2/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/grpc v1.13.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= +google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= @@ -62,3 +147,4 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/immutable_tree.go b/immutable_tree.go index 57573ea8a..a3bf08da0 100644 --- a/immutable_tree.go +++ b/immutable_tree.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - dbm "github.com/tendermint/tendermint/libs/db" + dbm "github.com/tendermint/tm-cmn/db" ) // ImmutableTree is a container for an immutable AVL+ ImmutableTree. Changes are performed by diff --git a/mutable_tree.go b/mutable_tree.go index 04b3d4dbb..fa055b39f 100644 --- a/mutable_tree.go +++ b/mutable_tree.go @@ -5,8 +5,9 @@ import ( "fmt" "sort" - cmn "github.com/tendermint/tendermint/libs/common" - dbm "github.com/tendermint/tendermint/libs/db" + "github.com/pkg/errors" + + dbm "github.com/tendermint/tm-cmn/db" ) // ErrVersionDoesNotExist is returned if a requested version does not exist. @@ -427,13 +428,13 @@ func (tree *MutableTree) SaveVersion() ([]byte, int64, error) { // longer be accessed. func (tree *MutableTree) DeleteVersion(version int64) error { if version == 0 { - return cmn.NewError("version must be greater than 0") + return errors.New("version must be greater than 0") } if version == tree.version { - return cmn.NewError("cannot delete latest saved version (%d)", version) + return errors.Errorf("cannot delete latest saved version (%d)", version) } if _, ok := tree.versions[version]; !ok { - return cmn.ErrorWrap(ErrVersionDoesNotExist, "") + return errors.Wrap(ErrVersionDoesNotExist, "") } tree.ndb.DeleteVersion(version, true) @@ -448,16 +449,16 @@ func (tree *MutableTree) DeleteVersion(version int64) error { // longer be accessed. func (tree *MutableTree) deleteVersionsFrom(version int64) error { if version <= 0 { - return cmn.NewError("version must be greater than 0") + return errors.New("version must be greater than 0") } newLatestVersion := version - 1 lastestVersion := tree.ndb.getLatestVersion() for ; version <= lastestVersion; version++ { if version == tree.version { - return cmn.NewError("cannot delete latest saved version (%d)", version) + return errors.Errorf("cannot delete latest saved version (%d)", version) } if _, ok := tree.versions[version]; !ok { - return cmn.ErrorWrap(ErrVersionDoesNotExist, "") + return errors.Wrap(ErrVersionDoesNotExist, "") } tree.ndb.DeleteVersion(version, false) delete(tree.versions, version) diff --git a/node.go b/node.go index 904656ae9..d684f35f2 100644 --- a/node.go +++ b/node.go @@ -8,9 +8,10 @@ import ( "fmt" "io" + "github.com/pkg/errors" + amino "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/crypto/tmhash" - cmn "github.com/tendermint/tendermint/libs/common" ) // Node represents a node in a Tree. @@ -43,30 +44,30 @@ func NewNode(key []byte, value []byte, version int64) *Node { // // The new node doesn't have its hash saved or set. The caller must set it // afterwards. -func MakeNode(buf []byte) (*Node, cmn.Error) { +func MakeNode(buf []byte) (*Node, error) { // Read node header (height, size, version, key). height, n, cause := amino.DecodeInt8(buf) if cause != nil { - return nil, cmn.ErrorWrap(cause, "decoding node.height") + return nil, errors.Wrap(cause, "decoding node.height") } buf = buf[n:] size, n, cause := amino.DecodeVarint(buf) if cause != nil { - return nil, cmn.ErrorWrap(cause, "decoding node.size") + return nil, errors.Wrap(cause, "decoding node.size") } buf = buf[n:] ver, n, cause := amino.DecodeVarint(buf) if cause != nil { - return nil, cmn.ErrorWrap(cause, "decoding node.version") + return nil, errors.Wrap(cause, "decoding node.version") } buf = buf[n:] key, n, cause := amino.DecodeByteSlice(buf) if cause != nil { - return nil, cmn.ErrorWrap(cause, "decoding node.key") + return nil, errors.Wrap(cause, "decoding node.key") } buf = buf[n:] @@ -82,19 +83,19 @@ func MakeNode(buf []byte) (*Node, cmn.Error) { if node.isLeaf() { val, _, cause := amino.DecodeByteSlice(buf) if cause != nil { - return nil, cmn.ErrorWrap(cause, "decoding node.value") + return nil, errors.Wrap(cause, "decoding node.value") } node.value = val } else { // Read children. leftHash, n, cause := amino.DecodeByteSlice(buf) if cause != nil { - return nil, cmn.ErrorWrap(cause, "deocding node.leftHash") + return nil, errors.Wrap(cause, "deocding node.leftHash") } buf = buf[n:] rightHash, _, cause := amino.DecodeByteSlice(buf) if cause != nil { - return nil, cmn.ErrorWrap(cause, "decoding node.rightHash") + return nil, errors.Wrap(cause, "decoding node.rightHash") } node.leftHash = leftHash node.rightHash = rightHash @@ -231,18 +232,18 @@ func (node *Node) hashWithCount() ([]byte, int64) { // Writes the node's hash to the given io.Writer. This function expects // child hashes to be already set. -func (node *Node) writeHashBytes(w io.Writer) cmn.Error { +func (node *Node) writeHashBytes(w io.Writer) error { err := amino.EncodeInt8(w, node.height) if err != nil { - return cmn.ErrorWrap(err, "writing height") + return errors.Wrap(err, "writing height") } err = amino.EncodeVarint(w, node.size) if err != nil { - return cmn.ErrorWrap(err, "writing size") + return errors.Wrap(err, "writing size") } err = amino.EncodeVarint(w, node.version) if err != nil { - return cmn.ErrorWrap(err, "writing version") + return errors.Wrap(err, "writing version") } // Key is not written for inner nodes, unlike writeBytes. @@ -250,14 +251,14 @@ func (node *Node) writeHashBytes(w io.Writer) cmn.Error { if node.isLeaf() { err = amino.EncodeByteSlice(w, node.key) if err != nil { - return cmn.ErrorWrap(err, "writing key") + return errors.Wrap(err, "writing key") } // Indirection needed to provide proofs without values. // (e.g. proofLeafNode.ValueHash) valueHash := tmhash.Sum(node.value) err = amino.EncodeByteSlice(w, valueHash) if err != nil { - return cmn.ErrorWrap(err, "writing value") + return errors.Wrap(err, "writing value") } } else { if node.leftHash == nil || node.rightHash == nil { @@ -265,11 +266,11 @@ func (node *Node) writeHashBytes(w io.Writer) cmn.Error { } err = amino.EncodeByteSlice(w, node.leftHash) if err != nil { - return cmn.ErrorWrap(err, "writing left hash") + return errors.Wrap(err, "writing left hash") } err = amino.EncodeByteSlice(w, node.rightHash) if err != nil { - return cmn.ErrorWrap(err, "writing right hash") + return errors.Wrap(err, "writing right hash") } } @@ -278,7 +279,7 @@ func (node *Node) writeHashBytes(w io.Writer) cmn.Error { // Writes the node's hash to the given io.Writer. // This function has the side-effect of calling hashWithCount. -func (node *Node) writeHashBytesRecursively(w io.Writer) (hashCount int64, err cmn.Error) { +func (node *Node) writeHashBytesRecursively(w io.Writer) (hashCount int64, err error) { if node.leftNode != nil { leftHash, leftCount := node.leftNode.hashWithCount() node.leftHash = leftHash @@ -295,31 +296,31 @@ func (node *Node) writeHashBytesRecursively(w io.Writer) (hashCount int64, err c } // Writes the node as a serialized byte slice to the supplied io.Writer. -func (node *Node) writeBytes(w io.Writer) cmn.Error { +func (node *Node) writeBytes(w io.Writer) error { var cause error cause = amino.EncodeInt8(w, node.height) if cause != nil { - return cmn.ErrorWrap(cause, "writing height") + return errors.Wrap(cause, "writing height") } cause = amino.EncodeVarint(w, node.size) if cause != nil { - return cmn.ErrorWrap(cause, "writing size") + return errors.Wrap(cause, "writing size") } cause = amino.EncodeVarint(w, node.version) if cause != nil { - return cmn.ErrorWrap(cause, "writing version") + return errors.Wrap(cause, "writing version") } // Unlike writeHashBytes, key is written for inner nodes. cause = amino.EncodeByteSlice(w, node.key) if cause != nil { - return cmn.ErrorWrap(cause, "writing key") + return errors.Wrap(cause, "writing key") } if node.isLeaf() { cause = amino.EncodeByteSlice(w, node.value) if cause != nil { - return cmn.ErrorWrap(cause, "writing value") + return errors.Wrap(cause, "writing value") } } else { if node.leftHash == nil { @@ -327,7 +328,7 @@ func (node *Node) writeBytes(w io.Writer) cmn.Error { } cause = amino.EncodeByteSlice(w, node.leftHash) if cause != nil { - return cmn.ErrorWrap(cause, "writing left hash") + return errors.Wrap(cause, "writing left hash") } if node.rightHash == nil { @@ -335,7 +336,7 @@ func (node *Node) writeBytes(w io.Writer) cmn.Error { } cause = amino.EncodeByteSlice(w, node.rightHash) if cause != nil { - return cmn.ErrorWrap(cause, "writing right hash") + return errors.Wrap(cause, "writing right hash") } } return nil diff --git a/nodedb.go b/nodedb.go index 2d97095c2..12625af63 100644 --- a/nodedb.go +++ b/nodedb.go @@ -8,7 +8,7 @@ import ( "sync" "github.com/tendermint/tendermint/crypto/tmhash" - dbm "github.com/tendermint/tendermint/libs/db" + dbm "github.com/tendermint/tm-cmn/db" ) const ( diff --git a/proof.go b/proof.go index e3c0d0c4d..e1fc5fc52 100644 --- a/proof.go +++ b/proof.go @@ -4,9 +4,11 @@ import ( "bytes" "fmt" + "github.com/pkg/errors" + "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/crypto/tmhash" - cmn "github.com/tendermint/tendermint/libs/common" + cmn "github.com/tendermint/tm-cmn/common" ) var ( @@ -153,7 +155,7 @@ func (node *Node) pathToLeaf(t *ImmutableTree, key []byte, path *PathToLeaf) (*N if bytes.Equal(node.key, key) { return node, nil } - return node, cmn.NewError("key does not exist") + return node, errors.New("key does not exist") } if bytes.Compare(key, node.key) < 0 { diff --git a/proof_iavl_absence.go b/proof_iavl_absence.go index 88a6587ae..6bc411a20 100644 --- a/proof_iavl_absence.go +++ b/proof_iavl_absence.go @@ -3,8 +3,9 @@ package iavl import ( "fmt" + "github.com/pkg/errors" + "github.com/tendermint/tendermint/crypto/merkle" - cmn "github.com/tendermint/tendermint/libs/common" ) const ProofOpIAVLAbsence = "iavl:a" @@ -34,12 +35,12 @@ func NewIAVLAbsenceOp(key []byte, proof *RangeProof) IAVLAbsenceOp { func IAVLAbsenceOpDecoder(pop merkle.ProofOp) (merkle.ProofOperator, error) { if pop.Type != ProofOpIAVLAbsence { - return nil, cmn.NewError("unexpected ProofOp.Type; got %v, want %v", pop.Type, ProofOpIAVLAbsence) + return nil, errors.Errorf("unexpected ProofOp.Type; got %v, want %v", pop.Type, ProofOpIAVLAbsence) } var op IAVLAbsenceOp // a bit strange as we'll discard this, but it works. err := cdc.UnmarshalBinaryLengthPrefixed(pop.Data, &op) if err != nil { - return nil, cmn.ErrorWrap(err, "decoding ProofOp.Data into IAVLAbsenceOp") + return nil, errors.Wrap(err, "decoding ProofOp.Data into IAVLAbsenceOp") } return NewIAVLAbsenceOp(pop.Key, op.Proof), nil } @@ -59,7 +60,7 @@ func (op IAVLAbsenceOp) String() string { func (op IAVLAbsenceOp) Run(args [][]byte) ([][]byte, error) { if len(args) != 0 { - return nil, cmn.NewError("expected 0 args, got %v", len(args)) + return nil, errors.Errorf("expected 0 args, got %v", len(args)) } // If the tree is nil, the proof is nil, and all keys are absent. if op.Proof == nil { @@ -70,14 +71,14 @@ func (op IAVLAbsenceOp) Run(args [][]byte) ([][]byte, error) { root := op.Proof.ComputeRootHash() err := op.Proof.Verify(root) if err != nil { - return nil, cmn.ErrorWrap(err, "computing root hash") + return nil, errors.Wrap(err, "computing root hash") } // XXX What is the encoding for keys? // We should decode the key depending on whether it's a string or hex, // maybe based on quotes and 0x prefix? err = op.Proof.VerifyAbsence([]byte(op.key)) if err != nil { - return nil, cmn.ErrorWrap(err, "verifying absence") + return nil, errors.Wrap(err, "verifying absence") } return [][]byte{root}, nil } diff --git a/proof_iavl_value.go b/proof_iavl_value.go index df3c905ef..ddbab992b 100644 --- a/proof_iavl_value.go +++ b/proof_iavl_value.go @@ -3,8 +3,9 @@ package iavl import ( "fmt" + "github.com/pkg/errors" + "github.com/tendermint/tendermint/crypto/merkle" - cmn "github.com/tendermint/tendermint/libs/common" ) const ProofOpIAVLValue = "iavl:v" @@ -35,12 +36,12 @@ func NewIAVLValueOp(key []byte, proof *RangeProof) IAVLValueOp { func IAVLValueOpDecoder(pop merkle.ProofOp) (merkle.ProofOperator, error) { if pop.Type != ProofOpIAVLValue { - return nil, cmn.NewError("unexpected ProofOp.Type; got %v, want %v", pop.Type, ProofOpIAVLValue) + return nil, errors.Errorf("unexpected ProofOp.Type; got %v, want %v", pop.Type, ProofOpIAVLValue) } var op IAVLValueOp // a bit strange as we'll discard this, but it works. err := cdc.UnmarshalBinaryLengthPrefixed(pop.Data, &op) if err != nil { - return nil, cmn.ErrorWrap(err, "decoding ProofOp.Data into IAVLValueOp") + return nil, errors.Wrap(err, "decoding ProofOp.Data into IAVLValueOp") } return NewIAVLValueOp(pop.Key, op.Proof), nil } @@ -60,7 +61,7 @@ func (op IAVLValueOp) String() string { func (op IAVLValueOp) Run(args [][]byte) ([][]byte, error) { if len(args) != 1 { - return nil, cmn.NewError("Value size is not 1") + return nil, errors.New("Value size is not 1") } value := args[0] @@ -69,14 +70,14 @@ func (op IAVLValueOp) Run(args [][]byte) ([][]byte, error) { root := op.Proof.ComputeRootHash() err := op.Proof.Verify(root) if err != nil { - return nil, cmn.ErrorWrap(err, "computing root hash") + return nil, errors.Wrap(err, "computing root hash") } // XXX What is the encoding for keys? // We should decode the key depending on whether it's a string or hex, // maybe based on quotes and 0x prefix? err = op.Proof.VerifyItem([]byte(op.key), value) if err != nil { - return nil, cmn.ErrorWrap(err, "verifying value") + return nil, errors.Wrap(err, "verifying value") } return [][]byte{root}, nil } diff --git a/proof_path.go b/proof_path.go index de366f338..3d78c2cd4 100644 --- a/proof_path.go +++ b/proof_path.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/pkg/errors" ) // pathWithLeaf is a path to a leaf node and the leaf node itself. @@ -31,7 +31,7 @@ func (pwl pathWithLeaf) StringIndented(indent string) string { // `verify` checks that the leaf node's hash + the inner nodes merkle-izes to // the given root. If it returns an error, it means the leafHash or the // PathToLeaf is incorrect. -func (pwl pathWithLeaf) verify(root []byte) cmn.Error { +func (pwl pathWithLeaf) verify(root []byte) error { leafHash := pwl.Leaf.Hash() return pwl.Path.verify(leafHash, root) } @@ -76,14 +76,14 @@ func (pl PathToLeaf) stringIndented(indent string) string { // `verify` checks that the leaf node's hash + the inner nodes merkle-izes to // the given root. If it returns an error, it means the leafHash or the // PathToLeaf is incorrect. -func (pl PathToLeaf) verify(leafHash []byte, root []byte) cmn.Error { +func (pl PathToLeaf) verify(leafHash []byte, root []byte) error { hash := leafHash for i := len(pl) - 1; i >= 0; i-- { pin := pl[i] hash = pin.Hash(hash) } if !bytes.Equal(root, hash) { - return cmn.ErrorWrap(ErrInvalidProof, "") + return errors.Wrap(ErrInvalidProof, "") } return nil } diff --git a/proof_range.go b/proof_range.go index 69a613db4..19c285773 100644 --- a/proof_range.go +++ b/proof_range.go @@ -6,8 +6,9 @@ import ( "sort" "strings" + "github.com/pkg/errors" + "github.com/tendermint/tendermint/crypto/tmhash" - cmn "github.com/tendermint/tendermint/libs/common" ) type RangeProof struct { @@ -94,20 +95,20 @@ func (proof *RangeProof) LeftIndex() int64 { func (proof *RangeProof) VerifyItem(key, value []byte) error { leaves := proof.Leaves if proof == nil { - return cmn.ErrorWrap(ErrInvalidProof, "proof is nil") + return errors.Wrap(ErrInvalidProof, "proof is nil") } if !proof.rootVerified { - return cmn.NewError("must call Verify(root) first.") + return errors.New("must call Verify(root) first.") } i := sort.Search(len(leaves), func(i int) bool { return bytes.Compare(key, leaves[i].Key) <= 0 }) if i >= len(leaves) || !bytes.Equal(leaves[i].Key, key) { - return cmn.ErrorWrap(ErrInvalidProof, "leaf key not found in proof") + return errors.Wrap(ErrInvalidProof, "leaf key not found in proof") } valueHash := tmhash.Sum(value) if !bytes.Equal(leaves[i].ValueHash, valueHash) { - return cmn.ErrorWrap(ErrInvalidProof, "leaf value hash not same") + return errors.Wrap(ErrInvalidProof, "leaf value hash not same") } return nil } @@ -117,20 +118,20 @@ func (proof *RangeProof) VerifyItem(key, value []byte) error { // For that, use Verify(root). func (proof *RangeProof) VerifyAbsence(key []byte) error { if proof == nil { - return cmn.ErrorWrap(ErrInvalidProof, "proof is nil") + return errors.Wrap(ErrInvalidProof, "proof is nil") } if !proof.rootVerified { - return cmn.NewError("must call Verify(root) first.") + return errors.New("must call Verify(root) first.") } cmp := bytes.Compare(key, proof.Leaves[0].Key) if cmp < 0 { if proof.LeftPath.isLeftmost() { return nil } else { - return cmn.NewError("absence not proved by left path") + return errors.New("absence not proved by left path") } } else if cmp == 0 { - return cmn.NewError("absence disproved via first item #0") + return errors.New("absence disproved via first item #0") } if len(proof.LeftPath) == 0 { return nil // proof ok @@ -146,7 +147,7 @@ func (proof *RangeProof) VerifyAbsence(key []byte) error { if cmp < 0 { return nil // proof ok } else if cmp == 0 { - return cmn.NewError("absence disproved via item #%v", i) + return errors.New(fmt.Sprintf("absence disproved via item #%v", i)) } else { if i == len(proof.Leaves)-1 { // If last item, check whether @@ -164,16 +165,16 @@ func (proof *RangeProof) VerifyAbsence(key []byte) error { // It's not a valid absence proof. if len(proof.Leaves) < 2 { - return cmn.NewError("absence not proved by right leaf (need another leaf?)") + return errors.New("absence not proved by right leaf (need another leaf?)") } else { - return cmn.NewError("absence not proved by right leaf") + return errors.New("absence not proved by right leaf") } } // Verify that proof is valid. func (proof *RangeProof) Verify(root []byte) error { if proof == nil { - return cmn.ErrorWrap(ErrInvalidProof, "proof is nil") + return errors.Wrap(ErrInvalidProof, "proof is nil") } err := proof.verify(root) return err @@ -189,7 +190,7 @@ func (proof *RangeProof) verify(root []byte) (err error) { rootHash = derivedHash } if !bytes.Equal(rootHash, root) { - return cmn.ErrorWrap(ErrInvalidRoot, "root hash doesn't match") + return errors.Wrap(ErrInvalidRoot, "root hash doesn't match") } else { proof.rootVerified = true } @@ -218,10 +219,10 @@ func (proof *RangeProof) computeRootHash() (rootHash []byte, err error) { func (proof *RangeProof) _computeRootHash() (rootHash []byte, treeEnd bool, err error) { if len(proof.Leaves) == 0 { - return nil, false, cmn.ErrorWrap(ErrInvalidProof, "no leaves") + return nil, false, errors.Wrap(ErrInvalidProof, "no leaves") } if len(proof.InnerNodes)+1 != len(proof.Leaves) { - return nil, false, cmn.ErrorWrap(ErrInvalidProof, "InnerNodes vs Leaves length mismatch, leaves should be 1 more.") + return nil, false, errors.Wrap(ErrInvalidProof, "InnerNodes vs Leaves length mismatch, leaves should be 1 more.") } // Start from the left path and prove each leaf. @@ -273,10 +274,10 @@ func (proof *RangeProof) _computeRootHash() (rootHash []byte, treeEnd bool, err // Recursively verify inners against remaining leaves. derivedRoot, treeEnd, done, err := COMPUTEHASH(inners, rightmost && rpath.isRightmost()) if err != nil { - return nil, treeEnd, false, cmn.ErrorWrap(err, "recursive COMPUTEHASH call") + return nil, treeEnd, false, errors.Wrap(err, "recursive COMPUTEHASH call") } if !bytes.Equal(derivedRoot, lpath.Right) { - return nil, treeEnd, false, cmn.ErrorWrap(ErrInvalidRoot, "intermediate root hash %X doesn't match, got %X", lpath.Right, derivedRoot) + return nil, treeEnd, false, errors.Wrapf(ErrInvalidRoot, "intermediate root hash %X doesn't match, got %X", lpath.Right, derivedRoot) } if done { return hash, treeEnd, true, nil @@ -293,9 +294,9 @@ func (proof *RangeProof) _computeRootHash() (rootHash []byte, treeEnd bool, err path := proof.LeftPath rootHash, treeEnd, done, err := COMPUTEHASH(path, true) if err != nil { - return nil, treeEnd, cmn.ErrorWrap(err, "root COMPUTEHASH call") + return nil, treeEnd, errors.Wrap(err, "root COMPUTEHASH call") } else if !done { - return nil, treeEnd, cmn.ErrorWrap(ErrInvalidProof, "left over leaves -- malformed proof") + return nil, treeEnd, errors.Wrap(ErrInvalidProof, "left over leaves -- malformed proof") } // Ok! @@ -452,7 +453,7 @@ func (t *ImmutableTree) getRangeProof(keyStart, keyEnd []byte, limit int) (proof func (t *ImmutableTree) GetWithProof(key []byte) (value []byte, proof *RangeProof, err error) { proof, _, values, err := t.getRangeProof(key, cpIncr(key), 2) if err != nil { - return nil, nil, cmn.ErrorWrap(err, "constructing range proof") + return nil, nil, errors.Wrap(err, "constructing range proof") } if len(values) > 0 && bytes.Equal(proof.Leaves[0].Key, key) { return values[0], proof, nil @@ -477,7 +478,7 @@ func (tree *MutableTree) GetVersionedWithProof(key []byte, version int64) ([]byt return t.GetWithProof(key) } - return nil, nil, cmn.ErrorWrap(ErrVersionDoesNotExist, "") + return nil, nil, errors.Wrap(ErrVersionDoesNotExist, "") } // GetVersionedRangeWithProof gets key/value pairs within the specified range @@ -492,5 +493,5 @@ func (tree *MutableTree) GetVersionedRangeWithProof(startKey, endKey []byte, lim } return t.GetRangeWithProof(startKey, endKey, limit) } - return nil, nil, nil, cmn.ErrorWrap(ErrVersionDoesNotExist, "") + return nil, nil, nil, errors.Wrap(ErrVersionDoesNotExist, "") } diff --git a/proof_test.go b/proof_test.go index 185b8ea76..1c84b703e 100644 --- a/proof_test.go +++ b/proof_test.go @@ -8,8 +8,9 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/go-amino" - "github.com/tendermint/tendermint/libs/db" + "github.com/tendermint/tm-cmn/db" "github.com/tendermint/tendermint/libs/test" + cmn "github.com/tendermint/tm-cmn/common" ) func TestTreeGetWithProof(t *testing.T) { @@ -17,7 +18,7 @@ func TestTreeGetWithProof(t *testing.T) { require := require.New(t) for _, ikey := range []byte{0x11, 0x32, 0x50, 0x72, 0x99} { key := []byte{ikey} - tree.Set(key, []byte(random.Str(8))) + tree.Set(key, []byte(cmn.RandStr(8))) } root := tree.WorkingHash() @@ -61,7 +62,7 @@ func TestTreeKeyExistsProof(t *testing.T) { // insert lots of info and store the bytes allkeys := make([][]byte, 200) for i := 0; i < 200; i++ { - key := randstr(20) + key := cmn.RandStr(20) value := "value_for_" + key tree.Set([]byte(key), []byte(value)) allkeys[i] = []byte(key) diff --git a/testutils_test.go b/testutils_test.go index f802148a4..7fc09b093 100644 --- a/testutils_test.go +++ b/testutils_test.go @@ -9,8 +9,8 @@ import ( mrand "math/rand" "github.com/tendermint/go-amino" - cmn "github.com/tendermint/tendermint/libs/common" - "github.com/tendermint/tendermint/libs/db" + cmn "github.com/tendermint/tm-cmn/common" + "github.com/tendermint/tm-cmn/db" ) func randstr(length int) string { @@ -119,7 +119,7 @@ func benchmarkImmutableAvlTreeWithDB(b *testing.B, db db.DB) { t := NewMutableTree(db, 100000) value := []byte{} for i := 0; i < 1000000; i++ { - t.Set(i2b(int(cmn.RandInt32())), value) + t.Set(i2b(int(cmn.RandInt31())), value) if i > 990000 && i%1000 == 999 { t.SaveVersion() } @@ -131,7 +131,7 @@ func benchmarkImmutableAvlTreeWithDB(b *testing.B, db db.DB) { b.StartTimer() for i := 0; i < b.N; i++ { - ri := i2b(int(cmn.RandInt32())) + ri := i2b(int(cmn.RandInt31())) t.Set(ri, value) t.Remove(ri) if i%100 == 99 { diff --git a/tree_dotgraph_test.go b/tree_dotgraph_test.go index cec1475bd..012498430 100644 --- a/tree_dotgraph_test.go +++ b/tree_dotgraph_test.go @@ -4,7 +4,7 @@ import ( "io/ioutil" "testing" - "github.com/tendermint/tendermint/libs/db" + "github.com/tendermint/tm-cmn/db" ) func TestWriteDOTGraph(t *testing.T) { diff --git a/tree_fuzz_test.go b/tree_fuzz_test.go index d5e0bcaf9..a44b0df23 100644 --- a/tree_fuzz_test.go +++ b/tree_fuzz_test.go @@ -2,10 +2,11 @@ package iavl import ( "fmt" + "math/rand" "testing" - cmn "github.com/tendermint/tendermint/libs/common" - "github.com/tendermint/tendermint/libs/db" + "github.com/tendermint/tm-cmn/db" + cmn "github.com/tendermint/tm-cmn/common" ) // This file implement fuzz testing by generating programs and then running @@ -85,7 +86,7 @@ func genRandomProgram(size int) *program { for p.size() < size { k, v := []byte(cmn.RandStr(1)), []byte(cmn.RandStr(1)) - switch cmn.RandInt() % 7 { + switch rand.Int() % 7 { //nolint: gosec Turn off gosec here because this is for testing case 0, 1, 2: p.addInstruction(instruction{op: "SET", k: k, v: v}) case 3, 4: @@ -94,7 +95,7 @@ func genRandomProgram(size int) *program { p.addInstruction(instruction{op: "SAVE", version: int64(nextVersion)}) nextVersion++ case 6: - if rv := cmn.RandInt() % nextVersion; rv < nextVersion && rv > 0 { + if rv := rand.Int() % nextVersion; rv < nextVersion && rv > 0 { //nolint: gosec Turn off gosec here because this is for testing p.addInstruction(instruction{op: "DELETE", version: int64(rv)}) } } diff --git a/tree_test.go b/tree_test.go index 32826a25e..cd5885bd4 100644 --- a/tree_test.go +++ b/tree_test.go @@ -11,11 +11,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/libs/db" - - mathrand "math/rand" - - cmn "github.com/tendermint/tendermint/libs/common" + cmn "github.com/tendermint/tm-cmn/common" + "github.com/tendermint/tm-cmn/db" ) var testLevelDB bool @@ -57,8 +54,8 @@ func TestVersionedRandomTree(t *testing.T) { // Create a tree of size 1000 with 100 versions. for i := 1; i <= versions; i++ { for j := 0; j < keysPerVersion; j++ { - k := []byte(random.Str(8)) - v := []byte(random.Str(8)) + k := []byte(cmn.RandStr(8)) + v := []byte(cmn.RandStr(8)) tree.Set(k, v) } tree.SaveVersion() @@ -110,8 +107,8 @@ func TestVersionedRandomTreeSmallKeys(t *testing.T) { for i := 1; i <= versions; i++ { for j := 0; j < keysPerVersion; j++ { // Keys of size one are likely to be overwritten. - k := []byte(random.Str(1)) - v := []byte(random.Str(8)) + k := []byte(cmn.RandStr(1)) + v := []byte(cmn.RandStr(8)) tree.Set(k, v) singleVersionTree.Set(k, v) } @@ -132,7 +129,7 @@ func TestVersionedRandomTreeSmallKeys(t *testing.T) { // Try getting random keys. for i := 0; i < keysPerVersion; i++ { - _, val := tree.Get([]byte(random.Str(1))) + _, val := tree.Get([]byte(cmn.RandStr(1))) require.NotNil(val) require.NotEmpty(val) } @@ -151,8 +148,8 @@ func TestVersionedRandomTreeSmallKeysRandomDeletes(t *testing.T) { for i := 1; i <= versions; i++ { for j := 0; j < keysPerVersion; j++ { // Keys of size one are likely to be overwritten. - k := []byte(random.Str(1)) - v := []byte(random.Str(8)) + k := []byte(cmn.RandStr(1)) + v := []byte(cmn.RandStr(8)) tree.Set(k, v) singleVersionTree.Set(k, v) } @@ -160,7 +157,7 @@ func TestVersionedRandomTreeSmallKeysRandomDeletes(t *testing.T) { } singleVersionTree.SaveVersion() - for _, i := range random.Perm(versions - 1) { + for _, i := range cmn.RandPerm(versions - 1) { tree.DeleteVersion(int64(i + 1)) } @@ -173,7 +170,7 @@ func TestVersionedRandomTreeSmallKeysRandomDeletes(t *testing.T) { // Try getting random keys. for i := 0; i < keysPerVersion; i++ { - _, val := tree.Get([]byte(random.Str(1))) + _, val := tree.Get([]byte(cmn.RandStr(1))) require.NotNil(val) require.NotEmpty(val) } @@ -710,8 +707,8 @@ func TestVersionedCheckpoints(t *testing.T) { for i := 1; i <= versions; i++ { for j := 0; j < keysPerVersion; j++ { - k := []byte(random.Str(1)) - v := []byte(random.Str(8)) + k := []byte(cmn.RandStr(1)) + v := []byte(cmn.RandStr(8)) keys[int64(i)] = append(keys[int64(i)], k) tree.Set(k, v) } @@ -944,7 +941,7 @@ func TestVersionedTreeEfficiency(t *testing.T) { for i := 1; i <= versions; i++ { for j := 0; j < keysPerVersion; j++ { // Keys of size one are likely to be overwritten. - tree.Set([]byte(random.Str(1)), []byte(random.Str(8))) + tree.Set([]byte(cmn.RandStr(1)), []byte(cmn.RandStr(8))) } sizeBefore := len(tree.ndb.nodes()) tree.SaveVersion() @@ -1056,7 +1053,7 @@ func TestOrphans(t *testing.T) { require.NoError(err, "SaveVersion should not error") } - idx := mathrand.Perm(NUMVERSIONS - 2) + idx := cmn.RandPerm(NUMVERSIONS - 2) for i := range idx { err := tree.DeleteVersion(int64(i + 2)) require.NoError(err, "DeleteVersion should not error") @@ -1298,7 +1295,7 @@ func BenchmarkTreeLoadAndDelete(b *testing.B) { tree := NewMutableTree(d, 0) for v := 1; v < numVersions; v++ { for i := 0; i < numKeysPerVersion; i++ { - tree.Set([]byte(random.Str(16)), random.Bytes(32)) + tree.Set([]byte(cmn.RandStr(16)), cmn.RandBytes(32)) } tree.SaveVersion() } @@ -1319,7 +1316,7 @@ func BenchmarkTreeLoadAndDelete(b *testing.B) { // If we can load quickly into a data-structure that allows for // efficient deletes, we are golden. for v := 0; v < numVersions/10; v++ { - version := (random.Int() % numVersions) + 1 + version := (cmn.RandInt() % numVersions) + 1 tree.DeleteVersion(int64(version)) } } diff --git a/version.go b/version.go index 98d8d8091..43e5a015b 100644 --- a/version.go +++ b/version.go @@ -1,4 +1,4 @@ package iavl // Version of iavl. -const Version = "0.12.2" +const Version = "0.12.3" diff --git a/with_gcc_test.go b/with_gcc_test.go index b3d590d71..7b0428d0b 100644 --- a/with_gcc_test.go +++ b/with_gcc_test.go @@ -9,7 +9,7 @@ package iavl import ( "testing" - "github.com/tendermint/tendermint/libs/db" + "github.com/tendermint/tm-cmn/db" ) func BenchmarkImmutableAvlTreeCLevelDB(b *testing.B) {