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

Commit

Permalink
Merge pull request #127 from ethereumjs/fix-lightsync-block-init-bug
Browse files Browse the repository at this point in the history
Fix lightsync block init bug
  • Loading branch information
holgerd77 committed Jun 9, 2020
2 parents fd76683 + 9b0de18 commit 8a05f49
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ ethereumjs.run({ network: 'rinkeby', syncmode: 'light', bootnodes: '/ip4/127.0.0

That's it! Now, you should start seeing headers being downloaded to the local storage of your browser. Since IndexDB is being used, even if you close and re-open the browser window, the headers you'll already downloaded will be saved.

![EthereumJS Client Libp2p Browser Syncing](./browser_sync.png?raw=true)

## Design

**Goals**
Expand Down
Binary file added browser_sync.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions lib/service/ethereumservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class EthereumService extends Service {

this.flow = new FlowControl(options)
this.chain = options.chain || new Chain(options)
this.common = options.common
this.minPeers = options.minPeers
this.interval = options.interval
this.timeout = options.timeout
Expand Down
1 change: 1 addition & 0 deletions lib/service/fastethereumservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class FastEthereumService extends EthereumService {
logger: this.logger,
pool: this.pool,
chain: this.chain,
common: this.common,
minPeers: this.minPeers,
interval: this.interval
})
Expand Down
1 change: 1 addition & 0 deletions lib/service/lightethereumservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class LightEthereumService extends EthereumService {
logger: this.logger,
pool: this.pool,
chain: this.chain,
common: this.common,
minPeers: this.minPeers,
flow: this.flow,
interval: this.interval
Expand Down
1 change: 1 addition & 0 deletions lib/sync/fastsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class FastSynchronizer extends Synchronizer {
this.blockFetcher = new BlockFetcher({
pool: this.pool,
chain: this.chain,
common: this.common,
logger: this.logger,
interval: this.interval,
first,
Expand Down
2 changes: 1 addition & 1 deletion lib/sync/fetcher/blockfetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class BlockFetcher extends Fetcher {
let { first, count } = task
const headers = await peer.eth.getBlockHeaders({ block: first, max: count })
const bodies = await peer.eth.getBlockBodies(headers.map(h => h.hash()))
const blocks = bodies.map((body, i) => new Block([headers[i]].concat(body)))
const blocks = bodies.map((body, i) => new Block([headers[i]].concat(body), { common: this.common }))
return { blocks }
}

Expand Down
4 changes: 4 additions & 0 deletions lib/sync/fetcher/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

const { Readable, Writable } = require('stream')
const Heap = require('qheap')
const Common = require('ethereumjs-common').default
const { defaultLogger } = require('../../logging')

const defaultOptions = {
common: new Common('mainnet', 'chainstart'),
logger: defaultLogger,
timeout: 5000,
interval: 1000,
Expand All @@ -24,6 +26,7 @@ class Fetcher extends Readable {
/**
* Create new fetcher
* @param {Object} options constructor parameters
* @param {Common} options.common common chain config
* @param {PeerPool} options.pool peer pool
* @param {number} [options.timeout] fetch task timeout
* @param {number} [options.banTime] how long to ban misbehaving peers
Expand All @@ -36,6 +39,7 @@ class Fetcher extends Readable {
super({ ...options, objectMode: true })
options = { ...defaultOptions, ...options }

this.common = options.common
this.pool = options.pool
this.logger = options.logger
this.timeout = options.timeout
Expand Down
1 change: 1 addition & 0 deletions lib/sync/lightsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class LightSynchronizer extends Synchronizer {
this.headerFetcher = new HeaderFetcher({
pool: this.pool,
chain: this.chain,
common: this.common,
flow: this.flow,
logger: this.logger,
interval: this.interval,
Expand Down
4 changes: 4 additions & 0 deletions lib/sync/sync.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict'

const Common = require('ethereumjs-common').default
const EventEmitter = require('events')
const { defaultLogger } = require('../logging')

const defaultOptions = {
common: new Common('mainnet', 'chainstart'),
logger: defaultLogger,
interval: 1000,
minPeers: 3
Expand All @@ -19,6 +21,7 @@ class Synchronizer extends EventEmitter {
* @param {Object} options constructor parameters
* @param {PeerPool} options.pool peer pool
* @param {Chain} options.chain blockchain
* @param {Common} options.common common chain config
* @param {FlowControl} options.flow flow control manager
* @param {number} [options.minPeers=3] number of peers needed before syncing
* @param {number} [options.interval] refresh interval
Expand All @@ -31,6 +34,7 @@ class Synchronizer extends EventEmitter {
this.logger = options.logger
this.pool = options.pool
this.chain = options.chain
this.common = options.common
this.flow = options.flow
this.minPeers = options.minPeers
this.interval = options.interval
Expand Down

0 comments on commit 8a05f49

Please sign in to comment.