-
Notifications
You must be signed in to change notification settings - Fork 177
Bloom Filter Example #1
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
Conversation
|
utACK |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
samle
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 |
There was a problem hiding this comment.
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/). | ||
| // |
There was a problem hiding this comment.
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 | ||
| // |
There was a problem hiding this comment.
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 => |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
BloomFilter/Program.cs
Outdated
|
|
||
| NodeRequirement req = new NodeRequirement(); | ||
| req.RequiredServices = NodeServices.NODE_BLOOM; | ||
| req.SupportSPV = true; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
BloomFilter/Program.cs
Outdated
| parameters.IsRelay = false; | ||
|
|
||
| NodeRequirement req = new NodeRequirement(); | ||
| req.RequiredServices = NodeServices.NODE_BLOOM; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
|
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 |
|
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 Too bad you deleted it already, I'd like to see it reopened. |
A new sample program that demonstrates how to use a bloom filter with NBitcoin.