From c827cf1c0e6bf6eedc816d9c4bfb634194b1f3ff Mon Sep 17 00:00:00 2001 From: LexLuthr <88259624+LexLuthr@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:23:41 +0400 Subject: [PATCH] fix: sealing: improve gasEstimate logging (#11840) * improve gasEstimate logging * use fmt for hex --- storage/pipeline/commit_batch.go | 8 ++++---- storage/pipeline/precommit_batch.go | 2 +- storage/pipeline/utils.go | 14 +++++++++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/storage/pipeline/commit_batch.go b/storage/pipeline/commit_batch.go index ecb8569d0..e7d89076f 100644 --- a/storage/pipeline/commit_batch.go +++ b/storage/pipeline/commit_batch.go @@ -449,9 +449,9 @@ func (b *CommitBatcher) processBatchV2(cfg sealiface.Config, sectors []abi.Secto _, err = simulateMsgGas(b.mctx, b.api, from, b.maddr, builtin.MethodsMiner.ProveCommitSectors3, needFunds, maxFee, enc.Bytes()) if err != nil && (!api.ErrorIsIn(err, []error{&api.ErrOutOfGas{}}) || len(sectors) < miner.MinAggregatedSectors*2) { - log.Errorf("simulating CommitBatch message failed (%x): %s", enc.Bytes(), err) + log.Errorf("simulating CommitBatch %s", err) res.Error = err.Error() - return []sealiface.CommitBatchRes{res}, xerrors.Errorf("simulating CommitBatch message failed: %w", err) + return []sealiface.CommitBatchRes{res}, xerrors.Errorf("simulating CommitBatch %w", err) } msgTooLarge := len(enc.Bytes()) > (messagepool.MaxMessageSize - 128) @@ -590,9 +590,9 @@ func (b *CommitBatcher) processBatchV1(cfg sealiface.Config, sectors []abi.Secto _, err = simulateMsgGas(b.mctx, b.api, from, b.maddr, builtin.MethodsMiner.ProveCommitAggregate, needFunds, maxFee, enc.Bytes()) if err != nil && (!api.ErrorIsIn(err, []error{&api.ErrOutOfGas{}}) || len(sectors) < miner.MinAggregatedSectors*2) { - log.Errorf("simulating CommitBatch message failed (%x): %s", enc.Bytes(), err) + log.Errorf("simulating CommitBatch %s", err) res.Error = err.Error() - return []sealiface.CommitBatchRes{res}, xerrors.Errorf("simulating CommitBatch message failed: %w", err) + return []sealiface.CommitBatchRes{res}, xerrors.Errorf("simulating CommitBatch %w", err) } // If we're out of gas, split the batch in half and evaluate again diff --git a/storage/pipeline/precommit_batch.go b/storage/pipeline/precommit_batch.go index 099988010..55bead590 100644 --- a/storage/pipeline/precommit_batch.go +++ b/storage/pipeline/precommit_batch.go @@ -291,7 +291,7 @@ func (b *PreCommitBatcher) processPreCommitBatch(cfg sealiface.Config, bf abi.To if err != nil && (!api.ErrorIsIn(err, []error{&api.ErrOutOfGas{}}) || len(entries) == 1) { res.Error = err.Error() - return []sealiface.PreCommitBatchRes{res}, xerrors.Errorf("simulating PreCommitBatch message failed: %w", err) + return []sealiface.PreCommitBatchRes{res}, xerrors.Errorf("simulating PreCommitBatch %w", err) } // If we're out of gas, split the batch in half and evaluate again diff --git a/storage/pipeline/utils.go b/storage/pipeline/utils.go index 4b99a5bea..ac519b6ac 100644 --- a/storage/pipeline/utils.go +++ b/storage/pipeline/utils.go @@ -1,7 +1,9 @@ package sealing import ( + "bytes" "context" + "fmt" "math/bits" "github.com/ipfs/go-cid" @@ -105,7 +107,17 @@ func simulateMsgGas(ctx context.Context, sa interface { Params: params, } - return sa.GasEstimateMessageGas(ctx, &msg, nil, types.EmptyTSK) + var b bytes.Buffer + err := msg.MarshalCBOR(&b) + if err != nil { + return nil, xerrors.Errorf("failed to unmarshal the signed message: %w", err) + } + + gmsg, err := sa.GasEstimateMessageGas(ctx, &msg, nil, types.EmptyTSK) + if err != nil { + err = fmt.Errorf("message %x failed: %w", b.Bytes(), err) + } + return gmsg, err } func sendMsg(ctx context.Context, sa interface {