Skip to content

Commit fbcd360

Browse files
committed
add with-skipped-blocks and with-reorgs flags
1 parent 3764a99 commit fbcd360

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## 1.7.2
4+
5+
- Added `--with-skipped-blocks` flag to control behavior of skipping blocks that are multiples of 13.
6+
- Added `--with-reorgs` flag to control behavior of producing 2 block reorg sequences every 17 blocks.
7+
38
## 1.7.1
49

510
- Fixed `--log-level` not being picked up correctly.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ To enable firehose instrumentation:
5050
Firehose logger statement will be printed as blocks are executed/produced. This mode is meant to be run
5151
using by a Firehose `reader-node`, see https://github.com/streamingfast/firehose-acme.
5252

53-
### Block Skipping and Forks
53+
### Block Skipping and Forks(reorgs)
5454

5555
The dummy chain skips a block that are divisible by 13 so for example we are at block #25 (abc) the next produced block will be #27 (def) and #26 will never be produced.
5656

5757
THe dummy chain also generates forks at regular interval, every 17 blocks. The generated fork sequence is of 1 block if the current block is odd otherwise if it's even, a 2 blocks fork sequence will be generated.
5858

59+
These two features can be disabled with flags `--with-skipped-blocks=false` and `--with-reorgs=false`.
60+
5961
## Tracer
6062

6163
This project showcase a "fake" blockchain's node codebase. For developers looking into integrating a native Firehose integration, we suggest to integrate in blockchain's client code directly by some form of tracing plugin that is able to receive all the important callback's while transactions are execution integrating as deeply as wanted.

cmd/dummy-blockchain/app/app.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type Flags struct {
2727
BlockSizeInBytes int
2828
ServerAddr string
2929
WithSignal bool
30+
WithSkippedBlocks bool
31+
WithReorgs bool
3032
Tracer string
3133
StopHeight uint64
3234

@@ -78,6 +80,8 @@ func initFlags(root *cobra.Command) error {
7880
flags.StringVar(&cliOpts.ServerAddr, "server-addr", "0.0.0.0:8080", "Server address")
7981
flags.StringVar(&cliOpts.Tracer, "tracer", "", "The tracer to use, either <empty>, none or firehose")
8082
flags.BoolVar(&cliOpts.WithSignal, "with-signal", false, "whether we produce BlockCommitmentLevel signals on top of blocks")
83+
flags.BoolVar(&cliOpts.WithSkippedBlocks, "with-skipped-blocks", true, "whether skip a block number every 13 slots")
84+
flags.BoolVar(&cliOpts.WithReorgs, "with-reorgs", true, "whether we produce reorgs every 17 slots")
8185

8286
return nil
8387
}
@@ -168,6 +172,8 @@ func makeStartComand() *cobra.Command {
168172
cliOpts.ServerAddr,
169173
blockTracer,
170174
cliOpts.WithSignal,
175+
cliOpts.WithSkippedBlocks,
176+
cliOpts.WithReorgs,
171177
)
172178

173179
if err := node.Initialize(); err != nil {

core/engine.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ type Engine struct {
2222
signalChan chan *types.Signal
2323
prevBlock *types.Block
2424
finalBlock *types.Block
25+
withSkippedBlocks bool
26+
withReorgs bool
2527
}
2628

27-
func NewEngine(genesisHash string, genesisHeight uint64, genesisTime time.Time, genesisBlockBurst uint64, stopHeight uint64, rate int, blockSizeInBytes int) Engine {
29+
func NewEngine(genesisHash string, genesisHeight uint64, genesisTime time.Time, genesisBlockBurst uint64, stopHeight uint64, rate int, blockSizeInBytes int, withSkippedBlocks bool, withReorgs bool) Engine {
2830
blockRate := time.Minute / time.Duration(rate)
2931

3032
return Engine{
@@ -37,6 +39,8 @@ func NewEngine(genesisHash string, genesisHeight uint64, genesisTime time.Time,
3739
blockSizeInBytes: blockSizeInBytes,
3840
blockChan: make(chan *types.Block),
3941
signalChan: make(chan *types.Signal),
42+
withSkippedBlocks: withSkippedBlocks,
43+
withReorgs: withReorgs,
4044
}
4145
}
4246

@@ -136,12 +140,12 @@ func (e *Engine) createBlocks() (out []*types.Block) {
136140
}
137141

138142
heightToProduce := e.prevBlock.Header.Height + 1
139-
if heightToProduce%13 == 0 {
143+
if e.withSkippedBlocks && heightToProduce%13 == 0 {
140144
heightToProduce += 1
141145
logrus.Info(fmt.Sprintf("skipping block #%d that is a multiple of 13, producing %d instead", heightToProduce-1, heightToProduce))
142146
}
143147

144-
if heightToProduce%17 == 0 {
148+
if e.withReorgs && heightToProduce%17 == 0 {
145149
if heightToProduce%2 == 0 {
146150
logrus.Info("producing 2 block fork sequence")
147151
firstFork := e.newBlock(heightToProduce, ptr(uint64(1)), e.prevBlock)

core/node.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ func NewNode(
3131
serverAddr string,
3232
tracer tracer.Tracer,
3333
withSignal bool,
34+
withSkippedBlocks bool,
35+
withReorgs bool,
3436
) *Node {
3537
store := NewStore(storeDir, genesisHash, genesisHeight, genesisTime)
3638

3739
return &Node{
38-
engine: NewEngine(genesisHash, genesisHeight, genesisTime, genesisBlockBurst, stopHeight, blockRate, blockSizeInBytes),
40+
engine: NewEngine(genesisHash, genesisHeight, genesisTime, genesisBlockBurst, stopHeight, blockRate, blockSizeInBytes, withSkippedBlocks, withReorgs),
3941
store: store,
4042
server: NewServer(store, serverAddr),
4143
tracer: tracer,

0 commit comments

Comments
 (0)