Skip to content

Commit 469776d

Browse files
committed
refactor: remove unused participant confirmation and protocol completion functions
1 parent fe25d6b commit 469776d

File tree

3 files changed

+16
-67
lines changed

3 files changed

+16
-67
lines changed

src/core/CrossStore.sol

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,6 @@ abstract contract CrossStore {
104104
compact.ackMask = _uint32ArrayToMask(data.acks);
105105
}
106106

107-
function _confirmParticipant(bytes32 txID) internal {
108-
_getCoordStorage().compactStates[txID].confirmedMask |= 0x02;
109-
}
110-
111-
function _completeSimpleProtocol(
112-
bytes32 txID,
113-
CoordinatorState.CoordinatorPhase phase,
114-
CoordinatorState.CoordinatorDecision decision
115-
) internal {
116-
CoordStateCompact storage compact = _getCoordStorage().compactStates[txID];
117-
compact.phase = phase;
118-
compact.decision = decision;
119-
compact.ackMask |= 0x03;
120-
}
121-
122107
function _maskToUint32Array(uint8 mask) internal pure returns (uint32[] memory) {
123108
uint256 count = 0;
124109
if ((mask & 0x01) != 0) ++count;

src/core/TxAtomicSimple.sol

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,7 @@ abstract contract TxAtomicSimple is
352352
}
353353

354354
// Mark Participant prepare as confirmed
355-
if (!_containsUint32(cs.confirmed_txs, TX_INDEX_PARTICIPANT)) {
356-
_confirmParticipant(txID);
357-
}
355+
cs.confirmed_txs = _addToUint32Array(cs.confirmed_txs, TX_INDEX_PARTICIPANT);
358356

359357
// --- 5. Determine Commit/Abort based on ACK ---
360358

@@ -373,16 +371,10 @@ abstract contract TxAtomicSimple is
373371
cs.phase = CoordinatorState.CoordinatorPhase.COORDINATOR_PHASE_COMMIT;
374372

375373
// Set ACK flags
376-
CoordinatorState.CoordinatorDecision decision;
377-
if (ack.status == PacketAcknowledgementCall.CommitStatus.COMMIT_STATUS_OK) {
378-
decision = CoordinatorState.CoordinatorDecision.COORDINATOR_DECISION_COMMIT;
379-
} else {
380-
decision = CoordinatorState.CoordinatorDecision.COORDINATOR_DECISION_ABORT;
381-
}
382-
383-
_completeSimpleProtocol(txID, CoordinatorState.CoordinatorPhase.COORDINATOR_PHASE_COMMIT, decision);
374+
cs.acks = _addToUint32Array(cs.acks, TX_INDEX_COORDINATOR);
375+
cs.acks = _addToUint32Array(cs.acks, TX_INDEX_PARTICIPANT);
384376

385-
cs = _loadCoordinatorState(txID);
377+
_saveCoordinatorState(txID, cs);
386378

387379
bool allPrepares =
388380
_containsUint32(cs.confirmed_txs, TX_INDEX_COORDINATOR)
@@ -463,6 +455,18 @@ abstract contract TxAtomicSimple is
463455
return false;
464456
}
465457

458+
function _addToUint32Array(uint32[] memory arr, uint32 val) internal view returns (uint32[] memory) {
459+
if (_containsUint32(arr, val)) {
460+
return arr;
461+
}
462+
uint32[] memory newArr = new uint32[](arr.length + 1);
463+
for (uint256 i = 0; i < arr.length; i++) {
464+
newArr[i] = arr[i];
465+
}
466+
newArr[arr.length] = val;
467+
return newArr;
468+
}
469+
466470
function packPacketAcknowledgementCall(PacketAcknowledgementCall.Data memory ack)
467471
internal
468472
pure

test/CrossStore.t.sol

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ contract CrossStoreHarness is CrossStore {
5050
_saveCoordinatorState(txID, data);
5151
}
5252

53-
function exposed_confirmParticipant(bytes32 txID) public {
54-
_confirmParticipant(txID);
55-
}
56-
57-
function exposed_completeSimpleProtocol(
58-
bytes32 txID,
59-
CoordinatorState.CoordinatorPhase phase,
60-
CoordinatorState.CoordinatorDecision decision
61-
) public {
62-
_completeSimpleProtocol(txID, phase, decision);
63-
}
64-
6553
function exposed_maskToUint32Array(uint8 mask) public pure returns (uint32[] memory) {
6654
return _maskToUint32Array(mask);
6755
}
@@ -268,32 +256,4 @@ contract CrossStoreTest is Test {
268256
acks: new uint32[](0)
269257
});
270258
}
271-
272-
function test_confirmParticipant_UpdatesMask() public {
273-
bytes32 txId = keccak256("tx.confirm");
274-
275-
test_SaveAndLoad_CoordinatorState();
276-
txId = keccak256("tx.save.load");
277-
278-
harness.exposed_confirmParticipant(txId);
279-
280-
CoordinatorState.Data memory loaded = harness.exposed_loadCoordinatorState(txId);
281-
assertEq(loaded.confirmed_txs.length, 2, "Should have 2 confirmed txs");
282-
assertEq(loaded.confirmed_txs[1], 1, "Participant should be confirmed");
283-
}
284-
285-
function test_completeSimpleProtocol_SetsCorrectValues() public {
286-
bytes32 txId = keccak256("tx.complete");
287-
288-
harness.exposed_completeSimpleProtocol(
289-
txId,
290-
CoordinatorState.CoordinatorPhase.COORDINATOR_PHASE_COMMIT,
291-
CoordinatorState.CoordinatorDecision.COORDINATOR_DECISION_COMMIT
292-
);
293-
294-
CoordinatorState.Data memory loaded = harness.exposed_loadCoordinatorState(txId);
295-
assertEq(uint256(loaded.phase), uint256(CoordinatorState.CoordinatorPhase.COORDINATOR_PHASE_COMMIT));
296-
assertEq(uint256(loaded.decision), uint256(CoordinatorState.CoordinatorDecision.COORDINATOR_DECISION_COMMIT));
297-
assertEq(loaded.acks.length, 2, "Both Coord and Participant should be in ACKs");
298-
}
299259
}

0 commit comments

Comments
 (0)