aionnetwork / aion_pool2

aion pool implementation with c# core.
13 stars 15 forks source link

Payouts issue stops mined blocks from processing and adding to balance. #3

Closed blake2n closed 6 years ago

blake2n commented 6 years ago

E] [PayoutManager] [aion] Payment processing failed System.OverflowException: Value was either too large or too small for a Decimal. at System.Decimal..ctor(Double value) at MiningCore.Payments.PaymentSchemes.PPLNSPaymentScheme.CalculateRewards(PoolConfig poolConfig, Decimal window, Block block, Decimal blockReward, Dictionary2 shares, Dictionary2 rewards) at MiningCore.Payments.PaymentSchemes.PPLNSPaymentScheme.UpdateBalancesAsync(IDbConnection con, IDbTransaction tx, PoolConfig poolConfig, IPayoutHandler payoutHandler, Block block, Decimal blockReward) in /home/foundry/aion_pool2/aion_pool/src/MiningCore/Payments/PaymentSchemes/PPLNSPaymentScheme.cs:line 91 at MiningCore.Payments.PayoutManager.<>cDisplayClass12_1.<b4>d.MoveNext() in sourcedir/aion_pool2/aion_pool/src/MiningCore/Payments/PayoutManager.cs:line 139 --- End of stack trace from previous location where exception was thrown --- at MiningCore.Extensions.ConnectionFactoryExtensions.RunTxAsync(IConnectionFactory factory, Func3 action, Boolean autoCommit, IsolationLevel isolation) in sourcedir/aion_pool2/aion_pool/src/MiningCore/Extensions/ConnectionFactoryExtensions.cs:line 214 at MiningCore.Payments.PayoutManager.UpdatePoolBalancesAsync(PoolConfig pool, IPayoutHandler handler, IPayoutScheme scheme) in sourcedir/aion_pool2/aion_pool/src/MiningCore/Payments/PayoutManager.cs:line 121 at MiningCore.Payments.PayoutManager.ProcessPoolsAsync() in sourcedir/aion_pool2/aion_pool/src/MiningCore/Payments/PayoutManager.cs:line 95 at System.Decimal..ctor(Double value) at MiningCore.Payments.PaymentSchemes.PPLNSPaymentScheme.CalculateRewards(PoolConfig poolConfig, Decimal window, Block block, Decimal blockReward, Dictionary2 shares, Dictionary`2 rewards) at MiningCore.Payments.PaymentSchemes.PPLNSPaymentScheme.UpdateBalancesAsync(IDbConnection con, IDbTransaction tx, PoolConfig poolConfig, IPayoutHandler payoutHandler, Block block, Decimal blockReward) in sourcedir/aion_pool2/aion_pool/src/MiningCore/Payments/PaymentSchemes/PPLNSPaymentScheme.cs:line 91 at MiningCore.Payments.PayoutManager.<>cDisplayClass12_1.<b4>d.MoveNext() in sourcedir/aion_pool2/aion_pool/src/MiningCore/Payments/PayoutManager.cs:line 139 --- End of stack trace from previous location where exception was thrown --- at MiningCore.Extensions.ConnectionFactoryExtensions.RunTxAsync(IConnectionFactory factory, Func`3 action, Boolean autoCommit, IsolationLevel isolation) in sourcedir/aion_pool2/aion_pool/src/MiningCore/Extensions/ConnectionFactoryExtensions.cs:line 214 at MiningCore.Payments.PayoutManager.UpdatePoolBalancesAsync(PoolConfig pool, IPayoutHandler handler, IPayoutScheme scheme) in sourcedir/aion_pool2/aion_pool/src/MiningCore/Payments/PayoutManager.cs:line 121 at MiningCore.Payments.PayoutManager.ProcessPoolsAsync() in sourcedir/aion_pool2/aion_pool/src/MiningCore/Payments/PayoutManager.cs:line 95

blake2n commented 6 years ago

If you have any code modification you wish tested for this problem please post in the comments and will do so.

alinturbut commented 6 years ago

Hi @aionmine-help,

How often does this error reproduce for you?

And care to give more insight on how did you reproduce this?

blake2n commented 6 years ago

Reproduce: import a database with the issue it occurred twice for us.

Please note this was different servers too. Occurrence: One time during testing (private invite). (9 days) One time after becoming public (2 weeks).

as you can see i have an instance read to test https://data.aionmine.org if we manually do payouts I no longer have this. I can only keep the users waiting so long.

The largest accounts outstanding have told me not to payout until fixed because they wish to help. This happened from hashpowerpool twice as reported.

Calculated manual payout for non calculated shares will take some time. We may pay balances manually and add the entry into the DB manually.

blake2n commented 6 years ago

@centrys-alin Hi please message me. It was brought to our attention it could be this part of the config. "address": "0xa0a1e55cbbffc99d9dcaf56e5350847267471cd6d69d4dead14953e5e82d97bf", "rewardRecipients": [ { "address": "0xa0066e02a7d87698339adb95f40a09869fd9e567080c3dc4172da98c3951dcc6", "percentage": 0.00 } ],

Divide by 0 = infinity so we put 0.01% fee during for now. We had trouble firing the pool up with no reward recipient in there.

I'll pm you so when I find the DB entries that caused this.

@Knevil (hashpowerpool) told us he would try to send you his database that incurred the issue also.

blake2n commented 6 years ago

@centrys-alin as per your question I can explain the two things I did that allowed the payout to function again. The system setup used has been improved for us, our db response speed is instant on all requests now and under heavy load.

The first thing we tried was changing the name of this miner nheqminer/0.1.8 to EWBF v0.4 in the DB entries.

We sorted through and found 1 share entry for a block we didn't mine. Simply insert 1 of my shares into your DB and it will fail to process. "aion 755619 6656 13993808 \N a008eb89aaee448efeb28f47e94efbcfd28ef004d3a4345a48d4d405ba182300 \N EWBF v0.4 99.216.96.102 \N 2018-07-24 22:45:13.77908"

alinturbut commented 6 years ago

@aionmine-help,

Thanks for your debugging. Will have a look debugging the issue you describe, but I don't understand how your db response has improved. You mean by adding the correct percentage to the rewardRecipients? Looked into the code and found 2 things:

Debugged this as well on localhost and it works (both situations).

blake2n commented 6 years ago

@centrys-alin Originally we didn't want to rule out the fee. DIV/0

No problem on debugging obviously a manual payout isn't a time worthy solution as we have about 100 blocks to process.

The issue for us was a share for a block not earned.

I'll check the daemon to see if it orphaned.

But I don't understand how your db response has improved?

We changed out setup completely. We are 16 cores strong now.
-> DDOS protected our complete setup and have only been getting reports of attacks without stopping mining blocks or miner disconnected.

Another issue going on is We have one address submitting hundreds of low diff shares a minute.
This was slowing the old setup but on this setup the processor remains under 5% We also patched aionjob to help with lowdiff shares see below which fixed this issue for all users except 1 address.

            throw new StratumException(StratumError.LowDifficultyShare, $"low difficulty share ({shareDiff})");
            // Check if matched a previous varDiff before retarget
            if (context.VarDiff?.LastUpdate != null && context.PreviousDifficulty.HasValue)
            {
                var prevSentTargetInt = new uint256(AionUtils.diffToTarget(context.PreviousDifficulty.Value).HexToByteArray().ReverseArray());
                var prevSentTargetBi = new BigInteger(prevSentTargetInt.ToBytes());
                if (prevSentTargetBi <= headerBigInt)
                {
                    stratumDifficulty = context.PreviousDifficulty.Value;
                }
            }
            else
            {
                throw new StratumException(StratumError.LowDifficultyShare, $"low difficulty share ({shareDiff})");   
            }                
alinturbut commented 6 years ago

@aionmine-help,

The address submitting hundreds of low diff shares is probably the EWBF miner fee coming from all the accounts at once. We have that as well from time to time.

We also fixed the effect of the original problem + some other fixes involving EWBF. We will provide these in this repo this week, so stay tuned. Before, we want to fix the cause of this original bug (the main problem is that there are shares with 0 difficulty, therefore making a 0 division.

All the best and thanks for your testing/debugging/coding.

blake2n commented 6 years ago

@centrys-alin Thank you for fixing the payout issue. Its resolved.