diff --git a/node/node.go b/node/node.go index 553b6f43b..0a60edf5e 100644 --- a/node/node.go +++ b/node/node.go @@ -103,7 +103,7 @@ func (node *Node) addPendingTransactionsAccount(newTxs types.Transactions) { node.pendingTxMutexAccount.Lock() node.pendingTransactionsAccount = append(node.pendingTransactionsAccount, newTxs...) node.pendingTxMutexAccount.Unlock() - node.log.Debug("Got more transactions (account model)", "num", len(newTxs), "totalPending", len(node.pendingTransactions), "node", node) + node.log.Debug("Got more transactions (account model)", "num", len(newTxs), "totalPending", len(node.pendingTransactionsAccount), "node", node) } // Take out a subset of valid transactions from the pending transaction list diff --git a/node/node_handler.go b/node/node_handler.go index fd6f2c41a..e736b630b 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -390,18 +390,27 @@ func (node *Node) WaitForConsensusReadyAccount(readySignal chan struct{}) { } if !retry { - if len(node.pendingTransactionsAccount) >= 1000 { - // Normal tx block consensus - selectedTxs, _ := node.getTransactionsForNewBlockAccount(MaxNumberOfTransactionsPerBlock) - if node.Worker.CommitTransactions(selectedTxs, pki.GetAddressFromPublicKey(node.SelfPeer.PubKey)) { - newBlock = node.Worker.Commit() - } else { - node.log.Debug("Failed to create new block") + for { + if len(node.pendingTransactionsAccount) >= 1000 { + // Normal tx block consensus + selectedTxs, _ := node.getTransactionsForNewBlockAccount(MaxNumberOfTransactionsPerBlock) + err := node.Worker.CommitTransactions(selectedTxs, pki.GetAddressFromPublicKey(node.SelfPeer.PubKey)) + if err == nil { + block, err := node.Worker.Commit() + if err != nil { + node.log.Debug("Failed commiting new block", "Error", err) + } else { + newBlock = block + break + } + } else { + node.log.Debug("Failed to create new block", "Error", err) + } } + // If not enough transactions to run Consensus, + // periodically check whether we have enough transactions to package into block. + time.Sleep(1 * time.Second) } - // If not enough transactions to run Consensus, - // periodically check whether we have enough transactions to package into block. - time.Sleep(1 * time.Second) } // Send the new block to Consensus so it can be confirmed. diff --git a/node/worker/worker.go b/node/worker/worker.go index d56a676a2..403408107 100644 --- a/node/worker/worker.go +++ b/node/worker/worker.go @@ -49,7 +49,7 @@ func (w *Worker) commitTransaction(tx *types.Transaction, coinbase common.Addres return receipt.Logs, nil } -func (w *Worker) CommitTransactions(txs []*types.Transaction, coinbase common.Address) bool { +func (w *Worker) CommitTransactions(txs []*types.Transaction, coinbase common.Address) error { snap := w.current.state.Snapshot() if w.current.gasPool == nil { @@ -59,11 +59,11 @@ func (w *Worker) CommitTransactions(txs []*types.Transaction, coinbase common.Ad _, err := w.commitTransaction(tx, coinbase) if err != nil { w.current.state.RevertToSnapshot(snap) - return false + return err } } - return true + return nil } func (w *Worker) UpdateCurrent() error { @@ -98,13 +98,13 @@ func (w *Worker) GetCurrentState() *state.StateDB { return w.current.state } -func (w *Worker) Commit() *types.Block { +func (w *Worker) Commit() (*types.Block, error) { s := w.current.state.Copy() block, err := w.engine.Finalize(w.chain, w.current.header, s, w.current.txs, w.current.receipts) if err != nil { - return nil + return nil, err } - return block + return block, nil } func New(config *params.ChainConfig, chain *core.BlockChain, engine consensus.Engine) *Worker { diff --git a/proto/node/node.go b/proto/node/node.go index bfabd40b2..00f36329a 100644 --- a/proto/node/node.go +++ b/proto/node/node.go @@ -4,8 +4,8 @@ import ( "bytes" "encoding/gob" "fmt" + "github.com/ethereum/go-ethereum/rlp" "github.com/harmony-one/harmony/core/types" - "go-ethereum/rlp" "log" "github.com/harmony-one/harmony/blockchain"