Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ To start all available features, or you want more customized operations, navigat
- **Gradle Docker**: Automate Docker image builds and testing. Check the [gradle docker](./tools/docker/README.md) documentation.
- **Toolkit**: Perform a set of database related operations. Follow the [Toolkit guidance](./tools/toolkit/README.md).
- **Stress Test**: Execute the stress test. Follow the [stress test guidance](./tools/stress_test/README.md).
- **Slack SR Monitor**: Monitor Super Representatives and notify a Slack channel after every maintenance period. Follow the [Slack SR Monitor guidance](./tools/slack_sr_monitor/README.md).

## Troubleshooting
If you encounter any difficulties, please refer to the [Issue Work Flow](https://tronprotocol.github.io/documentation-en/developers/issue-workflow/#issue-work-flow), then raise an issue on [GitHub](https://github.com/tronprotocol/tron-docker/issues). For general questions, please use [Discord](https://discord.gg/cGKSsRVCGm) or [Telegram](https://t.me/TronOfficialDevelopersGroupEn).
Expand Down
8 changes: 8 additions & 0 deletions tools/slack_sr_monitor/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Slack SR Monitor Configuration

# The Slack Webhook URL for sending notifications
SLACK_WEBHOOK=your_slack_webhook_url_here

# The Tron node API endpoint
# Default: https://api.trongrid.io
TRON_NODE=https://api.trongrid.io
4 changes: 4 additions & 0 deletions tools/slack_sr_monitor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
slack_sr_monitor
logs/

31 changes: 31 additions & 0 deletions tools/slack_sr_monitor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Build stage
FROM golang:1.25-alpine AS builder

WORKDIR /app

# Install dependencies
COPY go.mod go.sum ./
RUN go mod download

# Copy source code
COPY . .

# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -o slack_sr_monitor main.go

# Final stage
FROM alpine:latest

RUN apk --no-cache add ca-certificates tzdata

WORKDIR /root/

# Create logs directory
RUN mkdir -p logs

# Copy the binary from builder
COPY --from=builder /app/slack_sr_monitor .

# Command to run
CMD ["./slack_sr_monitor"]

63 changes: 63 additions & 0 deletions tools/slack_sr_monitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
## Slack SR Monitor Tool
The Slack SR Monitor tool is designed to monitor TRON Super Representatives (SRs) and notify a Slack channel after every maintenance period.
It automatically tracks vote changes and detects replacements in the top 27 SR positions, providing a clear and formatted report.

### Build and Run the monitor
To run the monitor tool, you can choose between native Go execution or Docker deployment.

#### Native Go Execution
Make sure you have Go 1.25+ installed.
```shell
# enter the directory
cd tools/slack_sr_monitor
# install dependencies
go mod tidy
# run the tool
go run main.go
```

#### Docker Deployment
We provide a Docker-based deployment for easier management in production environments.
```shell
# build and start the container
docker-compose up -d --build
# check logs
docker logs -f slack-sr-monitor
```

### Configuration
All configurations are managed via environment variables or a `.env` file in the project root. Please refer to [.env.example](./.env.example) as an example.

- `SLACK_WEBHOOK`: The Slack Incoming Webhook URL used to send notifications.
- `TRON_NODE`: The TRON node HTTP API endpoint (e.g., `http://https://api.trongrid.io`). Default is Trongrid.

### Key Features

#### SR vote monitor
Use `/wallet/getpaginatednowwitnesslist` to get the top **28** real-time votes, also the SR address and URL.

#### Dynamic Scheduling
Instead of a fixed interval, the tool queries `/wallet/getnextmaintenancetime` to calculate the exact wait time. It triggers the report **1 minute** after each maintenance period begins to ensure data consistency.

#### Parallel Data Acquisition
The tool uses Go routines to fetch `account_name` for all 28 witnesses in parallel from the `/wallet/getaccount` interface, significantly reducing the collection time.

#### Vote Change Tracking
The tool maintains an in-memory snapshot of the previous period's votes. It calculates the `Change` for each SR:
```text
*1. Poloniex*
Current: `3,228,089,488` Change: `+89,488`
```

#### Top 27 Replacement Detection
After each report, it compares the current Top 27 list with the previous one and highlights any changes:
```text
SR Replacement Detected:
>:inbox_tray: *Entered:* New_SR_Name
>:outbox_tray: *Left:* Old_SR_Name
```
If no changes occur, it displays `Top 27 SRs remain unchanged.`

### Notifications

This monitor only support java-tron node v4.8.1+, because of the API it used.
11 changes: 11 additions & 0 deletions tools/slack_sr_monitor/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
slack-sr-monitor:
build: .
container_name: slack-sr-monitor
restart: always
environment:
- SLACK_WEBHOOK=${SLACK_WEBHOOK}
- TRON_NODE=${TRON_NODE:-https://api.trongrid.io}
volumes:
- ./logs:/root/logs

5 changes: 5 additions & 0 deletions tools/slack_sr_monitor/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/tronprotocol/tron-docker/tools/slack_sr_monitor

go 1.25.5

require github.com/joho/godotenv v1.5.1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the security of this package

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package is the de-facto standard for environment variable management in the Go community (10k+ Stars), repo: https://github.com/joho/godotenv. Its logic is minimal and transparent (reading local files only).

I've scanned the project using the official Go vulnerability tool govulncheck, and no vulnerabilities were detected in this package.

2 changes: 2 additions & 0 deletions tools/slack_sr_monitor/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
Loading