Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop wCCD generator minting for everyone too fast #123

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

13 changes: 8 additions & 5 deletions generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
[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
[dependencies]
concordium-rust-sdk = { path = "../deps/concordium-rust-sdk", version = "*" }
clap = {version = "4", features = ["derive", "color"] }
clap = { version = "4", features = ["derive", "color"] }
anyhow = "1"
chrono = {version = "0.4", features = ["serde"] }
chrono = { version = "0.4", features = ["serde"] }
rand = "0.7"
tokio = {version = "1.27", features = ["rt-multi-thread", "macros", "time"]}
tonic = {version = "0.8", features = ["tls", "tls-roots"]} # Use system trust roots.
tokio = { version = "1.27", features = ["rt-multi-thread", "macros", "time"] }
tonic = { version = "0.8", features = [
"tls",
"tls-roots",
] } # Use system trust roots.
lassemoldrup marked this conversation as resolved.
Show resolved Hide resolved
futures = "0.3.28"
http = "0.2.9"
serde_json = "1.0.96"
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
Loading