|
| 1 | +--- |
| 2 | +Postmortem ID: 6 |
| 3 | +Title: Stake duration bonus not enabled for nft bucket |
| 4 | +Author: Chen Chen <chenchen@iotex.me> |
| 5 | +Created: 2023-10-10 |
| 6 | +Updated: 2023-11-09 |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +# Abstract |
| 11 | + |
| 12 | +During the testing of the Staking as NFT(IIP-13) feature on Mainnet, it was found that the vote calculation of the NFT Bucket was incorrect. This resulted in a slight decrease in the calculation of delegate total votes and the distribution of bucket rewards. To fix this issue, a hard fork upgrade is required. |
| 13 | + |
| 14 | +# Cause |
| 15 | + |
| 16 | +The votes for the NFT Bucket only calculate the staked amount and does not consider the weighting of stake duration and stake-lock. |
| 17 | + |
| 18 | +**Incorrect calculation** |
| 19 | + |
| 20 | +$$votes=amount$$ |
| 21 | + |
| 22 | +**The correct** |
| 23 | + |
| 24 | +$$votes=amount*(1+\log_{1.2}{(duration/86400)(1+m)})$$ |
| 25 | + |
| 26 | +$$m= \begin{cases} 1 & locked \\ 0 & unlocked \geq 1 \end{cases}$$ |
| 27 | + |
| 28 | +# Solution |
| 29 | + |
| 30 | +Using the accurate formula for vote calculation post hard-fork height. State patching is unnecessary as NFT votes are calculated in real-time, instead of being stored in the database. Also ensure the consistency of the vote calculation formula across blockchain, rewarding service, and web/mobile. |
| 31 | + |
| 32 | +We calculate the rewards for NFT staking from epoch 37021 to 39613 based on the new reward rules and provide users with a one-time supplemental payment for the difference. The details are shown below: |
| 33 | + |
| 34 | +| Reward Address (io) | Reward Address (eth) | Rewards (IOTX) | |
| 35 | +| ----------------------------------------- | ------------------------------------------ | -------------- | |
| 36 | +| io1q77yjjytau2t0yrs656djzu6xe63umuj9afq6j | 0x07bc49488bef14b79070d534d90b9a36751e6f92 | 226.1097975 | |
| 37 | +| io19jg5h2r5m9qfpwswdat8jzacadk5cljl9j4m98 | 0x2c914ba874d94090ba0e6f56790bb8eb6d4c7e5f | 218.281543 | |
| 38 | +| io1cdv420ksuerpgkh6wkdete7yq02ulnsp6usfdw | 0xc359553ed0e646145afa759b95e7c403d5cfce01 | 149.3072101 | |
| 39 | +| io1hwugvvl2aumf9jk64vrm98l0vglr923ntq5rfz | 0xbbb88633eaef3692cadaab07b29fef623e32aa33 | 109.3416226 | |
| 40 | +| io1ar4uhyg8l576vp2jl5wzz9wdvg73jhlglwtjad | 0xe8ebcb9107fd3da60552fd1c2115cd623d195fe8 | 81.54376056 | |
| 41 | +| io1yvvlkfcrzlkewye0dc6uaqc4gnvn5wfqkq0ctn | 0x2319fb270317ed97132f6e35ce831544d93a3920 | 42.81638365 | |
| 42 | +| io1e2rfj7mh4ejawp9dy2ns035305xyahlwmhc0c3 | 0xca86997b77ae65d704ad22a707c6917d0c4edfee | 39.67336968 | |
| 43 | +| io1x0d7ju9xmvrcj8u2g6glcpk0vqavcs5968d7j9 | 0x33dbe970a6db07891f8a4691fc06cf603acc4285 | 38.88607628 | |
| 44 | +| io17axg9h32tnjyk65vculc8u9jkegzjl4maevj84 | 0xf74c82de2a5ce44b6a8cc73f83f0b2b650297ebb | 34.01664689 | |
| 45 | +| io19s6f55ux5kuamsyfm7gn93y55tt5yn3c8tm6kj | 0x2c349a5386a5b9ddc089df9132c494a2d7424e38 | 9.705679169 | |
| 46 | +| io1cew5hztn9c5y3d26yuuwdwdl0wxpm3l42a3eta | 0xc65d4b89732e2848b55a2738e6b9bf7b8c1dc7f5 | 8.143316348 | |
| 47 | +| io19un9p5jx2r5x85m4uh8ylmphj22ee0h3myxvl3 | 0x2f2650d24650e863d375e5ce4fec3792959cbef1 | 7.258715476 | |
| 48 | +| io1e933nrdazcv55dwac6mvrn472qcnfvtvx3uuk6 | 0xc963198dbd16194a35ddc6b6c1cebe503134b16c | 6.437383934 | |
| 49 | +| io1wkflcfuupysc00a73h8590377azht4wh3x6lu5 | 0x7593fc279c092187bfbe8dcf42be3ef74575d5d7 | 6.26276931 | |
| 50 | +| io1dcuhfumkk8uznqery04t5cq6edamensask7ef8 | 0x6e3974f376b1f829832323eaba601acb7bbcce1d | 6.181853975 | |
| 51 | +| io1v7ts37jua2py826er9t3hr9tru4nne6csck2zl | 0x679708fa5cea8243ab5919571b8cab1f2b39e758 | 6.021873814 | |
| 52 | +| io1pr774gjrn8ecaug749288mrr3077eh54qfej9e | 0x08fdeaa24399f38ef11ea95473ec638bfdecde95 | 5.704900111 | |
| 53 | +| io14cntt59fx92erdm0h4x7jjmlu0lucf2umelpq2 | 0xae26b5d0a9315591b76fbd4de94b7fe3ffcc255c | 5.298415282 | |
| 54 | +| io1w4jxyy9vrlwzz0ahp2p3n2227a3hxwuna54adp | 0x75646210ac1fdc213fb70a8319a94af763733b93 | 4.904248324 | |
| 55 | +| io1q226ssx0tsw2z4uthtzcd62alq9fmm32ym72sd | 0x0295a840cf5c1ca1578bbac586e95df80a9dee2a | 3.231342886 | |
| 56 | +| io1leaukdnk42lf56eeev3l8f06g8hd0tgmep8z96 | 0xfe7bcb3676aabe9a6b39cb23f3a5fa41eed7ad1b | 2.562878204 | |
| 57 | +| io1k8rmm9jfq0p802qaa426g6gm00nmlsdr5zfa4g | 0xb1c7bd964903c277a81ded55a4691b7be7bfc1a3 | 1.841719759 | |
| 58 | +| io1jslfpm04ady9ht7vm9jl5fy930wa5t8utpwd5d | 0x943e90edf5eb485bafccd965fa24858bddda2cfc | 1.712134574 | |
| 59 | +| io16w526wlurq338h3jxr8a5gw7s7pwepq2lk8l7h | 0xd3a8ad3bfc182313de3230cfda21de8782ec840a | 0.418652519 | |
| 60 | +| io10dmh3t9uthk7w5kuc823fn96ldwg0m8wnfwy2t | 0x7b7778acbc5dede752dcc1d514ccbafb5c87ecee | 0.164680286 | |
| 61 | +| io19snrtfm6742akugdqg84rc5mcntc5e3dkupaad | 0x2c2635a77af555db710d020f51e29bc4d78a662d | 0.150885108 | |
| 62 | +| io15d0f4yzxg6ka6r4x6prdt3mflkcahlaqx7gtf6 | 0xa35e9a904646addd0ea6d046d5c769fdb1dbffa0 | 0.012317156 | |
| 63 | +| io1ftu2zrzl9gd3fxuxg806dylsaa2qjtudsafse7 | 0x4af8a10c5f2a1b149b8641dfa693f0ef54092f8d | 0.007601529 | |
| 64 | + |
| 65 | +# Impact |
| 66 | + |
| 67 | +The main impacts consist of three aspects: |
| 68 | +- On-chain data: NFT Bucket rewards are calculated incorrectly. |
| 69 | +- Partnerships: Integration progress with LSD partnership could be delayed. |
| 70 | +- Teams: Hard fork exhausts the team's human resources. |
| 71 | + |
| 72 | +# Activities |
| 73 | + |
| 74 | +- 2023-09-28 08:20 : Inconsistency found between the displayed Votes on the web and the blockchain |
| 75 | +- 2023-09-28 08:20 : After a small discussion, it was decided to align the web and reward distribution with blockchain |
| 76 | +- 2023-09-29 08:20 : Internal testing of Staking as NFT feature initiated on the mainnet |
| 77 | +- 2023-10-09 05:11 : Feedback received by the group regarding NFT staking bonus votes being zero |
| 78 | +- 2023-10-09 16:11 : After a wide-range discussion, it was decided to fix the vote counting method on blockchain and synchronize the changes to the web and rewarding service |
| 79 | +- 2023-11-06 07:59:45: Redsea hard-fork is activated |
| 80 | + |
| 81 | +# Why does this issue happen? |
| 82 | + |
| 83 | +- Why use incorrect formula |
| 84 | + - The focus was mainly on the processing logic of the NFT bucket itself, such as stake, restake-related procedures. The correctness of the vote counting logic was somewhat neglected. |
| 85 | + - It was assumed that it was equal to the amount without raising this issue. |
| 86 | + - The correct formula was not found, and the programming pattern needs to be improved. |
| 87 | + - Business background is not well understood |
| 88 | +- Why not discover during testnet |
| 89 | + - During unit testing, there was a misconception about vote counting, and the test case was incorrectly written. A formal test case review process is missing |
| 90 | + - Missing comparison of votes data during system integration testing(between chain and analystics) |
| 91 | +- Why not discover during code review |
| 92 | + - The PR was too large, making code review more challenging |
| 93 | + - The code review was not meticulous enough. |
| 94 | + |
| 95 | +# How can we avoid it in the future? |
| 96 | + |
| 97 | +- Raise any doubts you may have |
| 98 | +- Keep PRs as small as possible |
| 99 | +- Enhance Testing |
| 100 | + - Review test cases more carefully |
| 101 | + - Prepare a test plan for major upgrades |
| 102 | + - Monitor data consistency among multiple systems |
| 103 | +- Think as the perspective of user |
| 104 | + |
| 105 | +# Appendix |
| 106 | + |
| 107 | +- [staking fix weighted votes of contract staking bucket #3936](https://github.com/iotexproject/iotex-core/pull/3936) |
0 commit comments