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

feat!: add "is-genesis" check #267

Merged
merged 14 commits into from
Jun 20, 2022
3 changes: 3 additions & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets remove this || here, and just use IsGenesis

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or alternatively do IsGenesis && ctx.BlockHeight() == ctx.InitialHeight() as a defense in depth.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets remove this || here, and just use IsGenesis

Too many tests fail that would require funky re-wiring. This is why I suggested to add the || to keep the tests passing. Probably because IsGenesis returns false as it does not go through the InitGenesis flow.

Alternatively, the || ctx.BlockHeight() == ctx.InitialHeight() can work too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah @ValarDragon we switched it to the OR due to tests failing, should we aim to rewrite the tests or does this implementation work?

genesis := ctx.IsGenesis() || ctx.BlockHeight() == 0
chainID := ctx.ChainID()
var accNum uint64
if !genesis {
Expand Down