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

Check warning on line 71 in app/proposal.go

View check run for this annotation

Codecov / codecov/patch

app/proposal.go#L70-L71

Added lines #L70 - L71 were not covered by tests
}

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

Check warning on line 77 in app/proposal.go

View check run for this annotation

Codecov / codecov/patch

app/proposal.go#L74-L77

Added lines #L74 - L77 were not covered by tests
}

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)

Check warning on line 82 in app/proposal.go

View check run for this annotation

Codecov / codecov/patch

app/proposal.go#L80-L82

Added lines #L80 - L82 were not covered by tests
}

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())

Check warning on line 87 in app/proposal.go

View check run for this annotation

Codecov / codecov/patch

app/proposal.go#L85-L87

Added lines #L85 - L87 were not covered by tests
}
}
return nil

Check warning on line 90 in app/proposal.go

View check run for this annotation

Codecov / codecov/patch

app/proposal.go#L90

Added line #L90 was not covered by tests
}

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

Check warning on line 98 in app/proposal.go

View check run for this annotation

Codecov / codecov/patch

app/proposal.go#L95-L98

Added lines #L95 - L98 were not covered by tests
}
txs = append(txs, txBz)

Check warning on line 100 in app/proposal.go

View check run for this annotation

Codecov / codecov/patch

app/proposal.go#L100

Added line #L100 was not covered by tests
}

return abci.ResponsePrepareProposal{Txs: req.Txs}
return abci.ResponsePrepareProposal{Txs: txs}

Check warning on line 103 in app/proposal.go

View check run for this annotation

Codecov / codecov/patch

app/proposal.go#L103

Added line #L103 was not covered by tests
}
}

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}

Check warning on line 111 in app/proposal.go

View check run for this annotation

Codecov / codecov/patch

app/proposal.go#L109-L111

Added lines #L109 - L111 were not covered by tests
}
}

return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}

Check warning on line 115 in app/proposal.go

View check run for this annotation

Codecov / codecov/patch

app/proposal.go#L115

Added line #L115 was not covered by tests
Expand Down

0 comments on commit 2003711

Please sign in to comment.