Improve API requests when blockbook in sync with backend
parent
70249530ff
commit
5ef22e86dc
|
@ -176,7 +176,11 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
|
||||||
}
|
}
|
||||||
// mempool transactions are not in TxAddresses but confirmed should be there, log a problem
|
// mempool transactions are not in TxAddresses but confirmed should be there, log a problem
|
||||||
if bchainTx.Confirmations > 0 {
|
if bchainTx.Confirmations > 0 {
|
||||||
glog.Warning("DB inconsistency: tx ", bchainVin.Txid, ": not found in txAddresses")
|
inSync, _, _ := w.is.GetSyncState()
|
||||||
|
// backend can report tx as confirmed, however blockbook is still syncing (!inSync), in this case do not log a problem
|
||||||
|
if bchainTx.Confirmations != 1 || inSync {
|
||||||
|
glog.Warning("DB inconsistency: tx ", bchainVin.Txid, ": not found in txAddresses")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(otx.Vout) > int(vin.Vout) {
|
if len(otx.Vout) > int(vin.Vout) {
|
||||||
vout := &otx.Vout[vin.Vout]
|
vout := &otx.Vout[vin.Vout]
|
||||||
|
@ -610,21 +614,25 @@ func (w *Worker) txFromTxid(txid string, bestheight uint32, option AccountDetail
|
||||||
}
|
}
|
||||||
if ta == nil {
|
if ta == nil {
|
||||||
glog.Warning("DB inconsistency: tx ", txid, ": not found in txAddresses")
|
glog.Warning("DB inconsistency: tx ", txid, ": not found in txAddresses")
|
||||||
// as fallback, provide empty TxAddresses to return at least something
|
// as fallback, get tx from backend
|
||||||
ta = &db.TxAddresses{}
|
tx, err = w.GetTransaction(txid, false, true)
|
||||||
}
|
|
||||||
if blockInfo == nil {
|
|
||||||
blockInfo, err = w.db.GetBlockInfo(ta.Height)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Annotatef(err, "GetBlockInfo %v", ta.Height)
|
return nil, errors.Annotatef(err, "GetTransaction %v", txid)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if blockInfo == nil {
|
if blockInfo == nil {
|
||||||
glog.Warning("DB inconsistency: block height ", ta.Height, ": not found in db")
|
blockInfo, err = w.db.GetBlockInfo(ta.Height)
|
||||||
// provide empty BlockInfo to return the rest of tx data
|
if err != nil {
|
||||||
blockInfo = &db.BlockInfo{}
|
return nil, errors.Annotatef(err, "GetBlockInfo %v", ta.Height)
|
||||||
|
}
|
||||||
|
if blockInfo == nil {
|
||||||
|
glog.Warning("DB inconsistency: block height ", ta.Height, ": not found in db")
|
||||||
|
// provide empty BlockInfo to return the rest of tx data
|
||||||
|
blockInfo = &db.BlockInfo{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
tx = w.txFromTxAddress(txid, ta, blockInfo, bestheight)
|
||||||
}
|
}
|
||||||
tx = w.txFromTxAddress(txid, ta, blockInfo, bestheight)
|
|
||||||
} else {
|
} else {
|
||||||
tx, err = w.GetTransaction(txid, false, true)
|
tx, err = w.GetTransaction(txid, false, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -787,7 +795,19 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option Acco
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Worker) waitForBackendSync() {
|
||||||
|
// wait a short time if blockbook is synchronizing with backend
|
||||||
|
inSync, _, _ := w.is.GetSyncState()
|
||||||
|
count := 30
|
||||||
|
for !inSync && count > 0 {
|
||||||
|
time.Sleep(time.Millisecond * 100)
|
||||||
|
count--
|
||||||
|
inSync, _, _ = w.is.GetSyncState()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Worker) getAddrDescUtxo(addrDesc bchain.AddressDescriptor, ba *db.AddrBalance, onlyConfirmed bool, onlyMempool bool) (Utxos, error) {
|
func (w *Worker) getAddrDescUtxo(addrDesc bchain.AddressDescriptor, ba *db.AddrBalance, onlyConfirmed bool, onlyMempool bool) (Utxos, error) {
|
||||||
|
w.waitForBackendSync()
|
||||||
var err error
|
var err error
|
||||||
r := make(Utxos, 0, 8)
|
r := make(Utxos, 0, 8)
|
||||||
spentInMempool := make(map[string]struct{})
|
spentInMempool := make(map[string]struct{})
|
||||||
|
|
|
@ -51,9 +51,11 @@ func setupRocksDB(t *testing.T, parser bchain.BlockChainParser) (*db.RocksDB, *c
|
||||||
if err := d.ConnectBlock(dbtestdata.GetTestBitcoinTypeBlock1(parser)); err != nil {
|
if err := d.ConnectBlock(dbtestdata.GetTestBitcoinTypeBlock1(parser)); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := d.ConnectBlock(dbtestdata.GetTestBitcoinTypeBlock2(parser)); err != nil {
|
block2 := dbtestdata.GetTestBitcoinTypeBlock2(parser)
|
||||||
|
if err := d.ConnectBlock(block2); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
is.FinishedSync(block2.Height)
|
||||||
return d, is, tmp
|
return d, is, tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +75,6 @@ func setupPublicHTTPServer(t *testing.T) (*PublicServer, string) {
|
||||||
is.Coin = "Fakecoin"
|
is.Coin = "Fakecoin"
|
||||||
is.CoinLabel = "Fake Coin"
|
is.CoinLabel = "Fake Coin"
|
||||||
is.CoinShortcut = "FAKE"
|
is.CoinShortcut = "FAKE"
|
||||||
is.BestHeight = 225494
|
|
||||||
|
|
||||||
metrics, err := common.GetMetrics("Fakecoin")
|
metrics, err := common.GetMetrics("Fakecoin")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue