MCPcopy Create free account
hub / github.com/DNAProject/DNA / InitializeConsensus

Method InitializeConsensus

consensus/dbft/dbft_service.go:269–313  ·  view source on GitHub ↗
(viewNum byte)

Source from the content-addressed store, hash-verified

267}
268
269func (ds *DbftService) InitializeConsensus(viewNum byte) error {
270 log.Debug("[InitializeConsensus] Start InitializeConsensus.")
271 log.Debug("[InitializeConsensus] viewNum: ", viewNum)
272
273 if viewNum == 0 {
274 ds.context.Reset(ds.Account)
275 } else {
276 if ds.context.State.HasFlag(BlockGenerated) {
277 return nil
278 }
279 ds.context.ChangeView(viewNum)
280 }
281
282 if ds.context.BookkeeperIndex < 0 {
283 log.Info("You aren't bookkeeper")
284 return nil
285 }
286
287 if ds.context.BookkeeperIndex == int(ds.context.PrimaryIndex) {
288
289 //primary peer
290 ds.context.State |= Primary
291 ds.timerHeight = ds.context.Height
292 ds.timeView = viewNum
293 span := time.Now().Sub(ds.blockReceivedTime)
294 if span > genesis.GenBlockTime {
295 //TODO: double check the is the stop necessary
296 ds.timer.Stop()
297 ds.timer.Reset(0)
298 //go ds.Timeout()
299 } else {
300 ds.timer.Stop()
301 ds.timer.Reset(genesis.GenBlockTime - span)
302 }
303 } else {
304 //backup peer
305 ds.context.State = Backup
306 ds.timerHeight = ds.context.Height
307 ds.timeView = viewNum
308
309 ds.timer.Stop()
310 ds.timer.Reset(genesis.GenBlockTime << (viewNum + 1))
311 }
312 return nil
313}
314
315func (ds *DbftService) LocalNodeNewInventory(v interface{}) {
316 log.Debug()

Callers 3

CheckExpectedViewMethod · 0.95
startMethod · 0.95

Calls 7

DebugFunction · 0.92
InfoFunction · 0.92
HasFlagMethod · 0.80
ChangeViewMethod · 0.80
SubMethod · 0.80
StopMethod · 0.65
ResetMethod · 0.45

Tested by

no test coverage detected