Skip to content

Commit

Permalink
fix prepare proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed May 3, 2024
1 parent 42eab7d commit 2003711
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions app/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,45 @@ 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
}

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}
Expand Down

0 comments on commit 2003711

Please sign in to comment.