-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Removed unnecessary fields name and color of plane * Do not interrupt tx processing if duplicated MsgCreatePlane received * Do not check supervisor's sequence number to allow multiple parallel transactions
- Loading branch information
Showing
26 changed files
with
220 additions
and
2,303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package ante | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/cosmos/cosmos-sdk/x/auth/ante" | ||
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" | ||
) | ||
|
||
// SigVerificationDecorator is a copy of cosmos original SigVerificationDecorator | ||
// Own implementation is needed to skip signature checking for supervisors to allow | ||
// use the same key from many integrated services in parallel. | ||
type SigVerificationDecorator struct { | ||
ak AccountKeeper | ||
sk ScorumKeeper | ||
|
||
signModeHandler authsigning.SignModeHandler | ||
} | ||
|
||
func NewSigVerificationDecorator(ak AccountKeeper, sk ScorumKeeper, signModeHandler authsigning.SignModeHandler) SigVerificationDecorator { | ||
return SigVerificationDecorator{ | ||
ak: ak, | ||
sk: sk, | ||
signModeHandler: signModeHandler, | ||
} | ||
} | ||
func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { | ||
sigTx, ok := tx.(authsigning.SigVerifiableTx) | ||
if !ok { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") | ||
} | ||
|
||
// stdSigs contains the sequence number, account number, and signatures. | ||
// When simulating, this would just be a 0-length slice. | ||
sigs, err := sigTx.GetSignaturesV2() | ||
if err != nil { | ||
return ctx, err | ||
} | ||
|
||
signerAddrs := sigTx.GetSigners() | ||
|
||
// check that signer length and signature length are the same | ||
if len(sigs) != len(signerAddrs) { | ||
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "invalid number of signer; expected: %d, got %d", len(signerAddrs), len(sigs)) | ||
} | ||
|
||
for i, sig := range sigs { | ||
acc, err := ante.GetSignerAcc(ctx, svd.ak, signerAddrs[i]) | ||
if err != nil { | ||
return ctx, err | ||
} | ||
|
||
// retrieve pubkey | ||
pubKey := acc.GetPubKey() | ||
if !simulate && pubKey == nil { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set") | ||
} | ||
|
||
// Check account sequence number. | ||
// Applicable only for not supervisors | ||
if !svd.sk.IsSupervisor(ctx, acc.GetAddress().String()) && sig.Sequence != acc.GetSequence() { | ||
return ctx, sdkerrors.Wrapf( | ||
sdkerrors.ErrWrongSequence, | ||
"account sequence mismatch, expected %d, got %d", acc.GetSequence(), sig.Sequence, | ||
) | ||
} | ||
|
||
// retrieve signer data | ||
genesis := ctx.BlockHeight() == 0 | ||
chainID := ctx.ChainID() | ||
var accNum uint64 | ||
if !genesis { | ||
accNum = acc.GetAccountNumber() | ||
} | ||
signerData := authsigning.SignerData{ | ||
Address: acc.GetAddress().String(), | ||
ChainID: chainID, | ||
AccountNumber: accNum, | ||
Sequence: sig.Sequence, // acc.GetSequence() was originally here, but supervisors allowed to put any value | ||
PubKey: pubKey, | ||
} | ||
|
||
// no need to verify signatures on recheck tx | ||
if !simulate && !ctx.IsReCheckTx() { | ||
err := authsigning.VerifySignature(pubKey, signerData, sig.Data, svd.signModeHandler, tx) | ||
if err != nil { | ||
var errMsg string | ||
if ante.OnlyLegacyAminoSigners(sig.Data) { | ||
// If all signers are using SIGN_MODE_LEGACY_AMINO, we rely on VerifySignature to check account sequence number, | ||
// and therefore communicate sequence number as a potential cause of error. | ||
errMsg = fmt.Sprintf("signature verification failed; please verify account number (%d), sequence (%d) and chain-id (%s)", accNum, acc.GetSequence(), chainID) | ||
} else { | ||
errMsg = fmt.Sprintf("signature verification failed; please verify account number (%d) and chain-id (%s)", accNum, chainID) | ||
} | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, errMsg) | ||
|
||
} | ||
} | ||
} | ||
|
||
return next(ctx, tx, simulate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.