From 3e46ff7501a1a2fe4c02f4cbcdb925ea8293cc94 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 20 Jun 2022 15:06:11 -0500 Subject: [PATCH] feat!: add "is-genesis" check (#267) * is gen test * my attempt at isGenesis * logs and uncomment * more changes * comment out * change init gen call loc * further gen tests * more tests * another test * revert unneeded changes * remove extra * reset to false * Update x/auth/ante/sigverify.go Co-authored-by: Aleksandr Bezobchuk * changes from call with bez Co-authored-by: Aleksandr Bezobchuk --- baseapp/abci.go | 3 +++ types/context.go | 8 ++++++++ x/auth/ante/sigverify.go | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index dcfe431ce0d7..12bf9ce5cea5 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -63,9 +63,12 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC // add block gas meter for any genesis transactions (allow infinite gas) app.deliverState.ctx = app.deliverState.ctx.WithBlockGasMeter(sdk.NewInfiniteGasMeter()) + app.deliverState.ctx = app.deliverState.ctx.WithIsGenesis(true) res = app.initChainer(app.deliverState.ctx, req) + app.deliverState.ctx = app.deliverState.ctx.WithIsGenesis(false) + // sanity check if len(req.Validators) > 0 { if len(req.Validators) != len(res.Validators) { diff --git a/types/context.go b/types/context.go index 35030dad9a96..e3604df954ba 100644 --- a/types/context.go +++ b/types/context.go @@ -28,6 +28,7 @@ type Context struct { header tmproto.Header headerHash tmbytes.HexBytes chainID string + isGenesis bool txBytes []byte logger log.Logger voteInfo []abci.VoteInfo @@ -49,6 +50,7 @@ func (c Context) MultiStore() MultiStore { return c.ms } func (c Context) BlockHeight() int64 { return c.header.Height } func (c Context) BlockTime() time.Time { return c.header.Time } func (c Context) ChainID() string { return c.chainID } +func (c Context) IsGenesis() bool { return c.isGenesis } func (c Context) TxBytes() []byte { return c.txBytes } func (c Context) Logger() log.Logger { return c.logger } func (c Context) VoteInfos() []abci.VoteInfo { return c.voteInfo } @@ -196,6 +198,12 @@ func (c Context) WithIsReCheckTx(isRecheckTx bool) Context { return c } +// WithIsGenesis sets isGenesis +func (c Context) WithIsGenesis(isGenesis bool) Context { + c.isGenesis = isGenesis + return c +} + // WithMinGasPrices returns a Context with an updated minimum gas price value func (c Context) WithMinGasPrices(gasPrices DecCoins) Context { c.minGasPrice = gasPrices diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index dc2fedbc0772..9bb7d96f71f6 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -269,7 +269,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul } // retrieve signer data - genesis := ctx.BlockHeight() == 0 + genesis := ctx.IsGenesis() || ctx.BlockHeight() == 0 chainID := ctx.ChainID() var accNum uint64 if !genesis {