Skip to content

Commit

Permalink
add checks for nil/empty requests on cometbft
Browse files Browse the repository at this point in the history
  • Loading branch information
jordipainan committed Nov 23, 2023
1 parent ae80c39 commit 6833b75
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions vochain/cometbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ func (app *BaseApplication) InitChain(_ context.Context,
// CheckTx unmarshals req.Tx and checks its validity
func (app *BaseApplication) CheckTx(_ context.Context,
req *abcitypes.RequestCheckTx) (*abcitypes.ResponseCheckTx, error) {
if req == nil || req.Tx == nil {
return &abcitypes.ResponseCheckTx{
Code: 1,
Data: []byte("nil request or tx"),
}, errors.New("nil request or tx")
}
txReference := vochaintx.TxKey(req.Tx)
ref, ok := app.txReferences.Load(txReference)
if !ok {
Expand Down Expand Up @@ -219,6 +225,9 @@ func (app *BaseApplication) FinalizeBlock(_ context.Context,
req *abcitypes.RequestFinalizeBlock) (*abcitypes.ResponseFinalizeBlock, error) {
app.prepareProposalLock.Lock()
defer app.prepareProposalLock.Unlock()
if req == nil {
return nil, errors.New("nil request")
}
start := time.Now()
height := uint32(req.GetHeight())

Expand Down Expand Up @@ -327,6 +336,9 @@ func (app *BaseApplication) PrepareProposal(ctx context.Context,
req *abcitypes.RequestPrepareProposal) (*abcitypes.ResponsePrepareProposal, error) {
app.prepareProposalLock.Lock()
defer app.prepareProposalLock.Unlock()
if req == nil {
return nil, errors.New("nil request")
}
startTime := time.Now()

type txInfo struct {
Expand Down Expand Up @@ -431,6 +443,9 @@ func (app *BaseApplication) ProcessProposal(_ context.Context,
req *abcitypes.RequestProcessProposal) (*abcitypes.ResponseProcessProposal, error) {
app.prepareProposalLock.Lock()
defer app.prepareProposalLock.Unlock()
if req == nil {
return nil, errors.New("nil request")
}
// Check if the node is a validator, if not, just accept the proposal and return (nothing to say)
validator, err := app.State.Validator(app.NodeAddress, true)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions vochain/transaction/vochaintx/vochaintx.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type Tx struct {
// Extracts the signature. Prepares the signed body (ready to be checked) and
// computes the transaction ID (a hash of the data).
func (tx *Tx) Unmarshal(content []byte, chainID string) error {
if content == nil {
return fmt.Errorf("nil content")
}
stx := new(models.SignedTx)
if err := proto.Unmarshal(content, stx); err != nil {
return fmt.Errorf("failed to unmarshal signed transaction: %w", err)
Expand Down

0 comments on commit 6833b75

Please sign in to comment.