Skip to content

Commit

Permalink
Merge pull request #123 from Concordium/improve-wccd-transaction-gene…
Browse files Browse the repository at this point in the history
…rator

Stop wCCD generator minting for everyone too fast
  • Loading branch information
lassemoldrup authored Nov 29, 2023
2 parents 3a4dc75 + 2e0939f commit 3017432
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 34 deletions.
4 changes: 4 additions & 0 deletions generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.1

Stop `wccd` mode from minting to everyone faster than the specified TPS.

## 1.1.0

Support protocol 6 and node version 6.
Expand Down
2 changes: 1 addition & 1 deletion generator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "generator"
version = "1.1.0"
version = "1.1.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The transactions are sent in a round robin fashion.

### `wccd`

The tool first deploys and initializes the [`cis2-wccd`](https://github.com/Concordium/concordium-rust-smart-contracts/tree/fcc668d87207aaf07b43f5a3b02b6d0a634368d0/examples/cis2-wccd) example contract. It then mints 1 (micro) wCCD for each account on the chain in order to increase the size of the state of the contract. The transactions alternate between wrapping, transferring, and unwrapping wCCD. In each case the receiver is the sender, since it is simple and there is no special handling of this in the contract.
The tool first deploys and initializes the [`cis2-wccd`](https://github.com/Concordium/concordium-rust-smart-contracts/tree/fcc668d87207aaf07b43f5a3b02b6d0a634368d0/examples/cis2-wccd) example contract. It then starts minting 1 (micro) wCCD for each account on the chain in order to increase the size of the state of the contract. After that, the transactions alternate between wrapping, transferring, and unwrapping wCCD. In each case the receiver is the sender, since it is simple and there is no special handling of this in the contract.

### `register-credentials`

Expand Down
62 changes: 31 additions & 31 deletions generator/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,11 @@ impl Generate for TransferCis2Generator {

/// A generator that makes transactions that wrap, unwrap, and transfer WCCDs.
pub struct WccdGenerator {
client: Cis2Contract,
args: CommonArgs,
nonce: Nonce,
count: usize,
client: Cis2Contract,
args: CommonArgs,
nonce: Nonce,
count: usize,
accounts: Vec<AccountAddress>,
}

#[derive(concordium_std::Serial)]
Expand Down Expand Up @@ -596,45 +597,22 @@ impl WccdGenerator {

// Give everyone on the network a wCCD token to increase the size of the state
// of the contract.
println!("Minting wCCD tokens for everyone...");
let receivers: Vec<_> = client
let accounts: Vec<_> = client
.get_account_list(BlockIdentifier::LastFinal)
.await
.context("Could not obtain a list of accounts.")?
.response
.try_collect()
.await?;

let mut client = Cis2Contract::create(client, contract_address).await?;

for recv in receivers {
let params = WrapParams {
to: Receiver::Account(recv),
data: AdditionalData::new(vec![])?,
};

let metadata = ContractTransactionMetadata {
sender_address: args.keys.address,
nonce: nonce.nonce,
expiry: TransactionTime::seconds_after(args.expiry),
energy: GivenEnergy::Absolute(Energy::from(3500)),
amount: Amount::from_micro_ccd(1),
};
let transaction_hash = client
.update::<_, anyhow::Error>(&args.keys, &metadata, "wrap", &params)
.await?;
nonce.nonce.next_mut();
println!(
"{}: Transferred 1 wCCD to {recv} (hash = {transaction_hash}).",
chrono::Utc::now(),
);
}
let client = Cis2Contract::create(client, contract_address).await?;

Ok(Self {
client,
args,
nonce: nonce.nonce,
count: 0,
accounts,
})
}
}
Expand All @@ -651,10 +629,32 @@ impl Generate for WccdGenerator {
amount: Amount::zero(),
};

// Before doing anything else, we transfer a single wCCD to each account on the
// network to increase the size of the contract state.
if self.count < self.accounts.len() {
let recv = self.accounts[self.count];
let params = WrapParams {
to: Receiver::Account(recv),
data: AdditionalData::new(vec![])?,
};
metadata.amount = Amount::from_micro_ccd(1);

let tx = self.client.make_update::<_, anyhow::Error>(
&self.args.keys,
&metadata,
"wrap",
&params,
)?;
self.nonce.next_mut();
self.count += 1;

return Ok(tx);
}

// We modulate between wrapping, transferring, and unwrapping. All wCCD are
// minted for and transferred to our own account, which is fine for testing,
// since there is no special logic for this in the contract.
let tx = match self.count % 3 {
let tx = match (self.count - self.accounts.len()) % 3 {
// Wrap
0 => {
let params = WrapParams {
Expand Down

0 comments on commit 3017432

Please sign in to comment.