Skip to content

Conversation

@nytzuga
Copy link
Contributor

@nytzuga nytzuga commented Nov 2, 2023

Why this should be merged

Write a benchmark with a smart contract that will do a lot of inserts in the TrieDB to test and measure our improvements.

How this works

A smart contract has been created that inserts N number of elements in each transaction. The main goal is to effortlessly to make the EVM do a lot of inserts in the triedb and measure their performance.

How this was tested

How is this documented

@nytzuga nytzuga self-assigned this Nov 2, 2023
@nytzuga nytzuga force-pushed the trie-stress-test branch 4 times, most recently from 374e3bf to f520abe Compare November 14, 2023 17:16
Comment on lines 78 to 172
for {
gas -= gasTx
if gas < gasTx {
break
}
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(benchRootAddr), contractAddr, big.NewInt(0), gasTx, gasPrice, txPayload), signer, testKey)
gen.AddTx(tx)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to remove the gas calculation in favor of leaving it to the caller to ensure that the parameters they specify don't exceed the gas limit.

In my opinion, it's simpler to do it this way because it removes a bit of logic that is not necessary for the test and it's very reasonable to make that the responsibility of the caller imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it better now @aaronbuchwald? The gas calculation is to split the contract creations into multiple blocks, but no other gas calculation is being used.

@nytzuga nytzuga marked this pull request as ready for review November 15, 2023 22:12
@nytzuga nytzuga added this to the v0.5.10 milestone Nov 15, 2023
@nytzuga nytzuga changed the title Draft: Trie stress test Trie stress test Nov 15, 2023
@nytzuga nytzuga force-pushed the trie-stress-test branch 2 times, most recently from 533e771 to 920f16c Compare November 20, 2023 03:23
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this file required? if not can we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the source code of the smart contract. I think it should be included but it is your call. @ceyonur . What should be done?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This file is not being directly used (compiled files like .abi and .bin used) in tests. This really doesn't fit the purpose of contracts folder which is to provide examples/libraries for other smart contracts on chain. So we should either remove this, or if we want to keep it we should move all of these to a subpackage under core like core/trietest (assuming we don't need any unexported stuff from core package)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm moving to their folder inside core as suggested.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I meant moving the test as well to the same subpackage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ceyonur functions inside the tests files cannot be exported unfortunately. Unless a bigger refactor is involved this test must be inside core /cc @aaronbuchwald

This smart contract will append N new elements to a vector, this is a stress
test to our implementation of the trie structure
Make bench more generic and simpler to bootstrap
Remove gas calculation from benchmarks, gas is still calculated to make sure
all contracts are deployed.

stressTestTrieDb takes 3 arguments. The number of contracts to deploy, the
calls for each block and the numbers of elements to append to the vector on
each call
This function will treat execution errors as errors as well, useful for
testing.

ApplyTransaction has been modified to return the ExecutionResult
Breaking API changes should be avoided
Use existing code instead, reading the receipt from the last execution instead
of returning the exceutionresult struct
aaronbuchwald
aaronbuchwald previously approved these changes Nov 22, 2023
@ceyonur
Copy link
Collaborator

ceyonur commented Nov 23, 2023

I just want to make sure we're on the same page with benchmark target, this looked a bit static for me.
Also there is one unresolved convo here Other than that LGTM

ceyonur
ceyonur previously approved these changes Nov 29, 2023
aaronbuchwald
aaronbuchwald previously approved these changes Nov 29, 2023
Co-authored-by: aaronbuchwald <[email protected]>
Signed-off-by: Cesar <[email protected]>
@nytzuga nytzuga dismissed stale reviews from aaronbuchwald and ceyonur via 5e67ae9 November 29, 2023 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project
Status: In Review 👀

Development

Successfully merging this pull request may close these issues.

4 participants