diff --git a/consensus/blake3pow/consensus.go b/consensus/blake3pow/consensus.go index f0e6672edc..63c9da0755 100644 --- a/consensus/blake3pow/consensus.go +++ b/consensus/blake3pow/consensus.go @@ -366,8 +366,9 @@ func (blake3pow *Blake3pow) verifyHeader(chain consensus.ChainHeaderReader, head if header.ThresholdCount() != 0 { return fmt.Errorf("invalid threshold count: have %v, want %v", header.ThresholdCount(), 0) } - if header.ExpansionNumber() != 0 { - return fmt.Errorf("invalid expansion number: have %v, want %v", header.ExpansionNumber(), 0) + genesisHeader := chain.GetHeaderByNumber(0) + if header.ExpansionNumber() != genesisHeader.ExpansionNumber() { + return fmt.Errorf("invalid expansion number: have %v, want %v", header.ExpansionNumber(), genesisHeader.ExpansionNumber()) } } else { expectedEfficiencyScore := chain.ComputeEfficiencyScore(parent) @@ -503,6 +504,10 @@ func (blake3pow *Blake3pow) CalcDifficulty(chain consensus.ChainHeaderReader, pa // Base case: expansion number is 0 and the parent is the actual genesis block return parent.Difficulty() } + genesisBlock := chain.GetHeaderByHash(parent.Hash()) + if genesisBlock.ExpansionNumber() > 0 && parent.Hash() == chain.Config().DefaultGenesisHash { + return parent.Difficulty() + } genesis := chain.GetHeaderByHash(parent.Hash()) genesisTotalLogS := blake3pow.TotalLogS(chain, genesis) if genesisTotalLogS.Cmp(genesis.ParentEntropy(common.PRIME_CTX)) < 0 { // prevent negative difficulty diff --git a/consensus/progpow/consensus.go b/consensus/progpow/consensus.go index 963c79b825..192a5297fa 100644 --- a/consensus/progpow/consensus.go +++ b/consensus/progpow/consensus.go @@ -362,8 +362,9 @@ func (progpow *Progpow) verifyHeader(chain consensus.ChainHeaderReader, header, if header.ThresholdCount() != 0 { return fmt.Errorf("invalid threshold count: have %v, want %v", header.ThresholdCount(), 0) } - if header.ExpansionNumber() != 0 { - return fmt.Errorf("invalid expansion number: have %v, want %v", header.ExpansionNumber(), 0) + genesisHeader := chain.GetHeaderByNumber(0) + if header.ExpansionNumber() != genesisHeader.ExpansionNumber() { + return fmt.Errorf("invalid expansion number: have %v, want %v", header.ExpansionNumber(), genesisHeader.ExpansionNumber()) } } else { expectedEfficiencyScore := chain.ComputeEfficiencyScore(parent) @@ -501,6 +502,10 @@ func (progpow *Progpow) CalcDifficulty(chain consensus.ChainHeaderReader, parent // Base case: expansion number is 0 and the parent is the actual genesis block return parent.Difficulty() } + genesisBlock := chain.GetHeaderByHash(parent.Hash()) + if genesisBlock.ExpansionNumber() > 0 && parent.Hash() == chain.Config().DefaultGenesisHash { + return parent.Difficulty() + } genesis := chain.GetHeaderByHash(parent.Hash()) genesisTotalLogS := progpow.TotalLogS(chain, genesis) if genesisTotalLogS.Cmp(genesis.ParentEntropy(common.PRIME_CTX)) < 0 { // prevent negative difficulty diff --git a/core/genesis.go b/core/genesis.go index 4c197abc52..c1b9c8b765 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -274,6 +274,7 @@ func (g *Genesis) ToBlock(startingExpansionNumber uint64) *types.WorkObject { head.Header().SetExtra(g.ExtraData) head.Header().SetGasLimit(g.GasLimit) head.Header().SetGasUsed(0) + head.Header().SetExpansionNumber(uint8(startingExpansionNumber)) if startingExpansionNumber > 0 { // Fill each byte with 0xFF to set all bits to 1 var etxEligibleSlices common.Hash diff --git a/core/worker.go b/core/worker.go index a925d37f87..0caab89ca1 100644 --- a/core/worker.go +++ b/core/worker.go @@ -1090,7 +1090,11 @@ func (w *worker) prepareWork(genParams *generateParams, wo *types.WorkObject) (* if parent.NumberU64(common.PRIME_CTX) == 0 { newWo.Header().SetEfficiencyScore(0) newWo.Header().SetThresholdCount(0) - newWo.Header().SetExpansionNumber(0) + // get the genesis expansion number, since in the normal expansion + // scenario this is only triggered in the case of [0, 0] we can just read + // the genesis block by number 0 + genesisHeader := w.hc.GetBlockByNumber(0) + newWo.Header().SetExpansionNumber(genesisHeader.ExpansionNumber()) } else { // compute the efficiency score at each prime block efficiencyScore := w.hc.ComputeEfficiencyScore(parent)