diff --git a/cmd/arc/services/blocktx.go b/cmd/arc/services/blocktx.go index cf6c44389..3202a703f 100644 --- a/cmd/arc/services/blocktx.go +++ b/cmd/arc/services/blocktx.go @@ -8,12 +8,13 @@ import ( "go.opentelemetry.io/otel/attribute" + "github.com/libsv/go-p2p" + "github.com/bitcoin-sv/arc/internal/grpc_opts" "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_core" "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_jetstream" "github.com/bitcoin-sv/arc/internal/message_queue/nats/nats_connection" "github.com/bitcoin-sv/arc/internal/tracing" - "github.com/libsv/go-p2p" "github.com/bitcoin-sv/arc/config" "github.com/bitcoin-sv/arc/internal/blocktx" @@ -127,6 +128,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/config/config.go b/config/config.go index 793bfe117..eb715c08b 100644 --- a/config/config.go +++ b/config/config.go @@ -128,6 +128,7 @@ type BlocktxConfig struct { MaxAllowedBlockHeightMismatch int `mapstructure:"maxAllowedBlockHeightMismatch"` MessageQueue *MessageQueueConfig `mapstructure:"mq"` P2pReadBufferSize int `mapstructure:"p2pReadBufferSize"` + IncomingIsLongest bool `mapstructure:"incomingIsLongest"` } type DbConfig struct { diff --git a/config/defaults.go b/config/defaults.go index 869d44492..e46783a04 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -129,6 +129,7 @@ func getBlocktxConfig() *BlocktxConfig { MaxBlockProcessingDuration: 5 * time.Minute, MessageQueue: &MessageQueueConfig{}, P2pReadBufferSize: 8 * 1024 * 1024, + IncomingIsLongest: false, } } diff --git a/config/example_config.yaml b/config/example_config.yaml index 6f6f20c6f..69cf1415d 100644 --- a/config/example_config.yaml +++ b/config/example_config.yaml @@ -106,6 +106,7 @@ blocktx: registerTxsInterval: 10s # time interval to read from the channel registered transactions maxBlockProcessingDuration: 5m # maximum time a blocktx can spend on processing a block before unlocking it to be requested again monitorPeers: false # if enabled, peers which do not receive alive signal from nodes will be restarted + incomingIsLongest: false # whether each new block received is considered to be from the longest blockchain. If there are a lot of block gaps in blocktx database it is advisable to set this to true fillGaps: enabled: true interval: 15m # time interval to check and fill gaps in processed blocks diff --git a/internal/blocktx/processor.go b/internal/blocktx/processor.go index 701da61d0..c4da1bfe1 100644 --- a/internal/blocktx/processor.go +++ b/internal/blocktx/processor.go @@ -72,7 +72,7 @@ type Processor struct { processGuardsMap sync.Map stats *processorStats statCollectionInterval time.Duration - hasGaps bool + incomingIsLongest bool now func() time.Time maxBlockProcessingDuration time.Duration @@ -551,7 +551,7 @@ func (p *Processor) verifyAndInsertBlock(ctx context.Context, blockMsg *p2p.Bloc Chainwork: calculateChainwork(blockMsg.Header.Bits).String(), } - if p.hasGaps { + if p.incomingIsLongest { incomingBlock.Status = blocktx_api.Status_LONGEST } else { err = p.assignBlockStatus(ctx, incomingBlock, previousBlockHash) 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 + } +}