diff --git a/services/horizon/cmd/ingest.go b/services/horizon/cmd/ingest.go index 9c8bcc76e2..50638fc1c5 100644 --- a/services/horizon/cmd/ingest.go +++ b/services/horizon/cmd/ingest.go @@ -292,7 +292,7 @@ var ingestBuildStateCmd = &cobra.Command{ } mngr := historyarchive.NewCheckpointManager(globalConfig.CheckpointFrequency) - if !mngr.IsCheckpoint(ingestBuildStateSequence) && ingestBuildStateSequence != 1 { + if !mngr.IsCheckpoint(ingestBuildStateSequence) { return fmt.Errorf("`--sequence` must be a checkpoint ledger") } diff --git a/services/horizon/internal/ingest/fsm.go b/services/horizon/internal/ingest/fsm.go index b3fed4491f..00fb0e4c3f 100644 --- a/services/horizon/internal/ingest/fsm.go +++ b/services/horizon/internal/ingest/fsm.go @@ -301,9 +301,6 @@ func (b buildState) run(s *system) (transition, error) { // We don't need to prepare range for genesis checkpoint because we don't // perform protocol version and bucket list hash checks. - // In the long term we should probably create artificial xdr.LedgerCloseMeta - // for ledger #1 instead of using `ingest.GenesisChange` reader in - // ProcessorRunner.RunHistoryArchiveIngestion(). // We can also skip preparing range if `skipChecks` is `true` because we // won't need bucket list hash and protocol version. var protocolVersion uint32 diff --git a/services/horizon/internal/ingest/processor_runner_test.go b/services/horizon/internal/ingest/processor_runner_test.go index 2d867a52b2..6e307d3260 100644 --- a/services/horizon/internal/ingest/processor_runner_test.go +++ b/services/horizon/internal/ingest/processor_runner_test.go @@ -3,6 +3,7 @@ package ingest import ( "context" "fmt" + "github.com/stellar/go/amount" "io" "reflect" "testing" @@ -29,14 +30,33 @@ func TestProcessorRunnerRunHistoryArchiveIngestionHistoryArchive(t *testing.T) { q := &mockDBQ{} defer mock.AssertExpectationsForObjects(t, q) historyAdapter := &mockHistoryArchiveAdapter{} - defer mock.AssertExpectationsForObjects(t, historyAdapter) + defer mock.AssertExpectationsForObjects(t, historyAdapter) // this will fail m := &ingest.MockChangeReader{} - m.On("Read").Return(ingest.Change{}, io.EOF).Once() m.On("Close").Return(nil).Once() bucketListHash := xdr.Hash([32]byte{0, 1, 2}) m.On("VerifyBucketList", bucketListHash).Return(nil).Once() + changeEntry := ingest.Change{ + Type: xdr.LedgerEntryTypeAccount, + Post: &xdr.LedgerEntry{ + LastModifiedLedgerSeq: 1, + Data: xdr.LedgerEntryData{ + Type: xdr.LedgerEntryTypeAccount, + Account: &xdr.AccountEntry{ + // Master account address from Ledger 1 + AccountId: xdr.MustAddress("GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7"), + // 100B + Balance: amount.MustParse("100000000000"), + SeqNum: 0, + Thresholds: xdr.Thresholds{1, 0, 0, 0}, + }, + }, + }, + } + m.On("Read").Return(changeEntry, nil).Once() + m.On("Read").Return(ingest.Change{}, io.EOF).Once() + historyAdapter. On("GetState", ctx, uint32(63)). Return( @@ -45,10 +65,23 @@ func TestProcessorRunnerRunHistoryArchiveIngestionHistoryArchive(t *testing.T) { ).Once() batchBuilders := mockChangeProcessorBatchBuilders(q, ctx, true) - defer mock.AssertExpectationsForObjects(t, batchBuilders...) + defer mock.AssertExpectationsForObjects(t, batchBuilders...) // currently failing - assert.IsType(t, &history.MockAccountSignersBatchInsertBuilder{}, batchBuilders[0]) assert.IsType(t, &history.MockAccountsBatchInsertBuilder{}, batchBuilders[1]) + batchBuilders[1].(*history.MockAccountsBatchInsertBuilder).On("Add", history.AccountEntry{ + LastModifiedLedger: 1, + AccountID: "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7", + Balance: int64(1000000000000000000), + SequenceNumber: 0, + MasterWeight: 1, + }).Return(nil).Once() + + assert.IsType(t, &history.MockAccountSignersBatchInsertBuilder{}, batchBuilders[0]) + batchBuilders[0].(*history.MockAccountSignersBatchInsertBuilder).On("Add", history.AccountSigner{ + Account: "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7", + Signer: "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7", + Weight: 1, + }).Return(nil).Once() q.MockQAssetStats.On("InsertAssetStats", ctx, []history.ExpAssetStat{}, 100000). Return(nil)