[CHAIN] add debug msg that prints total tx count in main chain
@@ -251,9 +251,39 @@ func (cs *ChainService) addBlock(newBlock *types.Block, usedBstate *types.BlockS
// unnecessary chain execution & rollback.
cp.reorganize()
+ logger.Debug().Uint64("best", cs.cdb.getBestBlockNo()).Int("count", cs.CountTxsInChain()).
+ Msg("number of tx in chain")
+
return nil
}
+func (cs *ChainService) CountTxsInChain() int {
+ var txCount int
+
+ blk, err := cs.GetBestBlock()
+ if err != nil {
+ return -1
+ }
+
+ var no uint64
+ for {
+ no = blk.GetHeader().GetBlockNo()
+ if no == 0 {
+ break
+ }
+
+ txCount += len(blk.GetBody().GetTxs())
+
+ blk, err = cs.getBlock(blk.GetHeader().GetPrevBlockHash())
+ if err != nil {
+ txCount = -1
+ break
+ }
+ }
+
+ return txCount
+}
+
type txExecFn func(tx *types.Tx) error
type executor struct {
