diff --git a/cmd/arc/services/blocktx.go b/cmd/arc/services/blocktx.go index c3183d95e..568426e76 100644 --- a/cmd/arc/services/blocktx.go +++ b/cmd/arc/services/blocktx.go @@ -126,6 +126,7 @@ func StartBlockTx(logger *slog.Logger, arcConfig *config.ArcConfig) (func(), err blocktx.WithRegisterTxsInterval(btxConfig.RegisterTxsInterval), blocktx.WithMessageQueueClient(mqClient), blocktx.WithMaxBlockProcessingDuration(btxConfig.MaxBlockProcessingDuration), + blocktx.WithIncomingIsLongest(btxConfig.IncomingIsLongest), ) blockRequestCh := make(chan blocktx.BlockRequest, blockProcessingBuffer) diff --git a/internal/blocktx/processor.go b/internal/blocktx/processor.go index f463c5db9..0257b5b4a 100644 --- a/internal/blocktx/processor.go +++ b/internal/blocktx/processor.go @@ -71,6 +71,7 @@ type Processor struct { tracingAttributes []attribute.KeyValue stats *processorStats statCollectionInterval time.Duration + incomingIsLongest bool now func() time.Time maxBlockProcessingDuration time.Duration @@ -456,15 +457,17 @@ func (p *Processor) verifyAndInsertBlock(ctx context.Context, blockMsg *p2p.Bloc MerkleRoot: merkleRoot[:], Height: blockMsg.Height, Chainwork: calculateChainwork(blockMsg.Header.Bits).String(), - Status: blocktx_api.Status_LONGEST, // temporary fix (!), TODO: remove this when gaps are filling quickly again } - // TODO: uncomment when gaps are filling quickly again - // err = p.assignBlockStatus(ctx, incomingBlock, previousBlockHash) - // if err != nil { - // p.logger.Error("unable to assign block status", slog.String("hash", blockHash.String()), slog.Uint64("height", incomingBlock.Height), slog.String("err", err.Error())) - // return nil, err - // } + if p.incomingIsLongest { + incomingBlock.Status = blocktx_api.Status_LONGEST + } else { + err = p.assignBlockStatus(ctx, incomingBlock, previousBlockHash) + if err != nil { + p.logger.Error("unable to assign block status", slog.String("hash", blockHash.String()), slog.Uint64("height", incomingBlock.Height), slog.String("err", err.Error())) + return nil, err + } + } p.logger.Info("Inserting block", slog.String("hash", blockHash.String()), slog.Uint64("height", incomingBlock.Height), slog.String("status", incomingBlock.Status.String())) @@ -477,7 +480,6 @@ func (p *Processor) verifyAndInsertBlock(ctx context.Context, blockMsg *p2p.Bloc return incomingBlock, nil } -//lint:ignore U1000 Ignored until gaps are filling quickly again TODO: remove this ignore func (p *Processor) assignBlockStatus(ctx context.Context, block *blocktx_api.Block, prevBlockHash chainhash.Hash) (err error) { ctx, span := tracing.StartTracing(ctx, "assignBlockStatus", p.tracingEnabled, p.tracingAttributes...) defer func() { @@ -538,7 +540,6 @@ func (p *Processor) assignBlockStatus(ctx context.Context, block *blocktx_api.Bl return nil } -//lint:ignore U1000 Ignored until gaps are filling quickly again TODO: remove this ignore func (p *Processor) longestTipExists(ctx context.Context) (bool, error) { _, err := p.store.GetChainTip(ctx) if err != nil && !errors.Is(err, store.ErrBlockNotFound) { diff --git a/internal/blocktx/processor_opts.go b/internal/blocktx/processor_opts.go index 29b9291db..3cb5b9401 100644 --- a/internal/blocktx/processor_opts.go +++ b/internal/blocktx/processor_opts.go @@ -79,3 +79,9 @@ func WithMaxBlockProcessingDuration(d time.Duration) func(*Processor) { processor.maxBlockProcessingDuration = d } } + +func WithIncomingIsLongest(enabled bool) func(*Processor) { + return func(processor *Processor) { + processor.incomingIsLongest = enabled + } +}