Skip to content

TheoInTech/break-solana-game

 
 

Repository files navigation

Challenge4-solana

Comparison between hello-world and break-solana-game on creating transactions and its accounts.

Creating Transactions

  • On establishing a connection, hello-world uses just the clusterApiUrl for the devnet while the break-solana-game fetches a new connection everytime the RPC changes and has a try-catch to determine if the connection is successful.
  • On transaction creation, there are multiple differences:
  1. hello-world creates the instruction first using TransactionInstruction and passing the public key, programId and the data allocation while on break-solana-game, it creates a transaction message using an RPC worker to handle the messages and send them in transactions, then it will get a transaction response message that contains the signature and serialized transaction to finally send the transaction using a web socket.
  2. hello-world only adds the whole instruction object for the transaction paired with the connection but for the break-solana-game, it accepts a lot of arguments to create a transaction like trackingId, blockhash, programId, and many more.
  3. break-solana-game uses web sockets to fetch and check the pending transactions, then dispatches a timeout with the trackingId after 90 seconds of no confirmation.
  4. hello-world simply creates an instruction, sends and confirms it, and deserializes it with the account that made it while in break-solana-game, since the transaction is sent via web socket, it awaits for it to confirm with a certain amount of timeout and upon confirmation, it will be dispatched to the context with the transaction details (feeAccount, programAccount and signature), trackingId and the pendingTransaction with the targetSlot.
  5. break-solana-game has a retry capability while hello-world doesn't have one.
  6. break-solana-game has a debugging mode that allows the developers to be notified and know the status of the transaction and track it at the same time, while hello-world doesn't have one.

Accounts

Account/s in hello-world is a single account which was created if it's non-existent yet while on break-solana-game, multiple accounts are able to use the program simultaneously, which the program accounts can handle. Program accounts counter is being refreshed once a new transaction message is being created. Accounts has a config in break-solana-game which consists of the program accounts (publick keys of the accounts), fee payer keypairs (keypair of the program), and the account capacity of the program. I also noticed that on creating transactions on hello-world, it only needs the public key as an argument, while on break-solana-game, the feeAccountSecretKey needs to provide its secret key.


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

About

Break Solana Game

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 62.0%
  • SCSS 31.9%
  • CSS 4.1%
  • Rust 1.0%
  • HTML 0.6%
  • JavaScript 0.3%
  • Other 0.1%