2022-07-27 07:38:03 -05:00
|
|
|
---
|
|
|
|
title: Developer Guide
|
|
|
|
sort_key: A
|
|
|
|
---
|
|
|
|
|
2022-07-29 05:04:46 -05:00
|
|
|
This document is the entry point for developers who wish to work on Geth.
|
|
|
|
Developers are people who are interested to build, develop, debug, submit
|
|
|
|
a bug report or pull request or otherwise contribute to the Geth source code.
|
2022-07-27 07:38:03 -05:00
|
|
|
|
2022-07-29 05:04:46 -05:00
|
|
|
Please see [Contributing](/content/docs/developers/contributing.md) for the
|
|
|
|
GHeth contribution guidelines.
|
2022-07-27 07:38:03 -05:00
|
|
|
|
|
|
|
## Building and Testing
|
|
|
|
|
2022-07-29 05:04:46 -05:00
|
|
|
Developers should use a recent version of Go for building and testing. We use the go
|
2022-07-27 07:38:03 -05:00
|
|
|
toolchain for development, which you can get from the [Go downloads page][go-install].
|
|
|
|
|
2022-07-29 05:04:46 -05:00
|
|
|
Geth is a Go module, and uses the [Go modules system][go-modules] to manage
|
2022-07-27 07:38:03 -05:00
|
|
|
dependencies. Using `GOPATH` is not required to build go-ethereum.
|
|
|
|
|
|
|
|
### Building Executables
|
|
|
|
|
|
|
|
Switch to the go-ethereum repository root directory.
|
2022-07-29 05:04:46 -05:00
|
|
|
All code can be built using the go tool, placing the resulting binary in `$GOPATH/bin`.
|
2022-07-27 07:38:03 -05:00
|
|
|
|
|
|
|
```text
|
|
|
|
go install -v ./...
|
|
|
|
```
|
|
|
|
|
|
|
|
go-ethereum exectuables can be built individually. To build just geth, use:
|
|
|
|
|
|
|
|
```text
|
|
|
|
go install -v ./cmd/geth
|
|
|
|
```
|
|
|
|
|
2022-07-29 05:04:46 -05:00
|
|
|
Cross compilation is not recommended, please build Geth for the host architecture.
|
2022-07-27 07:38:03 -05:00
|
|
|
|
|
|
|
### Testing
|
|
|
|
|
|
|
|
Testing a package:
|
|
|
|
|
|
|
|
```
|
|
|
|
go test -v ./eth
|
|
|
|
```
|
|
|
|
|
|
|
|
Running an individual test:
|
|
|
|
|
|
|
|
```
|
|
|
|
go test -v ./eth -run TestMethod
|
|
|
|
```
|
|
|
|
|
2022-07-29 05:04:46 -05:00
|
|
|
**Note**: here all tests with prefix _TestMethod_ will be run, so if TestMethod and
|
|
|
|
TestMethod1 both exist then both tests will run.
|
2022-07-27 07:38:03 -05:00
|
|
|
|
|
|
|
Running benchmarks, eg.:
|
|
|
|
|
|
|
|
```
|
|
|
|
go test -v -bench . -run BenchmarkJoin
|
|
|
|
```
|
|
|
|
|
|
|
|
For more information, see the [go test flags][testflag] documentation.
|
|
|
|
|
|
|
|
### Getting Stack Traces
|
|
|
|
|
|
|
|
If `geth` is started with the `--pprof` option, a debugging HTTP server is made available
|
2022-07-29 05:04:46 -05:00
|
|
|
on port 6060. Navigating to <http://localhost:6060/debug/pprof> displays the heap,
|
|
|
|
running routines etc. By clicking "full goroutine stack dump" a trace can be generated
|
2022-07-27 07:38:03 -05:00
|
|
|
that is useful for debugging.
|
|
|
|
|
2022-07-29 05:04:46 -05:00
|
|
|
Note that if multiple instances of Geth exist, port `6060` will only work for the first
|
|
|
|
instance that was launched. To generate stacktraces for other instances,
|
|
|
|
they should be started up with alternative pprof ports. Ensure `stderr` is being
|
|
|
|
redirected to a logfile.
|
2022-07-27 07:38:03 -05:00
|
|
|
|
|
|
|
```
|
|
|
|
geth -port=30300 -verbosity 5 --pprof --pprof.port 6060 2>> /tmp/00.glog
|
|
|
|
geth -port=30301 -verbosity 5 --pprof --pprof.port 6061 2>> /tmp/01.glog
|
|
|
|
geth -port=30302 -verbosity 5 --pprof --pprof.port 6062 2>> /tmp/02.glog
|
|
|
|
```
|
|
|
|
|
2022-07-29 05:04:46 -05:00
|
|
|
Alternatively to kill the clients (in case they hang or stalled syncing, etc)
|
|
|
|
and have the stacktrace too, use the `-QUIT` signal with `kill`:
|
2022-07-27 07:38:03 -05:00
|
|
|
|
|
|
|
```
|
|
|
|
killall -QUIT geth
|
|
|
|
```
|
|
|
|
|
|
|
|
This will dump stack traces for each instance to their respective log file.
|
|
|
|
|
|
|
|
[install-guide]: ../install-and-build/installing-geth
|
|
|
|
[code-review]: ../developers/code-review-guidelines
|
|
|
|
[cross-compile]: ../install-and-build/cross-compile
|
|
|
|
[go-modules]: https://github.com/golang/go/wiki/Modules
|
|
|
|
[discord]: https://discord.gg/invite/nthXNEv
|
|
|
|
[go-install]: https://golang.org/doc/install
|
|
|
|
[testflag]: https://golang.org/cmd/go/#hdr-Testing_flags
|