forked from cerc-io/ipld-eth-server
rename blocks table to eth_blocks so that we don't clash with the ipfs blocks table; dockerfile and startup_script for the seed node
This commit is contained in:
@@ -64,7 +64,7 @@ func (r *blockRetriever) retrieveFirstBlockFromReceipts(contractAddr string) (in
|
||||
}
|
||||
err := r.db.Get(
|
||||
&firstBlock,
|
||||
`SELECT number FROM blocks
|
||||
`SELECT number FROM eth_blocks
|
||||
WHERE id = (SELECT block_id FROM full_sync_receipts
|
||||
WHERE contract_address_id = $1
|
||||
ORDER BY block_id ASC
|
||||
@@ -92,7 +92,7 @@ func (r *blockRetriever) RetrieveMostRecentBlock() (int64, error) {
|
||||
var lastBlock int64
|
||||
err := r.db.Get(
|
||||
&lastBlock,
|
||||
"SELECT number FROM blocks ORDER BY number DESC LIMIT 1",
|
||||
"SELECT number FROM eth_blocks ORDER BY number DESC LIMIT 1",
|
||||
)
|
||||
|
||||
return lastBlock, err
|
||||
|
||||
@@ -265,7 +265,7 @@ func TearDown(db *postgres.DB) {
|
||||
_, err = tx.Exec(`DELETE FROM addresses`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
_, err = tx.Exec(`DELETE FROM blocks`)
|
||||
_, err = tx.Exec(`DELETE FROM eth_blocks`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
_, err = tx.Exec(`DELETE FROM headers`)
|
||||
|
||||
@@ -19,8 +19,10 @@ package repositories
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
@@ -43,7 +45,7 @@ func NewBlockRepository(database *postgres.DB) *BlockRepository {
|
||||
func (blockRepository BlockRepository) SetBlocksStatus(chainHead int64) error {
|
||||
cutoff := chainHead - blocksFromHeadBeforeFinal
|
||||
_, err := blockRepository.database.Exec(`
|
||||
UPDATE blocks SET is_final = TRUE
|
||||
UPDATE eth_blocks SET is_final = TRUE
|
||||
WHERE is_final = FALSE AND number < $1`,
|
||||
cutoff)
|
||||
|
||||
@@ -74,7 +76,7 @@ func (blockRepository BlockRepository) MissingBlockNumbers(startingBlockNumber i
|
||||
FROM (
|
||||
SELECT generate_series($1::INT, $2::INT) AS all_block_numbers) series
|
||||
WHERE all_block_numbers NOT IN (
|
||||
SELECT number FROM blocks WHERE eth_node_fingerprint = $3
|
||||
SELECT number FROM eth_blocks WHERE eth_node_fingerprint = $3
|
||||
) `,
|
||||
startingBlockNumber,
|
||||
highestBlockNumber, nodeID)
|
||||
@@ -102,7 +104,7 @@ func (blockRepository BlockRepository) GetBlock(blockNumber int64) (core.Block,
|
||||
extra_data,
|
||||
reward,
|
||||
uncles_reward
|
||||
FROM blocks
|
||||
FROM eth_blocks
|
||||
WHERE eth_node_id = $1 AND number = $2`, blockRepository.database.NodeID, blockNumber)
|
||||
savedBlock, err := blockRepository.loadBlock(blockRows)
|
||||
if err != nil {
|
||||
@@ -124,7 +126,7 @@ func (blockRepository BlockRepository) insertBlock(block core.Block) (int64, err
|
||||
return 0, postgres.ErrBeginTransactionFailed(beginErr)
|
||||
}
|
||||
insertBlockErr := tx.QueryRow(
|
||||
`INSERT INTO blocks
|
||||
`INSERT INTO eth_blocks
|
||||
(eth_node_id, number, gas_limit, gas_used, time, difficulty, hash, nonce, parent_hash, size, uncle_hash, is_final, miner, extra_data, reward, uncles_reward, eth_node_fingerprint)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)
|
||||
RETURNING id `,
|
||||
@@ -260,7 +262,7 @@ func (blockRepository BlockRepository) getBlockHash(block core.Block) (string, b
|
||||
// TODO: handle possible error
|
||||
blockRepository.database.Get(&retrievedBlockHash,
|
||||
`SELECT hash
|
||||
FROM blocks
|
||||
FROM eth_blocks
|
||||
WHERE number = $1 AND eth_node_id = $2`,
|
||||
block.Number, blockRepository.database.NodeID)
|
||||
return retrievedBlockHash, blockExists(retrievedBlockHash)
|
||||
@@ -287,7 +289,7 @@ func blockExists(retrievedBlockHash string) bool {
|
||||
|
||||
func (blockRepository BlockRepository) removeBlock(blockNumber int64) error {
|
||||
_, err := blockRepository.database.Exec(
|
||||
`DELETE FROM blocks WHERE number=$1 AND eth_node_id=$2`,
|
||||
`DELETE FROM eth_blocks WHERE number=$1 AND eth_node_id=$2`,
|
||||
blockNumber, blockRepository.database.NodeID)
|
||||
if err != nil {
|
||||
return postgres.ErrDBDeleteFailed(err)
|
||||
|
||||
@@ -67,6 +67,8 @@ func (ecr *EthCIDRetriever) RetrieveCIDs(streamFilters config.Subscription) ([]C
|
||||
}
|
||||
log.Debug("backfill starting block:", streamFilters.StartingBlock)
|
||||
log.Debug("backfill ending block:", endingBlock)
|
||||
// THIS IS SUPER EXPENSIVE HAVING TO CYCLE THROUGH EACH BLOCK, NEED BETTER WAY TO FETCH CIDS
|
||||
// WHILE STILL MAINTAINING RELATION INFO ABOUT WHAT BLOCK THE CIDS BELONG TO
|
||||
for i := streamFilters.StartingBlock; i <= endingBlock; i++ {
|
||||
cw := CidWrapper{}
|
||||
if !streamFilters.HeaderFilter.Off {
|
||||
|
||||
Reference in New Issue
Block a user