Skip to content

Commit

Permalink
fix: removed conditional for after confirmation case
Browse files Browse the repository at this point in the history
  • Loading branch information
sendra committed Jan 9, 2024
1 parent 72f5a1c commit f6fc653
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 33 deletions.
16 changes: 3 additions & 13 deletions src/contracts/CrossChainReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,6 @@ contract CrossChainReceiver is OwnableWithGuardian, ICrossChainReceiver {

bytes32 transactionId = TransactionUtils.getId(encodedTransaction);

// if envelope was confirmed before, just return
if (_envelopesState[envelopeId] != EnvelopeState.None) {
emit TransactionReceivedWhenConfirmed(
transactionId,
envelopeId,
originChainId,
transaction,
msg.sender
);
return;
}

TransactionState storage internalTransaction = _transactionsState[transactionId];
ReceiverConfiguration memory configuration = _configurationsByChain[originChainId]
.configuration;
Expand Down Expand Up @@ -209,9 +197,11 @@ contract CrossChainReceiver is OwnableWithGuardian, ICrossChainReceiver {
// from additional bridges after reaching required number of confirmations
// >= is used for the case when confirmations gets lowered before message reached the old _requiredConfirmations
// but on receiving new messages it surpasses the current _requiredConfirmations. So it doesn't get stuck (if using ==)
// Envelope can only be set as confirmed or delivered once
if (
configuration.requiredConfirmation > 0 &&
newConfirmations >= configuration.requiredConfirmation
newConfirmations >= configuration.requiredConfirmation &&
_envelopesState[envelopeId] == EnvelopeState.None
) {
_envelopesState[envelopeId] = EnvelopeState.Delivered;
try
Expand Down
16 changes: 0 additions & 16 deletions src/contracts/interfaces/ICrossChainReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,6 @@ interface ICrossChainReceiver {
Delivered
}

/**
* @notice emitted when a transaction has been received after a message has already been confirmed
* @param transactionId id of the transaction
* @param envelopeId id of the envelope
* @param originChainId id of the chain where the envelope originated
* @param transaction the Transaction type data
* @param bridgeAdapter address of the bridge adapter who received the message (deployed on current network)
*/
event TransactionReceivedWhenConfirmed(
bytes32 transactionId,
bytes32 indexed envelopeId,
uint256 indexed originChainId,
Transaction transaction,
address indexed bridgeAdapter
);

/**
* @notice emitted when a transaction has been received successfully
* @param transactionId id of the transaction
Expand Down
9 changes: 5 additions & 4 deletions tests/CrossChainReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,13 @@ contract CrossChainReceiverTest is BaseTest {
// receive 2nd cross chain message after its already confirmed
hoax(BRIDGE_ADAPTER_2);
vm.expectEmit(true, true, true, true);
emit TransactionReceivedWhenConfirmed(
emit TransactionReceived(
txExtended.transactionId,
txExtended.envelopeId,
txExtended.envelope.originChainId,
txExtended.transaction,
BRIDGE_ADAPTER_2
BRIDGE_ADAPTER_2,
2
);
crossChainReceiver.receiveCrossChainMessage(
txExtended.transactionEncoded,
Expand All @@ -521,12 +522,12 @@ contract CrossChainReceiverTest is BaseTest {
// check internal transaction
assertEq(
crossChainReceiver.isTransactionReceivedByAdapter(txExtended.transactionId, BRIDGE_ADAPTER_2),
false
true
);
internalTransactionState = crossChainReceiver.getTransactionState(txExtended.transactionId);
internalEnvelopeState = crossChainReceiver.getEnvelopeState(txExtended.envelopeId);

assertEq(internalTransactionState.confirmations, 1);
assertEq(internalTransactionState.confirmations, 2);
assertEq(internalTransactionState.firstBridgedAt, block.timestamp);
assertTrue(internalEnvelopeState == ICrossChainReceiver.EnvelopeState.Delivered);
}
Expand Down

0 comments on commit f6fc653

Please sign in to comment.