From 56c1c85b1ad1b7a2b2831b52dc1bf8d5f2c60c6e Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Mon, 14 May 2018 15:46:39 +0200 Subject: [PATCH 1/3] Update todo list --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2ff7a57b..5cbcee98 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,7 @@ The data are separated to different column families: ## Todo +- add db data version (column data version) checking to db to avoid data corruption - update used paths and users according to specification by system admin - improve txcache (time of storage, number/size of cached txs, purge cache) - collect blockbook stats (number of items in indexes, ) From 993fe001e4989d4b61049e50fbb27ca740ed62af Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Mon, 14 May 2018 15:47:47 +0200 Subject: [PATCH 2/3] Extend range of valid estimateSmartFee in test of logged socket.io --- server/socketio_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/socketio_test.go b/server/socketio_test.go index 21b38465..c7a6ce53 100644 --- a/server/socketio_test.go +++ b/server/socketio_test.go @@ -201,7 +201,7 @@ func verifyEstimateSmartFee(t *testing.T, id int, lrs *logRequestResponse, bbRes } // it is not possible to compare fee directly, it changes over time, // verify that the BB fee is in a reasonable range - if bbResponse.Result > 0 && bbResponse.Result < 1e-3 { + if bbResponse.Result > 0 && bbResponse.Result < .1 { stat.SuccessCount++ } else { t.Log("estimateSmartFee", id, "mismatch bb:", bbResponse.Result, From 7cb8c8d3f0c7e88828e466c7836fd6ee34fc9641 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Mon, 14 May 2018 15:49:08 +0200 Subject: [PATCH 3/3] Add option to disable txcache --- blockbook.go | 4 +++- db/txcache.go | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/blockbook.go b/blockbook.go index 1aedb3c0..1de5c3cc 100644 --- a/blockbook.go +++ b/blockbook.go @@ -63,6 +63,8 @@ var ( explorerURL = flag.String("explorer", "", "address of blockchain explorer") coin = flag.String("coin", "btc", "coin name") + + noTxCache = flag.Bool("notxcache", false, "disable tx cache") ) var ( @@ -156,7 +158,7 @@ func main() { return } - if txCache, err = db.NewTxCache(index, chain, metrics); err != nil { + if txCache, err = db.NewTxCache(index, chain, metrics, !*noTxCache); err != nil { glog.Error("txCache ", err) return } diff --git a/db/txcache.go b/db/txcache.go index 3b339352..8c30b42a 100644 --- a/db/txcache.go +++ b/db/txcache.go @@ -12,29 +12,39 @@ type TxCache struct { db *RocksDB chain bchain.BlockChain metrics *common.Metrics + enabled bool } // NewTxCache creates new TxCache interface and returns its handle -func NewTxCache(db *RocksDB, chain bchain.BlockChain, metrics *common.Metrics) (*TxCache, error) { +func NewTxCache(db *RocksDB, chain bchain.BlockChain, metrics *common.Metrics, enabled bool) (*TxCache, error) { + if !enabled { + glog.Info("txcache: disabled") + } return &TxCache{ db: db, chain: chain, metrics: metrics, + enabled: enabled, }, nil } // GetTransaction returns transaction either from RocksDB or if not present from blockchain // it the transaction is confirmed, it is stored in the RocksDB func (c *TxCache) GetTransaction(txid string, bestheight uint32) (*bchain.Tx, uint32, error) { - tx, h, err := c.db.GetTx(txid) - if err != nil { - return nil, 0, err - } - if tx != nil { - // number of confirmations is not stored in cache, they change all the time - tx.Confirmations = bestheight - h + 1 - c.metrics.TxCacheEfficiency.With(common.Labels{"status": "hit"}).Inc() - return tx, h, nil + var tx *bchain.Tx + var h uint32 + var err error + if c.enabled { + tx, h, err = c.db.GetTx(txid) + if err != nil { + return nil, 0, err + } + if tx != nil { + // number of confirmations is not stored in cache, they change all the time + tx.Confirmations = bestheight - h + 1 + c.metrics.TxCacheEfficiency.With(common.Labels{"status": "hit"}).Inc() + return tx, h, nil + } } tx, err = c.chain.GetTransaction(txid) if err != nil { @@ -45,10 +55,12 @@ func (c *TxCache) GetTransaction(txid string, bestheight uint32) (*bchain.Tx, ui if tx.Confirmations > 0 { // the transaction in the currently best block has 1 confirmation h = bestheight - tx.Confirmations + 1 - err = c.db.PutTx(tx, h, tx.Blocktime) - // do not return caching error, only log it - if err != nil { - glog.Error("PutTx error ", err) + if c.enabled { + err = c.db.PutTx(tx, h, tx.Blocktime) + // do not return caching error, only log it + if err != nil { + glog.Error("PutTx error ", err) + } } } else { h = 0