From a38031864da79a3ba09edc378e17e84098177022 Mon Sep 17 00:00:00 2001
From: Silas Davis <silas@monax.io>
Date: Fri, 2 Mar 2018 18:51:02 +0000
Subject: [PATCH] Protect executor's Execute method with a defered panic
 recovery function to avoid crashing entire network due to transactions that
 triggers a panic.

Signed-off-by: Silas Davis <silas@monax.io>
---
 execution/execution.go | 8 +++++++-
 txs/tx.go              | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/execution/execution.go b/execution/execution.go
index ed822a71..caff450f 100644
--- a/execution/execution.go
+++ b/execution/execution.go
@@ -150,8 +150,14 @@ func (exe *executor) Reset() error {
 
 // If the tx is invalid, an error will be returned.
 // Unlike ExecBlock(), state will not be altered.
-func (exe *executor) Execute(tx txs.Tx) error {
+func (exe *executor) Execute(tx txs.Tx) (err error) {
+	defer func() {
+		if r := recover(); r != nil {
+			err = fmt.Errorf("recovered from panic in executor.Execute(%s): %v", tx.String(), r)
+		}
+	}()
 	logger := logging.WithScope(exe.logger, "executor.Execute(tx txs.Tx)")
+	logging.TraceMsg(logger, "Executing transaction", "tx", tx.String())
 	// TODO: do something with fees
 	fees := uint64(0)
 
diff --git a/txs/tx.go b/txs/tx.go
index 2d35e776..c24018d4 100644
--- a/txs/tx.go
+++ b/txs/tx.go
@@ -101,6 +101,7 @@ type (
 	// TODO: replace with sum-type struct like ResultEvent
 	Tx interface {
 		WriteSignBytes(chainID string, w io.Writer, n *int, err *error)
+		String() string
 	}
 
 	Wrapper struct {
-- 
GitLab