From 2003711946e3fcb303f3882643d51925798d7d4f Mon Sep 17 00:00:00 2001
From: yihuang <yi.codeplayer@gmail.com>
Date: Fri, 3 May 2024 10:42:14 +0800
Subject: [PATCH] fix prepare proposal

---
 app/proposal.go | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/app/proposal.go b/app/proposal.go
index 29eb1a0076..fe23975ba8 100644
--- a/app/proposal.go
+++ b/app/proposal.go
@@ -71,22 +71,20 @@ func (h *ProposalHandler) SetBlockList(blob []byte) error {
 	return nil
 }
 
-func (h *ProposalHandler) ValidateTransactions(txs [][]byte) error {
-	for _, txBz := range txs {
-		tx, err := h.TxDecoder(txBz)
-		if err != nil {
-			return err
-		}
+func (h *ProposalHandler) ValidateTransaction(txBz []byte) error {
+	tx, err := h.TxDecoder(txBz)
+	if err != nil {
+		return err
+	}
 
-		sigTx, ok := tx.(signing.SigVerifiableTx)
-		if !ok {
-			return fmt.Errorf("tx of type %T does not implement SigVerifiableTx", tx)
-		}
+	sigTx, ok := tx.(signing.SigVerifiableTx)
+	if !ok {
+		return fmt.Errorf("tx of type %T does not implement SigVerifiableTx", tx)
+	}
 
-		for _, signer := range sigTx.GetSigners() {
-			if _, ok := h.Blocklist[signer.String()]; ok {
-				return fmt.Errorf("signer is blocked: %s", signer.String())
-			}
+	for _, signer := range sigTx.GetSigners() {
+		if _, ok := h.Blocklist[signer.String()]; ok {
+			return fmt.Errorf("signer is blocked: %s", signer.String())
 		}
 	}
 	return nil
@@ -94,18 +92,24 @@ func (h *ProposalHandler) ValidateTransactions(txs [][]byte) error {
 
 func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
 	return func(ctx sdk.Context, req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
-		if err := h.ValidateTransactions(req.Txs); err != nil {
-			panic(err)
+		txs := make([][]byte, 0, len(req.Txs))
+		for _, txBz := range req.Txs {
+			if err := h.ValidateTransaction(txBz); err != nil {
+				continue
+			}
+			txs = append(txs, txBz)
 		}
 
-		return abci.ResponsePrepareProposal{Txs: req.Txs}
+		return abci.ResponsePrepareProposal{Txs: txs}
 	}
 }
 
 func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler {
 	return func(ctx sdk.Context, req abci.RequestProcessProposal) abci.ResponseProcessProposal {
-		if err := h.ValidateTransactions(req.Txs); err != nil {
-			return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
+		for _, txBz := range req.Txs {
+			if err := h.ValidateTransaction(txBz); err != nil {
+				return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
+			}
 		}
 
 		return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}