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 - don't write changesets to batch #1595

Merged
merged 5 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions cmd/integration/commands/state_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ func syncBySmallSteps(db ethdb.Database, miningConfig *params.MiningConfig, ctx
break
}

if miningConfig.Enabled {
nextBlock, err := rawdb.ReadBlockByNumberWithSenders(tx, execAtBlock+1)
if err != nil {
panic(err)
}
nextBlock, err := rawdb.ReadBlockByNumberWithSenders(tx, execAtBlock+1)
if err != nil {
panic(err)
}

if miningConfig.Enabled && nextBlock.Header().Coinbase != (common.Address{}) {
unordered, ordered := miningTransactions(nextBlock)
_ = ordered //TODO: test failing because non-determined order of transactions, need somehow inject order
miningWorld := stagedsync.NewMiningStagesParameters(miningConfig, true, unordered, nil)
Expand All @@ -289,6 +289,22 @@ func syncBySmallSteps(db ethdb.Database, miningConfig *params.MiningConfig, ctx
panic(err)
}
var minedBlock *types.Block
// set right uncles from nextBlock
miningStages.MockExecFunc(stages.MiningCreateBlock, func(s *stagedsync.StageState, u stagedsync.Unwinder) error {
err = stagedsync.SpawnMiningCreateBlockStage(s, tx,
miningWorld.Block,
chainConfig,
cc.Engine(),
miningWorld.ExtraData,
miningWorld.GasFloor,
miningWorld.GasCeil,
miningWorld.Etherbase,
miningWorld.TxPoolLocals,
miningWorld.PendingTxs,
quit)
miningWorld.Block.Uncles = nextBlock.Uncles()
return err
})
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)
Expand Down
1 change: 0 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,6 @@ func FinalizeBlockExecution(engine consensus.Engine, header *types.Header, txs t
if err := ibs.CommitBlock(ctx, stateWriter); err != nil {
return fmt.Errorf("committing block %d failed: %v", header.Number.Uint64(), err)
}

if err := stateWriter.WriteChangeSets(); err != nil {
return fmt.Errorf("writing changesets for block %d failed: %v", header.Number.Uint64(), err)
}
Expand Down
2 changes: 0 additions & 2 deletions core/state/intra_block_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"sync"

"github.com/holiman/uint256"

"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/u256"
"github.com/ledgerwatch/turbo-geth/core/types"
Expand Down Expand Up @@ -515,7 +514,6 @@ func (sdb *IntraBlockState) HasSuicided(addr common.Address) bool {
// DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account
func (sdb *IntraBlockState) AddBalance(addr common.Address, amount *uint256.Int) {
sdb.Lock()

if sdb.trace {
fmt.Printf("AddBalance %x, %d\n", addr, amount)
}
Expand Down
1 change: 0 additions & 1 deletion eth/stagedsync/stage_hashstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ func getExtractFunc(db ethdb.Getter, cache *shards.StateCache, changeSetBucket s
if err != nil {
return err
}

if cache != nil {
if len(k) == 20 {
_, inCache := cache.GetAccount(k)
Expand Down
8 changes: 4 additions & 4 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
Header *types.Header
Uncles []*types.Header
txs []*types.Transaction
receipts types.Receipts

Expand Down Expand Up @@ -221,8 +221,8 @@ func SpawnMiningCreateBlockStage(s *StageState, tx ethdb.Database, current *mini
}
}

current.header = header
current.uncles = makeUncles(env.uncles)
current.Header = header
current.Uncles = makeUncles(env.uncles)

// Split the pending transactions into locals and remotes
localTxs, remoteTxs := make(map[common.Address]types.Transactions), pendingTxs
Expand Down
16 changes: 8 additions & 8 deletions eth/stagedsync/stage_mining_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ func SpawnMiningExecStage(s *StageState, tx ethdb.Database, current *miningBlock

engine := cc.Engine()
tcount := 0
gasPool := new(core.GasPool).AddGas(current.header.GasLimit)
gasPool := new(core.GasPool).AddGas(current.Header.GasLimit)
signer := types.NewEIP155Signer(chainConfig.ChainID)
ibs := state.New(state.NewPlainStateReader(batch))
stateWriter := state.NewPlainStateWriter(batch, batch, current.header.Number.Uint64())
if chainConfig.DAOForkSupport && chainConfig.DAOForkBlock != nil && chainConfig.DAOForkBlock.Cmp(current.header.Number) == 0 {
stateWriter := state.NewPlainStateWriter(batch, tx, current.Header.Number.Uint64())
if chainConfig.DAOForkSupport && chainConfig.DAOForkBlock != nil && chainConfig.DAOForkBlock.Cmp(current.Header.Number) == 0 {
misc.ApplyDAOHardFork(ibs)
}

var miningCommitTx = func(txn *types.Transaction, coinbase common.Address, vmConfig *vm.Config, chainConfig *params.ChainConfig, cc *core.TinyChainContext, ibs *state.IntraBlockState, stateWriter state.StateWriter, current *miningBlock) ([]*types.Log, error) {
header := current.header
header := current.Header
receipt, err := core.ApplyTransaction(chainConfig, cc, &coinbase, gasPool, ibs, stateWriter, header, txn, &header.GasUsed, *vmConfig)
// batch Rollback/CommitAndBegin methods - keeps batch object valid,
// means don't need re-create state reader or re-inject batch or create new batch
Expand All @@ -57,7 +57,7 @@ func SpawnMiningExecStage(s *StageState, tx ethdb.Database, current *miningBlock
return receipt.Logs, nil
}
var commitTransactions = func(current *miningBlock, txs *types.TransactionsByPriceAndNonce, coinbase common.Address /*, interrupt *int32*/) bool {
header := current.header
header := current.Header

var coalescedLogs []*types.Log

Expand Down Expand Up @@ -172,7 +172,7 @@ func SpawnMiningExecStage(s *StageState, tx ethdb.Database, current *miningBlock
// Create an empty block based on temporary copied state for
// sealing in advance without waiting block execution finished.
if !noempty {
log.Info("Commit an empty block", "number", current.header.Number)
log.Info("Commit an empty block", "number", current.Header.Number)
s.Done()
return nil
}
Expand All @@ -193,7 +193,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
}
if err := batch.Commit(); err != nil {
Expand Down Expand Up @@ -229,7 +229,7 @@ func SpawnMiningExecStage(s *StageState, tx ethdb.Database, current *miningBlock
*/

// hack: pretend that we are real execution stage - next stages will rely on this progress
if err := stages.SaveStageProgress(tx, stages.Execution, current.header.Number.Uint64()); err != nil {
if err := stages.SaveStageProgress(tx, stages.Execution, current.Header.Number.Uint64()); err != nil {
return err
}
s.Done()
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 @@ -17,7 +17,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
12 changes: 6 additions & 6 deletions eth/stagedsync/stagebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ type MiningStagesParameters struct {
// in this case this feature will add all empty blocks into canonical chain
// non-stop and no real transaction will be included.
noempty bool
pendingTxs map[common.Address]types.Transactions
txPoolLocals []common.Address
PendingTxs map[common.Address]types.Transactions
TxPoolLocals []common.Address

// runtime dat
Block *miningBlock
}

func NewMiningStagesParameters(cfg *params.MiningConfig, noempty bool, pendingTxs map[common.Address]types.Transactions, txPoolLocals []common.Address) *MiningStagesParameters {
return &MiningStagesParameters{MiningConfig: cfg, noempty: noempty, pendingTxs: pendingTxs, txPoolLocals: txPoolLocals, Block: &miningBlock{}}
return &MiningStagesParameters{MiningConfig: cfg, noempty: noempty, PendingTxs: pendingTxs, TxPoolLocals: txPoolLocals, Block: &miningBlock{}}

}

Expand Down Expand Up @@ -418,8 +418,8 @@ func MiningStages() StageBuilders {
world.mining.GasFloor,
world.mining.GasCeil,
world.mining.Etherbase,
world.mining.txPoolLocals,
world.mining.pendingTxs,
world.mining.TxPoolLocals,
world.mining.PendingTxs,
world.QuitCh)
},
UnwindFunc: func(u *UnwindState, s *StageState) error { return nil },
Expand Down Expand Up @@ -472,7 +472,7 @@ func MiningStages() StageBuilders {
if err != nil {
return err
}
world.mining.Block.header.Root = stateRoot
world.mining.Block.Header.Root = stateRoot
return nil
},
UnwindFunc: func(u *UnwindState, s *StageState) error { return nil },
Expand Down