CREDITSCOM / node

Credits Node is the main module that provide an opportunity to run a node and participate in CREDITS blockchain network.
https://developers.credits.com/
GNU Affero General Public License v3.0
151 stars 16 forks source link

Current smart contracts are not suitable for a large number of players who play at the same time #43

Closed PresidentNavalny closed 5 years ago

PresidentNavalny commented 5 years ago

My English is not perfect, so for a better understanding of the problem, after the English description I posted the Russian version of this text because most of the developers are Russian

Describe the bug Current smart contracts are not suitable for a large number of players who play at the same time

To Reproduce I can't show it in testnet network, for the reason that testnet behaves inadequately. It doesn't respond to my requests, then does it after 2 minutes. So I'll show it in the dappsnet network The example in application egyptslot. Same problem in all networks Suppose that in egypetslot(or any other app) plays at the same 10 people. Traffic 10 transactions per second. all bets that will be in the same block will be with the same outcome. Let's say 10 transactions(bets) from different accounts fall into one block. The network will give a block in which there will be either 10 or 20 transactions(depending on whether there was a win or not) All 10 accounts will either receive the same winnings or lose. Example: I placed 3 bets at the same time from different accounts. They fell into one block and all three accounts received the same win or lose. In this case, all 3 bets that hit one block got a win of 4cs. Here is the hash block where there were 3 transactions(rates) from different accounts in one block "34ef00682698feda01233add1cecca471441d4deaf00c2c52ac55b30199a3912" 1 As a result, these bets that were in the same block received the same winnings for 4cs. here's the hash "5ef308db3d5e29dba860560f67c7a3c48798a50de27e44e9836e1818c5a667cc". 2 Here is another example. All bets that were in one block received a win of 8 cs. Безымянный Безымянный2 And this always happens. If there are 50 transactions (bets) in one block. Then these 50 bets will either win the same amount at the same time or lose. What can this lead to? With a large number of bets in one application, all players will either win the same amount at the same time or lose massively at the same time. All bets will have the same outcome for everyone. No randomness. It will be unprofitable for developers of casinos and other decentralized applications. Because in one moment may occur such a situation that all accounts whose transactions have been in the same block, will have to pay out large winnings. For example X10. Developers will suffer great losses

Не могу показать это в сети тестнет, по той причине, что тестнет ведёт себя неадекватно. Он то не отвечает на мои запросы, то делает это спустя 2 минуты. Поэтому я покажу это в сети дапснет. На примере приложения egyptslot. Та же самая проблема есть в сети тестнет, либо любой другой Предположим что в egypetslot(либо в любое другое приложение) играет одновременно 10 человек. Трафик 10 транзакций в секунду. все ставки, которые окажутся в одном блоке будут с одним и тем же исходом. Допустим попадает в один блок 10 транзакций(ставок) с разных аккаунтов. Сеть выдаст в ответ блок в котором будет либо 10 либо 20 транзакций(в зависимости от того был выигрыш или нет) Все 10 аккаунтов получат либо одинаковые выигрыши, либо проиграют. Пример: Я делал 3 ставки одновременно с разных аккаунтов. Они попадали в один блок и все эти три аккаунта получали одинаковый выигрыш, либо проигрывали. В данном случае все 3 ставки что попали в один блок получили выигрыш 4cs. Вот хеш блока где было 3 транзакции(ставки) с разных аккаунтов в одном блоке 34ef00682698feda01233add1cecca471441d4deaf00c2c52ac55b30199a3912 В итоге эти ставки которые оказались в одном блоке получили одинаковые выигрыши по 4cs. вот хеш 5ef308db3d5e29dba860560f67c7a3c48798a50de27e44e9836e1818c5a667cc И так происходит всегда. Если в одном блоке окажется 50 транзакций (ставок). То эти 50 ставок либо одновременно выиграют одну и ту же сумму, либо проиграют. К чему это может привести? При большом количестве ставок в одном приложении, все игроки будут либо одновременно выигрывать одинаковые суммы, либо массово одновременно проигрывать. У всех ставок будут одинаковые исходы. Никакого рандома. Это будет невыгодно разработчикам казино и других децентрализованных приложений. Потому что в один момент может произойти такая ситуация, что всем аккаунтам чьи транзакции попали в один блок, придётся выплачивать большие выигрыши. К примеру х10. Разработчики понесут большие потери

PresidentNavalny commented 5 years ago

*Update

I repeated the same in the testnet 5 6

kondrashovsv commented 5 years ago

Thanks for the detailed description of the problem. This was the first version, so a simple mechanism was chosen to form a random number. in next release it will depend not only on the block number, and for each participant the number will be different

angelesmanzo commented 5 years ago

Hi!

Probably is needed to consider an additional criteria. If It might happen that some players will do their bets at the same time, for instance, you might try to implement a random function to define which accounts win in the Smart Contract. However, we should take in mind that the blockchain is a distributed system where the blocks generation is based on a deterministic approach in order to reach a consensus.

Here an example code that could be useful by using the method getSeed().

import java.util.Arrays;
import java.util.Random;
…
…
private int generateRandomNumber() {
        Random random = new Random((long) Arrays.hashCode(getSeed()));
        return random.nextInt();
    }
…