Skip to content

Commit

Permalink
kit chain (#188)
Browse files Browse the repository at this point in the history
* kit boot-fake-node: update fakechain
* kit chain
  • Loading branch information
barraguda authored May 16, 2024
1 parent 4874cfb commit 2dcdb9e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [`start-package`](./kit/start-package.md)
- [`build-start-package`](./kit/build-start-package.md)
- [`remove-package`](./kit/remove-package.md)
- [`chain`](./kit/chain.md)
- [`dev-ui`](./kit/dev-ui.md)
- [`inject-message`](./kit/inject-message.md)
- [`run-tests`](./kit/run-tests.md)
Expand Down
25 changes: 14 additions & 11 deletions src/kit/boot-fake-node.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `kit boot-fake-node`

`kit boot-fake-node` starts a "fake" (i.e. not connected to the live network) node, e.g.,
`kit boot-fake-node` starts a "fake" node connected to a "fake" chain (i.e. not connected to the live network) , e.g.,

```
kit boot-fake-node
Expand All @@ -9,21 +9,24 @@ kit boot-fake-node
By default, `boot-fake-node` fetches a prebuilt binary and launches the node using it.
Alternatively, `boot-fake-node` can use a local binary or build a local Kinode core repo and use the resulting binary.

It also boots a fake chain with [anvil](https://book.getfoundry.sh/anvil/) in the background (see [kit chain](../kit/chain.md)).
The fake chain comes preseeded with two contracts: KNS, which nodes use to index networking info of other nodes; and app_store, which nodes use to index published packages.

## Example Usage

You can start a network of fake nodes that can communicate with each other (but not the live network).
You'll need to start a new terminal for each fake node.
For example, to start two fake nodes, `fake.os` and `fake2.os`:
For example, to start two fake nodes, `fake.dev` and `fake2.dev`:

```
kit boot-fake-node
# In a new terminal
kit boot-fake-node --home /tmp/kinode-fake-node-2 -p 8081 --fake-node-name fake2.os
kit boot-fake-node -f fake2.dev -p 8081 -h /tmp/kinode-fake-node-2
# Send a message from fake2.os to fake.os
# In the terminal of fake2.os:
hi fake.os hello!
# Send a message from fake2.dev to fake.dev
# In the terminal of fake2.dev:
hi fake.dev hello!
# You should see "hello!" in the first node's terminal
```
Expand Down Expand Up @@ -60,8 +63,8 @@ Options:
Where to place the home directory for the fake node [default: /tmp/kinode-fake-node]
-f, --fake-node-name <NODE_NAME>
Name for fake node [default: fake.os]
--network-router-port <NETWORK_ROUTER_PORT>
The port to run the network router on (or to connect to) [default: 9001]
-c, --fakechain-port <FAKECHAIN_PORT>
The port to run the fakechain on (or to connect to) [default: 8545]
--rpc <RPC_ENDPOINT>
Ethereum RPC endpoint (wss://)
--persist
Expand Down Expand Up @@ -115,10 +118,10 @@ short: `-f`

The name of the fake node; defaults to `fake.os`.

### `--network-router-port`
### `--fakechain-port`

Run the fake node network router on this port; defaults to `9001`.
Additional fake nodes must point to the same port to connect to the fake node network.
Run the anvil chain on this port; defaults to `8545`.
Additional fake nodes must point to the same port to connect to the chain.

### `--rpc`

Expand Down
36 changes: 36 additions & 0 deletions src/kit/chain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# kit chain

`kit chain` starts a local fakechain with foundry's [anvil](https://github.com/foundry-rs/foundry/tree/master/crates/anvil), e.g.,

```
kit chain
```

The default port is `8545` and the chain ID is `31337`.

## Discussion

`kit chain` starts an anvil node with the arguments `--load-state kinostate.json`.
This json file includes the [KNS](https://github.com/kinode-dao/KNS) & app_store contracts, and is included in the `kit` binary.

The [kinostate.json](https://github.com/kinode-dao/kit/blob/master/src/chain/kinostate.json) file can be found written into /tmp/kinode-kit-cache/kinostate-{hash}.json upon running the command.

Note that while the kns_indexer and app_store apps in fake nodes use this chain to index events, any events loaded from a json statefile, aren't replayed upon restarting anvil.

## Arguments

```
$ kit c --help
Start a local chain for development
Usage: kit chain [OPTIONS]
Options:
-p, --port <PORT> Port to run the chain on [default: 8545]
-h, --help Print help
```

### `--port`

Port to run anvil fakechain on.
Defaults to `8545`.
4 changes: 2 additions & 2 deletions src/kit/install.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Install `kit`


These documents describe some ways you can use these tools, but do not attempt to be completely exhaustive.
You are encouraged to make use of the `--help` flag, which can be used for the top-level `kit` command:

Expand All @@ -14,7 +13,8 @@ Commands:
boot-fake-node Boot a fake node for development [aliases: f]
build Build a Kinode package [aliases: b]
build-start-package Build and start a Kinode package [aliases: bs]
dev-ui Start the web UI development server with hot reloading (same as `cd ui && npm i && npm run dev`) [aliases: d]
chain Start a local chain for development [aliases: c]
dev-ui Start the web UI development server with hot reloading (same as `cd ui && npm i && npm run dev` [aliases: d]
inject-message Inject a message to a running Kinode [aliases: i]
new Create a Kinode template package [aliases: n]
remove-package Remove a running package from a node [aliases: r]
Expand Down

0 comments on commit 2dcdb9e

Please sign in to comment.