@@ -52,7 +52,6 @@ abstract contract ManagerBase is
52
52
}
53
53
54
54
function _migrate () internal virtual override {
55
- _checkThresholdInvariants ();
56
55
_checkTransceiversInvariants ();
57
56
}
58
57
@@ -68,13 +67,6 @@ abstract contract ManagerBase is
68
67
69
68
// =============== Storage Getters/Setters ==============================================
70
69
71
- function _getThresholdStorage () private pure returns (_Threshold storage $) {
72
- uint256 slot = uint256 (THRESHOLD_SLOT);
73
- assembly ("memory-safe" ) {
74
- $.slot := slot
75
- }
76
- }
77
-
78
70
function _getMessageAttestationsStorage ()
79
71
internal
80
72
pure
@@ -139,15 +131,19 @@ abstract contract ManagerBase is
139
131
bytes32 nttManagerMessageHash =
140
132
TransceiverStructs.nttManagerMessageDigest (sourceChainId, payload);
141
133
134
+ // The `msg.sender` is the transceiver. Get the index for it.
135
+ uint8 index = _getTransceiverInfosStorage ()[msg .sender ].index;
136
+
137
+ // TODO: Is there a race condition with disabling a transceiver while a tx is outstanding?
138
+ if (! _isRecvTransceiverEnabledForChain (sourceChainId, index)) {
139
+ revert CallerNotTransceiver (msg .sender );
140
+ }
141
+
142
142
// set the attested flag for this transceiver.
143
143
// NOTE: Attestation is idempotent (bitwise or 1), but we revert
144
144
// anyway to ensure that the client does not continue to initiate calls
145
145
// to receive the same message through the same transceiver.
146
- if (
147
- transceiverAttestedToMessage (
148
- nttManagerMessageHash, _getTransceiverInfosStorage ()[msg .sender ].index
149
- )
150
- ) {
146
+ if (transceiverAttestedToMessage (nttManagerMessageHash, index)) {
151
147
revert TransceiverAlreadyAttestedToMessage (nttManagerMessageHash);
152
148
}
153
149
_setTransceiverAttestedToMessage (nttManagerMessageHash, msg .sender );
@@ -162,7 +158,7 @@ abstract contract ManagerBase is
162
158
) internal returns (bytes32 , bool ) {
163
159
bytes32 digest = TransceiverStructs.nttManagerMessageDigest (sourceChainId, message);
164
160
165
- if (! isMessageApproved (digest)) {
161
+ if (! isMessageApproved (sourceChainId, digest)) {
166
162
revert MessageNotApproved (digest);
167
163
}
168
164
@@ -225,7 +221,7 @@ abstract contract ManagerBase is
225
221
)
226
222
{
227
223
// cache enabled transceivers to avoid multiple storage reads
228
- address [] memory enabledTransceivers = _getEnabledTransceiversStorage ( );
224
+ address [] memory enabledTransceivers = getEnabledSendTransceiversForChain (recipientChain );
229
225
230
226
TransceiverStructs.TransceiverInstruction[] memory instructions;
231
227
@@ -280,15 +276,16 @@ abstract contract ManagerBase is
280
276
}
281
277
282
278
/// @inheritdoc IManagerBase
283
- function getThreshold () public view returns (uint8 ) {
284
- return _getThresholdStorage ().num;
279
+ /// @dev This is here because it is defined in IManagerBase.
280
+ function getThreshold (
281
+ uint16 sourceChainId
282
+ ) public view returns (uint8 ) {
283
+ return _getPerChainRecvTransceiverDataStorage ()[sourceChainId].threshold;
285
284
}
286
285
287
286
/// @inheritdoc IManagerBase
288
- function isMessageApproved (
289
- bytes32 digest
290
- ) public view returns (bool ) {
291
- uint8 threshold = getThreshold ();
287
+ function isMessageApproved (uint16 sourceChainId , bytes32 digest ) public view returns (bool ) {
288
+ uint8 threshold = getThreshold (sourceChainId);
292
289
return messageAttestations (digest) >= threshold && threshold > 0 ;
293
290
}
294
291
@@ -354,63 +351,21 @@ abstract contract ManagerBase is
354
351
address transceiver
355
352
) external onlyOwner {
356
353
_setTransceiver (transceiver);
357
-
358
- _Threshold storage _threshold = _getThresholdStorage ();
359
- // We do not automatically increase the threshold here.
360
- // Automatically increasing the threshold can result in a scenario
361
- // where in-flight messages can't be redeemed.
362
- // For example: Assume there is 1 Transceiver and the threshold is 1.
363
- // If we were to add a new Transceiver, the threshold would increase to 2.
364
- // However, all messages that are either in-flight or that are sent on
365
- // a source chain that does not yet have 2 Transceivers will only have been
366
- // sent from a single transceiver, so they would never be able to get
367
- // redeemed.
368
- // Instead, we leave it up to the owner to manually update the threshold
369
- // after some period of time, ideally once all chains have the new Transceiver
370
- // and transfers that were sent via the old configuration are all complete.
371
- // However if the threshold is 0 (the initial case) we do increment to 1.
372
- if (_threshold.num == 0 ) {
373
- _threshold.num = 1 ;
374
- }
375
-
376
- emit TransceiverAdded (transceiver, _getNumTransceiversStorage ().enabled, _threshold.num);
377
-
378
- _checkThresholdInvariants ();
354
+ emit TransceiverAdded (transceiver, _getNumTransceiversStorage ().enabled);
379
355
}
380
356
381
357
/// @inheritdoc IManagerBase
382
358
function removeTransceiver (
383
359
address transceiver
384
360
) external onlyOwner {
385
361
_removeTransceiver (transceiver);
386
-
387
- _Threshold storage _threshold = _getThresholdStorage ();
388
- uint8 numEnabledTransceivers = _getNumTransceiversStorage ().enabled;
389
-
390
- if (numEnabledTransceivers < _threshold.num) {
391
- _threshold.num = numEnabledTransceivers;
392
- }
393
-
394
- emit TransceiverRemoved (transceiver, _threshold.num);
395
-
396
- _checkThresholdInvariants ();
362
+ emit TransceiverRemoved (transceiver);
397
363
}
398
364
399
365
/// @inheritdoc IManagerBase
400
- function setThreshold (
401
- uint8 threshold
402
- ) external onlyOwner {
403
- if (threshold == 0 ) {
404
- revert ZeroThreshold ();
405
- }
406
-
407
- _Threshold storage _threshold = _getThresholdStorage ();
408
- uint8 oldThreshold = _threshold.num;
409
-
410
- _threshold.num = threshold;
411
- _checkThresholdInvariants ();
412
-
413
- emit ThresholdChanged (oldThreshold, threshold);
366
+ /// @dev This is here because it is defined in IManagerBase.
367
+ function setThreshold (uint16 sourceChainId , uint8 threshold ) external onlyOwner {
368
+ _setThreshold (sourceChainId, threshold);
414
369
}
415
370
416
371
// =============== Internal ==============================================================
@@ -480,20 +435,4 @@ abstract contract ManagerBase is
480
435
);
481
436
}
482
437
}
483
-
484
- function _checkThresholdInvariants () internal view {
485
- uint8 threshold = _getThresholdStorage ().num;
486
- _NumTransceivers memory numTransceivers = _getNumTransceiversStorage ();
487
-
488
- // invariant: threshold <= enabledTransceivers.length
489
- if (threshold > numTransceivers.enabled) {
490
- revert ThresholdTooHigh (threshold, numTransceivers.enabled);
491
- }
492
-
493
- if (numTransceivers.registered > 0 ) {
494
- if (threshold == 0 ) {
495
- revert ZeroThreshold ();
496
- }
497
- }
498
- }
499
438
}
0 commit comments