Skip to content

Commit

Permalink
change emptyHeader to emptyWorkObject and create emptyHeader to be us…
Browse files Browse the repository at this point in the history
…ed on tests
  • Loading branch information
didaunesp committed May 30, 2024
1 parent ac34b36 commit 38c76d4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (c *Core) InsertChain(blocks types.WorkObjects) (int, error) {
}).Info("Already processing block")
return idx, errors.New("Already in process of appending this block")
}
newPendingEtxs, _, _, err := c.sl.Append(block, types.EmptyHeader(c.NodeCtx()), common.Hash{}, false, nil)
newPendingEtxs, _, _, err := c.sl.Append(block, types.EmptyWorkObject(c.NodeCtx()), common.Hash{}, false, nil)
c.processingCache.Remove(block.Hash())
if err == nil {
// If we have a dom, send the dom any pending ETXs which will become
Expand Down
34 changes: 17 additions & 17 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,35 +267,35 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
// ToBlock creates the genesis block and writes state of a genesis specification
// to the given database (or discards it if nil).
func (g *Genesis) ToBlock(startingExpansionNumber uint64) *types.WorkObject {
head := types.EmptyHeader(g.Config.Location.Context())
head.WorkObjectHeader().SetNonce(types.EncodeNonce(g.Nonce))
head.WorkObjectHeader().SetDifficulty(g.Difficulty)
head.WorkObjectHeader().SetTime(g.Timestamp)
head.Header().SetExtra(g.ExtraData)
head.Header().SetGasLimit(g.GasLimit)
head.Header().SetGasUsed(0)
head.Header().SetExpansionNumber(uint8(startingExpansionNumber))
wo := types.EmptyWorkObject(g.Config.Location.Context())
wo.WorkObjectHeader().SetNonce(types.EncodeNonce(g.Nonce))
wo.WorkObjectHeader().SetDifficulty(g.Difficulty)
wo.WorkObjectHeader().SetTime(g.Timestamp)
wo.Header().SetExtra(g.ExtraData)
wo.Header().SetGasLimit(g.GasLimit)
wo.Header().SetGasUsed(0)
wo.Header().SetExpansionNumber(uint8(startingExpansionNumber))
if startingExpansionNumber > 0 {
// Fill each byte with 0xFF to set all bits to 1
var etxEligibleSlices common.Hash
for i := 0; i < common.HashLength; i++ {
etxEligibleSlices[i] = 0xFF
}
head.Header().SetEtxEligibleSlices(etxEligibleSlices)
wo.Header().SetEtxEligibleSlices(etxEligibleSlices)
} else {
head.Header().SetEtxEligibleSlices(common.Hash{})
wo.Header().SetEtxEligibleSlices(common.Hash{})
}
head.Header().SetCoinbase(common.Zero)
head.Header().SetBaseFee(new(big.Int).SetUint64(params.InitialBaseFee))
head.Header().SetEtxSetRoot(types.EmptyRootHash)
wo.Header().SetCoinbase(common.Zero)
wo.Header().SetBaseFee(new(big.Int).SetUint64(params.InitialBaseFee))
wo.Header().SetEtxSetRoot(types.EmptyRootHash)
if g.GasLimit == 0 {
head.Header().SetGasLimit(params.GenesisGasLimit)
wo.Header().SetGasLimit(params.GenesisGasLimit)
}
for i := 0; i < common.HierarchyDepth; i++ {
head.SetNumber(big.NewInt(0), i)
head.SetParentHash(common.Hash{}, i)
wo.SetNumber(big.NewInt(0), i)
wo.SetParentHash(common.Hash{}, i)
}
return head
return wo
}

// Commit writes the block and state of a genesis specification to the database.
Expand Down
2 changes: 1 addition & 1 deletion core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ func (sl *Slice) generateSlicePendingHeader(block *types.WorkObject, newTermini
} else {
// Just compute the necessary information for the pending Header
// i.e ParentHash field, Number and writing manifest to the disk
localPendingHeader = types.EmptyHeader(sl.NodeCtx())
localPendingHeader = types.EmptyWorkObject(sl.NodeCtx())
localPendingHeader.SetParentHash(block.Hash(), nodeCtx)
localPendingHeader.SetNumber(big.NewInt(int64(block.NumberU64(nodeCtx))+1), nodeCtx)
localPendingHeader.Header().SetParentEntropy(sl.engine.TotalLogS(sl.hc, block), nodeCtx)
Expand Down
13 changes: 10 additions & 3 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,9 @@ type headerMarshaling struct {
Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON
}

// Construct an empty header
func EmptyHeader(nodeCtx int) *WorkObject {
func EmptyHeader() *Header {
h := &Header{}
wo := &WorkObject{woHeader: &WorkObjectHeader{}, woBody: &WorkObjectBody{}, tx: &Transaction{}}

h.parentHash = make([]common.Hash, common.HierarchyDepth-1)
h.manifestHash = make([]common.Hash, common.HierarchyDepth)
h.parentEntropy = make([]*big.Int, common.HierarchyDepth)
Expand Down Expand Up @@ -177,6 +176,14 @@ func EmptyHeader(nodeCtx int) *WorkObject {
h.parentHash[i] = EmptyRootHash
h.number[i] = big.NewInt(0)
}

return h
}

// Construct an empty header
func EmptyWorkObject(nodeCtx int) *WorkObject {
wo := &WorkObject{woHeader: &WorkObjectHeader{}, woBody: &WorkObjectBody{}, tx: &Transaction{}}
h := EmptyHeader()
wo.woHeader.SetHeaderHash(EmptyRootHash)
wo.woHeader.SetParentHash(EmptyRootHash)
wo.woHeader.SetNumber(big.NewInt(0))
Expand Down
2 changes: 1 addition & 1 deletion core/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ func (w *worker) prepareWork(genParams *generateParams, wo *types.WorkObject) (*
}
// Construct the sealing block header, set the extra field if it's allowed
num := parent.Number(nodeCtx)
newWo := types.EmptyHeader(nodeCtx)
newWo := types.EmptyWorkObject(nodeCtx)
newWo.SetParentHash(wo.Hash(), nodeCtx)
if w.hc.IsGenesisHash(parent.Hash()) {
newWo.SetNumber(big.NewInt(1), nodeCtx)
Expand Down

0 comments on commit 38c76d4

Please sign in to comment.