Skip to content

Conversation

@sipsorcery
Copy link

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

@nopara73
Copy link
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?

//
// 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
Collaborator

Choose a reason for hiding this comment

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

samle

// any kind of use on the main BitCoin network.
//
// Dependencies:
// The program relies on NBitCoin (https://github.com/MetacoSA/NBitcoin) for the
Copy link
Collaborator

Choose a reason for hiding this comment

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

NBitcoin

// 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
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.

//
// 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
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.

var chain = new ConcurrentChain(_network);
Node node = null;

LoadChain(chain, ct).ContinueWith(t =>
Copy link
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
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.


NodeRequirement req = new NodeRequirement();
req.RequiredServices = NodeServices.NODE_BLOOM;
req.SupportSPV = true;
Copy link
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
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.

parameters.IsRelay = false;

NodeRequirement req = new NodeRequirement();
req.RequiredServices = NodeServices.NODE_BLOOM;
Copy link
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.

tip = new ChainedBlock(header, header.GetHash(), prev);
chain.SetTip(tip);

ct.ThrowIfCancellationRequested();
Copy link
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
Copy link
Collaborator

NicolasDorier commented Aug 17, 2017

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
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
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