Skip to content

Commit

Permalink
Merge pull request #836 from ethereumjs/update-blockchain-readme
Browse files Browse the repository at this point in the history
Update blockchain readme example
  • Loading branch information
holgerd77 authored Aug 21, 2020
2 parents fcdd708 + a81be68 commit 1fcdc83
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions packages/blockchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,24 @@ The following is an example to iterate through an existing Geth DB (needs `level

This module performs write operations. Making a backup of your data before trying it is recommended. Otherwise, you can end up with a compromised DB state.

```javascript
const level = require('level')
const Blockchain = require('@ethereumjs/blockchain').default
const utils = require('ethereumjs-util')
```typescript
import Blockchain from '@ethereumjs/blockchain'
import { bufferToInt } from 'ethereumjs-util'
import level from 'level'

const gethDbPath = './chaindata' // Add your own path here. It will get modified, see remarks.

const db = level(gethDbPath)
const blockchain = new Blockchain({ db })

new Blockchain({ db: db }).iterator(
'i',
(block, reorg, cb) => {
const blockNumber = utils.bufferToInt(block.header.number)
const blockHash = block.hash().toString('hex')
console.log(`BLOCK ${blockNumber}: ${blockHash}`)
cb()
},
(err) => console.log(err || 'Done.'),
)
blockchain.iterator('i', (block) => {
const blockNumber = bufferToInt(block.header.number)
const blockHash = block.hash().toString('hex')
console.log(`Block ${blockNumber}: ${blockHash}`)
})
```

**WARNING**: Since `@ethereumjs/blockchain` is also doing write operations
on the DB for safety reasons only run this on a copy of your database, otherwise this might lead
to a compromised DB state.
**WARNING**: Since `@ethereumjs/blockchain` is also doing write operations on the DB for safety reasons only run this on a copy of your database, otherwise this might lead to a compromised DB state.

# EthereumJS

Expand Down

5 comments on commit 1fcdc83

@github-actions
Copy link

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 1fcdc83 Previous: b402204 Ratio
Block 9422905 2027 ops/sec (±4.16%) 4039 ops/sec (±3.38%) 1.99
Block 9422906 1997 ops/sec (±2.65%) 4008 ops/sec (±5.90%) 2.01
Block 9422907 1877 ops/sec (±9.35%) 3918 ops/sec (±8.83%) 2.09
Block 9422908 2040 ops/sec (±0.97%) 3977 ops/sec (±4.78%) 1.95
Block 9422909 1982 ops/sec (±1.30%) 4017 ops/sec (±1.68%) 2.03
Block 9422910 1915 ops/sec (±1.45%) 3958 ops/sec (±1.41%) 2.07
Block 9422911 1882 ops/sec (±1.17%) 3104 ops/sec (±16.21%) 1.65
Block 9422912 1842 ops/sec (±0.73%) 3770 ops/sec (±1.49%) 2.05
Block 9422913 1805 ops/sec (±1.15%) 3808 ops/sec (±1.39%) 2.11
Block 9422914 1214 ops/sec (±14.88%) 3676 ops/sec (±2.47%) 3.03

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 1fcdc83 Previous: b402204 Ratio
Block 9422906 1997 ops/sec (±2.65%) 4008 ops/sec (±5.90%) 2.01
Block 9422907 1877 ops/sec (±9.35%) 3918 ops/sec (±8.83%) 2.09
Block 9422909 1982 ops/sec (±1.30%) 4017 ops/sec (±1.68%) 2.03
Block 9422910 1915 ops/sec (±1.45%) 3958 ops/sec (±1.41%) 2.07
Block 9422912 1842 ops/sec (±0.73%) 3770 ops/sec (±1.49%) 2.05
Block 9422913 1805 ops/sec (±1.15%) 3808 ops/sec (±1.39%) 2.11
Block 9422914 1214 ops/sec (±14.88%) 3676 ops/sec (±2.47%) 3.03

This comment was automatically generated by workflow using github-action-benchmark.

@holgerd77
Copy link
Member Author

Choose a reason for hiding this comment

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

@ryanio Oh, at least it works. 😄 Think we need to get some practical feeling for what these kind of numbers mean, how stable this is and in what context we can use and apply this.

@holgerd77
Copy link
Member Author

Choose a reason for hiding this comment

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

(so this will very likely be due to the differing on resource allocation on CI?)

@ryanio
Copy link
Contributor

@ryanio ryanio commented on 1fcdc83 Aug 21, 2020

Choose a reason for hiding this comment

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

@holgerd77 oh yeah that is weird, in my testing i never saw a variance like that. it could very much be differing resources from gh actions. i will look more into it.

Please sign in to comment.