-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into cal/nonce-handling
- Loading branch information
Showing
43 changed files
with
1,056 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ jobs: | |
permissions: | ||
contents: write | ||
packages: write | ||
uses: celestiaorg/.github/.github/workflows/[email protected].2 | ||
uses: celestiaorg/.github/.github/workflows/[email protected].3 | ||
with: | ||
dockerfile: Dockerfile | ||
secrets: inherit | ||
|
@@ -29,7 +29,7 @@ jobs: | |
permissions: | ||
contents: write | ||
packages: write | ||
uses: celestiaorg/.github/.github/workflows/[email protected].2 | ||
uses: celestiaorg/.github/.github/workflows/[email protected].3 | ||
with: | ||
dockerfile: docker/Dockerfile_txsim | ||
packageName: txsim | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,10 +29,10 @@ jobs: | |
|
||
# hadolint lints the Dockerfile | ||
hadolint: | ||
uses: celestiaorg/.github/.github/workflows/[email protected].2 | ||
uses: celestiaorg/.github/.github/workflows/[email protected].3 | ||
|
||
yamllint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: celestiaorg/.github/.github/actions/[email protected].2 | ||
- uses: celestiaorg/.github/.github/actions/[email protected].3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ on: | |
jobs: | ||
auto-request-review: | ||
name: Auto request reviews | ||
uses: celestiaorg/.github/.github/workflows/[email protected].2 | ||
uses: celestiaorg/.github/.github/workflows/[email protected].3 | ||
secrets: inherit | ||
# write access for issues and pull requests is needed because the called | ||
# workflow requires write access to issues and pull requests and the | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package ante | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
var ( | ||
_ sdk.AnteDecorator = MsgVersioningGateKeeper{} | ||
_ baseapp.CircuitBreaker = MsgVersioningGateKeeper{} | ||
) | ||
|
||
// MsgVersioningGateKeeper dictates which transactions are accepted for an app version | ||
type MsgVersioningGateKeeper struct { | ||
// acceptedMsgs is a map from appVersion -> msgTypeURL -> struct{}. | ||
// If a msgTypeURL is present in the map it should be accepted for that appVersion. | ||
acceptedMsgs map[uint64]map[string]struct{} | ||
} | ||
|
||
func NewMsgVersioningGateKeeper(acceptedList map[uint64]map[string]struct{}) *MsgVersioningGateKeeper { | ||
return &MsgVersioningGateKeeper{ | ||
acceptedMsgs: acceptedList, | ||
} | ||
} | ||
|
||
// AnteHandle implements the ante.Decorator interface | ||
func (mgk MsgVersioningGateKeeper) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { | ||
acceptedMsgs, exists := mgk.acceptedMsgs[ctx.BlockHeader().Version.App] | ||
if !exists { | ||
return ctx, sdkerrors.ErrNotSupported.Wrapf("app version %d is not supported", ctx.BlockHeader().Version.App) | ||
} | ||
for _, msg := range tx.GetMsgs() { | ||
msgTypeURL := sdk.MsgTypeURL(msg) | ||
_, exists := acceptedMsgs[msgTypeURL] | ||
if !exists { | ||
return ctx, sdkerrors.ErrNotSupported.Wrapf("message type %s is not supported in version %d", msgTypeURL, ctx.BlockHeader().Version.App) | ||
} | ||
} | ||
|
||
return next(ctx, tx, simulate) | ||
} | ||
|
||
func (mgk MsgVersioningGateKeeper) IsAllowed(ctx context.Context, msgName string) (bool, error) { | ||
appVersion := sdk.UnwrapSDKContext(ctx).BlockHeader().Version.App | ||
acceptedMsgs, exists := mgk.acceptedMsgs[appVersion] | ||
if !exists { | ||
return false, sdkerrors.ErrNotSupported.Wrapf("app version %d is not supported", appVersion) | ||
} | ||
_, exists = acceptedMsgs[msgName] | ||
if !exists { | ||
return false, nil | ||
} | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package ante_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/celestiaorg/celestia-app/app" | ||
"github.com/celestiaorg/celestia-app/app/ante" | ||
"github.com/celestiaorg/celestia-app/app/encoding" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
"github.com/stretchr/testify/require" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
version "github.com/tendermint/tendermint/proto/tendermint/version" | ||
) | ||
|
||
func TestMsgGateKeeperAnteHandler(t *testing.T) { | ||
// Define test cases | ||
tests := []struct { | ||
name string | ||
msg sdk.Msg | ||
acceptMsg bool | ||
version uint64 | ||
}{ | ||
{ | ||
name: "Accept MsgSend", | ||
msg: &banktypes.MsgSend{}, | ||
acceptMsg: true, | ||
version: 1, | ||
}, | ||
{ | ||
name: "Reject MsgMultiSend", | ||
msg: &banktypes.MsgMultiSend{}, | ||
acceptMsg: false, | ||
version: 1, | ||
}, | ||
{ | ||
name: "Reject MsgSend with version 2", | ||
msg: &banktypes.MsgSend{}, | ||
acceptMsg: false, | ||
version: 2, | ||
}, | ||
} | ||
|
||
msgGateKeeper := ante.NewMsgVersioningGateKeeper(map[uint64]map[string]struct{}{ | ||
1: { | ||
"/cosmos.bank.v1beta1.MsgSend": {}, | ||
}, | ||
2: {}, | ||
}) | ||
cdc := encoding.MakeConfig(app.ModuleEncodingRegisters...) | ||
anteHandler := sdk.ChainAnteDecorators(msgGateKeeper) | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
ctx := sdk.NewContext(nil, tmproto.Header{Version: version.Consensus{App: tc.version}}, false, nil) | ||
txBuilder := cdc.TxConfig.NewTxBuilder() | ||
require.NoError(t, txBuilder.SetMsgs(tc.msg)) | ||
_, err := anteHandler(ctx, txBuilder.GetTx(), false) | ||
allowed, err2 := msgGateKeeper.IsAllowed(ctx, sdk.MsgTypeURL(tc.msg)) | ||
require.NoError(t, err2) | ||
if tc.acceptMsg { | ||
require.NoError(t, err, "expected message to be accepted") | ||
require.True(t, allowed) | ||
} else { | ||
require.Error(t, err, "expected message to be rejected") | ||
require.False(t, allowed) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.