From 2e3bd4ef32fa5887d8b6f7cff313a9b5ec4d65b1 Mon Sep 17 00:00:00 2001 From: Alexander Kolotov Date: Wed, 28 Feb 2018 00:49:26 +0300 Subject: [PATCH] keep gas consumption limits in the bridge contracts --- .../bridge_erc20_foreign_optimized.sol | 61 ++++++++++++++++++- erc20/bridge/contracts/make.sh | 4 +- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/erc20/bridge/contracts/bridge_erc20_foreign_optimized.sol b/erc20/bridge/contracts/bridge_erc20_foreign_optimized.sol index a411a70..4db4488 100644 --- a/erc20/bridge/contracts/bridge_erc20_foreign_optimized.sol +++ b/erc20/bridge/contracts/bridge_erc20_foreign_optimized.sol @@ -190,8 +190,64 @@ library MessageTest { } } +/// This contract introduces a new field which can be used by new bridge +/// instances to get information when the bridge contract was deployed. +/// This will avoid necessity to distribute this information as part of the +/// database file to new validators if they want to join to existing +/// bridge validators group. +/// So, now bridge deployment script or webapp could pickup HomeBridge +/// and ForeignBridge addresses and request block deployed from the contracts +/// in order to generate correct database file. +contract BridgeDeploymentAddressStorage { + uint256 public blockDeployed; -contract HomeBridge { + function BridgeDeploymentAddressStorage() public { + blockDeployed = block.number; + } +} + +/// Due to nature of bridge operations it makes sense to have the same value +/// of gas consumption limits which will distributed among all validators serving +/// particular bridge. This approach introduces few advantages: +/// --- new bridge instances will pickup limits from the contract instead of +/// looking at the configuration file (this configuration parameters could be +/// depricated) +/// --- as soon as upgradable bridge contract is implemented these limits needs +/// to be updated every time the contract is upgraded. Validators could get +/// an event that limits updated and use new values to send transactions. +contract HomeBridgeGasConsumptionLimitsStorage { + uint256 public gasLimitWithdrawRelay; + + event GasConsumptionLimitsUpdated(uint256); + + function setGasLimitWithdrawRelay(uint256 gas) { + gasLimitWithdrawRelay = gas; + + GasConsumptionLimitsUpdated(gasLimitWithdrawRelay); + } +} + +contract ForeignBridgeGasConsumptionLimitsStorage { + uint256 public gasLimitDepositRelay; + uint256 public gasLimitWithdrawConfirm; + + event GasConsumptionLimitsUpdated(uint256, uint256); + + function setGasLimitDepositRelay(uint256 gas) { + gasLimitDepositRelay = gas; + + GasConsumptionLimitsUpdated(gasLimitDepositRelay, gasLimitWithdrawConfirm); + } + + function setGasLimitWithdrawConfirm(uint256 gas) { + gasLimitWithdrawConfirm = gas; + + GasConsumptionLimitsUpdated(gasLimitDepositRelay, gasLimitWithdrawConfirm); + } +} + +contract HomeBridge is BridgeDeploymentAddressStorage, + HomeBridgeGasConsumptionLimitsStorage { /// Number of authorities signatures required to withdraw the money. /// /// Must be lesser than number of authorities. @@ -294,7 +350,8 @@ contract ERC20 { function allowance(address owner, address spender) public constant returns (uint256); } -contract ForeignBridge { +contract ForeignBridge is BridgeDeploymentAddressStorage, + ForeignBridgeGasConsumptionLimitsStorage { /// Number of authorities signatures required to withdraw the money. /// /// Must be less than number of authorities. diff --git a/erc20/bridge/contracts/make.sh b/erc20/bridge/contracts/make.sh index 1fc7577..dd004c4 100755 --- a/erc20/bridge/contracts/make.sh +++ b/erc20/bridge/contracts/make.sh @@ -2,8 +2,8 @@ solc='/opt/ethereum-go/bin/solc' -h_contract="HomeBridge" -f_contract="ForeignBridge" +h_contract="HomeBridge\." +f_contract="ForeignBridge\." rm *.bin rm *.abi