You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Refactor billing logic for smart contracts to improve payment tracking, overdraft handling, and fund reservations.
* Redesign off-chain worker logic to enhance billing effectiveness and prevent failures.
* Improve management of contract payments, focusing on overdue payments and grace periods.
*Enhance logging and error management to reduce the risk of unstable contract states.
* Introduce new events for better visibility into billing processes.
* Adjust utilization revenue distribution.
* Address bugs to improve billing reliability.
* Update benchmarks and weights for all pallets, and adjust relevant tests.
---------
# 23. Billing Refactor in pallet-smart-contract Module
2
+
3
+
Date: 2024-08-18
4
+
5
+
## Status
6
+
7
+
Accepted
8
+
9
+
## Context
10
+
11
+
The billing logic within the pallet-smart-contract module faced several issues, including critical bugs, inefficiencies in handling validators, and inadequate fund reservation mechanisms.
12
+
The goal of this refactor was to address these issues while enhancing the overall reliability and robustness of the billing process.
13
+
14
+
## Decision
15
+
16
+
The following architectural decisions were made to improve the billing logic:
17
+
18
+
### Refactoring Billing Logic
19
+
20
+
- Enhanced Tracking:
21
+
Improved tracking mechanisms were introduced for contract payments, especially during grace periods and when handling overdue payments.
22
+
The new ContractPaymentState was introduced to accurately manage contract payment states and resolve liquidity issues.
23
+
- Overdraft Handling:
24
+
Partial payments are now allowed, where users can cover part of their billing due if they lack sufficient funds for the full amount. Overdraft are tracked separately.
25
+
- Fund Reservation:
26
+
The use of balance locks/freezes was replaced with a more reliable reservation system, reducing issues related to fund availability for reward distribution.
27
+
28
+
### Improved Off-Chain Worker Logic
29
+
30
+
- Runtime Verification:
31
+
The is_next_block_author function was removed, with verification now occurring at runtime.
32
+
This change ensures transaction fees are reliably waived for validators and still prevents duplicate transactions.
33
+
34
+
### New Events Introduced
35
+
36
+
- ContractGracePeriodElapsed: Indicates that a contract's grace period has elapsed.
37
+
- ContractPaymentOverdrawn: Indicates that a contract's payment is overdrawn.
38
+
- RewardDistributed: Indicates that rewards have been distributed.
39
+
40
+
### Certified vs DIY Capacity
41
+
42
+
The system now correctly charges certified capacity at a higher rate (25% more) than DIY capacity.
43
+
44
+
## Consequences
45
+
46
+
- Increased Robustness: The billing process is now more robust and less prone to errors, particularly in scenarios involving partial payments and fund reservations.
47
+
- Better Visibility: The introduction of new events and improved logging provides better visibility into the billing and payment processes, aiding in debugging and monitoring.
48
+
- Backward Compatibility: While significant refactoring has been done, efforts were made to ensure backward compatibility where possible, especially concerning contract migration.
0 commit comments