Removes wormholeMessageFee from storage to avoid excessive gas costs.
This commit is contained in:
parent
fccec97383
commit
2c2f40ccd9
|
@ -187,8 +187,9 @@ contract CoreRelayer is CoreRelayerDelivery {
|
|||
payable
|
||||
returns (uint64 sequence)
|
||||
{
|
||||
updateWormholeMessageFee();
|
||||
uint256 totalFee = getTotalFeeMultichainSend(sendContainer);
|
||||
IWormhole wormhole = wormhole();
|
||||
uint256 wormholeMessageFee = wormhole.messageFee();
|
||||
uint256 totalFee = getTotalFeeMultichainSend(sendContainer, wormholeMessageFee);
|
||||
if (totalFee > msg.value) {
|
||||
revert IWormholeRelayer.MsgValueTooLow();
|
||||
}
|
||||
|
@ -214,12 +215,12 @@ contract CoreRelayer is CoreRelayerDelivery {
|
|||
|
||||
// Publish a wormhole message indicating to the relay provider (who is watching wormhole messages from this contract)
|
||||
// to relay the messages from this transaction (of nonce 'nonce') to the specified chains, each with the calculated amount of gas and receiverValue
|
||||
sequence = wormhole().publishMessage{value: wormholeMessageFee()}(
|
||||
sequence = wormhole.publishMessage{value: wormholeMessageFee}(
|
||||
nonce, encodeDeliveryInstructionsContainer(instructionsContainer), relayProvider.getConsistencyLevel()
|
||||
);
|
||||
|
||||
// Pay the relay provider
|
||||
pay(relayProvider.getRewardAddress(), totalFee - wormholeMessageFee());
|
||||
pay(relayProvider.getRewardAddress(), totalFee - wormholeMessageFee);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -252,7 +253,8 @@ contract CoreRelayer is CoreRelayerDelivery {
|
|||
revert IWormholeRelayer.ForwardRequestFromWrongAddress();
|
||||
}
|
||||
|
||||
uint256 totalFee = getTotalFeeMultichainSend(sendContainer);
|
||||
uint256 wormholeMessageFee = wormhole().messageFee();
|
||||
uint256 totalFee = getTotalFeeMultichainSend(sendContainer, wormholeMessageFee);
|
||||
|
||||
// For each 'Send' request,
|
||||
// calculate how much gas the relay provider can pay for on 'request.targetChain' using 'request.newTransactionFee',
|
||||
|
@ -298,8 +300,9 @@ contract CoreRelayer is CoreRelayerDelivery {
|
|||
payable
|
||||
returns (uint64 sequence)
|
||||
{
|
||||
updateWormholeMessageFee();
|
||||
if (request.newMaxTransactionFee + request.newReceiverValue + wormholeMessageFee() > msg.value) {
|
||||
IWormhole wormhole = wormhole();
|
||||
uint256 wormholeMessageFee = wormhole.messageFee();
|
||||
if (request.newMaxTransactionFee + request.newReceiverValue + wormholeMessageFee > msg.value) {
|
||||
revert IWormholeRelayer.MsgValueTooLow();
|
||||
}
|
||||
|
||||
|
@ -311,16 +314,16 @@ contract CoreRelayer is CoreRelayerDelivery {
|
|||
|
||||
// Check that the total amount of value the relay provider needs to use for this redelivery is <= the relayProvider's maximum budget for 'targetChain'
|
||||
// and check that the calculated gas is greater than 0
|
||||
checkRedeliveryInstruction(instruction, provider);
|
||||
checkRedeliveryInstruction(instruction, provider, wormholeMessageFee);
|
||||
|
||||
// Publish a wormhole message indicating to the relay provider (who is watching wormhole messages from this contract)
|
||||
// to re-relay the messages from transaction 'request.txHash' with the calculated amount of gas and receiverValue
|
||||
sequence = wormhole().publishMessage{value: wormholeMessageFee()}(
|
||||
sequence = wormhole.publishMessage{value: wormholeMessageFee}(
|
||||
0, encodeRedeliveryInstruction(instruction), provider.getConsistencyLevel()
|
||||
);
|
||||
|
||||
// Pay the relay provider
|
||||
pay(provider.getRewardAddress(), msg.value - wormholeMessageFee());
|
||||
pay(provider.getRewardAddress(), msg.value - wormholeMessageFee);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,11 +40,13 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
|
|||
|
||||
IRelayProvider relayProvider = IRelayProvider(forwardInstruction.relayProvider);
|
||||
|
||||
IWormhole wormhole = wormhole();
|
||||
uint256 wormholeMessageFee = wormhole.messageFee();
|
||||
if (forwardIsFunded) {
|
||||
// the rollover chain is the chain in the first request
|
||||
uint256 amountUnderMaximum = relayProvider.quoteMaximumBudget(container.instructions[0].targetChain)
|
||||
- (
|
||||
wormholeMessageFee() + container.instructions[0].maximumRefundTarget
|
||||
wormholeMessageFee + container.instructions[0].maximumRefundTarget
|
||||
+ container.instructions[0].receiverValueTarget
|
||||
);
|
||||
uint256 convertedExtraAmount = calculateTargetDeliveryMaximumRefund(
|
||||
|
@ -57,7 +59,7 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
|
|||
}
|
||||
|
||||
//emit forwarding instruction
|
||||
wormhole().publishMessage{value: wormholeMessageFee()}(
|
||||
wormhole.publishMessage{value: wormholeMessageFee}(
|
||||
forwardInstruction.nonce,
|
||||
encodeDeliveryInstructionsContainer(container),
|
||||
relayProvider.getConsistencyLevel()
|
||||
|
@ -139,14 +141,14 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
|
|||
status: status
|
||||
});
|
||||
|
||||
uint256 wormholeMessageFee = wormhole().messageFee();
|
||||
uint256 extraRelayerFunds = (
|
||||
msg.value - internalInstruction.receiverValueTarget - internalInstruction.maximumRefundTarget
|
||||
- wormholeMessageFee()
|
||||
- wormholeMessageFee
|
||||
);
|
||||
uint256 relayerRefundAmount = extraRelayerFunds
|
||||
+ (internalInstruction.maximumRefundTarget - transactionFeeRefundAmount)
|
||||
+ (forwardingRequest.isValid ? 0 : wormholeMessageFee())
|
||||
+ (refundPaidToRefundAddress ? 0 : refundToRefundAddress);
|
||||
+ (forwardingRequest.isValid ? 0 : wormholeMessageFee) + (refundPaidToRefundAddress ? 0 : refundToRefundAddress);
|
||||
// refund the rest to relayer
|
||||
pay(relayerRefund, relayerRefundAmount);
|
||||
}
|
||||
|
@ -158,7 +160,6 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
|
|||
function redeliverSingle(IDelivery.TargetRedeliveryByTxHashParamsSingle memory targetParams) public payable {
|
||||
//cache wormhole
|
||||
IWormhole wormhole = wormhole();
|
||||
updateWormholeMessageFee();
|
||||
|
||||
//validate the redelivery VM
|
||||
(IWormhole.VM memory redeliveryVM, bool valid, string memory reason) =
|
||||
|
@ -226,11 +227,12 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
|
|||
revert IDelivery.MismatchingRelayProvidersInRedelivery();
|
||||
}
|
||||
|
||||
uint256 wormholeMessageFee = wormhole().messageFee();
|
||||
// relayer must have covered the necessary funds
|
||||
if (
|
||||
msg.value
|
||||
< redeliveryInstruction.newMaximumRefundTarget + redeliveryInstruction.newReceiverValueTarget
|
||||
+ wormholeMessageFee()
|
||||
+ wormholeMessageFee
|
||||
) {
|
||||
revert IDelivery.InsufficientRelayerFunds();
|
||||
}
|
||||
|
@ -261,7 +263,6 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
|
|||
function deliverSingle(IDelivery.TargetDeliveryParametersSingle memory targetParams) public payable {
|
||||
// cache wormhole instance
|
||||
IWormhole wormhole = wormhole();
|
||||
updateWormholeMessageFee();
|
||||
|
||||
// validate the deliveryIndex
|
||||
(IWormhole.VM memory deliveryVM, bool valid, string memory reason) =
|
||||
|
@ -287,10 +288,11 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
|
|||
revert IDelivery.UnexpectedRelayer();
|
||||
}
|
||||
|
||||
uint256 wormholeMessageFee = wormhole.messageFee();
|
||||
//make sure relayer passed in sufficient funds
|
||||
if (
|
||||
msg.value
|
||||
< deliveryInstruction.maximumRefundTarget + deliveryInstruction.receiverValueTarget + wormholeMessageFee()
|
||||
< deliveryInstruction.maximumRefundTarget + deliveryInstruction.receiverValueTarget + wormholeMessageFee
|
||||
) {
|
||||
revert IDelivery.InsufficientRelayerFunds();
|
||||
}
|
||||
|
|
|
@ -33,10 +33,6 @@ contract CoreRelayerGetters is CoreRelayerState {
|
|||
return IWormhole(_state.provider.wormhole);
|
||||
}
|
||||
|
||||
function wormholeMessageFee() public view returns (uint256) {
|
||||
return _state.provider.wormholeMessageFee;
|
||||
}
|
||||
|
||||
function chainId() public view returns (uint16) {
|
||||
return _state.provider.chainId;
|
||||
}
|
||||
|
|
|
@ -20,12 +20,12 @@ contract CoreRelayerMessages is CoreRelayerStructs, CoreRelayerGetters {
|
|||
* @param sendContainer A MultichainSend struct describing all of the Send requests
|
||||
* @return totalFee
|
||||
*/
|
||||
function getTotalFeeMultichainSend(IWormholeRelayer.MultichainSend memory sendContainer)
|
||||
function getTotalFeeMultichainSend(IWormholeRelayer.MultichainSend memory sendContainer, uint256 wormholeMessageFee)
|
||||
internal
|
||||
view
|
||||
returns (uint256 totalFee)
|
||||
{
|
||||
totalFee = wormholeMessageFee();
|
||||
totalFee = wormholeMessageFee;
|
||||
uint256 length = sendContainer.requests.length;
|
||||
for (uint256 i = 0; i < length; i++) {
|
||||
IWormholeRelayer.Send memory request = sendContainer.requests[i];
|
||||
|
@ -131,15 +131,16 @@ contract CoreRelayerMessages is CoreRelayerStructs, CoreRelayerGetters {
|
|||
* @param instruction A RedeliveryByTxHashInstruction
|
||||
* @param relayProvider The relayProvider whos maximum budget we are checking against
|
||||
*/
|
||||
function checkRedeliveryInstruction(RedeliveryByTxHashInstruction memory instruction, IRelayProvider relayProvider)
|
||||
internal
|
||||
view
|
||||
{
|
||||
function checkRedeliveryInstruction(
|
||||
RedeliveryByTxHashInstruction memory instruction,
|
||||
IRelayProvider relayProvider,
|
||||
uint256 wormholeMessageFee
|
||||
) internal view {
|
||||
if (instruction.executionParameters.gasLimit == 0) {
|
||||
revert IWormholeRelayer.MaxTransactionFeeNotEnough(0);
|
||||
}
|
||||
if (
|
||||
instruction.newMaximumRefundTarget + instruction.newReceiverValueTarget + wormholeMessageFee()
|
||||
instruction.newMaximumRefundTarget + instruction.newReceiverValueTarget + wormholeMessageFee
|
||||
> relayProvider.quoteMaximumBudget(instruction.targetChain)
|
||||
) {
|
||||
revert IWormholeRelayer.FundsTooMuch(0);
|
||||
|
|
|
@ -35,10 +35,6 @@ contract CoreRelayerSetters is CoreRelayerState, Context {
|
|||
_state.provider.wormhole = payable(wh);
|
||||
}
|
||||
|
||||
function updateWormholeMessageFee() internal {
|
||||
_state.provider.wormholeMessageFee = IWormhole(_state.provider.wormhole).messageFee();
|
||||
}
|
||||
|
||||
function setRelayProvider(address defaultRelayProvider) internal {
|
||||
_state.defaultRelayProvider = defaultRelayProvider;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ contract CoreRelayerStorage {
|
|||
struct Provider {
|
||||
uint16 chainId;
|
||||
address payable wormhole;
|
||||
uint256 wormholeMessageFee;
|
||||
uint16 governanceChainId;
|
||||
bytes32 governanceContract;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue