Giter Club home page Giter Club logo

break's Introduction

Break Solana Game Build Status

How it works

The Break Solana Game consists of a 3 parts: a web client frontend, a web server backend, and an on-chain Solana program. The web server backend is not strictly required but it helps with certain performance improvements.

At a basic level, the Break Solana Game allows a player to send simple smart contract transactions as fast as they can to showcase Solana's speed. The web frontend is responsible for creating, sending, and confirming transactions and displays the status of each transaction in a colored grid. The web backend helps out by acting as a fast relay for transactions. It will forward transactions directly to the TPU (transaction processing unit) UDP port of the current cluster leader node (typically transactions are first sent to an RPC API node for forwarding). It also helps by creating a supply of game accounts ahead of time to speed up game setup time (these accounts can be tracked across server restarts using Redis).

Rather than subscribing to each transaction signature, the web client subscribes to account data updates. Each transaction will set a bit in the state within a Break program account, so each transaction can be uniquely identified by the bit it sets.

Prerequisites

Solana CLI Tooling: https://docs.solana.com/cli/install-solana-cli-tools For running this application you need to have NodeJs and NPM. We recommend to use NVM for managing NodeJs versions For NVM installation please refer to manual

Install

npm install

Run Server

Note: If the cluster you connect to doesn't provide a faucet, you will need to supply the server with a payer key. (See 'Configuration' below).

# Start local node
solana-test-validator

# Deploy program to local node
cd program
cargo build-bpf
solana program deploy target/deploy/break_solana_program.so --url localhost

# Connect to local node
cd server
npm run start:dev

Configuration

By default, the Break server will connect to a local node for RPC. To configure this behavior, set the following environment variables when running the server:

PORT

Set this option to specify the port for the API server. Default is 8080.

PORT=80 npm run start:dev
RPC_URL

Set this option to connect to a specific remote RPC API server.

RPC_URL=http://api.mainnet-beta.solana.com npm run start:dev
LIVE

Enable this option to connect to a remote cluster. The default cluster is devnet.

LIVE=true npm run start:dev
CLUSTER

Enable this option along with LIVE=true to connect to a specific remote cluster.

LIVE=true CLUSTER=devnet npm run start:dev
LIVE=true CLUSTER=testnet npm run start:dev
LIVE=true CLUSTER=mainnet-beta npm run start:dev
DEPLOYED_PROGRAM_ADDRESS

Set this option to use an existing loaded Break Solana program rather than load a new version. If the program doesn't exist, the server will exit with an error.

DEPLOYED_PROGRAM_ADDRESS=<BASE58 ENCODED ADDRESS> npm run start:dev

To use the Break Solana program that's used on https://break.solana.com, use the following address:

DEPLOYED_PROGRAM_ADDRESS=BrEAK7zGZ6dM71zUDACDqJnekihmwF15noTddWTsknjC npm run start:dev
SEND_TO_RPC

Enable this option to send transactions to the RPC API rather than directly to a validator TPU port.

SEND_TO_RPC=true npm run start:dev

Run Client

cd client
npm run start

Configuration

Client behavior can be modified with the usage of url parameters.

cluster

Set this parameter to pick a remote cluster. This parameter is automatically set when using the UI cluster selector.

https://break.solana.com/game?cluster=devnet
commitment

Set this parameter to set the commitment level used for confirming transactions. Default is 'confirmed' but 'processed' is also supported.

https://break.solana.com/game?commitment=processed
debug

Set this parameter to enable "debug mode" which will display a table of confirmation times instead of the colored grid.

https://break.solana.com/game?debug
retry

Set this parameter to disable retrying transactions which have not yet been confirmed. Retry behavior is enabled by default because some transactions will be forwarded to a leader who skips their block slot.

https://break.solana.com/game?retry=disabled
split

Set this parameter to split transactions across multiple payer and program accounts to increase transaction parallelization. Default is 4.

https://break.solana.com/game?split=1
test

Set this parameter to enable "test mode" which will automatically send approximately 33 transactions per second.

https://break.solana.com/game?test

Built With

break's People

Contributors

chaitanyapotti avatar criesofcarrots avatar darrensapalo avatar dependabot[bot] avatar evgenyshvingelsky avatar igorburak-zenio avatar joeaba avatar jstarry avatar memoriesadrift avatar mvines avatar ojshua avatar rmshea avatar ryan-shea avatar wargot-by avatar youjustdontknow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

break's Issues

Try game again

  1. When game is finished I can see "Try again" button
  2. Clicking on the button, I want to see /game screen

Load testing

5k concurrent users
15k in one hour
100k in one day

Subscribe to account data instead of program

Problem

Break is creating too many accounts. See more details here: #108

Proposed Changes

This captures the client side of the changes:

  • Change from program subscription to account subscription
  • Inspect account data to determine tx success

Details about transaction popover

  1. Popovers are available "Stats after game" screen
  2. Popover should be displayed hovering transaction
  3. Information on Popover:
    a. Lamports
    b. Signature
    c. Transaction time

Server crashes if cluster is not accessible

Problem

If apps do not bind to the provided PORT, Heroku will attempt to restart a few times until it marks it as crashed.

Proposed Solution

  • Always bind to the port
  • Add network failure UI state to the client app

I can see number of TPS, from all collaborators

  1. Number of created transactions from all clients should be collected an send to BE every second.
  2. Backend should sum up all transactions created for 5 seconds.
    a. result should be divided by 5 to get TPS
  3. FE should display TPS number.
    a. TPS number should refreshed every 5 seconds

Break solana STATS after the game is finished

Exists on /stats

  1. After the game is finished, stats should be displayed:
    Total amount of transactions
    #% of Solana capability used (Formula: #of transaction/50000)
  2. "Try again" button - display "Start the game screen"
  3. Message after game finished: "Well, perhaps if you invited a fem more friends...
    With transactions in 15 seconds you took up of our blockchain's network capabilities. If you invited couple more people our decentralized database would start to slow down.
    You can review every transaction with stats on confirmation and signatures hovering it."

Reuse break program account

Problem

Each new deploy of the break app creates a new program with a random pubkey. It would be nice if the program id was a vanity address and was always the same because these program instructions will be inspected on the explorer.

Break.Solana game screen

  1. Page should exist on break.solana.com/game
  2. Name for Browser tab: "Brake Solana"
  3. Browser tab should have Solana logo as favicon.
  4. Solana logo should exist on the screen
  5. Countdown clock should exist on the screen. It is frozen on 15 seconds, until game is started
  6. "BEGIN" button should exist on the screen. Clickin on it - game begins.

User can enter username

We'll need to store:

Time completed
Username
Email (make a field for this)
Referrer ID (if there was one, from the URL that created the session)

Stop bloating the account ledger

Problem

Break transactions create a new account for each transaction and these accounts bloat the ledger

Proposed changes

Use BPF instructions!

  • Client subscribes to account that it receives from the server
  • Client encodes an id in program ix data
  • Program modifies account data based on ix data id
  • Client checks account data to determine which ids were processed

The cost of each transaction is too high

Problem

Each transaction creates a rent exempt account but creating rent exempt accounts is not necessary.

Proposed Changes

Only transfer enough rent to cover a single epoch.

Broadcast active client count from Break Server

Problem

We want to show users that they're not alone when playing Break by showing the number of concurrent players.

Proposed Changes

The break server tracks websocket clients, broadcast the client count periodically

No Social share button

Otherwise, it's a bit solitaire-like. :)

Also, some kind of rankings by the transaction count would be nice to have. :)

Create square for click during the game

  1. During the game - every click should create a square on the screen.
  2. If the amount of squares is more, than fits the screen - scroll should appear
    a. When new row of squares is created - scrlollable area should scroll for 1 row.
  3. "Total amount of transaction" should increment by 1 after every click

Prepare a few hundred break programs

Problem

Break client transactions create program accounts, and those transactions can be easily verified by subscribing to the program using the RPC pub sub API. If all break clients create accounts for the same program, the fan out of program subscription notifications is going to overwhelm the RPC server as well the clients themselves.

Napkin math: 1000 users * 15 tps = 15,000 tps => 15,000 notifications * 1000 users => 15M websocket messages per second. Each user getting 15k messages per second.

Proposed Change

Sharding!

  1. Create a few hundred programs on the cluster ahead of time
  2. Give the same programId to a few clients before rotating to the next programId

Expand the TPS calculation window

Problem

TPS updates are too choppy because they are calculated with a short time window

Proposed Changes

Use a rolling time window for TPS calculation so that TPS updates are smooth

Break.solana INTRO screen

  1. Break solana page should exist on "break.solana.com"

  2. layouts should be based image, attached to this story.

  3. "Read how it works" button should exist on this screen. Clicking on the button - link should be opened in new browser tab. Link: https://solana.com/category/blog/

  4. Solona logo should exist, clickin on the logo - open Solana.com page in new browser tab.

  5. Solana static image should exist on this screen. This image can be animated in terms of future tasks.

  6. "Play the game" button should exsit on this screen. Clicking on the button - Start/break screen should be displayed

Track transactions created per day

Problem

We want to track the full impact of the break game on the cluster over time

Proposed Changes

  • Create break program config account
  • Add increment day count instruction
  • Profit

If short on time:

  • Add Redis Heroku addon
  • Track sent transactions in the server and increment a date redis key
  • Periodically broadcast daily transactions

Handle RPC server restarts

Problem

When the RPC server restarts, it binds to a new random TPU udp port. The break server is oblivious to that and doesn't realize it's sending transactions into the void when this happens.

Proposed Changes

Detect RPC restarts or periodically query cluster info to make sure tpu info is up to date

Calculate confirmation time

Problem

We want to show users how fast confirmation times are on Solana

Proposed Changes

  • Stream confirmation times and calculate a rolling median

Confirmation time calculation is incorrect

Problem

This is not a correct way to calculate transaction confirmation time.

            const t1 = performance.now();
            const response = await this.connection.sendTransaction(transaction, this.keypair);
            const t2 = performance.now();

All this is doing is broadcasting a transaction to the network. Next, the network sends the transaction to the leader node who will then process the transaction and eventually produce a block with the results of this transaction (if it succeeds).

Proposed Solution

Make use of https://solana-labs.github.io/solana-web3.js/function/index.html#static-function-sendAndConfirmRecentTransaction or https://solana-labs.github.io/solana-web3.js/class/src/connection.js~Connection.html#instance-method-confirmTransaction to get the correct transaction confirmation time

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.