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

[feat] collect txns fees to a specific account #4265

Merged
merged 8 commits into from
Dec 9, 2022

Conversation

peekpi
Copy link
Contributor

@peekpi peekpi commented Aug 15, 2022

epoch activation for devnet at epoch 574

Issue

#4261

After FeeCollectEpoch, all the transactions fees will be collected into the feeCollector account instead of be burned.
If the feeCollector account is a contract, it will not trigger any of its functions(fallback()/receive() in solidity).
feeCollector’s balance increases after each transaction is executed.

@peekpi peekpi requested review from MaxMustermann2, rlan35 and LeoHChen and removed request for MaxMustermann2 August 15, 2022 16:41
@rlan35
Copy link
Contributor

rlan35 commented Aug 15, 2022

looks good. How is this change tested? We need to at least test on localnet and testnet before launching on mainnet since it's token-related critical change.

@sophoah
Copy link
Contributor

sophoah commented Aug 16, 2022

@here, my ask here is to have a new test written in https://github.com/harmony-one/harmony-test so this feature can be tested at every new PR and be part of our CI/CD thanks.

Copy link
Contributor

@MaxMustermann2 MaxMustermann2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Please add a test as Soph described; let me know if you need help.

internal/configs/sharding/mainnet.go Outdated Show resolved Hide resolved
@peekpi
Copy link
Contributor Author

peekpi commented Aug 16, 2022

looks good. How is this change tested? We need to at least test on localnet and testnet before launching on mainnet since it's token-related critical change.

because testnet has not been fixed, we can only test it in localnet. will post test log later.

@peekpi
Copy link
Contributor Author

peekpi commented Aug 17, 2022

test js script:

// fee.js
const ethers = require('ethers')

const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:9500')
const feeCollector = '0x19E7E376E7C213B7E7e7e46cc70A5dD086DAff2A'
const faucetPrivateKey = ''
const faucetWallet = new ethers.Wallet(faucetPrivateKey, provider)

async function main() {
    const getBalance = async ()=>({
        feeCollector: await provider.getBalance(feeCollector).then(ethers.utils.formatEther),
        faucet: await faucetWallet.getBalance().then(ethers.utils.formatEther)
    })

    const beforeBalance = await getBalance()
    const gasPrice = ethers.utils.parseEther('0.001')  // 21000 * 0.001 ether = 21 ether
    await faucetWallet.sendTransaction({to:faucetWallet.address, gasPrice}).then(tx=>tx.wait())
    const afterBalance = await getBalance()
    console.log('beforeBalance:', beforeBalance)
    console.log('afterBalance :', afterBalance)
}

main()

run node fee.js after FeeCollectEpoch and it will send a transaction with gas fee of 21 ether. we can see the balance of feeCollector increases.

log:

beforeBalance: { feeCollector: '0.0', faucet: '10000000000.0' }
afterBalance : { feeCollector: '21.0'', faucet: '9999999979.0' }

@MaxMustermann2
Copy link
Contributor

Can you move the checks here to be inside mustValid ?

if c.IsStakingPrecompile(epoch) {
if !c.IsPreStaking(epoch) {
panic("cannot have staking precompile epoch if not prestaking epoch")
}
}
if c.IsCrossShardXferPrecompile(epoch) {
if !c.AcceptsCrossTx(epoch) {
panic("cannot have cross shard xfer precompile epoch if not accepting cross tx")
}
}

Secondly, can you ensure the FeeCollectEpoch variable is set in all ChainConfig objects in the file ? For example, it is currently missing in StressnetChainConfig.

@peekpi
Copy link
Contributor Author

peekpi commented Aug 30, 2022

Can you move the checks here to be inside mustValid ?

if c.IsStakingPrecompile(epoch) {
if !c.IsPreStaking(epoch) {
panic("cannot have staking precompile epoch if not prestaking epoch")
}
}
if c.IsCrossShardXferPrecompile(epoch) {
if !c.AcceptsCrossTx(epoch) {
panic("cannot have cross shard xfer precompile epoch if not accepting cross tx")
}
}

Secondly, can you ensure the FeeCollectEpoch variable is set in all ChainConfig objects in the file ? For example, it is currently missing in StressnetChainConfig.

fixed

@sophoah
Copy link
Contributor

sophoah commented Oct 17, 2022

@peekpi will that work for shard 1/2/3 fees ? cc @MaxMustermann2

Also let's assume one day we need a 5th shard, will that still work ?

here are some test case scenario :
fee on a tx between s0 to s0
fees on a tx between s1 to s1
fees on a tx between s0 to s1

What about future cross shard contract transaction fee ?

@MaxMustermann2
Copy link
Contributor

What about future cross shard contract transaction fee ?

I can confirm that this will work.

@peekpi
Copy link
Contributor Author

peekpi commented Oct 19, 2022

@peekpi will that work for shard 1/2/3 fees ? cc @MaxMustermann2

Also let's assume one day we need a 5th shard, will that still work ?

here are some test case scenario : fee on a tx between s0 to s0 fees on a tx between s1 to s1 fees on a tx between s0 to s1

What about future cross shard contract transaction fee ?

fee are always collected in src shard.
s0->s0: s0
s1->s1: s1
s0->s1: s0
s1->s0: s1

for future cross shard contract transaction, we need to handle this scenario carefully. fee collection takes place in function collectGas(). cc @MaxMustermann2

@MaxMustermann2
Copy link
Contributor

If the FeeCollector is going to be a multisig, #4165 must be activated at the same time (or before) this change. This will allow movement of funds across shards through the smart contract, something that is not currently possible.

@peekpi
Copy link
Contributor Author

peekpi commented Oct 23, 2022

If the FeeCollector is going to be a multisig, #4165 must be activated at the same time (or before) this change. This will allow movement of funds across shards through the smart contract, something that is not currently possible.

does pr #4165 only support cross shard transfer? or also support cross shard contract call?

@MaxMustermann2
Copy link
Contributor

does pr #4165 only support cross shard transfer? or also support cross shard contract call?

It supports only transfers. And it's actually disabled for smart contract (although that needs some more hardening in my opinion). Please ignore my original comment then.

@MaxMustermann2 MaxMustermann2 removed the request for review from LeoHChen December 8, 2022 15:24
@sophoah sophoah merged commit f75cccf into harmony-one:main Dec 9, 2022
@sophoah sophoah changed the title [hardfork] collect txns fees to a specific account [feat] collect txns fees to a specific account Dec 9, 2022
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

Successfully merging this pull request may close these issues.

[hardfork] transaction fee goes to a multisig/foundation account
5 participants