Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating native coins by native-to-native bridge using RewardByBlock contract #22

Open
varasev opened this issue Jul 12, 2018 · 5 comments

Comments

@varasev
Copy link

varasev commented Jul 12, 2018

Title

  Title: Creating native coins by native-to-native bridge using RewardByBlock contract
  Layer: Bridges

Abstract

When the bridge needs to generate native coins on POA Network side, it will be able to use RewardByBlock (BlockReward) smart contract, the support of which was added in Parity 1.11: openethereum/parity-ethereum#8419.

RewardByBlock contract allows pointing Parity at how many coins must be generated after creating of each block and on which addresses these coins must be accrued.

Rationale

It is the easiest and possibly only way native coins can be generated for the bridge.

Implementation

We need to complement RewardByBlock by the possibility of accruing coins to the specified address(es).

Smart contract of the bridge has to call some function of RewardByBlock, which will write the specified addresses and appropriate amounts of coins into contract's state. When a new block is being generated, and reward function is being called, those addresses and amounts will have to be in return statement of reward function and will have to be removed from contract's state.

RewardByBlock contract must control the address (msg.sender) of the bridge's contract.

@varasev
Copy link
Author

varasev commented Jul 12, 2018

@varasev
Copy link
Author

varasev commented Jul 12, 2018

@varasev
Copy link
Author

varasev commented Jul 16, 2018

RewardByBlock contract was supplemented by addExtraReceiver function in poanetwork/poa-network-consensus-contracts#144.

Unit tests were also added: https://github.com/poanetwork/poa-network-consensus-contracts/blob/35a618d1ebb60db60c6fd006f8a153be695c2cef/test/reward_by_block_test.js

That function may only be called once for the same receiver until a new block is created (reward function is called).

addExtraReceiver may only be called by bridge contract which address is stored in the bridgeContract constant: https://github.com/poanetwork/poa-network-consensus-contracts/blob/35a618d1ebb60db60c6fd006f8a153be695c2cef/contracts/RewardByBlock.sol#L23

@varasev
Copy link
Author

varasev commented Jul 16, 2018

https://github.com/varasev/test-block-reward repo has been updated to be able to rebuild contracts with npm run build.

Now if some contract code changes, we can recompile contracts with npm run build and completely restart setup with npm run restart.

I'm going to update contracts in that setup to the current versions available in https://github.com/poanetwork/poa-network-consensus-contracts/tree/35a618d1ebb60db60c6fd006f8a153be695c2cef and make send.js demo script showing how RewardByBlock.addExtraReceiver function works.

@varasev
Copy link
Author

varasev commented Jul 18, 2018

https://github.com/varasev/test-block-reward has been updated with the latest versions of smart contracts and complemented with npm run accrue 1 command that allows accruing one coin to a test address. Instructions are in README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant