Commit 844f9c77 authored by vipwzw's avatar vipwzw Committed by 33cn

fix ticket close bug

parent 020faa00
...@@ -485,6 +485,9 @@ func (client *Client) searchTargetTicket(parent, block *types.Block) (*ty.Ticket ...@@ -485,6 +485,9 @@ func (client *Client) searchTargetTicket(parent, block *types.Block) (*ty.Ticket
client.ticketmu.Lock() client.ticketmu.Lock()
defer client.ticketmu.Unlock() defer client.ticketmu.Unlock()
for ticketID, ticket := range client.ticketsMap { for ticketID, ticket := range client.ticketsMap {
if client.IsClosed() {
return nil, nil, nil, nil, "", nil
}
if ticket == nil { if ticket == nil {
tlog.Warn("Client searchTargetTicket ticket is nil", "ticketID", ticketID) tlog.Warn("Client searchTargetTicket ticket is nil", "ticketID", ticketID)
continue continue
...@@ -668,6 +671,10 @@ func (client *Client) updateBlock(block *types.Block, txHashList [][]byte) (*typ ...@@ -668,6 +671,10 @@ func (client *Client) updateBlock(block *types.Block, txHashList [][]byte) (*typ
// CreateBlock ticket create block func // CreateBlock ticket create block func
func (client *Client) CreateBlock() { func (client *Client) CreateBlock() {
for { for {
if client.IsClosed() {
tlog.Info("create block stop")
break
}
if !client.IsMining() || !(client.IsCaughtUp() || client.Cfg.ForceMining) { if !client.IsMining() || !(client.IsCaughtUp() || client.Cfg.ForceMining) {
tlog.Debug("createblock.ismining is disable or client is caughtup is false") tlog.Debug("createblock.ismining is disable or client is caughtup is false")
time.Sleep(time.Second) time.Sleep(time.Second)
......
...@@ -45,6 +45,7 @@ type BaseClient struct { ...@@ -45,6 +45,7 @@ type BaseClient struct {
client queue.Client client queue.Client
api client.QueueProtocolAPI api client.QueueProtocolAPI
minerStart int32 minerStart int32
isclosed int32
once sync.Once once sync.Once
Cfg *types.Consensus Cfg *types.Consensus
currentBlock *types.Block currentBlock *types.Block
...@@ -146,10 +147,16 @@ func (bc *BaseClient) InitBlock() { ...@@ -146,10 +147,16 @@ func (bc *BaseClient) InitBlock() {
//Close 关闭 //Close 关闭
func (bc *BaseClient) Close() { func (bc *BaseClient) Close() {
atomic.StoreInt32(&bc.minerStart, 0) atomic.StoreInt32(&bc.minerStart, 0)
atomic.StoreInt32(&bc.isclosed, 1)
bc.client.Close() bc.client.Close()
log.Info("consensus base closed") log.Info("consensus base closed")
} }
//IsClosed 是否已经关闭
func (bc *BaseClient) IsClosed() bool {
return atomic.LoadInt32(&bc.isclosed) == 1
}
//CheckTxDup 为了不引起交易检查时候产生的无序 //CheckTxDup 为了不引起交易检查时候产生的无序
func (bc *BaseClient) CheckTxDup(txs []*types.Transaction) (transactions []*types.Transaction) { func (bc *BaseClient) CheckTxDup(txs []*types.Transaction) (transactions []*types.Transaction) {
cacheTxs := types.TxsToCache(txs) cacheTxs := types.TxsToCache(txs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment