Repository: nervosnetwork/ckb (language: rust)

Issue:
ckb-miner cannot work properly
## Bug Report

After sending 1 million CKB transactions, start the ckb-miner program. However, after packaging 1,500 transactions in the first block, ckb-miner only continues to package cellbase transactions. There are still 1 million transactions waiting to be included in the chain in the transaction pool.
#### ckb-miner.toml
```
[miner.client]
rpc_url = "http://127.0.0.1:8114/"
block_on_submit = true

# block template polling interval in milliseconds
poll_interval = 100

# enable listen notify mode
#listen = "127.0.0.1:8888"

[[miner.workers]]
worker_type = "Dummy"
delay_type = "Constant"
value = 1000
```
After modifying the configuration, ckb-miner is able to package 1,500 transactions every 4 blocks.
####  ckb-miner.toml
```
[miner.client]
rpc_url = "http://127.0.0.1:8114/"
block_on_submit = true

# block template polling interval in milliseconds
poll_interval = 1000

# enable listen notify mode
# listen = "127.0.0.1:8888"

[[miner.workers]]
worker_type = "Dummy"
delay_type = "Constant"
value = 5000
```

### Environment

- **CKB version**: ckb 0.112.0-pre (a645ef2 2023-06-20)
- **Chain**: dev
- **Operating system**: Ubuntu 20.04
- **Arch**: x64 
- **Installation**: Built from source

### Additional context/Screenshots




Discussion / hints:
It seems that: `tx_pool_controller.load_persisted_data` take a long time:
https://github.com/nervosnetwork/ckb/blob/6d00f61b765188679678a56c2eddaa48a5b3ba04/tx-pool/src/service.rs#L621-L624
then `tx_pool_controller.started` will be `false` until `tx_pool_controller.load_persisted_data` finish.

Then, when `ChainService` get a new block, since `tx_pool_controller.started` is `false`, `tx_pool_controller.update_tx_pool_for_reorg` won't be executed:
https://github.com/nervosnetwork/ckb/blob/6d00f61b765188679678a56c2eddaa48a5b3ba04/chain/src/chain.rs#L511-L520
 and `template.current.work_id` won't be updated:
https://github.com/nervosnetwork/ckb/blob/6d00f61b765188679678a56c2eddaa48a5b3ba04/tx-pool/src/service.rs#L590-L611

Then, miner won't notify new work because `work_id` is not updated:
https://github.com/nervosnetwork/ckb/blob/6d00f61b765188679678a56c2eddaa48a5b3ba04/miner/src/client.rs#L266-L284
I'm considering to remove the `tx_pool_controller.service_started()` condition in `ChainService`:
https://github.com/nervosnetwork/ckb/blob/6d00f61b765188679678a56c2eddaa48a5b3ba04/chain/src/chain.rs#L511-L511


@chenyukang @zhangsoledad 

Seems `set_service_started` was not being invoked.
This seems the root reason, if a new block is inserted, and we don't call `update_tx_pool_for_reorg`, then even `work_id` is updated, and miner get new `work_id`, the hash here is legacy, and won't submit new block.

https://github.com/nervosnetwork/ckb/blob/5e67845bb337166615bbb638d36e08e2a66742c3/miner/src/miner.rs#L115

Fix patch:
diff --git a/tx-pool/src/service.rs b/tx-pool/src/service.rs
index b11564ea11..5dc54018b4 100644
--- a/tx-pool/src/service.rs
+++ b/tx-pool/src/service.rs
@@ -618,10 +618,10 @@ impl TxPoolServiceBuilder {
                 }
             }
         });
+        self.started.store(true, Ordering::Relaxed);
         if let Err(err) = self.tx_pool_controller.load_persisted_data(txs) {
             error!("Failed to import persisted txs, cause: {}", err);
         }
-        self.started.store(true, Ordering::Relaxed);
     }
 }
 


Test patch: