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: https://github.com/wavesplatform/Waves/tree/master/src/main/scala/com/wavesplatform/state/patch, but i do not understand logic in patches, can someone explain?

Here is an example to explain: https://testnet.wavesexplorer.com/address/3MsiHfvFVUULdn8bpVoDQ7JLKKjtPXUrCLT

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?

Hi,

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: https://github.com/deemru/w8io/blob/68361b1bea7c4c95c672a11ae97a2cc3127a7c62/include/w8io_blockchain_transactions.php#L755

It works but not precise as we have this counterexample: https://testnet.wavesexplorer.com/address/3MsiHfvFVUULdn8bpVoDQ7JLKKjtPXUrCLT

Where all leases are canceled even (seems) a legal one: https://testnet.wavesexplorer.com/tx/GW7dUbzDqbH9fkgXMa5kgJNTW2oCcRco5cAwWvCpfHKS

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: https://github.com/wavesplatform/Waves/blob/254c034f55006a4101ced5e1d7537342c49cb425/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala#L51

1 Like