From 5bfb9001eb1edfdeabff61a53c5031271066bef5 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Wed, 5 Sep 2018 16:49:34 +0400 Subject: [PATCH 1/7] switch from jmhodges/levigo to DataDog/leveldb Why: original fork is abandoned and not supported anymore. Changes: - LevelDB 1.19 (LevelDB and Snappy are both compiled and linked statically, so while you will not need them installed on your target machine, you should have a roughly compatible version of libstdc++.) - snappy and lz4 libs included by default --- Gopkg.lock | 16 +++++------ Gopkg.toml | 4 +-- config/config.go | 8 +++--- config/toml.go | 2 +- docs/introduction/install.md | 41 ++++++++++++++++++++++++--- docs/tendermint-core/configuration.md | 2 +- libs/db/Makefile | 4 +++ libs/db/backend_test.go | 12 ++++---- libs/db/c_level_db.go | 2 +- libs/db/c_level_db_test.go | 7 +++-- 10 files changed, 70 insertions(+), 28 deletions(-) create mode 100644 libs/db/Makefile diff --git a/Gopkg.lock b/Gopkg.lock index 8deb06378..9a27f344a 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1,6 +1,13 @@ # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. +[[projects]] + digest = "1:5da259989116f6ab5e05a80086c639c82efdbdb799ca07183eb0b660edfd91fe" + name = "github.com/DataDog/leveldb" + packages = ["."] + pruneopts = "UT" + revision = "12a0b6e10a5bf779330ed8b7c0f1f39f212d34e2" + [[projects]] branch = "master" digest = "1:d6afaeed1502aa28e80a4ed0981d570ad91b2579193404256ce672ed0a609e0d" @@ -161,13 +168,6 @@ revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" version = "v1.0" -[[projects]] - digest = "1:39b27d1381a30421f9813967a5866fba35dc1d4df43a6eefe3b7a5444cb07214" - name = "github.com/jmhodges/levigo" - packages = ["."] - pruneopts = "UT" - revision = "c42d9e0ca023e2198120196f842701bb4c55d7b9" - [[projects]] branch = "master" digest = "1:a64e323dc06b73892e5bb5d040ced475c4645d456038333883f58934abbf6f72" @@ -511,6 +511,7 @@ analyzer-name = "dep" analyzer-version = 1 input-imports = [ + "github.com/DataDog/leveldb", "github.com/btcsuite/btcutil/base58", "github.com/btcsuite/btcutil/bech32", "github.com/ebuchman/fail-test", @@ -529,7 +530,6 @@ "github.com/golang/protobuf/proto", "github.com/golang/protobuf/ptypes/timestamp", "github.com/gorilla/websocket", - "github.com/jmhodges/levigo", "github.com/pkg/errors", "github.com/prometheus/client_golang/prometheus", "github.com/prometheus/client_golang/prometheus/promhttp", diff --git a/Gopkg.toml b/Gopkg.toml index d3bca19e8..cda7988c5 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -73,8 +73,8 @@ ## Pin to revision [[override]] - name = "github.com/jmhodges/levigo" - revision = "c42d9e0ca023e2198120196f842701bb4c55d7b9" + name = "github.com/DataDog/leveldb" + revision = "12a0b6e10a5bf779330ed8b7c0f1f39f212d34e2" [[constraint]] name = "github.com/ebuchman/fail-test" diff --git a/config/config.go b/config/config.go index c0882546f..d0e075477 100644 --- a/config/config.go +++ b/config/config.go @@ -113,7 +113,7 @@ type BaseConfig struct { // and verifying their commits FastSync bool `mapstructure:"fast_sync"` - // Database backend: leveldb | memdb + // Database backend: leveldb | memdb | cleveldb DBBackend string `mapstructure:"db_backend"` // Database directory @@ -587,15 +587,15 @@ type TxIndexConfig struct { // Comma-separated list of tags to index (by default the only tag is "tx.hash") // // You can also index transactions by height by adding "tx.height" tag here. - // + // // It's recommended to index only a subset of tags due to possible memory // bloat. This is, of course, depends on the indexer's DB and the volume of // transactions. IndexTags string `mapstructure:"index_tags"` // When set to true, tells indexer to index all tags (predefined tags: - // "tx.hash", "tx.height" and all tags from DeliverTx responses). - // + // "tx.hash", "tx.height" and all tags from DeliverTx responses). + // // Note this may be not desirable (see the comment above). IndexTags has a // precedence over IndexAllTags (i.e. when given both, IndexTags will be // indexed). diff --git a/config/toml.go b/config/toml.go index 2a35d7c36..9beb9d799 100644 --- a/config/toml.go +++ b/config/toml.go @@ -77,7 +77,7 @@ moniker = "{{ .BaseConfig.Moniker }}" # and verifying their commits fast_sync = {{ .BaseConfig.FastSync }} -# Database backend: leveldb | memdb +# Database backend: leveldb | memdb | cleveldb db_backend = "{{ .BaseConfig.DBBackend }}" # Database directory diff --git a/docs/introduction/install.md b/docs/introduction/install.md index 10b66dad0..925ed2a80 100644 --- a/docs/introduction/install.md +++ b/docs/introduction/install.md @@ -48,6 +48,15 @@ to put the binary in `./build`. The latest `tendermint version` is now installed. +## Run + +To start a one-node blockchain with a simple in-process application: + +``` +tendermint init +tendermint node --proxy_app=kvstore +``` + ## Reinstall If you already have Tendermint installed, and you make updates, simply @@ -66,11 +75,35 @@ make get_vendor_deps make install ``` -## Run +## Compile with CLevelDB support -To start a one-node blockchain with a simple in-process application: +Make sure you have a roughly compatible version of libstdc++ (tested with +5.3.1). For example, on Ubuntu: ``` -tendermint init -tendermint node --proxy_app=kvstore +sudo apt-get update +sudo apt-get install gcc +sudo apt-cache show libstdc++6 +Version: 5.3.1-14ubuntu2 +``` + +Check out leveldb dependency using git (for some reason dep does not check out +submodules): + +``` +cd vendor/github.com/DataDog && rm -rf leveldb +git clone https://github.com/DataDog/leveldb.git +``` + +Set database backend to cleveldb: + +``` +# config/config.toml +db_backend = "cleveldb" +``` + +To build Tendermint, run + +``` +CGO_ENABLED=1 CGO_CXXFLAGS_ALLOW="(-fno-builtin-memcmp|-lpthread)" CGO_CFLAGS_ALLOW="-fno-builtin-memcmp" go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags "tendermint gcc" -o build/tendermint ./cmd/tendermint/ ``` diff --git a/docs/tendermint-core/configuration.md b/docs/tendermint-core/configuration.md index 7e20277f4..29db12125 100644 --- a/docs/tendermint-core/configuration.md +++ b/docs/tendermint-core/configuration.md @@ -30,7 +30,7 @@ moniker = "anonymous" # and verifying their commits fast_sync = true -# Database backend: leveldb | memdb +# Database backend: leveldb | memdb | cleveldb db_backend = "leveldb" # Database directory diff --git a/libs/db/Makefile b/libs/db/Makefile new file mode 100644 index 000000000..e0cd45b0a --- /dev/null +++ b/libs/db/Makefile @@ -0,0 +1,4 @@ +test_gcc: + CGO_CXXFLAGS_ALLOW="(-fno-builtin-memcmp|-lpthread)" CGO_CFLAGS_ALLOW="-fno-builtin-memcmp" go test -tags gcc + +.PHONY: test_gcc diff --git a/libs/db/backend_test.go b/libs/db/backend_test.go index 496f4c410..a93698226 100644 --- a/libs/db/backend_test.go +++ b/libs/db/backend_test.go @@ -55,9 +55,10 @@ func TestBackendsGetSetDelete(t *testing.T) { func withDB(t *testing.T, creator dbCreator, fn func(DB)) { name := fmt.Sprintf("test_%x", cmn.RandStr(12)) - db, err := creator(name, "") - defer cleanupDBDir("", name) - assert.Nil(t, err) + dir := os.TempDir() + db, err := creator(name, dir) + require.Nil(t, err) + defer cleanupDBDir(dir, name) fn(db) db.Close() } @@ -161,8 +162,9 @@ func TestDBIterator(t *testing.T) { func testDBIterator(t *testing.T, backend DBBackendType) { name := fmt.Sprintf("test_%x", cmn.RandStr(12)) - db := NewDB(name, backend, "") - defer cleanupDBDir("", name) + dir := os.TempDir() + db := NewDB(name, backend, dir) + defer cleanupDBDir(dir, name) for i := 0; i < 10; i++ { if i != 6 { // but skip 6. diff --git a/libs/db/c_level_db.go b/libs/db/c_level_db.go index 307461261..10f03aa0c 100644 --- a/libs/db/c_level_db.go +++ b/libs/db/c_level_db.go @@ -7,7 +7,7 @@ import ( "fmt" "path/filepath" - "github.com/jmhodges/levigo" + levigo "github.com/DataDog/leveldb" ) func init() { diff --git a/libs/db/c_level_db_test.go b/libs/db/c_level_db_test.go index d01a85e9d..c81b4185a 100644 --- a/libs/db/c_level_db_test.go +++ b/libs/db/c_level_db_test.go @@ -5,9 +5,11 @@ package db import ( "bytes" "fmt" + "os" "testing" "github.com/stretchr/testify/assert" + cmn "github.com/tendermint/tendermint/libs/common" ) @@ -88,8 +90,9 @@ func bytes2Int64(buf []byte) int64 { func TestCLevelDBBackend(t *testing.T) { name := fmt.Sprintf("test_%x", cmn.RandStr(12)) - db := NewDB(name, LevelDBBackend, "") - defer cleanupDBDir("", name) + dir := os.TempDir() + db := NewDB(name, LevelDBBackend, dir) + defer cleanupDBDir(dir, name) _, ok := db.(*CLevelDB) assert.True(t, ok) From 76302c651f786f3662011d3120d2de2bbd26956f Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Wed, 5 Sep 2018 16:53:51 +0400 Subject: [PATCH 2/7] remove LICENSE from libs/db in favor of root license --- libs/db/LICENSE.md | 3 --- libs/db/README.md | 1 - 2 files changed, 4 deletions(-) delete mode 100644 libs/db/LICENSE.md delete mode 100644 libs/db/README.md diff --git a/libs/db/LICENSE.md b/libs/db/LICENSE.md deleted file mode 100644 index ab8da59d8..000000000 --- a/libs/db/LICENSE.md +++ /dev/null @@ -1,3 +0,0 @@ -Tendermint Go-DB Copyright (C) 2015 All in Bits, Inc - -Released under the Apache2.0 license diff --git a/libs/db/README.md b/libs/db/README.md deleted file mode 100644 index ca5ab33f9..000000000 --- a/libs/db/README.md +++ /dev/null @@ -1 +0,0 @@ -TODO: syndtr/goleveldb should be replaced with actual LevelDB instance From 747797bf3b2581408ae69bdfd158b0df3435f563 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Wed, 5 Sep 2018 17:08:51 +0400 Subject: [PATCH 3/7] cleanup after tests! --- libs/db/backend_test.go | 6 +++++- libs/db/c_level_db_test.go | 4 +++- libs/db/common_test.go | 5 ++--- libs/db/db_test.go | 24 ++++++++++++++++++------ libs/db/go_level_db_test.go | 2 ++ libs/db/util_test.go | 16 +++++++++++----- 6 files changed, 41 insertions(+), 16 deletions(-) diff --git a/libs/db/backend_test.go b/libs/db/backend_test.go index a93698226..2aebde1c6 100644 --- a/libs/db/backend_test.go +++ b/libs/db/backend_test.go @@ -13,7 +13,10 @@ import ( ) func cleanupDBDir(dir, name string) { - os.RemoveAll(filepath.Join(dir, name) + ".db") + err := os.RemoveAll(filepath.Join(dir, name) + ".db") + if err != nil { + panic(err) + } } func testBackendGetSetDelete(t *testing.T, backend DBBackendType) { @@ -21,6 +24,7 @@ func testBackendGetSetDelete(t *testing.T, backend DBBackendType) { dirname, err := ioutil.TempDir("", fmt.Sprintf("test_backend_%s_", backend)) require.Nil(t, err) db := NewDB("testdb", backend, dirname) + defer cleanupDBDir(dirname, "testdb") // A nonexistent key should return nil, even if the key is empty require.Nil(t, db.Get([]byte(""))) diff --git a/libs/db/c_level_db_test.go b/libs/db/c_level_db_test.go index c81b4185a..eab3dfc41 100644 --- a/libs/db/c_level_db_test.go +++ b/libs/db/c_level_db_test.go @@ -34,7 +34,7 @@ func BenchmarkRandomReadsWrites2(b *testing.B) { // Write something { idx := (int64(cmn.RandInt()) % numItems) - internal[idx] += 1 + internal[idx]++ val := internal[idx] idxBytes := int642Bytes(int64(idx)) valBytes := int642Bytes(int64(val)) @@ -90,6 +90,8 @@ func bytes2Int64(buf []byte) int64 { func TestCLevelDBBackend(t *testing.T) { name := fmt.Sprintf("test_%x", cmn.RandStr(12)) + // Can't use "" (current directory) or "./" here because levigo.Open returns: + // "Error initializing DB: IO error: test_XXX.db: Invalid argument" dir := os.TempDir() db := NewDB(name, LevelDBBackend, dir) defer cleanupDBDir(dir, name) diff --git a/libs/db/common_test.go b/libs/db/common_test.go index 68420cd2b..13e6ed377 100644 --- a/libs/db/common_test.go +++ b/libs/db/common_test.go @@ -60,11 +60,10 @@ func checkValuePanics(t *testing.T, itr Iterator) { assert.Panics(t, func() { itr.Key() }, "checkValuePanics expected panic but didn't") } -func newTempDB(t *testing.T, backend DBBackendType) (db DB) { +func newTempDB(t *testing.T, backend DBBackendType) (db DB, dbDir string) { dirname, err := ioutil.TempDir("", "db_common_test") require.Nil(t, err) - db = NewDB("testdb", backend, dirname) - return db + return NewDB("testdb", backend, dirname), dirname } //---------------------------------------- diff --git a/libs/db/db_test.go b/libs/db/db_test.go index a56901016..ffa7bb6aa 100644 --- a/libs/db/db_test.go +++ b/libs/db/db_test.go @@ -2,6 +2,7 @@ package db import ( "fmt" + "os" "testing" "github.com/stretchr/testify/assert" @@ -10,7 +11,9 @@ import ( func TestDBIteratorSingleKey(t *testing.T) { for backend := range backends { t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { - db := newTempDB(t, backend) + db, dir := newTempDB(t, backend) + defer os.RemoveAll(dir) + db.SetSync(bz("1"), bz("value_1")) itr := db.Iterator(nil, nil) @@ -28,7 +31,9 @@ func TestDBIteratorSingleKey(t *testing.T) { func TestDBIteratorTwoKeys(t *testing.T) { for backend := range backends { t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { - db := newTempDB(t, backend) + db, dir := newTempDB(t, backend) + defer os.RemoveAll(dir) + db.SetSync(bz("1"), bz("value_1")) db.SetSync(bz("2"), bz("value_1")) @@ -54,7 +59,8 @@ func TestDBIteratorTwoKeys(t *testing.T) { func TestDBIteratorMany(t *testing.T) { for backend := range backends { t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { - db := newTempDB(t, backend) + db, dir := newTempDB(t, backend) + defer os.RemoveAll(dir) keys := make([][]byte, 100) for i := 0; i < 100; i++ { @@ -78,7 +84,9 @@ func TestDBIteratorMany(t *testing.T) { func TestDBIteratorEmpty(t *testing.T) { for backend := range backends { t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { - db := newTempDB(t, backend) + db, dir := newTempDB(t, backend) + defer os.RemoveAll(dir) + itr := db.Iterator(nil, nil) checkInvalid(t, itr) @@ -89,7 +97,9 @@ func TestDBIteratorEmpty(t *testing.T) { func TestDBIteratorEmptyBeginAfter(t *testing.T) { for backend := range backends { t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { - db := newTempDB(t, backend) + db, dir := newTempDB(t, backend) + defer os.RemoveAll(dir) + itr := db.Iterator(bz("1"), nil) checkInvalid(t, itr) @@ -100,7 +110,9 @@ func TestDBIteratorEmptyBeginAfter(t *testing.T) { func TestDBIteratorNonemptyBeginAfter(t *testing.T) { for backend := range backends { t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { - db := newTempDB(t, backend) + db, dir := newTempDB(t, backend) + defer os.RemoveAll(dir) + db.SetSync(bz("1"), bz("value_1")) itr := db.Iterator(bz("2"), nil) diff --git a/libs/db/go_level_db_test.go b/libs/db/go_level_db_test.go index 2b2346588..c24eec3c8 100644 --- a/libs/db/go_level_db_test.go +++ b/libs/db/go_level_db_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/binary" "fmt" + "os" "testing" "github.com/syndtr/goleveldb/leveldb/opt" @@ -17,6 +18,7 @@ func TestNewGoLevelDB(t *testing.T) { // Test write locks db, err := NewGoLevelDB(name, "") require.Nil(t, err) + defer os.RemoveAll("./" + name + ".db") _, err = NewGoLevelDB(name, "") require.NotNil(t, err) db.Close() // Close the db to release the lock diff --git a/libs/db/util_test.go b/libs/db/util_test.go index 44f1f9f73..07f9dd23e 100644 --- a/libs/db/util_test.go +++ b/libs/db/util_test.go @@ -2,6 +2,7 @@ package db import ( "fmt" + "os" "testing" ) @@ -9,7 +10,8 @@ import ( func TestPrefixIteratorNoMatchNil(t *testing.T) { for backend := range backends { t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { - db := newTempDB(t, backend) + db, dir := newTempDB(t, backend) + defer os.RemoveAll(dir) itr := IteratePrefix(db, []byte("2")) checkInvalid(t, itr) @@ -21,7 +23,8 @@ func TestPrefixIteratorNoMatchNil(t *testing.T) { func TestPrefixIteratorNoMatch1(t *testing.T) { for backend := range backends { t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { - db := newTempDB(t, backend) + db, dir := newTempDB(t, backend) + defer os.RemoveAll(dir) itr := IteratePrefix(db, []byte("2")) db.SetSync(bz("1"), bz("value_1")) @@ -34,7 +37,8 @@ func TestPrefixIteratorNoMatch1(t *testing.T) { func TestPrefixIteratorNoMatch2(t *testing.T) { for backend := range backends { t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { - db := newTempDB(t, backend) + db, dir := newTempDB(t, backend) + defer os.RemoveAll(dir) db.SetSync(bz("3"), bz("value_3")) itr := IteratePrefix(db, []byte("4")) @@ -47,7 +51,8 @@ func TestPrefixIteratorNoMatch2(t *testing.T) { func TestPrefixIteratorMatch1(t *testing.T) { for backend := range backends { t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { - db := newTempDB(t, backend) + db, dir := newTempDB(t, backend) + defer os.RemoveAll(dir) db.SetSync(bz("2"), bz("value_2")) itr := IteratePrefix(db, bz("2")) @@ -65,7 +70,8 @@ func TestPrefixIteratorMatch1(t *testing.T) { func TestPrefixIteratorMatches1N(t *testing.T) { for backend := range backends { t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { - db := newTempDB(t, backend) + db, dir := newTempDB(t, backend) + defer os.RemoveAll(dir) // prefixed db.SetSync(bz("a/1"), bz("value_1")) From 484194789fc4f5f62101ce96bee25e2e1da73244 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Mon, 10 Sep 2018 14:55:06 +0400 Subject: [PATCH 4/7] update Vagrantfile to install go1.11 --- Vagrantfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 095a6b061..320f3b1c3 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -29,10 +29,10 @@ Vagrant.configure("2") do |config| usermod -a -G docker vagrant # install go - wget -q https://dl.google.com/go/go1.10.1.linux-amd64.tar.gz - tar -xvf go1.10.1.linux-amd64.tar.gz + wget -q https://dl.google.com/go/go1.11.linux-amd64.tar.gz + tar -xvf go1.11.linux-amd64.tar.gz mv go /usr/local - rm -f go1.10.1.linux-amd64.tar.gz + rm -f go1.11.linux-amd64.tar.gz # cleanup apt-get autoremove -y From 788474d08d460b5d6074690adcade1ac1688c1d7 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Wed, 12 Sep 2018 13:12:12 +0400 Subject: [PATCH 5/7] change consensus_block_interval_seconds metric type to gauge Otherwise, it's impossible to see outliers https://github.com/tendermint/tendermint/issues/1835#issuecomment-402054099 --- CHANGELOG_PENDING.md | 1 + consensus/metrics.go | 8 ++++---- consensus/state.go | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index ad745fb82..bf4f3348b 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -21,5 +21,6 @@ FEATURES: IMPROVEMENTS: - [types] add Address to GenesisValidator [\#1714](https://github.com/tendermint/tendermint/issues/1714) +- [metrics] `consensus.block_interval_metrics` is now gauge, not histogram (you will be able to see spikes, if any) BUG FIXES: diff --git a/consensus/metrics.go b/consensus/metrics.go index 253880e84..91ae738d5 100644 --- a/consensus/metrics.go +++ b/consensus/metrics.go @@ -30,7 +30,7 @@ type Metrics struct { ByzantineValidatorsPower metrics.Gauge // Time between this and the last block. - BlockIntervalSeconds metrics.Histogram + BlockIntervalSeconds metrics.Gauge // Number of transactions. NumTxs metrics.Gauge @@ -85,11 +85,11 @@ func PrometheusMetrics() *Metrics { Help: "Total power of the byzantine validators.", }, []string{}), - BlockIntervalSeconds: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{ + + BlockIntervalSeconds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ Subsystem: "consensus", Name: "block_interval_seconds", Help: "Time between this and the last block.", - Buckets: []float64{1, 2.5, 5, 10, 60}, }, []string{}), NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ @@ -124,7 +124,7 @@ func NopMetrics() *Metrics { ByzantineValidators: discard.NewGauge(), ByzantineValidatorsPower: discard.NewGauge(), - BlockIntervalSeconds: discard.NewHistogram(), + BlockIntervalSeconds: discard.NewGauge(), NumTxs: discard.NewGauge(), BlockSizeBytes: discard.NewGauge(), diff --git a/consensus/state.go b/consensus/state.go index 63b10e0bf..bee0f893e 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1374,7 +1374,7 @@ func (cs *ConsensusState) recordMetrics(height int64, block *types.Block) { if height > 1 { lastBlockMeta := cs.blockStore.LoadBlockMeta(height - 1) - cs.metrics.BlockIntervalSeconds.Observe( + cs.metrics.BlockIntervalSeconds.Set( block.Time.Sub(lastBlockMeta.Header.Time).Seconds(), ) } From ff9d0cdfb62f89bdcc522366facaca4e81b743ab Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Fri, 14 Sep 2018 12:35:41 +0400 Subject: [PATCH 6/7] generate random txs otherwise we're benchmarking overriding single key (because hash stays the same!) --- state/txindex/kv/kv_test.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/state/txindex/kv/kv_test.go b/state/txindex/kv/kv_test.go index 67fdf9e24..f6ebe822c 100644 --- a/state/txindex/kv/kv_test.go +++ b/state/txindex/kv/kv_test.go @@ -190,34 +190,34 @@ func txResultWithTags(tags []cmn.KVPair) *types.TxResult { } func benchmarkTxIndex(txsCount int64, b *testing.B) { - tx := types.Tx("HELLO WORLD") - txResult := &types.TxResult{ - Height: 1, - Index: 0, - Tx: tx, - Result: abci.ResponseDeliverTx{ - Data: []byte{0}, - Code: abci.CodeTypeOK, - Log: "", - Tags: []cmn.KVPair{}, - }, - } - dir, err := ioutil.TempDir("", "tx_index_db") if err != nil { b.Fatal(err) } defer os.RemoveAll(dir) // nolint: errcheck - store := db.NewDB("tx_index", "leveldb", dir) + store := db.NewDB("tx_index", "bboltdb", dir) indexer := NewTxIndex(store) batch := txindex.NewBatch(txsCount) + txIndex := uint32(0) for i := int64(0); i < txsCount; i++ { + tx := cmn.RandBytes(250) + txResult := &types.TxResult{ + Height: 1, + Index: txIndex, + Tx: tx, + Result: abci.ResponseDeliverTx{ + Data: []byte{0}, + Code: abci.CodeTypeOK, + Log: "", + Tags: []cmn.KVPair{}, + }, + } if err := batch.Add(txResult); err != nil { b.Fatal(err) } - txResult.Index++ + txIndex++ } b.ResetTimer() From e1bda36c6ccc665df14819c82e38d67a1f0399b7 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Mon, 17 Sep 2018 13:25:17 +0400 Subject: [PATCH 7/7] switch back to original fork --- Gopkg.lock | 16 ++++++++-------- Gopkg.toml | 4 ++-- docs/introduction/install.md | 26 ++++++++++++++------------ libs/db/Makefile | 4 ---- libs/db/c_level_db.go | 2 +- state/txindex/kv/kv_test.go | 2 +- 6 files changed, 26 insertions(+), 28 deletions(-) delete mode 100644 libs/db/Makefile diff --git a/Gopkg.lock b/Gopkg.lock index 9a27f344a..8deb06378 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1,13 +1,6 @@ # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. -[[projects]] - digest = "1:5da259989116f6ab5e05a80086c639c82efdbdb799ca07183eb0b660edfd91fe" - name = "github.com/DataDog/leveldb" - packages = ["."] - pruneopts = "UT" - revision = "12a0b6e10a5bf779330ed8b7c0f1f39f212d34e2" - [[projects]] branch = "master" digest = "1:d6afaeed1502aa28e80a4ed0981d570ad91b2579193404256ce672ed0a609e0d" @@ -168,6 +161,13 @@ revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" version = "v1.0" +[[projects]] + digest = "1:39b27d1381a30421f9813967a5866fba35dc1d4df43a6eefe3b7a5444cb07214" + name = "github.com/jmhodges/levigo" + packages = ["."] + pruneopts = "UT" + revision = "c42d9e0ca023e2198120196f842701bb4c55d7b9" + [[projects]] branch = "master" digest = "1:a64e323dc06b73892e5bb5d040ced475c4645d456038333883f58934abbf6f72" @@ -511,7 +511,6 @@ analyzer-name = "dep" analyzer-version = 1 input-imports = [ - "github.com/DataDog/leveldb", "github.com/btcsuite/btcutil/base58", "github.com/btcsuite/btcutil/bech32", "github.com/ebuchman/fail-test", @@ -530,6 +529,7 @@ "github.com/golang/protobuf/proto", "github.com/golang/protobuf/ptypes/timestamp", "github.com/gorilla/websocket", + "github.com/jmhodges/levigo", "github.com/pkg/errors", "github.com/prometheus/client_golang/prometheus", "github.com/prometheus/client_golang/prometheus/promhttp", diff --git a/Gopkg.toml b/Gopkg.toml index cda7988c5..d3bca19e8 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -73,8 +73,8 @@ ## Pin to revision [[override]] - name = "github.com/DataDog/leveldb" - revision = "12a0b6e10a5bf779330ed8b7c0f1f39f212d34e2" + name = "github.com/jmhodges/levigo" + revision = "c42d9e0ca023e2198120196f842701bb4c55d7b9" [[constraint]] name = "github.com/ebuchman/fail-test" diff --git a/docs/introduction/install.md b/docs/introduction/install.md index 925ed2a80..c7b83b03c 100644 --- a/docs/introduction/install.md +++ b/docs/introduction/install.md @@ -77,22 +77,24 @@ make install ## Compile with CLevelDB support -Make sure you have a roughly compatible version of libstdc++ (tested with -5.3.1). For example, on Ubuntu: +Install [LevelDB](https://github.com/google/leveldb) (minimum version is 1.7) +with snappy. Example for Ubuntu: ``` sudo apt-get update -sudo apt-get install gcc -sudo apt-cache show libstdc++6 -Version: 5.3.1-14ubuntu2 -``` +sudo apt install build-essential -Check out leveldb dependency using git (for some reason dep does not check out -submodules): +sudo apt-get install libsnappy-dev -``` -cd vendor/github.com/DataDog && rm -rf leveldb -git clone https://github.com/DataDog/leveldb.git +wget https://github.com/google/leveldb/archive/v1.20.tar.gz && \ + tar -zxvf v1.20.tar.gz && \ + cd leveldb-1.20/ && \ + make && \ + sudo scp -r out-static/lib* out-shared/lib* /usr/local/lib/ && \ + cd include/ && \ + sudo scp -r leveldb /usr/local/include/ && \ + sudo ldconfig && \ + rm -f v1.20.tar.gz ``` Set database backend to cleveldb: @@ -105,5 +107,5 @@ db_backend = "cleveldb" To build Tendermint, run ``` -CGO_ENABLED=1 CGO_CXXFLAGS_ALLOW="(-fno-builtin-memcmp|-lpthread)" CGO_CFLAGS_ALLOW="-fno-builtin-memcmp" go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags "tendermint gcc" -o build/tendermint ./cmd/tendermint/ +CGO_LDFLAGS="-lsnappy" go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags "tendermint gcc" -o build/tendermint ./cmd/tendermint/ ``` diff --git a/libs/db/Makefile b/libs/db/Makefile deleted file mode 100644 index e0cd45b0a..000000000 --- a/libs/db/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -test_gcc: - CGO_CXXFLAGS_ALLOW="(-fno-builtin-memcmp|-lpthread)" CGO_CFLAGS_ALLOW="-fno-builtin-memcmp" go test -tags gcc - -.PHONY: test_gcc diff --git a/libs/db/c_level_db.go b/libs/db/c_level_db.go index 10f03aa0c..307461261 100644 --- a/libs/db/c_level_db.go +++ b/libs/db/c_level_db.go @@ -7,7 +7,7 @@ import ( "fmt" "path/filepath" - levigo "github.com/DataDog/leveldb" + "github.com/jmhodges/levigo" ) func init() { diff --git a/state/txindex/kv/kv_test.go b/state/txindex/kv/kv_test.go index f6ebe822c..78a76168d 100644 --- a/state/txindex/kv/kv_test.go +++ b/state/txindex/kv/kv_test.go @@ -196,7 +196,7 @@ func benchmarkTxIndex(txsCount int64, b *testing.B) { } defer os.RemoveAll(dir) // nolint: errcheck - store := db.NewDB("tx_index", "bboltdb", dir) + store := db.NewDB("tx_index", "leveldb", dir) indexer := NewTxIndex(store) batch := txindex.NewBatch(txsCount)