add absent validators to context

This commit is contained in:
rigelrozanski 2018-05-01 12:22:57 -04:00
parent d871605241
commit aeabdcae5d
2 changed files with 14 additions and 3 deletions

View File

@ -64,9 +64,10 @@ type BaseApp struct {
// See methods setCheckState and setDeliverState.
// .valUpdates accumulate in DeliverTx and are reset in BeginBlock.
// QUESTION: should we put valUpdates in the deliverState.ctx?
checkState *state // for CheckTx
deliverState *state // for DeliverTx
valUpdates []abci.Validator // cached validator changes from DeliverTx
checkState *state // for CheckTx
deliverState *state // for DeliverTx
valUpdates []abci.Validator // cached validator changes from DeliverTx
absentValidators []int32 // absent validators from begin block
}
var _ abci.Application = (*BaseApp)(nil)
@ -383,6 +384,8 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
if app.beginBlocker != nil {
res = app.beginBlocker(app.deliverState.ctx, req)
}
// set the absent validators for addition to context in deliverTx
app.absentValidators = req.AbsentValidators
return
}
@ -492,6 +495,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (result sdk
ctx = app.checkState.ctx.WithTxBytes(txBytes)
} else {
ctx = app.deliverState.ctx.WithTxBytes(txBytes)
ctx = ctx.WithAbsentValidators(app.absentValidators)
}
// Simulate a DeliverTx for gas calculation

View File

@ -129,6 +129,7 @@ const (
contextKeyTxBytes
contextKeyLogger
contextKeyGasMeter
contextKeyAbsentValidators
)
// NOTE: Do not expose MultiStore.
@ -160,6 +161,9 @@ func (c Context) Logger() log.Logger {
func (c Context) GasMeter() GasMeter {
return c.Value(contextKeyGasMeter).(GasMeter)
}
func (c Context) AbsentValidators() []int32 {
return c.Value(contextKeyAbsentValidators).([]int32)
}
func (c Context) WithMultiStore(ms MultiStore) Context {
return c.withValue(contextKeyMultiStore, ms)
}
@ -185,6 +189,9 @@ func (c Context) WithLogger(logger log.Logger) Context {
func (c Context) WithGasMeter(meter GasMeter) Context {
return c.withValue(contextKeyGasMeter, meter)
}
func (c Context) WithAbsentValidators(AbsentValidators []int32) Context {
return c.withValue(contextKeyAbsentValidators, AbsentValidators)
}
// Cache the multistore and return a new cached context. The cached context is
// written to the context when writeCache is called.