diff --git a/core/evm.go b/core/evm.go index bcc44353ed..fd95438f80 100644 --- a/core/evm.go +++ b/core/evm.go @@ -79,11 +79,11 @@ func NewEVMBlockContext(header *types.WorkObject, chain ChainContext, author *co } } - // Prime terminus determines which location is eligible to except the etx + // Prime terminus determines which location is eligible to accept the etx primeTerminus := header.PrimeTerminus() primeTerminusHeader := chain.GetHeaderByHash(primeTerminus) if primeTerminusHeader == nil { - log.Global.Error("Prime terminus header not found", "headerHash", header.Hash(), "primeTerminus", primeTerminus) + log.Global.Error("Prime terminus header not found ", " headerHash ", header.Hash(), " primeTerminus ", primeTerminus) return vm.BlockContext{}, ErrSubNotSyncedToDom } etxEligibleSlices := primeTerminusHeader.EtxEligibleSlices() diff --git a/core/genesis.go b/core/genesis.go index a7f02b686c..f707141470 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -433,7 +433,7 @@ func DefaultLocalGenesisBlock(consensusEngine string) *Genesis { Nonce: 66, ExtraData: hexutil.MustDecode("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fb"), GasLimit: 5000000, - Difficulty: big.NewInt(5000000), + Difficulty: big.NewInt(500000), } } return &Genesis{ diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index 330f80b460..1af51b06d8 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -990,7 +990,7 @@ func ReadReceipts(db ethdb.Reader, hash common.Hash, number uint64, config *para }).Error("Missing body but have receipt") return nil } - if err := receipts.DeriveFields(config, hash, number, body.QuaiTransactionsWithoutCoinbase()); err != nil { + if err := receipts.DeriveFields(config, hash, number, body.TransactionsWithReceipts()); err != nil { db.Logger().WithFields(log.Fields{ "hash": hash, "number": number, diff --git a/core/state_processor.go b/core/state_processor.go index 1b0acd828e..98e5c35928 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -336,6 +336,7 @@ func (p *StateProcessor) Process(block *types.WorkObject) (types.Receipts, []*ty timePrepare += timePrepareDelta var receipt *types.Receipt + var addReceipt bool if tx.Type() == types.ExternalTxType { startTimeEtx := time.Now() // ETXs MUST be included in order, so popping the first from the queue must equal the first in the block @@ -418,6 +419,7 @@ func (p *StateProcessor) Process(block *types.WorkObject) (types.Receipts, []*ty if err != nil { return nil, nil, nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err) } + addReceipt = true totalEtxGas += receipt.GasUsed timeEtxDelta := time.Since(startTimeEtx) timeEtx += timeEtxDelta @@ -429,6 +431,7 @@ func (p *StateProcessor) Process(block *types.WorkObject) (types.Receipts, []*ty if err != nil { return nil, nil, nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err) } + addReceipt = true timeTxDelta := time.Since(startTimeTx) timeTx += timeTxDelta } else { @@ -439,8 +442,10 @@ func (p *StateProcessor) Process(block *types.WorkObject) (types.Receipts, []*ty emittedEtxs = append(emittedEtxs, etx) } } - receipts = append(receipts, receipt) - allLogs = append(allLogs, receipt.Logs...) + if addReceipt { + receipts = append(receipts, receipt) + allLogs = append(allLogs, receipt.Logs...) + } i++ } diff --git a/core/types/wo.go b/core/types/wo.go index 61f4efb4a8..8816d0bdc9 100644 --- a/core/types/wo.go +++ b/core/types/wo.go @@ -339,6 +339,22 @@ func (wo *WorkObject) QiTransactionsWithoutCoinbase() []*Transaction { return qiTxs } +func (wo *WorkObject) TransactionsWithReceipts() []*Transaction { + txs := make([]*Transaction, 0) + for i, t := range wo.Transactions() { + if i == 0 && IsCoinBaseTx(t, wo.woHeader.parentHash, wo.woHeader.location) { + // ignore the Quai coinbase tx + continue + } + if t.Type() == QuaiTxType || (t.Type() == ExternalTxType && t.To().IsInQuaiLedgerScope()) { + txs = append(txs, t) + } + } + return txs +} + +// QuaiTransactionsWithoutCoinbase returns all Quai EVM transactions in the block, excluding the coinbase transaction. +// This also returns all transactions that have an associated receipt. func (wo *WorkObject) QuaiTransactionsWithoutCoinbase() []*Transaction { quaiTxs := make([]*Transaction, 0) for i, t := range wo.Transactions() { @@ -346,7 +362,7 @@ func (wo *WorkObject) QuaiTransactionsWithoutCoinbase() []*Transaction { // ignore the Quai coinbase tx and Quai->Qi to comply with prior functionality as it is not a normal transaction continue } - if t.Type() != QiTxType { + if t.Type() == QuaiTxType { quaiTxs = append(quaiTxs, t) } } @@ -369,16 +385,6 @@ func (wo *WorkObject) InputsAndOutputsWithoutCoinbase() (uint, uint) { return uint(inputs), uint(outputs) } -func (wo *WorkObject) QuaiTransactionsWithFees() []*Transaction { - quaiTxs := make([]*Transaction, 0) - for _, t := range wo.Transactions() { - if t.Type() == QuaiTxType { // QuaiTxType is the only type that gives Quai fees to the miner - quaiTxs = append(quaiTxs, t) - } - } - return quaiTxs -} - func (wo *WorkObject) NumberArray() []*big.Int { numArray := make([]*big.Int, common.HierarchyDepth) for i := 0; i < common.HierarchyDepth; i++ { @@ -578,7 +584,7 @@ func (wb *WorkObjectBody) QiTransactions() []*Transaction { func (wb *WorkObjectBody) QuaiTransactions() []*Transaction { quaiTxs := make([]*Transaction, 0) for _, t := range wb.Transactions() { - if t.Type() != QiTxType { + if t.Type() == QuaiTxType { quaiTxs = append(quaiTxs, t) } } diff --git a/core/worker.go b/core/worker.go index a38b6caad8..1a161cb1ad 100644 --- a/core/worker.go +++ b/core/worker.go @@ -731,7 +731,7 @@ func (w *worker) commitUncle(env *environment, uncle *types.WorkObjectHeader) er return nil } -func (w *worker) commitTransaction(env *environment, parent *types.WorkObject, tx *types.Transaction) ([]*types.Log, error) { +func (w *worker) commitTransaction(env *environment, parent *types.WorkObject, tx *types.Transaction) ([]*types.Log, bool, error) { if tx != nil { if tx.Type() == types.ExternalTxType && tx.To().IsInQiLedgerScope() { gasUsed := env.wo.GasUsed() @@ -740,7 +740,7 @@ func (w *worker) commitTransaction(env *environment, parent *types.WorkObject, t lock := new(big.Int).Add(env.wo.Number(w.hc.NodeCtx()), big.NewInt(params.ConversionLockPeriod)) primeTerminus := w.hc.GetPrimeTerminus(env.wo) if primeTerminus == nil { - return nil, errors.New("prime terminus not found") + return nil, false, errors.New("prime terminus not found") } value := misc.QuaiToQi(primeTerminus, tx.Value()) denominations := misc.FindMinDenominations(value) @@ -759,12 +759,12 @@ func (w *worker) commitTransaction(env *environment, parent *types.WorkObject, t } txGas -= params.CallValueTransferGas if err := env.gasPool.SubGas(params.CallValueTransferGas); err != nil { - return nil, err + return nil, false, err } gasUsed += params.CallValueTransferGas // the ETX hash is guaranteed to be unique if err := env.state.CreateUTXO(tx.Hash(), outputIndex, types.NewUtxoEntry(types.NewTxOut(uint8(denomination), tx.To().Bytes(), lock))); err != nil { - return nil, err + return nil, false, err } outputIndex++ } @@ -772,16 +772,16 @@ func (w *worker) commitTransaction(env *environment, parent *types.WorkObject, t } else { // This Qi ETX should cost more gas if err := env.gasPool.SubGas(params.CallValueTransferGas); err != nil { - return nil, err + return nil, false, err } if err := env.state.CreateUTXO(tx.OriginatingTxHash(), tx.ETXIndex(), types.NewUtxoEntry(types.NewTxOut(uint8(tx.Value().Uint64()), tx.To().Bytes(), big.NewInt(0)))); err != nil { - return nil, err + return nil, false, err } gasUsed += params.CallValueTransferGas } env.wo.Header().SetGasUsed(gasUsed) env.txs = append(env.txs, tx) - return []*types.Log{}, nil // need to make sure this does not modify receipt hash + return []*types.Log{}, false, nil } snap := env.state.Snapshot() // retrieve the gas used int and pass in the reference to the ApplyTransaction @@ -795,7 +795,7 @@ func (w *worker) commitTransaction(env *environment, parent *types.WorkObject, t "gasUsed": gasUsed, }).Debug("Error playing transaction in worker") env.state.RevertToSnapshot(snap) - return nil, err + return nil, false, err } if receipt.Status == types.ReceiptStatusSuccessful { env.etxs = append(env.etxs, receipt.Etxs...) @@ -806,9 +806,9 @@ func (w *worker) commitTransaction(env *environment, parent *types.WorkObject, t env.wo.Header().SetGasUsed(gasUsed) env.txs = append(env.txs, tx) env.receipts = append(env.receipts, receipt) - return receipt.Logs, nil + return receipt.Logs, true, nil } - return nil, errors.New("error finding transaction") + return nil, false, errors.New("error finding transaction") } func (w *worker) commitTransactions(env *environment, parent *types.WorkObject, txs *types.TransactionsByPriceAndNonce, interrupt *int32) bool { @@ -852,10 +852,12 @@ func (w *worker) commitTransactions(env *environment, parent *types.WorkObject, break } env.state.Prepare(etx.Hash(), env.tcount) - logs, err := w.commitTransaction(env, parent, etx) - if err == nil { + logs, receipt, err := w.commitTransaction(env, parent, etx) + if err == nil && receipt { coalescedLogs = append(coalescedLogs, logs...) env.tcount++ + } else if err == nil && !receipt { + env.tcount++ } oldestIndex.Add(oldestIndex, big.NewInt(1)) } @@ -925,7 +927,7 @@ func (w *worker) commitTransactions(env *environment, parent *types.WorkObject, // Start executing the transaction env.state.Prepare(tx.Hash(), env.tcount) - logs, err := w.commitTransaction(env, parent, tx) + logs, receipt, err := w.commitTransaction(env, parent, tx) switch { case errors.Is(err, types.ErrGasLimitReached): // Pop the current out-of-gas transaction without shifting in the next from the account @@ -955,7 +957,9 @@ func (w *worker) commitTransactions(env *environment, parent *types.WorkObject, case errors.Is(err, nil): // Everything ok, collect the logs and shift in the next transaction from the same account - coalescedLogs = append(coalescedLogs, logs...) + if receipt { + coalescedLogs = append(coalescedLogs, logs...) + } env.tcount++ txs.PopNoSort() @@ -1423,7 +1427,7 @@ func copyReceipts(receipts []*types.Receipt) []*types.Receipt { // totalFees computes total consumed miner fees in ETH. Block transactions and receipts have to have the same order. func totalFees(block *types.WorkObject, receipts []*types.Receipt) *big.Float { feesWei := new(big.Int) - for i, tx := range block.QuaiTransactionsWithoutCoinbase() { + for i, tx := range block.TransactionsWithReceipts() { minerFee, _ := tx.EffectiveGasTip(block.BaseFee()) feesWei.Add(feesWei, new(big.Int).Mul(new(big.Int).SetUint64(receipts[i].GasUsed), minerFee)) } diff --git a/params/config.go b/params/config.go index 95d28f3845..68592730d9 100644 --- a/params/config.go +++ b/params/config.go @@ -36,7 +36,7 @@ var ( Blake3PowColosseumGenesisHash = common.HexToHash("0x0ca6ff4426eab568de6773fb21d623d3fe6f2f0d2572c0b0b978384373e0895d") Blake3PowGardenGenesisHash = common.HexToHash("0x02874a9e708fd75a6ed73bf1d6dbc275a87b8914c3f57da0bbdc959c381d0f67") Blake3PowOrchardGenesisHash = common.HexToHash("0x43af9e6e91fbf408b9c6fd423ed34e5ad0bd2154737cefc204d145ffc660fc9c") - Blake3PowLocalGenesisHash = common.HexToHash("0xecbfee9f6bce9583520d16795bc9850783a8a86563c0ce9a5082d86f497b728f") + Blake3PowLocalGenesisHash = common.HexToHash("0xcc34daeac18fc7ad2f7fae0aecad5a34a0def7629776f6fd74a18463d9661588") Blake3PowLighthouseGenesisHash = common.HexToHash("0x43af9e6e91fbf408b9c6fd423ed34e5ad0bd2154737cefc204d145ffc660fc9c") ) diff --git a/quai/gasprice/feehistory.go b/quai/gasprice/feehistory.go index 84a3258071..d365335bbb 100644 --- a/quai/gasprice/feehistory.go +++ b/quai/gasprice/feehistory.go @@ -107,8 +107,8 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) { return } - sorter := make(sortGasAndReward, len(bf.block.QuaiTransactionsWithoutCoinbase())) - for i, tx := range bf.block.QuaiTransactionsWithoutCoinbase() { + sorter := make(sortGasAndReward, len(bf.block.TransactionsWithReceipts())) + for i, tx := range bf.block.TransactionsWithReceipts() { reward, _ := tx.EffectiveGasTip(bf.block.BaseFee()) sorter[i] = txGasAndReward{gasUsed: bf.receipts[i].GasUsed, reward: reward} }