Skip to content

Commit

Permalink
Working with uncles
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed Apr 5, 2024
1 parent e9d3f5d commit ecf7051
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
3 changes: 3 additions & 0 deletions core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ func (sl *Slice) readPhCache(hash common.Hash) (types.PendingHeader, bool) {
// Write the phCache
func (sl *Slice) writePhCache(hash common.Hash, pendingHeader types.PendingHeader) {
sl.miner.worker.AddPendingWorkObjectBody(pendingHeader.WorkObject())
if (pendingHeader.Header().ManifestHash(common.ZONE_CTX) == common.Hash{}) {
panic("manifest is nil")
}
sl.phCache.Add(hash, pendingHeader)
rawdb.WritePendingHeader(sl.sliceDb, hash, pendingHeader)
}
Expand Down
4 changes: 0 additions & 4 deletions core/types/gen_header_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 27 additions & 1 deletion core/types/wo.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,26 @@ func (wb *WorkObjectBody) SetInterlinkHashes(interlinkHashes common.Hashes) {
wb.interlinkHashes = interlinkHashes
}

func (wb *WorkObjectBody) CopyTransactions(transactions []*Transaction) {
wb.transactions = transactions
}

func (wb *WorkObjectBody) CopyExtTransactions(transactions []*Transaction) {
wb.extTransactions = transactions
}

func (wb *WorkObjectBody) CopyUncles(uncles []*WorkObject) {
wb.uncles = uncles
}

func (wb *WorkObjectBody) CopyManifest(manifest BlockManifest) {
wb.manifest = manifest
}

func (wb *WorkObjectBody) CopyInterlinkHashes(interlinkHashes common.Hashes) {
wb.interlinkHashes = interlinkHashes
}

////////////////////////////////////////////////////////////
/////////////////// Work Object Body Getters ///////////////
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -864,10 +884,16 @@ func (wb *WorkObjectBody) RPCMarshalWorkObjectBody() map[string]interface{} {
"header": wb.header.RPCMarshalHeader(),
"transactions": wb.Transactions(),
"extTransactions": wb.ExtTransactions(),
"uncles": wb.Uncles(),
"manifest": wb.Manifest(),
"interlinkHashes": wb.InterlinkHashes(),
}

workedUncles := make([]map[string]interface{}, len(wb.Uncles()))
for i, uncle := range wb.Uncles() {
workedUncles[i] = uncle.RPCMarshalWorkObject()
}
result["uncles"] = workedUncles

return result
}

Expand Down
6 changes: 3 additions & 3 deletions core/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func (w *worker) GeneratePendingHeader(block *types.WorkObject, fill bool) (*typ
work.txs = append(work.txs, types.NewTx(&types.QiTx{})) // placeholder
}
// Fill pending transactions from the txpool
w.adjustGasLimit(nil, work, block)
w.adjustGasLimit(work, block)
work.utxoFees = big.NewInt(0)
start := time.Now()
etxSet := w.fillTransactions(interrupt, work, block, fill)
Expand Down Expand Up @@ -1229,7 +1229,7 @@ func (w *worker) fillTransactions(interrupt *int32, env *environment, block *typ
// fillTransactions retrieves the pending transactions from the txpool and fills them
// into the given sealing block. The transaction selection and ordering strategy can
// be customized with the plugin in the future.
func (w *worker) adjustGasLimit(interrupt *int32, env *environment, parent *types.WorkObject) {
func (w *worker) adjustGasLimit(env *environment, parent *types.WorkObject) {
env.wo.Header().SetGasLimit(CalcGasLimit(parent, w.config.GasCeil))
}

Expand Down Expand Up @@ -1267,7 +1267,7 @@ func (w *worker) FinalizeAssemble(chain consensus.ChainHeaderReader, newWo *type

// Once the uncles list is assembled in the block
if nodeCtx == common.ZONE_CTX {
newWo.Header().SetUncledS(w.engine.UncledLogS(newWo))
wo.Header().SetUncledS(w.engine.UncledLogS(wo))
}

manifestHash := w.ComputeManifestHash(parent)
Expand Down
2 changes: 1 addition & 1 deletion internal/quaiapi/quai_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,6 @@ func (s *PublicBlockChainQuaiAPI) ReceiveMinedHeader(ctx context.Context, raw js
return err
}
woHeader.Header().SetCoinbase(common.BytesToAddress(woHeader.Coinbase().Bytes(), s.b.NodeLocation()))
log.Global.Warnf("Header mined %v", woHeader)
block, err := s.b.ConstructLocalMinedBlock(woHeader)
if err != nil && err.Error() == core.ErrBadSubManifest.Error() && nodeCtx < common.ZONE_CTX {
s.b.Logger().Info("filling sub manifest")
Expand Down Expand Up @@ -800,6 +799,7 @@ func (s *PublicBlockChainQuaiAPI) GetPendingHeader(ctx context.Context) (map[str
}
// Marshal the response.
marshaledPh := pendingHeader.RPCMarshalWorkObject()
log.Global.Warnf("manifest hash", pendingHeader.ManifestHash(common.ZONE_CTX))
return marshaledPh, nil
}

Expand Down

0 comments on commit ecf7051

Please sign in to comment.