|
| 1 | +# AGENTS Guidelines for This Repository |
| 2 | + |
| 3 | +This repository contains a Go-based tool for testing transaction latency on Base blockchain with Flashblocks support. When working on the project interactively with an agent (e.g. the Codex CLI) please follow the guidelines below for safe and efficient development. |
| 4 | + |
| 5 | +## 1. Use Docker for Consistent Testing |
| 6 | + |
| 7 | +* **Always use Docker** for running tests to ensure consistent environment. |
| 8 | +* **Test with small transaction counts first** (`NUMBER_OF_TRANSACTIONS=1-5`) during development. |
| 9 | +* **Use testnet endpoints** for development and testing before mainnet. |
| 10 | +* **Monitor gas costs** when testing on mainnet. |
| 11 | + |
| 12 | +## 2. Keep Dependencies in Sync |
| 13 | + |
| 14 | +If you update dependencies: |
| 15 | + |
| 16 | +1. Update using Go modules: `go get -u <package>`. |
| 17 | +2. Run `go mod tidy` to clean up dependencies. |
| 18 | +3. Test changes locally before committing. |
| 19 | +4. Verify compatibility with Go 1.24+ as specified in the project. |
| 20 | + |
| 21 | +## 3. Environment Configuration |
| 22 | + |
| 23 | +Create a `.env` file for testing (never commit): |
| 24 | + |
| 25 | +```env |
| 26 | +PRIVATE_KEY=your_test_private_key |
| 27 | +TO_ADDRESS=0xc2F695613de0885dA3bdd18E8c317B9fAf7d4eba |
| 28 | +POLLING_INTERVAL_MS=50 |
| 29 | +BASE_NODE_ENDPOINT_1=https://your-flashblocks-endpoint |
| 30 | +BASE_NODE_ENDPOINT_2=https://your-standard-endpoint |
| 31 | +REGION=test |
| 32 | +NUMBER_OF_TRANSACTIONS=5 |
| 33 | +SEND_TXN_SYNC=true |
| 34 | +RUN_ENDPOINT2_TESTING=true |
| 35 | +``` |
| 36 | + |
| 37 | +## 4. Code Quality Checks |
| 38 | + |
| 39 | +Before completing any task, run these quality checks: |
| 40 | + |
| 41 | +| Command | Purpose | |
| 42 | +| ------------------------ | ---------------------------------------- | |
| 43 | +| `go fmt ./...` | Format code to Go standards | |
| 44 | +| `go vet ./...` | Run static analysis | |
| 45 | +| `go test ./...` | Run unit tests | |
| 46 | +| `golangci-lint run` | Run comprehensive linting (if installed)| |
| 47 | + |
| 48 | +## 5. Testing Workflow |
| 49 | + |
| 50 | +Test changes progressively: |
| 51 | + |
| 52 | +1. **Build verification**: Ensure code compiles |
| 53 | + ```bash |
| 54 | + go build -o test-latency main.go |
| 55 | + ``` |
| 56 | + |
| 57 | +2. **Docker build**: Test container build |
| 58 | + ```bash |
| 59 | + docker build -t transaction-latency . |
| 60 | + ``` |
| 61 | + |
| 62 | +3. **Small test run**: Test with minimal transactions |
| 63 | + ```bash |
| 64 | + docker run -v $(pwd)/data:/data --env-file .env --rm -it transaction-latency |
| 65 | + ``` |
| 66 | + |
| 67 | +4. **Results verification**: Check output in `data/` directory |
| 68 | + |
| 69 | +## 6. Development Best Practices |
| 70 | + |
| 71 | +* Use proper error handling for all RPC calls. |
| 72 | +* Log important events for debugging. |
| 73 | +* Validate environment variables before use. |
| 74 | +* Handle network timeouts gracefully. |
| 75 | +* Clean up resources properly (close connections). |
| 76 | + |
| 77 | +## 7. Docker Development |
| 78 | + |
| 79 | +When modifying the Dockerfile: |
| 80 | + |
| 81 | +* Keep the image minimal (use multi-stage builds if needed). |
| 82 | +* Pin dependency versions for reproducibility. |
| 83 | +* Use non-root user for running the application. |
| 84 | +* Mount data directory for persistent results. |
| 85 | + |
| 86 | +## 8. Testing Modes |
| 87 | + |
| 88 | +### Synchronous Mode (`SEND_TXN_SYNC=true`) |
| 89 | +* Uses `eth_sendRawTransactionSync` method. |
| 90 | +* Requires Flashblocks-enabled endpoint. |
| 91 | +* Provides instant confirmation receipts. |
| 92 | +* Best for testing Flashblocks performance. |
| 93 | + |
| 94 | +### Asynchronous Mode (`SEND_TXN_SYNC=false`) |
| 95 | +* Uses standard `eth_sendTransaction` method. |
| 96 | +* Works with any Base endpoint. |
| 97 | +* Polls for receipts using `POLLING_INTERVAL_MS`. |
| 98 | +* Good for compatibility testing. |
| 99 | + |
| 100 | +## 9. Data Analysis |
| 101 | + |
| 102 | +Results are saved to `data/` directory: |
| 103 | +* Review CSV files for latency measurements. |
| 104 | +* Compare endpoint1 vs endpoint2 performance. |
| 105 | +* Check for anomalies in inclusion delays. |
| 106 | +* Validate block numbers for consistency. |
| 107 | + |
| 108 | +## 10. Useful Commands Recap |
| 109 | + |
| 110 | +| Command | Purpose | |
| 111 | +| ---------------------------------------------- | --------------------------------- | |
| 112 | +| `go build -o test-latency main.go` | Build the binary | |
| 113 | +| `docker build -t transaction-latency .` | Build Docker image | |
| 114 | +| `docker run -v $(pwd)/data:/data --env-file .env --rm -it transaction-latency` | Run test | |
| 115 | +| `go fmt ./...` | Format Go code | |
| 116 | +| `go mod tidy` | Clean up dependencies | |
| 117 | + |
| 118 | +## 11. Safety Reminders |
| 119 | + |
| 120 | +* **Never commit private keys** or sensitive data. |
| 121 | +* **Use testnet first** for all development testing. |
| 122 | +* **Monitor gas usage** to avoid unexpected costs. |
| 123 | +* **Start with few transactions** to validate logic. |
| 124 | +* **Check endpoint compatibility** before testing. |
| 125 | +* **Keep test data** for analysis and debugging. |
| 126 | + |
| 127 | +## 12. Common Issues |
| 128 | + |
| 129 | +* "Error loading .env file" in Docker is expected and harmless (env vars loaded via --env-file). |
| 130 | +* Ensure endpoints support required RPC methods for chosen mode. |
| 131 | +* Flashblocks endpoints required for synchronous mode. |
| 132 | +* Network latency affects actual confirmation times. |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +Following these practices ensures safe testing, prevents unnecessary gas costs, and maintains code quality. Always test with small transaction counts and testnet endpoints during development before scaling up to production testing. |
0 commit comments