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

Allow optional pre BIP-37 behavior (the original satoshi protocol) #19

Merged
merged 15 commits into from
May 26, 2014

Conversation

chjj
Copy link
Member

@chjj chjj commented May 23, 2014

I realize bcoin is supposed to be used as an spv, but it wouldn't be that hard to add an option to allow a more traditional blockchain downloader. What do you think, @indutny? Is there anything I missed here?

tx.ts = tx.ts || self.ts;
return tx;
});
this.hashes = this.txs.map(function(tx) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should verify merkle root here

@chjj
Copy link
Member Author

chjj commented May 24, 2014

Alright, I wrote a function to build a merkle tree and verify the merkle root correctly (modeled after the bitcoind code). I also added some verification checks that bitcoind does on blocks (maybe we might want to do some of them on merkleblocks too?).

Anyway, this all seems to work in practice. Let me know what you think.

@chjj
Copy link
Member Author

chjj commented May 24, 2014

I can also revert all the CheckBlock stuff if you don't want it.


Block.prototype._phash = function phash(p1begin, p1end, p2begin, p2end) {
var pblank = '';
var hash1 = hash.sha256();
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not utils.dsha256?

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 thought the same thing eventually. It now concatenates the two merkleTree hashes into utils.dsha256.

When I initially wrote it, I was essentially porting the awful c++ of bitcoind to javascript (to clarify: I'm not sure if I dislike the bitcoind codebase or just C++ in general), so it was confusing to say the least. The fuction looked too complex to be handled with just utils.dsha256. I was wrong.

@chjj
Copy link
Member Author

chjj commented May 25, 2014

I think the pull request is, more or less ready, but I kind of want to discuss usage.

I've been messing around adding some code to pool._addPeer, and although I can start receiving full blocks from peers, pool.chain.add(block) doesn't seem to like them. They don't get added to the blockchain, which is strange, becuase if I just instead do a _probeIndex on the prevBlock, it exists and I can then do an _addIndex on the block. I can't figure out why chain.add(block) is not working.

Even more puzzling, I can't seem to get more than ~6000 blocks from my peers, even if I do a getblocks loop of the last block hash I saw. The original protocol is a headache. :)

@chjj
Copy link
Member Author

chjj commented May 26, 2014

I definitely think there is something wrong with chain.add/chain.has. I cannot get a full blockchain by just relying on chain.has, chain.add, and pool.block.lastHash.

The only way I can get a full blockchain download is by creating my own version of pool.block.lastHash which simply checks a hash table of every block hash received so far, and then sets myownobj._lastHash to the last known hash received by the blocks event (INV). I then send peer.loadBlocks([myownobj._lastHash], 0) in every call.

With the former method, I'll usually get about 500-5000 unique blocks before bcoin hangs and stops requesting/receiving blocks completely. With the latter method, I can get a full blockchain download. I really can't figure it out. Does the Chain object need to be rewritten to accomodate these new features?

@indutny
Copy link
Collaborator

indutny commented May 26, 2014

Hm... it really shouldn't be. Unfortunately, I'm busy optimizing elliptic.js right now. Will look into it somewhere later.

@chjj
Copy link
Member Author

chjj commented May 26, 2014

I understand. I'll continue to look into it. In the meantime, could you merge this branch? I think it's ready despite the Chain issue (I can still get a full blockchain download with it).

Could you also merge the version packet pull request? I added a test like you said, and now the relay=false option actually has a purpose (to trigger the pre-bip-37 behavior).

indutny added a commit that referenced this pull request May 26, 2014
Allow optional pre BIP-37 behavior (the original satoshi protocol)
@indutny indutny merged commit d23cca1 into bcoin-org:master May 26, 2014
@chjj
Copy link
Member Author

chjj commented May 26, 2014

Awesome. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants