kopia lustrzana https://github.com/bugout-dev/moonstream
Txpool working with both blockchains
rodzic
a5d3226496
commit
e6f650624b
|
@ -44,6 +44,7 @@ POLYGON_MISSING_SERVICE_FILE="polygon-missing.service"
|
|||
POLYGON_MISSING_TIMER_FILE="polygon-missing.timer"
|
||||
POLYGON_STATISTICS_SERVICE_FILE="polygon-statistics.service"
|
||||
POLYGON_STATISTICS_TIMER_FILE="polygon-statistics.timer"
|
||||
POLYGON_TXPOOL_SERVICE_FILE="polygon-txpool.service"
|
||||
|
||||
|
||||
set -eu
|
||||
|
@ -52,8 +53,8 @@ echo
|
|||
echo
|
||||
echo -e "${PREFIX_INFO} Building executable Ethereum transaction pool crawler script with Go"
|
||||
EXEC_DIR=$(pwd)
|
||||
cd "${APP_CRAWLERS_DIR}/ethtxpool"
|
||||
HOME=/root /usr/local/go/bin/go build -o "${APP_CRAWLERS_DIR}/ethtxpool/ethtxpool" "${APP_CRAWLERS_DIR}/ethtxpool/main.go"
|
||||
cd "${APP_CRAWLERS_DIR}/txpool"
|
||||
HOME=/root /usr/local/go/bin/go build -o "${APP_CRAWLERS_DIR}/txpool/txpool" "${APP_CRAWLERS_DIR}/txpool/main.go"
|
||||
cd "${EXEC_DIR}"
|
||||
|
||||
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}"
|
||||
systemctl daemon-reload
|
||||
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}"
|
||||
|
|
|
@ -5,9 +5,9 @@ After=network.target
|
|||
[Service]
|
||||
User=ubuntu
|
||||
Group=www-data
|
||||
WorkingDirectory=/home/ubuntu/moonstream/crawlers/ethtxpool
|
||||
WorkingDirectory=/home/ubuntu/moonstream/crawlers/txpool
|
||||
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
|
||||
|
||||
[Install]
|
||||
|
|
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||
module github.com/bugout-dev/moonstream/crawlers/ethtxpool
|
||||
module github.com/bugout-dev/moonstream/crawlers/txpool
|
||||
|
||||
go 1.16
|
||||
|
|
@ -12,6 +12,7 @@ import (
|
|||
"fmt"
|
||||
"math/big"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
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
|
||||
func PollTxpoolContent(gethClient *rpc.Client, interval int, reporter *humbug.HumbugReporter) {
|
||||
func PollTxpoolContent(gethClient *rpc.Client, interval int, reporter *humbug.HumbugReporter, blockchain string) {
|
||||
initPoll := true
|
||||
currentTransactions := make(map[common.Hash]bool)
|
||||
|
||||
|
@ -121,7 +122,7 @@ func PollTxpoolContent(gethClient *rpc.Client, interval int, reporter *humbug.Hu
|
|||
continue
|
||||
}
|
||||
|
||||
ReportTitle := "Ethereum: Pending transaction: " + transactionHash.String()
|
||||
ReportTitle := fmt.Sprintf("%s: Pending transaction: ", strings.Title(blockchain)) + transactionHash.String()
|
||||
ReportTags := []string{
|
||||
"hash:" + transactionHash.String(),
|
||||
"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("gas:%d", pendingTx.Transaction.Gas),
|
||||
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{
|
||||
Title: ReportTitle,
|
||||
|
@ -175,13 +176,17 @@ func PollTxpoolContent(gethClient *rpc.Client, interval int, reporter *humbug.Hu
|
|||
}
|
||||
|
||||
func main() {
|
||||
var blockchain string
|
||||
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.Parse()
|
||||
|
||||
var MOONSTREAM_NODE_ETHEREUM_IPC_ADDR = os.Getenv("MOONSTREAM_NODE_ETHEREUM_IPC_ADDR")
|
||||
var MOONSTREAM_NODE_ETHEREUM_IPC_PORT = os.Getenv("MOONSTREAM_NODE_ETHEREUM_IPC_PORT")
|
||||
var MOONSTREAM_IPC_PATH = fmt.Sprintf("http://%s:%s", MOONSTREAM_NODE_ETHEREUM_IPC_ADDR, MOONSTREAM_NODE_ETHEREUM_IPC_PORT)
|
||||
var MOONSTREAM_NODE_IPC_ADDR = os.Getenv(fmt.Sprintf("MOONSTREAM_NODE_%s_IPC_ADDR", strings.ToUpper(blockchain)))
|
||||
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_IPC_ADDR, MOONSTREAM_NODE_IPC_PORT)
|
||||
|
||||
fmt.Println(MOONSTREAM_IPC_PATH)
|
||||
|
||||
sessionID := uuid.New().String()
|
||||
|
||||
|
@ -213,5 +218,5 @@ func main() {
|
|||
panic(fmt.Sprintf("Invalid Humbug configuration: %s", err.Error()))
|
||||
}
|
||||
|
||||
PollTxpoolContent(gethClient, intervalSeconds, reporter)
|
||||
PollTxpoolContent(gethClient, intervalSeconds, reporter, blockchain)
|
||||
}
|
Ładowanie…
Reference in New Issue