Skip to content

Commit

Permalink
feat: Add IPFS client to retrieve results (#400)
Browse files Browse the repository at this point in the history
* feat: Await job result from Bacalhau

* wip: Retrieve results from IPFS

* wip: Bacalhau target IPFS node

* add ipfs client to download results

* chore: Ensure bacalhau-results directory exists

* chore: Add ipfs-connect option

* refactor: Add IPFS client to Bacalhau executor

* chore: Add IPFS client to mediator

* chore: Remove print line and rearrange

* chore: Remove unused copyJobResults function

* docs: Add IPFS node docs

* feat: add ipfs to docker compose

* chore: Remove sleep from job completion poll loop

---------

Co-authored-by: James Walker <walkah@walkah.net>
  • Loading branch information
bgins and walkah authored Oct 9, 2024
1 parent 90a248d commit 85f92b9
Show file tree
Hide file tree
Showing 19 changed files with 503 additions and 542 deletions.
25 changes: 22 additions & 3 deletions LOCAL_DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ A minimal local Lilypad network consists of the following pieces of infrastructu
- One blockchain node
- One solver service
- One job creator service
- One IPFS node
- One bacalhau node
- One resource provider service

Expand All @@ -40,15 +41,33 @@ These are the commands to run the node and boot the network: `./stack chain-clea
A helper script is in place to verify balances on the accounts: `cd hardhat && npx hardhat run scripts/balances.ts --network dev`

### 2. Solver service

This process can be executed directly if Golang has been installed or in a docker container. The commands are `./stack solver`,`./stack solver-docker-build` and `./stack solver-docker-run` respectively. The `solver` service will output a log line that reads that "the solver has been registered successfully" or "the solver already exists". It is best to wait for this output before starting the services that will try to connect to the `solver`.

### 3. Job creator

This process can be executed directly if Golang has been installed or in a docker container. The commands are `./stack job-creator`,`./stack job-creator-docker-build` and `./stack job-creator-docker-run` respectively. The `job-creator` service's main function is to listen to events from the blockchain to execute jobs and when it receives such an event it will relay the payload to the `solver`. So think about the `job-creator` as the "on-chain solver".

### 4. Bacalhau node
### 4. IPFS node

This process can be run directly using an IPFS Kubo binary. [Download a Kubo binary](https://dist.ipfs.tech/#kubo) for your platform and architecture. Initiliaze an repository where Kubo will store settings and internal data:

```sh
ipfs init
```

Start the IPFS node with the default settings:

```sh
ipfs daemon
```

Kubo should report an RPC API server listening on `/ip4/127.0.0.1/tcp/5001`. Our Bacalhau node stores job results on this IPFS node.

### 5. Bacalhau node

For the time being this process has to be executed directly. This means following the instructions to download their cli tool and expose it as a bin that can be used. Here's how to install the `bacalhau` tool:

#### Linux
```sh
# install the latest
Expand All @@ -68,7 +87,7 @@ mv bacalhau /usr/local/bin

Once the tool has been installed, the following command can be used to start the node: `./stack bacalhau-node`.

### 5. Resource provider
### 6. Resource provider

For the time being this process has to be executed directly and needs Golang to be installed. This is the command to execute the service: `./stack resource-provider`. If you have a GPU you can use the following flag to use it: `./stack resource-provider --offer-gpu 1`

Expand Down Expand Up @@ -143,4 +162,4 @@ If you find that you have issues with the Job Creator not picking up your `run-c
2. Run the following command to clean up your Docker environment: `./stack compose-down && docker system prune -a`
3. Open your Docker Desktop app, go to `Volumes` and delete `lilypad_chain-data` as there might be stale data in the volume not allowing you to properly execute all the transactions
4. Re-run your Docker stack using: `./stack compose-build && ./stack compose-init && ./stack compose-up`
5. Re-run the onchain cowsay job: `./stack run-cowsay-onchain`
5. Re-run the onchain cowsay job: `./stack run-cowsay-onchain`
10 changes: 9 additions & 1 deletion cmd/lilypad/mediator.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package lilypad

import (
"fmt"

"github.com/lilypad-tech/lilypad/pkg/executor/bacalhau"
"github.com/lilypad-tech/lilypad/pkg/ipfs"
"github.com/lilypad-tech/lilypad/pkg/mediator"
optionsfactory "github.com/lilypad-tech/lilypad/pkg/options"
"github.com/lilypad-tech/lilypad/pkg/system"
Expand Down Expand Up @@ -45,7 +48,12 @@ func runMediator(cmd *cobra.Command, options mediator.MediatorOptions) error {
return err
}

executor, err := bacalhau.NewBacalhauExecutor(options.Bacalhau)
ipfsClient, err := ipfs.NewClient(commandCtx.Ctx, options.IPFS.Addr)
if err != nil {
return fmt.Errorf("error creating IPFS client: %s", err.Error())
}

executor, err := bacalhau.NewBacalhauExecutor(options.Bacalhau, ipfsClient)
if err != nil {
return err
}
Expand Down
10 changes: 9 additions & 1 deletion cmd/lilypad/resource-provider.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package lilypad

import (
"fmt"

"github.com/lilypad-tech/lilypad/pkg/executor/bacalhau"
"github.com/lilypad-tech/lilypad/pkg/ipfs"
optionsfactory "github.com/lilypad-tech/lilypad/pkg/options"
"github.com/lilypad-tech/lilypad/pkg/resourceprovider"
"github.com/lilypad-tech/lilypad/pkg/system"
Expand Down Expand Up @@ -50,7 +53,12 @@ func runResourceProvider(cmd *cobra.Command, options resourceprovider.ResourcePr
return err
}

executor, err := bacalhau.NewBacalhauExecutor(options.Bacalhau)
ipfsClient, err := ipfs.NewClient(commandCtx.Ctx, options.IPFS.Addr)
if err != nil {
return fmt.Errorf("error creating IPFS client: %s", err.Error())
}

executor, err := bacalhau.NewBacalhauExecutor(options.Bacalhau, ipfsClient)
if err != nil {
return err
}
Expand Down
12 changes: 11 additions & 1 deletion docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ services:
interval: 30s
timeout: 10s
retries: 5
ipfs:
image: ipfs/kubo:v0.30.0
container_name: ipfs
restart: unless-stopped
ports:
- 5001:5001
volumes:
- ipfs-data:/data/ipfs
solver:
image: ghcr.io/lilypad-tech/solver
container_name: solver
Expand Down Expand Up @@ -87,6 +95,7 @@ services:
depends_on:
- chain
- solver
- ipfs
build:
context: ..
dockerfile: ./docker/resource-provider/Dockerfile
Expand All @@ -100,9 +109,10 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- WEB3_PRIVATE_KEY=${RESOURCE_PROVIDER_PRIVATE_KEY}
- BACALHAU_SERVE_IPFS_PATH=/tmp/lilypad/data/ipfs
- IPFS_CONNECT=/dns4/ipfs/tcp/5001
- LOG_LEVEL=debug
- DISABLE_TELEMETRY=${DISABLE_TELEMETRY}
volumes:
chain-data:
ipfs-data:
bacalhau-data:
Loading

0 comments on commit 85f92b9

Please sign in to comment.