Skip to content

Conversation

@jonasschnelli
Copy link
Contributor

No description provided.

src/rest.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Remove the second '<< binaryTx'. The response is sent twice now (but the Content-Length only covers the first).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops. was to quick.
Now it seams to be okay:

curl -v http://localhost:18332/rest/tx/3cfe5051f7efe2702c5720b1ce6f5984181b9172a399935ff22a3e08df143c91/dat > test.bin

< Content-Length: 109

ls -la test.bin
-rw-r--r--  1 jonasschnelli  staff  109 20 Nov 14:13 test.bin

src/rest.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

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

I think the point of using HTTPReply with headersOnly=true here was to avoid an extra string copy.
You could use HTTPReplyHeader(HTTP_OK, fRun, binaryBlock.size(), "application/octet-stream") << binaryBlock

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. That makes sense.

@jonasschnelli jonasschnelli changed the title [REST] fix headersonly flag for BINARY responses [REST] fix headersonly flag for BINARY responses / overhaul format handling Nov 20, 2014
@jonasschnelli
Copy link
Contributor Author

just changed.

  • Removed binary as default format, made format option mandatory, list available formats if given format is not available (reduced need for documentation).
  • Also allow .<format> (along to /<format>) as format choosing option.

src/rest.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Don't indent cases please.

@sipa
Copy link
Member

sipa commented Nov 20, 2014

I'm not sure how useful .format is. .extension would be more natural. Of course, you could add dat as equivalent for binary, and .txt as equivalent for hex...

@jtimon
Copy link
Contributor

jtimon commented Nov 20, 2014

As said on IRC my preference would be to use ?format=hex and restore json as the default.
But this is probably bikeshedding and maybe too late.

@jgarzik
Copy link
Contributor

jgarzik commented Nov 20, 2014

No, it's not too late. Now would be the time for wider criticism of the API, and the fixing of any API bugs.

@jonasschnelli jonasschnelli changed the title [REST] fix headersonly flag for BINARY responses / overhaul format handling [REST] Post-Merge overhaul of the REST API Nov 20, 2014
@sipa
Copy link
Member

sipa commented Nov 20, 2014

utACK

src/init.cpp Outdated
Copy link

Choose a reason for hiding this comment

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

IMHO better: Accept public REST requests (default: 0)
Can you add the default for -server, too?
See e.g. -forcednsseed style to be able to use %d in the string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now i think it make sense to just change the -rest command. Changing the -server command in this pull would mix things up.

@jonasschnelli jonasschnelli force-pushed the rest-stuff branch 2 times, most recently from 1e1868e to 4820cae Compare November 21, 2014 20:26
Copy link
Member

Choose a reason for hiding this comment

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

Although in practice updates of booleans are likely atomic, this needs a LOCK(cs_rpcWarmup) for completeness' sake

@laanwj
Copy link
Member

laanwj commented Nov 24, 2014

Code looks good to me, and I've done some basic testing and it works as expected.

I am still in doubt whether we should expose the .json format at all, though.

  • Unlike the binary formats it is entirely Bitcoin Core RPC specific. If this is supposed to be a standard for REST access of blocks/transactions, every nook needs to be documented in a BIP.
  • It is not complete: for example, JSON format for block shows a list of transactions, but not the full data of the block. Of course with -txindex it's possible to fetch tx-by-tx after that, but that's quite the detour.
  • Parsing the data and formatting JSON takes a lot of memory, and increased overhead in time (not a concern at this point, but may be for an API designed to be potentially public). These are all things that could be done client-side.

@jtimon
Copy link
Contributor

jtimon commented Nov 24, 2014

So maybe a format arg (?format=hex) and binary as default?
On Nov 24, 2014 12:17 PM, "Wladimir J. van der Laan" <
[email protected]> wrote:

Code looks good to me, and I've done some basic testing and it works as
expected.

I am still in doubt whether we should expose the .json format at all,
though.

  • Unlike the binary formats it is entirely Bitcoin Core RPC specific.
    If this is supposed to be a standard for REST access of
    blocks/transactions, every nook needs to be documented in a BIP.
  • It is not complete: for example, JSON format for block shows a list
    of transactions, but not the full data of the block. Of course with
    -txindex it's possible to fetch tx-by-tx after that, but that's quite
    the detour.
  • Parsing the data and formatting JSON takes a lot of memory, and
    increased overhead in time (not a concern at this point, but may be for an
    API designed to be potentially public).


Reply to this email directly or view it on GitHub
#5326 (comment).

@jgarzik
Copy link
Contributor

jgarzik commented Nov 24, 2014

The JSON mirrors the RPC format output, when possible.

However, the non-native argument is somewhat persuasive. If you wanted to follow the "convert client side" logic to its conclusion, then removing JSON and hex would result. That certainly keeps in the in-bitcoind code at a minimum.

However, two counterpoints:

  • The primary argument used on IRC seemed to be a worry about localhost XSS, and all this objection to JSON seems like a parallel construction to achieve that.
  • Adding REST equivalent of "getutxos" is one of the proposed next steps for the interface, and JSON would seem to be one of the two logical output formats for that (the other being the binary result that @mikehearn's "getutxos" P2P patch added)

@jgarzik
Copy link
Contributor

jgarzik commented Nov 24, 2014

The fix + flag should be separate from the output format pull request. We can go ahead and merge the fix and -rest flag, IMO.

@jonasschnelli
Copy link
Contributor Author

Okay. I will separate the pulls.

@laanwj
Copy link
Member

laanwj commented Nov 26, 2014

The primary argument used on IRC seemed to be a worry about localhost XSS, and all this objection to JSON seems like a parallel construction to achieve that.

No, that was IMO addressed by putting the functionality behind an option. Even without JSON, XSS fingerprinting may be possible by checking for absence/presence of errors. BTW I recently learnt that Tor Browser Bundle explicltly works around this kind of local fingerprinting, that's nice:

pref("network.proxy.no_proxies_on", ""); // For fingerprinting and local service vulns (#10419)

Adding REST equivalent of "getutxos" is one of the proposed next steps for the interface, and JSON would seem to be one of the two logical output formats for that (the other being the binary result that @mikehearn's "getutxos" P2P patch added)

I don't have anything against returning well-defined JSON data. If there are multiple things to return they need to be packed into a structure, and getutxo is an excellent example of that.

However that is entirely different from bitcoind's lossy RPC format for blocks, which is here used because the code happens to be available.

So maybe a format arg (?format=hex) and binary as default?

Let's not have a default. People can specify the format that they want.

@jonasschnelli
Copy link
Contributor Author

Just updated.
Format specific changes are removed from this pull (i'll open a new pull for this).
Now we only deal with HTTP Response fix, -rest flag (default off), warmup response.

@laanwj laanwj merged commit 5dc713b into bitcoin:master Nov 26, 2014
laanwj added a commit that referenced this pull request Nov 26, 2014
5dc713b [REST] set REST API behind "-rest" option (Jonas Schnelli)
78bdc81 [REST] give an appropriate response in warmup phase (Jonas Schnelli)
210eba9 [REST] fix headersonly flag for BINARY responses (Jonas Schnelli)
Copy link

Choose a reason for hiding this comment

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

@laanwj Here is another new translation string ;)? Still hoping you merge the others ^^.

Copy link
Member

Choose a reason for hiding this comment

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

I know, but this one is unavoidable, and not just some cosmetic change.

@jonasschnelli
Copy link
Contributor Author

Also see #5376 for further format-specific discussions.
Also referencing #5379 (unit-tests).

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants