Skip to content

Commit 1d757e5

Browse files
committed
trie, client -> new CP mechanism: added integrated block execution log msg combining zero and non-zero tx blocks in client
1 parent 66effa9 commit 1d757e5

File tree

3 files changed

+26
-42
lines changed

3 files changed

+26
-42
lines changed

packages/client/lib/client.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ export interface EthereumClientOptions {
1414
* Default: Database created by the Blockchain class
1515
*/
1616
chainDB?: LevelUp
17-
<<<<<<< HEAD
18-
19-
/**
20-
* Database to store the state. Should be an abstract-leveldown compliant store.
21-
*
22-
* Default: Database created by the Trie class
23-
*/
24-
stateDB?: LevelUp
25-
=======
26-
>>>>>>> client -> VM execution: renamed chain db instances to chainDB for differentiation towards stateDB
2717

2818
/**
2919
* Database to store the state. Should be an abstract-leveldown compliant store.

packages/client/lib/sync/fullsync.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ export class FullSynchronizer extends Synchronizer {
2121
private stopSyncing: boolean
2222
private vmPromise?: Promise<void>
2323

24-
// Tracking vars for log msg condensation on zero tx blocks
25-
private NUM_ZERO_TXS_PER_LOG_MSG = 50
26-
public zeroTxsBlockLogMsgCounter: number = 0
27-
2824
constructor(options: SynchronizerOptions) {
2925
super(options)
3026
this.blockFetcher = null
@@ -68,9 +64,15 @@ export class FullSynchronizer extends Synchronizer {
6864
return
6965
}
7066
this.runningBlocks = true
67+
let blockCounter = 0
68+
let txCounter = 0
69+
const NUM_BLOCKS_PER_LOG_MSG = 50
7170
try {
7271
let oldHead = Buffer.alloc(0)
73-
let newHead = (await this.vm.blockchain.getHead()).hash()
72+
const newHeadBlock = await this.vm.blockchain.getHead()
73+
let newHead = newHeadBlock.hash()
74+
const firstHeadBlock = newHeadBlock
75+
let lastHeadBlock = newHeadBlock
7476
while (!newHead.equals(oldHead) && !this.stopSyncing) {
7577
oldHead = newHead
7678
this.vmPromise = this.vm.runBlockchain(this.vm.blockchain, 1)
@@ -79,27 +81,29 @@ export class FullSynchronizer extends Synchronizer {
7981
newHead = headBlock.hash()
8082
// check if we did run a new block:
8183
if (!newHead.equals(oldHead)) {
82-
const number = headBlock.header.number.toNumber()
83-
const hash = short(newHead)
84-
const numTxs = headBlock.transactions.length
85-
if (numTxs === 0) {
86-
this.zeroTxsBlockLogMsgCounter += 1
87-
}
88-
if (
89-
(numTxs > 0 && this.zeroTxsBlockLogMsgCounter > 0) ||
90-
(numTxs === 0 && this.zeroTxsBlockLogMsgCounter >= this.NUM_ZERO_TXS_PER_LOG_MSG)
91-
) {
92-
this.config.logger.info(`Processed ${this.zeroTxsBlockLogMsgCounter} blocks with 0 txs`)
93-
this.zeroTxsBlockLogMsgCounter = 0
94-
}
95-
if (numTxs > 0) {
96-
this.config.logger.info(`Executed block number=${number} hash=${hash} txs=${numTxs}`)
84+
blockCounter += 1
85+
txCounter += headBlock.transactions.length
86+
lastHeadBlock = headBlock
87+
88+
if (blockCounter >= NUM_BLOCKS_PER_LOG_MSG) {
89+
const firstNumber = firstHeadBlock.header.number.toNumber()
90+
const firstHash = short(firstHeadBlock.hash())
91+
const lastNumber = lastHeadBlock.header.number.toNumber()
92+
const lastHash = short(lastHeadBlock.hash())
93+
this.config.logger.info(
94+
`Executed blocks count=${blockCounter} first=${firstNumber} hash=${firstHash} last=${lastNumber} hash=${lastHash} with txs=${txCounter}`
95+
)
96+
blockCounter = 0
97+
txCounter = 0
9798
}
9899
}
99100
}
101+
} catch (error) {
102+
this.emit('error', error)
100103
} finally {
101104
this.runningBlocks = false
102105
}
106+
return blockCounter
103107
}
104108

105109
/**

packages/client/test/sync/fullsync.spec.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,7 @@ tape('[FullSynchronizer]', async (t) => {
190190
transactions: [],
191191
}
192192
)
193-
await sync.runBlocks()
194-
t.equal(
195-
sync.zeroTxsBlockLogMsgCounter,
196-
1,
197-
'should increase zero blocks counter on zero tx blocks'
198-
)
193+
t.equal(await sync.runBlocks(), 1)
199194

200195
td.when(blockchain.getHead()).thenResolve(
201196
{
@@ -213,12 +208,7 @@ tape('[FullSynchronizer]', async (t) => {
213208
transactions: [1, 2, 3],
214209
}
215210
)
216-
await sync.runBlocks()
217-
t.equal(
218-
sync.zeroTxsBlockLogMsgCounter,
219-
0,
220-
'should reset zero blocks counter on non-zero tx blocks'
221-
)
211+
t.equal(await sync.runBlocks(), 1)
222212

223213
t.end()
224214
})

0 commit comments

Comments
 (0)