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

Improve data destruction in EVM #1347

Closed
1 task done
DmytroNazarenko opened this issue Jan 18, 2023 · 13 comments · Fixed by #1546, #1554 or #1556
Closed
1 task done

Improve data destruction in EVM #1347

DmytroNazarenko opened this issue Jan 18, 2023 · 13 comments · Fixed by #1546, #1554 or #1556
Assignees
Labels
enhancement New feature or request release:2.2
Milestone

Comments

@DmytroNazarenko
Copy link
Collaborator

DmytroNazarenko commented Jan 18, 2023

There was an ineffective algorithm for data destruction in EVM that got fixed.

We iterate over LevelDB keys belonging to the account that has been destroyed and remove them

See also

Tasks

Preview Give feedback
  1. 1 of 1
    Technical debt release:2.2
    olehnikolaiev
@kladkogex
Copy link
Collaborator

Assigning to myself since I am already working on making data cleanup more effective

@DmytroNazarenko
Copy link
Collaborator Author

Check after levelDB update

@DmytroNazarenko DmytroNazarenko moved this from Ready For Pickup to In Progress in SKALE Engineering 🚀 May 4, 2023
@kladkogex kladkogex linked a pull request Jun 18, 2023 that will close this issue
@kladkogex kladkogex changed the title Consensus issues during data destruction Fix data destruction Jun 18, 2023
@kladkogex kladkogex changed the title Fix data destruction Fix data destruction in EVM Jun 18, 2023
@kladkogex kladkogex linked a pull request Jun 18, 2023 that will close this issue
@oleksandrSydorenkoJ
Copy link

STR: TC-1288

@github-project-automation github-project-automation bot moved this from In Progress to Ready For Release Candidate in SKALE Engineering 🚀 Jun 20, 2023
@DmytroNazarenko DmytroNazarenko linked a pull request Jun 21, 2023 that will close this issue
@DmytroNazarenko
Copy link
Collaborator Author

3.17.0-beta.1

@DmytroNazarenko DmytroNazarenko moved this from Ready For Release Candidate to Merged To Release Candidate in SKALE Engineering 🚀 Jun 21, 2023
@EvgeniyZZ EvgeniyZZ moved this from Merged To Release Candidate to QA in SKALE Engineering 🚀 Jun 21, 2023
@olehnikolaiev olehnikolaiev linked a pull request Jun 21, 2023 that will close this issue
@oleksandrSydorenkoJ
Copy link

Verified on Regression network
schain:3.17.0-beta.5

20 MB = 7 seconds
100 MB = 29 seconds

skaled_selfdestruct.log

@DmytroNazarenko
Copy link
Collaborator Author

DmytroNazarenko commented Sep 12, 2023

In this version we have switched on back the algorithm of destruction of the contracts' state, that is called by SELFDESTRUCT opcode. The algorithm is enabled from the storageDestructionPatchTimestamp. In the new version version of algorithm we iterate over LevelDB keys belonging to the account that has been destroyed and remove them. In the end all data in leveldb belonging to this account should be destroyed and the disk space should be freed accordingly

For the future investigation: #1644

@oleksandrSydorenkoJ
Copy link

oleksandrSydorenkoJ commented Sep 12, 2023

Self destruct function clears only contract's address, but not contract data.
And example 2.1.1 release, where selfdestruct function doesn't work at all

free-basic-rosy-SKALE
0xf97fA6B3c51D0ddfB83dE0e5fa5958528f3A2125
after deploy contract
"skaledDBUsage":{"blocks.db_disk_usage":272286815,"contractStorageUsed":136448,"pieceUsageBytes":89196093,"state.db_disk_usage":23122031}
after fill 1 mb of data 
npx hardhat getStorageUsage --network custom
1048576 bytes
"skaledDBUsage":{"blocks.db_disk_usage":272363541,"contractStorageUsed":1185056,"pieceUsageBytes":89207223,"state.db_disk_usage":22663530}
after selfDestruct
"skaledDBUsage":{"blocks.db_disk_usage":272494557,"contractStorageUsed":1185024,"pieceUsageBytes":89223476,"state.db_disk_usage":22664152}


on 2.1.1
breakable-anguished-tania-borealis
0x7c97049C499A30e204049a99F2281D3F2028e009
deploy
"skaledDBUsage":{"blocks.db_disk_usage":1093688091,"contractStorageUsed":39136,"pieceUsageBytes":15433841,"state.db_disk_usage":143017211}
upload 1 mb
"skaledDBUsage":{"blocks.db_disk_usage":1090131971,"contractStorageUsed":1087744,"pieceUsageBytes":15444995,"state.db_disk_usage":142040055}
1048576 bytes
"skaledDBUsage":{"blocks.db_disk_usage":1090486470,"contractStorageUsed":1087744,"pieceUsageBytes":15488002,"state.db_disk_usage":142040677}

Also, eth_getStorageAt show empty values after invoking self-destruct
3.16.1

> eth.getStorageAt('0xBC8606f37DF53Dce8E0F6bd6277E1d51C9438b56', "0x44faaa7d34c7d33bb0a48136375a3a746e717d5882d9e0a96571c9cd081ef069" )
"0x0000000000000000000000000000000000000000000000000000000000001c11"
> eth.getStorageAt('0xBC8606f37DF53Dce8E0F6bd6277E1d51C9438b56', "0x0" )
"0x0000000000000000000000000000000000000000000000000000000000008000"
> eth.getStorageAt('0xBC8606f37DF53Dce8E0F6bd6277E1d51C9438b56', "0x1" )
"0x00000000000000000000000071cbe3fede33905d4d1bf2bd51f9d4a62375e659"
> eth.getStorageAt('0xBC8606f37DF53Dce8E0F6bd6277E1d51C9438b56', "0x1" )
"0x0000000000000000000000000000000000000000000000000000000000000000"
> eth.getStorageAt('0xBC8606f37DF53Dce8E0F6bd6277E1d51C9438b56', "0x0" )
"0x0000000000000000000000000000000000000000000000000000000000000000"
> eth.getStorageAt('0xBC8606f37DF53Dce8E0F6bd6277E1d51C9438b56', "0x44faaa7d34c7d33bb0a48136375a3a746e717d5882d9e0a96571c9cd081ef069" )
"0x0000000000000000000000000000000000000000000000000000000000000000"

3.17.0-beta.8
Before self-destruct

> eth.getStorageAt('0xC63D41a176b54CCbb421C7Ddf65911b16A975BC7', "0x00a7e657b5a63a54839534ca6890ce88767f226b1483dc57dea10c3336f0548a")
"0x0000000000000000000000000000000000000000000000000000000000000563"
> eth.getStorageAt('0xC63D41a176b54CCbb421C7Ddf65911b16A975BC7', "0x1")
"0x000000000000000000000000b04a7f2cd74eb624df4bd8bed8f7034b5aed89c0"
> eth.getStorageAt('0xC63D41a176b54CCbb421C7Ddf65911b16A975BC7', "0x0")
"0x0000000000000000000000000000000000000000000000000000000000008000"

After self-destruct

> eth.getStorageAt('0xC63D41a176b54CCbb421C7Ddf65911b16A975BC7', "0x0")
"0x0000000000000000000000000000000000000000000000000000000000000000"
> eth.getStorageAt('0xC63D41a176b54CCbb421C7Ddf65911b16A975BC7', "0x1")
"0x0000000000000000000000000000000000000000000000000000000000000000"
> eth.getStorageAt('0xC63D41a176b54CCbb421C7Ddf65911b16A975BC7', "0x00a7e657b5a63a54839534ca6890ce88767f226b1483dc57dea10c3336f0548a")
"0x0000000000000000000000000000000000000000000000000000000000000000"

State_db still have key-value pairs 3.17.0-beta.8 after self-destruct

key:  c63d41a176b54ccbb421c7ddf65911b16a975bc70113557b3410a630f4e95dcd051a3e42b109fe18ede68d73ecbd10ccfef205bd
value:  00000000000000000000000000000000000000000000000000000000000073c3
key:  c63d41a176b54ccbb421c7ddf65911b16a975bc70114dd330fa5b9b7d551f118de8f46fe7ef6f16a5c8fbfb44270e2c48c6a11ba
value:  0000000000000000000000000000000000000000000000000000000000005eeb

@PolinaKiporenko PolinaKiporenko moved this from To Do to Ready For Pickup in SKALE Engineering 🚀 Sep 13, 2023
@PolinaKiporenko PolinaKiporenko moved this from Ready For Pickup to In Progress in SKALE Engineering 🚀 Sep 13, 2023
@DmytroNazarenko DmytroNazarenko moved this from In Progress to Code Review in SKALE Engineering 🚀 Sep 16, 2023
@DmytroNazarenko DmytroNazarenko moved this from Code Review to In Progress in SKALE Engineering 🚀 Sep 16, 2023
@PolinaKiporenko PolinaKiporenko moved this from In Progress to Code Review in SKALE Engineering 🚀 Sep 21, 2023
@PolinaKiporenko PolinaKiporenko moved this from Code Review to Ready For Release Candidate in SKALE Engineering 🚀 Sep 22, 2023
@oleksandrSydorenkoJ
Copy link

Actual for 3.17.0-develop.60

@oleksandrSydorenkoJ oleksandrSydorenkoJ moved this from Ready For Release Candidate to Ready For Pickup in SKALE Engineering 🚀 Sep 22, 2023
@PolinaKiporenko PolinaKiporenko moved this from Ready For Pickup to In Progress in SKALE Engineering 🚀 Sep 26, 2023
@DmytroNazarenko DmytroNazarenko moved this from In Progress to Code Review in SKALE Engineering 🚀 Sep 27, 2023
@kladkogex
Copy link
Collaborator

What we find out today that keys are deleted from LevelDB - the calls to delete are executed.

When you delete keys in LevelDB, it does not immediately descrease the size on disk. LevelDB does compaction from time to time, at that point space is freed

There is a way in LevelDB to manually ask to compact a range of keys. It includes lots of code changes, so I am moving this to 2.3.

I

@oleksandrSydorenkoJ
Copy link

oleksandrSydorenkoJ commented Sep 29, 2023

Verified on 3.17.0-develop.62
Need to re-test on beta

What we find out today that keys are deleted from LevelDB - the calls to delete are executed.

When you delete keys in LevelDB, it does not immediately descrease the size on disk. LevelDB does compaction from time to time, at that point space is freed

There is a way in LevelDB to manually ask to compact a range of keys. It includes lots of code changes, so I am moving this to 2.3.

will be fixed in a separate issue #1682

@oleksandrSydorenkoJ
Copy link

Verified on 3.17.0-beta.12

contract a3DfffF1DF4A9F4387b3e1CdCC5cB958dcd84667
1 MB of data cleared in 0.1 second

2023-10-05 13:13:00.477840   createBlock ID = #48481

2023-10-05 13:13:00.477911   Dropping good txn 5a8d4d942d089107348692f9847ee83c9520d17e64bdd5839c9f19691e4338c2

2023-10-05 13:13:00.477947   m_received = 0

2023-10-05 13:13:00.478179   Self-destructing#a3dffff1…
2023-10-05 13:13:00.478197   Iterating over the LevelDB prefix: �����J�C�����\�X��Fg
2023-10-05 13:13:00.589864   Self-destruct cleared values:32770

2023-10-05 13:13:00.709771   Block sealed #48481 (#ac687eca…)
2023-10-05 13:13:00.709808   Block stats:BN:48480:BTS:1696511577:TXS:3:HDRS:11:LOGS:40:SENGS:1:TXRS:61:BLCKS:3:ACCS:150:BQS:1:BDS:14552:TSS:0:UTX:0:VTX:0:CMM:15009185:KDS:32779

state DB:
before self-destruct:

Keys starting from LevelDB prefix a3DfffF1DF4A9F4387b3e1CdCC5cB958dcd84667: 32772
total key amount:  131441
total value amount: 131441

After seldFesdtruct function

Keys starting from LevelDB prefix a3DfffF1DF4A9F4387b3e1CdCC5cB958dcd84667: 0
Total key amount:  98669
Total value amount: 98669

@DmytroNazarenko DmytroNazarenko moved this from Code Review to Ready For Release Candidate in SKALE Engineering 🚀 Oct 18, 2023
@EvgeniyZZ EvgeniyZZ moved this from Ready For Release Candidate to Done in SKALE Engineering 🚀 Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment