Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove GetSignatures from SigVerifiableTx #6550

Merged
merged 14 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion client/tx/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ func TestBuildUnsignedTx(t *testing.T) {
tx, err := tx.BuildUnsignedTx(txf, msg)
require.NoError(t, err)
require.NotNil(t, tx)
require.Empty(t, tx.GetTx().(ante.SigVerifiableTx).GetSignatures())
sigs, err := tx.GetTx().(ante.SigVerifiableTx).GetSignaturesV2()
require.NoError(t, err)
require.Empty(t, sigs)
}

func TestSign(t *testing.T) {
Expand Down
30 changes: 28 additions & 2 deletions x/auth/ante/basic.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ante

import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/tendermint/tendermint/crypto"

"github.com/cosmos/cosmos-sdk/codec/legacy"
Expand Down Expand Up @@ -100,10 +101,15 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
// simulate gas cost for signatures in simulate mode
if simulate {
// in simulate mode, each element should be a nil signature
sigs := sigTx.GetSignatures()
sigs, err := sigTx.GetSignaturesV2()
if err != nil {
return ctx, err
}
n := len(sigs)
aaronc marked this conversation as resolved.
Show resolved Hide resolved

for i, signer := range sigTx.GetSigners() {
// if signature is already filled in, no need to simulate gas cost
if sigs[i] != nil {
if i < n && !isIncompleteSignature(sigs[i].Data) {
continue
}

Expand Down Expand Up @@ -139,3 +145,23 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim

return next(ctx, tx, simulate)
}

// isIncompleteSignature tests whether SignatureData is fully filled in for simulation purposes
func isIncompleteSignature(data signing.SignatureData) bool {
if data == nil {
return true
}

switch data := data.(type) {
case *signing.SingleSignatureData:
return len(data.Signature) == 0
case *signing.MultiSignatureData:
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
for _, s := range data.Signatures {
if isIncompleteSignature(s) {
return true
}
}
}

return false
}
1 change: 0 additions & 1 deletion x/auth/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type SigVerifiableTx interface {
sdk.Tx
GetSigners() []sdk.AccAddress
GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place
GetSignatures() [][]byte
GetSignaturesV2() ([]signing.SignatureV2, error)
}

Expand Down