### Installation Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/metrics/README.md Provides the go get command to install the go-metrics library. ```sh go get github.com/rcrowley/go-metrics ``` -------------------------------- ### Compiling Usage Examples Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/crypto/secp256k1/libsecp256k1/README.md Instructions on how to compile usage examples, including enabling specific modules required for certain examples. ```bash To compile them you need to configure with `--enable-examples`. * [ECDSA example](examples/ecdsa.c) * [Schnorr signatures example](examples/schnorr.c) * [Deriving a shared secret (ECDH) example](examples/ecdh.c) * [ElligatorSwift key exchange example](examples/ellswift.c) To compile the Schnorr signature and ECDH examples, you also need to configure with `--enable-module-schnorrsig` and `--enable-module-ecdh`. ``` -------------------------------- ### Fuzzer Output Example Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/tests/fuzzers/README.md Example output from a running go-fuzz process, showing statistics like workers, corpus size, crashes, and execution rate. ```shell 2019/11/26 13:36:54 workers: 6, corpus: 3 (3s ago), crashers: 0, restarts: 1/0, execs: 0 (0/sec), cover: 0, uptime: 3s 2019/11/26 13:36:57 workers: 6, corpus: 3 (6s ago), crashers: 0, restarts: 1/0, execs: 0 (0/sec), cover: 1054, uptime: 6s 2019/11/26 13:37:00 workers: 6, corpus: 3 (9s ago), crashers: 0, restarts: 1/8358, execs: 25074 (2786/sec), cover: 1054, uptime: 9s 2019/11/26 13:37:03 workers: 6, corpus: 3 (12s ago), crashers: 0, restarts: 1/8497, execs: 50986 (4249/sec), cover: 1054, uptime: 12s 2019/11/26 13:37:06 workers: 6, corpus: 3 (15s ago), crashers: 0, restarts: 1/9330, execs: 74640 (4976/sec), cover: 1054, uptime: 15s 2019/11/26 13:37:09 workers: 6, corpus: 3 (18s ago), crashers: 0, restarts: 1/9948, execs: 99482 (5527/sec), cover: 1054, uptime: 18s 2019/11/26 13:37:12 workers: 6, corpus: 3 (21s ago), crashers: 0, restarts: 1/9428, execs: 122568 (5836/sec), cover: 1054, uptime: 21s 2019/11/26 13:37:15 workers: 6, corpus: 3 (24s ago), crashers: 0, restarts: 1/9676, execs: 145152 (6048/sec), cover: 1054, uptime: 24s 2019/11/26 13:37:18 workers: 6, corpus: 3 (27s ago), crashers: 0, restarts: 1/9855, execs: 167538 (6205/sec), cover: 1054, uptime: 27s 2019/11/26 13:37:21 workers: 6, corpus: 3 (30s ago), crashers: 0, restarts: 1/9645, execs: 192901 (6430/sec), cover: 1054, uptime: 30s 2019/11/26 13:37:24 workers: 6, corpus: 3 (33s ago), crashers: 0, restarts: 1/9967, execs: 219294 (6645/sec), cover: 1054, uptime: 33s ``` -------------------------------- ### Sanity Check: Build and Test with CMake Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/crypto/secp256k1/libsecp256k1/doc/release-process.md Performs a sanity check by building and testing the project using CMake. This involves configuring the build with a specified installation prefix, building the project, and installing it. It also verifies installation and compiles an example using the installed library. ```shell dir=$(mktemp -d) build=$(mktemp -d) cmake -B $build -DCMAKE_INSTALL_PREFIX=$dir && cmake --build $build && cmake --install $build && ls -RlAh $dir gcc -o ecdsa examples/ecdsa.c -I $dir/include -L $dir/lib*/ -l secp256k1 -Wl,-rpath,"$dir/lib",-rpath,"$dir/lib64" && ./ecdsa ``` -------------------------------- ### Starting Clef Signer with Custom Rules Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/cmd/clef/tutorial.md Illustrates the command to start the Clef signer, specifying the keystore directory, chain ID, and the custom rules file. ```text $ clef --keystore ~/.ethereum/rinkeby/keystore --chainid 4 --rules rules.js INFO [07-01|14:12:41.636] Rule engine configured file=rules.js INFO [07-01|14:12:41.636] Starting signer chainid=4 keystore=$HOME/.ethereum/rinkeby/keystore light-kdf=false advanced=false DEBUG[07-01|14:12:41.636] FS scan times list=46.722µs set=4.47µs diff=2.157µs DEBUG[07-01|14:12:41.637] Ledger support enabled DEBUG[07-01|14:12:41.637] Trezor support enabled via HID DEBUG[07-01|14:12:41.638] Trezor support enabled via WebUSB INFO [07-01|14:12:41.638] Audit logs configured file=audit.log DEBUG[07-01|14:12:41.638] IPC registered namespace=account INFO [07-01|14:12:41.638] IPC endpoint opened url=$HOME/.clef/clef.ipc ------- Signer info ------- * intapi_version : 7.0.0 * extapi_version : 6.0.0 * extapi_http : n/a * extapi_ipc : $HOME/.clef/clef.ipc ``` -------------------------------- ### Install Debian Packaging Tools Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/build/ci-notes.md Installs necessary tools for building Debian packages, including Go and packaging utilities. ```bash sudo apt-get install build-essential golang-go devscripts debhelper python-bzrlib python-paramiko ``` -------------------------------- ### Install and Initialize Smartcard Application Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/accounts/scwallet/README.md Installs the smartcard application and initializes the card using the keycard-cli. This process generates a PIN, PUK, and pairing password. ```shell keycard install -a keycard_v2.2.1.cap && keycard init ``` -------------------------------- ### StatHat Support Installation Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/metrics/README.md Details the additional go get command required to install the StatHat Go client for StatHat support. ```sh go get github.com/stathat/go ``` -------------------------------- ### Logging Repeated Keys and Different Log Levels Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/cmd/geth/testdata/logging/logtest-logfmt.txt Demonstrates how repeated keys are handled in log messages and shows examples of logging at different levels (info, warn, error). ```go t=xxxx-xx-xxTxx:xx:xx+xxxx lvl=info msg="repeated-key 1" foo=alpha foo=beta t=xxxx-xx-xxTxx:xx:xx+xxxx lvl=info msg="repeated-key 2" xx=short xx=longer t=xxxx-xx-xxTxx:xx:xx+xxxx lvl=info msg="log at level info" t=xxxx-xx-xxTxx:xx:xx+xxxx lvl=warn msg="log at level warn" t=xxxx-xx-xxTxx:xx:xx+xxxx lvl=error msg="log at level error" ``` -------------------------------- ### Starting Clef with Rules Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/cmd/clef/tutorial.md This command starts the Clef signer with a specified keystore, chain ID, and rules file. It configures Clef to manage accounts and sign transactions based on the provided rules. ```text clef --keystore ~/.ethereum/rinkeby/keystore --chainid 4 --rules rules.js ``` -------------------------------- ### Log Alignment Examples Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/cmd/geth/testdata/logging/logtest-json.txt Shows examples of log messages designed to align key fields into columns for better readability. ```go {"t":"2023-11-22T15:42:00.408251+08:00","lvl":"info","msg":"test","bar":"short","a":"aligned left"} {"t":"2023-11-22T15:42:00.408254+08:00","lvl":"info","msg":"test","bar":"a long message","a":1} {"t":"2023-11-22T15:42:00.408258+08:00","lvl":"info","msg":"test","bar":"short","a":"aligned right"} {"t":"2023-11-22T15:42:00.408261+08:00","lvl":"info","msg":"The following logs should align so that the key-fields make 5 columns"} ``` -------------------------------- ### Starting Clef with Rinkeby Keystore Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/cmd/clef/tutorial.md This command starts the Clef signer, specifying the keystore directory for Rinkeby testnet accounts and the corresponding chain ID. ```bash $ clef --keystore ~/.ethereum/rinkeby/keystore --chainid 4 ``` -------------------------------- ### Starting Geth with Clef Signer Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/cmd/clef/tutorial.md This command starts the Geth client, connecting it to a local Clef instance via an IPC path. This allows Geth to use Clef for account management and transaction signing. ```text geth --rinkeby --signer=~/.clef/clef.ipc console ``` -------------------------------- ### Conditional Example Builds Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/crypto/secp256k1/libsecp256k1/examples/CMakeLists.txt Demonstrates how to conditionally add executable examples based on secp256k1 module enablement flags. The `add_example` function is called for `ecdsa` by default, and for `ecdh`, `schnorr`, `ellswift`, and `musig` only if their respective modules are enabled in the CMake configuration. ```cmake add_example(ecdsa) if(SECP256K1_ENABLE_MODULE_ECDH) add_example(ecdh) endif() if(SECP256K1_ENABLE_MODULE_SCHNORRSIG) add_example(schnorr) endif() if(SECP256K1_ENABLE_MODULE_ELLSWIFT) add_example(ellswift) endif() if(SECP256K1_ENABLE_MODULE_MUSIG) add_example(musig) endif() ``` -------------------------------- ### Running geth Examples Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/README.md Demonstrates common command-line parameter combinations for running the 'geth' Ethereum client. ```bash # Consult the CLI Wiki page for all command line flags: # https://geth.ethereum.org/docs/fundamentals/command-line-options # Example: Running geth as a full node on the mainnet # geth --mainnet # Example: Running geth as an archive node on a testnet # geth --testnet --datadir /path/to/archive/data # Example: Running geth with a custom network configuration # geth --datadir "MyNet" --networkid 12345 --rpc --rpcaddr "127.0.0.1" --rpcport 8545 ``` -------------------------------- ### Include Subdirectories and Print Summary Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/crypto/secp256k1/libsecp256k1/CMakeLists.txt Includes the 'src' subdirectory for core source files and optionally the 'examples' subdirectory if 'SECP256K1_BUILD_EXAMPLES' is enabled. It concludes by printing a summary of the secp256k1 configuration. ```cmake add_subdirectory(src) if(SECP256K1_BUILD_EXAMPLES) add_subdirectory(examples) endif() message("\n") message("secp256k1 configure summary") message("===========================") message("Build artifacts:") if(BUILD_SHARED_LIBS) set(library_type "Shared") ``` -------------------------------- ### RLP Fuzzer Panic Example Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/tests/fuzzers/README.md An example of a panic statement within the RLP fuzzer in Go, used to differentiate between different types of failures by including a counter. ```go if !bytes.Equal(input, output) { panic(fmt.Sprintf("case %d: encode-decode is not equal, \ninput : %x\noutput: %x", i, input, output)) } ``` -------------------------------- ### Build Fuzzing Binary Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/tests/fuzzers/README.md Builds a fuzzing binary for the RLP package using go-fuzz. Requires go-fuzz to be installed. ```shell (cd ./rlp && CGO_ENABLED=0 go-fuzz-build .) ``` -------------------------------- ### Geth Console Commands Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/cmd/clef/tutorial.md These are example commands executed within the Geth JavaScript console. They demonstrate how to list accounts, list wallets managed by Clef, and send a transaction. ```go > eth.accounts ["0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3", "0x086278a6c067775f71d6b2bb1856db6e28c30418"] ``` ```go > personal.listWallets [{ accounts: [{ address: "0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3", url: "extapi://$HOME/.clef/clef.ipc" }, { address: "0x086278a6c067775f71d6b2bb1856db6e28c30418", url: "extapi://$HOME/.clef/clef.ipc" }], status: "ok [version=6.0.0]", url: "extapi://$HOME/.clef/clef.ipc" }] ``` ```go > eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[0]}) ``` -------------------------------- ### Dump Geth Configuration Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/README.md Exports the current Geth configuration, including all active flags, to the console. This is useful for creating a configuration file by starting with an existing setup. ```shell $ geth --your-favourite-flags dumpconfig ``` -------------------------------- ### InfluxDB Reporter Setup Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/metrics/influxdb/README.md Configures and starts the InfluxDB reporter for go-metrics. It takes the metrics registry, reporting interval, InfluxDB URL, database name, username, and password as arguments. This function is intended to be run as a goroutine. ```go import "github.com/vrischmann/go-metrics-influxdb" import "github.com/rcrowley/go-metrics" import "time" go influxdb.InfluxDB( metrics.DefaultRegistry, // metrics registry time.Second * 10, // interval "http://localhost:8086", // the InfluxDB url "mydb", // your InfluxDB database "myuser", // your InfluxDB user "mypassword", // your InfluxDB password ) ``` -------------------------------- ### Docker Quick Start for Ethereum Node Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/README.md Starts a Geth node using Docker in snap-sync mode. It maps ports for RPC and P2P communication, creates a persistent volume for blockchain data, and uses the default configuration. The `--http.addr 0.0.0.0` flag is crucial for external RPC access. ```shell docker run -d --name ethereum-node -v /Users/alice/ethereum:/root \ -p 8545:8545 -p 30303:30303 \ ethereum/client-go ``` -------------------------------- ### Go: Basic Functionality Example Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/cmd/evm/testdata/eof/eof_benches.txt This snippet demonstrates a fundamental operation in Go, likely related to data processing or network interaction within the Mega-Op-Geth project. It serves as a starting point for understanding the project's Go-based components. ```go package main import "fmt" func main() { fmt.Println("Hello, Mega-Op-Geth!") } ``` -------------------------------- ### JavaScript Console Interaction with Geth Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/README.md Example of interacting with a running Geth node using the JavaScript console. It demonstrates calling a web3 method to get the current block number. Note that the bundled web3.js version in Geth is outdated. ```javascript web3.eth.getBlockNumber().then(console.log); ``` -------------------------------- ### Starting Clef with Custom Rules Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/cmd/clef/tutorial.md Shows how to launch the Clef signer with a specified rule file, chain ID, and keystore directory. This command configures Clef to use the provided rules for transaction signing. ```text $ clef --keystore ~/.ethereum/rinkeby/keystore --chainid 4 --rules rules.js INFO [07-01|13:39:49.726] Rule engine configured file=rules.js INFO [07-01|13:39:49.726] Starting signer chainid=4 keystore=$HOME/.ethereum/rinkeby/keystore light-kdf=false advanced=false DEBUG[07-01|13:39:49.726] FS scan times list=35.15µs set=4.251µs diff=2.766µs DEBUG[07-01|13:39:49.727] Ledger support enabled DEBUG[07-01|13:39:49.727] Trezor support enabled via HID DEBUG[07-01|13:39:49.727] Trezor support enabled via WebUSB INFO [07-01|13:39:49.728] Audit logs configured file=audit.log DEBUG[07-01|13:39:49.728] IPC registered namespace=account INFO [07-01|13:39:49.728] IPC endpoint opened url=$HOME/.clef/clef.ipc ------ Signer info ------ * intapi_version : 7.0.0 * extapi_version : 6.0.0 * extapi_http : n/a * extapi_ipc : $HOME/.clef/clef.ipc ``` -------------------------------- ### Sanity Check: Build and Test with Autotools Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/crypto/secp256k1/libsecp256k1/doc/release-process.md Performs a sanity check by building and testing the project using autotools. This includes generating build scripts, configuring the build with development mode, and running 'make distcheck'. It also verifies installation and compiles an example using pkg-config. ```shell ./autogen.sh && ./configure --enable-dev-mode && make distcheck ``` ```shell dir=$(mktemp -d) ./autogen.sh && ./configure --prefix=$dir && make clean && make install && ls -RlAh $dir gcc -o ecdsa examples/ecdsa.c $(PKG_CONFIG_PATH=$dir/lib/pkgconfig pkg-config --cflags --libs libsecp256k1) -Wl,-rpath,"$dir/lib" && ./ecdsa ``` -------------------------------- ### Clef CLI Example Usage Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/cmd/clef/README.md Demonstrates how to run the Clef command-line tool with specific configurations for keystore directory and chain ID. ```bash $ clef -keystore /my/keystore -chainid 4 ``` -------------------------------- ### Clef RPC Service for Qubes OS (Server) Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/cmd/clef/docs/setup.md This bash script defines an RPC service for Clef on a target Qubes OS VM. It starts the Clef signer if not running and forwards incoming requests from stdin to Clef's HTTP channel. It requires Clef and gtksigner to be installed. ```bash #!/bin/bash SIGNER_BIN="/home/user/tools/clef/clef" SIGNER_CMD="/home/user/tools/gtksigner/gtkui.py -s $SIGNER_BIN" # Start clef if not already started if [ ! -S /home/user/.clef/clef.ipc ]; then $SIGNER_CMD & sleep 1 fi # Should be started by now if [ -S /home/user/.clef/clef.ipc ]; then # Post incoming request to HTTP channel curl -H "Content-Type: application/json" -X POST -d @- http://localhost:8550 2>/dev/null fi ``` -------------------------------- ### Configure Geth with a Configuration File Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/README.md Launches the Geth client using a specified TOML configuration file. This method allows for managing numerous flags through a single configuration file for easier setup and management. ```shell $ geth --config /path/to/your_config.toml ``` -------------------------------- ### Install CMake Configuration and Generate PkgConfig Source: https://github.com/megaeth-labs/mega-op-geth/blob/optimism/crypto/secp256k1/libsecp256k1/src/CMakeLists.txt This snippet demonstrates how to install a CMake configuration version file and generate a pkg-config file for the project. It utilizes CMake's install command and the GeneratePkgConfig module. ```cmake install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) include(GeneratePkgConfigFile) generate_pkg_config_file(${PROJECT_SOURCE_DIR}/libsecp256k1.pc.in) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) endif() ```