Integrate go-nitro node for payments #256

Merged
ashwin merged 12 commits from deep-stack/ipld-eth-server:pm-integrate-go-nitro into payments 2023-10-13 09:03:11 +00:00
3 changed files with 20 additions and 18 deletions
Showing only changes of commit e6fb2d1e29 - Show all commits

View File

@ -39,21 +39,21 @@ func addDatabaseFlags(command *cobra.Command) {
func addNitroFlags(command *cobra.Command) {
// nitro flags
command.PersistentFlags().String("nitro-pk", "", "nitro pk")
command.PersistentFlags().String("nitro-chainPk", "", "nitro chainPk")
command.PersistentFlags().String("nitro-chainUrl", "", "nitro chainUrl")
command.PersistentFlags().String("nitro-naAddress", "", "nitro naAddress")
command.PersistentFlags().String("nitro-vpaAddress", "", "nitro vpaAddress")
command.PersistentFlags().String("nitro-caAddress", "", "nitro caAddress")
command.PersistentFlags().Bool("nitro-useDurableStore", false, "nitro useDurableStore")
command.PersistentFlags().String("nitro-durableStoreFolder", "", "nitro durableStoreFolder")
command.PersistentFlags().String("nitro-chain-pk", "", "nitro chainPk")
command.PersistentFlags().String("nitro-chain-url", "", "nitro chainUrl")
command.PersistentFlags().String("nitro-na-address", "", "nitro naAddress")
command.PersistentFlags().String("nitro-vpa-address", "", "nitro vpaAddress")
command.PersistentFlags().String("nitro-ca-address", "", "nitro caAddress")
command.PersistentFlags().Bool("nitro-use-durable-store", false, "nitro useDurableStore")
command.PersistentFlags().String("nitro-durable-store-folder", "", "nitro durableStoreFolder")
// nitro flag bindings
viper.BindPFlag("nitro.pk", command.PersistentFlags().Lookup("nitro-pk"))
viper.BindPFlag("nitro.chainPk", command.PersistentFlags().Lookup("nitro-chainPk"))
viper.BindPFlag("nitro.chainUrl", command.PersistentFlags().Lookup("nitro-chainUrl"))
viper.BindPFlag("nitro.naAddress", command.PersistentFlags().Lookup("nitro-naAddress"))
viper.BindPFlag("nitro.vpaAddress", command.PersistentFlags().Lookup("nitro-vpaAddress"))
viper.BindPFlag("nitro.caAddress", command.PersistentFlags().Lookup("nitro-caAddress"))
viper.BindPFlag("nitro.useDurableStore", command.PersistentFlags().Lookup("nitro-useDurableStore"))
viper.BindPFlag("nitro.durableStoreFolder", command.PersistentFlags().Lookup("nitro-durableStoreFolder"))
viper.BindPFlag("nitro.chainPk", command.PersistentFlags().Lookup("nitro-chain-pk"))
viper.BindPFlag("nitro.chainUrl", command.PersistentFlags().Lookup("nitro-chain-url"))
viper.BindPFlag("nitro.naAddress", command.PersistentFlags().Lookup("nitro-na-address"))
viper.BindPFlag("nitro.vpaAddress", command.PersistentFlags().Lookup("nitro-vpa-address"))
viper.BindPFlag("nitro.caAddress", command.PersistentFlags().Lookup("nitro-ca-address"))
viper.BindPFlag("nitro.useDurableStore", command.PersistentFlags().Lookup("nitro-use-durable-store"))
viper.BindPFlag("nitro.durableStoreFolder", command.PersistentFlags().Lookup("nitro-durable-store"))
}

View File

@ -90,7 +90,6 @@ func serve() {
server.Serve(wg)
// TODO: Create required config for Nitro node
nitroNode, err := initializeNitroNode(serverConfig.Nitro)
if err != nil {
logWithCommand.Fatal(err)
@ -105,7 +104,7 @@ func serve() {
voucherValidator := paymentsmanager.InProcessVoucherValidator{PaymentsManager: pm}
// TODO: Configure
// TODO: Read from config file
queryRates := map[string]*big.Int{
"eth_getBlockByNumber": big.NewInt(50),
"eth_getBlockByHash": big.NewInt(50),
@ -113,6 +112,7 @@ func serve() {
"eth_getLogs": big.NewInt(50),
}
// TODO: Read from config file
rpcPort := 4005
nitroRpcServer, err := initializeNitroRpcServer(nitroNode, rpcPort)
if err != nil {
@ -152,6 +152,7 @@ func serve() {
wg.Wait()
}
// TODO: Absorb voucherValidator and queryRates args into existing ones
func startServers(server s.Server, settings *s.Config, voucherValidator paymentsmanager.VoucherValidator, queryRates map[string]*big.Int) error {
if settings.IPCEnabled {
logWithCommand.Debug("starting up IPC server")
@ -389,9 +390,9 @@ func init() {
viper.BindPFlag("validator.everyNthBlock", serveCmd.PersistentFlags().Lookup("validator-every-nth-block"))
}
// https://github.com/cerc-io/go-nitro/releases/tag/github.com/cerc-io/go-nitro v0.1.1-ts-port-0.1.7
// https://github.com/cerc-io/go-nitro/blob/release-v0.1.1-ts-port-0.1.7/internal/node/node.go#L17
func initializeNitroNode(nitroConfig *s.NitroConfig) (*nitroNode.Node, error) {
// TODO: Configure
// TODO: Read from config file
pkString := nitroConfig.Pk
useDurableStore := nitroConfig.UseDurableStore
durableStoreFolder := nitroConfig.DurableStoreFolder

View File

@ -30,6 +30,7 @@ import (
)
// StartHTTPEndpoint starts the HTTP RPC endpoint, configured with cors/vhosts/modules.
// TODO: Absorb voucherValidator and queryRates args into existing ones
func StartHTTPEndpoint(endpoint string, apis []rpc.API, modules []string, cors []string, vhosts []string, timeouts rpc.HTTPTimeouts, voucherValidator paymentsmanager.VoucherValidator, queryRates map[string]*big.Int) (*rpc.Server, error) {
srv := rpc.NewServer()
err := node.RegisterApis(apis, modules, srv)