Quick Start
Examples
npm install @arcologynetwork/concurrentlib
1. Vending Machine Example with Cumulative Variables
To better understand cumulative variables work, consider the following example from the Ethereum developers docs:
In the original implementation, the cupcakeBalances
mapping is a shared variable accessed and modified by multiple functions (refill
and purchase
), and it is shared among different users interacting with the contract.
Conflict Analysis: Only one transaction will go through due to the obvious conflict caused by the concurrent updates to cupcakeBalances.
The parallel execution of transactions interacting with this contract won't bring any performance benefit.
pragma solidity 0.8.7;
contract VendingMachine {
// Declare state variables of the contract
address public owner;
mapping (address => uint) public cupcakeBalances;
// When 'VendingMachine' contract is deployed:
// 1. set the deploying address as the owner of the contract
// 2. set the deployed smart contract's cupcake balance to 100
constructor() {
owner = msg.sender;
cupcakeBalances[address(this)] = 100;
}
// Allow the owner to increase the smart contract's cupcake balance
function refill(uint amount) public {
require(msg.sender == owner, "Only the owner can refill.");
cupcakeBalances[address(this)] += amount;
}
// Allow anyone to purchase cupcakes
function purchase(uint amount) public payable {
require(msg.value >= amount * 1 ether, "You must pay at least 1 ETH per cupcake");
require(cupcakeBalances[address(this)] >= amount, "Not enough cupcakes in stock to complete this purchase");
cupcakeBalances[address(this)] -= amount;
cupcakeBalances[msg.sender] += amount;
}
}
Benchmarking
Contract Name
Vending Machine(Parallelized)
Arcology Version
V 1.9.0
Deployment Mode
Standard-alone
Operating System
Ubuntu 22.04
CPU
AMD Ryzen Threadripper 2950X 16-Core Processor
RAM
128G RAM
Storage
2T M2 SSD
Average gas burned/S:
712,118,171.6
Max gas burned/S
1,005,206,703
Last updated