forked from cerc-io/ipld-eth-server
Return missing headers after starting block number
- Previously, we required that the first missing header match the configured starting block number. This helps guarantee that we have the necessary data for method polling in memory, but prevents the process from moving forward if restarted after the starting block has already been checked.
This commit is contained in:
parent
a596966b7c
commit
eea0b0bdca
@ -179,7 +179,7 @@ func (r *headerRepository) MissingHeaders(startingBlockNumber, endingBlockNumber
|
||||
ORDER BY headers.block_number`
|
||||
err = r.db.Select(&result, query, startingBlockNumber, endingBlockNumber, r.db.Node.ID)
|
||||
}
|
||||
return contiguousHeaders(result, startingBlockNumber), err
|
||||
return continuousHeaders(result), err
|
||||
}
|
||||
|
||||
// Returns missing headers for all of the provided checked_headers column ids
|
||||
@ -207,26 +207,7 @@ func (r *headerRepository) MissingHeadersForAll(startingBlockNumber, endingBlock
|
||||
query = baseQuery + endStr
|
||||
err = r.db.Select(&result, query, startingBlockNumber, endingBlockNumber, r.db.Node.ID)
|
||||
}
|
||||
return contiguousHeaders(result, startingBlockNumber), err
|
||||
}
|
||||
|
||||
// Returns a continuous set of headers that is contiguous with the provided startingBlockNumber
|
||||
func contiguousHeaders(headers []core.Header, startingBlockNumber int64) []core.Header {
|
||||
if len(headers) < 1 {
|
||||
return headers
|
||||
}
|
||||
previousHeader := headers[0].BlockNumber
|
||||
if previousHeader != startingBlockNumber {
|
||||
return []core.Header{}
|
||||
}
|
||||
for i := 1; i < len(headers); i++ {
|
||||
previousHeader++
|
||||
if headers[i].BlockNumber != previousHeader {
|
||||
return headers[:i]
|
||||
}
|
||||
}
|
||||
|
||||
return headers
|
||||
return continuousHeaders(result), err
|
||||
}
|
||||
|
||||
// Returns headers that have been checked for all of the provided event ids but not for the provided method ids
|
||||
|
@ -203,6 +203,18 @@ var _ = Describe("Repository", func() {
|
||||
Expect(missingHeaders[1].BlockNumber).To(Equal(int64(6194633)))
|
||||
})
|
||||
|
||||
It("returns headers after starting header if starting header not missing", func() {
|
||||
addLaterHeaders(coreHeaderRepo)
|
||||
err := contractHeaderRepo.AddCheckColumns(eventIDs)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
missingHeaders, err := contractHeaderRepo.MissingHeadersForAll(6194632, -1, eventIDs)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(len(missingHeaders)).To(Equal(2))
|
||||
Expect(missingHeaders[0].BlockNumber).To(Equal(mocks.MockHeader3.BlockNumber))
|
||||
Expect(missingHeaders[1].BlockNumber).To(Equal(mocks.MockHeader4.BlockNumber))
|
||||
})
|
||||
|
||||
It("Fails if one of the eventIDs does not yet exist in check_headers table", func() {
|
||||
addHeaders(coreHeaderRepo)
|
||||
err := contractHeaderRepo.AddCheckColumns(eventIDs)
|
||||
@ -329,19 +341,31 @@ var _ = Describe("Repository", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(len(intersectionHeaders)).To(Equal(1))
|
||||
Expect(intersectionHeaders[0].Id).To(Equal(headerID2))
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
func addHeaders(coreHeaderRepo repositories.HeaderRepository) {
|
||||
coreHeaderRepo.CreateOrUpdateHeader(mocks.MockHeader1)
|
||||
coreHeaderRepo.CreateOrUpdateHeader(mocks.MockHeader2)
|
||||
coreHeaderRepo.CreateOrUpdateHeader(mocks.MockHeader3)
|
||||
_, err := coreHeaderRepo.CreateOrUpdateHeader(mocks.MockHeader1)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = coreHeaderRepo.CreateOrUpdateHeader(mocks.MockHeader2)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = coreHeaderRepo.CreateOrUpdateHeader(mocks.MockHeader3)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
func addDiscontinuousHeaders(coreHeaderRepo repositories.HeaderRepository) {
|
||||
coreHeaderRepo.CreateOrUpdateHeader(mocks.MockHeader1)
|
||||
coreHeaderRepo.CreateOrUpdateHeader(mocks.MockHeader2)
|
||||
coreHeaderRepo.CreateOrUpdateHeader(mocks.MockHeader4)
|
||||
_, err := coreHeaderRepo.CreateOrUpdateHeader(mocks.MockHeader1)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = coreHeaderRepo.CreateOrUpdateHeader(mocks.MockHeader2)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = coreHeaderRepo.CreateOrUpdateHeader(mocks.MockHeader4)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
func addLaterHeaders(coreHeaderRepo repositories.HeaderRepository) {
|
||||
_, err := coreHeaderRepo.CreateOrUpdateHeader(mocks.MockHeader3)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = coreHeaderRepo.CreateOrUpdateHeader(mocks.MockHeader4)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user