mirror of https://github.com/poanetwork/quorum.git
Merge pull request #5 from bas-vk/state
core/quorum, core: add private transaction state processing
This commit is contained in:
commit
f4b5a8c83e
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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()),
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue