Skip to content

Commit

Permalink
fix!: Dev/backport dragonberry (#374)
Browse files Browse the repository at this point in the history
* Add dragonberry changes

* Revert "chore(backport): Simulation is not deterministic due to GenTx (backport #356) (#362)"

This reverts commit f075384.

* fix liveness test

* Update
  • Loading branch information
ValarDragon authored Oct 27, 2022
1 parent f075384 commit 0439713
Show file tree
Hide file tree
Showing 35 changed files with 7,973 additions and 765 deletions.
47 changes: 0 additions & 47 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,6 @@ func (app *BaseApp) SetOption(req abci.RequestSetOption) (res abci.ResponseSetOp
return
}

// FilterPeerByAddrPort filters peers by address/port.
func (app *BaseApp) FilterPeerByAddrPort(info string) abci.ResponseQuery {
if app.addrPeerFilter != nil {
return app.addrPeerFilter(info)
}

return abci.ResponseQuery{}
}

// FilterPeerByID filters peers by node ID.
func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery {
if app.idPeerFilter != nil {
return app.idPeerFilter(info)
}

return abci.ResponseQuery{}
}

// BeginBlock implements the ABCI application interface.
func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
defer telemetry.MeasureSince(time.Now(), "abci", "begin_block")
Expand Down Expand Up @@ -829,35 +811,6 @@ func handleQueryStore(app *BaseApp, path []string, req abci.RequestQuery) abci.R
return resp
}

func handleQueryP2P(app *BaseApp, path []string) abci.ResponseQuery {
// "/p2p" prefix for p2p queries
if len(path) < 4 {
return sdkerrors.QueryResultWithDebug(
sdkerrors.Wrap(
sdkerrors.ErrUnknownRequest, "path should be p2p filter <addr|id> <parameter>",
), app.trace)
}

var resp abci.ResponseQuery

cmd, typ, arg := path[1], path[2], path[3]
switch cmd {
case "filter":
switch typ {
case "addr":
resp = app.FilterPeerByAddrPort(arg)

case "id":
resp = app.FilterPeerByID(arg)
}

default:
resp = sdkerrors.QueryResultWithDebug(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "expected second parameter to be 'filter'"), app.trace)
}

return resp
}

func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) abci.ResponseQuery {
// path[0] should be "custom" because "/custom" prefix is required for keeper
// queries.
Expand Down
38 changes: 38 additions & 0 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package baseapp

import (
"encoding/json"
"fmt"
"testing"

Expand Down Expand Up @@ -147,3 +148,40 @@ func TestBaseAppCreateQueryContextRejectsNegativeHeights(t *testing.T) {
})
}
}

type paramStore struct {
db *dbm.MemDB
}

func (ps *paramStore) Set(_ sdk.Context, key []byte, value interface{}) {
bz, err := json.Marshal(value)
if err != nil {
panic(err)
}

ps.db.Set(key, bz)
}

func (ps *paramStore) Has(_ sdk.Context, key []byte) bool {
ok, err := ps.db.Has(key)
if err != nil {
panic(err)
}

return ok
}

func (ps *paramStore) Get(_ sdk.Context, key []byte, ptr interface{}) {
bz, err := ps.db.Get(key)
if err != nil {
panic(err)
}

if len(bz) == 0 {
return
}

if err := json.Unmarshal(bz, ptr); err != nil {
panic(err)
}
}
45 changes: 45 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,51 @@ type BaseApp struct { // nolint: maligned

var _ upgrade.AppVersionManager = (*BaseApp)(nil)

type appStore struct {
db dbm.DB // common DB backend
cms sdk.CommitMultiStore // Main (uncached) state
storeLoader StoreLoader // function to handle store loading, may be overridden with SetStoreLoader()

// an inter-block write-through cache provided to the context during deliverState
interBlockCache sdk.MultiStorePersistentCache

fauxMerkleMode bool // if true, IAVL MountStores uses MountStoresDB for simulation speed.
}

type moduleRouter struct {
router sdk.Router // handle any kind of message
queryRouter sdk.QueryRouter // router for redirecting query calls
grpcQueryRouter *GRPCQueryRouter // router for redirecting gRPC query calls
msgServiceRouter *MsgServiceRouter // router for redirecting Msg service messages
}

type abciData struct {
initChainer sdk.InitChainer // initialize state with validators and state blob
beginBlocker sdk.BeginBlocker // logic to run before any txs
endBlocker sdk.EndBlocker // logic to run after all txs, and to determine valset changes

// absent validators from begin block
voteInfos []abci.VoteInfo
}

type baseappVersions struct {
// application's version string
version string

// application's protocol version that increments on every upgrade
// if BaseApp is passed to the upgrade keeper's NewKeeper method.
appVersion uint64
}

// should really get handled in some db struct
// which then has a sub-item, persistence fields
type snapshotData struct {
// manages snapshots, i.e. dumps of app state at certain intervals
snapshotManager *snapshots.Manager
snapshotInterval uint64 // block interval between state sync snapshots
snapshotKeepRecent uint32 // recent state sync snapshots to keep
}

// 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 Down
29 changes: 29 additions & 0 deletions baseapp/msg_service_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler inter
goCtx = context.WithValue(goCtx, sdk.SdkContextKey, ctx)
return handler(goCtx, req)
}
if err := req.ValidateBasic(); err != nil {
if mm, ok := req.(getter1); ok {
if !mm.GetAmount().Amount.IsZero() {
return nil, err
}
} else if mm, ok := req.(getter2); ok {
if !mm.GetTokenIn().Amount.IsZero() {
return nil, err
}
} else if mm, ok := req.(getter3); ok {
if !mm.GetTokenOut().Amount.IsZero() {
return nil, err
}
} else {
return nil, err
}
}
// Call the method handler from the service description with the handler object.
// We don't do any decoding here because the decoding was already done.
res, err := methodHandler(handler, sdk.WrapSDKContext(ctx), noopDecoder, interceptor)
Expand All @@ -138,3 +155,15 @@ func noopDecoder(_ interface{}) error { return nil }
func noopInterceptor(_ context.Context, _ interface{}, _ *grpc.UnaryServerInfo, _ grpc.UnaryHandler) (interface{}, error) {
return nil, nil
}

type getter1 interface {
GetAmount() sdk.Coin
}

type getter2 interface {
GetTokenIn() sdk.Coin
}

type getter3 interface {
GetTokenOut() sdk.Coin
}
54 changes: 54 additions & 0 deletions baseapp/p2p.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package baseapp

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
abci "github.com/tendermint/tendermint/abci/types"
)

func handleQueryP2P(app *BaseApp, path []string) abci.ResponseQuery {
// "/p2p" prefix for p2p queries
if len(path) < 4 {
return sdkerrors.QueryResult(
sdkerrors.Wrap(
sdkerrors.ErrUnknownRequest, "path should be p2p filter <addr|id> <parameter>",
),
)
}

var resp abci.ResponseQuery

cmd, typ, arg := path[1], path[2], path[3]
switch cmd {
case "filter":
switch typ {
case "addr":
resp = app.FilterPeerByAddrPort(arg)

case "id":
resp = app.FilterPeerByID(arg)
}

default:
resp = sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "expected second parameter to be 'filter'"))
}

return resp
}

// FilterPeerByAddrPort filters peers by address/port.
func (app *BaseApp) FilterPeerByAddrPort(info string) abci.ResponseQuery {
if app.addrPeerFilter != nil {
return app.addrPeerFilter(info)
}

return abci.ResponseQuery{}
}

// FilterPeerByID filters peers by node ID.
func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery {
if app.idPeerFilter != nil {
return app.idPeerFilter(info)
}

return abci.ResponseQuery{}
}
60 changes: 60 additions & 0 deletions baseapp/testutil/messages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package testutil

import (
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/msgservice"
)

func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgCounter{},
&MsgCounter2{},
&MsgKeyValue{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Counter_serviceDesc)
msgservice.RegisterMsgServiceDesc(registry, &_Counter2_serviceDesc)
msgservice.RegisterMsgServiceDesc(registry, &_KeyValue_serviceDesc)
}

var _ sdk.Msg = &MsgCounter{}

func (msg *MsgCounter) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{} }
func (msg *MsgCounter) ValidateBasic() error {
if msg.Counter >= 0 {
return nil
}
return sdkerrors.Wrap(sdkerrors.ErrInvalidSequence, "counter should be a non-negative integer")
}

var _ sdk.Msg = &MsgCounter2{}

func (msg *MsgCounter2) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{} }
func (msg *MsgCounter2) ValidateBasic() error {
if msg.Counter >= 0 {
return nil
}
return sdkerrors.Wrap(sdkerrors.ErrInvalidSequence, "counter should be a non-negative integer")
}

var _ sdk.Msg = &MsgKeyValue{}

func (msg *MsgKeyValue) GetSigners() []sdk.AccAddress {
if msg.Signer == "" {
return []sdk.AccAddress{}
}

return []sdk.AccAddress{sdk.MustAccAddressFromBech32(msg.Signer)}
}

func (msg *MsgKeyValue) ValidateBasic() error {
if msg.Key == nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "key cannot be nil")
}
if msg.Value == nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "value cannot be nil")
}
return nil
}
Loading

0 comments on commit 0439713

Please sign in to comment.