From 79936aefbb3931d32f6df6a9b91123e70ae65425 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 9 Oct 2023 19:22:42 +0530 Subject: [PATCH] Run Nitro node as part of serve command --- cmd/serve.go | 13 +++++++++++++ go.mod | 4 +++- pkg/nitro/node.go | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 pkg/nitro/node.go diff --git a/cmd/serve.go b/cmd/serve.go index a1fb8621..8a4f110a 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -26,6 +26,7 @@ import ( "time" "github.com/cerc-io/ipld-eth-server/v5/pkg/log" + "github.com/cerc-io/ipld-eth-server/v5/pkg/nitro" "github.com/ethereum/go-ethereum/rpc" "github.com/mailgun/groupcache/v2" "github.com/spf13/cobra" @@ -95,6 +96,14 @@ func serve() { logWithCommand.Debug("state validator disabled") } + // TODO: Create required config for Nitro node + + // TODO: Create a new Nitro node using the config + nitro, _ := nitro.NewNitroNode() + + // TODO: Start the Nitro node, pass wg + nitro.Start(wg) + shutdown := make(chan os.Signal, 1) signal.Notify(shutdown, os.Interrupt) <-shutdown @@ -102,6 +111,10 @@ func serve() { graphQL.Stop() } server.Stop() + + // TODO: Stop nitro node + nitro.Stop() + wg.Wait() } diff --git a/go.mod b/go.mod index ce49f25b..2db98e89 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/cerc-io/ipfs-ethdb/v5 v5.0.0-alpha github.com/cerc-io/ipld-eth-statedb v0.0.5-alpha github.com/cerc-io/plugeth-statediff v0.1.1 - github.com/ethereum/go-ethereum v1.11.6 + github.com/ethereum/go-ethereum v1.12.0 // TODO: Investigate github.com/google/uuid v1.3.0 github.com/graph-gophers/graphql-go v1.3.0 github.com/ipfs/go-cid v0.4.1 @@ -289,3 +289,5 @@ replace ( github.com/cerc-io/eth-ipfs-state-validator/v5 => git.vdb.to/deep-stack/eth-ipfs-state-validator/v5 v5.1.1-alpha.0.20231012040741-c76238e3501b github.com/cerc-io/ipfs-ethdb/v5 => git.vdb.to/deep-stack/ipfs-ethdb/v5 v5.0.1-alpha.0.20231003124335-b6cf70668a07 ) + +replace github.com/statechannels/go-nitro v0.1.1 => github.com/cerc-io/go-nitro v0.1.1-ts-port-0.1.5 diff --git a/pkg/nitro/node.go b/pkg/nitro/node.go new file mode 100644 index 00000000..8ca98430 --- /dev/null +++ b/pkg/nitro/node.go @@ -0,0 +1,48 @@ +// VulcanizeDB +// Copyright © 2023 Vulcanize + +// 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 . + +package nitro + +import ( + "sync" +) + +// TODO: Implement +// Struct representing the in-process Nitro node +type NitroNode struct { + // Used to signal shutdown of the node + QuitChan chan bool +} + +func NewNitroNode() (NitroNode, error) { + // TODO: Implement + return NitroNode{}, nil +} + +func (n *NitroNode) Start(wg *sync.WaitGroup) { + // TODO: Implement + go func() { + wg.Add(1) + defer wg.Done() + <-n.QuitChan + }() +} + +func (n *NitroNode) Stop() error { + // TODO: Implement + close(n.QuitChan) + return nil +}