Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server/eth: Monitor RPC provider health #2125

Merged
merged 6 commits into from Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions dex/testing/dcrdex/harness.sh
Expand Up @@ -217,16 +217,17 @@ EOF
fi

if [ $ETH_ON -eq 0 ]; then

ETH_CONFIG_PATH=${TEST_ROOT}/eth.conf
ETH_IPC_FILE=${TEST_ROOT}/eth/alpha/node/geth.ipc
cat << EOF >> $ETH_CONFIG_PATH

cat > $ETH_CONFIG_PATH <<EOF
ws://localhost:38557
# comments are respected
# http://localhost:38556
${ETH_IPC_FILE}
EOF
cat << EOF >> "./markets.json"

cat << EOF >> "./markets.json"
},
"ETH_simnet": {
"bip44symbol": "eth",
Expand Down
16 changes: 14 additions & 2 deletions server/asset/eth/eth.go
Expand Up @@ -281,12 +281,14 @@ func NewBackend(configPath string, log dex.Logger, net dex.Network) (*ETHBackend
defer file.Close()

var endpoints []string
endpointsMap := make(map[string]bool) // to avoid duplicates
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := strings.Trim(scanner.Text(), " ")
if line == "" || strings.HasPrefix(line, "#") {
if line == "" || strings.HasPrefix(line, "#") || endpointsMap[line] {
Copy link
Member

Choose a reason for hiding this comment

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

In testing I commented one with a ; like a lot of .conf files allow. Would you pls add that HasPrefix check?

continue
}
endpointsMap[line] = true
endpoints = append(endpoints, line)
}
if err := scanner.Err(); err != nil {
Expand All @@ -301,7 +303,17 @@ func NewBackend(configPath string, log dex.Logger, net dex.Network) (*ETHBackend
if err != nil {
return nil, err
}
eth.node = newRPCClient(eth.net, endpoints, log.SubLogger("RPC"))

netAddrs, found := dexeth.ContractAddresses[ethContractVersion]
if !found {
return nil, fmt.Errorf("no contract address for eth version %d", ethContractVersion)
}
ethContractAddr, found := netAddrs[eth.net]
if !found {
return nil, fmt.Errorf("no contract address for eth version %d on %s", ethContractVersion, eth.net)
}

eth.node = newRPCClient(eth.net, endpoints, ethContractAddr, log.SubLogger("RPC"))
return eth, nil
}

Expand Down