Skip to content

Bloom Filter Example#1

Closed
sipsorcery wants to merge 2 commits into
ProgrammingBlockchain:masterfrom
sipsorcery:master
Closed

Bloom Filter Example#1
sipsorcery wants to merge 2 commits into
ProgrammingBlockchain:masterfrom
sipsorcery:master

Conversation

@sipsorcery

Copy link
Copy Markdown

A new sample program that demonstrates how to use a bloom filter with NBitcoin.

@nopara73

Copy link
Copy Markdown
Contributor

utACK
By taking a quick look it seems good.
I'd like to merge it blindly, though it would take a few hours to make sure the example is fine. @NicolasDorier what do you think?

Comment thread BloomFilter/Program.cs Outdated
//
// 1. Load blockchain headers from disk (if not available will be requested from
// the full node but that takes longer),
// 2. Connect to a full BitCoin node (this samle is hard coded to use the loopback

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

samle

Comment thread BloomFilter/Program.cs Outdated
// any kind of use on the main BitCoin network.
//
// Dependencies:
// The program relies on NBitCoin (https://github.com/MetacoSA/NBitcoin) for the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

NBitcoin

Comment thread BloomFilter/Program.cs
// protocol. An invaluable tool for anyone attempting the same thing is WireShark
// (https://www.wireshark.org/) which has a builtin BitCoin protocol decoder. To
// use WireShark with the loopback adapter on Windows install Npcap (https://nmap.org/npcap/).
//

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

wow did not knew that awesome.

Comment thread BloomFilter/Program.cs
//
// The command line used for the local bitcoin full node:
// "C:\Program Files\Bitcoin\daemon\bitcoind" -printtoconsole -datadir=f:\temp\bitcoind -server -testnet -debug=1 -bind=[::1]:18333
//

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Actually your code should work just fine with "C:\Program Files\Bitcoin\daemon\bitcoind" -testnet, but yeah your parameters are better to understand what is going on.

Comment thread BloomFilter/Program.cs
var chain = new ConcurrentChain(_network);
Node node = null;

LoadChain(chain, ct).ContinueWith(t =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you use Async/Await instead of ContinueWith hacks ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You can't use await directly in main so it would require an additional method or lambda to switch. I don't find ContinueWith to be "hacky" it does a good job of conveying that the intention is to wait for a task to complete before continuing.

Comment thread BloomFilter/Program.cs Outdated

NodeRequirement req = new NodeRequirement();
req.RequiredServices = NodeServices.NODE_BLOOM;
req.SupportSPV = true;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you declare req next to where you use it?
Actually this code is optional, since your bitcoind supports bloomfilter, this code only make sure it does during the handshake (ie, if you disable bloomfilter with -peerbloomfilters=0, then the handshake will fail)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ok thx for the tip.

Comment thread BloomFilter/Program.cs Outdated
parameters.IsRelay = false;

NodeRequirement req = new NodeRequirement();
req.RequiredServices = NodeServices.NODE_BLOOM;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is useless, SupportSPV makes sure of that for you.
It limits also to who you can be connected, old nodes support NODE_BLOOM without advertising for it. req.SupportSPV = true do the proper checks.

Comment thread BloomFilter/Program.cs
tip = new ChainedBlock(header, header.GetHash(), prev);
chain.SetTip(tip);

ct.ThrowIfCancellationRequested();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

useless, you always call it at the beginning.

@NicolasDorier

NicolasDorier commented Aug 17, 2017

Copy link
Copy Markdown
Collaborator

first time I see pattern matching in the wild.

Made several point to improve. In general for such feature, I would advise people to encapsulate such code into a reusable TemplateBehavior. But I think this is fine for just understanding how bloom filters work.

@sipsorcery

Copy link
Copy Markdown
Author

I'm going to write a few more samples so I thin it'll work out easier to use my own repo. Closing this pull request.

@sipsorcery sipsorcery closed this Aug 21, 2017
@nopara73

Copy link
Copy Markdown
Contributor

@sipsorcery Too bad you deleted it already, I'd like to see it reopened.

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.

3 participants