mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
gasLimit (#12)
This commit is contained in:
parent
1202a3b64d
commit
7f40bbd7d8
7 changed files with 57 additions and 7 deletions
|
|
@ -24,6 +24,7 @@ func (p PayloadAttributes) MarshalJSON() ([]byte, error) {
|
||||||
// <specular modification>
|
// <specular modification>
|
||||||
Transactions []hexutil.Bytes `json:"transactions,omitempty" gencodec:"optional"`
|
Transactions []hexutil.Bytes `json:"transactions,omitempty" gencodec:"optional"`
|
||||||
NoTxPool bool `json:"noTxPool,omitempty" gencodec:"optional"`
|
NoTxPool bool `json:"noTxPool,omitempty" gencodec:"optional"`
|
||||||
|
GasLimit *hexutil.Uint64 `json:"gasLimit,omitempty" gencodec:"optional"`
|
||||||
// <specular modification/>
|
// <specular modification/>
|
||||||
}
|
}
|
||||||
var enc PayloadAttributes
|
var enc PayloadAttributes
|
||||||
|
|
@ -40,6 +41,7 @@ func (p PayloadAttributes) MarshalJSON() ([]byte, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enc.NoTxPool = p.NoTxPool
|
enc.NoTxPool = p.NoTxPool
|
||||||
|
enc.GasLimit = (*hexutil.Uint64)(p.GasLimit)
|
||||||
// <specular modification/>
|
// <specular modification/>
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
}
|
}
|
||||||
|
|
@ -55,6 +57,7 @@ func (p *PayloadAttributes) UnmarshalJSON(input []byte) error {
|
||||||
// <specular modification>
|
// <specular modification>
|
||||||
Transactions []hexutil.Bytes `json:"transactions,omitempty" gencodec:"optional"`
|
Transactions []hexutil.Bytes `json:"transactions,omitempty" gencodec:"optional"`
|
||||||
NoTxPool *bool `json:"noTxPool,omitempty" gencodec:"optional"`
|
NoTxPool *bool `json:"noTxPool,omitempty" gencodec:"optional"`
|
||||||
|
GasLimit *hexutil.Uint64 `json:"gasLimit,omitempty" gencodec:"optional"`
|
||||||
// <specular modification/>
|
// <specular modification/>
|
||||||
}
|
}
|
||||||
var dec PayloadAttributes
|
var dec PayloadAttributes
|
||||||
|
|
@ -89,6 +92,9 @@ func (p *PayloadAttributes) UnmarshalJSON(input []byte) error {
|
||||||
if dec.NoTxPool != nil {
|
if dec.NoTxPool != nil {
|
||||||
p.NoTxPool = *dec.NoTxPool
|
p.NoTxPool = *dec.NoTxPool
|
||||||
}
|
}
|
||||||
|
if dec.GasLimit != nil {
|
||||||
|
p.GasLimit = (*uint64)(dec.GasLimit)
|
||||||
|
}
|
||||||
// <specular modification/>
|
// <specular modification/>
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,8 @@ type PayloadAttributes struct {
|
||||||
// NoTxPool is a field for L2s: if true, the no transactions are taken out of the tx-pool,
|
// NoTxPool is a field for L2s: if true, the no transactions are taken out of the tx-pool,
|
||||||
// only transactions from the above Transactions list will be included.
|
// only transactions from the above Transactions list will be included.
|
||||||
NoTxPool bool `json:"noTxPool,omitempty" gencodec:"optional"`
|
NoTxPool bool `json:"noTxPool,omitempty" gencodec:"optional"`
|
||||||
|
// GasLimit is a field for L2s: if set, this sets the exact gas limit the block produced with.
|
||||||
|
GasLimit *uint64 `json:"gasLimit,omitempty" gencodec:"optional"`
|
||||||
// <specular modification//>
|
// <specular modification//>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,6 +52,7 @@ type payloadAttributesMarshaling struct {
|
||||||
Timestamp hexutil.Uint64
|
Timestamp hexutil.Uint64
|
||||||
// <specular modification>
|
// <specular modification>
|
||||||
Transactions []hexutil.Bytes
|
Transactions []hexutil.Bytes
|
||||||
|
GasLimit *hexutil.Uint64
|
||||||
// <specular modification/>
|
// <specular modification/>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,15 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade
|
||||||
if !config.IsLondon(parent.Number) {
|
if !config.IsLondon(parent.Number) {
|
||||||
parentGasLimit = parent.GasLimit * config.ElasticityMultiplier()
|
parentGasLimit = parent.GasLimit * config.ElasticityMultiplier()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// <specular modification>
|
||||||
|
if !config.EnableL2GasLimitApi { // gasLimit can adjust instantly on L2s
|
||||||
if err := misc.VerifyGaslimit(parentGasLimit, header.GasLimit); err != nil {
|
if err := misc.VerifyGaslimit(parentGasLimit, header.GasLimit); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// <specular modification>
|
||||||
|
|
||||||
// Verify the header is not malformed
|
// Verify the header is not malformed
|
||||||
if header.BaseFee == nil {
|
if header.BaseFee == nil {
|
||||||
return errors.New("header is missing baseFee")
|
return errors.New("header is missing baseFee")
|
||||||
|
|
|
||||||
|
|
@ -367,6 +367,9 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl
|
||||||
// will replace it arbitrarily many times in between.
|
// will replace it arbitrarily many times in between.
|
||||||
if payloadAttributes != nil {
|
if payloadAttributes != nil {
|
||||||
// <specular modification>
|
// <specular modification>
|
||||||
|
if api.eth.BlockChain().Config().EnableL2GasLimitApi && payloadAttributes.GasLimit == nil {
|
||||||
|
return engine.STATUS_INVALID, engine.InvalidPayloadAttributes.With(errors.New("gasLimit parameter is required"))
|
||||||
|
}
|
||||||
transactions := make(types.Transactions, 0, len(payloadAttributes.Transactions))
|
transactions := make(types.Transactions, 0, len(payloadAttributes.Transactions))
|
||||||
for i, otx := range payloadAttributes.Transactions {
|
for i, otx := range payloadAttributes.Transactions {
|
||||||
var tx types.Transaction
|
var tx types.Transaction
|
||||||
|
|
@ -387,6 +390,7 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl
|
||||||
// <specular modification>
|
// <specular modification>
|
||||||
NoTxPool: payloadAttributes.NoTxPool,
|
NoTxPool: payloadAttributes.NoTxPool,
|
||||||
Transactions: transactions,
|
Transactions: transactions,
|
||||||
|
GasLimit: payloadAttributes.GasLimit,
|
||||||
// <specular modification/>
|
// <specular modification/>
|
||||||
}
|
}
|
||||||
id := args.Id()
|
id := args.Id()
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,9 @@ type BuildPayloadArgs struct {
|
||||||
Withdrawals types.Withdrawals // The provided withdrawals
|
Withdrawals types.Withdrawals // The provided withdrawals
|
||||||
BeaconRoot *common.Hash // The provided beaconRoot (Cancun)
|
BeaconRoot *common.Hash // The provided beaconRoot (Cancun)
|
||||||
// <specular modification>
|
// <specular modification>
|
||||||
NoTxPool bool // Specular addition: option to disable tx pool contents from being included
|
NoTxPool bool // L2 engine api addition: option to disable tx pool contents from being included
|
||||||
Transactions []*types.Transaction // Specular addition: txs forced into the block via engine API
|
Transactions []*types.Transaction // L2 engine api addition: txs forced into the block via engine API
|
||||||
|
GasLimit *uint64 // L2 engine api addition: override gas limit of the block to build
|
||||||
// <specular modification/>
|
// <specular modification/>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,6 +69,9 @@ func (args *BuildPayloadArgs) Id() engine.PayloadID {
|
||||||
hasher.Write(h[:])
|
hasher.Write(h[:])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if args.GasLimit != nil {
|
||||||
|
binary.Write(hasher, binary.BigEndian, *args.GasLimit)
|
||||||
|
}
|
||||||
// <specular modification/>
|
// <specular modification/>
|
||||||
var out engine.PayloadID
|
var out engine.PayloadID
|
||||||
copy(out[:], hasher.Sum(nil)[:8])
|
copy(out[:], hasher.Sum(nil)[:8])
|
||||||
|
|
@ -193,6 +197,10 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
|
||||||
// Build the initial version with no transaction included. It should be fast
|
// Build the initial version with no transaction included. It should be fast
|
||||||
// enough to run. The empty payload can at least make sure there is something
|
// enough to run. The empty payload can at least make sure there is something
|
||||||
// to deliver for not missing slot.
|
// to deliver for not missing slot.
|
||||||
|
|
||||||
|
// <specular modification>
|
||||||
|
// With L2s, the "empty" block is constructed from provided txs only, i.e. no tx-pool usage.
|
||||||
|
// <specular modification/>
|
||||||
emptyParams := &generateParams{
|
emptyParams := &generateParams{
|
||||||
timestamp: args.Timestamp,
|
timestamp: args.Timestamp,
|
||||||
forceTime: true,
|
forceTime: true,
|
||||||
|
|
@ -204,6 +212,7 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
|
||||||
noTxs: true,
|
noTxs: true,
|
||||||
// <specular modification>
|
// <specular modification>
|
||||||
txs: args.Transactions,
|
txs: args.Transactions,
|
||||||
|
gasLimit: args.GasLimit,
|
||||||
// <specular modification/>
|
// <specular modification/>
|
||||||
}
|
}
|
||||||
empty := w.getSealingBlock(emptyParams)
|
empty := w.getSealingBlock(emptyParams)
|
||||||
|
|
@ -246,6 +255,7 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
|
||||||
noTxs: false,
|
noTxs: false,
|
||||||
// <specular modification>
|
// <specular modification>
|
||||||
txs: args.Transactions,
|
txs: args.Transactions,
|
||||||
|
gasLimit: args.GasLimit,
|
||||||
// <specular modification/>
|
// <specular modification/>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -903,6 +903,7 @@ type generateParams struct {
|
||||||
noTxs bool // Flag whether an empty block without any transaction is expected
|
noTxs bool // Flag whether an empty block without any transaction is expected
|
||||||
// <specular modification>
|
// <specular modification>
|
||||||
txs types.Transactions // Transactions to include at the start of the block
|
txs types.Transactions // Transactions to include at the start of the block
|
||||||
|
gasLimit *uint64 // Optional gas limit override
|
||||||
// <specular modification/>
|
// <specular modification/>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -958,6 +959,15 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
|
||||||
header.GasLimit = core.CalcGasLimit(parentGasLimit, w.config.GasCeil)
|
header.GasLimit = core.CalcGasLimit(parentGasLimit, w.config.GasCeil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// <specular modification>
|
||||||
|
if genParams.gasLimit != nil { // override gas limit if specified
|
||||||
|
header.GasLimit = *genParams.gasLimit
|
||||||
|
} else if w.chain.Config().EnableL2GasLimitApi && w.config.GasCeil != 0 {
|
||||||
|
// configure the gas limit of pending blocks with the miner gas limit config when L2 gas limit config is enabled
|
||||||
|
header.GasLimit = w.config.GasCeil
|
||||||
|
}
|
||||||
|
// <specular modification/>
|
||||||
|
|
||||||
// Apply EIP-4844, EIP-4788.
|
// Apply EIP-4844, EIP-4788.
|
||||||
if w.chainConfig.IsCancun(header.Number, header.Time) {
|
if w.chainConfig.IsCancun(header.Number, header.Time) {
|
||||||
var excessBlobGas uint64
|
var excessBlobGas uint64
|
||||||
|
|
@ -1031,6 +1041,9 @@ func (w *worker) generateWork(params *generateParams) *newPayloadResult {
|
||||||
}
|
}
|
||||||
defer work.discard()
|
defer work.discard()
|
||||||
// <specular modification>
|
// <specular modification>
|
||||||
|
if work.gasPool == nil {
|
||||||
|
work.gasPool = new(core.GasPool).AddGas(work.header.GasLimit)
|
||||||
|
}
|
||||||
for _, tx := range params.txs {
|
for _, tx := range params.txs {
|
||||||
from, _ := types.Sender(work.signer, tx)
|
from, _ := types.Sender(work.signer, tx)
|
||||||
work.state.SetTxContext(tx.Hash(), work.tcount)
|
work.state.SetTxContext(tx.Hash(), work.tcount)
|
||||||
|
|
|
||||||
|
|
@ -333,6 +333,10 @@ type ChainConfig struct {
|
||||||
Ethash *EthashConfig `json:"ethash,omitempty"`
|
Ethash *EthashConfig `json:"ethash,omitempty"`
|
||||||
Clique *CliqueConfig `json:"clique,omitempty"`
|
Clique *CliqueConfig `json:"clique,omitempty"`
|
||||||
IsDevMode bool `json:"isDev,omitempty"`
|
IsDevMode bool `json:"isDev,omitempty"`
|
||||||
|
|
||||||
|
// <specular modification>
|
||||||
|
EnableL2GasLimitApi bool `json:"enableL2GasLimitApi,omitempty"`
|
||||||
|
// <specular modification/>
|
||||||
}
|
}
|
||||||
|
|
||||||
// EthashConfig is the consensus engine configs for proof-of-work based sealing.
|
// EthashConfig is the consensus engine configs for proof-of-work based sealing.
|
||||||
|
|
@ -365,6 +369,10 @@ func (c *ChainConfig) Description() string {
|
||||||
}
|
}
|
||||||
banner += fmt.Sprintf("Chain ID: %v (%s)\n", c.ChainID, network)
|
banner += fmt.Sprintf("Chain ID: %v (%s)\n", c.ChainID, network)
|
||||||
switch {
|
switch {
|
||||||
|
// <specular modification>
|
||||||
|
case c.EnableL2GasLimitApi:
|
||||||
|
banner += "Consensus: L2 gas limit API enabled\n"
|
||||||
|
// <specular modification/>
|
||||||
case c.Ethash != nil:
|
case c.Ethash != nil:
|
||||||
if c.TerminalTotalDifficulty == nil {
|
if c.TerminalTotalDifficulty == nil {
|
||||||
banner += "Consensus: Ethash (proof-of-work)\n"
|
banner += "Consensus: Ethash (proof-of-work)\n"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue