Run Nitro node as part of serve command

This commit is contained in:
Prathamesh Musale 2023-10-09 19:22:42 +05:30
parent 6e8c80b2bd
commit 79936aefbb
3 changed files with 64 additions and 1 deletions

View File

@ -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()
}

4
go.mod
View File

@ -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

48
pkg/nitro/node.go Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
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
}