3
3
// Distributed under the MIT software license, see the accompanying
4
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
6
- #include " common/config.hpp"
6
+ #include " util/common/config.hpp"
7
+ #include " util/serialization/util.hpp"
8
+ #include " util/serialization/format.hpp"
9
+ #include " util/common/commitment.hpp"
7
10
8
11
#include < unordered_map>
9
12
@@ -24,13 +27,9 @@ auto main(int argc, char** argv) -> int {
24
27
}
25
28
auto cfg = std::get<cbdc::config::options>(cfg_or_err);
26
29
27
- struct total {
28
- uint64_t m_total_value{};
29
- size_t m_shard_count{};
30
- };
31
-
32
- auto totals = std::unordered_map<uint64_t , total>();
30
+ auto audits = std::unordered_map<uint64_t , std::unordered_map<unsigned char , cbdc::commitment_t >>();
33
31
32
+ // todo: ensure/detect whether or not the most recent audit has finished
34
33
for (auto & audit_file : cfg.m_shard_audit_logs ) {
35
34
auto f = std::ifstream (audit_file);
36
35
if (!f.good ()) {
@@ -39,22 +38,39 @@ auto main(int argc, char** argv) -> int {
39
38
}
40
39
41
40
uint64_t epoch{};
42
- uint64_t total_value{};
43
- while (f >> epoch >> total_value) {
44
- auto it = totals.find (epoch);
45
- if (it != totals.end ()) {
46
- it->second .m_total_value += total_value;
47
- it->second .m_shard_count ++;
41
+ std::string bucket_str{};
42
+ std::string commit_hex{};
43
+ while (f >> epoch >> bucket_str >> commit_hex) {
44
+ auto bucket = static_cast <unsigned char >(std::stoul (bucket_str));
45
+
46
+ auto commitbuf = cbdc::buffer::from_hex (commit_hex);
47
+ auto commit = cbdc::from_buffer<cbdc::commitment_t >(commitbuf.value ()).value ();
48
+
49
+ auto it = audits.find (epoch);
50
+ if (it != audits.end ()) {
51
+ auto & audit = it->second ;
52
+ auto entry = audit.find (bucket);
53
+ if (entry != audit.end ()) {
54
+ if (entry->second != commit) {
55
+ std::cerr << " Audit failed at epoch " << epoch
56
+ << " ; inconsistency in range "
57
+ << bucket_str << std::endl;
58
+ return 1 ;
59
+ }
60
+ } else {
61
+ audit[bucket] = commit;
62
+ }
48
63
} else {
49
- totals[epoch] = total{total_value, 1 };
64
+ auto entries = std::unordered_map<unsigned char , cbdc::commitment_t >();
65
+ entries.emplace (bucket, std::move (commit));
66
+ audits[epoch] = std::move (entries);
50
67
}
51
68
}
52
69
}
53
70
54
- for (auto & [epoch, tot] : totals) {
55
- std::cout << " epoch: " << epoch
56
- << " , total_value: " << tot.m_total_value
57
- << " , shard_count: " << tot.m_shard_count << std::endl;
71
+ // todo: per-epoch: get a vector of all commitments, push_back circulation_commitment, check sum = 1
72
+ for (auto & [epoch, entries] : audits) {
73
+ std::cout << " epoch: " << epoch << std::endl;
58
74
}
59
75
60
76
return 0 ;
0 commit comments