Skip to content

Commit

Permalink
Merge pull request #332 from darwinia-network/periphery/fix-weight-pe…
Browse files Browse the repository at this point in the history
…r-gas

Periphery/fix weight per gas and darwinia <> crab params
  • Loading branch information
wuminzhe committed Apr 28, 2023
2 parents 5ba4cd3 + 1d6b151 commit 9ed800e
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 116 deletions.
11 changes: 2 additions & 9 deletions contracts/periphery/contracts/s2s/MessageEndpoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ abstract contract MessageEndpoint {
// remote smart chain id
uint64 public remoteSmartChainId;

// 1 gas ~= 40_000 weight
uint64 public constant REMOTE_WEIGHT_PER_GAS = 40_000;
// 1 gas ~= 18_750 weight
uint64 public constant REMOTE_WEIGHT_PER_GAS = 18_750;

// LOCAL
// storage keys
Expand Down Expand Up @@ -48,13 +48,6 @@ abstract contract MessageEndpoint {
///////////////////////////////
// Outbound
///////////////////////////////
function remoteExecute(
uint32 pangolinSpecVersion,
address callReceiver,
bytes calldata callPayload,
uint256 gasLimit
) external payable virtual returns (uint256);

function fee() public view returns (uint128) {
return MessageLib.marketFee(STORAGE_ADDRESS, storageKeyForMarketFee);
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/periphery/contracts/s2s/examples/CrabEndpoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract CrabEndpoint is MessageEndpoint(0, 0x64616362, 0x64616362) {
storageKeyForLatestNonce = 0xf1501030816118b9129255f5096aa9b296c246acb9b55077390e3ca723a0ca1f; // checked, bridgeDarwiniaMessages's outboundLanes storage key
storageKeyForLastDeliveredNonce = 0xf1501030816118b9129255f5096aa9b2e5f83cf83f2127eb47afdc35d6e43fab; // checked, bridgeDarwiniaMessages's inboundLanes storage key
sendMessageCallIndex = 0x2903; // checked
remoteMessageTransactCallIndex = 0x3001; // checked, the call index of darwinia's ethereum.messageTransact
remoteMessageTransactCallIndex = 0x2600; // checked, the call index of darwinia's ethereum.messageTransact
remoteSmartChainId = 46; // checked, darwinia ethereum chain id
}

Expand All @@ -34,7 +34,7 @@ contract CrabEndpoint is MessageEndpoint(0, 0x64616362, 0x64616362) {
address callReceiver,
bytes calldata callPayload,
uint256 gasLimit
) external payable override returns (uint256) {
) external payable returns (uint256) {
return
_remoteExecute(
pangoroSpecVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import "../MessageEndpoint.sol";
// 0x64616362(dacb) is the lane id of Darwinia <> Crab Message channel
contract DarwiniaEndpoint is MessageEndpoint(0, 0x64616362, 0x64616362) {
constructor() {
storageKeyForMarketFee = 0x190d00dd4103825c78f55e5b5dbf8bfe2edb70953213f33a6ef6b8a5e3ffcab2;
storageKeyForMarketFee = 0x94594b5e37f74ce096905956485f9a7d2edb70953213f33a6ef6b8a5e3ffcab2;
storageKeyForLatestNonce = 0xf4e61b17ce395203fe0f3c53a0d3986096c246acb9b55077390e3ca723a0ca1f;
storageKeyForLastDeliveredNonce = 0xf4e61b17ce395203fe0f3c53a0d39860e5f83cf83f2127eb47afdc35d6e43fab;
sendMessageCallIndex = 0x2c03;
sendMessageCallIndex = 0x2903;
remoteMessageTransactCallIndex = 0x2600; // the call index of crab's messageTransact.messageTransact
remoteSmartChainId = 44;
}
Expand All @@ -27,7 +27,7 @@ contract DarwiniaEndpoint is MessageEndpoint(0, 0x64616362, 0x64616362) {
address callReceiver,
bytes calldata callPayload,
uint256 gasLimit
) external payable override returns (uint256) {
) external payable returns (uint256) {
return
_remoteExecute(
pangolinSpecVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract PangolinEndpoint is MessageEndpoint(0, 0x726f6c69, 0x726f6c69) {
address callReceiver,
bytes calldata callPayload,
uint256 gasLimit
) external payable override returns (uint256) {
) external payable returns (uint256) {
return
_remoteExecute(
pangoroSpecVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract PangoroEndpoint is MessageEndpoint(0, 0x726f6c69, 0x726f6c69) {
address callReceiver,
bytes calldata callPayload,
uint256 gasLimit
) external payable override returns (uint256) {
) external payable returns (uint256) {
return
_remoteExecute(
pangolinSpecVersion,
Expand Down
25 changes: 21 additions & 4 deletions contracts/periphery/contracts/s2s/types/CommonTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,16 @@ library CommonTypes {
// UnrewardedRelayer
////////////////////////////////////
struct UnrewardedRelayer {
bytes32 relayer;
address relayer;
DeliveredMessages messages;
}

function decodeUnrewardedRelayer(
bytes memory _data
) internal pure returns (UnrewardedRelayer memory) {
bytes32 relayer = Bytes.toBytes32(Bytes.substr(_data, 0, 32));
address relayer = toAddress(_data, 0);
DeliveredMessages memory messages = decodeDeliveredMessages(
Bytes.substr(_data, 32)
Bytes.substr(_data, 20)
);

return UnrewardedRelayer(relayer, messages);
Expand All @@ -206,7 +206,24 @@ library CommonTypes {
uint bytesLengthOfmessages = getBytesLengthOfDeliveredMessages(
unrewardedRelayer.messages
);
return 32 + bytesLengthOfmessages;
return 20 + bytesLengthOfmessages;
}

function toAddress(
bytes memory _bytes,
uint256 _start
) internal pure returns (address) {
require(_bytes.length >= _start + 20, "toAddress_outOfBounds");
address tempAddress;

assembly {
tempAddress := div(
mload(add(add(_bytes, 0x20), _start)),
0x1000000000000000000000000
)
}

return tempAddress;
}

////////////////////////////////////
Expand Down
125 changes: 29 additions & 96 deletions contracts/periphery/contracts/s2s/types/CommonTypes.t.sol

Large diffs are not rendered by default.

0 comments on commit 9ed800e

Please sign in to comment.