diff --git a/core/core.go b/core/core.go index 597d8a4606..854e6ecd2a 100644 --- a/core/core.go +++ b/core/core.go @@ -359,11 +359,12 @@ func (c *Core) WriteBlock(block *types.Block) { } nodeCtx := common.NodeLocation.Context() if order == nodeCtx { - c.addToAppendQueue(block) parentHeader := c.GetHeader(block.ParentHash(), block.NumberU64()-1) if parentHeader != nil { + c.sl.WriteBlock(block) c.InsertChain([]*types.Block{block}) } + c.addToAppendQueue(block) // If a dom block comes in and we havent appended it yet } else if order < nodeCtx && c.GetHeaderByHash(block.Hash()) == nil { if c.sl.domClient != nil { diff --git a/core/slice.go b/core/slice.go index fdbc7eae59..d25339e72a 100644 --- a/core/slice.go +++ b/core/slice.go @@ -255,7 +255,12 @@ func (sl *Slice) Append(header *types.Header, domPendingHeader *types.Header, do time8 = common.PrettyDuration(time.Since(start)) - subReorg = sl.miningStrategy(bestPh, block) + tempPendingHeader, err := sl.generateSlicePendingHeader(block, newTermini, domPendingHeader, domOrigin, false, false) + if err != nil { + return nil, false, err + } + + subReorg = sl.miningStrategy(bestPh, tempPendingHeader) if order < nodeCtx { // Store the inbound etxs for dom blocks that did not get picked and use @@ -319,6 +324,7 @@ func (sl *Slice) Append(header *types.Header, domPendingHeader *types.Header, do "uncles", len(block.Uncles()), "txs", len(block.Transactions()), "etxs", len(block.ExtTransactions()), "gas", block.GasUsed(), "root", block.Root(), "order", order, + "location", block.Header().Location(), "elapsed", common.PrettyDuration(time.Since(start))) if nodeCtx == common.ZONE_CTX { @@ -333,11 +339,11 @@ func (sl *Slice) Append(header *types.Header, domPendingHeader *types.Header, do return subPendingEtxs, subReorg, nil } } -func (sl *Slice) miningStrategy(bestPh types.PendingHeader, block *types.Block) bool { +func (sl *Slice) miningStrategy(bestPh types.PendingHeader, pendingHeader types.PendingHeader) bool { if bestPh.Header() == nil { // This is the case where we try to append the block before we have not initialized the bestPh return true } - subReorg := sl.poem(sl.engine.TotalLogS(block.Header()), bestPh.Header().ParentEntropy()) + subReorg := sl.poem(sl.engine.TotalLogPhS(pendingHeader.Header()), sl.engine.TotalLogPhS(bestPh.Header())) return subReorg } @@ -359,7 +365,7 @@ func (sl *Slice) relayPh(block *types.Block, pendingHeaderWithTermini types.Pend } else { log.Warn("Pending Header for Best ph key does not exist", "best ph key", sl.bestPhKey) } - } else if !domOrigin { + } else if !domOrigin && subReorg { for _, i := range sl.randomRelayArray() { if sl.subClients[i] != nil { sl.subClients[i].SubRelayPendingHeader(context.Background(), pendingHeaderWithTermini, pendingHeaderWithTermini.Header().ParentEntropy(), location, subReorg) @@ -416,7 +422,7 @@ func (sl *Slice) UpdateDom(oldTerminus common.Hash, newTerminus common.Hash, new log.Info("pendingHeaderWithTermini:", "parent Hash:", pendingHeaderWithTermini.Header().ParentHash(), "Number", pendingHeaderWithTermini.Header().NumberArray()) for _, i := range sl.randomRelayArray() { if sl.subClients[i] != nil { - go sl.subClients[i].SubRelayPendingHeader(context.Background(), pendingHeaderWithTermini, newEntropy, location, true) + sl.subClients[i].SubRelayPendingHeader(context.Background(), pendingHeaderWithTermini, newEntropy, location, true) } } } @@ -498,6 +504,14 @@ func (sl *Slice) generateSlicePendingHeader(block *types.Block, newTermini types localPendingHeader = types.EmptyHeader() localPendingHeader.SetParentHash(block.Hash(), nodeCtx) localPendingHeader.SetNumber(big.NewInt(int64(block.NumberU64()) + 1)) + localPendingHeader.SetParentEntropy(sl.engine.TotalLogS(block.Header())) + if nodeCtx != common.PRIME_CTX { + if domOrigin { + localPendingHeader.SetParentDeltaS(big.NewInt(0), nodeCtx) + } else { + localPendingHeader.SetParentDeltaS(sl.engine.DeltaLogS(block.Header()), nodeCtx) + } + } manifestHash := sl.miner.worker.ComputeManifestHash(block.Header()) localPendingHeader.SetManifestHash(manifestHash)