From f75149b1e2cd532c653bc519b1d08873cbf6c989 Mon Sep 17 00:00:00 2001 From: Sam Stuewe Date: Fri, 21 Oct 2022 10:52:12 -0500 Subject: [PATCH] Lift create_seeded_transaction outside hot loop Also includes modifying twophase mode's transaction-creation to reuse pedersen-commitments/range-proofs Signed-off-by: Sam Stuewe --- tools/shard-seeder/shard-seeder.cpp | 37 +++++++++++++++-------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/tools/shard-seeder/shard-seeder.cpp b/tools/shard-seeder/shard-seeder.cpp index fc3b85659..9d2d6c34b 100644 --- a/tools/shard-seeder/shard-seeder.cpp +++ b/tools/shard-seeder/shard-seeder.cpp @@ -128,6 +128,24 @@ auto main(int argc, char** argv) -> int { " to database ", shard_db_dir.str()); + auto value = cbdc::commit(secp_context.get(), + cfg.m_seed_value, + {}) + .value(); + auto range + = cbdc::transaction::prove(secp_context.get(), + bulletproof_gens.get(), + rng, + {{}, cfg.m_seed_value}, + &value); + auto value_comm + = cbdc::serialize_commitment(secp_context.get(), + value); + + auto tx = wal.create_seeded_transaction(0, + value_comm, + range) + .value(); if(!cfg.m_twophase_mode) { leveldb::Options opt; opt.create_if_missing = true; @@ -150,24 +168,8 @@ auto main(int argc, char** argv) -> int { } auto batch_size = 0; leveldb::WriteBatch batch; - auto value = cbdc::commit(secp_context.get(), - cfg.m_seed_value, - {}) - .value(); - auto range - = cbdc::transaction::prove(secp_context.get(), - bulletproof_gens.get(), - rng, - {{}, cfg.m_seed_value}, - &value); - auto value_comm - = cbdc::serialize_commitment(secp_context.get(), - value); for(size_t tx_idx = 0; tx_idx != num_utxos; tx_idx++) { - auto tx = wal.create_seeded_transaction(tx_idx, - value_comm, - range) - .value(); + tx.m_inputs[0].m_prevout.m_index = tx_idx; cbdc::transaction::compact_tx ctx(tx); const cbdc::hash_t& output_hash = cbdc::transaction::calculate_uhs_id( @@ -215,7 +217,6 @@ auto main(int argc, char** argv) -> int { // write dummy size auto ser = cbdc::ostream_serializer(out); ser << count; - auto tx = wal.create_seeded_transaction(0).value(); for(size_t tx_idx = 0; tx_idx != num_utxos; tx_idx++) { tx.m_inputs[0].m_prevout.m_index = tx_idx; cbdc::transaction::compact_tx ctx(tx);