Skip to content

Commit a797c1b

Browse files
authored
Merge pull request ethereum#272 from nextyio/consensus
Consensus for CoLoa hardfork
2 parents c8c5f9d + 51bb6b0 commit a797c1b

File tree

11 files changed

+1443
-40
lines changed

11 files changed

+1443
-40
lines changed

cmd/puppeth/wizard_genesis.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ func (w *wizard) makeGenesis() {
124124
ThangLongBlock: common.Big0,
125125
ThangLongEpoch: 3000,
126126
// CoLoa hardfork
127-
CoLoaBlock: common.Big0,
127+
CoLoaBlock: common.Big0,
128+
LeakDuration: 1024,
129+
ApplicationConfirmation: 128,
128130
}
129131
fmt.Println()
130132
fmt.Println("How many seconds should blocks take? (default = 2)")
@@ -212,6 +214,15 @@ func (w *wizard) makeGenesis() {
212214
fmt.Printf("Which block should CoLoa come into effect? (default = %v)\n", genesis.Config.Dccs.CoLoaBlock)
213215
genesis.Config.Dccs.CoLoaBlock = w.readDefaultBigInt(genesis.Config.Dccs.CoLoaBlock)
214216

217+
// CoLoa hardfork enabled
218+
fmt.Println()
219+
fmt.Printf("After how many block of inactivity should a sealer is kicked out? (default = %v)\n", genesis.Config.Dccs.LeakDuration)
220+
genesis.Config.Dccs.LeakDuration = uint64(w.readDefaultInt(int(genesis.Config.Dccs.LeakDuration)))
221+
222+
fmt.Println()
223+
fmt.Printf("How many confirmations is required before a sealer application takes effect? (default = %v)\n", genesis.Config.Dccs.ApplicationConfirmation)
224+
genesis.Config.Dccs.ApplicationConfirmation = uint64(w.readDefaultInt(int(genesis.Config.Dccs.ApplicationConfirmation)))
225+
215226
default:
216227
log.Crit("Invalid consensus engine choice", "choice", choice)
217228
}

consensus/dccs/1_dccs.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,20 @@ func (d *Dccs) getStateSnapshot(chain consensus.ChainReader, header *types.Heade
256256
// + the header in parents if available (nessesary for batch headers processing)
257257
// + chain.GetHeaderByNumber(number), if all else fail
258258
func getAvailableHeader(number uint64, header *types.Header, parents []*types.Header, chain consensus.ChainReader) *types.Header {
259-
headerNumber := header.Number.Uint64()
260-
if number == headerNumber {
261-
return header
262-
}
263-
if number > headerNumber {
264-
return chain.GetHeaderByNumber(number)
259+
var headerNumber uint64
260+
if header != nil {
261+
headerNumber = header.Number.Uint64()
262+
if number == headerNumber {
263+
return header
264+
}
265+
if number > headerNumber {
266+
return chain.GetHeaderByNumber(number)
267+
}
268+
} else {
269+
if len(parents) == 0 {
270+
return chain.GetHeaderByNumber(number)
271+
}
272+
headerNumber = parents[len(parents)-1].Number.Uint64() + 1
265273
}
266274
idx := len(parents) - int(headerNumber) + int(number)
267275
if idx >= 0 {

0 commit comments

Comments
 (0)