From 11abf3c7bd4add46e1b273d08e7a3254b6dc5d5a Mon Sep 17 00:00:00 2001 From: Yumin Xia Date: Wed, 9 Oct 2019 14:14:57 -0700 Subject: [PATCH] Upgrade3 genesis and Dockerfile. (#409) * add docker file * reset first to clean up genesis cache * no longer use patches * update ubuntu bootstrap script go version * upgrade go version * update genesis * typo --- Dockerfile | 29 ++ Makefile | 20 +- docker-compose.yml | 12 - docker/Dockerfile_lino | 28 -- docker/Dockerfile_linocli | 21 -- docker/cli_test.sh | 18 -- docker/genesis.json | 68 ----- docker/priv_validator.json | 14 - genesis/upgrade3/genesis.json | 3 +- .../fixes/cosmos-cleveldb-close-batch.patch | 12 - patches/fixes/iavl-cleveldb-close-batch.patch | 12 - .../tendermint-cleveldb-close-batch.patch | 201 ------------- .../tendermint-cached-txindexer.patch | 280 ------------------ patches/general/README.org | 3 - patches/general/constructors | 41 --- .../general/cosmos-server-constructor.patch | 11 - patches/general/gen_patch.sh | 7 - scripts/bootstrap_ubuntu.sh | 2 +- scripts/update_ubuntu.sh | 2 +- 19 files changed, 48 insertions(+), 736 deletions(-) create mode 100644 Dockerfile delete mode 100644 docker-compose.yml delete mode 100644 docker/Dockerfile_lino delete mode 100644 docker/Dockerfile_linocli delete mode 100755 docker/cli_test.sh delete mode 100644 docker/genesis.json delete mode 100644 docker/priv_validator.json delete mode 100644 patches/fixes/cosmos-cleveldb-close-batch.patch delete mode 100644 patches/fixes/iavl-cleveldb-close-batch.patch delete mode 100644 patches/fixes/tendermint-cleveldb-close-batch.patch delete mode 100644 patches/fullnode/tendermint-cached-txindexer.patch delete mode 100644 patches/general/README.org delete mode 100644 patches/general/constructors delete mode 100644 patches/general/cosmos-server-constructor.patch delete mode 100755 patches/general/gen_patch.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..f298cd25 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM golang:1.12 + +RUN apt-get update && \ + apt-get install -y make tar sudo wget curl + +RUN mkdir -p src/github.com/lino-network/lino +WORKDIR src/github.com/lino-network/lino + +COPY . . +RUN make get_tools +RUN make install + +RUN lino init +COPY genesis/upgrade3/config.toml /root/.lino/config/config.toml +COPY genesis/upgrade3/genesis.json /root/.lino/config/genesis.json +RUN cd /root/.lino && wget https://lino-blockchain-opendata.s3.amazonaws.com/prd/prevstates.tar.gz +RUN cd /root/.lino && tar -xf prevstates.tar.gz + +# prometheus if enabled +EXPOSE 26660 +# p2p +EXPOSE 26656 +# tendermint rpc +EXPOSE 26657 +# abci app +EXPOSE 26658 + +CMD ["lino", "unsafe-reset-all"] +CMD ["lino", "start"] diff --git a/Makefile b/Makefile index fb5a06d9..dac28e94 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +NAME=lino GOPATH ?= $(shell $(GO) env GOPATH) COMMIT := $(shell git --no-pager describe --tags --always --dirty) PACKAGES=$(shell go list ./... | grep -v '/vendor/') @@ -11,10 +12,6 @@ all: get_tools install build test get_tools: cd scripts && ./install_cleveldb.sh -# apply_patch: -# (cd vendor/github.com/tendermint/tendermint && patch -p1 -t < ../../../../patches/fullnode/tendermint-cached-txindexer.patch); exit 0 -# (cd vendor/github.com/cosmos/cosmos-sdk && patch -p1 -t < ../../../../patches/fixes/cosmos-cleveldb-close-batch.patch); exit 0 - update_mocks: GO111MODULE=$(GO111MODULE) go generate ./... @@ -44,6 +41,21 @@ test: benchmark: @go test -bench=. $(PACKAGES) +docker-build: + docker build -t $(NAME) . + +docker-build-nc: + docker build --no-cache -t $(NAME) . + +docker-run: + docker run --name=$(NAME) -it $(NAME) + +docker-up: docker-build docker-run + +docker-clean: + docker stop $(NAME) + docker rm $(NAME) + # lint GOLANGCI_LINT_VERSION := v1.17.1 GOLANGCI_LINT_HASHSUM := f5fa647a12f658924d9f7d6b9628d505ab118e8e049e43272de6526053ebe08d diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 2af188f7..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: '3' -services: - lino: - build: - context: . - dockerfile: docker/Dockerfile_lino - linocli: - build: - context: . - dockerfile: docker/Dockerfile_linocli - depends_on: - - "lino" \ No newline at end of file diff --git a/docker/Dockerfile_lino b/docker/Dockerfile_lino deleted file mode 100644 index d6ab15a6..00000000 --- a/docker/Dockerfile_lino +++ /dev/null @@ -1,28 +0,0 @@ -FROM golang:1.9 - - -RUN apt-get update && \ - apt-get -y install wget curl sudo && \ - apt-get install -y git - - -RUN mkdir -p src/github.com/lino-network/lino -WORKDIR src/github.com/lino-network/lino -COPY . . - -RUN go get -u github.com/golang/dep/cmd/dep - -RUN dep ensure - -WORKDIR cmd/lino -RUN go build - -RUN rm -rf /root/.lino -RUN mkdir -p /root/.lino/config/ -COPY docker/genesis.json /root/.lino/config/genesis.json -COPY docker/priv_validator.json /root/.lino/config/priv_validator.json - -EXPOSE 26657 - -CMD ["./lino", "unsafe_reset_all"] -CMD ["./lino", "start", "--log_level=error"] \ No newline at end of file diff --git a/docker/Dockerfile_linocli b/docker/Dockerfile_linocli deleted file mode 100644 index 5bd5c164..00000000 --- a/docker/Dockerfile_linocli +++ /dev/null @@ -1,21 +0,0 @@ -FROM golang:1.9 - - -RUN apt-get update && \ - apt-get -y install wget curl netcat sudo && \ - apt-get install -y git - - -RUN mkdir -p src/github.com/lino-network/lino -WORKDIR src/github.com/lino-network/lino -COPY . . - -RUN go get -u github.com/golang/dep/cmd/dep - -RUN dep ensure - -WORKDIR cmd/linocli -RUN go build -COPY docker/cli_test.sh . -RUN chmod +x cli_test.sh -CMD ./cli_test.sh \ No newline at end of file diff --git a/docker/cli_test.sh b/docker/cli_test.sh deleted file mode 100755 index 8fb0bd76..00000000 --- a/docker/cli_test.sh +++ /dev/null @@ -1,18 +0,0 @@ -#/bin/bash -while ! nc -z lino 26657; - do - echo sleeping; - sleep 1; - done; - echo Connected! - -echo "show username" -./linocli username lino --node=lino:26657 - - -echo "register user" -./linocli register --user=newuser --referrer=lino --amount=10 --priv-key=E1B0F79A20AECFA4549861801551DB876C3D54A1A729A030CC07BDEEB8935294CD51D6ADE2 --chain-id=lino-test --node=lino:26657 - - -echo "transfer to new user" -./linocli transfer --sender=lino --receiver=newuser --amount=10 --memo=memo --priv-key=E1B0F79A20AECFA4549861801551DB876C3D54A1A729A030CC07BDEEB8935294CD51D6ADE2 --chain-id=lino-test --sequence=1 --node=lino:26657 \ No newline at end of file diff --git a/docker/genesis.json b/docker/genesis.json deleted file mode 100644 index 6183b0d7..00000000 --- a/docker/genesis.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "app_state": { - "accounts": [ - { - "name": "lino", - "lino": "10000000000", - "master_key": { - "type": "F8CCEAEB5AE980", - "value": "AnYgbC0MZKJa2NDnN0rSVqGJU2/qisuEub6wcV0xsjjV" - }, - "transaction_key": { - "type": "F8CCEAEB5AE980", - "value": "A+NktLC8OjAtS7SLeJjUjR1aCTt39JDZUnT23jC/l9Uo" - }, - "post_key": { - "type": "F8CCEAEB5AE980", - "value": "AucwGqtBs628Ym0Lw2XkgWXdC1EecEU7/uos5mhzvzta" - }, - "is_validator": true, - "validator_pub_key": { - "type": "AC26791624DE60", - "value": "4ycR0jw6r99/Hx6jqnOEcLySMnKer1VxW9t6MxM5h9Y=" - } - } - ], - "developers": [ - { - "name": "lino", - "deposit": "1000000" - } - ], - "infra": [ - { - "name": "lino" - } - ] - }, - "genesis_time": "2018-06-22T15:52:48.850077-07:00", - "chain_id": "lino-test", - "consensus_params": { - "block_size_params": { - "max_bytes": 22020096, - "max_txs": 100000, - "max_gas": -1 - }, - "tx_size_params": { - "max_bytes": 10240, - "max_gas": -1 - }, - "block_gossip_params": { - "block_part_size_bytes": 65536 - }, - "evidence_params": { - "max_age": 100000 - } - }, - "validators": [ - { - "pub_key": { - "type": "AC26791624DE60", - "value": "4ycR0jw6r99/Hx6jqnOEcLySMnKer1VxW9t6MxM5h9Y=" - }, - "power": 1000, - "name": "" - } - ], - "app_hash": "" -} \ No newline at end of file diff --git a/docker/priv_validator.json b/docker/priv_validator.json deleted file mode 100644 index 0e1208be..00000000 --- a/docker/priv_validator.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "address": "32098C8E9A7DFFAB85D5165AD36BFD952EE988D8", - "pub_key": { - "type": "AC26791624DE60", - "value": "4ycR0jw6r99/Hx6jqnOEcLySMnKer1VxW9t6MxM5h9Y=" - }, - "last_height": 0, - "last_round": 0, - "last_step": 0, - "priv_key": { - "type": "954568A3288910", - "value": "Jv4vu4Wxmv7bU9g80wpvFH1EJ7Tulr6tidkY8Hcd6L3jJxHSPDqv338fHqOqc4RwvJIycp6vVXFb23ozEzmH1g==" - } -} \ No newline at end of file diff --git a/genesis/upgrade3/genesis.json b/genesis/upgrade3/genesis.json index 31ec76d5..9d55b6b3 100644 --- a/genesis/upgrade3/genesis.json +++ b/genesis/upgrade3/genesis.json @@ -1,6 +1,5 @@ -// TODO: add genesis time { - "genesis_time": "TODO", + "genesis_time": "2019-10-09T21:12:31.003806668Z", "chain_id": "lino-testnet-upgrade3", "consensus_params": { "block": { diff --git a/patches/fixes/cosmos-cleveldb-close-batch.patch b/patches/fixes/cosmos-cleveldb-close-batch.patch deleted file mode 100644 index 6505a0cb..00000000 --- a/patches/fixes/cosmos-cleveldb-close-batch.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go -index 85d9b5b20..9c55fed2c 100644 ---- a/store/rootmulti/store.go -+++ b/store/rootmulti/store.go -@@ -198,6 +198,7 @@ func (rs *Store) Commit() types.CommitID { - - // Need to update atomically. - batch := rs.db.NewBatch() -+ defer batch.Close() - setCommitInfo(batch, version, commitInfo) - setLatestVersion(batch, version) - batch.Write() diff --git a/patches/fixes/iavl-cleveldb-close-batch.patch b/patches/fixes/iavl-cleveldb-close-batch.patch deleted file mode 100644 index 3a8d52a6..00000000 --- a/patches/fixes/iavl-cleveldb-close-batch.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/nodedb.go b/nodedb.go -index c41a1c0..2d97095 100644 ---- a/nodedb.go -+++ b/nodedb.go -@@ -330,6 +330,7 @@ func (ndb *nodeDB) Commit() { - defer ndb.mtx.Unlock() - - ndb.batch.Write() -+ ndb.batch.Close() - ndb.batch = ndb.db.NewBatch() - } - diff --git a/patches/fixes/tendermint-cleveldb-close-batch.patch b/patches/fixes/tendermint-cleveldb-close-batch.patch deleted file mode 100644 index 1d92736b..00000000 --- a/patches/fixes/tendermint-cleveldb-close-batch.patch +++ /dev/null @@ -1,201 +0,0 @@ -diff --git a/libs/db/c_level_db.go b/libs/db/c_level_db.go -index 7f74b2a7..81d8be7c 100644 ---- a/libs/db/c_level_db.go -+++ b/libs/db/c_level_db.go -@@ -21,17 +21,22 @@ func init() { - var _ DB = (*CLevelDB)(nil) - - type CLevelDB struct { -- db *levigo.DB -- ro *levigo.ReadOptions -- wo *levigo.WriteOptions -- woSync *levigo.WriteOptions -+ db *levigo.DB -+ ro *levigo.ReadOptions -+ wo *levigo.WriteOptions -+ woSync *levigo.WriteOptions -+ cache *levigo.Cache -+ filterPolicy *levigo.FilterPolicy - } - - func NewCLevelDB(name string, dir string) (*CLevelDB, error) { - dbPath := filepath.Join(dir, name+".db") - -+ cache := levigo.NewLRUCache(500 * 1024 * 1024) // XXX(yumin): let's try use a smaller cache. -+ filter := levigo.NewBloomFilter(10) - opts := levigo.NewOptions() -- opts.SetCache(levigo.NewLRUCache(1 << 30)) -+ opts.SetCache(cache) -+ opts.SetFilterPolicy(filter) - opts.SetCreateIfMissing(true) - db, err := levigo.Open(dbPath, opts) - if err != nil { -@@ -42,10 +47,12 @@ func NewCLevelDB(name string, dir string) (*CLevelDB, error) { - woSync := levigo.NewWriteOptions() - woSync.SetSync(true) - database := &CLevelDB{ -- db: db, -- ro: ro, -- wo: wo, -- woSync: woSync, -+ db: db, -+ ro: ro, -+ wo: wo, -+ woSync: woSync, -+ cache: cache, -+ filterPolicy: filter, - } - return database, nil - } -@@ -113,6 +120,8 @@ func (db *CLevelDB) Close() { - db.ro.Close() - db.wo.Close() - db.woSync.Close() -+ db.cache.Close() -+ db.filterPolicy.Close() - } - - // Implements DB. -@@ -179,6 +188,11 @@ func (mBatch *cLevelDBBatch) WriteSync() { - } - } - -+// Implements Batch. -+func (mBatch *cLevelDBBatch) Close() { -+ mBatch.batch.Close() -+} -+ - //---------------------------------------- - // Iterator - // NOTE This is almost identical to db/go_level_db.Iterator -diff --git a/libs/db/debug_db.go b/libs/db/debug_db.go -index bb361a26..658cd055 100644 ---- a/libs/db/debug_db.go -+++ b/libs/db/debug_db.go -@@ -250,3 +250,8 @@ func (dbch debugBatch) WriteSync() { - fmt.Printf("%v.batch.WriteSync()\n", dbch.label) - dbch.bch.WriteSync() - } -+ -+// Implements Batch. -+func (dbch debugBatch) Close() { -+ dbch.bch.Close() -+} -diff --git a/libs/db/go_level_db.go b/libs/db/go_level_db.go -index fd487a4d..9a4358f6 100644 ---- a/libs/db/go_level_db.go -+++ b/libs/db/go_level_db.go -@@ -184,6 +184,10 @@ func (mBatch *goLevelDBBatch) WriteSync() { - } - } - -+// Implements Batch. -+// Close is no-op for goLevelDBBatch. -+func (mBatch *goLevelDBBatch) Close() {} -+ - //---------------------------------------- - // Iterator - // NOTE This is almost identical to db/c_level_db.Iterator -diff --git a/libs/db/mem_batch.go b/libs/db/mem_batch.go -index 5c5d0c13..ebba43f5 100644 ---- a/libs/db/mem_batch.go -+++ b/libs/db/mem_batch.go -@@ -46,6 +46,10 @@ func (mBatch *memBatch) WriteSync() { - mBatch.write(true) - } - -+func (mBatch *memBatch) Close() { -+ mBatch.ops = nil -+} -+ - func (mBatch *memBatch) write(doSync bool) { - if mtx := mBatch.db.Mutex(); mtx != nil { - mtx.Lock() -diff --git a/libs/db/prefix_db.go b/libs/db/prefix_db.go -index 40d72560..0dd06ef9 100644 ---- a/libs/db/prefix_db.go -+++ b/libs/db/prefix_db.go -@@ -248,6 +248,10 @@ func (pb prefixBatch) WriteSync() { - pb.source.WriteSync() - } - -+func (pb prefixBatch) Close() { -+ pb.source.Close() -+} -+ - //---------------------------------------- - // prefixIterator - -diff --git a/libs/db/remotedb/grpcdb/server.go b/libs/db/remotedb/grpcdb/server.go -index 3a9955dd..bfe65e61 100644 ---- a/libs/db/remotedb/grpcdb/server.go -+++ b/libs/db/remotedb/grpcdb/server.go -@@ -180,6 +180,7 @@ func (s *server) BatchWriteSync(c context.Context, b *protodb.Batch) (*protodb.N - - func (s *server) batchWrite(c context.Context, b *protodb.Batch, sync bool) (*protodb.Nothing, error) { - bat := s.db.NewBatch() -+ defer bat.Close() - for _, op := range b.Ops { - switch op.Type { - case protodb.Operation_SET: -diff --git a/libs/db/remotedb/remotedb.go b/libs/db/remotedb/remotedb.go -index 2b60d815..c70d54b9 100644 ---- a/libs/db/remotedb/remotedb.go -+++ b/libs/db/remotedb/remotedb.go -@@ -260,3 +260,7 @@ func (bat *batch) WriteSync() { - panic(fmt.Sprintf("RemoteDB.BatchWriteSync: %v", err)) - } - } -+ -+func (bat *batch) Close() { -+ bat.ops = nil -+} -diff --git a/libs/db/types.go b/libs/db/types.go -index 9b9c6d0b..30f8afd1 100644 ---- a/libs/db/types.go -+++ b/libs/db/types.go -@@ -57,10 +57,12 @@ type DB interface { - //---------------------------------------- - // Batch - -+// Batch Close must be called when the program no longer needs the object. - type Batch interface { - SetDeleter - Write() - WriteSync() -+ Close() - } - - type SetDeleter interface { -diff --git a/lite/dbprovider.go b/lite/dbprovider.go -index ef1b2a59..9a3636d5 100644 ---- a/lite/dbprovider.go -+++ b/lite/dbprovider.go -@@ -54,6 +54,7 @@ func (dbp *DBProvider) SaveFullCommit(fc FullCommit) error { - - dbp.logger.Info("DBProvider.SaveFullCommit()...", "fc", fc) - batch := dbp.db.NewBatch() -+ defer batch.Close() - - // Save the fc.validators. - // We might be overwriting what we already have, but -diff --git a/state/txindex/kv/kv.go b/state/txindex/kv/kv.go -index 93249b7f..84208b8c 100644 ---- a/state/txindex/kv/kv.go -+++ b/state/txindex/kv/kv.go -@@ -78,6 +78,7 @@ func (txi *TxIndex) Get(hash []byte) (*types.TxResult, error) { - // AddBatch indexes a batch of transactions using the given list of tags. - func (txi *TxIndex) AddBatch(b *txindex.Batch) error { - storeBatch := txi.store.NewBatch() -+ defer storeBatch.Close() - - for _, result := range b.Ops { - hash := result.Tx.Hash() -@@ -109,6 +110,7 @@ func (txi *TxIndex) AddBatch(b *txindex.Batch) error { - // Index indexes a single transaction using the given list of tags. - func (txi *TxIndex) Index(result *types.TxResult) error { - b := txi.store.NewBatch() -+ defer b.Close() - - hash := result.Tx.Hash() - diff --git a/patches/fullnode/tendermint-cached-txindexer.patch b/patches/fullnode/tendermint-cached-txindexer.patch deleted file mode 100644 index 4998a7d6..00000000 --- a/patches/fullnode/tendermint-cached-txindexer.patch +++ /dev/null @@ -1,280 +0,0 @@ -diff --git a/consensus/replay.go b/consensus/replay.go -index e47d4892..c249231a 100644 ---- a/consensus/replay.go -+++ b/consensus/replay.go -@@ -16,6 +16,8 @@ import ( - cmn "github.com/tendermint/tendermint/libs/common" - dbm "github.com/tendermint/tm-db" - "github.com/tendermint/tendermint/libs/log" -+ "github.com/tendermint/tendermint/state/txindex" -+ nulltxindexer "github.com/tendermint/tendermint/state/txindex/null" - - "github.com/tendermint/tendermint/proxy" - sm "github.com/tendermint/tendermint/state" -@@ -203,6 +205,9 @@ type Handshaker struct { - genDoc *types.GenesisDoc - logger log.Logger - -+ // indexer, null cacher if not set -+ txindexer txindex.TxIndexer -+ - nBlocks int // number of blocks applied to the state - } - -@@ -216,6 +221,7 @@ func NewHandshaker(stateDB dbm.DB, state sm.State, - eventBus: types.NopEventBus{}, - genDoc: genDoc, - logger: log.NewNopLogger(), -+ txindexer: &nulltxindexer.TxIndex{}, - nBlocks: 0, - } - } -@@ -224,6 +230,11 @@ func (h *Handshaker) SetLogger(l log.Logger) { - h.logger = l - } - -+// SetTxIndexer - sets tx indexer, if not called, nulltxinders. -+func (h *Handshaker) SetTxIndexer(indexer txindex.TxIndexer) { -+ h.txindexer = indexer -+} -+ - // SetEventBus - sets the event bus for publishing block related events. - // If not called, it defaults to types.NopEventBus. - func (h *Handshaker) SetEventBus(eventBus types.BlockEventPublisher) { -@@ -445,6 +456,9 @@ func (h *Handshaker) replayBlock(state sm.State, height int64, proxyApp proxy.Ap - blockExec := sm.NewBlockExecutor(h.stateDB, h.logger, proxyApp, sm.MockMempool{}, sm.MockEvidencePool{}) - blockExec.SetEventBus(h.eventBus) - -+ // XXX(yumin): setTxIndexer for cache is required as fullnodes hit this path. -+ blockExec.SetTxIndexer(h.txindexer) -+ - var err error - state, err = blockExec.ApplyBlock(state, meta.BlockID, block) - if err != nil { -diff --git a/node/node.go b/node/node.go -index c0a4d736..aaab98d2 100644 ---- a/node/node.go -+++ b/node/node.go -@@ -362,6 +362,9 @@ func NewNode(config *cfg.Config, - sm.BlockExecutorWithMetrics(smMetrics), - ) - -+ // set txIndexer -+ blockExec.SetTxIndexer(txIndexer) -+ - // Make BlockchainReactor - bcReactor := bc.NewBlockchainReactor(state.Copy(), blockExec, blockStore, fastSync) - bcReactor.SetLogger(logger.With("module", "blockchain")) -diff --git a/state/execution.go b/state/execution.go -index 3a11ecca..e962b487 100644 ---- a/state/execution.go -+++ b/state/execution.go -@@ -9,6 +9,8 @@ import ( - "github.com/tendermint/tendermint/libs/fail" - "github.com/tendermint/tendermint/libs/log" - "github.com/tendermint/tendermint/proxy" -+ "github.com/tendermint/tendermint/state/txindex" -+ nulltxindexer "github.com/tendermint/tendermint/state/txindex/null" - "github.com/tendermint/tendermint/types" - ) - -@@ -25,6 +27,9 @@ type BlockExecutor struct { - // execute the app against this - proxyApp proxy.AppConnConsensus - -+ // indexer, null cacher if not set -+ txindexer txindex.TxIndexer -+ - // events - eventBus types.BlockEventPublisher - -@@ -50,13 +55,14 @@ func BlockExecutorWithMetrics(metrics *Metrics) BlockExecutorOption { - // Call SetEventBus to provide one. - func NewBlockExecutor(db dbm.DB, logger log.Logger, proxyApp proxy.AppConnConsensus, mempool Mempool, evpool EvidencePool, options ...BlockExecutorOption) *BlockExecutor { - res := &BlockExecutor{ -- db: db, -- proxyApp: proxyApp, -- eventBus: types.NopEventBus{}, -- mempool: mempool, -- evpool: evpool, -- logger: logger, -- metrics: NopMetrics(), -+ db: db, -+ proxyApp: proxyApp, -+ txindexer: &nulltxindexer.TxIndex{}, -+ eventBus: types.NopEventBus{}, -+ mempool: mempool, -+ evpool: evpool, -+ logger: logger, -+ metrics: NopMetrics(), - } - - for _, option := range options { -@@ -66,6 +72,11 @@ func NewBlockExecutor(db dbm.DB, logger log.Logger, proxyApp proxy.AppConnConsen - return res - } - -+// SetTxIndexer - sets tx indexer, if not called, nulltxinders. -+func (blockExec *BlockExecutor) SetTxIndexer(indexer txindex.TxIndexer) { -+ blockExec.txindexer = indexer -+} -+ - // SetEventBus - sets the event bus for publishing block related events. - // If not called, it defaults to types.NopEventBus. - func (blockExec *BlockExecutor) SetEventBus(eventBus types.BlockEventPublisher) { -@@ -150,6 +161,16 @@ func (blockExec *BlockExecutor) ApplyBlock(state State, blockID types.BlockID, b - return state, fmt.Errorf("Commit failed for application: %v", err) - } - -+ // XXX(yumin): this must happen before Commit to cache txs. -+ for i, tx := range block.Data.Txs { -+ blockExec.txindexer.Cache(&types.TxResult{ -+ Height: block.Height, -+ Index: uint32(i), -+ Tx: tx, -+ Result: *(abciResponses.DeliverTx[i]), -+ }) -+ } -+ - // Lock mempool, commit app state, update mempoool. - appHash, err := blockExec.Commit(state, block) - if err != nil { -diff --git a/state/txindex/indexer.go b/state/txindex/indexer.go -index ab509f96..c8aee640 100644 ---- a/state/txindex/indexer.go -+++ b/state/txindex/indexer.go -@@ -9,6 +9,8 @@ import ( - - // TxIndexer interface defines methods to index and search transactions. - type TxIndexer interface { -+ // cache a result in memory, will be removed later if persisted in AddBatch. -+ Cache(result *types.TxResult) - - // AddBatch analyzes, indexes and stores a batch of transactions. - AddBatch(b *Batch) error -diff --git a/state/txindex/kv/kv.go b/state/txindex/kv/kv.go -index 84208b8c..9de38181 100644 ---- a/state/txindex/kv/kv.go -+++ b/state/txindex/kv/kv.go -@@ -7,11 +7,13 @@ import ( - "sort" - "strconv" - "strings" -+ "sync" - "time" - - "github.com/pkg/errors" - cmn "github.com/tendermint/tendermint/libs/common" - dbm "github.com/tendermint/tm-db" -+ "github.com/tendermint/tendermint/libs/log" - - "github.com/tendermint/tendermint/libs/pubsub/query" - "github.com/tendermint/tendermint/state/txindex" -@@ -20,6 +22,7 @@ import ( - - const ( - tagKeySeparator = "/" -+ cacheSizeMax = 5000 - ) - - var _ txindex.TxIndexer = (*TxIndex)(nil) -@@ -29,11 +32,16 @@ type TxIndex struct { - store dbm.DB - tagsToIndex []string - indexAllTags bool -+ -+ logger log.Logger -+ cache map[string]types.TxResult -+ cacheMux sync.Mutex - } - - // NewTxIndex creates new KV indexer. - func NewTxIndex(store dbm.DB, options ...func(*TxIndex)) *TxIndex { -- txi := &TxIndex{store: store, tagsToIndex: make([]string, 0), indexAllTags: false} -+ txi := &TxIndex{store: store, tagsToIndex: make([]string, 0), indexAllTags: false, -+ cache: make(map[string]types.TxResult)} - for _, o := range options { - o(txi) - } -@@ -54,6 +62,43 @@ func IndexAllTags() func(*TxIndex) { - } - } - -+func (txi *TxIndex) getFromCache(hash []byte) (types.TxResult, bool) { -+ txi.cacheMux.Lock() -+ defer txi.cacheMux.Unlock() -+ v, ok := txi.cache[string(hash)] -+ return v, ok -+} -+ -+func (txi *TxIndex) removeFromCache(hash []byte) { -+ txi.cacheMux.Lock() -+ defer txi.cacheMux.Unlock() -+ if _, ok := txi.cache[string(hash)]; !ok { -+ if txi.logger != nil { -+ txi.logger.Error("[CachedTxIndexer] Removing non-existed hash") -+ } else { -+ fmt.Printf("%s\n", "[CachedTxIndexer] Removing non-existed hash") -+ } -+ } -+ delete(txi.cache, string(hash)) -+} -+ -+func (txi *TxIndex) Cache(result *types.TxResult) { -+ if result == nil { -+ return -+ } -+ txi.cacheMux.Lock() -+ defer txi.cacheMux.Unlock() -+ txi.cache[string(result.Tx.Hash())] = *result -+ -+ if len(txi.cache) > cacheSizeMax { -+ if txi.logger != nil { -+ txi.logger.Error("TxIndexer cache size execeeds limit: %d", len(txi.cache)) -+ } else { -+ fmt.Printf("TxIndexer cache size execeeds limit: %d\n", len(txi.cache)) -+ } -+ } -+} -+ - // Get gets transaction from the TxIndex storage and returns it or nil if the - // transaction is not found. - func (txi *TxIndex) Get(hash []byte) (*types.TxResult, error) { -@@ -61,6 +106,10 @@ func (txi *TxIndex) Get(hash []byte) (*types.TxResult, error) { - return nil, txindex.ErrorEmptyHash - } - -+ if v, ok := txi.getFromCache(hash); ok { -+ return &v, nil -+ } -+ - rawBytes := txi.store.Get(hash) - if rawBytes == nil { - return nil, nil -@@ -104,6 +153,12 @@ func (txi *TxIndex) AddBatch(b *txindex.Batch) error { - } - - storeBatch.Write() -+ -+ // persisted, remove from cache -+ for _, result := range b.Ops { -+ txi.removeFromCache(result.Tx.Hash()) -+ } -+ - return nil - } - -diff --git a/state/txindex/null/null.go b/state/txindex/null/null.go -index f85de2e6..40c76be6 100644 ---- a/state/txindex/null/null.go -+++ b/state/txindex/null/null.go -@@ -13,6 +13,9 @@ var _ txindex.TxIndexer = (*TxIndex)(nil) - // TxIndex acts as a /dev/null. - type TxIndex struct{} - -+// Cache noop -+func (txi *TxIndex) Cache(result *types.TxResult) {} -+ - // Get on a TxIndex is disabled and panics when invoked. - func (txi *TxIndex) Get(hash []byte) (*types.TxResult, error) { - return nil, errors.New(`Indexing is disabled (set 'tx_index = "kv"' in config)`) diff --git a/patches/general/README.org b/patches/general/README.org deleted file mode 100644 index 9a4aaeb5..00000000 --- a/patches/general/README.org +++ /dev/null @@ -1,3 +0,0 @@ -* Patches -** cosmos -+ constructors.go: use cleveldb. diff --git a/patches/general/constructors b/patches/general/constructors deleted file mode 100644 index abece06a..00000000 --- a/patches/general/constructors +++ /dev/null @@ -1,41 +0,0 @@ -package server - -import ( - "encoding/json" - "io" - "os" - "path/filepath" - - abci "github.com/tendermint/tendermint/abci/types" - dbm "github.com/tendermint/tm-db" - "github.com/tendermint/tendermint/libs/log" - tmtypes "github.com/tendermint/tendermint/types" -) - -type ( - // AppCreator is a function that allows us to lazily initialize an - // application using various configurations. - AppCreator func(log.Logger, dbm.DB, io.Writer) abci.Application - - // AppExporter is a function that dumps all app state to - // JSON-serializable structure and returns the current validator set. - AppExporter func(log.Logger, dbm.DB, io.Writer, int64, bool, []string) (json.RawMessage, []tmtypes.GenesisValidator, error) -) - -func openDB(rootDir string) (dbm.DB, error) { - dataDir := filepath.Join(rootDir, "data") - db, err := dbm.NewCLevelDB("application", dataDir) - return db, err -} - -func openTraceWriter(traceWriterFile string) (w io.Writer, err error) { - if traceWriterFile != "" { - w, err = os.OpenFile( - traceWriterFile, - os.O_WRONLY|os.O_APPEND|os.O_CREATE, - 0666, - ) - return - } - return -} diff --git a/patches/general/cosmos-server-constructor.patch b/patches/general/cosmos-server-constructor.patch deleted file mode 100644 index 886ce265..00000000 --- a/patches/general/cosmos-server-constructor.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- ../../vendor/github.com/cosmos/cosmos-sdk/server/constructors.go 2019-02-27 14:38:01.534324194 -0800 -+++ ./constructors 2019-02-27 14:39:09.298777452 -0800 -@@ -24,7 +24,7 @@ - - func openDB(rootDir string) (dbm.DB, error) { - dataDir := filepath.Join(rootDir, "data") -- db, err := dbm.NewGoLevelDB("application", dataDir) -+ db, err := dbm.NewCLevelDB("application", dataDir) - return db, err - } - diff --git a/patches/general/gen_patch.sh b/patches/general/gen_patch.sh deleted file mode 100755 index d9e08ee0..00000000 --- a/patches/general/gen_patch.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -echo "info: MUST run dep ensure before this script" -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -diff -u $DIR/../../vendor/github.com/cosmos/cosmos-sdk/server/constructors.go $DIR/constructors > cosmos-server-constructor.patch -echo "patches generated." - diff --git a/scripts/bootstrap_ubuntu.sh b/scripts/bootstrap_ubuntu.sh index e7ec345a..459e3870 100755 --- a/scripts/bootstrap_ubuntu.sh +++ b/scripts/bootstrap_ubuntu.sh @@ -2,7 +2,7 @@ ### install golang -GOSOURCE=https://dl.google.com/go/go1.11.5.linux-amd64.tar.gz +GOSOURCE=https://dl.google.com/go/go1.12.10.linux-amd64.tar.gz GOTARGET=/usr/local GOPATH=\$HOME/go PROFILE=/home/ubuntu/.profile diff --git a/scripts/update_ubuntu.sh b/scripts/update_ubuntu.sh index 546cfb87..ff585565 100755 --- a/scripts/update_ubuntu.sh +++ b/scripts/update_ubuntu.sh @@ -2,7 +2,7 @@ ### update golang to latest. sudo rm -rf /usr/local/go -GOSOURCE=https://dl.google.com/go/go1.12.9.linux-amd64.tar.gz +GOSOURCE=https://dl.google.com/go/go1.12.10.linux-amd64.tar.gz GOTARGET=/usr/local GOPATH=\$HOME/go PROFILE=/home/ubuntu/.profile