Skip to content

Commit

Permalink
Feat/cherry pick upgrade (#365)
Browse files Browse the repository at this point in the history
* Add liquidity provider fee pool

* Add deliver tx and before commit hooks

* Implements Valuer and Scanner interface for Int and Dec

* Add after committer hook

* Add liquidity provider fee pool to module account invariant

* Add liquidity provider fee pool to distribution genesis check

* Revert "Emit anthandler events even if txn fails or panics"

This reverts commit c5adf7a.

* Fix deliverTxer not including ante events on failed txns

* Change authz module name from const to var

* feat: increase DefaultGasLimit for cli tx

* Add msg handler middleware

* add: Hooks for send keeper

* fix: Typos

* fix: Type error

* add error handling to hooks

* add IsModuleAccount function in AccountKeeper to check if a supplied address is a module account.

* add transfer hooks  BeforeMultiSend and  AfterMultiSend for multisend functionality

* fix make install issue

* remove unneeded hooks

* Delete version specifally

* Delete version

* Panic on error

* Add logs

* Hardcode version delete

* Force overwrite

* Update iavl

* Force delete version

* Fix ver deletion

* Rollback properly

* Fix merge regressions

* Fix rollback cmd

* add evm mapping logic in accountKeeper and bankKeeper

* edit getAccount to stay in line with initial cosmos sdk contract, ie return nil when address is nil instead of panic

* revert HasAccount to its original definition in case future libraries/code uses it.
set function which checks for account with mapping condition included name to be AccountExists instead

* reverts commit b45c030 "revert HasAccount to its original definition in case future libraries/code uses it."

* create GetMappedAccountAddressIfExists helper method in accountKeeper

* refactor GetMappedAccountAddressIfExists to GetMergedAccountAddressIfExists and remove GetMappedAccountAddressIfExists in BaseSendKeeper

* remove getting merged account logic in getAllBalances as it is already present in IterateAccountBalances

* code clean up

* move extraction of address from key to be in app logic rather than in accountKeeper

* Revert "move extraction of address from key to be in app logic rather than in accountKeeper"

This reverts commit e7af659.

* add guard for iteration of EthAddressToCosmosAddress and CosmosAddressToEthAddressKey to prevent panic

* update iavl

* Code Refactoring: Refactor telemetry to begin and end block (#316)

* Remove hardcoded telemetry from modules

* Add telemetry to begin/endblock

* Remove test labels

* add GetMappedAddress helper method

* ensure that event emitted from transfer of funds is from mapped address

* Add telemetry to GRPC handler (#320)

* feat/api node for off oracle service [WIP] (#333)

* Add new address field to `app.toml`

* Refactor typo

* Refactor naming

* Update oracle address port

* add refund-handler to base-app

* fix bug with refundHandler msCache

* append refund events to anteEvents

* feat: add before and after ModuleEndBlock

* fix: db_backend lookup in config.toml

see: cosmos#17181

* feat: telemetry monitor-store-size-interval config

* fix conflicts from cherry-picking

* add back legacy router to handle legacy sdk.msg routing

* update proto related files

* Revert "update proto related files"

This reverts commit 8145796.

* update distribution proto

* add back value and scanner interface for LegacyDec

* update cosmossdk.io/math pseudo ver

* feat: add pruning-start-height flag to prune cmd

* update distribution proto and rerun make proto-gen

* update distribution proto and rerun make proto-gen again

* change begin and end blockers for gov, staking and upgrade modules to accept ptr keeper instead

* remove duplicate pruning cmd flag

* use cosmos iavl instead of our fork

* remove previous forked rollback code

* update cometbft to v0.38.0 to fully utilise ABCI++

* Revert "update cometbft to v0.38.0 to fully utilise ABCI++"

This reverts commit 57a9676.

---------

Co-authored-by: Ivan Poon <ravenxce@gmail.com>
Co-authored-by: Lee Yik Jiun <yikjiun.lee@switcheo.network>
Co-authored-by: holyxiaoxin <jr.loves.maths@gmail.com>
Co-authored-by: Ivan Poon <ivan.poon@switcheo.network>
Co-authored-by: PC <spclight@gmail.com>
Co-authored-by: Randy <randy75828@gmail.com>
Co-authored-by: lance.lan <lmengsplist96@gmail.com>
Co-authored-by: Nicholas Chung <84615041+chungnicholas@users.noreply.github.com>
  • Loading branch information
9 people authored Nov 2, 2023
1 parent 2e9e5d6 commit 7ccb8b4
Show file tree
Hide file tree
Showing 82 changed files with 11,746 additions and 723 deletions.
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ ifeq (secp,$(findstring secp,$(COSMOS_BUILD_OPTIONS)))
build_tags += libsecp256k1_sdk
endif

ifeq (legacy,$(findstring legacy,$(COSMOS_BUILD_OPTIONS)))
build_tags += app_v1
endif

whitespace :=
whitespace += $(whitespace)
comma := ,
Expand Down
550 changes: 394 additions & 156 deletions api/cosmos/distribution/v1beta1/distribution.pulsar.go

Large diffs are not rendered by default.

1,357 changes: 1,164 additions & 193 deletions api/cosmos/distribution/v1beta1/query.pulsar.go

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions api/cosmos/distribution/v1beta1/query_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliv
gInfo := sdk.GasInfo{}
resultStr := "successful"

defer func() {
if app.deliverTxer != nil {
app.deliverTxer(app.deliverState.ctx, req, res)
}
}()

defer func() {
for _, streamingListener := range app.abciListeners {
if err := streamingListener.ListenDeliverTx(app.deliverState.ctx, req, res); err != nil {
Expand Down Expand Up @@ -436,6 +442,9 @@ func (app *BaseApp) Commit() abci.ResponseCommit {
if ok {
rms.SetCommitHeader(header)
}
if app.beforeCommitter != nil {
app.beforeCommitter(app.deliverState.ctx)
}

// Write the DeliverTx state into branched storage and commit the MultiStore.
// The write to the DeliverTx state writes all state transitions to the root
Expand Down Expand Up @@ -463,6 +472,10 @@ func (app *BaseApp) Commit() abci.ResponseCommit {
// Commit. Use the header from this latest block.
app.setState(runTxModeCheck, header)

if app.afterCommitter != nil {
app.afterCommitter(app.deliverState.ctx)
}

// empty/reset the deliver state
app.deliverState = nil

Expand Down Expand Up @@ -686,6 +699,7 @@ func (app *BaseApp) ApplySnapshotChunk(req abci.RequestApplySnapshotChunk) abci.
}

func (app *BaseApp) handleQueryGRPC(handler GRPCQueryHandler, req abci.RequestQuery) abci.ResponseQuery {
defer telemetry.ModuleMeasureSince(req.Path, time.Now(), "GRPC_query")
ctx, err := app.CreateQueryContext(req.Height, req.Prove)
if err != nil {
return sdkerrors.QueryResult(err, app.trace)
Expand Down
84 changes: 76 additions & 8 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
)

type (
Expand Down Expand Up @@ -56,13 +57,15 @@ type BaseApp struct { //nolint: maligned
storeLoader StoreLoader // function to handle store loading, may be overridden with SetStoreLoader()
grpcQueryRouter *GRPCQueryRouter // router for redirecting gRPC query calls
msgServiceRouter *MsgServiceRouter // router for redirecting Msg service messages
router sdk.Router // handle any kind of message
interfaceRegistry codectypes.InterfaceRegistry
txDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx
txEncoder sdk.TxEncoder // marshal sdk.Tx into []byte

mempool mempool.Mempool // application side mempool
anteHandler sdk.AnteHandler // ante handler for fee and auth
postHandler sdk.PostHandler // post handler, optional, e.g. for tips
refundHandler sdk.AnteHandler // refund handler for failed tx
initChainer sdk.InitChainer // initialize state with validators and state blob
beginBlocker sdk.BeginBlocker // logic to run before any txs
processProposal sdk.ProcessProposalHandler // the handler which runs on ABCI ProcessProposal
Expand All @@ -72,6 +75,8 @@ type BaseApp struct { //nolint: maligned
idPeerFilter sdk.PeerFilter // filter peers by node ID
fauxMerkleMode bool // if true, IAVL MountStores uses MountStoresDB for simulation speed.

customMiddlewares

// manages snapshots, i.e. dumps of app state at certain intervals
snapshotManager *snapshots.Manager

Expand Down Expand Up @@ -146,6 +151,14 @@ type BaseApp struct { //nolint: maligned
chainID string
}

type customMiddlewares struct {
deliverTxer sdk.DeliverTxer // logic to run on any deliver tx
beforeCommitter sdk.BeforeCommitter // logic to run before committing state
afterCommitter sdk.AfterCommitter // logic to run after committing state

msgHandlerMiddleware sdk.MsgHandlerMiddleware // middleware that wraps msg handlers
}

// NewBaseApp returns a reference to an initialized BaseApp. It accepts a
// variadic number of option functions, which act on the BaseApp to set
// configuration choices.
Expand All @@ -160,6 +173,7 @@ func NewBaseApp(
db: db,
cms: store.NewCommitMultiStore(db),
storeLoader: DefaultStoreLoader,
router: NewRouter(),
grpcQueryRouter: NewGRPCQueryRouter(),
msgServiceRouter: NewMsgServiceRouter(),
txDecoder: txDecoder,
Expand Down Expand Up @@ -405,6 +419,17 @@ func (app *BaseApp) setIndexEvents(ie []string) {
}
}

// Router returns the legacy router of the BaseApp.
func (app *BaseApp) Router() sdk.Router {
if app.sealed {
// We cannot return a Router when the app is sealed because we can't have
// any routes modified which would cause unexpected routing behavior.
panic("Router() on sealed BaseApp")
}

return app.router
}

// Seal seals a BaseApp. It prohibits any further modifications to a BaseApp.
func (app *BaseApp) Seal() { app.sealed = true }

Expand Down Expand Up @@ -770,6 +795,23 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re
// append the events in the order of occurrence
result.Events = append(anteEvents, result.Events...)
}
} else {
if app.refundHandler != nil {
refundCtx, msCache := app.cacheTxContext(ctx, txBytes)
refundCtx = refundCtx.WithEventManager(sdk.NewEventManager())
newCtx, err := app.refundHandler(refundCtx, tx, mode == runTxModeSimulate)
if err != nil {
return gInfo, result, anteEvents, priority, err
}

if mode == runTxModeDeliver {
msCache.Write()
}

if len(anteEvents) > 0 && (mode == runTxModeDeliver || mode == runTxModeSimulate) {
anteEvents = append(anteEvents, newCtx.EventManager().ABCIEvents()...)
}
}
}

return gInfo, result, anteEvents, priority, err
Expand All @@ -785,21 +827,43 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s
events := sdk.EmptyEvents()
var msgResponses []*codectypes.Any

middleware := app.msgHandlerMiddleware
if middleware == nil {
middleware = noopMiddleware
}

// NOTE: GasWanted is determined by the AnteHandler and GasUsed by the GasMeter.
for i, msg := range msgs {
if mode != runTxModeDeliver && mode != runTxModeSimulate {
break
}

handler := app.msgServiceRouter.Handler(msg)
if handler == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "can't route message %+v", msg)
}
var (
msgResult *sdk.Result
err error
)

// ADR 031 request type routing
msgResult, err := handler(ctx, msg)
if err != nil {
return nil, sdkerrors.Wrapf(err, "failed to execute message; message index: %d", i)
if handler := app.msgServiceRouter.Handler(msg); handler != nil {
// ADR 031 request type routing
msgResult, err = middleware(ctx, msg, handler)
if err != nil {
return nil, sdkerrors.Wrapf(err, "failed to execute message; message index: %d", i)
}
} else if legacyMsg, ok := msg.(legacytx.LegacyMsg); ok {
// legacy sdk.Msg routing
// Assuming that the app developer has migrated all their Msgs to
// proto messages and has registered all `Msg services`, then this
// path should never be called, because all those Msgs should be
// registered within the `msgServiceRouter` already.
msgRoute := legacyMsg.Route()
handler := app.router.Route(ctx, msgRoute)
if handler == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized message route: %s; message index: %d", msgRoute, i)
}

msgResult, err = middleware(ctx, msg, handler)
} else {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "can't route message %+v", msg)
}

// create message events
Expand Down Expand Up @@ -1074,3 +1138,7 @@ func NoOpProcessProposal() sdk.ProcessProposalHandler {
func (app *BaseApp) Close() error {
return nil
}

var noopMiddleware sdk.MsgHandlerMiddleware = func(c sdk.Context, m sdk.Msg, h sdk.Handler) (*sdk.Result, error) {
return h(c, m)
}
8 changes: 8 additions & 0 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,14 @@ func TestTxDecoder(t *testing.T) {
require.Equal(t, counter, dTxCounter)
}

// Interleave calls to Check and Deliver and ensure
// that there is no cross-talk. Check sees results of the previous Check calls
// and Deliver sees that of the previous Deliver calls, but they don't see eachother.
func TestConcurrentCheckDeliver(t *testing.T) {
// TODO
}

// Test custom panic handling within app.DeliverTx method
func TestCustomRunTxPanicHandler(t *testing.T) {
customPanicMsg := "test panic"
anteErr := sdkerrors.Register("fakeModule", 100500, "fakeError")
Expand Down
40 changes: 40 additions & 0 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,30 @@ func (app *BaseApp) SetEndBlocker(endBlocker sdk.EndBlocker) {
app.endBlocker = endBlocker
}

func (app *BaseApp) SetDeliverTxer(deliverTxer sdk.DeliverTxer) {
if app.sealed {
panic("SetDeliverTxer() on sealed BaseApp")
}

app.deliverTxer = deliverTxer
}

func (app *BaseApp) SetBeforeCommitter(beforeCommitter sdk.BeforeCommitter) {
if app.sealed {
panic("SetBeforeCommitter() on sealed BaseApp")
}

app.beforeCommitter = beforeCommitter
}

func (app *BaseApp) SetAfterCommitter(afterCommitter sdk.AfterCommitter) {
if app.sealed {
panic("SetBeforeCommitter() on sealed BaseApp")
}

app.afterCommitter = afterCommitter
}

func (app *BaseApp) SetAnteHandler(ah sdk.AnteHandler) {
if app.sealed {
panic("SetAnteHandler() on sealed BaseApp")
Expand All @@ -182,6 +206,22 @@ func (app *BaseApp) SetPostHandler(ph sdk.PostHandler) {
app.postHandler = ph
}

func (app *BaseApp) SetRefundHandler(rh sdk.AnteHandler) {
if app.sealed {
panic("SetRefundHandler() on sealed BaseApp")
}

app.refundHandler = rh
}

func (app *BaseApp) SetMsgHandlerMiddleware(msgHandlerMiddleware sdk.MsgHandlerMiddleware) {
if app.sealed {
panic("SetMsgHandlerMiddleware() on sealed BaseApp")
}

app.msgHandlerMiddleware = msgHandlerMiddleware
}

func (app *BaseApp) SetAddrPeerFilter(pf sdk.PeerFilter) {
if app.sealed {
panic("SetAddrPeerFilter() on sealed BaseApp")
Expand Down
Loading

0 comments on commit 7ccb8b4

Please sign in to comment.