From 7144b3f4cba1d4641a0c91b951ca1f90e763eb39 Mon Sep 17 00:00:00 2001 From: qinglin89 <316032931@qq.com> Date: Fri, 15 Apr 2022 15:09:06 +0800 Subject: [PATCH 1/3] fix:defer bloomprocessor close --- core/receipt_processor.go | 3 +++ core/state_processor.go | 1 + 2 files changed, 4 insertions(+) diff --git a/core/receipt_processor.go b/core/receipt_processor.go index 3b4c2579cc..07d5b2925a 100644 --- a/core/receipt_processor.go +++ b/core/receipt_processor.go @@ -60,6 +60,9 @@ func (p *AsyncReceiptBloomGenerator) Apply(receipt *types.Receipt) { } func (p *AsyncReceiptBloomGenerator) Close() { + if _, ok := <-p.receipts; !ok { + return + } close(p.receipts) p.isClosed = true p.wg.Wait() diff --git a/core/state_processor.go b/core/state_processor.go index 8e9422a8e8..ba3f5c6aba 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -403,6 +403,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg // initilise bloom processors bloomProcessors := NewAsyncReceiptBloomGenerator(txNum) + defer bloomProcessors.Close() statedb.MarkFullProcessed() // usually do have two tx, one for validator set contract, another for system reward contract. From d74b1da75e519dcc4aac4eaeb79df99038988d3d Mon Sep 17 00:00:00 2001 From: qinglin89 <316032931@qq.com> Date: Fri, 15 Apr 2022 15:38:28 +0800 Subject: [PATCH 2/3] fix: fix deadlock in Close --- core/receipt_processor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/receipt_processor.go b/core/receipt_processor.go index 07d5b2925a..d27a0139d5 100644 --- a/core/receipt_processor.go +++ b/core/receipt_processor.go @@ -60,7 +60,7 @@ func (p *AsyncReceiptBloomGenerator) Apply(receipt *types.Receipt) { } func (p *AsyncReceiptBloomGenerator) Close() { - if _, ok := <-p.receipts; !ok { + if p.isClosed { return } close(p.receipts) From 8b5a76d042fb816b35e3ff432bd049ac549df468 Mon Sep 17 00:00:00 2001 From: qinglin89 <316032931@qq.com> Date: Sun, 17 Apr 2022 23:33:21 +0800 Subject: [PATCH 3/3] perf:rm defer bloomprocessors Close and manual close before return --- core/receipt_processor.go | 3 --- core/state_processor.go | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/core/receipt_processor.go b/core/receipt_processor.go index d27a0139d5..3b4c2579cc 100644 --- a/core/receipt_processor.go +++ b/core/receipt_processor.go @@ -60,9 +60,6 @@ func (p *AsyncReceiptBloomGenerator) Apply(receipt *types.Receipt) { } func (p *AsyncReceiptBloomGenerator) Close() { - if p.isClosed { - return - } close(p.receipts) p.isClosed = true p.wg.Wait() diff --git a/core/state_processor.go b/core/state_processor.go index ba3f5c6aba..cdaaf1e643 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -403,7 +403,6 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg // initilise bloom processors bloomProcessors := NewAsyncReceiptBloomGenerator(txNum) - defer bloomProcessors.Close() statedb.MarkFullProcessed() // usually do have two tx, one for validator set contract, another for system reward contract. @@ -411,6 +410,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg for i, tx := range block.Transactions() { if isPoSA { if isSystemTx, err := posa.IsSystemTransaction(tx, block.Header()); err != nil { + bloomProcessors.Close() return statedb, nil, nil, 0, err } else if isSystemTx { systemTxs = append(systemTxs, tx) @@ -420,11 +420,13 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg msg, err := tx.AsMessage(signer) if err != nil { + bloomProcessors.Close() return statedb, nil, nil, 0, err } statedb.Prepare(tx.Hash(), block.Hash(), i) receipt, err := applyTransaction(msg, p.config, p.bc, nil, gp, statedb, header, tx, usedGas, vmenv, bloomProcessors) if err != nil { + bloomProcessors.Close() return statedb, nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err) }