Table of Contents
- 1. "Wrappers": A Gaming Platform for Benchmarking Layer 2 Blockchain Scalability on Hyperledger Fabric
- 2. 1. The Basic Gaming Framework for Layer 1
- 3. 2. Layer 2 Scaling Solutions
- 4. 3. Layer 2 Plasma Implementation (Workable)
1. "Wrappers": A Gaming Platform for Benchmarking Layer 2 Blockchain Scalability on Hyperledger Fabric
the aim is to create a versatile and scalable multiplayer gaming application named "Wrappers", built on Hyperledger Fabric. This platform will serve as a foundation to evaluate and compare the performance and scalability benefits of various Layer 2 scaling solutions, including state channels, plasma, sidechains, and rollups. By leveraging the controllability of Hyperledger Fabric, "Wrapper" will offer insights into the best-suited scaling solutions for different use cases, focusing on scalability and efficiency in a controlled environment.
1.1. Key Features:
- 1. Multiplayer Capability:
"Wrappers" will support an unlimited number of players interacting simultaneously, providing a robust testbed for scalability and performance under various load conditions.
- 2. Action Flexibility:
The platform will facilitate a wide range of in-game actions, from basic currency transactions to real-time interactions and computing-intensive tasks. This approach allows for comprehensive benchmarking across different chaincode applications without the need for a graphical user interface (GUI). The focus will be on backend transactions to simulate diverse gaming scenarios and workload types.
- 3. Incremental Implementation and Testing:
The development of "Wrapper" will follow a phased approach, starting with a basic asset transfer application as a proof of concept. This initial phase will ensure the platform's readiness for Layer 1 operations. Subsequent phases will introduce Layer 2 solutions, beginning with state channels for specific use cases like currency transactions or real-time player movements. Each scaling solution will be integrated and evaluated for its impact on system performance and scalability.
1.2. Development Strategy
- 1. Simplified Design:
By simplifying Layer 2 implementations, we aim to capture the core principles driving scalability improvements. This approach will help isolate and assess the effectiveness of each scaling solution without the complexities of full security mechanisms.
- 2. Decoupled Architecture:
To facilitate easy testing and maintainability, the codebase will be organized with a focus on decoupling components. This structure will allow for flexible adaptation and expansion as new Layer 2 solutions are explored.
1.3. Current Limitations of Fabric
In Hyperledger Fabric, a chaincode can invoke another chaincode, even if it's on a different channel. However, there's an important limitation to this functionality: if the called chaincode resides on a different channel from the calling chaincode, only read queries are allowed. This means a chaincode can access the state of another chaincode in a different channel but cannot change the state on that channel.
When a chaincode on one channel attempts to call a chaincode on another channel in Hyperledger Fabric, the operation is constrained in such a way that it cannot directly commit changes to the ledger of the called channel.
2. 1. The Basic Gaming Framework for Layer 1
2.1. Chaincode
2.1.1. contractapi
- contractapi.ContractInterface
All contracts for use in chaincode must implement the
contractapi.ContractInterface
. - contractapi.TransactionContext
The default transaction context provided by
contractapi
(contractapi.TransactionContext
) provides all the necessary functions for interacting with the world state. However, taking directlycontractapi.TransactionContext
does pose some problems: what if we were to write unit tests for our contract? We would have to create an instance of that type which would then require a stub instance and would end up making our tests complex. In the context of Hyperledger Fabric, a "stub" refers to an object that acts as an intermediary between chaincode and the ledger itself.- Testing and Mocking
By using an interface like
TransactionContextInterface
, you can easily create mock objects for testing without having to deal with the complexities of the actual ledger.TransactionContext
objects are complex because they encapsulate information and behaviors related to the transaction and the ledger state. Manually creating these objects for different scenarios or ledgers would not only be error-prone but also require a deep understanding of the internals ofTransactionContext
. - Decopling and Maintainability
Interfaces help in decoupling the chaincode logic from the underlying ledger API. This decoupling is beneficial because it makes the chaincode more modular, easier to read, and maintain. If the implementation of
TransactionContext
or the underlying ledger API changes, the chaincode itself may not need any modifications as long as it adheres to the interface.Fabric's ledger fundamentally operates on a key-value store model, where the key is a string and the value is a byte array (
[]byte
). This design is intentionally agnostic about the contents of the value, giving developers the flexibility to store and interpret the data in a way that best suits their application's needs.
- Testing and Mocking
2.1.2. Types
Carefully design data structure.
2.1.3. i. Package currency
A litmus test for the feasibility of more complex Layer 2 scaling solutions later on.
- 1). Exchanging real-world currency to in-game balance
- USD Deposit to Blockchain:
- User Action: The user sends USD to a designated banking system.
- Bank Action: Upon receiving USD, the banking system records the transaction on the blockchain ledger.
This record includes essential details like transactionID, userID, time, and USD amount.
- Feedback to User: The banking system then provides the transaction ID back to the user as confirmation.
- User Action: The user sends USD to a designated banking system.
- USD to In-Game Currency Exchange:
- User Action: With the transaction ID, the user initiates an exchange request to convert the deposited USD into in-game currency.
The user must verify their identity by proving ownership of the userID associated with the transaction ID.
- Blockchain Process: Once the user's identity is verified and the transaction ID is validated, the blockchain ledger updates to reflect the exchange.
The USD transaction record is marked as "used", and the user's in-game balance is increased accordingly.
- User Action: With the transaction ID, the user initiates an exchange request to convert the deposited USD into in-game currency.
- Scaling Approach: Plasma
- Child Chain Transactions:
Initial USD deposits and transaction records by the bank are processed in a child chain, which handles high-volume transactions efficiently.
- Main Chain Commitments: Periodically, the child chain commits its state to the main chain.
- Exchange on Main Chain: Users perform the currency exchange on the main chain by providing their transaction ID and proving their identity.
This ensures the finality and security of the currency exchange process.
- Child Chain Transactions:
- Safety Approach: Merkle Root for Fraud Proofs
Merkle root in this context serves a crucial role in proving that a specific transaction record is included in the set of transactions committed to the mainchain from the child chain.
- Merkle Trees:
A Merkle tree is a binary tree in which each leaf node contains a hash of a transaction record, and each non-leaf node contains a hash of the concatenation of its two child nodes. The root of this tree (the Merkle root) is a single hash that effectively represents all transactions in the tree.
- Challenge Process:
Let's say Alice controls majority of nodes of the child chain, and wants to fake a fake $3000 deposit to the gaming platform's banking account.
- 1. Transaction Commitment:
The child chain, where Alice's fraudulent transaction resides, periodically commits the state to the mainchain. This state is summarized in a Merkle root, which represents all transactions (including the fraudulent one) in the child chain's current state. The child chain submits this Merkle root to the mainchain, effectively claiming that all transactions it represents are valid.
- 2. Bob Notices the Fraudulent Transaction:
Bob, vigilant and monitoring the chain, identifies Alice's fraudulent transaction. He decides to challenge it during the challenge period.
- 3. Gathering Evidence:
To challenge the transaction, Bob needs to construct a fraud proof. This proof consists of:
- 1) The fraudulent transaction's details:
Including its unique identifier (e.g., transaction hash), Alice's account details, and the amount ($3000).
- 2) A Merkle proof:
A sequence of hashes that, starting from Alice's transaction, allows anyone to reconstruct the path up to the submitted Merkle root, proving the transaction's inclusion in the child chain's committed state.
- 1) The fraudulent transaction's details:
- 4. Submitting the Challenge:
Bob submits the fraud proof to a smart contract on the mainchain designed to handle such challenges. This submission includes the fraudulent transaction details and the Merkle proof.
- 5. Smart Contract Verification:
The smart contract then performs the following checks:
- 1) Verifying the transaction is part of the committed state.
It verifies the Merkle proof by recalculating the Merkle root using the provided path (the series of hashes Bob submitted) and comparing it with the committed Merkle root. If they match, it proves the transaction is part of the committed state.
- 2) Valuates the validity of the transaction based on predefined rules
(e.g., whether Alice had a legitimate claim to the $3000).
- 1) Verifying the transaction is part of the committed state.
- 6. Outcome of the Challenge:
If Bob's challenge is successful (i.e., the smart contract verifies the fraud and rules the transaction invalid), several actions occur:
- Alice's fraudulent transaction is marked invalid/revoked.
- The withdrawal or exchange request based on this transaction is canceled.
- Depending on the platform's governance, Alice may face additional penalties.
If the challenge fails (due to insufficient proof or if the challenge period has expired), Alice's fraudulent transaction would remain unchallenged.
- Alice's fraudulent transaction is marked invalid/revoked.
- 1. Transaction Commitment:
- Merkle Trees:
- USD Deposit to Blockchain:
2.2. Creating Fabric gateway application for this exchange app
Then adjusting the layer 1 parameters on that (endorsement nodes, http package of golang, etc), see how they affect the throughput. Carefully design the benchmarks, like enabling repetitive TIDs, and then using vegeta to generate repetitive transactions per second.
Seems that the # endorsement nodes won't affect the latency, but it will affect the throughput when multiple instances running in the same machine.
applications/ – bench-basic-wrappers/ URLs
- New Players Creation (player -> blockchain)
PUT 192.168.50.29/player/playerID
- Player Deposit USD to Blockchain (bank -> blockchain)
PUT 192.168.50.29/bank/txID/USD/playerID
- Player Exchanging USD to In-game Currency (player -> blockchain)
PUT 192.168.50.29/exchange/txID/playerID
- Another Way, Combine Two Steps (bank -> blockchain) bank exchange
PUT 192.168.50.29/bexchange/txID/USD/playerID
- 1. Single Commit
Bunch of non-repetitive deposit => Bunch of non-repetitive exchange
- 2. Two-phase exchange (bexchange)
Involves two commits (chaincode functions)
- # Endorsement Nodes
We can find whether the golang http package is a limitation by check whether reducing endorsement nodes will actually affect the overall throughput when the rate is quite high.
3. 2. Layer 2 Scaling Solutions
Layer 2 Survey Layer 2 is a collective term for solutions designed to help scale your application by handling transactions off the Ethereum Mainnet (layer 1) while taking advantage of the robust decentralized security model of Mainnet.
4. 3. Layer 2 Plasma Implementation (Workable)
4.1. 1. Launch Two Networks in Chains
4.1.1. layer1 chain (chains) (org01)
Same as the older config, certs (6001) as Design Layer 1 Network.
./fabric -e
4.1.2. plasma chain (chains) (org02)
./fabric -d
4.2. 2. Plasma Currency Chaincode
4.3. 3. Experiment & Benchmarking (Latency)
"Plasma is not designed to reach assured fiinality rapidly, even though transactions are confiirmed in the child chains rapidly, it requires it to be fiinalized on the underlying root blockchain." SCHEDULED:
4.3.1. DONE Familiar with client side code
4.4. 4. Thoughts
4.4.1. 1. Meaningness to just compare layer 1 with any single layer 2 solutions.
Start implementing rollups & other layer 2 solutions
4.4.2. 2. Plasma is not design to reduce latency, it is designed to increase throughput & reduce transaction fees.
Plasma is not designed to reach assured fiinality rapidly, even though transactions are confiirmed in the child chains rapidly, it requires it to be fiinalized on the underlying root blockchain. Maybe we need some other measurements, and change the response behaviour of the plasma chain.