From d21a0696197cd87165aed2d7bc5b8bf965580f91 Mon Sep 17 00:00:00 2001
From: Martin Holst Swende <martin@swende.se>
Date: Tue, 6 Jul 2021 10:35:39 +0200
Subject: [PATCH] eth, miner: add RPC method to modify miner gaslimit (pre
 london: ceiling) (#23134)

---
 eth/api.go                  | 6 ++++++
 internal/web3ext/web3ext.go | 6 ++++++
 miner/miner.go              | 6 ++++++
 miner/worker.go             | 6 ++++++
 4 files changed, 24 insertions(+)

diff --git a/eth/api.go b/eth/api.go
index 6a22c9e41..8b96d1f31 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -129,6 +129,12 @@ func (api *PrivateMinerAPI) SetGasPrice(gasPrice hexutil.Big) bool {
 	return true
 }
 
+// SetGasLimit sets the gaslimit to target towards during mining.
+func (api *PrivateMinerAPI) SetGasLimit(gasLimit hexutil.Uint64) bool {
+	api.e.Miner().SetGasCeil(uint64(gasLimit))
+	return true
+}
+
 // SetEtherbase sets the etherbase of the miner
 func (api *PrivateMinerAPI) SetEtherbase(etherbase common.Address) bool {
 	api.e.SetEtherbase(etherbase)
diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go
index a7b326692..9f9b2ba35 100644
--- a/internal/web3ext/web3ext.go
+++ b/internal/web3ext/web3ext.go
@@ -641,6 +641,12 @@ web3._extend({
 			params: 1,
 			inputFormatter: [web3._extend.utils.fromDecimal]
 		}),
+		new web3._extend.Method({
+			name: 'setGasLimit',
+			call: 'miner_setGasLimit',
+			params: 1,
+			inputFormatter: [web3._extend.utils.fromDecimal]
+		}),
 		new web3._extend.Method({
 			name: 'setRecommitInterval',
 			call: 'miner_setRecommitInterval',
diff --git a/miner/miner.go b/miner/miner.go
index 714367926..a4a01b9f4 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -204,6 +204,12 @@ func (miner *Miner) SetEtherbase(addr common.Address) {
 	miner.worker.setEtherbase(addr)
 }
 
+// SetGasCeil sets the gaslimit to strive for when mining blocks post 1559.
+// For pre-1559 blocks, it sets the ceiling.
+func (miner *Miner) SetGasCeil(ceil uint64) {
+	miner.worker.setGasCeil(ceil)
+}
+
 // EnablePreseal turns on the preseal mining feature. It's enabled by default.
 // Note this function shouldn't be exposed to API, it's unnecessary for users
 // (miners) to actually know the underlying detail. It's only for outside project
diff --git a/miner/worker.go b/miner/worker.go
index 05dcc3650..457f32915 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -244,6 +244,12 @@ func (w *worker) setEtherbase(addr common.Address) {
 	w.coinbase = addr
 }
 
+func (w *worker) setGasCeil(ceil uint64) {
+	w.mu.Lock()
+	defer w.mu.Unlock()
+	w.config.GasCeil = ceil
+}
+
 // setExtra sets the content used to initialize the block extra field.
 func (w *worker) setExtra(extra []byte) {
 	w.mu.Lock()
-- 
GitLab