Skip to content

Commit

Permalink
feat!: implement FillSquare method for the testnode (#866)
Browse files Browse the repository at this point in the history
This PR 
- adds a modified FillSquare method for the testnode that only submits a
single large message
- modifies the default configs for a testnode's mempool to accept large
transactions
- modifies the `PostData` method to accept a flag that determines if the
process blocks

The issue with the old approach was that it was submitting too many
transactions for a block with such short block times. The testnode was
unlikely to get all of the transactions included in a single block,
particularly when waiting to submit each transaction until the previous
one was accepted into the mempool.

Co-authored-by: CHAMI Rachid <chamirachid1@gmail.com>
Co-authored-by: Rootul P <rootulp@gmail.com>
  • Loading branch information
3 people committed Oct 13, 2022
1 parent 108d772 commit c9dce39
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
3 changes: 2 additions & 1 deletion testutil/testnode/full_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func DefaultParams() *tmproto.ConsensusParams {

func DefaultTendermintConfig() *config.Config {
tmCfg := config.DefaultConfig()
tmCfg.Consensus.TimeoutCommit = time.Millisecond * 70
tmCfg.Consensus.TimeoutCommit = time.Millisecond * 100
tmCfg.Mempool.MaxTxBytes = 22020096 // 21MB
return tmCfg
}
26 changes: 25 additions & 1 deletion testutil/testnode/full_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import (
"context"
"testing"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/testutil"
"github.com/celestiaorg/celestia-app/testutil/namespace"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
)
Expand Down Expand Up @@ -75,10 +79,30 @@ func (s *IntegrationTestSuite) Test_Liveness() {

func (s *IntegrationTestSuite) Test_PostData() {
require := s.Require()
_, err := s.cctx.PostData(s.accounts[0], namespace.RandomMessageNamespace(), tmrand.Bytes(100000))
_, err := s.cctx.PostData(s.accounts[0], flags.BroadcastBlock, namespace.RandomMessageNamespace(), tmrand.Bytes(100000))
require.NoError(err)
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}

func (s *IntegrationTestSuite) Test_FillBlock() {
require := s.Require()

for squareSize := 2; squareSize < appconsts.MaxSquareSize; squareSize *= 2 {
resp, err := s.cctx.FillBlock(squareSize, s.accounts, flags.BroadcastAsync)
require.NoError(err)

err = s.cctx.WaitForNextBlock()
require.NoError(err)

res, err := testutil.QueryWithOutProof(s.cctx.Context, resp.TxHash)
require.NoError(err)
require.Equal(abci.CodeTypeOK, res.TxResult.Code)

b, err := s.cctx.Client.Block(context.TODO(), &res.Height)
require.NoError(err)
require.Equal(uint64(squareSize), b.Block.OriginalSquareSize)
}
}
43 changes: 39 additions & 4 deletions testutil/testnode/node_interaction_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import (
"fmt"
"time"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/testutil/namespace"
"github.com/celestiaorg/celestia-app/x/payment"
"github.com/celestiaorg/celestia-app/x/payment/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
)

type Context struct {
Expand Down Expand Up @@ -86,7 +90,7 @@ func (c *Context) WaitForNextBlock() error {
// namespace. This function blocks until the PFD has been included in a block
// and returns an error if the transaction is invalid or is rejected by the
// mempool.
func (c *Context) PostData(account string, ns, msg []byte) (*sdk.TxResponse, error) {
func (c *Context) PostData(account, broadcastMode string, ns, msg []byte) (*sdk.TxResponse, error) {
opts := []types.TxBuilderOption{
types.SetGasLimit(100000000000000),
}
Expand Down Expand Up @@ -130,14 +134,45 @@ func (c *Context) PostData(account string, ns, msg []byte) (*sdk.TxResponse, err
if err != nil {
return nil, err
}

res, err := c.BroadcastTxCommit(rawTx)
var res *sdk.TxResponse
switch broadcastMode {
case flags.BroadcastSync:
res, err = c.BroadcastTxSync(rawTx)
case flags.BroadcastAsync:
res, err = c.BroadcastTxAsync(rawTx)
case flags.BroadcastBlock:
res, err = c.BroadcastTxCommit(rawTx)
default:
return nil, fmt.Errorf("unsupported broadcast mode %s; supported modes: sync, async, block", c.BroadcastMode)
}
if err != nil {
return nil, err
}
if res.Code != abci.CodeTypeOK {
return nil, fmt.Errorf("failure to broadcast tx sync: %s", res.RawLog)
return res, fmt.Errorf("failure to broadcast tx sync: %s", res.RawLog)
}

return res, nil
}

// FillBlock creates and submits a single transaction that is large enough to
// create a square of the desired size. broadcast mode indicates if the tx
// should be submitted async, sync, or block. (see flags.BroadcastModeSync). If
// broadcast mode is the string zero value, then it will be set to block. This
// function does not perform checks on the passed squaresize arg, and only works
// with squaresize >= 2. TODO: perform checks (is a power of 2 and is > 2) on
// the passed squaresize arg
func (c *Context) FillBlock(squareSize int, accounts []string, broadcastMode string) (*sdk.TxResponse, error) {
if broadcastMode == "" {
broadcastMode = flags.BroadcastBlock
}
maxShareCount := squareSize * squareSize
// we use a formula to guarantee that the tx is the exact size needed to force a specific square size.
msgSize := (maxShareCount - (2 * squareSize)) * appconsts.SparseShareContentSize
// this last patch allows for the formula above to work on a square size of
// 2.
if msgSize < 1 {
msgSize = 1
}
return c.PostData(accounts[0], broadcastMode, namespace.RandomMessageNamespace(), tmrand.Bytes(msgSize))
}

0 comments on commit c9dce39

Please sign in to comment.