add commitTransaction code for staking

pull/1795/head
chao 5 years ago
parent 2c1819a4e2
commit 89ef7317ff
  1. 4
      node/node_newblock.go
  2. 13
      node/worker/worker.go

@ -90,6 +90,10 @@ func (node *Node) proposeNewBlock() (*types.Block, error) {
return nil, err return nil, err
} }
if len(selectedStakingTxs) > 0 {
utils.Logger().Debug().Int("selectedStakingtxs", len(selectedStakingTxs)).Msg("hehe, staking txs proposed")
}
// Prepare cross shard transaction receipts // Prepare cross shard transaction receipts
receiptsList := node.proposeReceiptsProof() receiptsList := node.proposeReceiptsProof()
if len(receiptsList) != 0 { if len(receiptsList) != 0 {

@ -161,6 +161,7 @@ func (w *Worker) SelectStakingTransactionsForNewBlock(
} }
selected := staking.StakingTransactions{} selected := staking.StakingTransactions{}
// TODO: chao add total gas fee checking when needed
unselected := staking.StakingTransactions{} unselected := staking.StakingTransactions{}
invalid := staking.StakingTransactions{} invalid := staking.StakingTransactions{}
for _, tx := range txs { for _, tx := range txs {
@ -181,7 +182,6 @@ func (w *Worker) SelectStakingTransactionsForNewBlock(
w.current.header.GasUsed()).Msg("[SelectStakingTransaction] Block gas limit and usage info") w.current.header.GasUsed()).Msg("[SelectStakingTransaction] Block gas limit and usage info")
return selected, unselected, invalid return selected, unselected, invalid
} }
func (w *Worker) commitStakingTransaction(tx *staking.StakingTransaction, coinbase common.Address) ([]*types.Log, error) { func (w *Worker) commitStakingTransaction(tx *staking.StakingTransaction, coinbase common.Address) ([]*types.Log, error) {
@ -256,9 +256,14 @@ func (w *Worker) CommitTransactions(txs types.Transactions, stakingTxns staking.
} }
} }
for _, stakingTx := range stakingTxns { for _, tx := range stakingTxns {
_ = stakingTx snap := w.current.state.Snapshot()
// TODO: add logic to commit staking txns _, err := w.commitStakingTransaction(tx, coinbase)
if err != nil {
w.current.state.RevertToSnapshot(snap)
return err
}
} }
return nil return nil
} }

Loading…
Cancel
Save