Skip to content

Commit 8cd5ab3

Browse files
Add flag to skip protocol version check in Horizon (stellar#5834)
1 parent 2871a7c commit 8cd5ab3

File tree

6 files changed

+93
-3
lines changed

6 files changed

+93
-3
lines changed

services/horizon/internal/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ type Config struct {
104104
// IngestEnableExtendedLogLedgerStats enables extended ledger stats in
105105
// logging.
106106
IngestEnableExtendedLogLedgerStats bool
107+
// IngestSkipProtocolVersionCheck skips protocol version verification during
108+
// ingestion.
109+
IngestSkipProtocolVersionCheck bool
107110
// ApplyMigrations will apply pending migrations to the horizon database
108111
// before starting the horizon service
109112
ApplyMigrations bool

services/horizon/internal/flags.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,14 @@ func Flags() (*Config, support.ConfigOptions) {
729729
Usage: "enables extended ledger stats in the log (ledger entry changes and operations stats)",
730730
UsedInCommands: IngestionCommands,
731731
},
732+
&support.ConfigOption{
733+
Name: "ingest-skip-protocol-version-check",
734+
ConfigKey: &config.IngestSkipProtocolVersionCheck,
735+
OptType: types.Bool,
736+
FlagDefault: false,
737+
Usage: "skip protocol version verification during ingestion",
738+
UsedInCommands: IngestionCommands,
739+
},
732740
&support.ConfigOption{
733741
Name: "apply-migrations",
734742
ConfigKey: &config.ApplyMigrations,

services/horizon/internal/ingest/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ type Config struct {
134134
DisableStateVerification bool
135135
ReapLookupTables bool
136136
EnableExtendedLogLedgerStats bool
137+
SkipProtocolVersionCheck bool
137138

138139
MaxReingestRetries int
139140
ReingestRetryBackoffSeconds int

services/horizon/internal/ingest/processor_runner.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ func (s *ProcessorRunner) buildFilteredOutProcessor() *groupTransactionProcessor
184184
// checkIfProtocolVersionSupported checks if this Horizon version supports the
185185
// protocol version of a ledger with the given sequence number.
186186
func (s *ProcessorRunner) checkIfProtocolVersionSupported(ledgerProtocolVersion uint32) error {
187+
if s.config.SkipProtocolVersionCheck {
188+
return nil
189+
}
187190
if ledgerProtocolVersion > MaxSupportedProtocolVersion {
188191
return fmt.Errorf(
189192
"This Horizon version does not support protocol version %d. "+

services/horizon/internal/ingest/processor_runner_test.go

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ func TestProcessorRunnerRunAllProcessorsOnLedgerProtocolVersionNotSupported(t *t
401401
maxBatchSize := 100000
402402

403403
config := Config{
404-
NetworkPassphrase: network.PublicNetworkPassphrase,
404+
NetworkPassphrase: network.PublicNetworkPassphrase,
405+
SkipProtocolVersionCheck: false,
405406
}
406407

407408
q := &mockDBQ{}
@@ -411,7 +412,7 @@ func TestProcessorRunnerRunAllProcessorsOnLedgerProtocolVersionNotSupported(t *t
411412
V0: &xdr.LedgerCloseMetaV0{
412413
LedgerHeader: xdr.LedgerHeaderHistoryEntry{
413414
Header: xdr.LedgerHeader{
414-
LedgerVersion: 200,
415+
LedgerVersion: xdr.Uint32(MaxSupportedProtocolVersion + 1),
415416
},
416417
},
417418
},
@@ -444,12 +445,85 @@ func TestProcessorRunnerRunAllProcessorsOnLedgerProtocolVersionNotSupported(t *t
444445
_, err := runner.RunAllProcessorsOnLedger(ledger)
445446
assert.EqualError(t, err,
446447
fmt.Sprintf(
447-
"Error while checking for supported protocol version: This Horizon version does not support protocol version 200. The latest supported protocol version is %d. Please upgrade to the latest Horizon version.",
448+
"Error while checking for supported protocol version: This Horizon version does not support protocol version %d. The latest supported protocol version is %d. Please upgrade to the latest Horizon version.",
449+
MaxSupportedProtocolVersion+1,
448450
MaxSupportedProtocolVersion,
449451
),
450452
)
451453
}
452454

455+
func TestProcessorRunnerRunAllProcessorsOnLedgerProtocolVersionNotSupportedButAllowed(t *testing.T) {
456+
ctx := context.Background()
457+
458+
config := Config{
459+
NetworkPassphrase: network.PublicNetworkPassphrase,
460+
SkipProtocolVersionCheck: true,
461+
}
462+
463+
mockSession := &db.MockSession{}
464+
q := &mockDBQ{}
465+
defer mock.AssertExpectationsForObjects(t, q)
466+
467+
ledger := xdr.LedgerCloseMeta{
468+
V0: &xdr.LedgerCloseMetaV0{
469+
LedgerHeader: xdr.LedgerHeaderHistoryEntry{
470+
Header: xdr.LedgerHeader{
471+
LedgerVersion: xdr.Uint32(MaxSupportedProtocolVersion + 1),
472+
BucketListHash: xdr.Hash([32]byte{0, 1, 2}),
473+
LedgerSeq: 23,
474+
},
475+
},
476+
},
477+
}
478+
479+
// Batches
480+
defer mock.AssertExpectationsForObjects(t, mockTxProcessorBatchBuilders(q, mockSession, ctx)...)
481+
defer mock.AssertExpectationsForObjects(t, mockChangeProcessorBatchBuilders(q, ctx, true)...)
482+
defer mock.AssertExpectationsForObjects(t, mockFilteredOutProcessorsForNoRules(q, mockSession, ctx)...)
483+
484+
mockBatchInsertBuilder := &history.MockLedgersBatchInsertBuilder{}
485+
q.MockQLedgers.On("NewLedgerBatchInsertBuilder").Return(mockBatchInsertBuilder)
486+
mockBatchInsertBuilder.On(
487+
"Add",
488+
ledger.V0.LedgerHeader, 0, 0, 0, 0, CurrentVersion).Return(nil).Once()
489+
mockBatchInsertBuilder.On(
490+
"Exec",
491+
ctx,
492+
mockSession,
493+
).Return(nil).Once()
494+
495+
defer mock.AssertExpectationsForObjects(t, mockBatchInsertBuilder)
496+
497+
q.MockQAssetStats.On("InsertAssetContracts", ctx, []history.AssetContract(nil)).
498+
Return(nil).Once()
499+
q.MockQAssetStats.On("UpdateAssetContractExpirations", ctx, []xdr.Hash{}, []uint32{}).
500+
Return(nil).Once()
501+
q.MockQAssetStats.On("DeleteAssetContractsExpiringAt", ctx, uint32(22)).
502+
Return(int64(0), nil).Once()
503+
504+
q.MockQAssetStats.On("RemoveContractAssetBalances", ctx, []xdr.Hash(nil)).
505+
Return(nil).Once()
506+
q.MockQAssetStats.On("UpdateContractAssetBalanceAmounts", ctx, []xdr.Hash{}, []string{}).
507+
Return(nil).Once()
508+
q.MockQAssetStats.On("InsertContractAssetBalances", ctx, []history.ContractAssetBalance(nil)).
509+
Return(nil).Once()
510+
q.MockQAssetStats.On("UpdateContractAssetBalanceExpirations", ctx, []xdr.Hash{}, []uint32{}).
511+
Return(nil).Once()
512+
q.MockQAssetStats.On("DeleteContractAssetBalancesExpiringAt", ctx, uint32(22)).
513+
Return([]history.ContractAssetBalance{}, nil).Once()
514+
515+
runner := ProcessorRunner{
516+
ctx: ctx,
517+
config: config,
518+
historyQ: q,
519+
session: mockSession,
520+
filters: &MockFilters{},
521+
}
522+
523+
_, err := runner.RunAllProcessorsOnLedger(ledger)
524+
assert.NoError(t, err)
525+
}
526+
453527
func mockTxProcessorBatchBuilders(q *mockDBQ, mockSession *db.MockSession, ctx context.Context) []interface{} {
454528
// no mocking of builder Add methods needed, the fake ledgers used in tests don't have any operations
455529
// that would trigger the respective processors to invoke Add, each test locally decides to use

services/horizon/internal/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func initIngester(app *App) {
100100
StateVerificationTimeout: app.config.IngestStateVerificationTimeout,
101101
ReapLookupTables: app.config.ReapLookupTables && app.config.HistoryRetentionCount > 0,
102102
EnableExtendedLogLedgerStats: app.config.IngestEnableExtendedLogLedgerStats,
103+
SkipProtocolVersionCheck: app.config.IngestSkipProtocolVersionCheck,
103104
RoundingSlippageFilter: app.config.RoundingSlippageFilter,
104105
SkipTxmeta: app.config.SkipTxmeta,
105106
ReapConfig: ingest.ReapConfig{

0 commit comments

Comments
 (0)