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

500 error returned by getblockreward api #3692

Closed
Drunken-Dragon opened this issue Mar 9, 2021 · 7 comments
Closed

500 error returned by getblockreward api #3692

Drunken-Dragon opened this issue Mar 9, 2021 · 7 comments
Labels
waiting on feedback Waiting for original opener to respond if bug is fixed

Comments

@Drunken-Dragon
Copy link

Describe your issue here.

Environment

  • Operating System: Ubuntu 18.04.4 LTS
  • Blockscout Version/branch: 2.5.13-stable

Steps to reproduce

When calling the API via web browser or curl:
https://explorer.energyweb.org/api?module=block&action=getblockreward&blockno=10090232
we get 500 error and "Something went wrong" message.

Expected behaviour

Calling above API we get a response containing the block info, like in the below example prom POA network:
{ "message": "OK", "result": { "blockMiner": "0xdfe10d55d9248b2ed66f1647df0b0a46deb25165", "blockNumber": "11897954", "blockReward": "2000000000000000000", "timeStamp": 1573204620, "uncleInclusionReward": null, "uncles": null }, "status": "1" }

Actual behaviour

We get the following response:
{ "message": "Something went wrong.", "result": null, "status": "0" }

We already checked issue #2848, and we use the chain spec file for our custom chain.

Any suggestion what else can we try will be much appreciated.

@vbaranov
Copy link
Member

@Drunken-Dragon likely this means, that spec file was not parsed correctly and you should see errors in the logs regarding failed spec file import on your instance of Blockscout. Import is happening in the first minutes of the application start. You can try to restart the application in order to find errors in the logs.

@vbaranov vbaranov added the waiting on feedback Waiting for original opener to respond if bug is fixed label Mar 10, 2021
@Drunken-Dragon
Copy link
Author

Drunken-Dragon commented Mar 10, 2021

@vbaranov I went through the logs and did not find anything related to spec file loading. However I found something like this in our explorer.log:
2021-03-10T10:26:01.783 application=explorer [warn] Failed to fetch genesis data. :enoent
That happened just right after I restarted the Blockscout container.

I also get the following results (from the container logs), when calling the API for the reward:
`2021-03-10T10:43:28.275 application=plug request_id=Fmr1MUIFJyFLZtEAAnfi [info] GET /api

2021-03-10T10:43:28.317 application=block_scout_web request_id=Fmr1MUIFJyFLZtEAAnfi [error] Error while calling RPC action"** (Plug.Conn.WrapperError) ** (Ecto.NoResultsError) expected at least one result but got none in query:\n\nfrom b0 in Explorer.Chain.Block,\n left_join: t1 in assoc(b0, :transactions),\n join: e2 in Explorer.Chain.Block.EmissionReward,\n on: fragment("? <@ ?", b0.number, e2.block_range),\n where: b0.number == ^10090232,\n group_by: [e2.reward],\n select: %Explorer.Chain.Wei{value: coalesce(sum(t1.gas_used * t1.gas_price), 0) + e2.reward}\n\n (ecto 3.5.5) lib/ecto/repo/queryable.ex:159: Ecto.Repo.Queryable.one!/3\n (block_scout_web 0.0.1) lib/block_scout_web/controllers/api/rpc/block_controller.ex:12: BlockScoutWeb.API.RPC.BlockController.getblockreward/2\n (block_scout_web 0.0.1) lib/block_scout_web/controllers/api/rpc/block_controller.ex:1: BlockScoutWeb.API.RPC.BlockController.action/2\n (block_scout_web 0.0.1) lib/block_scout_web/controllers/api/rpc/block_controller.ex:1: BlockScoutWeb.API.RPC.BlockController.phoenix_controller_pipeline/2\n (block_scout_web 0.0.1) lib/block_scout_web/controllers/api/rpc/rpc_translator.ex:101: BlockScoutWeb.API.RPC.RPCTranslator.call_controller/3\n (block_scout_web 0.0.1) lib/block_scout_web/controllers/api/rpc/rpc_translator.ex:31: BlockScoutWeb.API.RPC.RPCTranslator.call/2\n (phoenix 1.5.6) lib/phoenix/router/route.ex:41: Phoenix.Router.Route.call/2\n (phoenix 1.5.6) lib/phoenix/router.ex:352: Phoenix.Router.call/2\n"

2021-03-10T10:43:28.317 application=plug request_id=Fmr1MUIFJyFLZtEAAnfi [info] Sent 500 in 41ms`

I checked the CHAIN_SPEC_PATH and it shows correctly our chainspec the Github, the path is also visible inside the running container.

Can our problem be related to failing to fetch genesis data?

Also, is there any other way to verify if the chainspec data is indeed loaded correctly, apart from no error logs and ENV verification?

@vbaranov
Copy link
Member

@Drunken-Dragon is emission format in EnergyWeb chain is identical to POA? If yes, you also need to specify EMISSION_FORMAT=POA

From the docs:

Should be set to POA if you have block emission identical to POA Network. This env var is used only if CHAIN_SPEC_PATH is set

If no, your spec file somehow different from standard Geth genesis or OpenEthereum chain spec files which are supported from the ox y this feature.

Actually, in order to make the requested endpoint work, emission_rewards table should not be empty. It stores the amount of reward for each range of block numers. It should look something like this:

block_range | reward
-------------+---------------------
[0,) | 1000000000000000000

You can try to fill it manually.

@Drunken-Dragon
Copy link
Author

Drunken-Dragon commented Mar 16, 2021

@vbaranov I tried setting the EMISSION_FORMAT=POA and it does not help.

However, the emission_rewards table is empty indeed.

Could you share some more details about it? How is it supposed to fill? Should we set some flag or variable to fill it with the right data?

I am not entirely sure what should I put to the table, if it can be filled manually, like you mentioned.

@vbaranov
Copy link
Member

@Drunken-Dragon

emission_rewards table stores the value of emission reward which is acquired at each range of block numbers

block_range column - a range of block numbers where emission reward has the same value per block
reward column - the value of emission reward per block in the given range of blocks

If your chain doesn't have any defined emission rewards, just put a single row to the table:

block_range | reward
-------------+----------
[0,) | 0

@vbaranov
Copy link
Member

@Drunken-Dragon I am closing this issue. Please re-open it if the issue still persists.

@Drunken-Dragon
Copy link
Author

@vbaranov I inserted the row manually just like you suggest and it worked, we get a correct response from the endpoint. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting on feedback Waiting for original opener to respond if bug is fixed
Projects
None yet
Development

No branches or pull requests

3 participants
@vbaranov @Drunken-Dragon and others