diff --git a/core/engine.go b/core/engine.go index 6fd5f18..bebdb11 100644 --- a/core/engine.go +++ b/core/engine.go @@ -11,22 +11,24 @@ import ( ) type Engine struct { - genesisHeight uint64 - stopHeight uint64 - blockRate time.Duration - blockChan chan *types.Block - prevBlock *types.Block - finalBlock *types.Block + genesisHeight uint64 + genesisBlockBurst uint64 + stopHeight uint64 + blockRate time.Duration + blockChan chan *types.Block + prevBlock *types.Block + finalBlock *types.Block } -func NewEngine(genesisHeight, stopHeight uint64, rate int) Engine { +func NewEngine(genesisHeight, genesisBlockBurst, stopHeight uint64, rate int) Engine { blockRate := time.Minute / time.Duration(rate) return Engine{ - genesisHeight: genesisHeight, - stopHeight: stopHeight, - blockRate: blockRate, - blockChan: make(chan *types.Block), + genesisHeight: genesisHeight, + genesisBlockBurst: genesisBlockBurst, + stopHeight: stopHeight, + blockRate: blockRate, + blockChan: make(chan *types.Block), } } @@ -84,6 +86,11 @@ func (e *Engine) createBlocks() (out []*types.Block) { e.finalBlock = genesisBlock out = append(out, genesisBlock) + + for len(out)-1 < int(e.genesisBlockBurst) { + out = append(out, e.createBlocks()...) + } + return } diff --git a/core/node.go b/core/node.go index 9858b95..6b0ca0b 100644 --- a/core/node.go +++ b/core/node.go @@ -20,6 +20,7 @@ func NewNode( storeDir string, blockRate int, genesisHeight uint64, + genesisBlockBurst uint64, stopHeight uint64, serverAddr string, tracer tracer.Tracer, @@ -27,7 +28,7 @@ func NewNode( store := NewStore(storeDir, genesisHeight) return &Node{ - engine: NewEngine(genesisHeight, stopHeight, blockRate), + engine: NewEngine(genesisHeight, genesisBlockBurst, stopHeight, blockRate), store: store, server: NewServer(store, serverAddr), tracer: tracer, @@ -35,7 +36,9 @@ func NewNode( } func (node *Node) Initialize() error { - logrus.WithField("genesis_height", node.store.genesisHeight).Info("initializing node") + logrus. + WithField("genesis_height", node.store.genesisHeight). + Info("initializing node") logrus.Info("initializing store") if err := node.store.Initialize(); err != nil { diff --git a/main.go b/main.go index 6630461..03b3135 100644 --- a/main.go +++ b/main.go @@ -14,13 +14,14 @@ import ( ) var cliOpts = struct { - GenesisHeight uint64 - LogLevel string - StoreDir string - BlockRate int - ServerAddr string - Tracer string - StopHeight uint64 + GenesisHeight uint64 + GenesisBlockBurst uint64 + LogLevel string + StoreDir string + BlockRate int + ServerAddr string + Tracer string + StopHeight uint64 }{} func main() { @@ -53,6 +54,7 @@ func initFlags(root *cobra.Command) error { flags := root.PersistentFlags() flags.Uint64Var(&cliOpts.GenesisHeight, "genesis-height", 1, "Blockchain genesis height") + flags.Uint64Var(&cliOpts.GenesisBlockBurst, "genesis-block-burst", 0, "The amount of block to produce when initially starting from genesis block") flags.StringVar(&cliOpts.LogLevel, "log-level", "info", "Logging level") flags.StringVar(&cliOpts.StoreDir, "store-dir", "./data", "Directory for storing blockchain state") flags.IntVar(&cliOpts.BlockRate, "block-rate", 60, "Block production rate (per minute)") @@ -82,7 +84,10 @@ func makeInitCommand() *cobra.Command { Short: "Initialize local blockchain state", SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { - logrus.WithField("dir", cliOpts.StoreDir).WithField("genesis_height", cliOpts.GenesisHeight).Info("initializing chain store") + logrus. + WithField("dir", cliOpts.StoreDir). + WithField("genesis_height", cliOpts.GenesisHeight). + Info("initializing chain store") store := core.NewStore(cliOpts.StoreDir, cliOpts.GenesisHeight) return store.Initialize() @@ -127,6 +132,7 @@ func makeStartComand() *cobra.Command { cliOpts.StoreDir, cliOpts.BlockRate, cliOpts.GenesisHeight, + cliOpts.GenesisBlockBurst, cliOpts.StopHeight, cliOpts.ServerAddr, blockTracer,