forked from cerc-io/ipld-eth-server
split btc and eth super node processes into serpate containers; dockerfile for Postgraphile with plugins
This commit is contained in:
parent
93e7eb35c5
commit
e7225317d4
@ -54,7 +54,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func superNode() {
|
func superNode() {
|
||||||
superNodeConfigs, err := super_node.NewSuperNodeConfigs()
|
superNodeConfig, err := super_node.NewSuperNodeConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -62,7 +62,6 @@ func superNode() {
|
|||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
for _, superNodeConfig := range superNodeConfigs {
|
|
||||||
superNode, err := super_node.NewSuperNode(superNodeConfig)
|
superNode, err := super_node.NewSuperNode(superNodeConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
@ -87,7 +86,6 @@ func superNode() {
|
|||||||
}
|
}
|
||||||
backFiller.FillGapsInSuperNode(wg)
|
backFiller.FillGapsInSuperNode(wg)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
dockerfiles/postgraphile/Dockerfile
Normal file
8
dockerfiles/postgraphile/Dockerfile
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
FROM node:alpine
|
||||||
|
|
||||||
|
RUN npm install -g postgraphile
|
||||||
|
RUN npm install -g postgraphile-plugin-connection-filter
|
||||||
|
RUN npm install -g @graphile/pg-pubsub
|
||||||
|
|
||||||
|
EXPOSE 5000
|
||||||
|
ENTRYPOINT ["postgraphile", "-n", "0.0.0.0"]
|
@ -34,8 +34,6 @@ ARG USER
|
|||||||
ARG CONFIG_FILE
|
ARG CONFIG_FILE
|
||||||
ARG EXPOSE_PORT_1
|
ARG EXPOSE_PORT_1
|
||||||
ARG EXPOSE_PORT_2
|
ARG EXPOSE_PORT_2
|
||||||
ARG EXPOSE_PORT_3
|
|
||||||
ARG EXPOSE_PORT_4
|
|
||||||
|
|
||||||
RUN adduser -Du 5000 $USER
|
RUN adduser -Du 5000 $USER
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@ -57,7 +55,5 @@ COPY --from=builder /go/src/github.com/ipfs/go-ipfs/ipfs ipfs
|
|||||||
|
|
||||||
EXPOSE $EXPOSE_PORT_1
|
EXPOSE $EXPOSE_PORT_1
|
||||||
EXPOSE $EXPOSE_PORT_2
|
EXPOSE $EXPOSE_PORT_2
|
||||||
EXPOSE $EXPOSE_PORT_3
|
|
||||||
EXPOSE $EXPOSE_PORT_4
|
|
||||||
|
|
||||||
CMD ["./startup_script.sh"]
|
CMD ["./startup_script.sh"]
|
||||||
|
@ -2,6 +2,7 @@ version: '3.2'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
|
restart: always
|
||||||
image: postgres:10.12-alpine
|
image: postgres:10.12-alpine
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: "postgres"
|
POSTGRES_USER: "postgres"
|
||||||
@ -13,13 +14,8 @@ services:
|
|||||||
- "5432"
|
- "5432"
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8079:5432"
|
- "127.0.0.1:8079:5432"
|
||||||
healthcheck:
|
|
||||||
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
||||||
interval: 5s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 30
|
|
||||||
|
|
||||||
supernode:
|
btc:
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
build:
|
build:
|
||||||
@ -29,7 +25,29 @@ services:
|
|||||||
- golang:1.12.4
|
- golang:1.12.4
|
||||||
dockerfile: ./dockerfiles/super_node/Dockerfile
|
dockerfile: ./dockerfiles/super_node/Dockerfile
|
||||||
args:
|
args:
|
||||||
CONFIG_FILE: ./environments/superNode.toml
|
CONFIG_FILE: ./environments/superNodeBTC.toml
|
||||||
|
environment:
|
||||||
|
IPFS_INIT: "true"
|
||||||
|
VDB_PG_NAME: "vulcanize_public"
|
||||||
|
VDB_PG_HOSTNAME: "db"
|
||||||
|
VDB_PG_PORT: 5432
|
||||||
|
VDB_PG_USER: "postgres"
|
||||||
|
VDB_PG_PASSWORD: "password"
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8082:8082"
|
||||||
|
- "127.0.0.1:8083:8083"
|
||||||
|
|
||||||
|
eth:
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
build:
|
||||||
|
context: ./../../
|
||||||
|
cache_from:
|
||||||
|
- alpine:latest
|
||||||
|
- golang:1.12.4
|
||||||
|
dockerfile: ./dockerfiles/super_node/Dockerfile
|
||||||
|
args:
|
||||||
|
CONFIG_FILE: ./environments/superNodeETH.toml
|
||||||
environment:
|
environment:
|
||||||
IPFS_INIT: "true"
|
IPFS_INIT: "true"
|
||||||
VDB_PG_NAME: "vulcanize_public"
|
VDB_PG_NAME: "vulcanize_public"
|
||||||
@ -40,9 +58,30 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8080:8080"
|
- "127.0.0.1:8080:8080"
|
||||||
- "127.0.0.1:8081:8081"
|
- "127.0.0.1:8081:8081"
|
||||||
- "127.0.0.1:8082:8082"
|
|
||||||
- "127.0.0.1:8083:8083"
|
graphql:
|
||||||
|
restart: always
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
build:
|
||||||
|
context: ./../../
|
||||||
|
cache_from:
|
||||||
|
- node:alpine
|
||||||
|
dockerfile: ./dockerfiles/postgraphile/Dockerfile
|
||||||
|
environment:
|
||||||
|
DATABASE_URL: postgres://postgres:password@db:5432/vulcanize_public
|
||||||
|
expose:
|
||||||
|
- "5000"
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:5000:5000"
|
||||||
|
command: ["--plugins", "@graphile/pg-pubsub",
|
||||||
|
"--subscriptions",
|
||||||
|
"--simple-subscriptions",
|
||||||
|
"--connection", $DATABASE_URL,
|
||||||
|
"--host", "0.0.0.0",
|
||||||
|
"--port", "5000",
|
||||||
|
"--schema", "public,btc,eth"
|
||||||
|
"--append-plugins", "postgraphile-plugin-connection-filter"]
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
vulcanizedb_db_data:
|
vulcanizedb_db_data:
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package super_node
|
package super_node
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
@ -60,12 +59,18 @@ type Config struct {
|
|||||||
BatchSize uint64
|
BatchSize uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSuperNodeConfigs is used to initialize multiple SuperNode configs from a single config .toml file
|
// NewSuperNodeConfig is used to initialize a SuperNode config from a .toml file
|
||||||
// Separate chain supernode instances need to be ran in the same process in order to avoid lock contention on the ipfs repository
|
// Separate chain supernode instances need to be ran with separate ipfs path in order to avoid lock contention on the ipfs repository lockfile
|
||||||
func NewSuperNodeConfigs() ([]*Config, error) {
|
func NewSuperNodeConfig() (*Config, error) {
|
||||||
chains := viper.GetStringSlice("superNode.chains")
|
c := new(Config)
|
||||||
configs := make([]*Config, len(chains))
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
chain := viper.GetString("superNode.chain")
|
||||||
|
c.Chain, err = shared.NewChainType(chain)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
ipfsPath := viper.GetString("superNode.ipfsPath")
|
ipfsPath := viper.GetString("superNode.ipfsPath")
|
||||||
if ipfsPath == "" {
|
if ipfsPath == "" {
|
||||||
home, err := os.UserHomeDir()
|
home, err := os.UserHomeDir()
|
||||||
@ -74,58 +79,47 @@ func NewSuperNodeConfigs() ([]*Config, error) {
|
|||||||
}
|
}
|
||||||
ipfsPath = filepath.Join(home, ".ipfs")
|
ipfsPath = filepath.Join(home, ".ipfs")
|
||||||
}
|
}
|
||||||
for i, chain := range chains {
|
c.IPFSPath = ipfsPath
|
||||||
sn := new(Config)
|
|
||||||
sn.Chain, err = shared.NewChainType(chain)
|
c.Sync = viper.GetBool("superNode.sync")
|
||||||
if err != nil {
|
if c.Sync {
|
||||||
return nil, err
|
workers := viper.GetInt("superNode.workers")
|
||||||
}
|
|
||||||
sn.DBConfig = config.Database{
|
|
||||||
Name: viper.GetString(fmt.Sprintf("superNode.%s.database.name", chain)),
|
|
||||||
Hostname: viper.GetString(fmt.Sprintf("superNode.%s.database.hostname", chain)),
|
|
||||||
Port: viper.GetInt(fmt.Sprintf("superNode.%s.database.port", chain)),
|
|
||||||
User: viper.GetString(fmt.Sprintf("superNode.%s.database.user", chain)),
|
|
||||||
Password: viper.GetString(fmt.Sprintf("superNode.%s.database.password", chain)),
|
|
||||||
}
|
|
||||||
sn.IPFSPath = ipfsPath
|
|
||||||
sn.Serve = viper.GetBool(fmt.Sprintf("superNode.%s.server.on", chain))
|
|
||||||
sn.Sync = viper.GetBool(fmt.Sprintf("superNode.%s.sync.on", chain))
|
|
||||||
if sn.Sync {
|
|
||||||
workers := viper.GetInt("superNode.sync.workers")
|
|
||||||
if workers < 1 {
|
if workers < 1 {
|
||||||
workers = 1
|
workers = 1
|
||||||
}
|
}
|
||||||
sn.Workers = workers
|
c.Workers = workers
|
||||||
switch sn.Chain {
|
switch c.Chain {
|
||||||
case shared.Ethereum:
|
case shared.Ethereum:
|
||||||
sn.NodeInfo, sn.WSClient, err = getEthNodeAndClient(viper.GetString("superNode.ethereum.sync.wsPath"))
|
c.NodeInfo, c.WSClient, err = getEthNodeAndClient(viper.GetString("ethereum.wsPath"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case shared.Bitcoin:
|
case shared.Bitcoin:
|
||||||
sn.NodeInfo = core.Node{
|
c.NodeInfo = core.Node{
|
||||||
ID: viper.GetString("superNode.bitcoin.node.nodeID"),
|
ID: viper.GetString("bitcoin.nodeID"),
|
||||||
ClientName: viper.GetString("superNode.bitcoin.node.clientName"),
|
ClientName: viper.GetString("bitcoin.clientName"),
|
||||||
GenesisBlock: viper.GetString("superNode.bitcoin.node.genesisBlock"),
|
GenesisBlock: viper.GetString("bitcoin.genesisBlock"),
|
||||||
NetworkID: viper.GetString("superNode.bitcoin.node.networkID"),
|
NetworkID: viper.GetString("bitcoin.networkID"),
|
||||||
}
|
}
|
||||||
// For bitcoin we load in node info from the config because there is no RPC endpoint to retrieve this from the node
|
// For bitcoin we load in node info from the config because there is no RPC endpoint to retrieve this from the node
|
||||||
sn.WSClient = &rpcclient.ConnConfig{
|
c.WSClient = &rpcclient.ConnConfig{
|
||||||
Host: viper.GetString("superNode.bitcoin.sync.wsPath"),
|
Host: viper.GetString("bitcoin.wsPath"),
|
||||||
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
|
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
|
||||||
DisableTLS: true, // Bitcoin core does not provide TLS by default
|
DisableTLS: true, // Bitcoin core does not provide TLS by default
|
||||||
Pass: viper.GetString("superNode.bitcoin.sync.pass"),
|
Pass: viper.GetString("bitcoin.pass"),
|
||||||
User: viper.GetString("superNode.bitcoin.sync.user"),
|
User: viper.GetString("bitcoin.user"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if sn.Serve {
|
|
||||||
wsPath := viper.GetString(fmt.Sprintf("superNode.%s.server.wsPath", chain))
|
c.Serve = viper.GetBool("superNode.server")
|
||||||
|
if c.Serve {
|
||||||
|
wsPath := viper.GetString("superNode.wsPath")
|
||||||
if wsPath == "" {
|
if wsPath == "" {
|
||||||
wsPath = "ws://127.0.0.1:8546"
|
wsPath = "ws://127.0.0.1:8546"
|
||||||
}
|
}
|
||||||
sn.WSEndpoint = wsPath
|
c.WSEndpoint = wsPath
|
||||||
ipcPath := viper.GetString(fmt.Sprintf("superNode.%s.server.ipcPath", chain))
|
ipcPath := viper.GetString("superNode.ipcPath")
|
||||||
if ipcPath == "" {
|
if ipcPath == "" {
|
||||||
home, err := os.UserHomeDir()
|
home, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -133,24 +127,32 @@ func NewSuperNodeConfigs() ([]*Config, error) {
|
|||||||
}
|
}
|
||||||
ipcPath = filepath.Join(home, ".vulcanize/vulcanize.ipc")
|
ipcPath = filepath.Join(home, ".vulcanize/vulcanize.ipc")
|
||||||
}
|
}
|
||||||
sn.IPCEndpoint = ipcPath
|
c.IPCEndpoint = ipcPath
|
||||||
httpPath := viper.GetString(fmt.Sprintf("superNode.%s.server.httpPath", chain))
|
httpPath := viper.GetString("superNode.httpPath")
|
||||||
if httpPath == "" {
|
if httpPath == "" {
|
||||||
httpPath = "http://127.0.0.1:8545"
|
httpPath = "http://127.0.0.1:8545"
|
||||||
}
|
}
|
||||||
sn.HTTPEndpoint = httpPath
|
c.HTTPEndpoint = httpPath
|
||||||
}
|
}
|
||||||
db := utils.LoadPostgres(sn.DBConfig, sn.NodeInfo)
|
|
||||||
sn.DB = &db
|
c.DBConfig = config.Database{
|
||||||
sn.Quit = make(chan bool)
|
Name: viper.GetString("database.name"),
|
||||||
if viper.GetBool(fmt.Sprintf("superNode.%s.backFill.on", chain)) {
|
Hostname: viper.GetString("database.hostname"),
|
||||||
if err := sn.BackFillFields(chain); err != nil {
|
Port: viper.GetInt("database.port"),
|
||||||
|
User: viper.GetString("database.user"),
|
||||||
|
Password: viper.GetString("database.password"),
|
||||||
|
}
|
||||||
|
|
||||||
|
db := utils.LoadPostgres(c.DBConfig, c.NodeInfo)
|
||||||
|
c.DB = &db
|
||||||
|
c.Quit = make(chan bool)
|
||||||
|
if viper.GetBool("superNode.backFill") {
|
||||||
|
if err := c.BackFillFields(chain); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
configs[i] = sn
|
|
||||||
}
|
return c, nil
|
||||||
return configs, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BackFillFields is used to fill in the BackFill fields of the config
|
// BackFillFields is used to fill in the BackFill fields of the config
|
||||||
@ -160,21 +162,21 @@ func (sn *Config) BackFillFields(chain string) error {
|
|||||||
var err error
|
var err error
|
||||||
switch sn.Chain {
|
switch sn.Chain {
|
||||||
case shared.Ethereum:
|
case shared.Ethereum:
|
||||||
_, httpClient, err = getEthNodeAndClient(viper.GetString("superNode.ethereum.backFill.httpPath"))
|
_, httpClient, err = getEthNodeAndClient(viper.GetString("ethereum.httpPath"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case shared.Bitcoin:
|
case shared.Bitcoin:
|
||||||
httpClient = &rpcclient.ConnConfig{
|
httpClient = &rpcclient.ConnConfig{
|
||||||
Host: viper.GetString("superNode.bitcoin.backFill.httpPath"),
|
Host: viper.GetString("bitcoin.httpPath"),
|
||||||
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
|
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
|
||||||
DisableTLS: true, // Bitcoin core does not provide TLS by default
|
DisableTLS: true, // Bitcoin core does not provide TLS by default
|
||||||
Pass: viper.GetString("superNode.bitcoin.backFill.pass"),
|
Pass: viper.GetString("bitcoin.pass"),
|
||||||
User: viper.GetString("superNode.bitcoin.backFill.user"),
|
User: viper.GetString("bitcoin.user"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sn.HTTPClient = httpClient
|
sn.HTTPClient = httpClient
|
||||||
freq := viper.GetInt(fmt.Sprintf("superNode.%s.backFill.frequency", chain))
|
freq := viper.GetInt("superNode.frequency")
|
||||||
var frequency time.Duration
|
var frequency time.Duration
|
||||||
if freq <= 0 {
|
if freq <= 0 {
|
||||||
frequency = time.Second * 30
|
frequency = time.Second * 30
|
||||||
@ -182,7 +184,7 @@ func (sn *Config) BackFillFields(chain string) error {
|
|||||||
frequency = time.Second * time.Duration(freq)
|
frequency = time.Second * time.Duration(freq)
|
||||||
}
|
}
|
||||||
sn.Frequency = frequency
|
sn.Frequency = frequency
|
||||||
sn.BatchSize = uint64(viper.GetInt64(fmt.Sprintf("superNode.%s.backFill.batchSize", chain)))
|
sn.BatchSize = uint64(viper.GetInt64("superNode.batchSize"))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ type Config struct {
|
|||||||
func NewReSyncConfig() (*Config, error) {
|
func NewReSyncConfig() (*Config, error) {
|
||||||
c := new(Config)
|
c := new(Config)
|
||||||
var err error
|
var err error
|
||||||
ipfsPath := viper.GetString("superNode.ipfsPath")
|
ipfsPath := viper.GetString("resync.ipfsPath")
|
||||||
if ipfsPath == "" {
|
if ipfsPath == "" {
|
||||||
home, err := os.UserHomeDir()
|
home, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -94,24 +94,24 @@ func NewReSyncConfig() (*Config, error) {
|
|||||||
|
|
||||||
switch c.Chain {
|
switch c.Chain {
|
||||||
case shared.Ethereum:
|
case shared.Ethereum:
|
||||||
c.NodeInfo, c.HTTPClient, err = getEthNodeAndClient(viper.GetString("ethereum.node.httpPath"))
|
c.NodeInfo, c.HTTPClient, err = getEthNodeAndClient(viper.GetString("ethereum.httpPath"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case shared.Bitcoin:
|
case shared.Bitcoin:
|
||||||
c.NodeInfo = core.Node{
|
c.NodeInfo = core.Node{
|
||||||
ID: viper.GetString("bitcoin.node.nodeID"),
|
ID: viper.GetString("bitcoin.nodeID"),
|
||||||
ClientName: viper.GetString("bitcoin.node.clientName"),
|
ClientName: viper.GetString("bitcoin.clientName"),
|
||||||
GenesisBlock: viper.GetString("bitcoin.node.genesisBlock"),
|
GenesisBlock: viper.GetString("bitcoin.genesisBlock"),
|
||||||
NetworkID: viper.GetString("bitcoin.node.networkID"),
|
NetworkID: viper.GetString("bitcoin.networkID"),
|
||||||
}
|
}
|
||||||
// For bitcoin we load in node info from the config because there is no RPC endpoint to retrieve this from the node
|
// For bitcoin we load in node info from the config because there is no RPC endpoint to retrieve this from the node
|
||||||
c.HTTPClient = &rpcclient.ConnConfig{
|
c.HTTPClient = &rpcclient.ConnConfig{
|
||||||
Host: viper.GetString("bitcoin.node.httpPath"),
|
Host: viper.GetString("bitcoin.httpPath"),
|
||||||
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
|
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
|
||||||
DisableTLS: true, // Bitcoin core does not provide TLS by default
|
DisableTLS: true, // Bitcoin core does not provide TLS by default
|
||||||
Pass: viper.GetString("bitcoin.node.pass"),
|
Pass: viper.GetString("bitcoin.pass"),
|
||||||
User: viper.GetString("bitcoin.node.user"),
|
User: viper.GetString("bitcoin.user"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db := utils.LoadPostgres(c.DBConfig, c.NodeInfo)
|
db := utils.LoadPostgres(c.DBConfig, c.NodeInfo)
|
||||||
|
Loading…
Reference in New Issue
Block a user