Skip to content

Commit de9b066

Browse files
nonsensegbalint
authored andcommitted
swarm/README: add more sections to easily onboard developers (#17333)
1 parent 0421913 commit de9b066

1 file changed

Lines changed: 190 additions & 1 deletion

File tree

‎swarm/README.md‎

Lines changed: 190 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ Swarm is a distributed storage platform and content distribution service, a nati
77
[![Travis](https://travis-ci.org/ethereum/go-ethereum.svg?branch=master)](https://travis-ci.org/ethereum/go-ethereum)
88
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ethersphere/orange-lounge?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
99

10+
## Table of Contents
11+
12+
* [Building the source](#building-the-source)
13+
* [Running Swarm](#running-swarm)
14+
* [Documentation](#documentation)
15+
* [Developers Guide](#developers-guide)
16+
* [Go Environment](#development-environment)
17+
* [Vendored Dependencies](#vendored-dependencies)
18+
* [Testing](#testing)
19+
* [Profiling Swarm](#profiling-swarm)
20+
* [Metrics and Instrumentation in Swarm](#metrics-and-instrumentation-in-swarm)
21+
* [Public Gateways](#public-gateways)
22+
* [Swarm Dapps](#swarm-dapps)
23+
* [Contributing](#contributing)
24+
* [License](#license)
1025

1126
## Building the source
1227

@@ -16,13 +31,187 @@ Building Swarm requires Go (version 1.10 or later).
1631

1732
go install github.com/ethereum/go-ethereum/cmd/swarm
1833

34+
## Running Swarm
35+
36+
Going through all the possible command line flags is out of scope here, but we've enumerated a few common parameter combos to get you up to speed quickly on how you can run your own Swarm node.
37+
38+
To run Swarm you need an Ethereum account. You can create a new account by running the following command:
39+
40+
geth account new
41+
42+
You will be prompted for a password:
43+
44+
Your new account is locked with a password. Please give a password. Do not forget this password.
45+
Passphrase:
46+
Repeat passphrase:
47+
48+
Once you have specified the password, the output will be the Ethereum address representing that account. For example:
49+
50+
Address: {2f1cd699b0bf461dcfbf0098ad8f5587b038f0f1}
51+
52+
Using this account, connect to Swarm with
53+
54+
swarm --bzzaccount <your-account-here>
55+
56+
# in our example
57+
58+
swarm --bzzaccount 2f1cd699b0bf461dcfbf0098ad8f5587b038f0f1
59+
60+
61+
### Verifying that your local Swarm node is running
62+
63+
When running, Swarm is accessible through an HTTP API on port 8500.
64+
65+
Confirm that it is up and running by pointing your browser to http://localhost:8500
66+
67+
### Ethereum Name Service resolution
68+
69+
The Ethereum Name Service is the Ethereum equivalent of DNS in the classic web. In order to use ENS to resolve names to Swarm content hashes (e.g. `bzz://theswarm.eth`), `swarm` has to connect to a `geth` instance, which is synced with the Ethereum mainnet. This is done using the `--ens-api` flag.
70+
71+
swarm --bzzaccount <your-account-here> \
72+
--ens-api '$HOME/.ethereum/geth.ipc'
73+
74+
# in our example
75+
76+
swarm --bzzaccount 2f1cd699b0bf461dcfbf0098ad8f5587b038f0f1 \
77+
--ens-api '$HOME/.ethereum/geth.ipc'
78+
79+
For more information on usage, features or command line flags, please consult the Documentation.
80+
1981

2082
## Documentation
2183

2284
Swarm documentation can be found at [https://swarm-guide.readthedocs.io](https://swarm-guide.readthedocs.io).
2385

2486

25-
## Contribution
87+
## Developers Guide
88+
89+
### Go Environment
90+
91+
We assume that you have Go v1.10 installed, and `GOPATH` is set.
92+
93+
You must have your working copy under `$GOPATH/src/github.com/ethereum/go-ethereum`.
94+
95+
Most likely you will be working from your fork of `go-ethereum`, let's say from `github.com/nirname/go-ethereum`. Clone or move your fork into the right place:
96+
97+
```
98+
git clone git@github.com:nirname/go-ethereum.git $GOPATH/src/github.com/ethereum/go-ethereum
99+
```
100+
101+
102+
### Vendored Dependencies
103+
104+
All dependencies are tracked in the `vendor` directory. We use `govendor` to manage them.
105+
106+
If you want to add a new dependency, run `govendor fetch <import-path>`, then commit the result.
107+
108+
If you want to update all dependencies to their latest upstream version, run `govendor fetch +v`.
109+
110+
111+
### Testing
112+
113+
This section explains how to run unit, integration, and end-to-end tests in your development sandbox.
114+
115+
Testing one library:
116+
117+
```
118+
go test -v -cpu 4 ./swarm/api
119+
```
120+
121+
Note: Using options -cpu (number of cores allowed) and -v (logging even if no error) is recommended.
122+
123+
Testing only some methods:
124+
125+
```
126+
go test -v -cpu 4 ./eth -run TestMethod
127+
```
128+
129+
Note: here all tests with prefix TestMethod will be run, so if you got TestMethod, TestMethod1, then both!
130+
131+
Running benchmarks:
132+
133+
```
134+
go test -v -cpu 4 -bench . -run BenchmarkJoin
135+
```
136+
137+
138+
### Profiling Swarm
139+
140+
This section explains how to add Go `pprof` profiler to Swarm
141+
142+
If `swarm` is started with the `--pprof` option, a debugging HTTP server is made available on port 6060.
143+
144+
You can bring up http://localhost:6060/debug/pprof to see the heap, running routines etc.
145+
146+
By clicking full goroutine stack dump (clicking http://localhost:6060/debug/pprof/goroutine?debug=2) you can generate trace that is useful for debugging.
147+
148+
149+
### Metrics and Instrumentation in Swarm
150+
151+
This section explains how to visualize and use existing Swarm metrics and how to instrument Swarm with a new metric.
152+
153+
Swarm metrics system is based on the `go-metrics` library.
154+
155+
The most common types of measurements we use in Swarm are `counters` and `resetting timers`. Consult the `go-metrics` documentation for full reference of available types.
156+
157+
```
158+
# incrementing a counter
159+
metrics.GetOrRegisterCounter("network.stream.received_chunks", nil).Inc(1)
160+
161+
# measuring latency with a resetting timer
162+
start := time.Now()
163+
t := metrics.GetOrRegisterResettingTimer("http.request.GET.time"), nil)
164+
...
165+
t := UpdateSince(start)
166+
```
167+
168+
#### Visualizing metrics
169+
170+
Swarm supports an InfluxDB exporter. Consult the help section to learn about the command line arguments used to configure it:
171+
172+
```
173+
swarm --help | grep metrics
174+
```
175+
176+
We use Grafana and InfluxDB to visualise metrics reported by Swarm. We keep our Grafana dashboards under version control at `./swarm/grafana_dashboards`. You could use them or design your own.
177+
178+
We have built a tool to help with automatic start of Grafana and InfluxDB and provisioning of dashboards at https://github.com/nonsense/stateth , which requires that you have Docker installed.
179+
180+
Once you have `stateth` installed, and you have Docker running locally, you have to:
181+
182+
1. Run `stateth` and keep it running in the background
183+
```
184+
stateth --rm --grafana-dashboards-folder $GOPATH/src/github.com/ethereum/go-ethereum/swarm/grafana_dashboards --influxdb-database metrics
185+
```
186+
187+
2. Run `swarm` with at least the following params:
188+
```
189+
--metrics \
190+
--metrics.influxdb.export \
191+
--metrics.influxdb.endpoint "http://localhost:8086" \
192+
--metrics.influxdb.username "admin" \
193+
--metrics.influxdb.password "admin" \
194+
--metrics.influxdb.database "metrics"
195+
```
196+
197+
3. Open Grafana at http://localhost:3000 and view the dashboards to gain insight into Swarm.
198+
199+
200+
## Public Gateways
201+
202+
Swarm offers a local HTTP proxy API that Dapps can use to interact with Swarm. The Ethereum Foundation is hosting a public gateway, which allows free access so that people can try Swarm without running their own node.
203+
204+
The Swarm public gateways are temporary and users should not rely on their existence for production services.
205+
206+
The Swarm public gateway can be found at https://swarm-gateways.net and is always running the latest `stable` Swarm release.
207+
208+
## Swarm Dapps
209+
210+
You can find a few reference Swarm decentralised applications at: https://swarm-gateways.net/bzz:/swarmapps.eth
211+
212+
Their source code can be found at: https://github.com/ethersphere/swarm-dapps
213+
214+
## Contributing
26215

27216
Thank you for considering to help out with the source code! We welcome contributions from
28217
anyone on the internet, and are grateful for even the smallest of fixes!

0 commit comments

Comments
 (0)