forked from cerc-io/ipld-eth-server
Merge pull request #57 from vulcanize/fix-missing-blocks-lookup
Fix missing block numbers lookup
This commit is contained in:
commit
b1df139d29
@ -56,11 +56,11 @@ func (blockRepository BlockRepository) MissingBlockNumbers(startingBlockNumber i
|
|||||||
numbers := make([]int64, 0)
|
numbers := make([]int64, 0)
|
||||||
blockRepository.database.Select(&numbers,
|
blockRepository.database.Select(&numbers,
|
||||||
`SELECT all_block_numbers
|
`SELECT all_block_numbers
|
||||||
FROM (
|
FROM (
|
||||||
SELECT generate_series($1::INT, $2::INT) AS all_block_numbers) series
|
SELECT generate_series($1::INT, $2::INT) AS all_block_numbers) series
|
||||||
LEFT JOIN blocks
|
WHERE all_block_numbers NOT IN (
|
||||||
ON number = all_block_numbers
|
SELECT number FROM blocks WHERE eth_node_fingerprint = $3
|
||||||
WHERE number ISNULL OR eth_node_fingerprint != $3`,
|
) `,
|
||||||
startingBlockNumber,
|
startingBlockNumber,
|
||||||
highestBlockNumber, nodeId)
|
highestBlockNumber, nodeId)
|
||||||
return numbers
|
return numbers
|
||||||
|
@ -241,6 +241,23 @@ var _ = Describe("Saving blocks", func() {
|
|||||||
Expect(len(blockRepository.MissingBlockNumbers(1, 1, node.ID))).To(Equal(0))
|
Expect(len(blockRepository.MissingBlockNumbers(1, 1, node.ID))).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("is empty if copies of block exist from both current node and another", func() {
|
||||||
|
blockRepository.CreateOrUpdateBlock(core.Block{Number: 0})
|
||||||
|
blockRepository.CreateOrUpdateBlock(core.Block{Number: 1})
|
||||||
|
nodeTwo := core.Node{
|
||||||
|
GenesisBlock: "0x456",
|
||||||
|
NetworkID: 1,
|
||||||
|
}
|
||||||
|
dbTwo, err := postgres.NewDB(test_config.DBConfig, nodeTwo)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
repositoryTwo := repositories.NewBlockRepository(dbTwo)
|
||||||
|
repositoryTwo.CreateOrUpdateBlock(core.Block{Number: 0})
|
||||||
|
|
||||||
|
missing := blockRepository.MissingBlockNumbers(0, 1, node.ID)
|
||||||
|
|
||||||
|
Expect(len(missing)).To(BeZero())
|
||||||
|
})
|
||||||
|
|
||||||
It("is the only missing block number", func() {
|
It("is the only missing block number", func() {
|
||||||
blockRepository.CreateOrUpdateBlock(core.Block{Number: 2})
|
blockRepository.CreateOrUpdateBlock(core.Block{Number: 2})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user