Skip to content

Commit d8f9638

Browse files
cmd, params: implement Gray Glacier hard-fork (EIP-5133) (#25088)
* cmd/geth, params: implement Gray Glacier (EIP-5133) * cmd/evm: add gray glacier tests * params: nitpicks * params: fixes
1 parent 3060216 commit d8f9638

File tree

18 files changed

+100
-35
lines changed

18 files changed

+100
-35
lines changed

cmd/evm/internal/t8ntool/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ var (
152152
"\n\tSyntax <forkname>(+ExtraEip)",
153153
strings.Join(tests.AvailableForks(), "\n\t "),
154154
strings.Join(vm.ActivateableEips(), ", ")),
155-
Value: "ArrowGlacier",
155+
Value: "GrayGlacier",
156156
}
157157
VerbosityFlag = cli.IntFlag{
158158
Name: "verbosity",

cmd/evm/t8n_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ func TestT8n(t *testing.T) {
211211
output: t8nOutput{result: true},
212212
expOut: "exp_arrowglacier.json",
213213
},
214+
{ // Difficulty calculation on gray glacier
215+
base: "./testdata/19",
216+
input: t8nInput{
217+
"alloc.json", "txs.json", "env.json", "GrayGlacier", "",
218+
},
219+
output: t8nOutput{result: true},
220+
expOut: "exp_grayglacier.json",
221+
},
214222
{ // Sign unprotected (pre-EIP155) transaction
215223
base: "./testdata/23",
216224
input: t8nInput{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"result": {
3+
"stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc",
4+
"txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
5+
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
6+
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
7+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
8+
"receipts": [],
9+
"currentDifficulty": "0x2000000004000",
10+
"gasUsed": "0x0"
11+
}
12+
}

cmd/evm/testdata/19/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
## Difficulty calculation
22

33
This test shows how the `evm t8n` can be used to calculate the (ethash) difficulty, if none is provided by the caller,
4-
this time on `ArrowGlacier` (Eip 4345).
4+
this time on `GrayGlacier` (Eip 5133).
55

6-
Calculating it (with an empty set of txs) using `ArrowGlacier` rules (and no provided unclehash for the parent block):
6+
Calculating it (with an empty set of txs) using `GrayGlacier` rules (and no provided unclehash for the parent block):
77
```
8-
[user@work evm]$ ./evm t8n --input.alloc=./testdata/14/alloc.json --input.txs=./testdata/14/txs.json --input.env=./testdata/14/env.json --output.result=stdout --state.fork=ArrowGlacier
8+
[user@work evm]$ ./evm t8n --input.alloc=./testdata/19/alloc.json --input.txs=./testdata/19/txs.json --input.env=./testdata/19/env.json --output.result=stdout --state.fork=GrayGlacier
99
```

cmd/geth/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
156156
// makeFullNode loads geth configuration and creates the Ethereum backend.
157157
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
158158
stack, cfg := makeConfigNode(ctx)
159-
if ctx.GlobalIsSet(utils.OverrideArrowGlacierFlag.Name) {
160-
cfg.Eth.OverrideArrowGlacier = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideArrowGlacierFlag.Name))
159+
if ctx.GlobalIsSet(utils.OverrideGrayGlacierFlag.Name) {
160+
cfg.Eth.OverrideGrayGlacier = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideGrayGlacierFlag.Name))
161161
}
162162
if ctx.GlobalIsSet(utils.OverrideTerminalTotalDifficulty.Name) {
163163
cfg.Eth.OverrideTerminalTotalDifficulty = utils.GlobalBig(ctx, utils.OverrideTerminalTotalDifficulty.Name)

cmd/geth/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var (
6969
utils.NoUSBFlag,
7070
utils.USBFlag,
7171
utils.SmartCardDaemonPathFlag,
72-
utils.OverrideArrowGlacierFlag,
72+
utils.OverrideGrayGlacierFlag,
7373
utils.OverrideTerminalTotalDifficulty,
7474
utils.EthashCacheDirFlag,
7575
utils.EthashCachesInMemoryFlag,

cmd/utils/flags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ var (
257257
Usage: "Megabytes of memory allocated to bloom-filter for pruning",
258258
Value: 2048,
259259
}
260-
OverrideArrowGlacierFlag = cli.Uint64Flag{
261-
Name: "override.arrowglacier",
262-
Usage: "Manually specify Arrow Glacier fork-block, overriding the bundled setting",
260+
OverrideGrayGlacierFlag = cli.Uint64Flag{
261+
Name: "override.grayglacier",
262+
Usage: "Manually specify Gray Glacier fork-block, overriding the bundled setting",
263263
}
264264
OverrideTerminalTotalDifficulty = BigFlag{
265265
Name: "override.terminaltotaldifficulty",

consensus/ethash/consensus.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ var (
4545
maxUncles = 2 // Maximum number of uncles allowed in a single block
4646
allowedFutureBlockTimeSeconds = int64(15) // Max seconds from current time allowed for blocks, before they're considered future blocks
4747

48+
// calcDifficultyEip5133 is the difficulty adjustment algorithm as specified by EIP 5133.
49+
// It offsets the bomb a total of 11.4M blocks.
50+
// Specification EIP-5133: https://eips.ethereum.org/EIPS/eip-5133
51+
calcDifficultyEip5133 = makeDifficultyCalculator(big.NewInt(11_400_000))
52+
4853
// calcDifficultyEip4345 is the difficulty adjustment algorithm as specified by EIP 4345.
4954
// It offsets the bomb a total of 10.7M blocks.
5055
// Specification EIP-4345: https://eips.ethereum.org/EIPS/eip-4345
@@ -334,6 +339,8 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainHeaderReader, time uin
334339
func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
335340
next := new(big.Int).Add(parent.Number, big1)
336341
switch {
342+
case config.IsGrayGlacier(next):
343+
return calcDifficultyEip5133(time, parent)
337344
case config.IsArrowGlacier(next):
338345
return calcDifficultyEip4345(time, parent)
339346
case config.IsLondon(next):

core/forkid/forkid_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
// the correct fork ID.
3232
func TestCreation(t *testing.T) {
3333
mergeConfig := *params.MainnetChainConfig
34-
mergeConfig.MergeNetsplitBlock = big.NewInt(15000000)
34+
mergeConfig.MergeNetsplitBlock = big.NewInt(18000000)
3535
type testcase struct {
3636
head uint64
3737
want ID
@@ -68,8 +68,10 @@ func TestCreation(t *testing.T) {
6868
{12964999, ID{Hash: checksumToBytes(0x0eb440f6), Next: 12965000}}, // Last Berlin block
6969
{12965000, ID{Hash: checksumToBytes(0xb715077d), Next: 13773000}}, // First London block
7070
{13772999, ID{Hash: checksumToBytes(0xb715077d), Next: 13773000}}, // Last London block
71-
{13773000, ID{Hash: checksumToBytes(0x20c327fc), Next: 0}}, // First Arrow Glacier block
72-
{20000000, ID{Hash: checksumToBytes(0x20c327fc), Next: 0}}, // Future Arrow Glacier block
71+
{13773000, ID{Hash: checksumToBytes(0x20c327fc), Next: 15050000}}, // First Arrow Glacier block
72+
{15049999, ID{Hash: checksumToBytes(0x20c327fc), Next: 15050000}}, // Last Arrow Glacier block
73+
{15050000, ID{Hash: checksumToBytes(0xf0afd0e3), Next: 0}}, // First Gray Glacier block
74+
{20000000, ID{Hash: checksumToBytes(0xf0afd0e3), Next: 0}}, // Future Gray Glacier block
7375
},
7476
},
7577
// Ropsten test cases
@@ -163,9 +165,11 @@ func TestCreation(t *testing.T) {
163165
{12964999, ID{Hash: checksumToBytes(0x0eb440f6), Next: 12965000}}, // Last Berlin block
164166
{12965000, ID{Hash: checksumToBytes(0xb715077d), Next: 13773000}}, // First London block
165167
{13772999, ID{Hash: checksumToBytes(0xb715077d), Next: 13773000}}, // Last London block
166-
{13773000, ID{Hash: checksumToBytes(0x20c327fc), Next: 15000000}}, // First Arrow Glacier block
167-
{15000000, ID{Hash: checksumToBytes(0xe3abe201), Next: 0}}, // First Merge Start block
168-
{20000000, ID{Hash: checksumToBytes(0xe3abe201), Next: 0}}, // Future Merge Start block
168+
{13773000, ID{Hash: checksumToBytes(0x20c327fc), Next: 15050000}}, // First Arrow Glacier block
169+
{15049999, ID{Hash: checksumToBytes(0x20c327fc), Next: 15050000}}, // Last Arrow Glacier block
170+
{15050000, ID{Hash: checksumToBytes(0xf0afd0e3), Next: 18000000}}, // First Gray Glacier block
171+
{18000000, ID{Hash: checksumToBytes(0x4fb8a872), Next: 0}}, // First Merge Start block
172+
{20000000, ID{Hash: checksumToBytes(0x4fb8a872), Next: 0}}, // Future Merge Start block
169173
},
170174
},
171175
}
@@ -242,11 +246,11 @@ func TestValidation(t *testing.T) {
242246
// Local is mainnet Petersburg, remote is Rinkeby Petersburg.
243247
{7987396, ID{Hash: checksumToBytes(0xafec6b27), Next: 0}, ErrLocalIncompatibleOrStale},
244248

245-
// Local is mainnet Arrow Glacier, far in the future. Remote announces Gopherium (non existing fork)
249+
// Local is mainnet Gray Glacier, far in the future. Remote announces Gopherium (non existing fork)
246250
// at some future block 88888888, for itself, but past block for local. Local is incompatible.
247251
//
248252
// This case detects non-upgraded nodes with majority hash power (typical Ropsten mess).
249-
{88888888, ID{Hash: checksumToBytes(0x20c327fc), Next: 88888888}, ErrLocalIncompatibleOrStale},
253+
{88888888, ID{Hash: checksumToBytes(0xf0afd0e3), Next: 88888888}, ErrLocalIncompatibleOrStale},
250254

251255
// Local is mainnet Byzantium. Remote is also in Byzantium, but announces Gopherium (non existing
252256
// fork) at block 7279999, before Petersburg. Local is incompatible.

core/genesis.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig
233233
return SetupGenesisBlockWithOverride(db, genesis, nil, nil)
234234
}
235235

236-
func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideArrowGlacier, overrideTerminalTotalDifficulty *big.Int) (*params.ChainConfig, common.Hash, error) {
236+
func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideGrayGlacier, overrideTerminalTotalDifficulty *big.Int) (*params.ChainConfig, common.Hash, error) {
237237
if genesis != nil && genesis.Config == nil {
238238
return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig
239239
}
@@ -279,8 +279,8 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
279279
}
280280
// Get the existing chain configuration.
281281
newcfg := genesis.configOrDefault(stored)
282-
if overrideArrowGlacier != nil {
283-
newcfg.ArrowGlacierBlock = overrideArrowGlacier
282+
if overrideGrayGlacier != nil {
283+
newcfg.GrayGlacierBlock = overrideGrayGlacier
284284
}
285285
if overrideTerminalTotalDifficulty != nil {
286286
newcfg.TerminalTotalDifficulty = overrideTerminalTotalDifficulty
@@ -301,8 +301,8 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
301301
// apply the overrides.
302302
if genesis == nil && stored != params.MainnetGenesisHash {
303303
newcfg = storedcfg
304-
if overrideArrowGlacier != nil {
305-
newcfg.ArrowGlacierBlock = overrideArrowGlacier
304+
if overrideGrayGlacier != nil {
305+
newcfg.GrayGlacierBlock = overrideGrayGlacier
306306
}
307307
if overrideTerminalTotalDifficulty != nil {
308308
newcfg.TerminalTotalDifficulty = overrideTerminalTotalDifficulty

0 commit comments

Comments
 (0)