Skip to content

Commit

Permalink
feat!: add "is-genesis" check (#267) (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic authored Jun 20, 2022
1 parent 8b021d2 commit 1f9cc80
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,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) {
Expand Down
8 changes: 8 additions & 0 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/auth/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1f9cc80

Please sign in to comment.