public inbox for bitcoindev@googlegroups.com
 help / color / mirror / Atom feed
From: Christian Bodt <sirk390@gmail•com>
To: bitcoin-development@lists•sourceforge.net
Subject: [Bitcoin-development] Adding request/reply id in messages
Date: Wed, 11 Apr 2012 20:39:40 +0200	[thread overview]
Message-ID: <CA+XhJbpNYUyPm2Ymcpg3grbfGnfERCsUJNJuByEJbJLsMMmMbQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 3013 bytes --]

Hi,

I would like to discuss the following bitcoin protocol improvement proposal:

         Adding request/reply id in all messages (in the message header,
based on what was done for the "checksum" field)

The original reason is that I found it very hard to implement robust
blockchain downloading as we are missing context information:
The download protocol relies on the other peer sending one (or more) "inv"
reponse(s) to "getblocks" and sending the "hashContinue".
But if the other peer doesn't send a response to getblock, send a partial
response to getblocks, mixes it with some unrelated blocks inventories
or doesn't send the "hashContinue" it is very hard to detect and handle
(e.g. ban the peer and switch to another).  This could cause some DoS
attacks by misbehaving peers.
The problems are that 1/ we don't know how many "inv" messages to wait for
after "getblocks" and 2/ we don't know how to distinguish between result of
"getblocks" and spontaneous "inv" notifications.
The same is true for  "addr" messages (it is both a notification and reply)
but this is less of a problem as a lack of response to getaddr
doesn't constitute a DoS.

The idea would be to add a new "requestid" field in messages and define the
following:
      - verack sends back the requestid given in version.
      - inv sends back the requestid given in getblocks or a special value
in case of a notification.
      - addr sends back the requestid given in getaddr or a special value
in case of a notification.
      - tx sends back the requestid  given in getdata.
      - block sends back the requestid given in getdata
      - headers sends back the requestid given in getheaders.
      - reply sends back the requestid given in checkorder/submitorder.
      - pong sends back the requestid given in ping.

With the following rules:
       - getblocks always results in a single"inv" reply (0-500 elements
allowed).
       - getdata still result in multiple 'tx' or 'block' 's (as currently).

This is inspired by the common request/reply pattern (the id is sometimes
called "correlation id").
This would permit better asynchronous messaging (multiple request of the
same type in parallel. This could be useful for
getblocks/getdata/getheaders and future messages).

Historic note: It seems similar to the existing mechanism of
"CRequestTracker, hashReply & PushRequest" in the current bitcoin source
code except requestId  would only be a 32bits instead of the 256bits
of hashReply .

I have implemented a prototype here: https://github.com/sirk390/bitcoin/
This could allow to remove "hashContinue" in a second step like this:
https://github.com/sirk390/bitcoin/tree/better_block_download

I'm discussing it now as I read the PONG BIP and saw some similar nonce
field added.
I was not sure if this nonce field would still be required if we had
request/reply ids .

What do you think?

Best Regards,
Christian Bodt, France
Note: I am working on a python implementation of bitcoin.
See https://github.com/sirk390/coinpy

[-- Attachment #2: Type: text/html, Size: 4411 bytes --]

             reply	other threads:[~2012-04-11 18:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-11 18:39 Christian Bodt [this message]
2012-04-12 15:41 ` Gavin Andresen
2012-04-12 16:01   ` Pieter Wuille
2012-04-12 16:33     ` Amir Taaki
     [not found]     ` <CA+XhJbq01knW4XizF3DjaaXnzChvixsxwgFMzWiPPehYuvVk1w@mail.gmail.com>
2012-04-12 16:54       ` Christian Bodt
2012-04-12 17:12 ` Jeff Garzik
2012-04-12 17:24   ` Amir Taaki
2012-04-12 18:04     ` Peter Vessenes
2012-04-12 20:53     ` Christian Bodt
2012-04-13  6:30       ` Wladimir

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+XhJbpNYUyPm2Ymcpg3grbfGnfERCsUJNJuByEJbJLsMMmMbQ@mail.gmail.com \
    --to=sirk390@gmail$(echo .)com \
    --cc=bitcoin-development@lists$(echo .)sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox