diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 896f19ebed16..443ebc44503b 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -174,7 +174,7 @@ func TestBaseApp_BlockGas(t *testing.T) { require.Equal(t, []byte("ok"), okValue) } // check block gas is always consumed - baseGas := uint64(54436) // baseGas is the gas consumed before tx msg + baseGas := uint64(57504) // baseGas is the gas consumed before tx msg expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas) if expGasConsumed > uint64(simtestutil.DefaultConsensusParams.Block.MaxGas) { // capped by gasLimit diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index 458176363168..4eb95c5c2e6b 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -131,35 +131,47 @@ func (w *wrapper) ValidateBasic() error { func (w *wrapper) getBodyBytes() []byte { if len(w.bodyBz) == 0 { - if !w.tx.Body.Unordered && (w.tx.Body.TimeoutTimestamp.IsZero() || w.tx.Body.TimeoutTimestamp.Unix() == 0) { - anyMsgs, err := msgsV1toAnyV2(w.GetMsgs()) - if err != nil { - panic(fmt.Errorf("unable to convert messages: %w", err)) - } - body := &txv1beta1.TxBodyCompat{ - Messages: anyMsgs, - Memo: w.GetMemo(), - TimeoutHeight: w.GetTimeoutHeight(), - ExtensionOptions: intoAnyV2(w.GetExtensionOptions()), - NonCriticalExtensionOptions: intoAnyV2(w.GetNonCriticalExtensionOptions()), + if w.tx.Body != nil { + if w.tx.Body.TimeoutTimestamp == nil { + w.tx.Body.TimeoutTimestamp = &time.Time{} } - bodyBytes, err := marshalOption.Marshal(body) - if err != nil { - panic(fmt.Errorf("unable to marshal body: %w", err)) - } - w.bodyBz = bodyBytes - } else { - // if bodyBz is empty, then marshal the body. bodyBz will generally - // be set to nil whenever SetBody is called so the result of calling - // this method should always return the correct bytes. Note that after - // decoding bodyBz is derived from TxRaw so that it matches what was - // transmitted over the wire - var err error - w.bodyBz, err = proto.Marshal(w.tx.Body) - if err != nil { - panic(err) + if !w.tx.Body.Unordered && (w.tx.Body.TimeoutTimestamp.IsZero() || w.tx.Body.TimeoutTimestamp.Unix() == 0) { + var anyMsgs []*anypb.Any + if len(w.tx.Body.Messages) > 0 { + for _, msg := range w.tx.Body.Messages { + anyMsgs = append(anyMsgs, &anypb.Any{ + TypeUrl: msg.TypeUrl, + Value: msg.Value, + }) + } + } + + body := &txv1beta1.TxBodyCompat{ + Messages: anyMsgs, + Memo: w.GetMemo(), + TimeoutHeight: w.GetTimeoutHeight(), + ExtensionOptions: intoAnyV2(w.GetExtensionOptions()), + NonCriticalExtensionOptions: intoAnyV2(w.GetNonCriticalExtensionOptions()), + } + bodyBytes, err := marshalOption.Marshal(body) + if err != nil { + panic(fmt.Errorf("unable to marshal body: %w", err)) + } + w.bodyBz = bodyBytes + return w.bodyBz } } + + // if bodyBz is empty, then marshal the body. bodyBz will generally + // be set to nil whenever SetBody is called so the result of calling + // this method should always return the correct bytes. Note that after + // decoding bodyBz is derived from TxRaw so that it matches what was + // transmitted over the wire + var err error + w.bodyBz, err = proto.Marshal(w.tx.Body) + if err != nil { + panic(err) + } } return w.bodyBz } @@ -454,25 +466,6 @@ func (w *wrapper) setSignatureAtIndex(index int, sig []byte) { } func (w *wrapper) GetTx() authsigning.Tx { - if !w.tx.Body.Unordered && (w.tx.Body.TimeoutTimestamp.IsZero() || w.tx.Body.TimeoutTimestamp.Unix() == 0) { - anyMsgs, err := msgsV1toAnyV2(w.GetMsgs()) - if err != nil { - panic(fmt.Errorf("unable to convert messages: %w", err)) - } - body := &txv1beta1.TxBodyCompat{ - Messages: anyMsgs, - Memo: w.GetMemo(), - TimeoutHeight: w.GetTimeoutHeight(), - ExtensionOptions: intoAnyV2(w.GetExtensionOptions()), - NonCriticalExtensionOptions: intoAnyV2(w.GetNonCriticalExtensionOptions()), - } - bodyBytes, err := marshalOption.Marshal(body) - if err != nil { - panic(fmt.Errorf("unable to marshal body: %w", err)) - } - - w.bodyBz = bodyBytes - } return w }