Handling failed deployment transactions

pull/866/head
Kieran Prasch 2019-04-18 22:48:31 +03:00
parent 14a24d7085
commit 42a1495047
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
4 changed files with 46 additions and 10 deletions

View File

@ -112,7 +112,7 @@ class TokenEconomics:
maximum_locked_periods = reward_saturation * 365
# Injected
self.initial_supply = initial_supply
self.__initial_supply = initial_supply
self.initial_inflation = initial_inflation
self.token_halving = halving_delay
self.token_saturation = reward_saturation
@ -126,8 +126,15 @@ class TokenEconomics:
self.maximum_locked_periods = maximum_locked_periods
@property
def total_supply(self):
"""ERC20 deployment parameter"""
def erc20_deployment_supply(self) -> int:
return int(self.__initial_supply)
@property
def escrow_deployment_reward_supply(self) -> int:
return int(self.__initial_supply)
@property
def total_supply(self) -> int:
return int(self.__total_supply)
@property

View File

@ -171,7 +171,7 @@ class NucypherTokenDeployer(ContractDeployer):
_contract, deployment_txhash = self.blockchain.interface.deploy_contract(
self.contract_name,
self.__economics.total_supply)
self.__economics.erc20_deployment_supply)
self._contract = _contract
return {'txhash': deployment_txhash}
@ -275,7 +275,10 @@ class MinerEscrowDeployer(ContractDeployer):
the_escrow_contract = wrapped_escrow_contract
# 3 - Transfer tokens to the miner escrow #
reward_txhash = self.token_agent.contract.functions.transfer(the_escrow_contract.address, self.__economics.reward_supply).transact(origin_args)
reward_txhash = self.token_agent.contract.functions.transfer(
the_escrow_contract.address,
self.__economics.escrow_deployment_reward_supply
).transact(origin_args)
_reward_receipt = self.blockchain.wait_for_receipt(reward_txhash)

View File

@ -407,6 +407,9 @@ class BlockchainDeployerInterface(BlockchainInterface):
class NoDeployerAddress(RuntimeError):
pass
class DeploymentFailed(RuntimeError):
pass
def __init__(self, deployer_address: str=None, *args, **kwargs) -> None:
super().__init__(*args, **kwargs) # Depends on web3 instance
self.__deployer_address = deployer_address if deployer_address is not None else NO_DEPLOYER_CONFIGURED
@ -419,7 +422,12 @@ class BlockchainDeployerInterface(BlockchainInterface):
def deployer_address(self, checksum_address: str) -> None:
self.__deployer_address = checksum_address
def deploy_contract(self, contract_name: str, *constructor_args, enroll: bool = True, **kwargs) -> Tuple[Contract, str]:
def deploy_contract(self,
contract_name: str,
*constructor_args,
enroll: bool = True,
**kwargs
) -> Tuple[Contract, str]:
"""
Retrieve compiled interface data from the cache and
return an instantiated deployed contract
@ -428,9 +436,11 @@ class BlockchainDeployerInterface(BlockchainInterface):
raise self.NoDeployerAddress
#
# Build the deployment tx #
# Build the deployment transaction #
#
deploy_transaction = {'from': self.deployer_address, 'gasPrice': self.w3.eth.gasPrice}
deployment_gas = 6_000_000 # TODO: Gas management
deploy_transaction = {'from': self.deployer_address, 'gas': deployment_gas}
self.log.info("Deployer address is {}".format(deploy_transaction['from']))
contract_factory = self.get_contract_factory(contract_name=contract_name)
@ -444,7 +454,23 @@ class BlockchainDeployerInterface(BlockchainInterface):
self.log.info("{} Deployment TX sent : txhash {}".format(contract_name, txhash.hex()))
# Wait for receipt
self.log.info(f"Waiting for deployment receipt for {contract_name}")
receipt = self.w3.eth.waitForTransactionReceipt(txhash)
# Verify deployment success
# Primary check
deployment_status = receipt['status']
if deployment_status is 0:
failure = f"{contract_name.upper()} Deployment transaction submitted, but receipt returned status code 0. " \
f"Full receipt: \n {receipt}"
raise self.DeploymentFailed(failure)
# Secondary check
tx = self.w3.eth.getTransaction(txhash)
if tx["gas"] == receipt["gasUsed"]:
raise self.DeploymentFailed(f"Deployment transaction failed and consumed 100% of transaction gas ({deployment_gas})")
address = receipt['contractAddress']
self.log.info("Confirmed {} deployment: address {}".format(contract_name, address))

View File

@ -375,8 +375,6 @@ def three_agents(testerchain):
miner_escrow_deployer.deploy()
miner_agent = miner_escrow_deployer.make_agent() # 2 Miner Escrow
policy_manager_secret = os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH)
policy_manager_deployer = PolicyManagerDeployer(
deployer_address=origin,
@ -384,6 +382,8 @@ def three_agents(testerchain):
policy_manager_deployer.deploy()
miner_agent = miner_escrow_deployer.make_agent() # 2 Miner Escrow
policy_agent = policy_manager_deployer.make_agent() # 3 Policy Agent
return token_agent, miner_agent, policy_agent