Skip to content

Commit

Permalink
Reconciliation with sentinel attestations
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Stuewe <[email protected]>
  • Loading branch information
HalosGhost committed Jun 6, 2022
1 parent 0236ec2 commit ea6735a
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/uhs/atomizer/sentinel/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ namespace cbdc::sentinel {
if(!res.has_value()) {
m_logger->debug("Accepted tx:", cbdc::to_string(tx_id));
// Only forward transactions that are valid
const transaction::compact_tx ctx(tx);
send_transaction(ctx);
send_transaction(tx);
} else {
m_logger->debug("Rejected tx:", cbdc::to_string(tx_id));
}

return response{status, res};
return execute_response{status, res};
}

void controller::send_transaction(const transaction::compact_tx& tx) {
// todo: need to take a full_tx instead of a compact_tx for gather_attestations
void controller::send_transaction(const transaction::full_tx& tx) {
const auto compact_tx = cbdc::transaction::compact_tx(tx);
auto ctx_pkt = std::make_shared<cbdc::buffer>();
auto ctx_ser = cbdc::buffer_serializer(*ctx_pkt);
Expand Down
2 changes: 1 addition & 1 deletion src/uhs/atomizer/sentinel/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace cbdc::sentinel {

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

void send_transaction(const transaction::compact_tx& tx);
void send_transaction(const transaction::full_tx& tx);
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/uhs/transaction/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ namespace cbdc::transaction {

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

/// Equality of two compact transactions. Only compares the transaction
/// IDs.
Expand Down
8 changes: 2 additions & 6 deletions src/uhs/twophase/locking_shard/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@
namespace cbdc::locking_shard {
/// Transaction type processed by locking shards.
struct tx {
/// The TX ID of the transaction, if provided.
std::optional<hash_t> m_tx_id{};
/// Vector of input hashes for the shard to process as spent.
std::vector<hash_t> m_spending{};
/// Vector of output hashes to create on the shard.
std::vector<transaction::compact_output> m_creating{};
/// Compact TX.
transaction::compact_tx m_tx;

auto operator==(const tx& rhs) const -> bool;
};
Expand Down
2 changes: 1 addition & 1 deletion src/uhs/twophase/locking_shard/locking_shard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace cbdc::locking_shard {
m_completed_txs.add(tx.m_tx.m_id);
}

for(auto&& proof : tx.m_creating) {
for(auto&& proof : tx.m_tx.m_outputs) {
auto uhs_id = proof.m_id;
if(hash_in_shard_range(uhs_id) && complete_txs[i]) {
m_uhs.emplace(uhs_id);
Expand Down
24 changes: 20 additions & 4 deletions tests/unit/locking_shard/format_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,26 @@ class locking_shard_format_test : public ::testing::Test {
cbdc::buffer_serializer m_ser{m_target_packet};
cbdc::buffer_serializer m_deser{m_target_packet};

cbdc::locking_shard::tx m_tx{
std::optional<cbdc::hash_t>({'a', 'b', 'c'}),
{{'d', 'e', 'f'}, {'g', 'h', 'i'}},
{{{'w'}, {'x'}, {'y'}, {'z'}}, {{'z'}, {'z'}, {'z'}, {'z'}}}};
cbdc::locking_shard::tx m_tx{};

void SetUp () {
m_tx.m_tx.m_id = {'a', 'b', 'c'};
m_tx.m_tx.m_inputs = {
{'d', 'e', 'f'},
{'g', 'h', 'i'}
};
m_tx.m_tx.m_outputs = {
{
{'w'}, {'x'}, {'y'}, {'z'}
},
{
{'z'}, {'z'}, {'z'}, {'z'}
}
};
m_tx.m_tx.m_attestations = {
{{'a'}, {'b'}}
};
}
};

TEST_F(locking_shard_format_test, tx) {
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/twophase_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ TEST_F(TwoPhaseTest, test_one_shard) {
auto tx = cbdc::locking_shard::tx();
auto uhs_id = cbdc::hash_t();
std::memcpy(uhs_id.data(), &i, sizeof(i));
tx.m_creating.push_back({uhs_id, {}, {}, {}});
tx.m_tx.m_outputs.push_back({uhs_id, {}, {}, {}});
txs.push_back(tx);
}

Expand Down Expand Up @@ -115,8 +115,8 @@ TEST_F(TwoPhaseTest, test_one_shard_random) {
const auto val = rnd(e);
std::memcpy(&output1[j * 8], &val, sizeof(val));
}
tx.m_creating.push_back({output0, {}, {}, {}});
tx.m_creating.push_back({output1, {}, {}, {}});
tx.m_tx.m_outputs.push_back({output0, {}, {}, {}});
tx.m_tx.m_outputs.push_back({output1, {}, {}, {}});
outputs.push(output0);
outputs.push(output1);
txs.push_back(tx);
Expand Down Expand Up @@ -144,9 +144,9 @@ TEST_F(TwoPhaseTest, test_one_shard_random) {
const auto val = rnd(e);
std::memcpy(&output1[j * 8], &val, sizeof(val));
}
tx.m_creating.push_back({output0, {}, {}, {}});
tx.m_creating.push_back({output1, {}, {}, {}});
tx.m_spending.push_back(outputs.front());
tx.m_tx.m_outputs.push_back({output0, {}, {}, {}});
tx.m_tx.m_outputs.push_back({output1, {}, {}, {}});
tx.m_tx.m_inputs.push_back(outputs.front());
outputs.pop();
tx.m_tx.m_inputs.push_back(outputs.front());
outputs.pop();
Expand Down

0 comments on commit ea6735a

Please sign in to comment.