Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Add debug getbadblocks #9207

Closed
wants to merge 6 commits into from

Conversation

cpurta
Copy link
Contributor

@cpurta cpurta commented Jul 23, 2018

Blockchain implementation will now have a blacklist of hashes that will allow for it to add bad blocks to a HashMap and in order to get all bad blocks we return a vector of hashes. This then allows for the rpc api to then return all of the current bad blocks that are within the current blockchain.

This will resolve #8761 when merged.

Chris Purta added 3 commits July 18, 2018 12:21
Updated the traits to allow for endpoints to return a result
of badblocks that are held in the blockchain implementation.
@parity-cla-bot
Copy link

It looks like @cpurta hasn't signed our Contributor License Agreement, yet.

The purpose of a CLA is to ensure that the guardian of a project's outputs has the necessary ownership or grants of rights over all contributions to allow them to distribute under the chosen licence.
Wikipedia

You can read and sign our full Contributor License Agreement at the following URL: https://cla.parity.io

Once you've signed, please reply to this thread with [clabot:check] to prove it.

Many thanks,

Parity Technologies CLA Bot

@cpurta
Copy link
Contributor Author

cpurta commented Jul 23, 2018

[clabot:check]

@parity-cla-bot
Copy link

It looks like @cpurta signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

@cpurta
Copy link
Contributor Author

cpurta commented Jul 23, 2018

This currently does not build as of now. Issue is stemming from rpc/src/v1/impls/eth.rs L821. Currently working on getting that to work. Would appreciate a review of the merge request as a whole.

I am still pretty new to Rust so there are probably some lines that can be refactored. Also if the naming of the new functions seems off I can rename those.

@5chdn 5chdn added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. M6-rpcapi 📣 RPC API. labels Jul 24, 2018
@5chdn 5chdn added this to the 2.1 milestone Jul 24, 2018
@cpurta
Copy link
Contributor Author

cpurta commented Aug 2, 2018

Any chance that I can get a quick review on the changes here and some feedback on how to finish this?

@Tbaut
Copy link
Contributor

Tbaut commented Aug 3, 2018

Let me blindly ping @andresilva @debris @tomusdrw to attract their attention :)

Fixed the bad_blocks function by correctly unwrapping and chaining
together functions to create RichBlocks from the hashes of the current
bad_blocks on the chain.
Copy link
Contributor

@folsen folsen left a comment

Choose a reason for hiding this comment

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

Overall it looks OK, maybe you could add some comment about expected performance impact? How many bad blocks would be held in memory? Do we want to persist bad blocks to db at some point?

See line by line comments for nitpicks/grumbles.

@@ -985,6 +987,11 @@ impl BlockChain {

let info = self.block_info(&header, route, &extras);

if self.is_blacklisted_hash(hash) {
self.bad_blocks.write().insert(hash, info);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you describe how this lock is used? Locks are generally bad and increase complexity, but if its use and pattern is straightforward then it can obviously be completely fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason behind using a lock for those hashes is due to the potential for a blockchain client to try and read what the current bad blocks are. At the same time a bad block could be inserted into our hashmap of bad blocks. Thus a race condition for the same resource so it made sense to have a lock.

/// Get all blacklisted hashes
fn blacklisted_hashes(&self) -> HashMap<H256, bool> {
let mut blacklist = HashMap::new();
blacklist.insert("05bef30ef572270f654746da22639a7a0c97dd97a7050b9e252391996aaeb689".into(), true);
Copy link
Contributor

Choose a reason for hiding this comment

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

What are these and why are they inserted here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These represent the list of bad hashes (usually hard forks) that determine whether a block is considered "bad". Similar to the implementation in geth: https://github.com/ethereum/go-ethereum/blob/master/core/blocks.go

@@ -817,6 +817,16 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
Ok(true)
}

fn bad_blocks(&self, include_txs: bool) -> BoxFuture<Vec<RichBlock>> {
let blocks = self.client.bad_blocks()
.unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please see our contribution guidelines regarding unwrap() here https://wiki.parity.io/Coding-guide.

Basically at no point in any code should unwrap() ever be called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh. I didn't see that guide. I'll get on fixing that.

@cpurta
Copy link
Contributor Author

cpurta commented Aug 22, 2018

@folsen addressed the unwrap issue and commented back on a couple of your comments. Would appreciate some feedback on comments and changes when you have some time.

@5chdn 5chdn added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Aug 30, 2018
@5chdn 5chdn mentioned this pull request Sep 4, 2018
@5chdn 5chdn changed the title WIP: Add debug getbadblocks Add debug getbadblocks Sep 6, 2018
@5chdn
Copy link
Contributor

5chdn commented Sep 8, 2018

Superseeded by #9433

@5chdn 5chdn closed this Sep 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-pleasereview 🤓 Pull request needs code review. M6-rpcapi 📣 RPC API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature-request: debug_getBadBlocks
5 participants