Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Worldchain support #8044

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13,902 changes: 13,902 additions & 0 deletions src/Nethermind/Chains/worldchain-mainnet.json

Large diffs are not rendered by default.

13,902 changes: 13,902 additions & 0 deletions src/Nethermind/Chains/worldchain-sepolia.json

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions src/Nethermind/Nethermind.Runner/configs/worldchain-mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"$schema": "https://raw.githubusercontent.com/NethermindEth/core-scripts/refs/heads/main/schemas/config.json",
"Init": {
"ChainSpecPath": "chainspec/worldchain-mainnet.json",
"GenesisHash": "0x70d316d2e0973b62332ba2e9768dd7854298d7ffe77f0409ffdb8d859f2d3fa3",
"BaseDbPath": "nethermind_db/worldchain-mainnet",
"LogFileName": "worldchain-mainnet.logs.txt",
"DisableGcOnNewPayload": false
},
"TxPool": {
"BlobsSupport": "Disabled"
},
"Sync": {
"FastSync": true,
"SnapSync": true,
"FastSyncCatchUpHeightDelta": "10000000000"
},
"Discovery": {
"DiscoveryVersion": "V5"
},
"JsonRpc": {
"Enabled": true,
"Port": 8545,
"EnginePort": 8551
},
"Pruning": {
"PruningBoundary": 192
},
"Blocks": {
"SecondsPerSlot": 2,
"TargetBlockGasLimit": 30000000
},
"Merge": {
"Enabled": true
},
"Optimism": {
"SequencerUrl": "https://worldchain-mainnet-sequencer.g.alchemy.com"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://raw.githubusercontent.com/NethermindEth/core-scripts/refs/heads/main/schemas/config.json",
"Init": {
"ChainSpecPath": "chainspec/worldchain-mainnet.json",
"GenesisHash": "0x70d316d2e0973b62332ba2e9768dd7854298d7ffe77f0409ffdb8d859f2d3fa3",
"BaseDbPath": "nethermind_db/worldchain-mainnet-archive",
"LogFileName": "worldchain-mainnet-archive.logs.txt",
"DisableGcOnNewPayload": false
},
"TxPool": {
"BlobsSupport": "Disabled"
},
"Discovery": {
"DiscoveryVersion": "V5"
},
"Receipt": {
"TxLookupLimit": 0
},
"Pruning": {
"Mode": "None"
},
"JsonRpc": {
"Enabled": true,
"Port": 8545,
"EnginePort": 8551
},
"Optimism": {
"SequencerUrl": "https://worldchain-mainnet-sequencer.g.alchemy.com"
}
}
39 changes: 39 additions & 0 deletions src/Nethermind/Nethermind.Runner/configs/worldchain-sepolia.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"$schema": "https://raw.githubusercontent.com/NethermindEth/core-scripts/refs/heads/main/schemas/config.json",
"Init": {
"ChainSpecPath": "chainspec/worldchain-sepolia.json",
"GenesisHash": "0xf1deb67ee953f94d8545d2647918687fa8ba1f30fa6103771f11b7c483984070",
"BaseDbPath": "nethermind_db/worldchain-sepolia",
"LogFileName": "worldchain-sepolia.logs.txt",
"DisableGcOnNewPayload": false
},
"TxPool": {
"BlobsSupport": "Disabled"
},
"Sync": {
"FastSync": true,
"SnapSync": true,
"FastSyncCatchUpHeightDelta": "10000000000"
},
"Discovery": {
"DiscoveryVersion": "V5"
},
"JsonRpc": {
"Enabled": true,
"Port": 8545,
"EnginePort": 8551
},
"Pruning": {
"PruningBoundary": 192
},
"Blocks": {
"SecondsPerSlot": 2,
"TargetBlockGasLimit": 30000000
},
"Merge": {
"Enabled": true
},
"Optimism": {
"SequencerUrl": "https://worldchain-sepolia-sequencer.g.alchemy.com"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://raw.githubusercontent.com/NethermindEth/core-scripts/refs/heads/main/schemas/config.json",
"Init": {
"ChainSpecPath": "chainspec/worldchain-sepolia.json",
"GenesisHash": "0xf1deb67ee953f94d8545d2647918687fa8ba1f30fa6103771f11b7c483984070",
"BaseDbPath": "nethermind_db/worldchain-archive",
"LogFileName": "worldchain-archive.logs.txt",
"DisableGcOnNewPayload": false
},
"TxPool": {
"BlobsSupport": "Disabled"
},
"Discovery": {
"DiscoveryVersion": "V5"
},
"Receipt": {
"TxLookupLimit": 0
},
"Pruning": {
"Mode": "None"
},
"JsonRpc": {
"Enabled": true,
"Port": 8545,
"EnginePort": 8551
},
"Optimism": {
"SequencerUrl": "https://worldchain-sepolia-sequencer.g.alchemy.com"
}
}
43 changes: 37 additions & 6 deletions src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,17 @@ private static void LoadAllocations(ChainSpecJson chainSpecJson, ChainSpec chain
return;
}

Dictionary<Hash256, byte[]> codes = new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this dictionary and can just use chainSpecJson.CodeHashes directly later to conserve a bit of memory.

codes[Hash256.Zero] = [];
if (chainSpecJson.CodeHashes is not null)
{
foreach (KeyValuePair<string, byte[]> codeHash in chainSpecJson.CodeHashes)
{
if (ValueKeccak.Compute(codeHash.Value) != new ValueHash256(codeHash.Key)) throw new ArgumentException($"Unexpected code {codeHash.Key}");
codes[new(codeHash.Key)] = codeHash.Value;
}
}

chainSpec.Allocations = new Dictionary<Address, ChainSpecAllocation>();
foreach (KeyValuePair<string, AllocationJson> account in chainSpecJson.Accounts)
{
Expand All @@ -363,12 +374,32 @@ private static void LoadAllocations(ChainSpecJson chainSpecJson, ChainSpec chain
continue;
}

chainSpec.Allocations[new Address(account.Key)] = new ChainSpecAllocation(
account.Value.Balance ?? UInt256.Zero,
account.Value.Nonce,
account.Value.Code,
account.Value.Constructor,
account.Value.GetConvertedStorage());
if (account.Value.CodeHash is not null && account.Value.Code is not null)
{
throw new ArgumentException("CodeHash and Code are both not null");
}

Address address = new(account.Key);

if (account.Value.CodeHash is not null)
{
if (codes is null || !codes.ContainsKey(account.Value.CodeHash)) throw new ArgumentException($"CodeHash {account.Value.CodeHash} is not found");
chainSpec.Allocations[address] = new ChainSpecAllocation(
account.Value.Balance ?? UInt256.Zero,
account.Value.Nonce,
codes[account.Value.CodeHash],
account.Value.Constructor,
account.Value.GetConvertedStorage());
}
else
{
chainSpec.Allocations[address] = new ChainSpecAllocation(
account.Value.Balance ?? UInt256.Zero,
account.Value.Nonce,
account.Value.Code!,
account.Value.Constructor,
account.Value.GetConvertedStorage());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.Linq;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
using Nethermind.Int256;

Expand All @@ -16,11 +17,13 @@ internal class AllocationJson

public UInt256 Nonce { get; set; }

public byte[] Code { get; set; }
public byte[]? Code { get; set; }

public byte[] Constructor { get; set; }
public Dictionary<string, string> Storage { get; set; }

public Hash256? CodeHash { get; set; }

public Dictionary<UInt256, byte[]> GetConvertedStorage()
{
return Storage?.ToDictionary(static s => Bytes.FromHexString(s.Key).ToUInt256(), static s => Bytes.FromHexString(s.Value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal class ChainSpecJson
public string[] Nodes { get; set; }
[JsonPropertyName("accounts")]
public Dictionary<string, AllocationJson> Accounts { get; set; }
public Dictionary<string, byte[]>? CodeHashes { get; set; }

internal class EngineJson
{
Expand Down
Loading