Skip to content

Commit

Permalink
Merge branch 'main' into sanaz/block-height-check-prepareproposal
Browse files Browse the repository at this point in the history
  • Loading branch information
staheri14 committed Aug 9, 2023
2 parents cd4686e + b70048b commit f522b3f
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pull_request_rules:
- name: backport patches to v1.x branch
conditions:
- base=main
- label=S:backport:v1.x
- label=backport:v1.x
actions:
backport:
branches:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docker-build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ jobs:
uses: celestiaorg/.github/.github/workflows/[email protected]
with:
dockerfile: docker/Dockerfile_txsim
packageName: txsim
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions app/errors/nonce_mismatch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package errors

import (
"errors"
"fmt"
"strconv"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// IsNonceMismatch checks if the error is due to a sequence mismatch.
func IsNonceMismatch(err error) bool {
return errors.Is(err, sdkerrors.ErrWrongSequence)
}

// ParseNonceMismatch extracts the expected sequence number from the
// ErrWrongSequence error.
func ParseNonceMismatch(err error) (uint64, error) {
if !IsNonceMismatch(err) {
return 0, errors.New("error is not a sequence mismatch")
}

numbers := regexpInt.FindAllString(err.Error(), -1)
if len(numbers) != 2 {
return 0, fmt.Errorf("unexpected wrong sequence error: %w", err)
}

// the first number is the expected sequence number
return strconv.ParseUint(numbers[0], 10, 64)
}
56 changes: 56 additions & 0 deletions app/errors/nonce_mismatch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package errors_test

import (
"fmt"
"testing"

"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
apperr "github.com/celestiaorg/celestia-app/app/errors"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/namespace"
testutil "github.com/celestiaorg/celestia-app/test/util"
blob "github.com/celestiaorg/celestia-app/x/blob/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

// This will detect any changes to the DeductFeeDecorator which may cause a
// different error message that does not match the regexp.
func TestNonceMismatchIntegration(t *testing.T) {
account := "test"
testApp, kr := testutil.SetupTestAppWithGenesisValSet(app.DefaultConsensusParams(), account)
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
minGasPrice, err := sdk.ParseDecCoins(fmt.Sprintf("%v%s", appconsts.DefaultMinGasPrice, app.BondDenom))
require.NoError(t, err)
ctx := testApp.NewContext(true, tmproto.Header{}).WithMinGasPrices(minGasPrice)
signer := blob.NewKeyringSigner(kr, account, testutil.ChainID)
// set the sequence to an incorrect value
signer.SetSequence(2)
builder := signer.NewTxBuilder()

address, err := signer.GetSignerInfo().GetAddress()
require.NoError(t, err)

b, err := blob.NewBlob(namespace.RandomNamespace(), []byte("hello world"), 0)
require.NoError(t, err)

pfb, err := blob.NewMsgPayForBlobs(address.String(), b)
require.NoError(t, err, address)

tx, err := signer.BuildSignedTx(builder, pfb)
require.NoError(t, err)

decorator := ante.NewSigVerificationDecorator(testApp.AccountKeeper, encCfg.TxConfig.SignModeHandler())
anteHandler := sdk.ChainAnteDecorators(decorator)

// We set simulate to true here to bypass having to initialize the
// accounts public key.
_, err = anteHandler(ctx, tx, true)
require.True(t, apperr.IsNonceMismatch(err), err)
expectedNonce, err := apperr.ParseNonceMismatch(err)
require.NoError(t, err)
require.EqualValues(t, 0, expectedNonce, err)
}
8 changes: 4 additions & 4 deletions app/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,23 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() {
}

// Tendermint's default tx size limit is 1 MiB, so we get close to that by
// generating transactions of size 600 KiB because 3 blobs per transaction *
// 200,000 bytes each = 600,000 total bytes = 600 KiB per transaction.
// generating transactions of size 600 KB because 3 blobs per transaction *
// 200,000 bytes each = 600,000 total bytes = 600 KB per transaction.
randMultiBlob1MbTxGen := func(c client.Context) []coretypes.Tx {
return blobfactory.RandBlobTxsWithAccounts(
s.ecfg.TxConfig.TxEncoder(),
tmrand.NewRand(),
s.cctx.Keyring,
c.GRPCClient,
200000, // 200 KiB
200000, // 200 KB
3,
false,
s.cctx.ChainID,
s.accounts[20:40],
)
}

// Generate 80 randomly sized txs (max size == 50 KiB). Generate these
// Generate 80 randomly sized txs (max size == 50 KB). Generate these
// transactions using some of the same accounts as the previous generator to
// ensure that the sequence number is being utilized correctly in blob
// txs
Expand Down
5 changes: 3 additions & 2 deletions test/txsim/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package txsim
import (
"context"
"fmt"
"math"
"strings"
"sync"

Expand Down Expand Up @@ -183,9 +184,9 @@ func (am *AccountManager) Submit(ctx context.Context, op Operation) error {
} else {
builder.SetGasLimit(op.GasLimit)
if op.GasPrice > 0 {
builder.SetFeeAmount(types.NewCoins(types.NewInt64Coin(app.BondDenom, int64(float64(op.GasLimit)*op.GasPrice))))
builder.SetFeeAmount(types.NewCoins(types.NewInt64Coin(app.BondDenom, int64(math.Ceil(float64(op.GasLimit)*op.GasPrice)))))
} else {
builder.SetFeeAmount(types.NewCoins(types.NewInt64Coin(app.BondDenom, int64(float64(op.GasLimit)*appconsts.DefaultMinGasPrice))))
builder.SetFeeAmount(types.NewCoins(types.NewInt64Coin(app.BondDenom, int64(math.Ceil(float64(op.GasLimit)*appconsts.DefaultMinGasPrice)))))
}
}

Expand Down

0 comments on commit f522b3f

Please sign in to comment.