Skip to content

Commit

Permalink
chore(SDK): Downgrading Cosmos SDK version to latest 47 version (#8)
Browse files Browse the repository at this point in the history
* migrating codebase, need to make base app fix

* working unit tests

* can build an sim app

* working integration tests

* adding CI for integration tests

* nits
  • Loading branch information
davidterpay authored Aug 21, 2023
1 parent dee2fc5 commit 27a17ec
Show file tree
Hide file tree
Showing 37 changed files with 1,511 additions and 1,304 deletions.
57 changes: 28 additions & 29 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,33 @@ jobs:
run: |
make test
# TODO: Add this back once we have a working version of v0.50.0 with ITS and v0.47.x
# test-integration:
# runs-on: ubuntu-latest
# timeout-minutes: 25
# steps:
# - uses: actions/checkout@v3
# - uses: technote-space/[email protected]
# with:
# PATTERNS: |
# **/**.go
# go.mod
# go.sum
# - uses: actions/setup-go@v4
# if: env.GIT_DIFF
# with:
# go-version: "1.20"
# cache: true
test-integration:
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@v3
- uses: technote-space/[email protected]
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: actions/setup-go@v4
if: env.GIT_DIFF
with:
go-version: "1.20"
cache: true

# # In this step, this action saves a list of existing images, the cache is
# # created without them in the post run. It also restores the cache if it
# # exists.
# - name: cache docker layer
# uses: satackey/[email protected]
# if: env.GIT_DIFF
# # Ignore the failure of a step and avoid terminating the job.
# continue-on-error: true
# In this step, this action saves a list of existing images, the cache is
# created without them in the post run. It also restores the cache if it
# exists.
- name: cache docker layer
uses: satackey/[email protected]
if: env.GIT_DIFF
# Ignore the failure of a step and avoid terminating the job.
continue-on-error: true

# - name: Integration Tests
# if: env.GIT_DIFF
# run: |
# make test-integration
- name: Integration Tests
if: env.GIT_DIFF
run: |
make test-integration
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ docker-build: use-main

docker-build-integration: use-main
@echo "Building integration-test Docker image..."
@DOCKER_BUILDKIT=1 docker build -t pob-integration -f contrib/images/pob.integration.Dockerfile .
@DOCKER_BUILDKIT=1 docker build -t block-sdk-integration -f contrib/images/pob.integration.Dockerfile .

###############################################################################
### Tests ###
Expand Down
27 changes: 11 additions & 16 deletions abci/abci.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package abci

import (
"fmt"

"cosmossdk.io/log"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/skip-mev/block-sdk/block"
"github.com/skip-mev/block-sdk/block/utils"
Expand Down Expand Up @@ -39,19 +37,19 @@ func NewProposalHandler(logger log.Logger, txDecoder sdk.TxDecoder, lanes []bloc
// the default lane will not have a boundary on the number of bytes that can be included in the proposal and
// will include all valid transactions in the proposal (up to MaxTxBytes).
func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
return func(ctx sdk.Context, req *abci.RequestPrepareProposal) (resp *abci.ResponsePrepareProposal, err error) {
return func(ctx sdk.Context, req abci.RequestPrepareProposal) (resp abci.ResponsePrepareProposal) {
// In the case where there is a panic, we recover here and return an empty proposal.
defer func() {
if err := recover(); err != nil {
h.logger.Error("failed to prepare proposal", "err", err)
resp = &abci.ResponsePrepareProposal{Txs: make([][]byte, 0)}
resp = abci.ResponsePrepareProposal{Txs: make([][]byte, 0)}
}
}()

proposal, err := h.prepareLanesHandler(ctx, block.NewProposal(req.MaxTxBytes))
if err != nil {
h.logger.Error("failed to prepare proposal", "err", err)
return &abci.ResponsePrepareProposal{Txs: make([][]byte, 0)}, err
return abci.ResponsePrepareProposal{Txs: make([][]byte, 0)}
}

h.logger.Info(
Expand All @@ -61,9 +59,7 @@ func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
"height", req.Height,
)

return &abci.ResponsePrepareProposal{
Txs: proposal.GetProposal(),
}, nil
return abci.ResponsePrepareProposal{Txs: proposal.GetProposal()}
}
}

Expand All @@ -72,39 +68,38 @@ func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
// If a lane's portion of the proposal is invalid, we reject the proposal. After a lane's portion
// of the proposal is verified, we pass the remaining transactions to the next lane in the chain.
func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler {
return func(ctx sdk.Context, req *abci.RequestProcessProposal) (resp *abci.ResponseProcessProposal, err error) {
return func(ctx sdk.Context, req abci.RequestProcessProposal) (resp abci.ResponseProcessProposal) {
// In the case where any of the lanes panic, we recover here and return a reject status.
defer func() {
if rec := recover(); rec != nil {
h.logger.Error("failed to process proposal", "recover_err", rec)

resp = &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
err = fmt.Errorf("failed to process proposal: %v", rec)
resp = abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
}
}()

txs := req.Txs
if len(txs) == 0 {
h.logger.Info("accepted empty proposal")
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}
}

// Decode the transactions from the proposal.
decodedTxs, err := utils.GetDecodedTxs(h.txDecoder, txs)
if err != nil {
h.logger.Error("failed to decode transactions", "err", err)
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
}

// Verify the proposal using the verification logic from each lane.
if _, err := h.processLanesHandler(ctx, decodedTxs); err != nil {
h.logger.Error("failed to validate the proposal", "err", err)
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
}

h.logger.Info("validated proposal", "num_txs", len(txs))

return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}
}
}

Expand Down
Loading

0 comments on commit 27a17ec

Please sign in to comment.