Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsec atomic commit fix #246

Merged
merged 3 commits into from
Jan 17, 2024
Merged

Parsec atomic commit fix #246

merged 3 commits into from
Jan 17, 2024

Conversation

maurermi
Copy link
Collaborator

Fixes a bug which occurs when a smart contract does not request locks on all update keys, resulting in undesirable behavior.

Aborts a transaction where the agent does not have tickets associated with all update keys. In the case that a contract does not prompt for all update keys to be locked, enforces that the transaction aborts (+ rolls back) and no updates are written, rather than those which are locked. Does not abort if the smart contract correctly requested locks and is still waiting on them, but still rolls back and retries.

@maurermi
Copy link
Collaborator Author

Thanks to @ayeshaali and @madars for identifying this

@maurermi
Copy link
Collaborator Author

This PR also contains a new util called get_row which is also included in #241 to enable the integration tests included with this PR. If this is not wanted, we can keep only the commit which fixes this behavior.

@maurermi maurermi changed the title Atomic commit Parsec atomic commit fix Jan 13, 2024
Copy link
Collaborator

@anders94 anders94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - nit-picks only.

@@ -183,6 +184,8 @@ namespace cbdc::parsec {
cfg.m_runner_type = runner_type::evm;
} else if(val == "lua") {
cfg.m_runner_type = runner_type::lua;
} else if(val == "py") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I love this, I don't believe this should be in here - part of the other PR you are on AFAIK

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

@@ -25,6 +25,8 @@ namespace cbdc::parsec {
lua,
/// Ethereum-style transactions using EVM.
evm,
/// Python Script using CPython
py,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here

@@ -71,6 +73,20 @@ namespace cbdc::parsec {
broker::key_type key,
broker::value_type value,
const std::function<void(bool)>& result_callback) -> bool;

/// Asynchronously get the value stored at key from the cluster.
/// Intended for testing purposes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit-picky but potentially administrative functions as well like migrating keys? I wouldn't use that example but maybe the comment should say "testing and administration purposes" instead?

Yes, I did just add a review comment on a code comment... :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can get on board with that, will update

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context, this comment is trying to convey that this is not the optimal method for reading from the shards as a system component, it is better to handle shard responses in the agent

Adds a tool to get information directly from the
shards, for debug and testing purposes.

Signed-off-by: Michael Maurer <[email protected]>
Addresses a bug identified which allows for a smart contract
to return an update map containing keys that the agent has
not acquired tickets for. This fix ensures that when smart
contract execution completes, all updates will be committed
or none of them will. Previously, committed changes which
the agent held write locks for would be committed, but changes
which never had ticket requests made would silently fail.
Note: if a key has a ticket but is waiting on a lock, the
transaction rolls back and retries. If a ticket has not
been acquired, the transaction should fail as the contract
specifically needs to request locks on important keys.

Signed-off-by: Michael Maurer <[email protected]>
Adds an integration test to ensure that updates either
all commit or none of them do in parsec. Specifically
ensures that a commit attempt where not all update keys
have associated tickets aborts.

Signed-off-by: Michael Maurer <[email protected]>
@HalosGhost
Copy link
Collaborator

utACK, clear and simple fix (core fix in 1e51249) to throw a reasonable error in the agent if a change-set includes modifications to keys which don't have tickets.

I also want to call out how easy it is to review this PR because of the pleasant separation of the commits. CI passed, and the output for the added integration tests looks good:

Running integration tests...
Running main() from /build/googletest-j5yxiC/googletest-1.10.0/googletest/src/gtest_main.cc
[==========] Running 23 tests from 11 test suites.
[----------] Global test environment set-up.
[----------] 2 tests from parsec_smart_contract_updates_test
[ RUN      ] parsec_smart_contract_updates_test.valid_updates
[       OK ] parsec_smart_contract_updates_test.valid_updates (1038 ms)
[ RUN      ] parsec_smart_contract_updates_test.invalid_updates
Error: 1-13 16:47:58.584] [ERROR] Update map contains keys not associated with tickets. Aborting.
Error: 1-13 16:47:58.585] [ERROR] Broker error for commit for 14
[2024-01-13 16:47:58.585] [WARN ] Exec failed
[       OK ] parsec_smart_contract_updates_test.invalid_updates (1036 ms)
[----------] 2 tests from parsec_smart_contract_updates_test (2074 ms total)

Copy link
Collaborator

@HalosGhost HalosGhost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK. Does what it says on the tin! Merging.

@HalosGhost HalosGhost merged commit c3ea4df into mit-dci:trunk Jan 17, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants