Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable websocket transport and implement payments manager #80

Merged
merged 18 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
8f758d6
Add websocket transport in message service to connect with browser cl…
nikugogoi Jun 28, 2023
b883a18
Use mplex muxer (#4)
prathamesh0 Jul 12, 2023
d824131
Add workflow to publish `nitro-protocol` package (#5)
nikugogoi Aug 25, 2023
d938f46
Upgrade `nitro-protocol` package to `2.0.0-alpha.4-ts-port-0.1.1` (#7)
nikugogoi Sep 6, 2023
5d24303
Use Node version 18.15 for publishing package (#8)
nikugogoi Sep 6, 2023
4bd2a2d
Add back `receivePeerInfo` method for connecting with ts-nitro (#9)
nikugogoi Sep 12, 2023
ab1eb66
Use slog in receivePeerInfo and revert use of mplex (#10)
nikugogoi Sep 15, 2023
c7e1bca
Add WebSocket message port in InitializeNode method (#11)
nikugogoi Sep 25, 2023
92a7912
Disable compression in payment proxy transport and add proxy in the D…
prathamesh0 Oct 3, 2023
2afbb39
Changes required for running proxy server and `nitro-rpc-client` in p…
nikugogoi Oct 5, 2023
280c6d0
Parse RPC method from request body in proxy server (#15)
nikugogoi Oct 5, 2023
96cea67
Improve filtering for paid RPC methods in payment proxy (#16)
prathamesh0 Oct 5, 2023
4e73249
Setup a payments manager with voucher cache (#17)
prathamesh0 Oct 13, 2023
ff6ac64
Implement RPC API for voucher validation (#18)
prathamesh0 Oct 18, 2023
8a35266
Reduce voucher check retry interval (#20)
prathamesh0 Oct 19, 2023
760b373
Add steps to run go-nitro nodes (#23)
prathamesh0 Apr 26, 2024
f9bc083
Update steps to run go-nitro nodes and make payments (#24)
nikugogoi May 9, 2024
0711b79
Revert change to remove default TLS cert in go-nitro node CLI (#14)
neerajvijay1997 Aug 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.54.2
args: --timeout 3m0s --verbose --modules-download-mode readonly
args: --timeout 5m0s --verbose --modules-download-mode readonly

- name: Run staticcheck # see: staticcheck.io
uses: dominikh/staticcheck-action@v1.3.0
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish npm package to gitea
on:
release:
types: [published]
jobs:
npm_publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# https://github.com/NomicFoundation/hardhat/issues/3877
- name: Use Node.js 18.15
uses: actions/setup-node@v3
with:
node-version: "18.15.0"
- name: "Install dependencies and build packages"
run: |
cd ./packages/nitro-protocol
npm ci --legacy-peer-deps
- name: Configure git.vdb.to npm registry
run: |
npm config set registry https://git.vdb.to/api/packages/cerc-io/npm/
- name: Authenticate to git.vdb.to registry
run: |
npm config set -- '//git.vdb.to/api/packages/cerc-io/npm/:_authToken' "${{ secrets.GITEA_PUBLISH_TOKEN }}"
- name: npm publish
run: |
cd ./nitro-protocol
npm publish
4 changes: 2 additions & 2 deletions bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ func (b *Bridge) Start(configOpts BridgeConfig) (nodeL1 *node.Node, nodeL2 *node

messageOptsL1 := p2pms.MessageOpts{
PkBytes: common.Hex2Bytes(configOpts.StateChannelPK),
Port: configOpts.NodeL1MsgPort,
TcpPort: configOpts.NodeL1MsgPort,
BootPeers: nil,
PublicIp: configOpts.BridgePublicIp,
ExtMultiAddr: configOpts.NodeL1ExtMultiAddr,
}

messageOptsL2 := p2pms.MessageOpts{
PkBytes: common.Hex2Bytes(configOpts.StateChannelPK),
Port: configOpts.NodeL2MsgPort,
TcpPort: configOpts.NodeL2MsgPort,
BootPeers: nil,
PublicIp: configOpts.BridgePublicIp,
ExtMultiAddr: configOpts.NodeL2ExtMultiAddr,
Expand Down
2 changes: 1 addition & 1 deletion cmd/create-channels/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func createChannels() error {
logging.SetupDefaultFileLogger(LOG_FILE, slog.LevelDebug)

url := fmt.Sprintf(":%d/api/v1", participantOpts.RpcPort)
clientConnection, err := http.NewHttpTransportAsClient(url, 500*time.Millisecond)
clientConnection, err := http.NewHttpTransportAsClient(url, true, 500*time.Millisecond)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/create-ledger-channel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func main() {
Usage: "Creates a ledger channel with the specified counterparty and amount",
Flags: flags,
Action: func(cCtx *cli.Context) error {
clientConnection, err := http.NewHttpTransportAsClient(cCtx.String(NITRO_ENDPOINT), 10*time.Millisecond)
clientConnection, err := http.NewHttpTransportAsClient(cCtx.String(NITRO_ENDPOINT), true, 10*time.Millisecond)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/start-bridge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/statechannels/go-nitro/cmd/utils"
"github.com/statechannels/go-nitro/internal/logging"
"github.com/statechannels/go-nitro/internal/rpc"
"github.com/statechannels/go-nitro/paymentsmanager"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
)
Expand Down Expand Up @@ -266,12 +267,12 @@ func main() {
}

// RPC servers for individual nodes used only for debugging
nodeL1RpcServer, err := rpc.InitializeNodeRpcServer(nodeL1, NODEL1_RPC_PORT, false, &cert)
nodeL1RpcServer, err := rpc.InitializeNodeRpcServer(nodeL1, paymentsmanager.PaymentsManager{}, NODEL1_RPC_PORT, false, &cert)
if err != nil {
return err
}

nodeL2RpcServer, err := rpc.InitializeNodeRpcServer(nodeL2, NODEL2_RPC_PORT, false, &cert)
nodeL2RpcServer, err := rpc.InitializeNodeRpcServer(nodeL2, paymentsmanager.PaymentsManager{}, NODEL2_RPC_PORT, false, &cert)
if err != nil {
return err
}
Expand Down
16 changes: 12 additions & 4 deletions cmd/start-payment-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
)

const (
NITRO_ENDPOINT = "nitroendpoint"
PROXY_ADDRESS = "proxyaddress"
DESTINATION_URL = "destinationurl"
COST_PER_BYTE = "costperbyte"
NITRO_ENDPOINT = "nitroendpoint"
PROXY_ADDRESS = "proxyaddress"
DESTINATION_URL = "destinationurl"
COST_PER_BYTE = "costperbyte"
ENABLE_PAID_RPC_METHODS = "enablepaidrpcmethods"

TLS_CERT_FILEPATH = "tlscertfilepath"
TLS_KEY_FILEPATH = "tlskeyfilepath"
Expand Down Expand Up @@ -61,6 +62,12 @@ func main() {
Usage: "Filepath to the TLS private key. If not specified, TLS will not be used.",
Value: "",
},
&cli.BoolFlag{
Name: ENABLE_PAID_RPC_METHODS,
Usage: "Flag to enable/disable payment for RPC methods",
Value: false,
Aliases: []string{"r"},
},
},
Action: func(c *cli.Context) error {
proxyEndpoint := c.String(PROXY_ADDRESS)
Expand All @@ -75,6 +82,7 @@ func main() {
c.Uint64(COST_PER_BYTE),
c.String(TLS_CERT_FILEPATH),
c.String(TLS_KEY_FILEPATH),
c.Bool(ENABLE_PAID_RPC_METHODS),
)

return proxy.Start()
Expand Down
1 change: 1 addition & 0 deletions cmd/test-configs/alice.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
usedurablestore = true

msgport = 3005
wsmsgport = 6005
rpcport = 4005
guiport = 5005

Expand Down
1 change: 1 addition & 0 deletions cmd/test-configs/bob.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ usedurablestore = true

guiport = 5007
msgport = 3007
wsmsgport = 6007
rpcport = 4007

# PeerID: 16Uiu2HAmJDxLM8rSybX78FH51iZq9PdrwCoCyyHRBCndNzcAYMes
Expand Down
1 change: 1 addition & 0 deletions cmd/test-configs/irene.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ usedurablestore = true

guiport = 5006
msgport = 3006
wsmsgport = 6006
rpcport = 4006

# PeerID: 16Uiu2HAmHntR3SGeS7iF2tdeNBefSahXBhmTrqVozVLHydxzkaZn
Expand Down
2 changes: 2 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// Specifies whether to deploy the adjudicator and create2deployer contracts.
// -msgport int
// Specifies the tcp port for the message service. (default 3005)
// -wsmsgport int
// Specifies the websocket port for the message service. (default 6005)
// -naaddress string
// Specifies the address of the nitro adjudicator contract. Default is the address computed by the Create2Deployer contract. (default "0xC6A55E07566416274dBF020b5548eecEdB56290c")
// -pk string
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ require (
require (
github.com/BurntSushi/toml v1.3.2
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/hashicorp/golang-lru/v2 v2.0.5
github.com/libp2p/go-libp2p-kad-dht v0.24.2
github.com/lmittmann/tint v1.0.2
github.com/tidwall/buntdb v1.2.10
github.com/urfave/cli/v2 v2.25.7

)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d h1:dg1dEPuWpEqDnvIw251EVy4zlP8gWbsGj4BsUKCRpYs=
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru/v2 v2.0.5 h1:wW7h1TG88eUIJ2i69gaE3uNVtEPIagzhGvHgwfx2Vm4=
github.com/hashicorp/golang-lru/v2 v2.0.5/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 h1:X4egAf/gcS1zATw6wn4Ej8vjuVGxeHdan+bRb2ebyv4=
github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc=
Expand Down
2 changes: 1 addition & 1 deletion internal/node/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func InitializeL2Node(l2ChainOpts chainservice.L2ChainOpts, storeOpts store.Stor
return nil, nil, nil, nil, err
}

slog.Info("Initializing message service on port " + fmt.Sprint(messageOpts.Port) + "...")
slog.Info("Initializing message service on port " + fmt.Sprint(messageOpts.TcpPort) + "...")
messageOpts.SCAddr = *ourStore.GetAddress()
messageService := p2pms.NewMessageService(messageOpts)

Expand Down
3 changes: 1 addition & 2 deletions internal/node/node.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package node

import (
"fmt"
"log/slog"

"github.com/statechannels/go-nitro/node"
Expand All @@ -18,7 +17,7 @@ func InitializeNode(chainOpts chainservice.ChainOpts, storeOpts store.StoreOpts,
return nil, nil, nil, nil, err
}

slog.Info("Initializing message service on port " + fmt.Sprint(messageOpts.Port) + "...")
slog.Info("Initializing message service", "tcp port", messageOpts.TcpPort, "web socket port", messageOpts.WsMsgPort)
messageOpts.SCAddr = *ourStore.GetAddress()
messageService := p2pms.NewMessageService(messageOpts)

Expand Down
5 changes: 3 additions & 2 deletions internal/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import (

"github.com/statechannels/go-nitro/bridge"
"github.com/statechannels/go-nitro/node"
"github.com/statechannels/go-nitro/paymentsmanager"
"github.com/statechannels/go-nitro/rpc"
"github.com/statechannels/go-nitro/rpc/transport"
httpTransport "github.com/statechannels/go-nitro/rpc/transport/http"
"github.com/statechannels/go-nitro/rpc/transport/nats"
)

func InitializeNodeRpcServer(node *node.Node, rpcPort int, useNats bool, cert *tls.Certificate) (*rpc.NodeRpcServer, error) {
func InitializeNodeRpcServer(node *node.Node, paymentManager paymentsmanager.PaymentsManager, rpcPort int, useNats bool, cert *tls.Certificate) (*rpc.NodeRpcServer, error) {
transport, err := initializeTransport(rpcPort, useNats, cert)
if err != nil {
return nil, err
}

rpcServer, err := rpc.NewNodeRpcServer(node, transport)
rpcServer, err := rpc.NewNodeRpcServer(node, paymentManager, transport)
if err != nil {
return nil, err
}
Expand Down
12 changes: 11 additions & 1 deletion internal/testactors/actors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Actor struct {
Name ActorName
ChainAccountIndex uint
Port uint
WSPort uint
}

func (a Actor) Destination() types.Destination {
Expand All @@ -25,7 +26,10 @@ func (a Actor) Address() types.Address {
return crypto.GetAddressFromSecretKeyBytes(a.PrivateKey)
}

const START_PORT = 3200
const (
START_PORT = 3200
WS_START_PORT = 6200
)

// Alice has the address 0xAAA6628Ec44A8a742987EF3A114dDFE2D4F7aDCE
// peerId: 16Uiu2HAmSjXJqsyBJgcBUU2HQmykxGseafSatbpq5471XmuaUqyv
Expand All @@ -35,6 +39,7 @@ var Alice Actor = Actor{
"alice",
0,
START_PORT + 0,
WS_START_PORT + 0,
}

// Bob has the address 0xBBB676f9cFF8D242e9eaC39D063848807d3D1D94
Expand All @@ -45,6 +50,7 @@ var Bob Actor = Actor{
"bob",
1,
START_PORT + 1,
WS_START_PORT + 1,
}

// Ivan has the address 0xA8d2D06aCE9c7FFc24Ee785C2695678aeCDfd7A0
Expand All @@ -55,6 +61,7 @@ var Ivan Actor = Actor{
"ivan",
2,
START_PORT + 2,
WS_START_PORT + 2,
}

// Irene has the address 0x111A00868581f73AB42FEEF67D235Ca09ca1E8db
Expand All @@ -65,6 +72,7 @@ var Irene Actor = Actor{
"irene",
3,
START_PORT + 3,
WS_START_PORT + 3,
}

// Actors for L2
Expand All @@ -77,6 +85,7 @@ var AlicePrime Actor = Actor{
"alice",
0,
START_PORT + 4,
WS_START_PORT + 4,
}

// BobPrime has the address 0xBBB676f9cFF8D242e9eaC39D063848807d3D1D94
Expand All @@ -87,4 +96,5 @@ var BobPrime Actor = Actor{
"bob",
1,
START_PORT + 5,
WS_START_PORT + 5,
}
38 changes: 33 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/signal"
"strings"
"sync"
"syscall"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -18,6 +19,7 @@ import (
"github.com/statechannels/go-nitro/node/engine/chainservice"
p2pms "github.com/statechannels/go-nitro/node/engine/messageservice/p2p-message-service"
"github.com/statechannels/go-nitro/node/engine/store"
"github.com/statechannels/go-nitro/paymentsmanager"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
)
Expand All @@ -38,6 +40,7 @@ func main() {
BRIDGE_ADDRESS = "bridgeaddress"
PUBLIC_IP = "publicip"
MSG_PORT = "msgport"
WS_MSG_PORT = "wsmsgport"
RPC_PORT = "rpcport"
GUI_PORT = "guiport"
BOOT_PEERS = "bootpeers"
Expand All @@ -60,7 +63,7 @@ func main() {
TLS_KEY_FILEPATH = "tlskeyfilepath"
)
var pkString, chainUrl, chainAuthToken, naAddress, vpaAddress, caAddress, bridgeAddress, chainPk, durableStoreFolder, bootPeers, publicIp, extMultiAddr string
var msgPort, rpcPort, guiPort int
var msgPort, wsMsgPort, rpcPort, guiPort int
var chainStartBlock uint64
var useNats, useDurableStore, l2 bool

Expand Down Expand Up @@ -184,6 +187,13 @@ func main() {
Category: CONNECTIVITY_CATEGORY,
Destination: &msgPort,
}),
altsrc.NewIntFlag(&cli.IntFlag{
Name: WS_MSG_PORT,
Usage: "Specifies the websocket port for the message service.",
Value: 6005,
Category: "Connectivity:",
Destination: &wsMsgPort,
}),
altsrc.NewIntFlag(&cli.IntFlag{
Name: RPC_PORT,
Usage: "Specifies the tcp port for the rpc server.",
Expand Down Expand Up @@ -249,7 +259,8 @@ func main() {

messageOpts := p2pms.MessageOpts{
PkBytes: common.Hex2Bytes(pkString),
Port: msgPort,
TcpPort: msgPort,
WsMsgPort: wsMsgPort,
BootPeers: peerSlice,
PublicIp: publicIp,
ExtMultiAddr: extMultiAddr,
Expand Down Expand Up @@ -288,16 +299,33 @@ func main() {
if err != nil {
return err
}
var cert tls.Certificate

paymentsManager, err := paymentsmanager.NewPaymentsManager(node)
if err != nil {
return err
}

wg := new(sync.WaitGroup)
defer wg.Wait()

paymentsManager.Start(wg)
defer func() {
err := paymentsManager.Stop()
if err != nil {
panic(err)
}
}()

var cert *tls.Certificate
if tlsCertFilepath != "" && tlsKeyFilepath != "" {
cert, err = tls.LoadX509KeyPair(tlsCertFilepath, tlsKeyFilepath)
loadedCert, err := tls.LoadX509KeyPair(tlsCertFilepath, tlsKeyFilepath)
if err != nil {
panic(err)
}
cert = &loadedCert
}

rpcServer, err := rpc.InitializeNodeRpcServer(node, rpcPort, useNats, &cert)
rpcServer, err := rpc.InitializeNodeRpcServer(node, paymentsManager, rpcPort, useNats, cert)
if err != nil {
return err
}
Expand Down
Loading
Loading