Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bugs related to gas fees (ethereum#144)
When paying gas fees in C$ or any other non-native currency 1. Charge the user upfront for three things - balanceOf - to determine their balance in that currency) - debitFrom - to debit gas from their account - creditTo - to credit miner at the end 2. At the end if the fee to be refunded is less than the transaction fee to refund then pass that fee to the miner. Prior to this diff, ethereum#1 was not happening properly and ethereum#2 was not happening at all. As a more concrete example, if user passes 100K C$ wei as gas amount for a send tranaction then we will deduct 2195 to determine their balance in C$, then we will deduct 10,000 for a debitFrom transaction and another 10K for a creditTo transaction. So, the available gas (`st.gas`) would be 100,000 - 22,195 = 77,805 for rest of the transaction. At the end, we will pay the gas fees to the miner, which in this case is 22,195 + 21,000 (send fee) = 43,195, at the end, 56,805 gas is left, out of which 10, 000 is further deducted and then 46,805 is refunded to the sender and 43, 195 + 10, 000 is sent to the miner. Sample logs with gas price = 999 ``` DEBUG[03-21|18:18:51.003|core/state_transition.go:252] debitGas amount=99900000 gasCurrency=0x13f252CFCd0AED2FBAdAE507AA812aa1De01d8a4 TRACE[03-21|18:18:51.003|core/state_transition.go:262] debitGas rootCaller=0 customTokenContractAddress=0x13f252CFCd0AED2FBAdAE507AA812aa1De01d8a4 gas=10000 value=0 transactionData=0x362a5f80000000000000000000000000fee1a22f43beecb912b5a4912ba87527682ef0fc0000000000000000000000000000000000000000000000000000000005f45a60 DEBUG[03-21|18:18:51.003|core/state_transition.go:273] debitGas successful ret=0x00000000000000000000000000000000000000000000006c4fd1ee2454c9dd59 leftoverGas=2351 TRACE[03-21|18:18:51.003|core/state_transition.go:192] buyGas after debitGas upfrontGasCharges=22195 available gas=77805 initial gas=100000 gasCurrency=0x13f252CFCd0AED2FBAdAE507AA812aa1De01d8a4 TRACE[03-21|18:18:51.003|core/state_transition.go:463] Refunding gas to sender sender=0xfeE1a22F43BeeCB912B5a4912ba87527682ef0fC refundAmount=46758195 gas Currency=0x13f252CFCd0AED2FBAdAE507AA812aa1De01d8a4 DEBUG[03-21|18:18:51.003|core/state_transition.go:252] creditGas amount=46758195 gasCurrency=0x13f252CFCd0AED2FBAdAE507AA812aa1De01d8a4 TRACE[03-21|18:18:51.003|core/state_transition.go:262] creditGas rootCaller=0 customTokenContractAddress=0x13f252CFCd0AED2FBAdAE507AA812aa1De01d8a4 gas=10000 value=0 transactionData=0x9951b90c000000000000000000000000fee1a22f43beecb912b5a4912ba87527682ef0fc0000000000000000000000000000000000000000000000000000000002c97933 DEBUG[03-21|18:18:51.004|core/state_transition.go:273] creditGas successful ret=0x00000000000000000000000000000000000000000000006c4fd1ee245793568c leftoverGas=2057 TRACE[03-21|18:18:51.004|core/state_transition.go:425] Paying gas fees to miner unrefundedGas=0 gas used=53195 gasFeesForMiner=53195 miner Fee=53141805 TRACE[03-21|18:18:51.004|core/state_transition.go:428] Paying gas fees to miner miner=0xfeE1a22F43BeeCB912B5a4912ba87527682ef0fC minerFee=53141805 gas Currency=0x13f252CFCd0AED2FBAdAE507AA812aa1De01d8a4 ```
- Loading branch information