Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mining test: set correct header.Timestamp and header.GasLimit #1603

Merged
merged 10 commits into from
Mar 25, 2021
Prev Previous commit
Next Next commit
mock header timestamp
  • Loading branch information
AskAlexSharov committed Mar 25, 2021
commit 84842868b924ff736bfc8aeb9dc8035c228796b2
12 changes: 8 additions & 4 deletions cmd/integration/commands/state_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,14 @@ func syncBySmallSteps(db ethdb.Database, miningConfig *params.MiningConfig, ctx
}
integrity.Trie(tx.(ethdb.HasTx).Tx(), integritySlow, quit)
}
//if err := tx.RollbackAndBegin(context.Background()); err != nil {
// return err
//}
if err := tx.CommitAndBegin(context.Background()); err != nil {
receiptsInDB := rawdb.ReadReceiptsByNumber(tx, progress(tx, stages.Execution))

if err := tx.RollbackAndBegin(context.Background()); err != nil {
return err
}
//if err := tx.CommitAndBegin(context.Background()); err != nil {
// return err
//}
execAtBlock = progress(tx, stages.Execution)
if execAtBlock == stopAt {
break
Expand Down Expand Up @@ -344,6 +346,8 @@ func syncBySmallSteps(db ethdb.Database, miningConfig *params.MiningConfig, ctx
miningStages.MockExecFunc(stages.MiningFinish, func(s *stagedsync.StageState, u stagedsync.Unwinder) error {
var err error
minedBlock, err = stagedsync.SpawnMiningFinishStage(s, tx, miningWorld.Block, cc.Engine(), chainConfig, quit)
debugprint.Transactions(nextBlock.Transactions(), miningWorld.Block.Txs)
debugprint.Receipts(receiptsInDB, miningWorld.Block.Receipts)
return err
})

Expand Down
44 changes: 41 additions & 3 deletions common/debugprint/receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,48 @@ import (
"github.com/ledgerwatch/turbo-geth/core/types"
)

//nolint
func Transactions(ts1, ts2 types.Transactions) {
fmt.Printf("==== Transactions ====\n")
fmt.Printf("len(Transactions): %d, %d\n", len(ts1), len(ts2))
for len(ts2) < len(ts1) {
ts2 = append(ts2, nil)
}
for i := range ts1 {
t1, t2 := ts1[i], ts2[i]
fmt.Printf(" ==== Transaction ====\n")
if t2 == nil {
fmt.Printf(" TxHash: %x\n", t1.Hash())
fmt.Printf(" To: %x\n", t1.To())
continue
}
fmt.Printf(" TxHash: %x, %x\n", t1.Hash(), t2.Hash())
fmt.Printf(" To: %x, %x\n", t1.To(), t2.To())
}
}

//nolint
func Receipts(rs1, rs2 types.Receipts) {
fmt.Printf("==== Receipts ====\n")
fmt.Printf("len(Receipts): %d, %d\n", len(rs1), len(rs2))
for len(rs2) < len(rs1) {
rs2 = append(rs2, &types.Receipt{})
rs2 = append(rs2, nil)
}

for i := range rs1 {
r1, r2 := rs1[i], rs2[i]
fmt.Printf(" ==== Receipt ====\n")
if r2 == nil {
fmt.Printf(" TxHash: %x\n", r1.TxHash)
fmt.Printf(" PostState: %x\n", r1.PostState)
fmt.Printf(" Status: %d\n", r1.Status)
fmt.Printf(" CumulativeGasUsed: %d\n", r1.CumulativeGasUsed)
fmt.Printf(" ContractAddress: %x\n", r1.ContractAddress)
fmt.Printf(" GasUsed: %x\n", r1.GasUsed)
fmt.Printf(" len(Logs): %d\n", len(r1.Logs))
continue
}

fmt.Printf(" TxHash: %x, %x\n", r1.TxHash, r2.TxHash)
fmt.Printf(" PostState: %x, %x\n", r1.PostState, r2.PostState)
fmt.Printf(" Status: %d, %d\n", r1.Status, r2.Status)
Expand All @@ -25,10 +56,17 @@ func Receipts(rs1, rs2 types.Receipts) {
fmt.Printf(" GasUsed: %x, %x\n", r1.GasUsed, r2.GasUsed)
fmt.Printf(" len(Logs): %d, %d\n", len(r1.Logs), len(r2.Logs))
for len(r2.Logs) < len(r1.Logs) {
r2.Logs = append(r2.Logs, &types.Log{})
r2.Logs = append(r2.Logs, nil)
}
for j := range r1.Logs {
l1, l2 := r1.Logs[j], r2.Logs[j]
l1 := r1.Logs[j]
l2 := r2.Logs[j]
if l2 == nil {
fmt.Printf(" Logs[%d].Address: %x\n", j, l1.Address)
fmt.Printf(" Logs[%d].Topic: %x\n", j, l1.Topics)
fmt.Printf(" Logs[%d].Data: %x\n", j, l1.Data)
continue
}
fmt.Printf(" Logs[%d].Address: %x, %x\n", j, l1.Address, l2.Address)
fmt.Printf(" Logs[%d].Topic: %x, %x\n", j, l1.Topics, l2.Topics)
fmt.Printf(" Logs[%d].Data: %x, %x\n", j, l1.Data, l2.Data)
Expand Down
3 changes: 3 additions & 0 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ func HasBody(db databaseReader, hash common.Hash, number uint64) bool {
// ReadBody retrieves the block body corresponding to the hash.
func ReadBody(db ethdb.Getter, hash common.Hash, number uint64) *types.Body {
body, baseTxId, txAmount := ReadBodyWithoutTransactions(db, hash, number)
if body == nil {
return nil
}
var err error
body.Transactions, err = ReadTransactions(db, baseTxId, txAmount)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions eth/stagedsync/stage_mining_create_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
type miningBlock struct {
Header *types.Header
Uncles []*types.Header
txs []*types.Transaction
receipts types.Receipts
Txs []*types.Transaction
Receipts types.Receipts

localTxs *types.TransactionsByPriceAndNonce
remoteTxs *types.TransactionsByPriceAndNonce
Expand Down
6 changes: 3 additions & 3 deletions eth/stagedsync/stage_mining_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func SpawnMiningExecStage(s *StageState, tx ethdb.Database, current *miningBlock
}
}

if err := core.FinalizeBlockExecution(engine, current.Header, current.txs, current.Uncles, stateWriter, chainConfig, ibs); err != nil {
if err := core.FinalizeBlockExecution(engine, current.Header, current.Txs, current.Uncles, stateWriter, chainConfig, ibs); err != nil {
return err
}

Expand Down Expand Up @@ -128,8 +128,8 @@ func addTransactionsToMiningBlock(current *miningBlock, chainConfig *params.Chai
//}
//fmt.Printf("Tx Hash: %x\n", txn.Hash())

current.txs = append(current.txs, txn)
current.receipts = append(current.receipts, receipt)
current.Txs = append(current.Txs, txn)
current.Receipts = append(current.Receipts, receipt)
return receipt.Logs, nil
}

Expand Down
2 changes: 1 addition & 1 deletion eth/stagedsync/stage_mining_finish.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func SpawnMiningFinishStage(s *StageState, tx ethdb.Database, current *miningBlo
// continue
//}

block := types.NewBlock(current.Header, current.txs, current.Uncles, current.receipts)
block := types.NewBlock(current.Header, current.Txs, current.Uncles, current.Receipts)

//sealHash := engine.SealHash(block.Header())
// Reject duplicate sealing work due to resubmitting.
Expand Down