Need an explanation on cancel lease patches

Help needed, i am working on lease processing for an independent from nodes blockchain explorer and noticed duplicates on cancel lease txs, waves developers patched it here:, but i do not understand logic in patches, can someone explain?

Here is an example to explain:

We see some lease and cancel lease txs, but all cancel lease txs are cancelling only first lease tx (4X85MhqxukwaPqJC4sSSeN3ptSYHbEca7KgiYtUa2ECX). How does a node calculate zero here?

Moreover, if these cancel tx duplicates seem wrong, why a legal lease tx canceled from 3N65xeNsETsQT6NncwpufwVAkTpiabRRpUm?


In the early days of leasing we had several bugs with it, like one could cancel the same lease twice.
There were more, you can find relative examples in tests. To revert unlawful mining balance changes, all leases were canceled at some point, and minig power was reset for each miner. Hence patch, cancelling all leases

Another patch I remember was relative to leasing funds that were leased to an account.

The rest details depend on what you are actually trying to achieve.

I am trying to reproduce effective balance calculation independently on mainnet and testnet.

My current approach is very naive:

It works but not precise as we have this counterexample:

Where all leases are canceled even (seems) a legal one:

If you provide a simple algorithm how this happened it would be great. For example:

  • we apply patch X at height H
  • we looking for all effective balances with < 0
  • we reset all leases with no exceptions for addresses with effective balance < 0

if you look into blockdiffer, you’ll see three different patches applied at certain heights:

The issue that you are struggling with is different.
You are looking at account which, if I remember correctly, cancelled a lease which another account performed, multiple times. This is one bizzare instersection of bugs, and we have to support it in consensus for that time:

Here, it’s canceller, not the leaser, who decreased lease-out.

Now, if your goal is to process waves blockchain with your code, you’ll have to reimplement all these issues, probably by writing tests.
What exact block or transaction are you struggling with?

Thank you, solved.

I didn’t notice these magic constants:

1 Like