Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

fix(commit_store): fix bug in get_batch_by_transaction #31

Open
wants to merge 3 commits into
base: btp-releases/1-2
Choose a base branch
from

Conversation

suchapalaver
Copy link

@suchapalaver suchapalaver commented Feb 22, 2023

sawtooth_validator::journal::commit_store::CommitStore::get_batch_by_transaction contains a bug where the method will return the first batch that does not contain the provided transaction_id 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

//! 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,
    }
}

Signed-off-by: Joseph Livesey joseph.livesey@btp.works

@suchapalaver suchapalaver force-pushed the fix/fix-bug-in-commit-store-get-batch-by-transaction branch from b38eed6 to 1805f50 Compare February 22, 2023 17:44
@suchapalaver suchapalaver changed the title fix(commit_store): fix bug in get_batch_by_transaction fix(commit_store): fix bug in get_batch_by_transaction Feb 22, 2023
@suchapalaver suchapalaver force-pushed the fix/fix-bug-in-commit-store-get-batch-by-transaction branch from 1805f50 to 8235ad2 Compare February 24, 2023 15:32
@suchapalaver suchapalaver force-pushed the fix/fix-bug-in-commit-store-get-batch-by-transaction branch 2 times, most recently from 93c0a2a to e7e5653 Compare March 3, 2023 15:57
Signed-off-by: Joseph Livesey <joseph.livesey@btp.works>
Signed-off-by: Joseph Livesey <joseph.livesey@btp.works>
…ction

Signed-off-by: Joseph Livesey <joseph.livesey@btp.works>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants