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
|
payable
|
||||||
returns (uint64 sequence)
|
returns (uint64 sequence)
|
||||||
{
|
{
|
||||||
updateWormholeMessageFee();
|
IWormhole wormhole = wormhole();
|
||||||
uint256 totalFee = getTotalFeeMultichainSend(sendContainer);
|
uint256 wormholeMessageFee = wormhole.messageFee();
|
||||||
|
uint256 totalFee = getTotalFeeMultichainSend(sendContainer, wormholeMessageFee);
|
||||||
if (totalFee > msg.value) {
|
if (totalFee > msg.value) {
|
||||||
revert IWormholeRelayer.MsgValueTooLow();
|
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)
|
// 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
|
// 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()
|
nonce, encodeDeliveryInstructionsContainer(instructionsContainer), relayProvider.getConsistencyLevel()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Pay the relay provider
|
// 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();
|
revert IWormholeRelayer.ForwardRequestFromWrongAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 totalFee = getTotalFeeMultichainSend(sendContainer);
|
uint256 wormholeMessageFee = wormhole().messageFee();
|
||||||
|
uint256 totalFee = getTotalFeeMultichainSend(sendContainer, wormholeMessageFee);
|
||||||
|
|
||||||
// For each 'Send' request,
|
// For each 'Send' request,
|
||||||
// calculate how much gas the relay provider can pay for on 'request.targetChain' using 'request.newTransactionFee',
|
// 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
|
payable
|
||||||
returns (uint64 sequence)
|
returns (uint64 sequence)
|
||||||
{
|
{
|
||||||
updateWormholeMessageFee();
|
IWormhole wormhole = wormhole();
|
||||||
if (request.newMaxTransactionFee + request.newReceiverValue + wormholeMessageFee() > msg.value) {
|
uint256 wormholeMessageFee = wormhole.messageFee();
|
||||||
|
if (request.newMaxTransactionFee + request.newReceiverValue + wormholeMessageFee > msg.value) {
|
||||||
revert IWormholeRelayer.MsgValueTooLow();
|
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'
|
// 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
|
// 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)
|
// 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
|
// 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()
|
0, encodeRedeliveryInstruction(instruction), provider.getConsistencyLevel()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Pay the relay provider
|
// 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);
|
IRelayProvider relayProvider = IRelayProvider(forwardInstruction.relayProvider);
|
||||||
|
|
||||||
|
IWormhole wormhole = wormhole();
|
||||||
|
uint256 wormholeMessageFee = wormhole.messageFee();
|
||||||
if (forwardIsFunded) {
|
if (forwardIsFunded) {
|
||||||
// the rollover chain is the chain in the first request
|
// the rollover chain is the chain in the first request
|
||||||
uint256 amountUnderMaximum = relayProvider.quoteMaximumBudget(container.instructions[0].targetChain)
|
uint256 amountUnderMaximum = relayProvider.quoteMaximumBudget(container.instructions[0].targetChain)
|
||||||
- (
|
- (
|
||||||
wormholeMessageFee() + container.instructions[0].maximumRefundTarget
|
wormholeMessageFee + container.instructions[0].maximumRefundTarget
|
||||||
+ container.instructions[0].receiverValueTarget
|
+ container.instructions[0].receiverValueTarget
|
||||||
);
|
);
|
||||||
uint256 convertedExtraAmount = calculateTargetDeliveryMaximumRefund(
|
uint256 convertedExtraAmount = calculateTargetDeliveryMaximumRefund(
|
||||||
|
@ -57,7 +59,7 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
|
||||||
}
|
}
|
||||||
|
|
||||||
//emit forwarding instruction
|
//emit forwarding instruction
|
||||||
wormhole().publishMessage{value: wormholeMessageFee()}(
|
wormhole.publishMessage{value: wormholeMessageFee}(
|
||||||
forwardInstruction.nonce,
|
forwardInstruction.nonce,
|
||||||
encodeDeliveryInstructionsContainer(container),
|
encodeDeliveryInstructionsContainer(container),
|
||||||
relayProvider.getConsistencyLevel()
|
relayProvider.getConsistencyLevel()
|
||||||
|
@ -139,14 +141,14 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
|
||||||
status: status
|
status: status
|
||||||
});
|
});
|
||||||
|
|
||||||
|
uint256 wormholeMessageFee = wormhole().messageFee();
|
||||||
uint256 extraRelayerFunds = (
|
uint256 extraRelayerFunds = (
|
||||||
msg.value - internalInstruction.receiverValueTarget - internalInstruction.maximumRefundTarget
|
msg.value - internalInstruction.receiverValueTarget - internalInstruction.maximumRefundTarget
|
||||||
- wormholeMessageFee()
|
- wormholeMessageFee
|
||||||
);
|
);
|
||||||
uint256 relayerRefundAmount = extraRelayerFunds
|
uint256 relayerRefundAmount = extraRelayerFunds
|
||||||
+ (internalInstruction.maximumRefundTarget - transactionFeeRefundAmount)
|
+ (internalInstruction.maximumRefundTarget - transactionFeeRefundAmount)
|
||||||
+ (forwardingRequest.isValid ? 0 : wormholeMessageFee())
|
+ (forwardingRequest.isValid ? 0 : wormholeMessageFee) + (refundPaidToRefundAddress ? 0 : refundToRefundAddress);
|
||||||
+ (refundPaidToRefundAddress ? 0 : refundToRefundAddress);
|
|
||||||
// refund the rest to relayer
|
// refund the rest to relayer
|
||||||
pay(relayerRefund, relayerRefundAmount);
|
pay(relayerRefund, relayerRefundAmount);
|
||||||
}
|
}
|
||||||
|
@ -158,7 +160,6 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
|
||||||
function redeliverSingle(IDelivery.TargetRedeliveryByTxHashParamsSingle memory targetParams) public payable {
|
function redeliverSingle(IDelivery.TargetRedeliveryByTxHashParamsSingle memory targetParams) public payable {
|
||||||
//cache wormhole
|
//cache wormhole
|
||||||
IWormhole wormhole = wormhole();
|
IWormhole wormhole = wormhole();
|
||||||
updateWormholeMessageFee();
|
|
||||||
|
|
||||||
//validate the redelivery VM
|
//validate the redelivery VM
|
||||||
(IWormhole.VM memory redeliveryVM, bool valid, string memory reason) =
|
(IWormhole.VM memory redeliveryVM, bool valid, string memory reason) =
|
||||||
|
@ -226,11 +227,12 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
|
||||||
revert IDelivery.MismatchingRelayProvidersInRedelivery();
|
revert IDelivery.MismatchingRelayProvidersInRedelivery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint256 wormholeMessageFee = wormhole().messageFee();
|
||||||
// relayer must have covered the necessary funds
|
// relayer must have covered the necessary funds
|
||||||
if (
|
if (
|
||||||
msg.value
|
msg.value
|
||||||
< redeliveryInstruction.newMaximumRefundTarget + redeliveryInstruction.newReceiverValueTarget
|
< redeliveryInstruction.newMaximumRefundTarget + redeliveryInstruction.newReceiverValueTarget
|
||||||
+ wormholeMessageFee()
|
+ wormholeMessageFee
|
||||||
) {
|
) {
|
||||||
revert IDelivery.InsufficientRelayerFunds();
|
revert IDelivery.InsufficientRelayerFunds();
|
||||||
}
|
}
|
||||||
|
@ -261,7 +263,6 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
|
||||||
function deliverSingle(IDelivery.TargetDeliveryParametersSingle memory targetParams) public payable {
|
function deliverSingle(IDelivery.TargetDeliveryParametersSingle memory targetParams) public payable {
|
||||||
// cache wormhole instance
|
// cache wormhole instance
|
||||||
IWormhole wormhole = wormhole();
|
IWormhole wormhole = wormhole();
|
||||||
updateWormholeMessageFee();
|
|
||||||
|
|
||||||
// validate the deliveryIndex
|
// validate the deliveryIndex
|
||||||
(IWormhole.VM memory deliveryVM, bool valid, string memory reason) =
|
(IWormhole.VM memory deliveryVM, bool valid, string memory reason) =
|
||||||
|
@ -287,10 +288,11 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
|
||||||
revert IDelivery.UnexpectedRelayer();
|
revert IDelivery.UnexpectedRelayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint256 wormholeMessageFee = wormhole.messageFee();
|
||||||
//make sure relayer passed in sufficient funds
|
//make sure relayer passed in sufficient funds
|
||||||
if (
|
if (
|
||||||
msg.value
|
msg.value
|
||||||
< deliveryInstruction.maximumRefundTarget + deliveryInstruction.receiverValueTarget + wormholeMessageFee()
|
< deliveryInstruction.maximumRefundTarget + deliveryInstruction.receiverValueTarget + wormholeMessageFee
|
||||||
) {
|
) {
|
||||||
revert IDelivery.InsufficientRelayerFunds();
|
revert IDelivery.InsufficientRelayerFunds();
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,10 +33,6 @@ contract CoreRelayerGetters is CoreRelayerState {
|
||||||
return IWormhole(_state.provider.wormhole);
|
return IWormhole(_state.provider.wormhole);
|
||||||
}
|
}
|
||||||
|
|
||||||
function wormholeMessageFee() public view returns (uint256) {
|
|
||||||
return _state.provider.wormholeMessageFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
function chainId() public view returns (uint16) {
|
function chainId() public view returns (uint16) {
|
||||||
return _state.provider.chainId;
|
return _state.provider.chainId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,12 +20,12 @@ contract CoreRelayerMessages is CoreRelayerStructs, CoreRelayerGetters {
|
||||||
* @param sendContainer A MultichainSend struct describing all of the Send requests
|
* @param sendContainer A MultichainSend struct describing all of the Send requests
|
||||||
* @return totalFee
|
* @return totalFee
|
||||||
*/
|
*/
|
||||||
function getTotalFeeMultichainSend(IWormholeRelayer.MultichainSend memory sendContainer)
|
function getTotalFeeMultichainSend(IWormholeRelayer.MultichainSend memory sendContainer, uint256 wormholeMessageFee)
|
||||||
internal
|
internal
|
||||||
view
|
view
|
||||||
returns (uint256 totalFee)
|
returns (uint256 totalFee)
|
||||||
{
|
{
|
||||||
totalFee = wormholeMessageFee();
|
totalFee = wormholeMessageFee;
|
||||||
uint256 length = sendContainer.requests.length;
|
uint256 length = sendContainer.requests.length;
|
||||||
for (uint256 i = 0; i < length; i++) {
|
for (uint256 i = 0; i < length; i++) {
|
||||||
IWormholeRelayer.Send memory request = sendContainer.requests[i];
|
IWormholeRelayer.Send memory request = sendContainer.requests[i];
|
||||||
|
@ -131,15 +131,16 @@ contract CoreRelayerMessages is CoreRelayerStructs, CoreRelayerGetters {
|
||||||
* @param instruction A RedeliveryByTxHashInstruction
|
* @param instruction A RedeliveryByTxHashInstruction
|
||||||
* @param relayProvider The relayProvider whos maximum budget we are checking against
|
* @param relayProvider The relayProvider whos maximum budget we are checking against
|
||||||
*/
|
*/
|
||||||
function checkRedeliveryInstruction(RedeliveryByTxHashInstruction memory instruction, IRelayProvider relayProvider)
|
function checkRedeliveryInstruction(
|
||||||
internal
|
RedeliveryByTxHashInstruction memory instruction,
|
||||||
view
|
IRelayProvider relayProvider,
|
||||||
{
|
uint256 wormholeMessageFee
|
||||||
|
) internal view {
|
||||||
if (instruction.executionParameters.gasLimit == 0) {
|
if (instruction.executionParameters.gasLimit == 0) {
|
||||||
revert IWormholeRelayer.MaxTransactionFeeNotEnough(0);
|
revert IWormholeRelayer.MaxTransactionFeeNotEnough(0);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
instruction.newMaximumRefundTarget + instruction.newReceiverValueTarget + wormholeMessageFee()
|
instruction.newMaximumRefundTarget + instruction.newReceiverValueTarget + wormholeMessageFee
|
||||||
> relayProvider.quoteMaximumBudget(instruction.targetChain)
|
> relayProvider.quoteMaximumBudget(instruction.targetChain)
|
||||||
) {
|
) {
|
||||||
revert IWormholeRelayer.FundsTooMuch(0);
|
revert IWormholeRelayer.FundsTooMuch(0);
|
||||||
|
|
|
@ -35,10 +35,6 @@ contract CoreRelayerSetters is CoreRelayerState, Context {
|
||||||
_state.provider.wormhole = payable(wh);
|
_state.provider.wormhole = payable(wh);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateWormholeMessageFee() internal {
|
|
||||||
_state.provider.wormholeMessageFee = IWormhole(_state.provider.wormhole).messageFee();
|
|
||||||
}
|
|
||||||
|
|
||||||
function setRelayProvider(address defaultRelayProvider) internal {
|
function setRelayProvider(address defaultRelayProvider) internal {
|
||||||
_state.defaultRelayProvider = defaultRelayProvider;
|
_state.defaultRelayProvider = defaultRelayProvider;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ contract CoreRelayerStorage {
|
||||||
struct Provider {
|
struct Provider {
|
||||||
uint16 chainId;
|
uint16 chainId;
|
||||||
address payable wormhole;
|
address payable wormhole;
|
||||||
uint256 wormholeMessageFee;
|
|
||||||
uint16 governanceChainId;
|
uint16 governanceChainId;
|
||||||
bytes32 governanceContract;
|
bytes32 governanceContract;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue