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

Dynamic gas data trie loads #4804

Merged
merged 30 commits into from Aug 18, 2023
Merged

Dynamic gas data trie loads #4804

merged 30 commits into from Aug 18, 2023

Conversation

BeniaminDrasovean
Copy link
Contributor

@BeniaminDrasovean BeniaminDrasovean commented Dec 13, 2022

Reasoning behind the pull request

  • The new feature of dynamic gas cost computation based on trie loads needs to be activated at a certain epoch by all nodes.

Proposed changes

  • Add a new flag DynamicGasCostForDataTrieStorageLoadEnableEpoch that will enable at the specified epoch the computation of gas cost for data trie loads based on the depth of the trie.

Testing procedure

  • Create a smart contract with multiple leaves in the dataTrie. When a leaf is accessed, check that the gas cost is computed dynamically based on the depth of the leaf.

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

…-trie-loads

# Conflicts:
#	cmd/node/config/enableEpochs.toml
#	cmd/node/config/gasSchedules/gasScheduleV7.toml
#	common/enablers/enableEpochsHandler.go
#	common/enablers/epochFlags.go
#	config/epochConfig.go
#	go.mod
#	go.sum
@codecov-commenter
Copy link

codecov-commenter commented Dec 14, 2022

Codecov Report

Patch coverage: 50.00% and project coverage change: -0.02% ⚠️

Comparison is base (02d6610) 80.10% compared to head (8a46f6e) 80.09%.
Report is 1 commits behind head on rc/v1.6.0.

❗ Current head 8a46f6e differs from pull request most recent head 12a225a. Consider uploading reports for the commit 12a225a to get more accurate results

Additional details and impacted files
@@              Coverage Diff              @@
##           rc/v1.6.0    #4804      +/-   ##
=============================================
- Coverage      80.10%   80.09%   -0.02%     
=============================================
  Files            708      706       -2     
  Lines          93408    93359      -49     
=============================================
- Hits           74821    74772      -49     
+ Misses         13275    13271       -4     
- Partials        5312     5316       +4     
Files Changed Coverage Δ
common/enablers/epochFlags.go 98.70% <33.33%> (-0.65%) ⬇️
common/enablers/enableEpochsHandler.go 100.00% <100.00%> (ø)

... and 9 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

# The current values for the coefficients were computed based on benchmarking
[DynamicStorageLoad]
A = 687
SignOfA = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking for better naming...

@BeniaminDrasovean BeniaminDrasovean marked this pull request as ready for review December 22, 2022 12:04
…-trie-loads

# Conflicts:
#	cmd/node/config/enableEpochs.toml
#	common/enablers/enableEpochsHandler.go
#	common/enablers/epochFlags.go
#	common/interface.go
#	config/epochConfig.go
#	go.mod
#	go.sum
#	sharding/mock/enableEpochsHandlerMock.go
#	testscommon/enableEpochsHandlerStub.go
…-trie-loads

# Conflicts:
#	go.mod
#	go.sum
#	integrationTests/vm/txsFee/multiShard/asyncCall_test.go
#	integrationTests/vm/txsFee/multiShard/asyncESDT_test.go
#	integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go
#	integrationTests/vm/txsFee/multiShard/scCalls_test.go
#	integrationTests/vm/txsFee/relayedScCalls_test.go
#	integrationTests/vm/txsFee/scCalls_test.go
#	integrationTests/vm/wasm/utils.go
@@ -236,6 +236,9 @@
# WipeSingleNFTLiquidityDecreaseEnableEpoch represents the epoch when the system account liquidity is decreased for wipeSingleNFT as well
WipeSingleNFTLiquidityDecreaseEnableEpoch = 5

# DynamicGasCostForDataTrieStorageLoadEnableEpoch represents the epoch when dynamic gas cost for data trie storage load will be enabled
DynamicGasCostForDataTrieStorageLoadEnableEpoch = 6
Copy link
Contributor

Choose a reason for hiding this comment

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

switch the value to 3? (what will come from rc/v1.4.0 will have all the other values set to 2)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -691,3 +691,16 @@
MaxBuiltInCallsPerTx = 100
MaxNumberOfTransfersPerTx = 100
MaxNumberOfTrieReadsPerTx = 100

# Quadratic, Linear and Constant are the coefficients for a quadratic func. Separate variables are used for the
# sign of each coefficient, 0 meaning + and 1 meaning -
Copy link
Contributor

Choose a reason for hiding this comment

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

0 meaning positive and 1 meaning negative?
as it reads better. Valid on all the other gasmaps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -91,6 +91,7 @@ type EnableEpochs struct {
RefactorPeersMiniBlocksEnableEpoch uint32
MaxBlockchainHookCountersEnableEpoch uint32
WipeSingleNFTLiquidityDecreaseEnableEpoch uint32
DynamicGasCostForDataTrieStorageLoadEnableEpoch uint32
Copy link
Contributor

Choose a reason for hiding this comment

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

also adapt tests in the tomlConfig_test.go ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -11,14 +11,17 @@ import (
"testing"

"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/integrationTests"
Copy link
Contributor

Choose a reason for hiding this comment

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

please add a semiintegration test here in which you test the transaction fee is computed correctly if the DynamicGasCostForDataTrieStorageLoad is activated. Suggestion to have 2 tests: one when using the SaveKeyValue builtin function and one using a contract that can add data (maybe using an internal array or something).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

…-trie-loads

# Conflicts:
#	cmd/node/config/gasSchedules/gasScheduleV1.toml
#	cmd/node/config/gasSchedules/gasScheduleV2.toml
#	cmd/node/config/gasSchedules/gasScheduleV3.toml
#	cmd/node/config/gasSchedules/gasScheduleV4.toml
#	cmd/node/config/gasSchedules/gasScheduleV5.toml
#	cmd/node/config/gasSchedules/gasScheduleV6.toml
#	cmd/node/config/gasSchedules/gasScheduleV7.toml
#	common/enablers/enableEpochsHandler.go
#	common/enablers/epochFlags.go
#	common/interface.go
#	config/epochConfig.go
#	sharding/mock/enableEpochsHandlerMock.go
#	testscommon/enableEpochsHandlerStub.go
…-trie-loads

# Conflicts:
#	config/tomlConfig_test.go
#	go.mod
#	go.sum
go.sum Outdated
@@ -611,14 +611,14 @@ github.com/multiversx/mx-chain-storage-go v1.0.7 h1:UqLo/OLTD3IHiE/TB/SEdNRV1GG2
github.com/multiversx/mx-chain-storage-go v1.0.7/go.mod h1:gtKoV32Cg2Uy8deHzF8Ud0qAl0zv92FvWgPSYIP0Zmg=
github.com/multiversx/mx-chain-vm-common-go v1.3.34/go.mod h1:sZ2COLCxvf2GxAAJHGmGqWybObLtFuk2tZUyGqnMXE8=
github.com/multiversx/mx-chain-vm-common-go v1.3.36/go.mod h1:sZ2COLCxvf2GxAAJHGmGqWybObLtFuk2tZUyGqnMXE8=
github.com/multiversx/mx-chain-vm-common-go v1.3.37 h1:KeK6JCjeNUOHC5Z12/CTQIa8Z1at0dnnL9hY1LNrHS8=
github.com/multiversx/mx-chain-vm-common-go v1.3.37/go.mod h1:sZ2COLCxvf2GxAAJHGmGqWybObLtFuk2tZUyGqnMXE8=
github.com/multiversx/mx-chain-vm-common-go v1.3.38-0.20230227140728-5bd58c1e7990 h1:AYpgFg+jhi90nuxK8sRFyFPovSvQgbF4wdo025SrsFE=
Copy link
Contributor

Choose a reason for hiding this comment

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

proper release after initial tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add a proper release right before merge

integrationTests/testInitializer.go Show resolved Hide resolved
integrationTests/vm/txsFee/dynamicGasCost_test.go Outdated Show resolved Hide resolved
integrationTests/vm/txsFee/dynamicGasCost_test.go Outdated Show resolved Hide resolved
integrationTests/vm/txsFee/dynamicGasCost_test.go Outdated Show resolved Hide resolved
@ssd04 ssd04 self-requested a review February 28, 2023 13:41
Comment on lines 785 to 786
RuntimeMemStoreLimitEnableEpoch: 63,
DynamicGasCostForDataTrieStorageLoadEnableEpoch: 64,
Copy link
Contributor

Choose a reason for hiding this comment

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

go fmt here? plus remove line 690

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@BeniaminDrasovean BeniaminDrasovean changed the base branch from rc/v1.6.0 to feat/vm1.5 March 1, 2023 10:49
@BeniaminDrasovean BeniaminDrasovean changed the base branch from feat/vm1.5 to rc/v1.6.0 March 9, 2023 14:41
@BeniaminDrasovean BeniaminDrasovean marked this pull request as draft March 9, 2023 14:50
BeniaminDrasovean and others added 6 commits June 28, 2023 13:03
…-trie-loads

# Conflicts:
#	common/enablers/enableEpochsHandler.go
#	common/enablers/epochFlags.go
#	common/interface.go
#	config/epochConfig.go
#	config/tomlConfig_test.go
#	go.mod
#	go.sum
#	integrationTests/benchmarks/loadFromTrie_test.go
#	integrationTests/testInitializer.go
#	integrationTests/vm/txsFee/asyncCall_test.go
#	integrationTests/vm/wasm/utils.go
#	sharding/mock/enableEpochsHandlerMock.go
#	testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go
…-trie-loads

# Conflicts:
#	config/tomlConfig_test.go
#	go.sum
#	sharding/mock/enableEpochsHandlerMock.go
gabi-vuls
gabi-vuls previously approved these changes Aug 17, 2023
Copy link
Collaborator

@gabi-vuls gabi-vuls left a comment

Choose a reason for hiding this comment

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

Normal allin test: master-0a0bcee937 -> dynamic-gas-data-trie-load-2a6908a5d3

--- Specific errors ---

block hash does not match 8743
wrong nonce in block 3105
miniblocks does not match 0
num miniblocks does not match 0
miniblock hash does not match 0
block bodies does not match 0
receipts hash missmatch 0

/------/

--- Statistics ---

Nr. of all ERRORS: 3
Nr. of all WARNS: 145
Nr. of new ERRORS: 0
Nr. of new WARNS: 5
Nr. of PANICS: 0

/------/

Copy link
Contributor

@iulianpascalau iulianpascalau left a comment

Choose a reason for hiding this comment

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

just the proper release

Copy link
Collaborator

@gabi-vuls gabi-vuls left a comment

Choose a reason for hiding this comment

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

Normal allin test: master-0a0bcee937 -> dynamic-gas-data-trie-load-12a225a566

--- Specific errors ---

block hash does not match 1080
wrong nonce in block 467
miniblocks does not match 0
num miniblocks does not match 0
miniblock hash does not match 0
block bodies does not match 0
receipts hash missmatch 0

/------/

--- Statistics ---

Nr. of all ERRORS: 0
Nr. of all WARNS: 133
Nr. of new ERRORS: 0
Nr. of new WARNS: 0
Nr. of PANICS: 0

/------/

--- ERRORS ---

/------/

--- WARNINGS ---

/------/

@gabi-vuls gabi-vuls merged commit f7045ec into rc/v1.6.0 Aug 18, 2023
6 checks passed
@gabi-vuls gabi-vuls deleted the dynamic-gas-data-trie-loads branch August 18, 2023 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants