Skip to content

Commit ea6735a

Browse files
committed
Reconciliation with sentinel attestations
Signed-off-by: Sam Stuewe <[email protected]>
1 parent 0236ec2 commit ea6735a

File tree

7 files changed

+35
-23
lines changed

7 files changed

+35
-23
lines changed

src/uhs/atomizer/sentinel/controller.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,16 @@ namespace cbdc::sentinel {
9797
if(!res.has_value()) {
9898
m_logger->debug("Accepted tx:", cbdc::to_string(tx_id));
9999
// Only forward transactions that are valid
100-
const transaction::compact_tx ctx(tx);
101-
send_transaction(ctx);
100+
send_transaction(tx);
102101
} else {
103102
m_logger->debug("Rejected tx:", cbdc::to_string(tx_id));
104103
}
105104

106-
return response{status, res};
105+
return execute_response{status, res};
107106
}
108107

109-
void controller::send_transaction(const transaction::compact_tx& tx) {
108+
// todo: need to take a full_tx instead of a compact_tx for gather_attestations
109+
void controller::send_transaction(const transaction::full_tx& tx) {
110110
const auto compact_tx = cbdc::transaction::compact_tx(tx);
111111
auto ctx_pkt = std::make_shared<cbdc::buffer>();
112112
auto ctx_ser = cbdc::buffer_serializer(*ctx_pkt);

src/uhs/atomizer/sentinel/controller.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace cbdc::sentinel {
9898

9999
void send_compact_tx(const transaction::compact_tx& ctx);
100100

101-
void send_transaction(const transaction::compact_tx& tx);
101+
void send_transaction(const transaction::full_tx& tx);
102102
};
103103
}
104104

src/uhs/transaction/transaction.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ namespace cbdc::transaction {
206206

207207
/// Signatures from sentinels attesting the compact TX is valid.
208208
std::unordered_map<pubkey_t, signature_t, hashing::null>
209-
m_attestations;
209+
m_attestations{};
210210

211211
/// Equality of two compact transactions. Only compares the transaction
212212
/// IDs.

src/uhs/twophase/locking_shard/interface.hpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@
1616
namespace cbdc::locking_shard {
1717
/// Transaction type processed by locking shards.
1818
struct tx {
19-
/// The TX ID of the transaction, if provided.
20-
std::optional<hash_t> m_tx_id{};
21-
/// Vector of input hashes for the shard to process as spent.
22-
std::vector<hash_t> m_spending{};
23-
/// Vector of output hashes to create on the shard.
24-
std::vector<transaction::compact_output> m_creating{};
19+
/// Compact TX.
20+
transaction::compact_tx m_tx;
2521

2622
auto operator==(const tx& rhs) const -> bool;
2723
};

src/uhs/twophase/locking_shard/locking_shard.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ namespace cbdc::locking_shard {
166166
m_completed_txs.add(tx.m_tx.m_id);
167167
}
168168

169-
for(auto&& proof : tx.m_creating) {
169+
for(auto&& proof : tx.m_tx.m_outputs) {
170170
auto uhs_id = proof.m_id;
171171
if(hash_in_shard_range(uhs_id) && complete_txs[i]) {
172172
m_uhs.emplace(uhs_id);

tests/unit/locking_shard/format_test.cpp

+20-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,26 @@ class locking_shard_format_test : public ::testing::Test {
1414
cbdc::buffer_serializer m_ser{m_target_packet};
1515
cbdc::buffer_serializer m_deser{m_target_packet};
1616

17-
cbdc::locking_shard::tx m_tx{
18-
std::optional<cbdc::hash_t>({'a', 'b', 'c'}),
19-
{{'d', 'e', 'f'}, {'g', 'h', 'i'}},
20-
{{{'w'}, {'x'}, {'y'}, {'z'}}, {{'z'}, {'z'}, {'z'}, {'z'}}}};
17+
cbdc::locking_shard::tx m_tx{};
18+
19+
void SetUp () {
20+
m_tx.m_tx.m_id = {'a', 'b', 'c'};
21+
m_tx.m_tx.m_inputs = {
22+
{'d', 'e', 'f'},
23+
{'g', 'h', 'i'}
24+
};
25+
m_tx.m_tx.m_outputs = {
26+
{
27+
{'w'}, {'x'}, {'y'}, {'z'}
28+
},
29+
{
30+
{'z'}, {'z'}, {'z'}, {'z'}
31+
}
32+
};
33+
m_tx.m_tx.m_attestations = {
34+
{{'a'}, {'b'}}
35+
};
36+
}
2137
};
2238

2339
TEST_F(locking_shard_format_test, tx) {

tests/unit/twophase_test.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ TEST_F(TwoPhaseTest, test_one_shard) {
3434
auto tx = cbdc::locking_shard::tx();
3535
auto uhs_id = cbdc::hash_t();
3636
std::memcpy(uhs_id.data(), &i, sizeof(i));
37-
tx.m_creating.push_back({uhs_id, {}, {}, {}});
37+
tx.m_tx.m_outputs.push_back({uhs_id, {}, {}, {}});
3838
txs.push_back(tx);
3939
}
4040

@@ -115,8 +115,8 @@ TEST_F(TwoPhaseTest, test_one_shard_random) {
115115
const auto val = rnd(e);
116116
std::memcpy(&output1[j * 8], &val, sizeof(val));
117117
}
118-
tx.m_creating.push_back({output0, {}, {}, {}});
119-
tx.m_creating.push_back({output1, {}, {}, {}});
118+
tx.m_tx.m_outputs.push_back({output0, {}, {}, {}});
119+
tx.m_tx.m_outputs.push_back({output1, {}, {}, {}});
120120
outputs.push(output0);
121121
outputs.push(output1);
122122
txs.push_back(tx);
@@ -144,9 +144,9 @@ TEST_F(TwoPhaseTest, test_one_shard_random) {
144144
const auto val = rnd(e);
145145
std::memcpy(&output1[j * 8], &val, sizeof(val));
146146
}
147-
tx.m_creating.push_back({output0, {}, {}, {}});
148-
tx.m_creating.push_back({output1, {}, {}, {}});
149-
tx.m_spending.push_back(outputs.front());
147+
tx.m_tx.m_outputs.push_back({output0, {}, {}, {}});
148+
tx.m_tx.m_outputs.push_back({output1, {}, {}, {}});
149+
tx.m_tx.m_inputs.push_back(outputs.front());
150150
outputs.pop();
151151
tx.m_tx.m_inputs.push_back(outputs.front());
152152
outputs.pop();

0 commit comments

Comments
 (0)