mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-30 14:41:20 +00:00
simplify indexer service main loop
This commit is contained in:
parent
6f7333fd5f
commit
5e3a23df6d
@ -343,6 +343,7 @@ func NewNode(config *cfg.Config,
|
|||||||
}
|
}
|
||||||
|
|
||||||
indexerService := txindex.NewIndexerService(txIndexer, eventBus)
|
indexerService := txindex.NewIndexerService(txIndexer, eventBus)
|
||||||
|
indexerService.SetLogger(logger.With("module", "txindex"))
|
||||||
|
|
||||||
// run the profile server
|
// run the profile server
|
||||||
profileHost := config.ProfListenAddress
|
profileHost := config.ProfListenAddress
|
||||||
|
@ -41,32 +41,24 @@ func (is *IndexerService) OnStart() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
var numTxs, got int64
|
|
||||||
var batch *Batch
|
|
||||||
for {
|
for {
|
||||||
select {
|
e, ok := <-blockHeadersCh
|
||||||
case e, ok := <-blockHeadersCh:
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
numTxs = e.(types.EventDataNewBlockHeader).Header.NumTxs
|
header := e.(types.EventDataNewBlockHeader).Header
|
||||||
batch = NewBatch(numTxs)
|
batch := NewBatch(header.NumTxs)
|
||||||
case e, ok := <-txsCh:
|
for i := int64(0); i < header.NumTxs; i++ {
|
||||||
|
e, ok := <-txsCh
|
||||||
if !ok {
|
if !ok {
|
||||||
|
is.Logger.Error("Failed to index all transactions due to closed transactions channel", "height", header.Height, "numTxs", header.NumTxs, "numProcessed", i)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if batch == nil {
|
|
||||||
panic("Expected pubsub to send block header first, but got tx event")
|
|
||||||
}
|
|
||||||
txResult := e.(types.EventDataTx).TxResult
|
txResult := e.(types.EventDataTx).TxResult
|
||||||
batch.Add(&txResult)
|
batch.Add(&txResult)
|
||||||
got++
|
}
|
||||||
if numTxs == got {
|
|
||||||
is.idr.AddBatch(batch)
|
is.idr.AddBatch(batch)
|
||||||
batch = nil
|
is.Logger.Info("Indexed block", "height", header.Height)
|
||||||
got = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user