Steem Powr Rent Bug Fix: Update Previous Existing Current Delegation Status to "Premature"

in hive-102132 •  15 hours ago 

The SP Lease when status is "premature" means that the current delegation has not expired and yet a payment is received.

image.png

Previously, dealing this is tricky - and the code was buggy - I manually updated the status to "premature". Let's say if I forgot to do this what would happen?

  1. a payment is received for the delegation to person A for 7 days.
  2. delegation of amount X is given to A.
  3. another payment is sent for the new delegation to person A for 100 days.
  4. delegation of amount Y is given to A. (Y overrides the amount X)
  5. however, after day 7 - the delegation of first record (X amount) will be revoked meaning person A will be delegated none.
  6. day 100, the undelegation will fail because there is no delegation at that moment.

This can be fixed by updating the delegation records at the point of current delegate action is being performed e.g. steem.broadcast.delegateVestingShares. So basically, this:

function updatePrematureLeases(currentRecord) {
  return new Promise((resolve, reject) => {
      const sql = "update `rentsp` set `result`='premature' where `id` < ? and `sender_block` < ? and `ts` < ? and `delegatee` = ? and `result`='leasing' limit 1";
      const values = [
        currentRecord.id, currentRecord.sender_block, currentRecord.ts, currentRecord.delegatee
      ];
      db.connection.query(sql, values).on('result', function (row) {
          resolve(true);
      }).on('error', function (err) {
          resolve(false);
      });
  });
}

Steem to the Moon🚀!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!