2019-05-28 19:13:06 +00:00
|
|
|
// Copyright © 2019 Vulcanize, Inc
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
syn "sync"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
2019-06-07 16:01:29 +00:00
|
|
|
"github.com/spf13/viper"
|
2019-05-28 19:13:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// syncPublishScreenAndServeCmd represents the syncPublishScreenAndServe command
|
|
|
|
var syncPublishScreenAndServeCmd = &cobra.Command{
|
|
|
|
Use: "syncPublishScreenAndServe",
|
2019-06-06 17:55:59 +00:00
|
|
|
Short: "Syncs all Ethereum data into IPFS, indexing the CIDs, and uses this to serve data requests to requesting clients",
|
|
|
|
Long: `This command works alongside a modified geth node which streams
|
|
|
|
all block and state (diff) data over a websocket subscription. This process
|
|
|
|
then converts the eth data to IPLD objects and publishes them to IPFS. Additionally,
|
|
|
|
it maintains a local index of the IPLD objects' CIDs in Postgres. It then opens up a server which
|
|
|
|
relays relevant data to requesting clients.`,
|
2019-05-28 19:13:06 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2019-10-14 14:41:29 +00:00
|
|
|
subCommand = cmd.CalledAs()
|
|
|
|
logWithCommand = *log.WithField("SubCommand", subCommand)
|
2019-05-28 19:13:06 +00:00
|
|
|
syncPublishScreenAndServe()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(syncPublishScreenAndServeCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func syncPublishScreenAndServe() {
|
2019-10-08 19:51:38 +00:00
|
|
|
superNode, newNodeErr := newSuperNode()
|
|
|
|
if newNodeErr != nil {
|
2019-10-14 14:41:29 +00:00
|
|
|
logWithCommand.Fatal(newNodeErr)
|
2019-05-28 19:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wg := &syn.WaitGroup{}
|
2020-01-17 23:16:01 +00:00
|
|
|
forwardPayloadChan := make(chan interface{}, 20000)
|
2019-06-07 02:09:27 +00:00
|
|
|
forwardQuitChan := make(chan bool, 1)
|
2019-10-08 19:51:38 +00:00
|
|
|
syncAndPubErr := superNode.SyncAndPublish(wg, forwardPayloadChan, forwardQuitChan)
|
|
|
|
if syncAndPubErr != nil {
|
2019-10-14 14:41:29 +00:00
|
|
|
logWithCommand.Fatal(syncAndPubErr)
|
2019-05-28 19:13:06 +00:00
|
|
|
}
|
2019-10-08 19:51:38 +00:00
|
|
|
superNode.ScreenAndServe(wg, forwardPayloadChan, forwardQuitChan)
|
2019-10-14 14:41:29 +00:00
|
|
|
if viper.GetBool("superNodeBackFill.on") && viper.GetString("superNodeBackFill.rpcPath") != "" {
|
2019-10-08 19:51:38 +00:00
|
|
|
backfiller, newBackFillerErr := newBackFiller()
|
|
|
|
if newBackFillerErr != nil {
|
2019-10-14 14:41:29 +00:00
|
|
|
logWithCommand.Fatal(newBackFillerErr)
|
2019-10-02 14:10:37 +00:00
|
|
|
}
|
|
|
|
backfiller.FillGaps(wg, nil)
|
|
|
|
}
|
2019-06-07 16:01:29 +00:00
|
|
|
|
2019-10-08 19:51:38 +00:00
|
|
|
serverErr := startServers(superNode)
|
|
|
|
if serverErr != nil {
|
2019-10-14 14:41:29 +00:00
|
|
|
logWithCommand.Fatal(serverErr)
|
2019-06-07 16:01:29 +00:00
|
|
|
}
|
2019-05-28 19:13:06 +00:00
|
|
|
wg.Wait()
|
|
|
|
}
|