Skip to content

Commit 8f55ea1

Browse files
MariusVanDerWijdencp-wjhan
authored andcommitted
cmd, params: implement Gray Glacier hard-fork (EIP-5133) (ethereum#25088)
* cmd/geth, params: implement Gray Glacier (EIP-5133) * cmd/evm: add gray glacier tests * params: nitpicks * params: fixes * It is not activated in Wemix.
1 parent 5117bf4 commit 8f55ea1

File tree

18 files changed

+101
-36
lines changed

18 files changed

+101
-36
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
@@ -157,8 +157,8 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
157157
// makeFullNode loads geth configuration and creates the Ethereum backend.
158158
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
159159
stack, cfg := makeConfigNode(ctx)
160-
if ctx.GlobalIsSet(utils.OverrideArrowGlacierFlag.Name) {
161-
cfg.Eth.OverrideArrowGlacier = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideArrowGlacierFlag.Name))
160+
if ctx.GlobalIsSet(utils.OverrideGrayGlacierFlag.Name) {
161+
cfg.Eth.OverrideGrayGlacier = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideGrayGlacierFlag.Name))
162162
}
163163
if ctx.GlobalIsSet(utils.OverrideTerminalTotalDifficulty.Name) {
164164
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
@@ -75,7 +75,7 @@ var (
7575
utils.NoUSBFlag,
7676
utils.USBFlag,
7777
utils.SmartCardDaemonPathFlag,
78-
utils.OverrideArrowGlacierFlag,
78+
utils.OverrideGrayGlacierFlag,
7979
utils.OverrideTerminalTotalDifficulty,
8080
utils.EthashCacheDirFlag,
8181
utils.EthashCachesInMemoryFlag,

cmd/utils/flags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ var (
261261
Usage: "Megabytes of memory allocated to bloom-filter for pruning",
262262
Value: 2048,
263263
}
264-
OverrideArrowGlacierFlag = cli.Uint64Flag{
265-
Name: "override.arrowglacier",
266-
Usage: "Manually specify Arrow Glacier fork-block, overriding the bundled setting",
264+
OverrideGrayGlacierFlag = cli.Uint64Flag{
265+
Name: "override.grayglacier",
266+
Usage: "Manually specify Gray Glacier fork-block, overriding the bundled setting",
267267
}
268268
OverrideTerminalTotalDifficulty = BigFlag{
269269
Name: "override.terminaltotaldifficulty",

consensus/ethash/consensus.go

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

50+
// calcDifficultyEip5133 is the difficulty adjustment algorithm as specified by EIP 5133.
51+
// It offsets the bomb a total of 11.4M blocks.
52+
// Specification EIP-5133: https://eips.ethereum.org/EIPS/eip-5133
53+
calcDifficultyEip5133 = makeDifficultyCalculator(big.NewInt(11_400_000))
54+
5055
// calcDifficultyEip4345 is the difficulty adjustment algorithm as specified by EIP 4345.
5156
// It offsets the bomb a total of 10.7M blocks.
5257
// Specification EIP-4345: https://eips.ethereum.org/EIPS/eip-4345
@@ -344,6 +349,8 @@ func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Heade
344349

345350
next := new(big.Int).Add(parent.Number, big1)
346351
switch {
352+
case config.IsGrayGlacier(next):
353+
return calcDifficultyEip5133(time, parent)
347354
case config.IsArrowGlacier(next):
348355
return calcDifficultyEip4345(time, parent)
349356
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
@@ -236,7 +236,7 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig
236236
return SetupGenesisBlockWithOverride(db, genesis, nil, nil)
237237
}
238238

239-
func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideArrowGlacier, overrideTerminalTotalDifficulty *big.Int) (*params.ChainConfig, common.Hash, error) {
239+
func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideGrayGlacier, overrideTerminalTotalDifficulty *big.Int) (*params.ChainConfig, common.Hash, error) {
240240
if genesis != nil && genesis.Config == nil {
241241
return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig
242242
}
@@ -282,8 +282,8 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
282282
}
283283
// Get the existing chain configuration.
284284
newcfg := genesis.configOrDefault(stored)
285-
if overrideArrowGlacier != nil {
286-
newcfg.ArrowGlacierBlock = overrideArrowGlacier
285+
if overrideGrayGlacier != nil {
286+
newcfg.GrayGlacierBlock = overrideGrayGlacier
287287
}
288288
if overrideTerminalTotalDifficulty != nil {
289289
newcfg.TerminalTotalDifficulty = overrideTerminalTotalDifficulty
@@ -304,8 +304,8 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
304304
// apply the overrides.
305305
if genesis == nil && !(stored == params.MainnetGenesisHash || stored == params.WemixMainnetGenesisHash) {
306306
newcfg = storedcfg
307-
if overrideArrowGlacier != nil {
308-
newcfg.ArrowGlacierBlock = overrideArrowGlacier
307+
if overrideGrayGlacier != nil {
308+
newcfg.GrayGlacierBlock = overrideGrayGlacier
309309
}
310310
if overrideTerminalTotalDifficulty != nil {
311311
newcfg.TerminalTotalDifficulty = overrideTerminalTotalDifficulty

0 commit comments

Comments
 (0)