MCPcopy Create free account
hub / github.com/CPChain/chain / CalcGasLimit

Function CalcGasLimit

core/block_validator.go:105–135  ·  view source on GitHub ↗

CalcGasLimit computes the gas limit of the next block after parent. This is miner strategy, not consensus protocol.

(parent *types.Block)

Source from the content-addressed store, hash-verified

103// CalcGasLimit computes the gas limit of the next block after parent.
104// This is miner strategy, not consensus protocol.
105func CalcGasLimit(parent *types.Block) uint64 {
106 // contrib = (parentGasUsed * 3 / 2) / 1024
107 contrib := (parent.GasUsed() + parent.GasUsed()/2) / configs.GasLimitBoundDivisor
108
109 // decay = parentGasLimit / 1024 -1
110 decay := parent.GasLimit()/configs.GasLimitBoundDivisor - 1
111
112 /*
113 strategy: gasLimit of block-to-mine is set based on parent's
114 gasUsed value. if parentGasUsed > parentGasLimit * (2/3) then we
115 increase it, otherwise lower it (or leave it unchanged if it's right
116 at that usage) the amount increased/decreased depends on how far away
117 from parentGasLimit * (2/3) parentGasUsed is.
118 */
119 limit := parent.GasLimit() - decay + contrib
120 if limit < configs.MinGasLimit {
121 limit = configs.MinGasLimit
122 }
123 // however, if we're now below the target (TargetGasLimit) we increase the
124 // limit as much as we can (parentGasLimit / 1024 -1)
125 if limit < configs.TargetGasLimit {
126 limit = parent.GasLimit() + decay
127 if limit > configs.TargetGasLimit {
128 limit = configs.TargetGasLimit
129 }
130 }
131 if limit > configs.MaxGasLimit {
132 limit = configs.MaxGasLimit
133 }
134 return limit
135}

Callers 2

makeHeaderFunction · 0.85
genTxRingFunction · 0.85

Calls 2

GasUsedMethod · 0.80
GasLimitMethod · 0.45

Tested by 1

genTxRingFunction · 0.68