Optimizing to delete a contract in protocol
Context
This MR is a refactoring to improve the speed of the protocol code. When deleting a implicit contract, remove the entire directory because it is less processing than deleting individual files.
Background
There is a function to delete a implicit contract in the protocol code. This function called for a implicit contract when the balance is exhausted by payment.
Contract_storage.delete : Raw_context.t -> Contract_repr.t -> Raw_contract.t tzresult Lwt.t
What I did
I deleted entire the directory when the contract was deleted. see diff: !4342 (diffs)
Remark
Consumed gas cost will be changed
In the current implementation, consume_gas occurs in Storage.Contract.Code.remove and Storage.Contract.Storage.remove.
The cost of a 0 bytes write is always consumed twice, whether the target file path is exists or not.
The new our implementation only removes the tree once, so this is reduced to once.
The unnecessary file spendable will be removed
There is a bug in contract deletion that causes unwanted files ./spendable to remain.
This MR also resolves the problem.
see also: #2155
Testing
I backported this change to Hangzouh protocol and ran replay on 10,000 blocks from level 2111165.
Manually testing the MR
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Document any change to the user interface, including configuration parameters (see node configuration) -
Provide automatic testing (see the testing guide). -
For new features and bug fixes, add an item in the appropriate changelog ( docs/protocols/alpha.rstfor the protocol and the environment,CHANGES.rstat the root of the repository for everything else). -
Select suitable reviewers using the Reviewersfield below. -
Select as Assigneethe next person who should take action on that MR