41 std::string& commit_evidence,
43 bool include_reads =
false)
47 throw std::logic_error(
"Transaction not yet committed");
52 throw std::logic_error(
"Transaction aborted");
55 if (claims_digest_.
empty())
57 throw std::logic_error(
"Missing claims");
61 const bool any_changes =
63 return it.second.changeset->has_writes();
71 auto e =
pimpl->store->get_encryptor();
77 commit_evidence = e->get_commit_evidence({
pimpl->commit_view,
version});
80 commit_evidence_digest = tx_commit_evidence_digest;
93 tx_commit_evidence_digest,
101 const auto&
map = it.second.map;
102 const auto& changeset = it.second.changeset;
103 if (
map->get_security_domain() == domain && changeset->has_writes())
105 map->serialise_changes(
106 changeset.get(), replicated_serialiser, include_reads);
112 return replicated_serialiser.get_raw_data();
120 const std::string& commit_evidence)>;
137 std::function<std::tuple<Version, Version>(
bool has_new_map)>
138 version_resolver =
nullptr,
143 throw std::logic_error(
"Transaction already committed");
155 const bool maps_created = !
pimpl->created_maps.empty();
158 this->
pimpl->store->lock_map_set();
163 std::optional<Version> new_maps_conflict_version = std::nullopt;
165 bool track_deletes_on_missing_keys =
false;
166 auto c = apply_changes(
168 version_resolver ==
nullptr ?
169 [&](
bool has_new_map) {
170 return pimpl->store->next_version(has_new_map);
175 new_maps_conflict_version,
176 track_deletes_on_missing_keys);
180 this->
pimpl->store->unlock_map_set();
183 success = c.has_value();
189 LOG_TRACE_FMT(
"Could not commit transaction due to conflict");
198 auto chunker =
pimpl->store->get_chunker();
201 chunker->force_end_of_chunk(
version);
207 pimpl->store->set_flag(
224 std::string commit_evidence;
225 auto data =
serialise(commit_evidence_digest, commit_evidence, claims);
232 if (write_set_observer !=
nullptr)
235 write_set_observer(ws_digest, commit_evidence);
238 auto claims_ = claims;
240 return pimpl->store->commit(
242 std::make_unique<MovePendingTx>(
245 std::move(commit_evidence_digest),
249 catch (
const std::exception& e)
273 throw std::logic_error(
"Transaction not yet committed");
278 throw std::logic_error(
"Transaction aborted");
295 throw std::logic_error(
"Transaction not yet committed");
300 throw std::logic_error(
"Transaction aborted");
303 return pimpl->commit_view;
310 throw std::logic_error(
"Transaction not yet committed");
313 if (!
pimpl->read_txid.has_value())
324 return pimpl->read_txid;
333 if (
pimpl->read_txid.has_value())
335 throw std::logic_error(
"Read TxID already set");
337 pimpl->read_txid = tx_id;
338 pimpl->commit_view = commit_view_;
353 flags &= ~static_cast<TxFlags>(flag);
378 const TxID& reserved_tx_id,
381 rollback_count(rollback_count_)
384 pimpl->commit_view = reserved_tx_id.
view;
393 throw std::logic_error(
"Transaction already committed");
398 throw std::logic_error(
"Reserved transaction cannot be empty");
401 std::vector<ConsensusHookPtr> hooks;
402 bool track_deletes_on_missing_keys =
false;
403 auto c = apply_changes(
409 track_deletes_on_missing_keys,
415 if (
pimpl->store->check_rollback_count(rollback_count))
417 throw std::logic_error(
"Failed to commit reserved transaction");
426 std::string commit_evidence;
431 if (
pimpl->store->should_create_ledger_chunk_unsafe(
version))
435 "Ending ledger chunk with signature at {}.{}",
439 auto chunker =
pimpl->store->get_chunker();
442 chunker->produced_chunk_at(
version);
447 auto claims = ccf::empty_claims();
448 auto data =
serialise(commit_evidence_digest, commit_evidence, claims);
454 std::move(commit_evidence_digest),
Definition claims_digest.h:10
bool empty() const
Definition claims_digest.h:33
Definition sha256_hash.h:16
Definition kv_types.h:632
@ SNAPSHOT_AT_NEXT_SIGNATURE
OrderedChanges all_changes
Definition tx.h:51
std::optional< ccf::crypto::Sha256Hash > root_at_read_version
Definition tx.h:53
std::unique_ptr< PrivateImpl > pimpl
Definition tx.h:49
Definition committable_tx.h:19
SerialisedEntryFlags entry_flags
Definition committable_tx.h:37
std::vector< uint8_t > serialise(ccf::crypto::Sha256Hash &commit_evidence_digest, std::string &commit_evidence, const ccf::ClaimsDigest &claims_digest_, bool include_reads=false)
Definition committable_tx.h:39
bool success
Definition committable_tx.h:32
bool committed
Definition committable_tx.h:31
Version version
Definition committable_tx.h:34
virtual void unset_tx_flag(TxFlag flag)
Definition committable_tx.h:351
Version commit_term() const
Definition committable_tx.h:291
void set_read_txid(const TxID &tx_id, Term commit_view_)
Definition committable_tx.h:331
TxFlag
Definition committable_tx.h:24
@ LEDGER_CHUNK_AT_NEXT_SIGNATURE
@ SNAPSHOT_AT_NEXT_SIGNATURE
@ LEDGER_CHUNK_BEFORE_THIS_TX
virtual bool tx_flag_enabled(TxFlag f) const
Definition committable_tx.h:356
CommitResult commit(const ccf::ClaimsDigest &claims=ccf::empty_claims(), std::function< std::tuple< Version, Version >(bool has_new_map)> version_resolver=nullptr, WriteSetObserver write_set_observer=nullptr)
Definition committable_tx.h:135
Version commit_version() const
Definition committable_tx.h:269
uint8_t TxFlags
Definition committable_tx.h:21
std::function< void(const ccf::crypto::Sha256Hash &write_set_digest, const std::string &commit_evidence)> WriteSetObserver
Definition committable_tx.h:120
void set_root_at_read_version(const ccf::crypto::Sha256Hash &r)
Definition committable_tx.h:341
CommittableTx(AbstractStore *_store)
Definition committable_tx.h:116
TxFlags flags
Definition committable_tx.h:36
std::optional< TxID > get_txid() const
Definition committable_tx.h:306
virtual void set_tx_flag(TxFlag flag)
Definition committable_tx.h:346
Definition generic_serialise_wrapper.h:21
Definition kv_types.h:318
Definition committable_tx.h:370
ReservedTx(AbstractStore *_store, Term read_term, const TxID &reserved_tx_id, Version rollback_count_)
Definition committable_tx.h:375
PendingTxInfo commit_reserved()
Definition committable_tx.h:389
#define LOG_TRACE_FMT
Definition internal_logger.h:13
#define LOG_DEBUG_FMT
Definition internal_logger.h:14
#define LOG_FAIL_FMT
Definition internal_logger.h:16
Definition app_interface.h:18
uint64_t Term
Definition kv_types.h:46
@ WriteSetWithCommitEvidenceAndClaims
CommitResult
Definition kv_types.h:212
@ FAIL_NO_REPLICATE
Definition kv_types.h:215
@ SUCCESS
Definition kv_types.h:213
@ FAIL_CONFLICT
Definition kv_types.h:214
@ PRIVATE
Definition kv_types.h:221
@ PUBLIC
Definition kv_types.h:220
uint64_t Version
Definition version.h:10
uint8_t SerialisedEntryFlags
Definition serialised_entry_format.h:12
@ FORCE_LEDGER_CHUNK_BEFORE
Definition serialised_entry_format.h:17
@ FORCE_LEDGER_CHUNK_AFTER
Definition serialised_entry_format.h:16
std::vector< ConsensusHookPtr > ConsensusHookPtrs
Definition hooks.h:22
Definition map_serializers.h:11
SeqNo seqno
Definition tx_id.h:46
View view
Definition tx_id.h:45
Definition kv_types.h:430