1

Creating a dapp, which requires half allocated mining fee should go to an address.

I managed to cut down the mining as well as the block reward:

consensus.go

    // Accumulate the rewards for the miner and any included uncles
    reward := new(big.Int).Set(blockReward)
    rew := new(big.Int).Set(blockReward)
    r := new(big.Int)
    for _, uncle := range uncles {
        r.Add(uncle.Number, big8)
        r.Sub(r, header.Number)
        r.Mul(r, blockReward)
        r.Div(r, big8)
        state.AddBalance(uncle.Coinbase, r)

        r.Div(blockReward, big32)
        reward.Add(reward, r)
    }

    changedRew := new(big.Int).Set(rew) // half reward
    changedRew.Div(changedRew, big.NewInt(2))
    log.Warn("Mining block reward status .. ", "CHANGED", changedRew )
    state.AddBalance(header.Coinbase, changedRew)
}

state_transition.go

        if vmerr == vm.ErrInsufficientBalance {
            return nil, 0, false, vmerr
        }
    }
    st.refundGas()
    log.Warn("Half fee taken away ")
    // change price 
    st.state.AddBalance(st.evm.Coinbase, changedRew.Div(new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), st.gasPrice), big.NewInt(2)))

    return ret, st.gasUsed(), vmerr != nil, err
}

How can I now transfer the other half to an address? If I specify an account/address to be transferred , that can be easily changed without effecting the block rules. How can I do it securely ?

P.S : Just one account constant account for every node to transfer half mining fee.

2

As easy as this:

the_other_half_addr:=common.HexToAddress("0xlajfklsadjflsafjklsadjdflkadjfl")
state.AddBalance(the_other_half_addr,changedRew)

You are doing it securely, but you forgot to take the half from the uncles too.

  • Thanks ! It's secure because if the address is changed, it will result into a different block hash. Is that true? – rohan sethi Jul 13 '18 at 7:22
  • Yes, the Root() of the types.Block will return a different output since every modification to the State will change its hash . But you have to verify this in a test, just to be sure you didn't made any mistake. Create a 2 different datadirs and mine one block with different addresses. The hashes of the Root() and Hash() of the block should be different in both datadirs, If someone modifies this address and runs his own node, his block will be discarded by the network on the first block with different hash. – Nulik Jul 14 '18 at 15:04
  • I tried doing it. Keeping keystore same for datadir and datadir2, it gave me a different stateRoot hash .From the first datadir, I kept the same keystore and minerBase. Then I re-ran the setup from datadir2, which gave me same state hash each new time. Then I changed the account address from the source, the stateRoot hash was different this time.So it does verify it. But what could be the possible reason i was unable to get same state root same as datadir (original folder) ? – rohan sethi Jul 15 '18 at 12:14
  • Also, the transactions Root are same in every case.Is this because i'm mining empty blocks? I think transactions have different tree than the state. – rohan sethi Jul 15 '18 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.