diff --git a/consensus/parlia/parlia.go b/consensus/parlia/parlia.go index 323daf2973..4338f83e15 100644 --- a/consensus/parlia/parlia.go +++ b/consensus/parlia/parlia.go @@ -336,7 +336,10 @@ func (p *Parlia) verifyHeader(chain consensus.ChainReader, header *types.Header, if len(header.Extra) < extraVanity+extraSeal { return errMissingSignature } - + // Verify that the gasUsed is <= gasLimit + if header.GasUsed > header.GasLimit { + return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d", header.GasUsed, header.GasLimit) + } // check extra data isEpoch := number%p.config.Epoch == 0 @@ -742,6 +745,10 @@ func (p *Parlia) FinalizeAndAssemble(chain consensus.ChainReader, header *types. if err != nil { panic(err) } + // should not happen. Once happen, stop the node is better than broadcast the block + if header.GasLimit < header.GasUsed { + panic("Gas consumption of system txs exceed the gas limit") + } header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number)) header.UncleHash = types.CalcUncleHash(nil) diff --git a/miner/worker.go b/miner/worker.go index 79272fe870..f0c622d181 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -732,6 +732,7 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin if w.current.gasPool == nil { w.current.gasPool = new(core.GasPool).AddGas(w.current.header.GasLimit) + w.current.gasPool.SubGas(params.SystemTxsGas) } var coalescedLogs []*types.Log diff --git a/params/protocol_params.go b/params/protocol_params.go index ab5411d2e0..d759305cac 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -19,21 +19,22 @@ package params import "math/big" const ( - GasLimitBoundDivisor uint64 = 256 // The bound divisor of the gas limit, used in update calculations. + GasLimitBoundDivisor uint64 = 256 // The bound divisor of the gas limit, used in update calculations. MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be. GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block. - MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis. - ExpByteGas uint64 = 10 // Times ceil(log256(exponent)) for the EXP instruction. - SloadGas uint64 = 50 // Multiplied by the number of 32-byte words that are copied (round up) for any *COPY operation and added. - CallValueTransferGas uint64 = 9000 // Paid for CALL when the value transfer is non-zero. - CallNewAccountGas uint64 = 25000 // Paid for CALL when the destination address didn't exist prior. - TxGas uint64 = 21000 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions. - TxGasContractCreation uint64 = 53000 // Per transaction that creates a contract. NOTE: Not payable on data of calls between transactions. - TxDataZeroGas uint64 = 4 // Per byte of data attached to a transaction that equals zero. NOTE: Not payable on data of calls between transactions. - QuadCoeffDiv uint64 = 512 // Divisor for the quadratic particle of the memory cost equation. - LogDataGas uint64 = 8 // Per byte in a LOG* operation's data. - CallStipend uint64 = 2300 // Free gas given at beginning of call. + MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis. + ExpByteGas uint64 = 10 // Times ceil(log256(exponent)) for the EXP instruction. + SloadGas uint64 = 50 // Multiplied by the number of 32-byte words that are copied (round up) for any *COPY operation and added. + CallValueTransferGas uint64 = 9000 // Paid for CALL when the value transfer is non-zero. + CallNewAccountGas uint64 = 25000 // Paid for CALL when the destination address didn't exist prior. + TxGas uint64 = 21000 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions. + SystemTxsGas uint64 = 100000 // The gas reserved for system txs; only for parlia consensus + TxGasContractCreation uint64 = 53000 // Per transaction that creates a contract. NOTE: Not payable on data of calls between transactions. + TxDataZeroGas uint64 = 4 // Per byte of data attached to a transaction that equals zero. NOTE: Not payable on data of calls between transactions. + QuadCoeffDiv uint64 = 512 // Divisor for the quadratic particle of the memory cost equation. + LogDataGas uint64 = 8 // Per byte in a LOG* operation's data. + CallStipend uint64 = 2300 // Free gas given at beginning of call. Sha3Gas uint64 = 30 // Once per SHA3 operation. Sha3WordGas uint64 = 6 // Once per word of the SHA3 operation's data.