Skip to content

Commit

Permalink
Add pull-ledger-diff ci test for calamari (#919)
Browse files Browse the repository at this point in the history
* Add pull-ledger-diff ci test for calamari

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Add bigger sleep

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Fix

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Add governance to rpc performance test

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Add governance to rpc performance test

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Temp

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Should work with governance. Needs cleanup

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Wait less for finalizaiton

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Clean up

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Clean up

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Add more sleep between governance executions

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* CLean up

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Reduce expected avg sync time

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Clean up

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Clean up

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Fix pass by reference

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>
  • Loading branch information
ghzlatarev committed Dec 19, 2022
1 parent 9c6f1fb commit b5699bc
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 49 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/integration_test_calamari.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,23 @@ jobs:
--no-autorestart \
-- \
--address=ws://127.0.0.1:9921
- uses: actions/checkout@v2
with:
repository: Manta-Network/Manta
path: Manta
- name: run test suites
run: |
# TODO: implement moonbeam-like js test suite triggers here
sleep 300
sleep 120
cd ${{ github.workspace }}/Manta/tests
yarn install
yarn
yarn correctness_test --address=ws://127.0.0.1:9921 --exit
echo $?
if [ $? != 0 ]; then echo "Ledger RPC correctness test failed!"; exit 1; fi
yarn performance_test --address=ws://127.0.0.1:9921 --exit
echo $?
if [ $? != 0 ]; then echo "Ledger RPC performance test failed!"; exit 1; fi
- name: check if target block is finalized
run: |
cd ${{ github.workspace }}/dev-tools-calamari/check-finalized-block
Expand Down
66 changes: 42 additions & 24 deletions tests/manta_pay.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ApiPromise } from '@polkadot/api';
import { KeyringPair } from '@polkadot/keyring/types';
import { u8aToHex, numberToU8a } from '@polkadot/util';
import { single_map_storage_key, double_map_storage_key, delay, emojis, HashType } from './test-util';
import { blake2AsHex } from "@polkadot/util-crypto";
import { single_map_storage_key, double_map_storage_key, delay, HashType } from './test-util';

// number of shards at MantaPay
export const manta_pay_config = {
Expand Down Expand Up @@ -56,7 +57,7 @@ function next_checkpoint(
}

/**
* geenrate a utxo batch from a checkpoint
* generate a utxo batch from a checkpoint
* @param per_shard_amount number of utxo per shard generated.
* @param checkpoint the starting indices of each shard.
* @returns an array of pair: [(storage_key, utxo_data)]
Expand All @@ -75,6 +76,8 @@ function generate_batched_utxos(per_shard_amount: number, checkpoint: Array<numb
return {data: data, checkpoint: new_checkpoint};
}

var referendumIndexObject = { referendumIndex: 0 };

/**
* Insert utxos in batches
* @param api api object connecting to node.
Expand All @@ -83,7 +86,7 @@ function generate_batched_utxos(per_shard_amount: number, checkpoint: Array<numb
* @param per_shard_amount number of utxos per shard per batch.
* @param init_checkpoint initial checkpoint (an array of starting indices in shard).
* @param max_wait_time_sec maximum waiting time (in second).
* @returns number of batches sucessfully inserted.
* @returns number of batches successfully inserted.
*/
async function insert_utxos_in_batches(
api: ApiPromise,
Expand All @@ -102,19 +105,13 @@ async function insert_utxos_in_batches(
for (let batch_idx = 0; batch_idx < batch_number; batch_idx ++){
const {data, checkpoint} = generate_batched_utxos(per_shard_amount, cur_checkpoint);
cur_checkpoint = checkpoint;
const call_data = api.tx.system.setStorage(data);
// https://substrate.stackexchange.com/questions/1776/how-to-use-polkadot-api-to-send-multiple-transactions-simultaneously
const unsub = await api.tx.sudo.sudo(call_data).signAndSend(keyring, {nonce: -1}, ({ events = [], status }) => {
if (status.isFinalized) {
success_batch ++;
console.log("%s %i batch utxos insertion finalized.", emojis.write, success_batch);
unsub();
}
});
const callData = api.tx.system.setStorage(data);
execute_with_root_via_governance(api, keyring, callData, referendumIndexObject);
await delay(5000);
}

// wait all txs finalized
for(let i =0; i < max_wait_time_sec; i ++){
for(let i = 0; i < max_wait_time_sec; i ++){
await delay(1000);
if (success_batch === batch_number) {
console.log("total wait: %i sec.", i + 1);
Expand Down Expand Up @@ -149,7 +146,7 @@ function generate_vn_insertion_data(
* @param amount_per_batch amount of void numbers per batch.
* @param batch_number number of batch inserted.
* @param start_index starting index.
* @param max_wait_time_sec maxium time before timeout (in sec).
* @param max_wait_time_sec maximum time before timeout (in sec).
* @returns number of batches successfully inserted before timeout.
*/
async function insert_void_numbers_in_batch(
Expand All @@ -165,15 +162,10 @@ async function insert_void_numbers_in_batch(
for(let batch_idx = 0; batch_idx < batch_number; batch_idx ++) {
console.log("start vn batch %i", batch_idx);
const data = generate_vn_insertion_data(sender_idx, amount_per_batch);
const call_data = api.tx.system.setStorage(data);
const unsub = await api.tx.sudo.sudo(call_data).signAndSend(keyring, {nonce: -1}, ({ events = [], status }) => {
if (status.isFinalized) {
success_batch ++;
console.log("%s %i batch void number insertion finalized.", emojis.write, success_batch);
unsub();
}
});
const callData = api.tx.system.setStorage(data);
execute_with_root_via_governance(api, keyring, callData, referendumIndexObject);
sender_idx += amount_per_batch;
await delay(5000);
}
// wait all txs finalized
for(let i =0; i < max_wait_time_sec; i++){
Expand Down Expand Up @@ -215,15 +207,41 @@ export async function setup_storage(
receiver_checkpoint.fill(check_idx);
console.log("starting utxo idx: %i", receiver_checkpoint[0]);
const utxo_batch_done = await insert_utxos_in_batches(
api, keyring, config.utxo_batch_number, config.utxo_batch_size_per_shard, receiver_checkpoint, 1000);
api, keyring, config.utxo_batch_number, config.utxo_batch_size_per_shard, receiver_checkpoint, 250);
console.log(">>>> Complete %i big batch with %i UTXOs",
big_batch_idx + 1 , utxo_batch_done * config.utxo_batch_size_per_shard * manta_pay_config.shard_number);
}
console.log(">>>>>>>>> UTXO INSERT DONE >>>>>>>>");

console.log(">>>> Inserting void numbers: %i per batch, %i batch",
config.vn_batch_size, config.vn_batch_number);
const vn_batch_done = await insert_void_numbers_in_batch(api, keyring, config.vn_batch_size, config.vn_batch_number, 0, 1000);
const vn_batch_done = await insert_void_numbers_in_batch(api, keyring, config.vn_batch_size, config.vn_batch_number, 0, 250);
console.log(">>>> Complete inserting %i void numbers", vn_batch_done * config.vn_batch_size);
}

/**
* Execute an extrinsic with Root origin via governance.
* @param api API object connecting to node.
* @param keyring keyring to sign extrinsics.
* @param extrinsicData the callData of the extrinsic that will be executed
* @param referendumIndexObject the index of the referendum that will be executed
*/
export async function execute_with_root_via_governance(
api: ApiPromise,
keyring: KeyringPair,
extrinsicData: any,
referendumIndexObject: any
) {
const encodedCallData = extrinsicData.method.toHex();
await api.tx.democracy.notePreimage(encodedCallData).signAndSend(keyring, {nonce: -1});
let encodedCallDataHash = blake2AsHex(encodedCallData);
let externalProposeDefault = await api.tx.democracy.externalProposeDefault(encodedCallDataHash);
const encodedExternalProposeDefault = externalProposeDefault.method.toHex();
await api.tx.council.propose(1, encodedExternalProposeDefault, encodedExternalProposeDefault.length).signAndSend(keyring, {nonce: -1});
let fastTrackCall = await api.tx.democracy.fastTrack(encodedCallDataHash, 1, 1);
await api.tx.technicalCommittee.propose(1, fastTrackCall, fastTrackCall.encodedLength).signAndSend(keyring, {nonce: -1});
await api.tx.democracy.vote(referendumIndexObject.referendumIndex, {
Standard: { balance: 1_000_000_000_000, vote: { aye: true, conviction: 1 } },
}).signAndSend(keyring, {nonce: -1});
referendumIndexObject.referendumIndex++;
}
42 changes: 21 additions & 21 deletions tests/rpc_correctness_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const test_config = {
vn_batch_number: 1,
vn_batch_size: 1024,
},
timeout: 200000
timeout: 2000000
}

describe('Node RPC Test', () => {
Expand Down Expand Up @@ -44,27 +44,27 @@ describe('Node RPC Test', () => {
BigInt(1024), BigInt(1024));
expect(data.receivers.length).to.not.equal(0);
data.receivers.forEach((value: any, index:number) => {
let is_transparent = 0;
let payload = new Uint8Array([
...numberToU8a(is_transparent),
...value[0].public_asset.id,
...value[0].public_asset.value,
...value[0].commitment,
...numberToU8a(value[1].address_partition, 1 * 8),
... value[1].incoming_note.ephemeral_public_key,
... value[1].incoming_note.tag,
... value[1].incoming_note.ciphertext[0],
... value[1].incoming_note.ciphertext[1],
... value[1].incoming_note.ciphertext[2],
... value[1].light_incoming_note.ephemeral_public_key,
... value[1].light_incoming_note.ciphertext[0],
... value[1].light_incoming_note.ciphertext[1],
... value[1].light_incoming_note.ciphertext[2],
let is_transparent = 0;
let payload = new Uint8Array([
...numberToU8a(is_transparent),
...value[0].public_asset.id,
...value[0].public_asset.value,
...value[0].commitment,
...numberToU8a(value[1].address_partition, 1 * 8),
... value[1].incoming_note.ephemeral_public_key,
... value[1].incoming_note.tag,
... value[1].incoming_note.ciphertext[0],
... value[1].incoming_note.ciphertext[1],
... value[1].incoming_note.ciphertext[2],
... value[1].light_incoming_note.ephemeral_public_key,
... value[1].light_incoming_note.ciphertext[0],
... value[1].light_incoming_note.ciphertext[1],
... value[1].light_incoming_note.ciphertext[2],

]);
let size_per_shard = test_config.storage_prepare_config.utxo_batch_size_per_shard;
// this uses the fact that the RPC request is filled greedly
expect(payload).to.deep.equal(generate_shards_entry(~~(index/size_per_shard), index % size_per_shard));
]);
let size_per_shard = test_config.storage_prepare_config.utxo_batch_size_per_shard;
// this uses the fact that the RPC request is filled greedily
expect(payload).to.deep.equal(generate_shards_entry(~~(index/size_per_shard), index % size_per_shard));
});
expect(data.senders.length).to.not.equal(0);
data.senders.forEach((value: any, index: number)=>{
Expand Down
8 changes: 5 additions & 3 deletions tests/rpc_performance_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Keyring } from '@polkadot/keyring';
import { manta_pay_types, rpc_api } from './types';
import { StoragePrepareConfig, setup_storage, manta_pay_config} from './manta_pay';
import { setup_storage, manta_pay_config} from './manta_pay';
import minimist, { ParsedArgs } from 'minimist';
import { performance } from 'perf_hooks';
import { expect } from 'chai';
Expand All @@ -16,9 +16,9 @@ const test_config = {
vn_batch_number: 2,
vn_batch_size: 4096,
},
storage_setup_phase_timeout: 750000,
storage_setup_phase_timeout: 7500000,
sync_iterations: 50,
expected_average_sync_time: 1500,
expected_average_sync_time: 250,
testing_phase_timeout_tolerance: 1.5
}

Expand All @@ -33,6 +33,8 @@ async function single_rpc_performance(api:ApiPromise) {
BigInt(8192), BigInt(8192));
const after_rpc = performance.now();
const sync_time = after_rpc - before_rpc;
expect(data.receivers.length).to.not.equal(0);
expect(data.senders.length).to.not.equal(0);
console.log("ledger diff receiver size: %i", data.receivers.length);
console.log("ledger diff void number size: %i", data.senders.length);
console.log("single rpc sync time: %i ms", after_rpc - before_rpc);
Expand Down

0 comments on commit b5699bc

Please sign in to comment.