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

core,eth,internal: Added debug_getBadBlocks() method #3654

Merged
merged 4 commits into from
Feb 13, 2017

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Feb 7, 2017

When bad blocks are discovered, these are stored within geth.
An RPC-endpoint makes them availablewithin the debug
namespace. This feature makes it easier to discover network forks.

Example output:

> debug.getBadBlocks()
[{
    hash: "0xf29000250e8c61b192ee15ad71802cc2d76d1e73db06bd166b79b0918d9024b7",
    header: {
      difficulty: "0x62a132d85e60",
      extraData: "0x4477617266506f6f6c",
      gasLimit: "0x3d5eb1",
      gasUsed: "0x0",
      logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
      miner: "0x2a65aca4d5fc5b5c859090a6c34d164135398226",
      mixHash: "0x1a082b9b670d4d5cc822a56196e341393477d3b9b2979181323bddbe1b886b4b",
      nonce: "0xda611ab00c7dab10",
      number: "0x2e9a95",
      parentHash: "0x051f6e8c0d456cac879e6707b8507f22cd970be8b5bb5901778acad3bec27007",
      receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
      sha3Uncles: "0x01f86b8b6264aed8800b73405ef5d57319a8b268f0b23c11037fc42d7dd260d4",
      stateRoot: "0x2f35c2feb45f16a4f7a00719ee44683103cdb291d58311d938c6a8b622f34c51",
      timestamp: "0x58871d5b",
      transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
    }
}, {
    hash: "0xba1a9029ba293fe207667cd2e01882ef18d2a8037918803855313ca15ed22da1",
    header: {
      difficulty: "0x62a142d85e60",
      extraData: "0x61736961312e65746865726d696e652e6f7267",
      gasLimit: "0x3d6e07",
      gasUsed: "0xcbb4f",
      logsBloom: "0x0000000000000000000000000000000000000000004000000000000000002000000000000020000000000004000000010000100000002000000000080000000000000000004000008000000c000000080000000000000000000000000000000001000200001200000000000000000000004080200000000000000010000100000040000100000000000000000008000000000000000000002000000000000000000200000000000100000000000000100000000001000020000000000000000000000002000000000000002000000000000000000000001000920000008000200000000000000000000000000000000400000000000000000000000000000020",
      miner: "0xea674fdde714fd979de3edf0f56aa9716b898ec8",
      mixHash: "0xec517cdda407d8b26b48d46ecf0ea0c1884e2017b355f373991208754e5d3176",
      nonce: "0x7e0fa9600d34bb9d",
      number: "0x2e9a96",
      parentHash: "0xf29000250e8c61b192ee15ad71802cc2d76d1e73db06bd166b79b0918d9024b7",
      receiptsRoot: "0xc601cb85c158f2cc9a2a66ad6e23c14aea23ebe46837fb882ecb3acf8f958280",
      sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
      stateRoot: "0xf1f377c6cbaf53cce72b05e9fb3392b784eceb35737aa83033bfe1d4551f83bb",
      timestamp: "0x58871d6a",
      transactionsRoot: "0x0d1ef5239269e1462b6a3ced7d74e9d61b8af4e67db00da8084e608beffc1781"
    }
}]

When bad blocks are discovered, these are stored within geth.
An RPC-endpoint makes them availablewithin the `debug`
namespace. This feature makes it easier to discover network forks.

```
@mention-bot
Copy link

@holiman, thanks for your PR! By analyzing the history of the files in this pull request, we identified @obscuren, @karalabe and @fjl to be potential reviewers.

headers := make([]BadBlockArgs, 0, bc.badBlocks.Len())
for _, hash := range bc.badBlocks.Keys() {
if hdr, exist := bc.badBlocks.Peek(hash); exist {
headers = append(headers, BadBlockArgs{hdr.(*types.Header).Hash(), hdr.(*types.Header)})
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe assign hdr.(*types.Header) first so you don't need to type assert twice.

}
return headers, nil
}
// Adds a 'bad lock' to the LRU
Copy link
Contributor

Choose a reason for hiding this comment

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

please change comment to addBadBlock adds a bad block to the bad-block LRU cache.

@obscuren
Copy link
Contributor

Tested. Works very well. LGTM

@obscuren obscuren merged commit 72dcd3c into ethereum:master Feb 13, 2017
@karalabe karalabe added this to the 1.6.0 milestone Feb 23, 2017
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.

4 participants