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

Receiving different responses targeting a host name locally or remotely #2688

Open
emclab opened this issue Aug 28, 2021 · 11 comments
Open

Receiving different responses targeting a host name locally or remotely #2688

emclab opened this issue Aug 28, 2021 · 11 comments
Labels
bug Something isn't working P3 Medium (ex: JSON-RPC request not working with a specific client library due to loose spec assumtion)

Comments

@emclab
Copy link

emclab commented Aug 28, 2021

Description

This error happened in React Native 0.64.2 app, with ethersjs 5.4. The app used to use IP address to connect to boot node. After the boot node was assigned a domain name, the domain name is used to connect to the Besu network. Then there is an no response error when trying to read the blockNumber. Here is the code:

import { ContractFactory, ethers } from "ethers"; //<<==ethers 5.4
PROVIDER_URL:"http://mydomain",  //<<== domain name is used for provider. GLOBAL.PROVIDER_URL
..............

let connection = {};
        connection.url = GLOBAL.PROVIDER_URL;
        connection.headers = {
          "Authorization" : `Bearer ${ _tokenBesu }`. //<<==no authorization required as it is not enabled on Besu network
        };
const _provider = new ethers.providers.StaticJsonRpcProvider(connection, 2018); 
        //test connection
        _provider.getBlockNumber().then(res => {
          console.log("blockNumber returned : ", res);
        }).catch(error => console.log("Connection mainchain error ", error));

The error is

LOG Connection mainchain error [Error: missing response (requestBody="{\"method\":\"eth_blockNumber\",\"params\":[],\"id\":42,\"jsonrpc\":\"2.0\"}", requestMethod="POST", serverError={}, url="http://mydomain", code=SERVER_ERROR, version=web/5.4.0)]

If replacing domain name with IP address of boot node in connection url, then it works:

LOG blockNumber returned : 53826

Acceptance Criteria

Shall return block number.

Steps to Reproduce (Bug)

See code in above
2. [Step 2]
3. [Step ...]

Expected behavior: [What you expect to happen]
Shall return block number with domain name in provider
Actual behavior: [What actually happens]
NO response with domain name.
Frequency: [What percentage of the time does it occur?]
every time

Versions (Add all that apply)

  • Software version: [besu --version]21.7.2
  • Java version: [java -version] openjdk 14
  • OS Name & Version: [cat /etc/*release] MacOS
  • Kernel Version: [uname -a]
  • Virtual Machine software & version: [vmware -v]
  • Docker Version: [docker version]
  • Cloud VM, type, size: [Amazon Web Services I3-large]

Additional Information

React Native : 0.64.2
ethers: 5.4

@atoulme
Copy link
Contributor

atoulme commented Aug 28, 2021

Did you set up besu to allow the host name? What parameters did you use running Besu?

@emclab
Copy link
Author

emclab commented Aug 31, 2021

atoulme, here is my config.toml for boot node. I am not aware of setting up for host name.

# Valid TOML config file
data-path="/home/besu_network/node1/data" # Path

p2p-port=30303 
max-peers=25
rpc-http-host=["0.0.0.0"] 
rpc-http-port=8545 
rpc-http-enabled=true 
rpc-http-api=["ETH","NET","WEB3","ADMIN","TXPOOL","IBFT", "EEA","DEBUG"] 

metrics-port=9545 
metrics-push-port=9001 
min-gas-price=0 
logging="DEBUG"
#allow all
host-allowlist=["*"] 
rpc-http-cors-origins=["*"]
# Chain
genesis-file="/home/besu_network/genesis.json" # Path to the custom genesis file
miner-enabled=false 
miner-coinbase="0xfe3b557b8fb62b89f4116b721be55deb828dbd73"

@emclab
Copy link
Author

emclab commented Aug 31, 2021

added host-whitelist=["domain.com"] and removed host-allowlist in config.toml above and restart. Still the same error.

@vmichalik vmichalik added bug Something isn't working P3 Medium (ex: JSON-RPC request not working with a specific client library due to loose spec assumtion) labels Sep 1, 2021
@macfarla macfarla added the TeamRevenant GH issues worked on by Revenant Team label Sep 1, 2021
@vmichalik vmichalik removed the TeamRevenant GH issues worked on by Revenant Team label Sep 6, 2021
@emclab
Copy link
Author

emclab commented Sep 7, 2021

Is there workaround about the issue? https is preferred in production environment and, without domain only http can be used.

@atoulme
Copy link
Contributor

atoulme commented Sep 7, 2021

Still no idea what the problem is from your steps. Please provide a detailed log. Do you reproduce with a curl command?

@emclab
Copy link
Author

emclab commented Sep 7, 2021

Here is a message posted on Besu chat:

Hi, when host-whitelist and host-allowlist enabled at the same time in config.toml for boot node, there is an error. It is on ubuntu 20.04 and Besu 21.7.2:
picocli.CommandLine$ParameterException: Values '*' or 'all' can't be used with other hostnames
at org.hyperledger.besu.cli.BesuCommand.run(BesuCommand.java:1223)
at picocli.CommandLine.executeUserObject(CommandLine.java:1939)
at picocli.CommandLine.access$1300(CommandLine.java:145)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2346)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2311)
at picocli.CommandLine$AbstractParseResultHandler.handleParseResult(CommandLine.java:2172)
at picocli.CommandLine.parseWithHandlers(CommandLine.java:2550)
at org.hyperledger.besu.cli.util.ConfigOptionSearchAndRunHandler.handle(ConfigOptionSearchAndRunHandler.java:56)
at org.hyperledger.besu.cli.util.ConfigOptionSearchAndRunHandler.handle(ConfigOptionSearchAndRunHandler.java:31)
at picocli.CommandLine$AbstractParseResultHandler.handleParseResult(CommandLine.java:2172)
at picocli.CommandLine.parseWithHandlers(CommandLine.java:2550)
at org.hyperledger.besu.cli.BesuCommand.parse(BesuCommand.java:1367)
at org.hyperledger.besu.cli.BesuCommand.parse(BesuCommand.java:1190)
at org.hyperledger.besu.Besu.main(Besu.java:50)
Caused by: java.lang.IllegalArgumentException: Values '*' or 'all' can't be used with other hostnames
at org.hyperledger.besu.cli.custom.JsonRPCAllowlistHostsProperty.addAll(JsonRPCAllowlistHostsProperty.java:81)
at org.hyperledger.besu.cli.BesuCommand.configure(BesuCommand.java:1607)
at org.hyperledger.besu.cli.BesuCommand.run(BesuCommand.java:1216)
... 14 more

To display full help:
besu [COMMAND] --help



The config.toml code is:
host-whitelist=["my domain"]
host-allowlist=["*"]
If I would like to use domain name in provider, how shall host-whitelist and host-allowlist be configured? What I find is that if host-allowlist is removed, then using IP address in provider does not work.

@emclab
Copy link
Author

emclab commented Sep 7, 2021

Here is the link of discussion on ethers GitHub about domain name vs IP address in provider. No error in bootnode log was found when submitting with a domain name.

@emclab
Copy link
Author

emclab commented Sep 7, 2021

ssh into the boot node to run the curl works:

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":51}' http://domain.top
{
  "jsonrpc" : "2.0",
  "id" : 51,
  "result" : "0x7a558"

However if do a curl on a remote PC, then there is an error. Is that related to configuration below?

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":51}' http://mydomain.top    
<html>
<head>
<meta http-equiv="Content-Type" content="textml;charset=UTF-8" />
   <style>body{background-color:#FFFFFF}</style> 
<title>TestPage184</title>
  <script language="javascript" type="text/javascript">
         window.onload = function () { 
           document.getElementById("mainFrame").src= "http://batit.aliyun.com/alww.html"; 
            }
</script>   
</head>
  <body>
    <iframe style="width:860px; height:500px;position:absolute;margin-left:-430px;margin-top:-250px;top:50%;left:50%;" id="mainFrame" src="" frameborder="0" scrolling="no"></iframe>
    </body>
      </html>

Here is the config.toml on boot node:

data-path="/home/besu_network/node1/data" # Path
p2p-port=30303
max-peers=25

rpc-http-host=["0.0.0.0"]
rpc-http-port=8545
rpc-http-enabled=true
rpc-http-api=["ETH","NET","WEB3","ADMIN","TXPOOL","IBFT", "EEA","DEBUG"]

metrics-port=9545
metrics-push-port=9001
min-gas-price=0
logging="DEBUG"
#allow all
#host-whitelist=["mydomain.top"]
host-allowlist=["*"]
rpc-http-cors-origins=["*"]
# Chain
genesis-file="/home/besu_network/genesis.json" # Path to the custom genesis file
miner-enabled=false
miner-coinbase="0xfe3b557e8fb62b89f4916b721be55ceb828dbd73"

@atoulme
Copy link
Contributor

atoulme commented Sep 8, 2021

So you’re not receiving nothing. You’re receiving a html page.

please do this for me: compare the output of host domain.top on the mode and remotely.

@atoulme atoulme changed the title No response using domain name and works with IP address of boot node Receiving different responses targeting a host name locally or remotely Sep 8, 2021
@emclab
Copy link
Author

emclab commented Sep 8, 2021

remote:

host mydomain.top
mydomain.top has address xxx.xxx.21.141
;; connection timed out; no servers could be reached
;; connection timed out; no servers could be reached

on boot node:
host mydomain.top
mydomain.top has address xxx.xxx.21.141

@emclab
Copy link
Author

emclab commented Sep 8, 2021

The boot node is behind nginx reverse proxy server on port 80. Any http request to http://mydomain.top or http://IP address will be forwarded by proxy to port 8485,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P3 Medium (ex: JSON-RPC request not working with a specific client library due to loose spec assumtion)
Projects
None yet
Development

No branches or pull requests

4 participants