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

Fix NEO callstates #3599

Merged
merged 21 commits into from
Dec 19, 2024
Merged
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
Prev Previous commit
Next Next commit
Reuse Load from stream
shargon committed Nov 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 2dd5e29c291743a76b2110102231a43891edfdc5
47 changes: 40 additions & 7 deletions src/Neo/ProtocolSettings.cs
Original file line number Diff line number Diff line change
@@ -125,13 +125,13 @@ public record ProtocolSettings
public static ProtocolSettings Custom { get; set; }

/// <summary>
/// Loads the <see cref="ProtocolSettings"/> at the specified path.
/// Loads the <see cref="ProtocolSettings"/> from the specified stream.
/// </summary>
/// <param name="stream">The stream of the settings.</param>
/// <returns>The loaded <see cref="ProtocolSettings"/>.</returns>
public static ProtocolSettings Load(Stream stream)
{
using var config = new ConfigurationBuilder().AddJsonStream(stream).Build();
var config = new ConfigurationBuilder().AddJsonStream(stream).Build();
shargon marked this conversation as resolved.
Show resolved Hide resolved
var section = config.GetSection("ProtocolConfiguration");
var settings = Load(section);
CheckingHardfork(settings);
@@ -146,11 +146,21 @@ public static ProtocolSettings Load(Stream stream)
/// <returns>The loaded <see cref="ProtocolSettings"/>.</returns>
public static ProtocolSettings Load(string path, bool optional = true)
{
using var config = new ConfigurationBuilder().AddJsonFile(path, optional).Build();
var section = config.GetSection("ProtocolConfiguration");
var settings = Load(section);
CheckingHardfork(settings);
return settings;
if (!File.Exists(path))
{
if (optional)
shargon marked this conversation as resolved.
Show resolved Hide resolved
{
// Same as default
return Load(Default);
}
else
{
throw new FileNotFoundException(path);
}
}

using var stream = File.OpenRead(path);
return Load(stream);
}

/// <summary>
@@ -183,6 +193,29 @@ public static ProtocolSettings Load(IConfigurationSection section)
return Custom;
}

/// <summary>
/// Loads the <see cref="ProtocolSettings"/> cloning another <see cref="ProtocolSettings"/>.
/// </summary>
/// <param name="settings">The <see cref="IConfigurationSection"/> to be cloned.</param>
/// <returns>The loaded <see cref="ProtocolSettings"/>.</returns>
public static ProtocolSettings Load(ProtocolSettings settings)
{
return Custom = new ProtocolSettings
{
Network = settings.Network,
AddressVersion = settings.AddressVersion,
StandbyCommittee = [.. settings.StandbyCommittee], // Clone
ValidatorsCount = settings.ValidatorsCount,
SeedList = [.. settings.SeedList], // Clone
MillisecondsPerBlock = settings.MillisecondsPerBlock,
MaxTransactionsPerBlock = settings.MaxTransactionsPerBlock,
MemoryPoolMaxTransactions = settings.MemoryPoolMaxTransactions,
MaxTraceableBlocks = settings.MaxTraceableBlocks,
InitialGasDistribution = settings.InitialGasDistribution,
Hardforks = settings.Hardforks // Already immutable
};
}

/// <summary>
/// Explicitly set the height of all old omitted hardforks to 0 for proper IsHardforkEnabled behaviour.
/// </summary>