@@ -23,43 +23,47 @@ but please do not over-use it. We try to keep all data structured
2323and standard additions here would be better just to add to the Context struct
2424*/
2525type Context struct {
26- baseCtx context.Context
27- ms MultiStore
28- header tmproto.Header
29- headerHash tmbytes.HexBytes
30- chainID string
31- txBytes []byte
32- logger log.Logger
33- voteInfo []abci.VoteInfo
34- gasMeter GasMeter
35- blockGasMeter GasMeter
36- checkTx bool
37- recheckTx bool // if recheckTx == true, then checkTx must also be true
38- minGasPrice DecCoins
39- consParams * tmproto.ConsensusParams
40- eventManager * EventManager
41- priority int64 // The tx priority, only relevant in CheckTx
26+ baseCtx context.Context
27+ ms MultiStore
28+ header tmproto.Header
29+ headerHash tmbytes.HexBytes
30+ chainID string
31+ txBytes []byte
32+ logger log.Logger
33+ voteInfo []abci.VoteInfo
34+ gasMeter GasMeter
35+ blockGasMeter GasMeter
36+ checkTx bool
37+ recheckTx bool // if recheckTx == true, then checkTx must also be true
38+ minGasPrice DecCoins
39+ consParams * tmproto.ConsensusParams
40+ eventManager * EventManager
41+ priority int64 // The tx priority, only relevant in CheckTx
42+ kvGasConfig storetypes.GasConfig
43+ transientKVGasConfig storetypes.GasConfig
4244}
4345
4446// Proposed rename, not done to avoid API breakage
4547type Request = Context
4648
4749// Read-only accessors
48- func (c Context ) Context () context.Context { return c .baseCtx }
49- func (c Context ) MultiStore () MultiStore { return c .ms }
50- func (c Context ) BlockHeight () int64 { return c .header .Height }
51- func (c Context ) BlockTime () time.Time { return c .header .Time }
52- func (c Context ) ChainID () string { return c .chainID }
53- func (c Context ) TxBytes () []byte { return c .txBytes }
54- func (c Context ) Logger () log.Logger { return c .logger }
55- func (c Context ) VoteInfos () []abci.VoteInfo { return c .voteInfo }
56- func (c Context ) GasMeter () GasMeter { return c .gasMeter }
57- func (c Context ) BlockGasMeter () GasMeter { return c .blockGasMeter }
58- func (c Context ) IsCheckTx () bool { return c .checkTx }
59- func (c Context ) IsReCheckTx () bool { return c .recheckTx }
60- func (c Context ) MinGasPrices () DecCoins { return c .minGasPrice }
61- func (c Context ) EventManager () * EventManager { return c .eventManager }
62- func (c Context ) Priority () int64 { return c .priority }
50+ func (c Context ) Context () context.Context { return c .baseCtx }
51+ func (c Context ) MultiStore () MultiStore { return c .ms }
52+ func (c Context ) BlockHeight () int64 { return c .header .Height }
53+ func (c Context ) BlockTime () time.Time { return c .header .Time }
54+ func (c Context ) ChainID () string { return c .chainID }
55+ func (c Context ) TxBytes () []byte { return c .txBytes }
56+ func (c Context ) Logger () log.Logger { return c .logger }
57+ func (c Context ) VoteInfos () []abci.VoteInfo { return c .voteInfo }
58+ func (c Context ) GasMeter () GasMeter { return c .gasMeter }
59+ func (c Context ) BlockGasMeter () GasMeter { return c .blockGasMeter }
60+ func (c Context ) IsCheckTx () bool { return c .checkTx }
61+ func (c Context ) IsReCheckTx () bool { return c .recheckTx }
62+ func (c Context ) MinGasPrices () DecCoins { return c .minGasPrice }
63+ func (c Context ) EventManager () * EventManager { return c .eventManager }
64+ func (c Context ) Priority () int64 { return c .priority }
65+ func (c Context ) KVGasConfig () storetypes.GasConfig { return c .kvGasConfig }
66+ func (c Context ) TransientKVGasConfig () storetypes.GasConfig { return c .transientKVGasConfig }
6367
6468// clone the header before returning
6569func (c Context ) BlockHeader () tmproto.Header {
@@ -95,15 +99,17 @@ func NewContext(ms MultiStore, header tmproto.Header, isCheckTx bool, logger log
9599 // https://github.com/gogo/protobuf/issues/519
96100 header .Time = header .Time .UTC ()
97101 return Context {
98- baseCtx : context .Background (),
99- ms : ms ,
100- header : header ,
101- chainID : header .ChainID ,
102- checkTx : isCheckTx ,
103- logger : logger ,
104- gasMeter : storetypes .NewInfiniteGasMeter (),
105- minGasPrice : DecCoins {},
106- eventManager : NewEventManager (),
102+ baseCtx : context .Background (),
103+ ms : ms ,
104+ header : header ,
105+ chainID : header .ChainID ,
106+ checkTx : isCheckTx ,
107+ logger : logger ,
108+ gasMeter : storetypes .NewInfiniteGasMeter (),
109+ minGasPrice : DecCoins {},
110+ eventManager : NewEventManager (),
111+ kvGasConfig : storetypes .KVGasConfig (),
112+ transientKVGasConfig : storetypes .TransientGasConfig (),
107113 }
108114}
109115
@@ -194,6 +200,20 @@ func (c Context) WithBlockGasMeter(meter GasMeter) Context {
194200 return c
195201}
196202
203+ // WithKVGasConfig returns a Context with an updated gas configuration for
204+ // the KVStore
205+ func (c Context ) WithKVGasConfig (gasConfig storetypes.GasConfig ) Context {
206+ c .kvGasConfig = gasConfig
207+ return c
208+ }
209+
210+ // WithTransientKVGasConfig returns a Context with an updated gas configuration for
211+ // the transient KVStore
212+ func (c Context ) WithTransientKVGasConfig (gasConfig storetypes.GasConfig ) Context {
213+ c .transientKVGasConfig = gasConfig
214+ return c
215+ }
216+
197217// WithIsCheckTx enables or disables CheckTx value for verifying transactions and returns an updated Context
198218func (c Context ) WithIsCheckTx (isCheckTx bool ) Context {
199219 c .checkTx = isCheckTx
@@ -258,12 +278,12 @@ func (c Context) Value(key interface{}) interface{} {
258278
259279// KVStore fetches a KVStore from the MultiStore.
260280func (c Context ) KVStore (key storetypes.StoreKey ) KVStore {
261- return gaskv .NewStore (c .MultiStore ().GetKVStore (key ), c .GasMeter (), storetypes . KVGasConfig () )
281+ return gaskv .NewStore (c .MultiStore ().GetKVStore (key ), c .GasMeter (), c . kvGasConfig )
262282}
263283
264284// TransientStore fetches a TransientStore from the MultiStore.
265285func (c Context ) TransientStore (key storetypes.StoreKey ) KVStore {
266- return gaskv .NewStore (c .MultiStore ().GetKVStore (key ), c .GasMeter (), storetypes . TransientGasConfig () )
286+ return gaskv .NewStore (c .MultiStore ().GetKVStore (key ), c .GasMeter (), c . transientKVGasConfig )
267287}
268288
269289// CacheContext returns a new Context with the multi-store cached and a new
0 commit comments