Skip to content

Commit

Permalink
refactor(ARCO-312): Implement setting
Browse files Browse the repository at this point in the history
  • Loading branch information
boecklim committed Jan 15, 2025
1 parent 2072131 commit 78fc981
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions cmd/arc/services/blocktx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions internal/blocktx/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Processor struct {
tracingAttributes []attribute.KeyValue
stats *processorStats
statCollectionInterval time.Duration
incomingIsLongest bool

now func() time.Time
maxBlockProcessingDuration time.Duration
Expand Down Expand Up @@ -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()))

Expand All @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions internal/blocktx/processor_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 78fc981

Please sign in to comment.