Skip to content

Commit

Permalink
Merge pull request #6419 from filecoin-project/feat/increase-msg-limit
Browse files Browse the repository at this point in the history
Increase message size limit
  • Loading branch information
magik6k authored Jun 8, 2021
2 parents c98b6f6 + 39bab14 commit 227932f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
4 changes: 3 additions & 1 deletion chain/messagepool/messagepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ var MaxUntrustedActorPendingMessages = 10

var MaxNonceGap = uint64(4)

const MaxMessageSize = 64 << 10 // 64KiB

var (
ErrMessageTooBig = errors.New("message too big")

Expand Down Expand Up @@ -665,7 +667,7 @@ func (mp *MessagePool) Push(ctx context.Context, m *types.SignedMessage) (cid.Ci

func (mp *MessagePool) checkMessage(m *types.SignedMessage) error {
// big messages are bad, anti DOS
if m.Size() > 32*1024 {
if m.Size() > MaxMessageSize {
return xerrors.Errorf("mpool message too large (%dB): %w", m.Size(), ErrMessageTooBig)
}

Expand Down
68 changes: 68 additions & 0 deletions chain/messagepool/messagepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import (

builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"

"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/messagepool/gasguess"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/types/mock"
"github.com/filecoin-project/lotus/chain/wallet"
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
"github.com/stretchr/testify/assert"
)

func init() {
Expand Down Expand Up @@ -260,6 +262,72 @@ func TestMessagePool(t *testing.T) {
assertNonce(t, mp, sender, 2)
}

func TestCheckMessageBig(t *testing.T) {
tma := newTestMpoolAPI()

w, err := wallet.NewWallet(wallet.NewMemKeyStore())
assert.NoError(t, err)

from, err := w.WalletNew(context.Background(), types.KTBLS)
assert.NoError(t, err)

tma.setBalance(from, 1000e9)

ds := datastore.NewMapDatastore()

mp, err := New(tma, ds, "mptest", nil)
assert.NoError(t, err)

to := mock.Address(1001)

{
msg := &types.Message{
To: to,
From: from,
Value: types.NewInt(1),
Nonce: 0,
GasLimit: 50000000,
GasFeeCap: types.NewInt(100),
GasPremium: types.NewInt(1),
Params: make([]byte, 41<<10), // 41KiB payload
}

sig, err := w.WalletSign(context.TODO(), from, msg.Cid().Bytes(), api.MsgMeta{})
if err != nil {
panic(err)
}
sm := &types.SignedMessage{
Message: *msg,
Signature: *sig,
}
mustAdd(t, mp, sm)
}

{
msg := &types.Message{
To: to,
From: from,
Value: types.NewInt(1),
Nonce: 0,
GasLimit: 50000000,
GasFeeCap: types.NewInt(100),
GasPremium: types.NewInt(1),
Params: make([]byte, 64<<10), // 64KiB payload
}

sig, err := w.WalletSign(context.TODO(), from, msg.Cid().Bytes(), api.MsgMeta{})
if err != nil {
panic(err)
}
sm := &types.SignedMessage{
Message: *msg,
Signature: *sig,
}
err = mp.Add(context.TODO(), sm)
assert.ErrorIs(t, err, ErrMessageTooBig)
}
}

func TestMessagePoolMessagesInEachBlock(t *testing.T) {
tma := newTestMpoolAPI()

Expand Down

0 comments on commit 227932f

Please sign in to comment.