This document is the entry point for developers who wish to work on Etn-sc. Developers are people who are interested to build, develop, debug, submit a bug report or pull request or otherwise contribute to the Etn-sc source code.
Please see for the Etn-sc contribution guidelines.
Building and Testing
Developers should use a recent version of Go for building and testing. We use the go toolchain for development, which you can get from the . Etn-sc is a Go module, and uses the to manage dependencies. Using GOPATH is not required to build electroneum-sc.
Building Executables
Switch to the electroneum-sc repository root directory. All code can be built using the go tool, placing the resulting binary in $GOPATH/bin.
go install -v ./...
electroneum-sc executables can be built individually. To build just etn-sc, use:
go install -v ./cmd/etn-sc
Cross compilation is not recommended, please build Etn-sc for the host architecture.
Testing
Testing a package:
go test -v ./eth
Running an individual test:
go test -v ./eth -run TestMethod
Note: here all tests with prefix TestMethod will be run, so if TestMethod and TestMethod1 both exist then both tests will run.
Running benchmarks, eg.:
go test -v -bench . -run BenchmarkJoin
Getting Stack Traces
A stack trace provides a very detailed look into the current state of the etn-sc node. It helps us to debug issues easier as it contains information about what is currently done by the node. Stack traces can be created by running debug.stacks() in the Etn-sc console. If the node was started without the console command or with a script in the background, the following command can be used to dump the stack trace into a file.
Etn-sc logs the location of the IPC endpoint on startup. It is typically under /home/user/.electroneum-sc/etn-sc.ipc or /tmp/etn-sc.ipc.
debug.stacks() also takes an optional filter argument. Passing a package name or filepath to filter restricts the output to stack traces involving only that package/file. For example:
debug.stacks("enode")
returns data that looks like:
INFO [11-04|16:15:54.486] Expanded filter expression filter=enode expanded="`enode` in Value"
goroutine 121 [chan receive, 3 minutes]:
github.com/ethereum/go-ethereum/p2p/enode.(*FairMix).nextFromAny(...)
github.com/ethereum/go-ethereum/p2p/enode/iter.go:241
github.com/ethereum/go-ethereum/p2p/enode.(*FairMix).Next(0xc0008c6060)
github.com/ethereum/go-ethereum/p2p/enode/iter.go:215 +0x2c5
github.com/ethereum/go-ethereum/p2p.(*dialScheduler).readNodes(0xc00021c2c0, {0x18149b0, 0xc0008c6060})
github.com/ethereum/go-ethereum/p2p/dial.go:321 +0x9f
created by github.com/ethereum/go-ethereum/p2p.newDialScheduler
github.com/ethereum/go-ethereum/p2p/dial.go:179 +0x425
Note that if multiple instances of Etn-sc 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.
Alternatively to kill the clients (in case they hang or stalled syncing, etc) and have the stacktrace too, use the -QUIT signal with kill:
killall -QUIT etn-sc
This will dump stack traces for each instance to their respective log file.
Where to go next
Read the remaining pages in the Etn-sc developer section, and get building!
For more information, see the documentation.
If Etn-sc is started with the --pprof option, a debugging HTTP server is made available on port 6060. Navigating to displays the heap, running routines etc. By clicking "full goroutine stack dump" a trace can be generated that is useful for debugging.