Skip to content

Commit

Permalink
Merge pull request #1775 from statechannels/update-with-main
Browse files Browse the repository at this point in the history
Merge main into demo branch
  • Loading branch information
lalexgap authored Sep 20, 2023
2 parents 095ea1d + 1b85ad0 commit 334dfdf
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 201 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy-cloud-nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ jobs:

- name: Build Docker image
if: github.event.inputs.build-image == 'true'
run: make docker/cloud/build
run: make docker/nitro/build

- name: Login to DigitalOcean Docker Registry
if: github.event.inputs.build-image == 'true'
run: docker login -u ${{ secrets.DO_API_KEY }} -p ${{ secrets.DO_API_KEY }} registry.digitalocean.com

- name: Push Docker image to DigitalOcean
if: github.event.inputs.build-image == 'true'
run: make docker/cloud/push
run: make docker/nitro/push

deploy-iris:
needs: build-image
Expand Down
44 changes: 14 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
docker/cloud/build:
docker build -f docker/cloud/Dockerfile -t go-nitro-cloud .
docker/cloud/start:
docker remove go-nitro-cloud || true
docker run -it -d --name go-nitro-cloud -p 3005:3005 -p 4005:4005 -p 5005:5005 -e NITRO_CONFIG_PATH="./nitro_config/iris.toml" go-nitro-cloud
docker/nitro/build:
docker build -f docker/nitro/Dockerfile -t go-nitro .

docker/cloud/push:
docker tag go-nitro-cloud:latest registry.digitalocean.com/magmo/go-nitro:latest
docker/nitro/start:
docker remove go-nitro || true
docker run -it -d --name go-nitro \
-p 3005:3005 -p 4005:4005 -p 5005:5005 \
-e NITRO_CONFIG_PATH="./nitro_config/iris.toml" \
-v ./docker/nitro:/app/nitro_config \
-v ./tls:/app/tls \
-v ./data:/app/data \
go-nitro

docker/nitro/push:
docker tag go-nitro:latest registry.digitalocean.com/magmo/go-nitro:latest
docker push registry.digitalocean.com/magmo/go-nitro:latest

docker/local/build:
docker build -f docker/local/Dockerfile -t go-nitro-local .

docker/local/start:
docker remove go-nitro-local || true
docker run -it -d --name go-nitro-local -p 3005:3005 -p 4005:4005 -p 5005:5005 go-nitro-local

docker/paymentproxy/build:
docker build -f docker/paymentproxy/Dockerfile -t nitro-payment-proxy .

Expand All @@ -26,21 +26,5 @@ docker/paymentproxy/start:
docker remove payment-proxy || true
docker run -it -d --name payment-proxy -p 5511:5511 -e PROXY_PORT=5511 payment-proxy

docker/network/build:
docker build -f docker/Dockerfile -t go-nitro .

docker/network/start:
docker remove go-nitro || true
docker run -it -d --name go-nitro -p 4005:4005 -p 4006:4006 -p 4007:4007 go-nitro

docker/network/stop:
docker stop go-nitro
docker rm go-nitro

docker/network/restart: docker/network/stop docker/network/start

docker/network/attach:
docker exec -it go-nitro bash

ui/build:
yarn workspace nitro-gui build
16 changes: 0 additions & 16 deletions docker/Dockerfile

This file was deleted.

14 changes: 0 additions & 14 deletions docker/entrypoint.sh

This file was deleted.

17 changes: 0 additions & 17 deletions docker/local/Dockerfile

This file was deleted.

22 changes: 0 additions & 22 deletions docker/local/config.toml

This file was deleted.

2 changes: 1 addition & 1 deletion docker/cloud/Dockerfile → docker/nitro/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN yarn --version
# Copy files into image
WORKDIR /app
COPY . .
COPY ./docker/cloud ./nitro_config
COPY ./docker/nitro ./nitro_config

# Build the binary
RUN yarn workspace nitro-gui install
Expand Down
6 changes: 3 additions & 3 deletions docker/cloud/README.md → docker/nitro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The Dockerfile in this directory defines a container that can act as a `bootnode

## Create image

Update the `docker/cloud/config.toml` file (or pass as env vars) with the private keys you will use for the state channel address and chain address. You can run the following command to generate a fresh key pair:
Update the `docker/nitro/config.toml` file (or pass as env vars) with the private keys you will use for the state channel address and chain address. You can run the following command to generate a fresh key pair:

```
go run ./cmd/generate-keypair
Expand All @@ -15,14 +15,14 @@ You can use [this faucet](https://faucet.calibration.fildev.network/funds.html)
Build the image:

```
make docker/cloud/build
make docker/nitro/build
```

## Push image to docker registry

```
docker login -u <api_key> -p <api_key> registry.digitalocean.com
make docker/cloud/push
make docker/nitro/push
```

## Create ssh key-pair
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 0 additions & 10 deletions internal/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ import (
"github.com/statechannels/go-nitro/types"
)

type ChainOpts struct {
ChainUrl string
ChainStartBlock uint64
ChainAuthToken string
ChainPk string
NaAddress common.Address
VpaAddress common.Address
CaAddress common.Address
}

func StartAnvil() (*exec.Cmd, error) {
chainCmd := exec.Command("anvil", "--chain-id", "1337", "--block-time", "1", "--silent")
chainCmd.Stdout = os.Stdout
Expand Down
19 changes: 5 additions & 14 deletions internal/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,23 @@ import (
"fmt"
"log/slog"

"github.com/ethereum/go-ethereum/common"
"github.com/statechannels/go-nitro/internal/chain"
"github.com/statechannels/go-nitro/node"
"github.com/statechannels/go-nitro/node/engine"
"github.com/statechannels/go-nitro/node/engine/chainservice"
"github.com/statechannels/go-nitro/node/engine/store"
"github.com/tidwall/buntdb"

p2pms "github.com/statechannels/go-nitro/node/engine/messageservice/p2p-message-service"
)

func InitializeNode(pkString string, chainOpts chain.ChainOpts,
useDurableStore bool, durableStoreFolder string, msgPort int, bootPeers []string, publicIp string,
) (*node.Node, *store.Store, *p2pms.P2PMessageService, chainservice.ChainService, error) {
if pkString == "" {
panic("pk must be set")
}

pk := common.Hex2Bytes(pkString)
ourStore, err := store.NewStore(pk, useDurableStore, durableStoreFolder, buntdb.Config{})
func InitializeNode(chainOpts chainservice.ChainOpts, storeOpts store.StoreOpts, messageOpts p2pms.MessageOpts) (*node.Node, *store.Store, *p2pms.P2PMessageService, chainservice.ChainService, error) {
ourStore, err := store.NewStore(storeOpts)
if err != nil {
return nil, nil, nil, nil, err
}

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

// Compare chainOpts.ChainStartBlock to lastBlockNum seen in store. The larger of the two
// gets passed as an argument when creating NewEthChainService
Expand Down
24 changes: 21 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
"syscall"

"github.com/ethereum/go-ethereum/common"
"github.com/statechannels/go-nitro/internal/chain"
"github.com/statechannels/go-nitro/internal/logging"
"github.com/statechannels/go-nitro/internal/node"
"github.com/statechannels/go-nitro/internal/rpc"
"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/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
)
Expand Down Expand Up @@ -100,12 +102,14 @@ func main() {
DefaultText: "hardhat / anvil default",
Category: CONNECTIVITY_CATEGORY,
Destination: &chainUrl,
EnvVars: []string{"CHAIN_URL"},
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: CHAIN_AUTH_TOKEN,
Usage: "The bearer token used for auth when making requests to the chain's RPC endpoint.",
Category: CONNECTIVITY_CATEGORY,
Destination: &chainAuthToken,
EnvVars: []string{"CHAIN_AUTH_TOKEN"},
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: CHAIN_PK,
Expand All @@ -120,6 +124,7 @@ func main() {
Value: 0,
Category: CONNECTIVITY_CATEGORY,
Destination: &chainStartBlock,
EnvVars: []string{"CHAIN_START_BLOCK"},
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: NA_ADDRESS,
Expand Down Expand Up @@ -203,7 +208,7 @@ func main() {
Flags: flags,
Before: altsrc.InitInputSourceWithContext(flags, altsrc.NewTomlSourceFromFlagFunc(CONFIG)),
Action: func(cCtx *cli.Context) error {
chainOpts := chain.ChainOpts{
chainOpts := chainservice.ChainOpts{
ChainUrl: chainUrl,
ChainStartBlock: chainStartBlock,
ChainAuthToken: chainAuthToken,
Expand All @@ -213,14 +218,27 @@ func main() {
CaAddress: common.HexToAddress(caAddress),
}

storeOpts := store.StoreOpts{
PkBytes: common.Hex2Bytes(pkString),
UseDurableStore: useDurableStore,
DurableStoreFolder: durableStoreFolder,
}

var peerSlice []string
if bootPeers != "" {
peerSlice = strings.Split(bootPeers, ",")
}

messageOpts := p2pms.MessageOpts{
PkBytes: common.Hex2Bytes(pkString),
Port: msgPort,
BootPeers: peerSlice,
PublicIp: publicIp,
}

logging.SetupDefaultLogger(os.Stdout, slog.LevelDebug)

node, _, _, _, err := node.InitializeNode(pkString, chainOpts, useDurableStore, durableStoreFolder, msgPort, peerSlice, publicIp)
node, _, _, _, err := node.InitializeNode(chainOpts, storeOpts, messageOpts)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 334dfdf

Please sign in to comment.