Skip to content

Commit

Permalink
Merge pull request #26 from hollygrimm/sepolia
Browse files Browse the repository at this point in the history
int for tokens instead of wei; deploy contracts to sepolia
  • Loading branch information
hollygrimm authored Nov 1, 2023
2 parents 275e5f3 + e724527 commit de302b2
Show file tree
Hide file tree
Showing 44 changed files with 6,553 additions and 171 deletions.
102 changes: 66 additions & 36 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
# Development
# Development Setup

We need the following installed:
Before starting development, ensure that the following dependencies are installed on your system:

* docker
* node.js
* golang
- Docker
- Node.js
- Golang

## install
## Installation

Get the node modules installed and generate a local .env file with private keys for the various services.
First, install the required Node.js modules and generate a local `.env` file containing private keys for various services. Run the following commands:

```bash
(cd hardhat && yarn install)
./stack print-env > .env
```

## boot stack
## Booting the Stack

### bacalhau
### 1 - Bacalhau

We need a bacalhau node running on the same machine as the resource provider.

Here is how we got bacalhau up and running:
To run a Bacalhau node on the same machine as the resource provider, follow these steps:

```bash
# install the latest bacalhau which works with GPUs (https://github.com/bacalhau-project/bacalhau/issues/2858)
# Install the latest Bacalhau release which works with GPUs (https://github.com/bacalhau-project/bacalhau/issues/2858)
wget https://github.com/bacalhau-project/bacalhau/releases/download/v1.0.3/bacalhau_v1.0.3_linux_amd64.tar.gz
# Extract the downloaded archive and move the `bacalhau` binary to `/usr/local/bin`
tar xfv bacalhau_v1.0.3_linux_amd64.tar.gz
mv bacalhau /usr/local/bin
# configure this to where you want the ipfs data to be stored
# Set the IPFS data path by exporting the `BACALHAU_SERVE_IPFS_PATH` variable to your desired location
export BACALHAU_SERVE_IPFS_PATH=/tmp/lilypad/data/ipfs
# run bacalhau as both compute node and requester node
./stack bacalhau-serve
# Run Bacalhau as both a compute node and a requester node
bacalhau serve --node-type compute,requester --peer none --private-internal-ipfs=false --job-selection-accept-networked
```

### lilypad
### 2 - Lilypad

To initiate the boot sequence for Lilypad, run the following command:

```bash
./stack boot
```

This does the following things:
This command performs the following four phases within the boot sequence:

#### geth
#### 2.1 - Geth

We need to start geth, move funds to our admin account and then fund the various other accounts.
During this phase, the following tasks are executed:

```bash
./stack geth
Expand All @@ -53,79 +54,108 @@ We need to start geth, move funds to our admin account and then fund the various
./stack balances
```

Geth is now running and each of our services has some ether allocated.
These commands start Geth, allocates eth to the admin, faucet, solver, mediator, resource_provider, job_creator, and directory accounts.

#### compile contracts
#### 2.2 - Compile Contracts

```bash
./stack compile-contracts
```

This will also generate go bindings in `pkg/contract/bindings/contracts`
This compiles the smart contracts and generates Go bindings in `pkg/contract/bindings/contracts`.

#### deploy contracts
#### 2.3 - Deploy Contracts

```bash
./stack deploy-contracts
```

Contracts are now deployed - no services have any tokens though
This deploys the smart contracts. Note that services will not have any tokens at this point.

#### fund tokens
#### 2.4 - Fund Tokens

```bash
./stack fund-services-tokens
./stack balances
```
This funds the services with tokens and prints the balances.

### run services
### 3 - Run Services

Run the following commands in separate terminals:
Run the following commands in separate terminal windows:

```bash
./stack solver
```

Wait for the solver to start when `🟡 SOL solver registered` is logged, and then run:

```bash
./stack mediator
```

If you have a GPU, run the following command in a separate terminal window:

```bash
./stack resource-provider --offer-gpu 1
```

Otherwise, if you don't have a GPU:

```bash
./stack resource-provider
```

Run Cowsay:

```bash
./stack run cowsay:v0.0.1 -i Message="moo"
```

## stop stack
Run SDXL:

To stop geth running at any time:
```bash
./stack runsdxl sdxl:v0.9-lilypad1 PROMPT="beautiful view of iceland with a record player"
```

## Stopping the Stack

To stop Geth at any time, use the following command:

```bash
./stack geth-stop
```

To reset the geth data (i.e. a complete restart):
To reset Geth data, effectively performing a complete restart, use the following command:

```bash
./stack clean
```

NOTE: you will need to re-run the `fund-admin` and `fund-services` commands after a `clean`.
Please note that after running `clean`, you will need to re-run the `fund-admin` and `fund-services` commands.

## unit tests
## Unit Tests

Run the smart contract unit tests:
Run the smart contract unit tests with the following command:

```bash
./stack unit-tests
```

## re-generate go bindings
## Regenerating Go Bindings

When you change the smart contracts the go bindings in `pkg/contract/bindings/contracts` will need regenerating.
Whenever you make changes to the smart contracts, regenerate the Go bindings in `pkg/contract/bindings/contracts` by running:

```bash
./stack compile-contracts
```

## Troubleshooting

### Receive Buffer Size Error

`failed to sufficiently increase receive buffer size` See https://github.com/quic-go/quic-go/wiki/UDP-Receive-Buffer-Size for details. Fix for Linux:
```
sudo sysctl -w net.core.rmem_max=2500000
sudo sysctl -w net.core.wmem_max=2500000
```
127 changes: 127 additions & 0 deletions TESTNETDEPLOY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Testnet Deployment


## Installation

First, install the required Node.js modules and generate a local `.env` file containing private keys for various services. Run the following commands:

```bash
(cd hardhat && yarn install)
./stack print-env > .env
```

## Booting the Stack

### 1 - Bacalhau

To run a Bacalhau node on the same machine as the resource provider, follow these steps:

```bash
# install the latest bacalhau which works with GPUs (https://github.com/bacalhau-project/bacalhau/issues/2858)
wget https://github.com/bacalhau-project/bacalhau/releases/download/v1.0.3/bacalhau_v1.0.3_linux_amd64.tar.gz
tar xfv bacalhau_v1.0.3_linux_amd64.tar.gz
mv bacalhau /usr/local/bin
# configure this to where you want the ipfs data to be stored
export BACALHAU_SERVE_IPFS_PATH=/tmp/lilypad/data/ipfs
# run bacalhau as both compute node and requester node
./stack bacalhau-serve
```

## Create Seven New Accounts

Follow the `README.md` in the `generate_accts` directory to create seven new accounts.

Copy `hardhat/.env.sample` to `.env` and update the following environment variables:
```
ADDRESS_ADMIN=
PRIVATE_KEY_ADMIN=
ADDRESS_FAUCET=
PRIVATE_KEY_FAUCET=
ADDRESS_SOLVER=
PRIVATE_KEY_SOLVER=
ADDRESS_MEDIATOR=
PRIVATE_KEY_MEDIATOR=
ADDRESS_RESOURCE_PROVIDER=
PRIVATE_KEY_RESOURCE_PROVIDER=
ADDRESS_JOB_CREATOR=
PRIVATE_KEY_JOB_CREATOR=
ADDRESS_DIRECTORY=
PRIVATE_KEY_DIRECTORY=
```

## Create a new Infura Project

Create a new Infura project and update the following environment variable in `hardhat/.env`:
```
INFURA_KEY=
```

Also add the infura key to the `.env` file:
```
export INFURA_KEY=
```

## Setup Hardhat

set defaultNetwork to `sepolia` in `hardhat.config.js`

Update the following values in the `.env` file. Replace `<INFURA_KEY>` with the Infura key from above:
```
export NETWORK=sepolia
export WEB3_RPC_URL=wss://sepolia.infura.io/ws/v3/<INFURA_KEY>
export WEB3_CHAIN_ID=11155111
```

## Fund the Seven New Accounts

Fund the `admin` acccount with .7 ETH.

Fund the remaining six accounts with .1 ETH each.

```bash
./stack fund-services-ether
```

Check the balances

```bash
./stack balances
```

## Compile Contracts

```bash
./stack compile-contracts
```

## Deploy Contracts

```bash
./stack deploy-contracts
```

## Fund Services Tokens

```bash
./stack fund-services-tokens
```

### Run Services

Run the following commands in separate terminals:

```bash
./stack solver
```

```bash
./stack mediator
```

```bash
./stack resource-provider
```

```bash
./stack run cowsay:v0.0.1 -i Message="moo"
```
2 changes: 2 additions & 0 deletions cmd/lilypad/mediator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
optionsfactory "github.com/bacalhau-project/lilypad/pkg/options"
"github.com/bacalhau-project/lilypad/pkg/system"
"github.com/bacalhau-project/lilypad/pkg/web3"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -50,6 +51,7 @@ func runMediator(cmd *cobra.Command, options mediator.MediatorOptions) error {
return err
}

log.Debug().Msgf("Starting mediator service.")
mediatorErrors := mediatorService.Start(commandCtx.Ctx, commandCtx.Cm)
for {
select {
Expand Down
17 changes: 17 additions & 0 deletions hardhat/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
INFURA_KEY=
ETHERSCAN_API_KEY=

ADDRESS_ADMIN=
PRIVATE_KEY_ADMIN=
ADDRESS_FAUCET=
PRIVATE_KEY_FAUCET=
ADDRESS_SOLVER=
PRIVATE_KEY_SOLVER=
ADDRESS_MEDIATOR=
PRIVATE_KEY_MEDIATOR=
ADDRESS_RESOURCE_PROVIDER=
PRIVATE_KEY_RESOURCE_PROVIDER=
ADDRESS_JOB_CREATOR=
PRIVATE_KEY_JOB_CREATOR=
ADDRESS_DIRECTORY=
PRIVATE_KEY_DIRECTORY=
2 changes: 1 addition & 1 deletion hardhat/contracts/LilypadToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ contract LilypadToken is ControllerOwnable, ERC20, ERC20Pausable {
function _beforeTokenTransfer(address from, address to, uint256 amount) internal override(ERC20, ERC20Pausable) {
super._beforeTokenTransfer(from, to, amount);
}
}
}
2 changes: 2 additions & 0 deletions hardhat/deploy/001_deploy_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const deployToken: DeployFunction = async function (hre: HardhatRuntimeEnvironme
const {
admin,
} = await getNamedAccounts()
// log the admin address
console.log(`admin: ${admin}`)
await deploy("LilypadToken", {
from: admin,
args: [
Expand Down
1 change: 1 addition & 0 deletions hardhat/deployments/sepolia/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11155111
9 changes: 9 additions & 0 deletions hardhat/deployments/sepolia/.migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"deployToken": 1698866546,
"deployPayments": 1698866582,
"deployStorage": 1698866604,
"deployUsers": 1698866631,
"deployMediation": 1698866654,
"deployJobCreator": 1698866729,
"deployController": 1698866787
}
Loading

0 comments on commit de302b2

Please sign in to comment.