Merge pull request #460 from bugout-dev/txpool-polygon

Txpool working with both blockchains
pull/462/head
Sergei Sumarokov 2021-11-25 16:14:23 +03:00 zatwierdzone przez GitHub
commit 8f459fbee9
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
8 zmienionych plików z 40 dodań i 12 usunięć

Wyświetl plik

@ -44,6 +44,7 @@ POLYGON_MISSING_SERVICE_FILE="polygon-missing.service"
POLYGON_MISSING_TIMER_FILE="polygon-missing.timer" POLYGON_MISSING_TIMER_FILE="polygon-missing.timer"
POLYGON_STATISTICS_SERVICE_FILE="polygon-statistics.service" POLYGON_STATISTICS_SERVICE_FILE="polygon-statistics.service"
POLYGON_STATISTICS_TIMER_FILE="polygon-statistics.timer" POLYGON_STATISTICS_TIMER_FILE="polygon-statistics.timer"
POLYGON_TXPOOL_SERVICE_FILE="polygon-txpool.service"
set -eu set -eu
@ -52,8 +53,8 @@ echo
echo echo
echo -e "${PREFIX_INFO} Building executable Ethereum transaction pool crawler script with Go" echo -e "${PREFIX_INFO} Building executable Ethereum transaction pool crawler script with Go"
EXEC_DIR=$(pwd) EXEC_DIR=$(pwd)
cd "${APP_CRAWLERS_DIR}/ethtxpool" cd "${APP_CRAWLERS_DIR}/txpool"
HOME=/root /usr/local/go/bin/go build -o "${APP_CRAWLERS_DIR}/ethtxpool/ethtxpool" "${APP_CRAWLERS_DIR}/ethtxpool/main.go" HOME=/root /usr/local/go/bin/go build -o "${APP_CRAWLERS_DIR}/txpool/txpool" "${APP_CRAWLERS_DIR}/txpool/main.go"
cd "${EXEC_DIR}" cd "${EXEC_DIR}"
echo echo
@ -141,3 +142,11 @@ cp "${SCRIPT_DIR}/${POLYGON_STATISTICS_SERVICE_FILE}" "/etc/systemd/system/${POL
cp "${SCRIPT_DIR}/${POLYGON_STATISTICS_TIMER_FILE}" "/etc/systemd/system/${POLYGON_STATISTICS_TIMER_FILE}" cp "${SCRIPT_DIR}/${POLYGON_STATISTICS_TIMER_FILE}" "/etc/systemd/system/${POLYGON_STATISTICS_TIMER_FILE}"
systemctl daemon-reload systemctl daemon-reload
systemctl restart "${POLYGON_STATISTICS_TIMER_FILE}" systemctl restart "${POLYGON_STATISTICS_TIMER_FILE}"
# echo
# echo
# echo -e "${PREFIX_INFO} Replacing existing Polygon transaction pool crawler service definition with ${POLYGON_TXPOOL_SERVICE_FILE}"
# chmod 644 "${SCRIPT_DIR}/${POLYGON_TXPOOL_SERVICE_FILE}"
# cp "${SCRIPT_DIR}/${POLYGON_TXPOOL_SERVICE_FILE}" "/etc/systemd/system/${POLYGON_TXPOOL_SERVICE_FILE}"
# systemctl daemon-reload
# systemctl restart "${POLYGON_TXPOOL_SERVICE_FILE}"

Wyświetl plik

@ -5,9 +5,9 @@ After=network.target
[Service] [Service]
User=ubuntu User=ubuntu
Group=www-data Group=www-data
WorkingDirectory=/home/ubuntu/moonstream/crawlers/ethtxpool WorkingDirectory=/home/ubuntu/moonstream/crawlers/txpool
EnvironmentFile=/home/ubuntu/moonstream-secrets/app.env EnvironmentFile=/home/ubuntu/moonstream-secrets/app.env
ExecStart=/home/ubuntu/moonstream/crawlers/ethtxpool/ethtxpool ExecStart=/home/ubuntu/moonstream/crawlers/txpool/txpool -blockchain ethereum
SyslogIdentifier=ethereum-txpool SyslogIdentifier=ethereum-txpool
[Install] [Install]

Wyświetl plik

@ -0,0 +1,14 @@
[Unit]
Description=Polygon txpool crawler
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/moonstream/crawlers/txpool
EnvironmentFile=/home/ubuntu/moonstream-secrets/app.env
ExecStart=/home/ubuntu/moonstream/crawlers/txpool/txpool -blockchain polygon
SyslogIdentifier=polygon-txpool
[Install]
WantedBy=multi-user.target

Wyświetl plik

@ -1,4 +1,4 @@
module github.com/bugout-dev/moonstream/crawlers/ethtxpool module github.com/bugout-dev/moonstream/crawlers/txpool
go 1.16 go 1.16

Wyświetl plik

@ -12,6 +12,7 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"os" "os"
"strings"
"time" "time"
humbug "github.com/bugout-dev/humbug/go/pkg" humbug "github.com/bugout-dev/humbug/go/pkg"
@ -83,7 +84,7 @@ func generateChunks(xs []humbug.Report, chunkSize int) [][]humbug.Report {
} }
// Fetch list of transactions form Ethereum TxPool // Fetch list of transactions form Ethereum TxPool
func PollTxpoolContent(gethClient *rpc.Client, interval int, reporter *humbug.HumbugReporter) { func PollTxpoolContent(gethClient *rpc.Client, interval int, reporter *humbug.HumbugReporter, blockchain string) {
initPoll := true initPoll := true
currentTransactions := make(map[common.Hash]bool) currentTransactions := make(map[common.Hash]bool)
@ -121,7 +122,7 @@ func PollTxpoolContent(gethClient *rpc.Client, interval int, reporter *humbug.Hu
continue continue
} }
ReportTitle := "Ethereum: Pending transaction: " + transactionHash.String() ReportTitle := fmt.Sprintf("%s: Pending transaction: ", strings.Title(blockchain)) + transactionHash.String()
ReportTags := []string{ ReportTags := []string{
"hash:" + transactionHash.String(), "hash:" + transactionHash.String(),
"from_address:" + fromAddress, "from_address:" + fromAddress,
@ -131,7 +132,7 @@ func PollTxpoolContent(gethClient *rpc.Client, interval int, reporter *humbug.Hu
fmt.Sprintf("max_fee_per_gas:%d", pendingTx.Transaction.MaxFeePerGas.ToInt()), fmt.Sprintf("max_fee_per_gas:%d", pendingTx.Transaction.MaxFeePerGas.ToInt()),
fmt.Sprintf("gas:%d", pendingTx.Transaction.Gas), fmt.Sprintf("gas:%d", pendingTx.Transaction.Gas),
fmt.Sprintf("value:%d", new(big.Float).Quo(new(big.Float).SetInt(transaction.Value.ToInt()), big.NewFloat(params.Ether))), fmt.Sprintf("value:%d", new(big.Float).Quo(new(big.Float).SetInt(transaction.Value.ToInt()), big.NewFloat(params.Ether))),
"crawl_type:ethereum_txpool", fmt.Sprintf("crawl_type:%s_txpool", blockchain),
} }
report := humbug.Report{ report := humbug.Report{
Title: ReportTitle, Title: ReportTitle,
@ -175,13 +176,17 @@ func PollTxpoolContent(gethClient *rpc.Client, interval int, reporter *humbug.Hu
} }
func main() { func main() {
var blockchain string
var intervalSeconds int var intervalSeconds int
flag.StringVar(&blockchain, "blockchain", "ethereum", "Blockchain to crawl")
flag.IntVar(&intervalSeconds, "interval", 1, "Number of seconds to wait between RPC calls to query the transaction pool (default: 1)") flag.IntVar(&intervalSeconds, "interval", 1, "Number of seconds to wait between RPC calls to query the transaction pool (default: 1)")
flag.Parse() flag.Parse()
var MOONSTREAM_NODE_ETHEREUM_IPC_ADDR = os.Getenv("MOONSTREAM_NODE_ETHEREUM_IPC_ADDR") var MOONSTREAM_NODE_IPC_ADDR = os.Getenv(fmt.Sprintf("MOONSTREAM_NODE_%s_IPC_ADDR", strings.ToUpper(blockchain)))
var MOONSTREAM_NODE_ETHEREUM_IPC_PORT = os.Getenv("MOONSTREAM_NODE_ETHEREUM_IPC_PORT") var MOONSTREAM_NODE_IPC_PORT = os.Getenv(fmt.Sprintf("MOONSTREAM_NODE_%s_IPC_PORT", strings.ToUpper(blockchain)))
var MOONSTREAM_IPC_PATH = fmt.Sprintf("http://%s:%s", MOONSTREAM_NODE_ETHEREUM_IPC_ADDR, MOONSTREAM_NODE_ETHEREUM_IPC_PORT) var MOONSTREAM_IPC_PATH = fmt.Sprintf("http://%s:%s", MOONSTREAM_NODE_IPC_ADDR, MOONSTREAM_NODE_IPC_PORT)
fmt.Println(MOONSTREAM_IPC_PATH)
sessionID := uuid.New().String() sessionID := uuid.New().String()
@ -213,5 +218,5 @@ func main() {
panic(fmt.Sprintf("Invalid Humbug configuration: %s", err.Error())) panic(fmt.Sprintf("Invalid Humbug configuration: %s", err.Error()))
} }
PollTxpoolContent(gethClient, intervalSeconds, reporter) PollTxpoolContent(gethClient, intervalSeconds, reporter, blockchain)
} }