Subcurrency
A Parallelizable Ethereum Example
This example comes from Solidity's official document, Subcurrency Example. It implements a simple cryptocurrency, with two main functions:
Mint
Send
Analysis
It is clear that both of the two functions modify the balances only. The minting function modifies the account balance of a recipient, while the transferring changes the account balances of both parties.
This Ethereum contract is naturally parallelizable by itself, two transactions calling mint
can be executed in parallel because they won't access any shared states. As long as they're not targeting the same recipient. This applies to coins transfers too.
Parallel Caller
The SubcurrencyCaller
contract is designed to demonstrate the parallel processing capability of Arcology's multiprocessing feature. It interacts with the Subcurrency
contract, which is a simplified version of a token contract named Coin
.
The SubcurrencyCaller
contract utilizes Arcology's Multiprocess
library to perform parallel processing of multiple minting transactions on the Subcurrency
contract. By using Multiprocess
, it is able to submit and execute multiple minting transactions concurrently, greatly improving the overall efficiency and reducing the processing time.
The Multiprocess
library provides a convenient way to execute multiple transactions in parallel within a single smart contract call. It allows the contract to bundle multiple transactions together and execute them simultaneously, taking advantage of Arcology's parallel processing capabilities.
Note: The example highlights the main features and applications of Arcology's multiprocessing capability. It demonstrates how Arcology's technology can enhance the execution of smart contracts and provide significant benefits in terms of scalability and efficiency.
Code Analysis
Parallel Minting Transactions: In the
call
function of theSubcurrencyCaller
contract, four minting transactions are added to theMultiprocess
queue. These transactions are designed to mint tokens for four different addresses: Alice, Bob, Carol, and Dave.Execution and Verification: After adding the minting transactions to the
Multiprocess
queue usingmp.push()
, the contract checks if the number of transactions in the queue is equal to 4 by usingmp.length()
. This ensures that all four minting transactions have been successfully added to the queue.Parallel Execution: The
mp.run()
function is then called, which executes all the minting transactions in parallel. Arcology's parallel processing capability allows these transactions to be processed simultaneously, reducing the overall execution time and gas cost.Verification of Minted Balances: After the parallel execution, the contract verifies the balances of the four addresses by calling the
getter
function of theSubcurrency
contract. This demonstrates that the transactions were executed correctly, and the minted amounts were applied to the corresponding addresses.
Applications
The SubcurrencyCaller
contract showcases the potential applications of Arcology's parallel processing capability in smart contract development. By enabling parallel execution of transactions, Arcology can significantly enhance the scalability and efficiency of smart contracts.
Last updated