update version; minor refactoring

This commit is contained in:
Ian Norden
2020-05-04 12:14:57 -05:00
parent 9b0ded692b
commit dfb66eb67b
16 changed files with 127 additions and 159 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils"
utils "github.com/vulcanize/vulcanizedb/libraries/shared/utilities"
"github.com/vulcanize/vulcanizedb/pkg/super_node/shared"
)
+5 -9
View File
@@ -17,17 +17,16 @@
package btc
import (
"database/sql"
"fmt"
"math/big"
"github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils"
"github.com/lib/pq"
"github.com/ethereum/go-ethereum/common"
"github.com/jmoiron/sqlx"
"github.com/lib/pq"
log "github.com/sirupsen/logrus"
utils "github.com/vulcanize/vulcanizedb/libraries/shared/utilities"
"github.com/vulcanize/vulcanizedb/pkg/postgres"
"github.com/vulcanize/vulcanizedb/pkg/super_node/shared"
)
@@ -179,7 +178,7 @@ func (ecr *CIDRetriever) RetrieveGapsInData(validationLevel int) ([]shared.Gap,
Start uint64 `db:"start"`
Stop uint64 `db:"stop"`
}, 0)
if err := ecr.db.Select(&results, pgStr); err != nil {
if err := ecr.db.Select(&results, pgStr); err != nil && err != sql.ErrNoRows {
return nil, err
}
emptyGaps := make([]shared.Gap, len(results))
@@ -196,12 +195,9 @@ func (ecr *CIDRetriever) RetrieveGapsInData(validationLevel int) ([]shared.Gap,
WHERE times_validated < $1
ORDER BY block_number`
var heights []uint64
if err := ecr.db.Select(&heights, pgStr, validationLevel); err != nil {
if err := ecr.db.Select(&heights, pgStr, validationLevel); err != nil && err != sql.ErrNoRows {
return nil, err
}
if len(heights) == 0 {
return emptyGaps, nil
}
return append(emptyGaps, utils.MissingHeightsToGaps(heights)...), nil
}
+4 -7
View File
@@ -17,17 +17,17 @@
package eth
import (
"database/sql"
"fmt"
"math/big"
"github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/jmoiron/sqlx"
"github.com/lib/pq"
log "github.com/sirupsen/logrus"
utils "github.com/vulcanize/vulcanizedb/libraries/shared/utilities"
"github.com/vulcanize/vulcanizedb/pkg/postgres"
"github.com/vulcanize/vulcanizedb/pkg/super_node/shared"
)
@@ -452,7 +452,7 @@ func (ecr *CIDRetriever) RetrieveGapsInData(validationLevel int) ([]shared.Gap,
Start uint64 `db:"start"`
Stop uint64 `db:"stop"`
}, 0)
if err := ecr.db.Select(&results, pgStr); err != nil {
if err := ecr.db.Select(&results, pgStr); err != nil && err != sql.ErrNoRows {
return nil, err
}
emptyGaps := make([]shared.Gap, len(results))
@@ -469,12 +469,9 @@ func (ecr *CIDRetriever) RetrieveGapsInData(validationLevel int) ([]shared.Gap,
WHERE times_validated < $1
ORDER BY block_number`
var heights []uint64
if err := ecr.db.Select(&heights, pgStr, validationLevel); err != nil {
if err := ecr.db.Select(&heights, pgStr, validationLevel); err != nil && err != sql.ErrNoRows {
return nil, err
}
if len(heights) == 0 {
return emptyGaps, nil
}
return append(emptyGaps, utils.MissingHeightsToGaps(heights)...), nil
}
+1 -1
View File
@@ -152,7 +152,7 @@ func (pub *IPLDPublisherAndIndexer) Publish(payload shared.ConvertedData) (share
err = pub.publishAndIndexStateAndStorage(tx, ipldPayload, headerID)
// This IPLDPublisher does both publishing and indexing, we do not need to pass anything forward to the indexer
return nil, err // return err variable explicity so that we return the err = tx.Commit() assignment in the defer
return nil, err // return err variable explicitly so that we return the err = tx.Commit() assignment in the defer
}
func (pub *IPLDPublisherAndIndexer) publishAndIndexStateAndStorage(tx *sqlx.Tx, ipldPayload ConvertedPayload, headerID int64) error {
+4 -4
View File
@@ -82,8 +82,8 @@ func NewReSyncConfig() (*Config, error) {
viper.BindEnv("resync.timeout", shared.HTTP_TIMEOUT)
timeout := viper.GetInt("resync.timeout")
if timeout < 15 {
timeout = 15
if timeout < 5 {
timeout = 5
}
c.Timeout = time.Second * time.Duration(timeout)
@@ -104,7 +104,7 @@ func NewReSyncConfig() (*Config, error) {
}
}
resyncType := viper.GetString("resync.type")
c.ResyncType, err = shared.GenerateResyncTypeFromString(resyncType)
c.ResyncType, err = shared.GenerateDataTypeFromString(resyncType)
if err != nil {
return nil, err
}
@@ -113,7 +113,7 @@ func NewReSyncConfig() (*Config, error) {
if err != nil {
return nil, err
}
if ok, err := shared.SupportedResyncType(c.ResyncType, c.Chain); !ok {
if ok, err := shared.SupportedDataType(c.ResyncType, c.Chain); !ok {
if err != nil {
return nil, err
}
+1 -1
View File
@@ -22,7 +22,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils"
utils "github.com/vulcanize/vulcanizedb/libraries/shared/utilities"
"github.com/vulcanize/vulcanizedb/pkg/super_node"
"github.com/vulcanize/vulcanizedb/pkg/super_node/shared"
)
+3 -3
View File
@@ -57,8 +57,8 @@ func (r DataType) String() string {
}
}
// GenerateResyncTypeFromString
func GenerateResyncTypeFromString(str string) (DataType, error) {
// GenerateDataTypeFromString
func GenerateDataTypeFromString(str string) (DataType, error) {
switch strings.ToLower(str) {
case "full", "f":
return Full, nil
@@ -79,7 +79,7 @@ func GenerateResyncTypeFromString(str string) (DataType, error) {
}
}
func SupportedResyncType(d DataType, c ChainType) (bool, error) {
func SupportedDataType(d DataType, c ChainType) (bool, error) {
switch c {
case Ethereum:
switch d {
+1 -1
View File
@@ -90,7 +90,7 @@ func GetIPFSMode() (IPFSMode, error) {
if ipfsMode == "" {
return DirectPostgres, nil
}
return NewIPLFMode(ipfsMode)
return NewIPFSMode(ipfsMode)
}
// GetBtcNodeAndClient returns btc node info from path url
+3 -3
View File
@@ -44,15 +44,15 @@ func (c IPFSMode) String() string {
}
}
func NewIPLFMode(name string) (IPFSMode, error) {
func NewIPFSMode(name string) (IPFSMode, error) {
switch strings.ToLower(name) {
case "local", "interface", "minimal":
return LocalInterface, nil
case "remote", "client":
return RemoteClient, nil
return RemoteClient, errors.New("remote IPFS client mode is not currently supported")
case "postgres", "direct":
return DirectPostgres, nil
default:
return Unknown, errors.New("invalid name for ipfs mode")
return Unknown, errors.New("unrecognized name for ipfs mode")
}
}