From e0293eed4d128f5cf86d1bb5d567435ab4f4b945 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 31 May 2022 16:58:06 +0200 Subject: [PATCH] add fix --- client/tx/factory.go | 46 ++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/client/tx/factory.go b/client/tx/factory.go index b65264d6671f..8a89e80142dd 100644 --- a/client/tx/factory.go +++ b/client/tx/factory.go @@ -317,15 +317,40 @@ func (f Factory) BuildSimTx(msgs ...sdk.Msg) ([]byte, error) { return nil, err } - // use the first element from the list of keys in order to generate a valid - // pubkey that supports multiple algorithms + pk, err := f.getSimPK() + if err != nil { + return nil, err + } + // Create an empty signature literal as the ante handler will populate with a + // sentinel pubkey. + sig := signing.SignatureV2{ + PubKey: pk, + Data: &signing.SingleSignatureData{ + SignMode: f.signMode, + }, + Sequence: f.Sequence(), + } + if err := txb.SetSignatures(sig); err != nil { + return nil, err + } + + return f.txConfig.TxEncoder()(txb.GetTx()) +} + +// getSimPK gets the public key to use for building a simulation tx +// note we should only check for keys in the keybase if we are in simulate and execute mode +// (f.e. when using --gas=auto - ref #11283) +// when using --dry-run, we are is simulation mode only and should not check the keybase +func (f Factory) getSimPK() (cryptotypes.PubKey, error) { var ( ok bool pk cryptotypes.PubKey = &secp256k1.PubKey{} // use default public key type ) - if f.keybase != nil { + // use the first element from the list of keys in order to generate a valid + // pubkey that supports multiple algorithms + if f.simulateAndExecute && f.keybase != nil { records, _ := f.keybase.List() if len(records) == 0 { return nil, errors.New("cannot build signature for simulation, key records slice is empty") @@ -338,20 +363,7 @@ func (f Factory) BuildSimTx(msgs ...sdk.Msg) ([]byte, error) { } } - // Create an empty signature literal as the ante handler will populate with a - // sentinel pubkey. - sig := signing.SignatureV2{ - PubKey: pk, - Data: &signing.SingleSignatureData{ - SignMode: f.signMode, - }, - Sequence: f.Sequence(), - } - if err := txb.SetSignatures(sig); err != nil { - return nil, err - } - - return f.txConfig.TxEncoder()(txb.GetTx()) + return pk, nil } // Prepare ensures the account defined by ctx.GetFromAddress() exists and