Skip to content

Conversation

@Retropex
Copy link
Member

@Retropex Retropex commented Jul 2, 2025

Could be very usefull for the upcoming datum-gateway package for the debian official package distribution.

// fetch latest template
snprintf(gbt_req, sizeof(gbt_req), "{\"method\":\"getblocktemplate\",\"params\":[{\"rules\":[\"segwit\"]}],\"id\":%"PRIu64"}",(uint64_t)((uint64_t)time(NULL)<<(uint64_t)8)|(uint64_t)(i&255));
gbt = bitcoind_json_rpc_call(tcurl, &datum_config, gbt_req);
gbt = bitcoind_json_rpc_call(tcurl, &datum_config, gbt_req, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're not going to set FAILONERROR, we should be checking the return code here somewhere instead

Copy link
Member Author

Choose a reason for hiding this comment

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

That's what I do below?

if ((int)json_integer_value(code_val) == -10) {

Copy link
Contributor

Choose a reason for hiding this comment

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

The HTTP return code

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm looking for a way to not touch FAILONERROR but there is something I don't understand, why do datum return the HTTP code 500 while curl ... -w "%{http_code}\n" return 200 on the same syncing node?

2025-08-27 15:12:59.975 [                          json_rpc_call_full] DEBUG: JSON decode failed(-1): wrong arguments
2025-08-27 15:12:59.975 [               datum_gateway_template_thread] ERROR: Could not fetch new template from http://localhost:8332!
2025-08-27 15:13:01.102 [                          json_rpc_call_full] DEBUG: json_rpc_call: HTTP request failed: The requested URL returned error: 500
2025-08-27 15:13:01.102 [                          json_rpc_call_full] DEBUG: json_rpc_call: Request was: {"method":"getblocktemplate","params":[{"rules":["segwit"]}],"id":449614740504}
curl --user <user> --data-binary '{"jsonrpc": "2.0", "id": "curltest", "method": "getblocktemplate", "params": [{"rules": ["segwit"]}]}' -H 'content-type: application/json' http://127.0.0.1:8332/ -w "%{http_code}\n"
Enter host password for user '<user>': <password>
{"jsonrpc":"2.0","error":{"code":-10,"message":"Bitcoin Knots is in initial sync and waiting for blocks..."},"id":"curltest"}
200

bool update_rpc_cookie(global_config_t *cfg);
void update_rpc_auth(global_config_t *cfg);
json_t *bitcoind_json_rpc_call(CURL *curl, global_config_t *cfg, const char *rpc_req);
json_t *bitcoind_json_rpc_call(CURL *curl, global_config_t *cfg, const char *rpc_req, int failonerror);
Copy link
Contributor

Choose a reason for hiding this comment

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

If it makes sense to pass failonerror (IMO it doesn't), it should be a bool

Copy link
Member Author

Choose a reason for hiding this comment

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

Why? that an easy way to not affect other call?

@luke-jr luke-jr added the enhancement New feature or request label Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants