Skip to content

Idea: Add support for Dynamic Pre Allocation #2561

@raxhvl

Description

@raxhvl

I think, the way we handle "pre alloc" is hitting a wall.

Currently our tests have "Static Allocation"
We embed the pre-state directly into the genesis file. It is simple, but it does not scale for large states.

Dynamic Alloc

We need a new flavor of allocation: Dynamic Allocation
In this case, the genesis block remains slim. We inject pre-state it via RPC calls once the client is live. The "setup" becomes a separate, a portable payload (dynmic_alloc.json?) added to our text fixtures.

We could hint the type of allocation we use by having a type field in our test fixture payload (or test runners could infer it by checking presense of dynamic_alloc.json)

Pseudo-code for the Test Runner 
if test.type == "dynamic": 
   # Inject the heavy state via RPC 
   Rpc.run(test.dynamic_alloc.payload) 

# Start client and load genesis
client.start(test.gensis) 

# Run the actual test 
Rpc.run(test.payload) 

How to dynamic alloc

we can use markers in our pytest functions. This keeps the system backwards compatible.

  • Standard tests: Remain unmarked and use the current genesis-based allocation.
  • Heavy tests: Use a specific marker to trigger the creation of a dynamic alloc.
@pytest.mark.dynamic_alloc() 
def test_erc20_sload(): 
# This automatically creates the dynamic allocation artifact pass 

We could further simplify by letting "fill" handle this for us, and remove need for any marking.
The filler can monitor the state size during test generation.
If the account count or storage slots cross a specific threshold, the filler automatically switches the test to Dynamic Allocation.

if pre_state.size > THRESHOLD: 
    test.type = "dynamic" test.generate_rpc_payload() 
    test.generate_slim_genesis() 
else: test.type = "static" 
    # current worfklow; prealloc embeded in genesis 
    test.generate_full_genesis()  

This makes the transition invisible to the developer, and fill adapts to allocation size.

Related #2125

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions