Skip to content

Commit

Permalink
Merge pull request #376 from ipfs-force-community/fix/check-gas-limit
Browse files Browse the repository at this point in the history
fix: check gas limit
  • Loading branch information
simlecode authored Jan 31, 2024
2 parents 9c61238 + d694974 commit 1d54235
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions service/message_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"go.uber.org/zap"
"modernc.org/mathutil"

"github.com/filecoin-project/venus/pkg/constants"
"github.com/filecoin-project/venus/pkg/crypto"
"github.com/filecoin-project/venus/venus-shared/actors/builtin"
v1 "github.com/filecoin-project/venus/venus-shared/api/chain/v1"
Expand Down Expand Up @@ -407,6 +408,14 @@ func (w *work) selectMessage(ctx context.Context, appliedNonce *utils.NonceMap,
break
}

// 检查 gaslimit 是否超出上限
if estimateMsg.GasLimit > constants.BlockGasLimit {
err := fmt.Sprintf("%s gas limit %d over limit %d", gasEstimate, estimateMsg.GasLimit, constants.BlockGasLimit)
errMsg = append(errMsg, msgErrInfo{id: msg.ID, err: err})
w.log.Errorf(err)
continue
}

// 分配nonce
msg.Nonce = addrInfo.Nonce
msg.GasFeeCap = estimateMsg.GasFeeCap
Expand Down
35 changes: 35 additions & 0 deletions service/message_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ipfs-force-community/sophon-messager/models/repo"
"github.com/ipfs-force-community/sophon-messager/testhelper"

"github.com/filecoin-project/venus/pkg/constants"
"github.com/filecoin-project/venus/venus-shared/testutil"
shared "github.com/filecoin-project/venus/venus-shared/types"
types "github.com/filecoin-project/venus/venus-shared/types/messager"
Expand Down Expand Up @@ -532,6 +533,40 @@ func TestErrorMsg(t *testing.T) {
}
}

func TestGasLimitOverLimit(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

msh := newMessageServiceHelper(ctx, t, skipPushMessage())
addrs := msh.genAddresses()
ms := msh.MessageService
msh.start()
defer msh.stop()

msgs := genMessages(addrs, len(addrs)*10)
for _, msg := range msgs {
// will estimate gas failed
msg.GasLimit = constants.BlockGasLimit + 10
}
assert.NoError(t, pushMessage(ctx, ms, msgs))
msgsMap := testhelper.SliceToMap(msgs)

ts, err := msh.fullNode.ChainHead(ctx)
assert.NoError(t, err)
selectResult := selectMsgWithAddress(ctx, t, msh, addrs, ts)
assert.Len(t, selectResult.SelectMsg, 0)
assert.Len(t, selectResult.ErrMsg, len(msgs))
assert.Len(t, selectResult.ToPushMsg, 0)

list, err := ms.ListFailedMessage(ctx, &repo.MsgQueryParams{})
assert.NoError(t, err)
for _, msg := range list {
_, ok := msgsMap[msg.ID]
assert.True(t, ok)
assert.Contains(t, msg.ErrorMsg, fmt.Sprintf("gas limit %d over limit %d", msg.GasLimit, constants.BlockGasLimit))
}
}

func pushMessage(ctx context.Context, ms *MessageService, msgs []*types.Message) error {
for _, msg := range msgs {
// avoid been modified
Expand Down

0 comments on commit 1d54235

Please sign in to comment.