From 31377189163b0d5129d9136623c4e62bb2fac674 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Wed, 23 Oct 2024 15:00:14 +0700 Subject: [PATCH] handle error from `semaphore.Aquire` (#12417) ``` panic: semaphore: released more than held goroutine 10342 [running]: golang.org/x/sync/semaphore.(*Weighted).Release(0xc002e8cdc0, 0x1114288c0?) golang.org/x/sync@v0.8.0/semaphore/semaphore.go:127 +0xb8 github.com/erigontech/erigon/turbo/execution/eth1.(*EthereumExecutionModule).Start(0xc003766780, {0x10fef16f8, 0xc001901d60}) github.com/erigontech/erigon/turbo/execution/eth1/ethereum_execution.go:349 +0x167 created by github.com/erigontech/erigon/eth.(*Ethereum).Start in goroutine 1 github.com/erigontech/erigon/eth/backend.go:1516 +0xddf exit status 2 ``` --- turbo/execution/eth1/ethereum_execution.go | 9 +++++++-- turbo/execution/eth1/inserters.go | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/turbo/execution/eth1/ethereum_execution.go b/turbo/execution/eth1/ethereum_execution.go index fd4317610b4..a8159784669 100644 --- a/turbo/execution/eth1/ethereum_execution.go +++ b/turbo/execution/eth1/ethereum_execution.go @@ -135,7 +135,7 @@ func (e *EthereumExecutionModule) getHeader(ctx context.Context, tx kv.Tx, block return e.blockReader.Header(ctx, tx, blockHash, blockNumber) } -func (e *EthereumExecutionModule) getTD(ctx context.Context, tx kv.Tx, blockHash libcommon.Hash, blockNumber uint64) (*big.Int, error) { +func (e *EthereumExecutionModule) getTD(_ context.Context, tx kv.Tx, blockHash libcommon.Hash, blockNumber uint64) (*big.Int, error) { return rawdb.ReadTd(tx, blockHash, blockNumber) } @@ -338,7 +338,12 @@ func (e *EthereumExecutionModule) purgeBadChain(ctx context.Context, tx kv.RwTx, } func (e *EthereumExecutionModule) Start(ctx context.Context) { - e.semaphore.Acquire(ctx, 1) + if err := e.semaphore.Acquire(ctx, 1); err != nil { + if !errors.Is(err, context.Canceled) { + e.logger.Error("Could not start execution service", "err", err) + } + return + } defer e.semaphore.Release(1) if err := stages.ProcessFrozenBlocks(ctx, e.db, e.blockReader, e.executionPipeline, nil); err != nil { diff --git a/turbo/execution/eth1/inserters.go b/turbo/execution/eth1/inserters.go index c2900a9e475..b0310de4314 100644 --- a/turbo/execution/eth1/inserters.go +++ b/turbo/execution/eth1/inserters.go @@ -31,7 +31,7 @@ import ( "github.com/erigontech/erigon/turbo/execution/eth1/eth1_utils" ) -func (s *EthereumExecutionModule) validatePayloadBlobs(expectedBlobHashes []libcommon.Hash, transactions []types.Transaction, blobGasUsed uint64) error { +func (e *EthereumExecutionModule) validatePayloadBlobs(expectedBlobHashes []libcommon.Hash, transactions []types.Transaction, blobGasUsed uint64) error { if expectedBlobHashes == nil { return &rpc.InvalidParamsError{Message: "nil blob hashes array"} } @@ -39,11 +39,11 @@ func (s *EthereumExecutionModule) validatePayloadBlobs(expectedBlobHashes []libc for _, txn := range transactions { actualBlobHashes = append(actualBlobHashes, txn.GetBlobHashes()...) } - if len(actualBlobHashes) > int(s.config.GetMaxBlobsPerBlock()) || blobGasUsed > s.config.GetMaxBlobGasPerBlock() { + if len(actualBlobHashes) > int(e.config.GetMaxBlobsPerBlock()) || blobGasUsed > e.config.GetMaxBlobGasPerBlock() { return nil } if !reflect.DeepEqual(actualBlobHashes, expectedBlobHashes) { - s.logger.Warn("[NewPayload] mismatch in blob hashes", + e.logger.Warn("[NewPayload] mismatch in blob hashes", "expectedBlobHashes", expectedBlobHashes, "actualBlobHashes", actualBlobHashes) return nil }