Skip to content

Commit

Permalink
more clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski committed May 30, 2024
1 parent 6e54d78 commit 58fd5e3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
10 changes: 8 additions & 2 deletions server/v2/cometbft/client/rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func GetBlockByHeight(ctx context.Context, rpcClient CometRPC, height *int64) (*
return nil, err
}

out := NewResponseResultBlock(resBlock)
out, err := NewResponseResultBlock(resBlock)
if err != nil {
return nil, err
}
if out == nil {
return nil, fmt.Errorf("unable to create response block from comet result block: %v", resBlock)
}
Expand All @@ -88,7 +91,10 @@ func GetBlockByHash(ctx context.Context, rpcClient CometRPC, hashHexString strin
}

// TODO: Also move NewResponseResultBlock somewhere around this package
out := NewResponseResultBlock(resBlock)
out, err := NewResponseResultBlock(resBlock)
if err != nil {
return nil, err
}
if out == nil {
return nil, fmt.Errorf("unable to create response block from comet result block: %v", resBlock)
}
Expand Down
20 changes: 13 additions & 7 deletions server/v2/cometbft/client/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ import (

// formatBlockResults parses the indexed blocks into a slice of BlockResponse objects.
func formatBlockResults(resBlocks []*coretypes.ResultBlock) ([]*v11.Block, error) {
out := make([]*v11.Block, len(resBlocks))
var (
err error
out = make([]*v11.Block, len(resBlocks))
)
for i := range resBlocks {
out[i] = NewResponseResultBlock(resBlocks[i])
out[i], err = NewResponseResultBlock(resBlocks[i])
if err != nil {
return nil, fmt.Errorf("unable to create response block from comet result block: %v: %w", resBlocks[i], err)
}
if out[i] == nil {
return nil, fmt.Errorf("unable to create response block from comet result block: %v", resBlocks[i])
}
Expand All @@ -37,22 +43,22 @@ func NewSearchBlocksResult(totalCount, count, page, limit int64, blocks []*v11.B
}

// NewResponseResultBlock returns a BlockResponse given a ResultBlock from CometBFT
func NewResponseResultBlock(res *coretypes.ResultBlock) *v11.Block {
func NewResponseResultBlock(res *coretypes.ResultBlock) (*v11.Block, error) {
blkProto, err := res.Block.ToProto()
if err != nil {
panic(err)
return nil, err
}
blkBz, err := gogoproto.Marshal(blkProto)
if err != nil {
panic(err)
return nil, err
}

blk := &v11.Block{}
err = protov2.Unmarshal(blkBz, blk)
if err != nil {
panic(err)
return nil, err
}
return blk
return blk, nil
}

// calculate total pages in an overflow safe manner
Expand Down
2 changes: 1 addition & 1 deletion server/v2/cometbft/handlers/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (h *DefaultProposalHandler[T]) PrepareHandler() PrepareHandler[T] {
return func(ctx context.Context, app AppManager[T], txs []T, req proto.Message) ([]T, error) {
abciReq, ok := req.(*abci.PrepareProposalRequest)
if !ok {
return nil, fmt.Errorf("invalid request type: %T", req)
return nil, fmt.Errorf("expected abci.PrepareProposalRequest, invalid request type: %T,", req)
}

var maxBlockGas uint64
Expand Down

0 comments on commit 58fd5e3

Please sign in to comment.