Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: backport for rc7 #2024

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/prepare_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
// create a context using a branch of the state and loaded using the
// proposal height and chain-id
sdkCtx := app.NewProposalContext(core.Header{ChainID: app.GetChainID(), Height: app.LastBlockHeight() + 1})
sdkCtx := app.NewProposalContext(core.Header{ChainID: req.ChainId, Height: app.LastBlockHeight() + 1})
// filter out invalid transactions.
// TODO: we can remove all state independent checks from the ante handler here such as signature verification
// and only check the state dependent checks like fees and nonces as all these transactions have already
Expand Down
2 changes: 1 addition & 1 deletion app/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp
ante.DefaultSigVerificationGasConsumer,
app.IBCKeeper,
)
sdkCtx := app.NewProposalContext(req.Header).WithChainID(app.GetChainID())
sdkCtx := app.NewProposalContext(req.Header)

// iterate over all txs and ensure that all blobTxs are valid, PFBs are correctly signed and non
// blobTxs have no PFBs present
Expand Down
9 changes: 5 additions & 4 deletions app/test/fuzz_abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/test/util"
testutil "github.com/celestiaorg/celestia-app/test/util"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
Expand Down Expand Up @@ -82,14 +82,14 @@ func TestPrepareProposalConsistency(t *testing.T) {
cparams := app.DefaultConsensusParams()
cparams.Block.MaxBytes = size.maxBytes

testApp, kr := util.SetupTestAppWithGenesisValSet(cparams, accounts...)
testApp, kr := testutil.SetupTestAppWithGenesisValSet(cparams, accounts...)

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// repeat the test multiple times with random data each
// iteration.
for i := 0; i < tt.iterations; i++ {
txs := util.RandBlobTxsWithAccounts(
txs := testutil.RandBlobTxsWithAccounts(
t,
testApp,
encConf.TxConfig.TxEncoder(),
Expand All @@ -101,7 +101,7 @@ func TestPrepareProposalConsistency(t *testing.T) {
accounts[:tt.count],
)
// create 100 send transactions
sendTxs := util.SendTxsWithAccounts(
sendTxs := testutil.SendTxsWithAccounts(
t,
testApp,
encConf.TxConfig.TxEncoder(),
Expand All @@ -116,6 +116,7 @@ func TestPrepareProposalConsistency(t *testing.T) {
BlockData: &core.Data{
Txs: coretypes.Txs(txs).ToSliceOfBytes(),
},
ChainId: testutil.ChainID,
})

// check that the square size is smaller than or equal to
Expand Down
2 changes: 2 additions & 0 deletions app/test/prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestPrepareProposalPutsPFBsAtEnd(t *testing.T) {
BlockData: &tmproto.Data{
Txs: txs,
},
ChainId: testutil.ChainID,
})
require.Len(t, resp.BlockData.Txs, numBlobTxs+numNormalTxs)
for idx, txBytes := range resp.BlockData.Txs {
Expand Down Expand Up @@ -183,6 +184,7 @@ func TestPrepareProposalFiltering(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
resp := testApp.PrepareProposal(abci.RequestPrepareProposal{
BlockData: &tmproto.Data{Txs: tt.txs()},
ChainId: testutil.ChainID,
})
// check that we have the expected number of transactions
require.Equal(t, len(tt.txs())-len(tt.prunedTxs), len(resp.BlockData.Txs))
Expand Down
2 changes: 2 additions & 0 deletions app/test/process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ func TestProcessProposal(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
resp := testApp.PrepareProposal(abci.RequestPrepareProposal{
BlockData: tt.input,
ChainId: testutil.ChainID,
})
require.Equal(t, len(tt.input.Txs), len(resp.BlockData.Txs))
tt.mutator(resp.BlockData)
Expand All @@ -309,6 +310,7 @@ func TestProcessProposal(t *testing.T) {
Header: tmproto.Header{
Height: 1,
DataHash: resp.BlockData.Hash,
ChainID: testutil.ChainID,
},
})
assert.Equal(t, tt.expectedResult, res.Result, fmt.Sprintf("expected %v, got %v", tt.expectedResult, res.Result))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,5 @@ replace (
github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.15.0-sdk-v0.46.13
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.22.0-tm-v0.34.28
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.23.0-tm-v0.34.28
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ github.com/bufbuild/protocompile v0.1.0 h1:HjgJBI85hY/qmW5tw/66sNDZ7z0UDdVSi/5r4
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34=
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/celestiaorg/celestia-core v1.22.0-tm-v0.34.28 h1:idHJK9i4WCkYOf5PXVWZbOs8pWkCiHHQGI4MZr0iMtQ=
github.com/celestiaorg/celestia-core v1.22.0-tm-v0.34.28/go.mod h1:LOxHW9nA++/9U8TgvTyKo9TO3F09sWv8asKQs00m73U=
github.com/celestiaorg/celestia-core v1.23.0-tm-v0.34.28 h1:G7/rq6xTnuFf3XsVZEcl/Sa6vtagm9NQNhaUaSgjvy0=
github.com/celestiaorg/celestia-core v1.23.0-tm-v0.34.28/go.mod h1:J/GsBjoTZaFz71VeyrLZbG8rV+Rzi6oFEUZUipQ97hQ=
github.com/celestiaorg/cosmos-sdk v1.15.0-sdk-v0.46.13 h1:vaQKgaOm0w58JAvOgn2iDohqjH7kvvRqVKiMcBDWifA=
github.com/celestiaorg/cosmos-sdk v1.15.0-sdk-v0.46.13/go.mod h1:G9XkhOJZde36FH0kt/1ayg4ZaioZEQmmRfMa/zQig0I=
github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 h1:CJdIpo8n5MFP2MwK0gSRcOVlDlFdQJO1p+FqdxYzmvc=
Expand Down
5 changes: 2 additions & 3 deletions pkg/shares/parse_sparse_shares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package shares
import (
"bytes"
"fmt"
"sort"
"testing"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
Expand Down Expand Up @@ -59,7 +58,7 @@ func Test_parseSparseShares(t *testing.T) {
blobs[i] = testfactory.GenerateRandomBlob(tc.blobSize)
}

sort.Sort(coretypes.BlobsByNamespace(blobs))
blobs = testfactory.SortBlobs(blobs)

shares, err := SplitBlobs(blobs...)
require.NoError(t, err)
Expand Down Expand Up @@ -135,7 +134,7 @@ func Test_parseSparseSharesWithNamespacedPadding(t *testing.T) {
randomSmallBlob,
randomLargeBlob,
}
sort.Sort(coretypes.BlobsByNamespace(blobs))
blobs = testfactory.SortBlobs(blobs)

err := sss.Write(blobs[0])
require.NoError(t, err)
Expand Down
9 changes: 7 additions & 2 deletions test/util/testfactory/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ func GenerateRandomlySizedBlobs(count, maxBlobSize int) []types.Blob {
blobs = nil
}

sort.Sort(types.BlobsByNamespace(blobs))
blobs = SortBlobs(blobs)
return blobs
}

// GenerateBlobsWithNamespace generates blobs with namespace ns.
func GenerateBlobsWithNamespace(count int, blobSize int, ns appns.Namespace) types.BlobsByNamespace {
func GenerateBlobsWithNamespace(count int, blobSize int, ns appns.Namespace) []types.Blob {
blobs := make([]types.Blob, count)
for i := 0; i < count; i++ {
blobs[i] = types.Blob{
Expand Down Expand Up @@ -78,3 +78,8 @@ func DelimLen(size uint64) int {
lenBuf := make([]byte, binary.MaxVarintLen64)
return binary.PutUvarint(lenBuf, size)
}

func SortBlobs(blobs []types.Blob) []types.Blob {
sort.Slice(blobs, func(i, j int) bool { return bytes.Compare(blobs[i].NamespaceID, blobs[j].NamespaceID) < 0 })
return blobs
}