Skip to content
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: 14 additions & 12 deletions core/quorum/block_maker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ type BlockMaker interface {
}

type pendingState struct {
state *state.StateDB // apply state changes here
tcount int // tx count in cycle
gp *core.GasPool
ownedAccounts *set.Set
txs types.Transactions // set of transactions
lowGasTxs types.Transactions
failedTxs types.Transactions
parent *types.Block
publicState, privateState *state.StateDB
tcount int // tx count in cycle
gp *core.GasPool
ownedAccounts *set.Set
txs types.Transactions // set of transactions
lowGasTxs types.Transactions
failedTxs types.Transactions
parent *types.Block

header *types.Header
receipts types.Receipts
Expand All @@ -38,7 +38,7 @@ type pendingState struct {
}

func (ps *pendingState) applyTransaction(tx *types.Transaction, bc *core.BlockChain, cc *core.ChainConfig) (error, vm.Logs) {
snap := ps.state.Snapshot()
publicSnaphot, privateSnapshot := ps.publicState.Snapshot(), ps.privateState.Snapshot()

// this is a bit of a hack to force jit for the miners
config := cc.VmConfig
Expand All @@ -47,9 +47,11 @@ func (ps *pendingState) applyTransaction(tx *types.Transaction, bc *core.BlockCh
}
config.ForceJit = false // disable forcing jit

receipt, logs, _, err := core.ApplyTransaction(cc, bc, ps.gp, ps.state, ps.state, ps.header, tx, ps.header.GasUsed, config)
receipt, logs, _, err := core.ApplyTransaction(cc, bc, ps.gp, ps.publicState, ps.privateState, ps.header, tx, ps.header.GasUsed, config)
if err != nil {
ps.state.RevertToSnapshot(snap)
ps.publicState.RevertToSnapshot(publicSnaphot)
ps.privateState.RevertToSnapshot(privateSnapshot)

return err, nil
}
ps.txs = append(ps.txs, tx)
Expand All @@ -76,7 +78,7 @@ func (ps *pendingState) applyTransactions(txs *types.TransactionsByPriorityAndNo
from, _ := tx.From()

// Start executing the transaction
ps.state.StartRecord(tx.Hash(), common.Hash{}, 0)
ps.publicState.StartRecord(tx.Hash(), common.Hash{}, 0)

err, logs := ps.applyTransaction(tx, bc, cc)
switch {
Expand Down
13 changes: 7 additions & 6 deletions core/quorum/block_voting.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ func NewBlockVoting(bc *core.BlockChain, chainConfig *core.ChainConfig, txpool *
}

func (bv *BlockVoting) resetPendingState(parent *types.Block) {
statedb, _, err := bv.bc.StateAt(parent.Root())
publicState, privateState, err := bv.bc.State()
if err != nil {
panic(fmt.Sprintf("State corrupt: %v", err))
panic(fmt.Sprintf("State error: %v", err))
}

ps := &pendingState{
parent: parent,
state: statedb,
publicState: publicState,
privateState: privateState,
header: bv.makeHeader(parent),
gp: new(core.GasPool),
ownedAccounts: accountAddressesSet(bv.am.Accounts()),
Expand Down Expand Up @@ -295,7 +296,7 @@ func (bv *BlockVoting) applyTransaction(tx *types.Transaction) {
func (bv *BlockVoting) Pending() (*types.Block, *state.StateDB) {
bv.pStateMu.Lock()
defer bv.pStateMu.Unlock()
return types.NewBlock(bv.pState.header, bv.pState.txs, nil, bv.pState.receipts), bv.pState.state.Copy()
return types.NewBlock(bv.pState.header, bv.pState.txs, nil, bv.pState.receipts), bv.pState.publicState.Copy()
}

func (bv *BlockVoting) createBlock() (*types.Block, error) {
Expand All @@ -314,13 +315,13 @@ func (bv *BlockVoting) createBlock() (*types.Block, error) {
bv.pStateMu.Lock()
defer bv.pStateMu.Unlock()

state := bv.pState.state // shortcut
state := bv.pState.publicState // shortcut
header := bv.pState.header
receipts := bv.pState.receipts

core.AccumulateRewards(state, header, nil)

header.Root = bv.pState.state.IntermediateRoot()
header.Root = state.IntermediateRoot()

// Quorum blocks contain a signature of the header in the Extra field.
// This signature is verified during block import and ensures that the
Expand Down
4 changes: 4 additions & 0 deletions core/vm_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ func (self *VMEnv) SnapshotDatabase() int {
return self.currentState().Snapshot()
}

// We only need to revert the current state because when we call from private
// public state it's read only, there wouldn't be anything to reset.
// (A)->(B)->C->(B): A failure in (B) wouldn't need to reset C, as C was flagged
// read only.
func (self *VMEnv) RevertToSnapshot(snapshot int) {
self.currentState().RevertToSnapshot(snapshot)
}
Expand Down