fix: TestRPCGetTransactionReceiptsByBlock

This commit is contained in:
anshalshukla 2024-09-01 13:36:21 +05:30
parent 02faed0a32
commit fc30355849
No known key found for this signature in database
GPG key ID: 84BE5474523D8CBC
4 changed files with 22 additions and 21 deletions

View file

@ -521,7 +521,7 @@ func (ethash *Ethash) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number)) header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
// Header seems complete, assemble into a block and return // Header seems complete, assemble into a block and return
return types.NewBlock(header, &types.Body{Transactions: body.Transactions, Uncles: body.Uncles}, receipts, trie.NewStackTrie(nil)), nil return types.NewBlock(header, &types.Body{Transactions: body.Transactions, Uncles: body.Uncles, Withdrawals: body.Withdrawals}, receipts, trie.NewStackTrie(nil)), nil
} }
// SealHash returns the hash of a block prior to it being sealed. // SealHash returns the hash of a block prior to it being sealed.

View file

@ -150,6 +150,17 @@ func CanTransfer(db vm.StateDB, addr common.Address, amount *uint256.Int) bool {
// Transfer subtracts amount from sender and adds amount to recipient using the given Db // Transfer subtracts amount from sender and adds amount to recipient using the given Db
func Transfer(db vm.StateDB, sender, recipient common.Address, amount *uint256.Int) { func Transfer(db vm.StateDB, sender, recipient common.Address, amount *uint256.Int) {
// get inputs before
input1 := db.GetBalance(sender)
input2 := db.GetBalance(recipient)
db.SubBalance(sender, amount, tracing.BalanceChangeTransfer) db.SubBalance(sender, amount, tracing.BalanceChangeTransfer)
db.AddBalance(recipient, amount, tracing.BalanceChangeTransfer) db.AddBalance(recipient, amount, tracing.BalanceChangeTransfer)
// get outputs after
output1 := db.GetBalance(sender)
output2 := db.GetBalance(recipient)
// add transfer log
AddTransferLog(db, sender, recipient, amount.ToBig(), input1.ToBig(), input2.ToBig(), output1.ToBig(), output2.ToBig())
} }

View file

@ -443,7 +443,7 @@ func newTestBackend(t *testing.T, n int, gspec *core.Genesis, engine consensus.E
} }
) )
accman, acc := newTestAccountManager(t) accman, acc := newTestAccountManager(t)
gspec.Alloc[acc.Address] = types.Account{Balance: big.NewInt(params.Ether)} // gspec.Alloc[acc.Address] = types.Account{Balance: big.NewInt(params.Ether)}
// Generate blocks for testing // Generate blocks for testing
db, blocks, _ := core.GenerateChainWithGenesis(gspec, engine, n, generator) db, blocks, _ := core.GenerateChainWithGenesis(gspec, engine, n, generator)
txlookupLimit := uint64(0) txlookupLimit := uint64(0)

View file

@ -1764,19 +1764,16 @@ func (w *worker) commit(ctx context.Context, env *environment, interval func(),
return err return err
} }
// If we're post merge, just ignore select {
if !w.isTTDReached(block.Header()) { case w.taskCh <- &task{ctx: ctx, receipts: env.receipts, state: env.state, block: block, createdAt: time.Now()}:
select { fees := totalFees(block, env.receipts)
case w.taskCh <- &task{ctx: ctx, receipts: env.receipts, state: env.state, block: block, createdAt: time.Now()}: feesInEther := new(big.Float).Quo(new(big.Float).SetInt(fees), big.NewFloat(params.Ether))
fees := totalFees(block, env.receipts) log.Info("Commit new sealing work", "number", block.Number(), "sealhash", w.engine.SealHash(block.Header()),
feesInEther := new(big.Float).Quo(new(big.Float).SetInt(fees), big.NewFloat(params.Ether)) "txs", env.tcount, "gas", block.GasUsed(), "fees", feesInEther,
log.Info("Commit new sealing work", "number", block.Number(), "sealhash", w.engine.SealHash(block.Header()), "elapsed", common.PrettyDuration(time.Since(start)))
"txs", env.tcount, "gas", block.GasUsed(), "fees", feesInEther,
"elapsed", common.PrettyDuration(time.Since(start)))
case <-w.exitCh: case <-w.exitCh:
log.Info("Worker has exited") log.Info("Worker has exited")
}
} }
} }
@ -1806,13 +1803,6 @@ func (w *worker) getSealingBlock(params *generateParams) *newPayloadResult {
} }
} }
// isTTDReached returns the indicator if the given block has reached the total
// terminal difficulty for The Merge transition.
func (w *worker) isTTDReached(header *types.Header) bool {
td, ttd := w.chain.GetTd(header.ParentHash, header.Number.Uint64()-1), w.chain.Config().TerminalTotalDifficulty
return td != nil && ttd != nil && td.Cmp(ttd) >= 0
}
// adjustResubmitInterval adjusts the resubmit interval. // adjustResubmitInterval adjusts the resubmit interval.
func (w *worker) adjustResubmitInterval(message *intervalAdjust) { func (w *worker) adjustResubmitInterval(message *intervalAdjust) {
select { select {