Skip to content

Commit 8930df2

Browse files
holgerd77ryanio
authored andcommitted
blockchain -> debugging: added blockchain:clique debug logger
1 parent 0dda417 commit 8930df2

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

packages/blockchain/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ blockchain.iterator('i', (block) => {
4646

4747
[Documentation](./docs/README.md)
4848

49+
# DEVELOPER
50+
51+
For debugging blockchain control flows the [debug](https://github.com/visionmedia/debug) library is used and can be activated on the CL with `DEBUG=[Logger Selection] node [Your Script to Run].js`.
52+
53+
The following initial logger is currently available:
54+
55+
| Logger | Description |
56+
| - | - |
57+
| `blockchain:clique` | Clique operations like updating the vote and/or signer list |
58+
59+
The following is an example for a logger run:
60+
61+
Run with the clique logger:
62+
63+
```shell
64+
DEBUG=blockchain:clique ts-node test.ts
65+
```
66+
4967
# EthereumJS
5068

5169
See our organizational [documentation](https://ethereumjs.readthedocs.io) for an introduction to `EthereumJS` as well as information on current standards and best practices.

packages/blockchain/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@ethereumjs/block": "^3.0.0",
4040
"@ethereumjs/common": "^2.0.0",
4141
"@ethereumjs/ethash": "^1.0.0",
42+
"debug": "^2.2.0",
4243
"ethereumjs-util": "^7.0.8",
4344
"level-mem": "^5.0.1",
4445
"lru-cache": "^5.1.1",

packages/blockchain/src/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { debug as createDebugLogger } from 'debug'
12
import Semaphore from 'semaphore-async-await'
23
import { Address, BN, rlp } from 'ethereumjs-util'
34
import { Block, BlockData, BlockHeader } from '@ethereumjs/block'
@@ -17,6 +18,8 @@ import {
1718
CLIQUE_NONCE_DROP,
1819
} from './clique'
1920

21+
const debug = createDebugLogger('blockchain:clique')
22+
2023
import type { LevelUp } from 'levelup'
2124
const level = require('level-mem')
2225

@@ -445,6 +448,7 @@ export default class Blockchain implements BlockchainInterface {
445448
genesisBlock.header.cliqueEpochTransitionSigners(),
446449
]
447450
await this.cliqueUpdateSignerStates(genesisSignerState)
451+
debug(`[Block 0] Genesis block -> update signer states`)
448452
await this.cliqueUpdateVotes()
449453
}
450454

@@ -483,6 +487,12 @@ export default class Blockchain implements BlockchainInterface {
483487
dbOps.push(DBOp.set(DBTarget.CliqueSignerStates, rlp.encode(formatted)))
484488

485489
await this.dbManager.batch(dbOps)
490+
// Output active signers for debugging purposes
491+
let i = 0
492+
for (const signer of this.cliqueActiveSigners()) {
493+
debug(`Clique signer [${i}]: ${signer}`)
494+
i++
495+
}
486496
}
487497

488498
/**
@@ -509,6 +519,11 @@ export default class Blockchain implements BlockchainInterface {
509519
// Always add the latest vote to the history no matter if already voted
510520
// the same vote or not
511521
this._cliqueLatestVotes.push(latestVote)
522+
debug(
523+
`[Block ${header.number.toNumber()}] New clique vote: ${signer} -> ${beneficiary} ${
524+
nonce.equals(CLIQUE_NONCE_AUTH) ? 'AUTH' : 'DROP'
525+
}`
526+
)
512527

513528
// remove any opposite votes for [signer, beneficiary]
514529
const oppositeNonce = nonce.equals(CLIQUE_NONCE_AUTH) ? CLIQUE_NONCE_DROP : CLIQUE_NONCE_AUTH
@@ -545,6 +560,9 @@ export default class Blockchain implements BlockchainInterface {
545560
const auth = beneficiaryVotesAuth.length >= limit
546561
// Majority consensus
547562
if (consensus) {
563+
debug(
564+
`[Block ${header.number.toNumber()}] Clique majority consensus -> update signer states`
565+
)
548566
let activeSigners = this.cliqueActiveSigners()
549567
if (auth) {
550568
// Authorize new signer

packages/vm/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ The following loggers are currently available:
177177

178178
| Logger | Description |
179179
| - | - |
180-
| `vm:block` | Block operations (run txs, generating receipts, block rewards,...)
180+
| `vm:block` | Block operations (run txs, generating receipts, block rewards,...) |
181181
| `vm:tx` | Transaction operations (account updates, checkpointing,...) |
182182
| `vm:tx:gas` | Transaction gas logger |
183183
| `vm:evm` | EVM control flow, CALL or CREATE message execution |

0 commit comments

Comments
 (0)