forked from cerc-io/ipld-eth-server
backfiller refactoring; explicity errs; golint
This commit is contained in:
+21
-25
@@ -16,27 +16,23 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
syn "sync"
|
||||
"time"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/super_node"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth/client"
|
||||
vRpc "github.com/vulcanize/vulcanizedb/pkg/geth/converters/rpc"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth/node"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/super_node"
|
||||
"github.com/vulcanize/vulcanizedb/utils"
|
||||
)
|
||||
|
||||
@@ -60,19 +56,19 @@ func init() {
|
||||
}
|
||||
|
||||
func syncAndPublish() {
|
||||
superNode, err := newSuperNode()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
superNode, newNodeErr := newSuperNode()
|
||||
if newNodeErr != nil {
|
||||
log.Fatal(newNodeErr)
|
||||
}
|
||||
wg := &syn.WaitGroup{}
|
||||
err = superNode.SyncAndPublish(wg, nil, nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
syncAndPubErr := superNode.SyncAndPublish(wg, nil, nil)
|
||||
if syncAndPubErr != nil {
|
||||
log.Fatal(syncAndPubErr)
|
||||
}
|
||||
if viper.GetBool("backfill.on") && viper.GetString("backfill.ipcPath") != "" {
|
||||
backfiller := newBackFiller(superNode.GetPublisher())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
backfiller, newBackFillerErr := newBackFiller()
|
||||
if newBackFillerErr != nil {
|
||||
log.Fatal(newBackFillerErr)
|
||||
}
|
||||
backfiller.FillGaps(wg, nil)
|
||||
}
|
||||
@@ -80,9 +76,9 @@ func syncAndPublish() {
|
||||
}
|
||||
|
||||
func getBlockChainAndClient(path string) (*geth.BlockChain, core.RpcClient) {
|
||||
rawRpcClient, err := rpc.Dial(path)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
rawRpcClient, dialErr := rpc.Dial(path)
|
||||
if dialErr != nil {
|
||||
log.Fatal(dialErr)
|
||||
}
|
||||
rpcClient := client.NewRpcClient(rawRpcClient, ipc)
|
||||
ethClient := ethclient.NewClient(rawRpcClient)
|
||||
@@ -99,9 +95,9 @@ func newSuperNode() (super_node.NodeInterface, error) {
|
||||
quitChan := make(chan bool)
|
||||
ipfsPath = viper.GetString("client.ipfsPath")
|
||||
if ipfsPath == "" {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
home, homeDirErr := os.UserHomeDir()
|
||||
if homeDirErr != nil {
|
||||
log.Fatal(homeDirErr)
|
||||
}
|
||||
ipfsPath = filepath.Join(home, ".ipfs")
|
||||
}
|
||||
@@ -112,7 +108,7 @@ func newSuperNode() (super_node.NodeInterface, error) {
|
||||
return super_node.NewSuperNode(ipfsPath, &db, rpcClient, quitChan, workers, blockChain.Node())
|
||||
}
|
||||
|
||||
func newBackFiller(ipfsPublisher ipfs.IPLDPublisher) super_node.BackFillInterface {
|
||||
func newBackFiller() (super_node.BackFillInterface, error) {
|
||||
blockChain, archivalRpcClient := getBlockChainAndClient(viper.GetString("backfill.ipcPath"))
|
||||
db := utils.LoadPostgres(databaseConfig, blockChain.Node())
|
||||
freq := viper.GetInt("backfill.frequency")
|
||||
@@ -122,5 +118,5 @@ func newBackFiller(ipfsPublisher ipfs.IPLDPublisher) super_node.BackFillInterfac
|
||||
} else {
|
||||
frequency = time.Duration(freq)
|
||||
}
|
||||
return super_node.NewBackFillService(ipfsPublisher, &db, archivalRpcClient, time.Minute*frequency)
|
||||
return super_node.NewBackFillService(ipfsPath, &db, archivalRpcClient, time.Minute*frequency)
|
||||
}
|
||||
|
||||
@@ -16,11 +16,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
syn "sync"
|
||||
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@@ -47,51 +44,30 @@ func init() {
|
||||
}
|
||||
|
||||
func syncPublishScreenAndServe() {
|
||||
superNode, err := newSuperNode()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
superNode, newNodeErr := newSuperNode()
|
||||
if newNodeErr != nil {
|
||||
log.Fatal(newNodeErr)
|
||||
}
|
||||
|
||||
wg := &syn.WaitGroup{}
|
||||
forwardPayloadChan := make(chan ipfs.IPLDPayload, 20000)
|
||||
forwardQuitChan := make(chan bool, 1)
|
||||
err = superNode.SyncAndPublish(wg, forwardPayloadChan, forwardQuitChan)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
syncAndPubErr := superNode.SyncAndPublish(wg, forwardPayloadChan, forwardQuitChan)
|
||||
if syncAndPubErr != nil {
|
||||
log.Fatal(syncAndPubErr)
|
||||
}
|
||||
superNode.ScreenAndServe(forwardPayloadChan, forwardQuitChan)
|
||||
superNode.ScreenAndServe(wg, forwardPayloadChan, forwardQuitChan)
|
||||
if viper.GetBool("backfill.on") && viper.GetString("backfill.ipcPath") != "" {
|
||||
backfiller := newBackFiller(superNode.GetPublisher())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
backfiller, newBackFillerErr := newBackFiller()
|
||||
if newBackFillerErr != nil {
|
||||
log.Fatal(newBackFillerErr)
|
||||
}
|
||||
backfiller.FillGaps(wg, nil)
|
||||
}
|
||||
|
||||
var ipcPath string
|
||||
ipcPath = viper.GetString("server.ipcPath")
|
||||
if ipcPath == "" {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
ipcPath = filepath.Join(home, ".vulcanize/vulcanize.ipc")
|
||||
}
|
||||
_, _, err = rpc.StartIPCEndpoint(ipcPath, superNode.APIs())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var wsEndpoint string
|
||||
wsEndpoint = viper.GetString("server.wsEndpoint")
|
||||
if wsEndpoint == "" {
|
||||
wsEndpoint = "127.0.0.1:8080"
|
||||
}
|
||||
var exposeAll = true
|
||||
var wsOrigins []string = nil
|
||||
_, _, err = rpc.StartWSEndpoint(wsEndpoint, superNode.APIs(), []string{"vulcanizedb"}, wsOrigins, exposeAll)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
serverErr := startServers(superNode)
|
||||
if serverErr != nil {
|
||||
log.Fatal(serverErr)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user