uaktags / explorer

An open source block explorer
BSD 3-Clause "New" or "Revised" License
6 stars 8 forks source link

Explorer show minus balance on wallet when self transfer occurs #42

Open minkcrypto-zz opened 5 years ago

minkcrypto-zz commented 5 years ago

https://explorer.cpuchain.org/address/CPZ1y3vwjW8xcqL7H7w2xdSvRipUMatG11

Very strange 🤔

uaktags commented 5 years ago

Please give some examples of what the self transfers are.

There's some pecularities though. How is https://explorer.cpuchain.org/tx/841dbe832d448b69fa6cc7794f8a9ea945c7d1ae96355642ab3bfb4d1ecfca27 able to occur? The address only received 6.35cpu prior to making its first tx tx/841dbe832d448b69fa6cc7794f8a9ea945c7d1ae96355642ab3bfb4d1ecfca27 which totalled 11.23cpu. Only 3.74 went out, but that means that there was 7.49 left over with no indication of where that additional 4.88cpu came from.

My sync also has different values than yours.

2019-07-10 05_16_55-CPUchain Block Explorer - Vivaldi 2019-07-10 05_16_26-CPUC - Vivaldi

So something seems amiss.

minkcrypto-zz commented 5 years ago

I assume this transaction is a problem https://explorer.cpuchain.org/tx/6491d766fb903407a7bf20949d0ebf285e35aa795aef07a3c27756fcf342981f

minkcrypto-zz commented 5 years ago

This issue is a show stopper, have you figured out?

uaktags commented 5 years ago

I'm still looking into it. It's a first time i've ever seen anything like that appear and it's only showing on this coin (none of my other 3 coins i use for dev purposes).

uaktags commented 5 years ago

It's definitely an issue with this explorer and not iquidus though.

2019-07-20 16_45_15-IQUIDUS - Vivaldi 2019-07-20 16_45_28-CPUchain Block Explorer - Vivaldi

minkcrypto-zz commented 5 years ago

You mean it is a problem with forked one but not for original?

uaktags commented 5 years ago

image So the issue is basically somewhere around this step. What's being calculated appears to be the input's negative and not the sum of the input/output. In this case, the very first transaction where we see an issue start, it should be -3.74 because of the -11, only 3.74 went somewhere.

"You mean it is a problem with the forked one but not for original?" Yes, it's a problem with some logic in my fork and is not present in the original Iquidius. I have a number of explorers running with your CPUCoin on it to just test this, and Original Iquidus appears to handle this fine, it's mine that has some broken logic.

minkcrypto-zz commented 5 years ago

Understood 😂

uaktags commented 5 years ago

It looks like the breakage comes from this: https://github.com/iquidus/explorer/pull/270 which was brought into uaktasg/explorer by this commit: https://github.com/uaktags/explorer/commit/89d91ea2cac316517628c4d34cda480eaae05840

minkcrypto-zz commented 5 years ago

So we may revert or fix the commit 🤔

uaktags commented 5 years ago

Only the database.js file where the applicable change is needed, still testing to find out what part of it is not working right. The rest of the commit and PR was useful and still good

uaktags commented 5 years ago

I've gotten closer to this, but still can't seem to nail it correctly.

uaktags commented 5 years ago

This is where i'm almost at so far:

node .\test\cpu-test.js
344cfb3b40078a693c40ed2fb28e0c05ad2fb0fb09cc939beaab072fff067274
Balance Amount:  3.74261505
d1ccf73676779a03b0f4e9458d986d92e7017c1b6b769a52f3ffb854f3d5343a
Balance Amount:  6.35007129
841dbe832d448b69fa6cc7794f8a9ea945c7d1ae96355642ab3bfb4d1ecfca27
Balance Amount:  2.60745624
d6cb8c0c270751968a894a4bf3b0e3cefedee2192ed1ab06ba0da148fefc27c4
Balance Amount:  5.60738584
a1af5337f954652e4bc414496c5d09229c70de9c5d0226de30f0d4d498faab33
Balance Amount:  7.07141328
f787c0fd22d45db10bc11cf692e0f32dfbc1abdb9808878c223657f3a4e5267f
Balance Amount:  8.08410395
2b8fc015d57f71fb613acfa4b2d035b52d6949dda59aff85a1b20fc7eec8b7af
Balance Amount:  9.24540919
8bf82e0a5153500522f309fb64fd9aff85070220d0c91947978d6db35ac878d2
Balance Amount:  10.84085951
bfae7a6dce8bd7c185f96e51d3d236daf622c8bc93b6f35e3bb5298a5270a2a0
Balance Amount:  12.55098529
77e6daf878c02477072f9b62f109aeb6f387e05f3f94f353dcba196127f2d0d3
Balance Amount:  13.6310135
e3661d7579b07de16b14242030409464365efa2a9e9f872da0a5ddf275c710f7
Balance Amount:  14.70028375
a0d778d1ad08c6b8f5ee4a0717e22cbf72e1388a7dda657e6a005ee8cc3382ee
Balance Amount:  15.71203137
e41dbefb7c8e60c61d5459664b28c8155895b4b6bcd4ee33925540128762e282
Balance Amount:  16.72055625
2b5ff9be29a7ea62937b7592e0454e124343d61fd2756c32ed19980b813e253c
Balance Amount:  -5.65390587

compared to the OG Iquidus

date | hash | tx-amount | address-balance
8th   Jul 2019 01:11:15 | 2b5ff9be29a7ea62937b7592e0454e124343d61fd2756c32ed19980b813e253c | -16.7205563 | -0.000000000000003553
8th Jul 2019 00:55:21 | e41dbefb7c8e60c61d5459664b28c8155895b4b6bcd4ee33925540128762e282 | 1.00852488 | 16.72055625
7th   Jul 2019 23:55:16 | a0d778d1ad08c6b8f5ee4a0717e22cbf72e1388a7dda657e6a005ee8cc3382ee | 1.01174762 | 15.71203137
7th Jul 2019 21:55:13 | e3661d7579b07de16b14242030409464365efa2a9e9f872da0a5ddf275c710f7 | 1.06927025 | 14.70028375
7th   Jul 2019 19:53:01 | 77e6daf878c02477072f9b62f109aeb6f387e05f3f94f353dcba196127f2d0d3 | 1.08002821 | 13.6310135
7th Jul 2019 17:51:28 | bfae7a6dce8bd7c185f96e51d3d236daf622c8bc93b6f35e3bb5298a5270a2a0 | 1.71012578 | 12.55098529
7th   Jul 2019 15:50:13 | 8bf82e0a5153500522f309fb64fd9aff85070220d0c91947978d6db35ac878d2 | 1.59545032 | 10.84085951
7th Jul 2019 12:50:28 | 2b8fc015d57f71fb613acfa4b2d035b52d6949dda59aff85a1b20fc7eec8b7af | 1.16130524 | 9.24540919
7th   Jul 2019 09:52:48 | f787c0fd22d45db10bc11cf692e0f32dfbc1abdb9808878c223657f3a4e5267f | 1.01269067 | 8.08410395
7th Jul 2019 06:47:33 | a1af5337f954652e4bc414496c5d09229c70de9c5d0226de30f0d4d498faab33 | 1.46402744 | 7.07141328
7th   Jul 2019 05:07:49 | d6cb8c0c270751968a894a4bf3b0e3cefedee2192ed1ab06ba0da148fefc27c4 | 2.9999296 | 5.60738584
7th Jul 2019 05:05:29 | 841dbe832d448b69fa6cc7794f8a9ea945c7d1ae96355642ab3bfb4d1ecfca27 | -3.74261505 | 2.60745624
7th   Jul 2019 03:46:45 | d1ccf73676779a03b0f4e9458d986d92e7017c1b6b769a52f3ffb854f3d5343a | 2.60745624 | 6.35007129
7th Jul 2019 02:46:41 | 344cfb3b40078a693c40ed2fb28e0c05ad2fb0fb09cc939beaab072fff067274 | 3.74261505 | 3.74261505

so now my problem area is to figure out what about 2b5ff9be29a7ea62937b7592e0454e124343d61fd2756c32ed19980b813e253c is breaking things.

uaktags commented 5 years ago

https://gist.github.com/uaktags/facf765727f4eec2fb05a7e580538b84

this is what i'm working with right now for testing purposes.

minkcrypto-zz commented 5 years ago

Hmm that script seems good

uaktags commented 5 years ago

This is really pissing me off, because I feel like it's sitting right in front of me. Here's some current test results, there's definitely an issue with calculating the vin amounts:

PS C:\Users\tim\Documents\git\official-explorer> node .\test\cpu-test.js
rec: 20.4631713, sent: 3.74261505, amount: 28.00332721, balance: 16.72055625, type: vin
PS C:\Users\tim\Documents\git\official-explorer> node .\test\cpu-test.js
rec: 20.4631713, sent: 3.74261505, amount: 18.87266996, balance: 16.72055625, type: vin
PS C:\Users\tim\Documents\git\official-explorer> node .\test\cpu-test.js
rec: 20.4631713, sent: 3.74261505, amount: 22.90676948, balance: 16.72055625, type: vin
PS C:\Users\tim\Documents\git\official-explorer> node .\test\cpu-test.js
[
  {
    addresses: 'CPC2V6crVr5imZLdipes23Du4Yi64EzJns',
    amount: 222767175
  },
  {
    addresses: 'CPZ1y3vwjW8xcqL7H7w2xdSvRipUMatG11',
    amount: 1887266996
  }
]
rec: 20.4631713, sent: 3.74261505, amount: 18.87266996, balance: 16.72055625, type: vin
PS C:\Users\tim\Documents\git\official-explorer> ^C
PS C:\Users\tim\Documents\git\official-explorer> node .\test\cpu-test.js
duplicate
duplicate
[
  {
    addresses: 'CPC2V6crVr5imZLdipes23Du4Yi64EzJns',
    amount: 222767175
  },
  {
    addresses: 'CPZ1y3vwjW8xcqL7H7w2xdSvRipUMatG11',
    amount: 2176334068
  }
]
rec: 20.4631713, sent: 3.74261505, amount: 21.76334068, balance: 16.72055625, type: vin
PS C:\Users\tim\Documents\git\official-explorer> node .\test\cpu-test.js
[
  {
    addresses: 'CPC2V6crVr5imZLdipes23Du4Yi64EzJns',
    amount: 222767175
  },
  {
    addresses: 'CPZ1y3vwjW8xcqL7H7w2xdSvRipUMatG11',
    amount: 1932400673
  }
]

for some reason, once I get to particular tx, it miscalculates the vin amount for the address

uaktags commented 5 years ago

There's definitely a miscalculation going on with the vins. So the tx in question for me right now is 2b5ff9be29a7ea62937b7592e0454e124343d61fd2756c32ed19980b813e253c It's the one, above, that's been seeing so many different values for CPZ1y3vwjW8xcqL7H7w2xdSvRipUMatG11. So if I go through the vins manually (and then go through and grab the values and addresses from the subsequent vouts), and throw it into a script, I get the following: https://gist.github.com/uaktags/174470d1de2c48d29218c97c7326e17c which has this output:

node cpu-test2.js
[
  CPC2V6crVr5imZLdipes23Du4Yi64EzJns: 0.74255725,
  CPZ1y3vwjW8xcqL7H7w2xdSvRipUMatG11: 16.720556249999998
]

This will then mean that we go from having a balance of 16.72055625 at the end of e41dbefb7c8e60c61d5459664b28c8155895b4b6bcd4ee33925540128762e282 to being 0.

uaktags commented 5 years ago

So this isn't related to just my repo either. It's been a reported issue at the OG one as well for different coins. This seems really weird.

https://github.com/iquidus/explorer/issues/293

TheHolyRoger commented 4 years ago

This is fixed in #319 but not merged yet, awaiting review