Skip to content

Commit 52d3a80

Browse files
RahulMaganti47Rahul Maganti
and
Rahul Maganti
authored
feat: make the consistency level on the WormholeEndpoint configurable (#165)
Co-authored-by: Rahul Maganti <rahulmaganti@Rahuls-MacBook-Pro.local>
1 parent a4530ec commit 52d3a80

5 files changed

+130
-29
lines changed

evm/src/WormholeEndpoint.sol

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ abstract contract WormholeEndpoint is Endpoint, IWormholeEndpoint, IWormholeRece
1414
using BytesParsing for bytes;
1515

1616
uint256 public constant GAS_LIMIT = 500000;
17-
uint8 public constant CONSISTENCY_LEVEL = 1;
17+
uint8 public immutable consistencyLevel;
1818

1919
/// @dev Prefix for all EndpointMessage payloads
2020
/// This is 0x99'E''W''H'
@@ -116,12 +116,14 @@ abstract contract WormholeEndpoint is Endpoint, IWormholeEndpoint, IWormholeRece
116116
address manager,
117117
address wormholeCoreBridge,
118118
address wormholeRelayerAddr,
119-
address specialRelayerAddr
119+
address specialRelayerAddr,
120+
uint8 _consistencyLevel
120121
) Endpoint(manager) {
121122
wormhole = IWormhole(wormholeCoreBridge);
122123
wormholeRelayer = IWormholeRelayer(wormholeRelayerAddr);
123124
specialRelayer = ISpecialRelayer(specialRelayerAddr);
124125
wormholeEndpoint_evmChainId = block.chainid;
126+
consistencyLevel = _consistencyLevel;
125127
}
126128

127129
function _checkInvalidRelayingConfig(uint16 chainId) internal view returns (bool) {
@@ -189,12 +191,12 @@ abstract contract WormholeEndpoint is Endpoint, IWormholeEndpoint, IWormholeRece
189191
GAS_LIMIT
190192
);
191193
} else if (!weIns.shouldSkipRelayerSend && isSpecialRelayingEnabled(recipientChain)) {
192-
uint64 sequence = wormhole.publishMessage(0, encodedEndpointPayload, CONSISTENCY_LEVEL);
194+
uint64 sequence = wormhole.publishMessage(0, encodedEndpointPayload, consistencyLevel);
193195
specialRelayer.requestDelivery{value: deliveryPayment}(
194196
getManagerToken(), recipientChain, 0, sequence
195197
);
196198
} else {
197-
wormhole.publishMessage(0, encodedEndpointPayload, CONSISTENCY_LEVEL);
199+
wormhole.publishMessage(0, encodedEndpointPayload, consistencyLevel);
198200
}
199201

200202
emit SendEndpointMessage(recipientChain, endpointMessage);

evm/test/IntegrationRelayer.t.sol

+13-4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ contract TestEndToEndRelayer is
7373

7474
uint16 constant chainId1 = 4;
7575
uint16 constant chainId2 = 5;
76+
uint8 constant FAST_CONSISTENCY_LEVEL = 200;
7677

7778
WormholeSimulator guardian;
7879
uint256 initialBlockTimestamp;
@@ -102,7 +103,8 @@ contract TestEndToEndRelayer is
102103
address(managerChain1),
103104
address(chainInfosTestnet[chainId1].wormhole),
104105
address(relayerSource),
105-
address(0x0)
106+
address(0x0),
107+
FAST_CONSISTENCY_LEVEL
106108
);
107109

108110
wormholeEndpointChain1 = MockWormholeEndpointContract(
@@ -132,7 +134,8 @@ contract TestEndToEndRelayer is
132134
address(managerChain2),
133135
address(chainInfosTestnet[chainId2].wormhole),
134136
address(relayerTarget),
135-
address(0x0)
137+
address(0x0),
138+
FAST_CONSISTENCY_LEVEL
136139
);
137140

138141
wormholeEndpointChain2 = MockWormholeEndpointContract(
@@ -406,6 +409,7 @@ contract TestRelayerEndToEndManual is
406409

407410
uint16 constant chainId1 = 4;
408411
uint16 constant chainId2 = 5;
412+
uint8 constant FAST_CONSISTENCY_LEVEL = 200;
409413

410414
uint256 constant DEVNET_GUARDIAN_PK =
411415
0xcfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0;
@@ -436,7 +440,11 @@ contract TestRelayerEndToEndManual is
436440
managerChain1.initialize();
437441

438442
wormholeEndpointChain1 = new MockWormholeEndpointContract(
439-
address(managerChain1), address(wormhole), address(relayer), address(0x0)
443+
address(managerChain1),
444+
address(wormhole),
445+
address(relayer),
446+
address(0x0),
447+
FAST_CONSISTENCY_LEVEL
440448
);
441449
wormholeEndpointChain1 = MockWormholeEndpointContract(
442450
address(new ERC1967Proxy(address(wormholeEndpointChain1), ""))
@@ -460,7 +468,8 @@ contract TestRelayerEndToEndManual is
460468
address(managerChain2),
461469
address(wormhole),
462470
address(relayer), // TODO - add support for this later
463-
address(0x0) // TODO - add support for this later
471+
address(0x0), // TODO - add support for this later
472+
FAST_CONSISTENCY_LEVEL
464473
);
465474
wormholeEndpointChain2 = MockWormholeEndpointContract(
466475
address(new ERC1967Proxy(address(wormholeEndpointChain2), ""))

evm/test/IntegrationStandalone.t.sol

+21-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ contract TestEndToEndBase is Test, IManagerEvents, IRateLimiterEvents {
3434

3535
uint16 constant chainId1 = 7;
3636
uint16 constant chainId2 = 100;
37+
uint8 constant FAST_CONSISTENCY_LEVEL = 200;
3738

3839
uint16 constant SENDING_CHAIN_ID = 1;
3940
uint256 constant DEVNET_GUARDIAN_PK =
@@ -67,7 +68,11 @@ contract TestEndToEndBase is Test, IManagerEvents, IRateLimiterEvents {
6768
managerChain1.initialize();
6869

6970
WormholeEndpoint wormholeEndpointChain1Implementation = new MockWormholeEndpointContract(
70-
address(managerChain1), address(wormhole), address(relayer), address(0x0)
71+
address(managerChain1),
72+
address(wormhole),
73+
address(relayer),
74+
address(0x0),
75+
FAST_CONSISTENCY_LEVEL
7176
);
7277
wormholeEndpointChain1 = MockWormholeEndpointContract(
7378
address(new ERC1967Proxy(address(wormholeEndpointChain1Implementation), ""))
@@ -89,7 +94,11 @@ contract TestEndToEndBase is Test, IManagerEvents, IRateLimiterEvents {
8994
managerChain2.initialize();
9095

9196
WormholeEndpoint wormholeEndpointChain2Implementation = new MockWormholeEndpointContract(
92-
address(managerChain2), address(wormhole), address(relayer), address(0x0)
97+
address(managerChain2),
98+
address(wormhole),
99+
address(relayer),
100+
address(0x0),
101+
FAST_CONSISTENCY_LEVEL
93102
);
94103
wormholeEndpointChain2 = MockWormholeEndpointContract(
95104
address(new ERC1967Proxy(address(wormholeEndpointChain2Implementation), ""))
@@ -406,7 +415,11 @@ contract TestEndToEndBase is Test, IManagerEvents, IRateLimiterEvents {
406415

407416
// Dual endpoint setup
408417
WormholeEndpoint wormholeEndpointChain1_2 = new MockWormholeEndpointContract(
409-
address(managerChain1), address(wormhole), address(relayer), address(0x0)
418+
address(managerChain1),
419+
address(wormhole),
420+
address(relayer),
421+
address(0x0),
422+
FAST_CONSISTENCY_LEVEL
410423
);
411424

412425
wormholeEndpointChain1_2 = MockWormholeEndpointContract(
@@ -419,7 +432,11 @@ contract TestEndToEndBase is Test, IManagerEvents, IRateLimiterEvents {
419432

420433
// Dual endpoint setup
421434
WormholeEndpoint wormholeEndpointChain2_2 = new MockWormholeEndpointContract(
422-
address(managerChain2), address(wormhole), address(relayer), address(0x0)
435+
address(managerChain2),
436+
address(wormhole),
437+
address(relayer),
438+
address(0x0),
439+
FAST_CONSISTENCY_LEVEL
423440
);
424441

425442
wormholeEndpointChain2_2 = MockWormholeEndpointContract(

evm/test/Upgrades.t.sol

+46-9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
4141
0xcfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0;
4242
WormholeSimulator guardian;
4343
uint256 initialBlockTimestamp;
44+
uint8 constant FAST_CONSISTENCY_LEVEL = 200;
4445

4546
WormholeEndpoint wormholeEndpointChain1;
4647
WormholeEndpoint wormholeEndpointChain2;
@@ -68,7 +69,11 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
6869
managerChain1.initialize();
6970

7071
WormholeEndpoint wormholeEndpointChain1Implementation = new MockWormholeEndpointContract(
71-
address(managerChain1), address(wormhole), address(relayer), address(0x0)
72+
address(managerChain1),
73+
address(wormhole),
74+
address(relayer),
75+
address(0x0),
76+
FAST_CONSISTENCY_LEVEL
7277
);
7378
wormholeEndpointChain1 = MockWormholeEndpointContract(
7479
address(new ERC1967Proxy(address(wormholeEndpointChain1Implementation), ""))
@@ -90,7 +95,11 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
9095
managerChain2.initialize();
9196

9297
WormholeEndpoint wormholeEndpointChain2Implementation = new MockWormholeEndpointContract(
93-
address(managerChain2), address(wormhole), address(relayer), address(0x0)
98+
address(managerChain2),
99+
address(wormhole),
100+
address(relayer),
101+
address(0x0),
102+
FAST_CONSISTENCY_LEVEL
94103
);
95104
wormholeEndpointChain2 = MockWormholeEndpointContract(
96105
address(new ERC1967Proxy(address(wormholeEndpointChain2Implementation), ""))
@@ -131,7 +140,11 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
131140
function test_basicUpgradeEndpoint() public {
132141
// Basic call to upgrade with the same contact as well
133142
WormholeEndpoint wormholeEndpointChain1Implementation = new MockWormholeEndpointContract(
134-
address(managerChain1), address(wormhole), address(relayer), address(0x0)
143+
address(managerChain1),
144+
address(wormhole),
145+
address(relayer),
146+
address(0x0),
147+
FAST_CONSISTENCY_LEVEL
135148
);
136149
wormholeEndpointChain1.upgrade(address(wormholeEndpointChain1Implementation));
137150

@@ -159,7 +172,11 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
159172
function test_doubleUpgradeEndpoint() public {
160173
// Basic call to upgrade with the same contact as well
161174
WormholeEndpoint wormholeEndpointChain1Implementation = new MockWormholeEndpointContract(
162-
address(managerChain1), address(wormhole), address(relayer), address(0x0)
175+
address(managerChain1),
176+
address(wormhole),
177+
address(relayer),
178+
address(0x0),
179+
FAST_CONSISTENCY_LEVEL
163180
);
164181
wormholeEndpointChain1.upgrade(address(wormholeEndpointChain1Implementation));
165182

@@ -190,7 +207,11 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
190207
function test_storageSlotEndpoint() public {
191208
// Basic call to upgrade with the same contact as ewll
192209
WormholeEndpoint newImplementation = new MockWormholeEndpointLayoutChange(
193-
address(managerChain1), address(wormhole), address(relayer), address(0x0)
210+
address(managerChain1),
211+
address(wormhole),
212+
address(relayer),
213+
address(0x0),
214+
FAST_CONSISTENCY_LEVEL
194215
);
195216
wormholeEndpointChain1.upgrade(address(newImplementation));
196217

@@ -219,7 +240,11 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
219240
function test_callMigrateEndpoint() public {
220241
// Basic call to upgrade with the same contact as well
221242
MockWormholeEndpointMigrateBasic wormholeEndpointChain1Implementation = new MockWormholeEndpointMigrateBasic(
222-
address(managerChain1), address(wormhole), address(relayer), address(0x0)
243+
address(managerChain1),
244+
address(wormhole),
245+
address(relayer),
246+
address(0x0),
247+
FAST_CONSISTENCY_LEVEL
223248
);
224249

225250
vm.expectRevert("Proper migrate called");
@@ -248,7 +273,11 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
248273

249274
address oldManager = wormholeEndpointChain1.manager();
250275
WormholeEndpoint wormholeEndpointChain1Implementation = new MockWormholeEndpointMigrateBasic(
251-
address(managerChain2), address(wormhole), address(relayer), address(0x0)
276+
address(managerChain2),
277+
address(wormhole),
278+
address(relayer),
279+
address(0x0),
280+
FAST_CONSISTENCY_LEVEL
252281
);
253282

254283
vm.expectRevert(); // Reverts with a panic on the assert. So, no way to tell WHY this happened.
@@ -276,7 +305,11 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
276305

277306
function test_immutableBlockUpdateSuccessEndpoint() public {
278307
WormholeEndpoint wormholeEndpointChain1Implementation = new MockWormholeEndpointImmutableAllow(
279-
address(managerChain1), address(wormhole), address(relayer), address(0x0)
308+
address(managerChain1),
309+
address(wormhole),
310+
address(relayer),
311+
address(0x0),
312+
FAST_CONSISTENCY_LEVEL
280313
);
281314

282315
//vm.expectRevert(); // Reverts with a panic on the assert. So, no way to tell WHY this happened.
@@ -338,7 +371,11 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
338371

339372
// Basic call so that we can easily see what the new endpoint is.
340373
WormholeEndpoint wormholeEndpointChain1Implementation = new MockWormholeEndpointContract(
341-
address(managerChain1), address(wormhole), address(relayer), address(0x0)
374+
address(managerChain1),
375+
address(wormhole),
376+
address(relayer),
377+
address(0x0),
378+
FAST_CONSISTENCY_LEVEL
342379
);
343380
wormholeEndpointChain1.upgrade(address(wormholeEndpointChain1Implementation));
344381
basicFunctionality(); // Ensure that the upgrade was proper

evm/test/mocks/MockEndpoints.sol

+44-8
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ contract MockWormholeEndpointContract is WormholeEndpoint {
99
address manager,
1010
address wormholeCoreBridge,
1111
address wormholeRelayerAddr,
12-
address specialRelayerAddr
13-
) WormholeEndpoint(manager, wormholeCoreBridge, wormholeRelayerAddr, specialRelayerAddr) {}
12+
address specialRelayerAddr,
13+
uint8 _consistencyLevel
14+
)
15+
WormholeEndpoint(
16+
manager,
17+
wormholeCoreBridge,
18+
wormholeRelayerAddr,
19+
specialRelayerAddr,
20+
_consistencyLevel
21+
)
22+
{}
1423

1524
/// @dev Override the [`transferOwnership`] method from OwnableUpgradeable
1625
/// to ensure owner of this contract is in sync with the onwer of the Manager contract.
@@ -30,8 +39,17 @@ contract MockWormholeEndpointMigrateBasic is WormholeEndpoint {
3039
address manager,
3140
address wormholeCoreBridge,
3241
address wormholeRelayerAddr,
33-
address specialRelayerAddr
34-
) WormholeEndpoint(manager, wormholeCoreBridge, wormholeRelayerAddr, specialRelayerAddr) {}
42+
address specialRelayerAddr,
43+
uint8 _consistencyLevel
44+
)
45+
WormholeEndpoint(
46+
manager,
47+
wormholeCoreBridge,
48+
wormholeRelayerAddr,
49+
specialRelayerAddr,
50+
_consistencyLevel
51+
)
52+
{}
3553

3654
function _migrate() internal pure override {
3755
revert("Proper migrate called");
@@ -43,8 +61,17 @@ contract MockWormholeEndpointImmutableAllow is WormholeEndpoint {
4361
address manager,
4462
address wormholeCoreBridge,
4563
address wormholeRelayerAddr,
46-
address specialRelayerAddr
47-
) WormholeEndpoint(manager, wormholeCoreBridge, wormholeRelayerAddr, specialRelayerAddr) {}
64+
address specialRelayerAddr,
65+
uint8 _consistencyLevel
66+
)
67+
WormholeEndpoint(
68+
manager,
69+
wormholeCoreBridge,
70+
wormholeRelayerAddr,
71+
specialRelayerAddr,
72+
_consistencyLevel
73+
)
74+
{}
4875

4976
// Allow for the immutables to be migrated
5077
function _migrate() internal override {
@@ -62,8 +89,17 @@ contract MockWormholeEndpointLayoutChange is WormholeEndpoint {
6289
address manager,
6390
address wormholeCoreBridge,
6491
address wormholeRelayerAddr,
65-
address specialRelayerAddr
66-
) WormholeEndpoint(manager, wormholeCoreBridge, wormholeRelayerAddr, specialRelayerAddr) {}
92+
address specialRelayerAddr,
93+
uint8 _consistencyLevel
94+
)
95+
WormholeEndpoint(
96+
manager,
97+
wormholeCoreBridge,
98+
wormholeRelayerAddr,
99+
specialRelayerAddr,
100+
_consistencyLevel
101+
)
102+
{}
67103

68104
function setData() public {
69105
a = address(0x1);

0 commit comments

Comments
 (0)