sawtooth-core
sawtooth-core copied to clipboard
fix(commit_store): fix bug in `get_batch_by_transaction`
This PR fixes a bug in the sawtooth_validator::journal::commit_store::CommitStore
's get_batch_by_transaction
method, which heretofore returned the first batch that does not contain the provided transaction_id
argument without any error.
The equivalent Python method calls the Rust method via FFI:
# validator/sawtooth_validator/journal/block_store.py
def get_batch_by_transaction(self, transaction_id):
"""
Check to see if the requested transaction_id is in the current chain.
If so, find the batch that has the transaction referenced by the
transaction_id and return the batch. This is done by finding the block
and searching for the batch.
:param transaction_id (string): The id of the transaction that is being
requested.
:return:
The batch that has the transaction.
"""
payload = self._get_data_by_id(
transaction_id, 'commit_store_get_batch_by_transaction')
batch = Batch()
batch.ParseFromString(payload)
return batch
Here's commit_store_get_batch_by_transaction
, which is called in the snippet above and calls get_batch_by_transaction
:
//! validator/src/journal/commit_store_ffi.rs
#[no_mangle]
pub unsafe extern "C" fn commit_store_get_batch_by_transaction(
commit_store: *mut c_void,
transaction_id: *const c_char,
batch_ptr: *mut *const u8,
batch_len: *mut usize,
batch_cap: *mut usize,
) -> ErrorCode {
check_null!(commit_store, transaction_id);
match deref_cstr(transaction_id) {
Ok(transaction_id) => {
match (*(commit_store as *mut CommitStore)).get_batch_by_transaction(transaction_id) {
Ok(batch) => return_batch(batch, batch_ptr, batch_len, batch_cap),
Err(err) => map_database_error(err),
}
}
Err(err) => err,
}
}
Concomitant changes were merged into sawtooth-lib
in this PR.
Original work
Signed-off-by: Joseph Livesey [email protected]
Rebase should resolve the jenkins build error (it should be excluded).