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 EngineRequestGenerator tool #7266

Open
wants to merge 90 commits into
base: master
Choose a base branch
from

Conversation

marcindsobczak
Copy link
Contributor

@marcindsobczak marcindsobczak commented Jul 17, 2024

Changes

  • adding tool used for gas limit project to main repo

Despite of more than 3500 lines of code it is safe to be merged to the master - most of lines is just newly added code to EngineRequestGenerator project. From main solution, only 2 classes are modified:

  • TestBlockchain
  • EngineModuleTests.Setup

Types of changes

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: tool for gas limit project

Testing

Requires testing

  • Yes
  • No

Documentation

Requires documentation update

  • Yes
  • No

Copy link
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

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

A lot of memory inefficiency - is it at least fast?
Where lists are temporary we could use ArrayPoolList.
Changes to main classes could be done better.

@@ -131,32 +134,35 @@ protected virtual async Task<TestBlockchain> Build(ISpecProvider? specProvider =
TrieStore = new TrieStore(StateDb, LogManager);
State = new WorldState(TrieStore, DbProvider.CodeDb, LogManager, new PreBlockCaches());

// Eip4788 precompile state account
if (specProvider?.GenesisSpec?.IsBeaconBlockRootAvailable ?? false)
if (!keepStateEmpty)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of adding a parameter maybe better to:

  1. Put below state modifying code into virtual method and then override it and do nothing.
  2. Have a property That indicates if state should be empty - set it or override it in usages.

Comment on lines +18 to +20
List<byte> currentWord = i == 0
? initCode.Slice(0, initCode.Count % 32)
: initCode.Slice((int)i - 32 + initCode.Count % 32, 32);
Copy link
Member

Choose a reason for hiding this comment

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

Use Spans


// push memory offset - i
byte[] memoryOffset = i.ToBigEndianByteArrayWithoutLeadingZeros();
if (memoryOffset is [0])
Copy link
Member

Choose a reason for hiding this comment

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

why not compare i here?

}

// push size of init code to read from memory
byte[] sizeOfInitCode = initCode.Count.ToByteArray().WithoutLeadingZeros().ToArray();
Copy link
Member

Choose a reason for hiding this comment

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

ToArray() x2

return byteCode;
}

private static List<byte> GenerateInitCode(List<byte> codeToDeploy)
Copy link
Member

Choose a reason for hiding this comment

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

same stuff here

Comment on lines +27 to +29
var str = JsonConvert.SerializeObject(metadatas);

await File.WriteAllTextAsync($"{_outputPath}/metadata.json", str);
Copy link
Member

Choose a reason for hiding this comment

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

Serialize directly to file

Comment on lines +56 to +59
if (attributes == null || attributes.Length != 1)
throw new ArgumentException("Incorrect amount of attributes found");

return attributes[0];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (attributes == null || attributes.Length != 1)
throw new ArgumentException("Incorrect amount of attributes found");
return attributes[0];
return attributes?.First() ?? throw new ArgumentException("Incorrect amount of attributes found");

codeToDeploy.Add((byte)Instruction.MSTORE8);


byte[] stateVector = new byte[64];
Copy link
Member

Choose a reason for hiding this comment

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

stackalloc?

codeToDeploy.Add((byte)Instruction.MSTORE);


byte[] messageBlockVector = new byte[128];
Copy link
Member

Choose a reason for hiding this comment

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

stackalloc?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants