Skip to content

Commit

Permalink
Replace GasFeeRecipient with GatewayFee (ethereum#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor "Nate" Graf authored and Asa Oines committed Nov 21, 2019
1 parent 32d15e8 commit c3e4005
Show file tree
Hide file tree
Showing 52 changed files with 640 additions and 431 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -12,7 +12,7 @@ end-to-end-defaults: &end-to-end-defaults
docker:
- image: celohq/node10-gcloud
environment:
CELO_MONOREPO_BRANCH_TO_TEST: master
CELO_MONOREPO_BRANCH_TO_TEST: victor/gateway-fee

jobs:
unit-tests:
Expand Down
21 changes: 11 additions & 10 deletions accounts/abi/bind/backends/simulated.go
Expand Up @@ -410,16 +410,17 @@ type callmsg struct {
ethereum.CallMsg
}

func (m callmsg) From() common.Address { return m.CallMsg.From }
func (m callmsg) Nonce() uint64 { return 0 }
func (m callmsg) CheckNonce() bool { return false }
func (m callmsg) To() *common.Address { return m.CallMsg.To }
func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callmsg) GasCurrency() *common.Address { return m.CallMsg.GasCurrency }
func (m callmsg) GasFeeRecipient() *common.Address { return m.CallMsg.GasFeeRecipient }
func (m callmsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
func (m callmsg) Data() []byte { return m.CallMsg.Data }
func (m callmsg) From() common.Address { return m.CallMsg.From }
func (m callmsg) Nonce() uint64 { return 0 }
func (m callmsg) CheckNonce() bool { return false }
func (m callmsg) To() *common.Address { return m.CallMsg.To }
func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callmsg) FeeCurrency() *common.Address { return m.CallMsg.FeeCurrency }
func (m callmsg) GatewayFeeRecipient() *common.Address { return m.CallMsg.GatewayFeeRecipient }
func (m callmsg) GatewayFee() *big.Int { return m.CallMsg.GatewayFee }
func (m callmsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
func (m callmsg) Data() []byte { return m.CallMsg.Data }

// filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account.
Expand Down
29 changes: 16 additions & 13 deletions accounts/abi/bind/base.go
Expand Up @@ -49,11 +49,12 @@ type TransactOpts struct {
Nonce *big.Int // Nonce to use for the transaction execution (nil = use pending state)
Signer SignerFn // Method to use for signing the transaction (mandatory)

Value *big.Int // Funds to transfer along along the transaction (nil = 0 = no funds)
GasPrice *big.Int // Gas price to use for the transaction execution (nil = gas price oracle)
GasCurrency *common.Address // Gas currency to be used for transaction (nil = default currency = Celo Gold)
GasFeeRecipient *common.Address // Address to which gas fees should be paid (nil = fees are returned to sender)
GasLimit uint64 // Gas limit to set for the transaction execution (0 = estimate)
Value *big.Int // Funds to transfer along along the transaction (nil = 0 = no funds)
GasPrice *big.Int // Gas price to use for the transaction execution (nil = gas price oracle)
FeeCurrency *common.Address // Fee currency to be used for transaction (nil = default currency = Celo Gold)
GatewayFeeRecipient *common.Address // Address to which gateway fees should be paid (nil = no gateway fees are paid)
GatewayFee *big.Int // Value of gateway fees to be paid (nil = no gateway fees are paid)
GasLimit uint64 // Gas limit to set for the transaction execution (0 = estimate)

Context context.Context // Network context to support cancellation and timeouts (nil = no timeout)
}
Expand Down Expand Up @@ -209,17 +210,19 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
return nil, fmt.Errorf("failed to suggest gas price: %v", err)
}
}
gasCurrency := opts.GasCurrency
// TODO(ashishb): Add SuggestGasCurrency to Transactor to get gas currency

feeCurrency := opts.FeeCurrency
// TODO(nategraf): Add SuggestFeeCurrency to Transactor to get fee currency
// Otherwise, the user might not be able to pay in non-native currency for contract
// deployment. Paying for Contract deployment in non-native currency might not work right now.
// Only paying for token transfer in non-native currency is supported.
//if gasCurrency == 0 {
// gasCurrency = c.transactor.SuggestGasCurrency(opts.Context)
//if feeCurrency == 0 {
// feeCurrency = c.transactor.SuggestFeeCurrency(opts.Context)
//}

gasFeeRecipient := opts.GasFeeRecipient
// TODO(asa): Add SuggestGasFeeRecipient to Transactor.
gatewayFeeRecipient := opts.GatewayFeeRecipient
gatewayFee := opts.GatewayFee
// TODO(nategraf): Add SuggestGatewayFee to Transactor.

gasLimit := opts.GasLimit
if gasLimit == 0 {
Expand All @@ -241,9 +244,9 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
// Create the transaction, sign it and schedule it for execution
var rawTx *types.Transaction
if contract == nil {
rawTx = types.NewContractCreation(nonce, value, gasLimit, gasPrice, gasCurrency, gasFeeRecipient, input)
rawTx = types.NewContractCreation(nonce, value, gasLimit, gasPrice, feeCurrency, gatewayFeeRecipient, gatewayFee, input)
} else {
rawTx = types.NewTransaction(nonce, c.address, value, gasLimit, gasPrice, gasCurrency, gasFeeRecipient, input)
rawTx = types.NewTransaction(nonce, c.address, value, gasLimit, gasPrice, feeCurrency, gatewayFeeRecipient, gatewayFee, input)
}
if opts.Signer == nil {
return nil, errors.New("no signer to authorize the transaction with")
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/util_test.go
Expand Up @@ -60,7 +60,7 @@ func TestWaitDeployed(t *testing.T) {
)

// Create the transaction.
tx := types.NewContractCreation(0, big.NewInt(0), test.gas, big.NewInt(1), nil, nil, common.FromHex(test.code))
tx := types.NewContractCreation(0, big.NewInt(0), test.gas, big.NewInt(1), nil, nil, nil, common.FromHex(test.code))
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey)

// Wait for it to get mined in the background.
Expand Down
2 changes: 1 addition & 1 deletion cmd/faucet/faucet.go
Expand Up @@ -472,7 +472,7 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {
amount = new(big.Int).Mul(amount, new(big.Int).Exp(big.NewInt(5), big.NewInt(int64(msg.Tier)), nil))
amount = new(big.Int).Div(amount, new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(msg.Tier)), nil))

tx := types.NewTransaction(f.nonce+uint64(len(f.reqs)), address, amount, 21000, f.price, nil, nil, nil)
tx := types.NewTransaction(f.nonce+uint64(len(f.reqs)), address, amount, 21000, f.price, nil, nil, nil, nil)
signed, err := f.keystore.SignTx(f.account, tx, f.config.ChainID)
if err != nil {
f.lock.Unlock()
Expand Down
8 changes: 8 additions & 0 deletions cmd/utils/flags.go
Expand Up @@ -203,6 +203,11 @@ var (
Usage: "Public address for transaction broadcasting and block mining rewards (default = first account)",
Value: "0",
}
GatewayFeeFlag = BigFlag{
Name: "gatewayfee",
Usage: "Minimum value of gateway fee to serve a light client transaction",
Value: eth.DefaultConfig.GatewayFee,
}
BLSbaseFlag = cli.StringFlag{
Name: "blsbase",
Usage: "Public address for block mining BLS signatures (default = first account created)",
Expand Down Expand Up @@ -1415,6 +1420,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
if ctx.GlobalIsSet(EVMInterpreterFlag.Name) {
cfg.EVMInterpreter = ctx.GlobalString(EVMInterpreterFlag.Name)
}
if ctx.GlobalIsSet(GatewayFeeFlag.Name) {
cfg.GatewayFee = GlobalBig(ctx, GatewayFeeFlag.Name)
}

// Override any default configs for hard coded networks.
switch {
Expand Down
6 changes: 3 additions & 3 deletions contract_comm/blockchain_parameters/blockchain_parameters.go
Expand Up @@ -69,7 +69,7 @@ const (
{
"constant": true,
"inputs": [],
"name": "intrinsicGasForAlternativeGasCurrency",
"name": "intrinsicGasForAlternativeFeeCurrency",
"outputs": [
{
"name": "",
Expand Down Expand Up @@ -133,8 +133,8 @@ func GetGasCost(header *types.Header, state vm.StateDB, defaultGas uint64, metho
return gas.Uint64()
}

func GetIntrinsicGasForAlternativeGasCurrency(header *types.Header, state vm.StateDB) uint64 {
return GetGasCost(header, state, params.IntrinsicGasForAlternativeGasCurrency, "intrinsicGasForAlternativeGasCurrency")
func GetIntrinsicGasForAlternativeFeeCurrency(header *types.Header, state vm.StateDB) uint64 {
return GetGasCost(header, state, params.IntrinsicGasForAlternativeFeeCurrency, "intrinsicGasForAlternativeFeeCurrency")
}

func CheckMinimumVersion(header *types.Header, state vm.StateDB) {
Expand Down
14 changes: 7 additions & 7 deletions contract_comm/currency/currency.go
Expand Up @@ -77,7 +77,7 @@ const (
"type": "function"
}]`

// This is taken from celo-monorepo/packages/protocol/build/<env>/contracts/GasCurrency.json
// This is taken from celo-monorepo/packages/protocol/build/<env>/contracts/FeeCurrency.json
getWhitelistABI = `[{"constant": true,
"inputs": [],
"name": "getWhitelist",
Expand Down Expand Up @@ -190,12 +190,12 @@ func getExchangeRate(currencyAddress *common.Address) (*exchangeRate, error) {
log.Warn("Registry address lookup failed", "err", err)
return &exchangeRate{big.NewInt(1), big.NewInt(1)}, err
} else {
log.Error("medianRate invocation error", "gasCurrencyAddress", currencyAddress.Hex(), "leftoverGas", leftoverGas, "err", err)
log.Error("medianRate invocation error", "feeCurrencyAddress", currencyAddress.Hex(), "leftoverGas", leftoverGas, "err", err)
return &exchangeRate{big.NewInt(1), big.NewInt(1)}, err
}
}
}
log.Trace("medianRate invocation success", "gasCurrencyAddress", currencyAddress, "returnArray", returnArray, "leftoverGas", leftoverGas)
log.Trace("medianRate invocation success", "feeCurrencyAddress", currencyAddress, "returnArray", returnArray, "leftoverGas", leftoverGas)
return &exchangeRate{returnArray[0], returnArray[1]}, nil
}

Expand All @@ -217,12 +217,12 @@ func GetBalanceOf(accountOwner common.Address, contractAddress common.Address, g
}

// ------------------------------
// GasCurrencyWhiteList Functions
// FeeCurrencyWhiteList Functions
//-------------------------------
func retrieveWhitelist(header *types.Header, state vm.StateDB) ([]common.Address, error) {
returnList := []common.Address{}

_, err := contract_comm.MakeStaticCall(params.GasCurrencyWhitelistRegistryId, getWhitelistFuncABI, "getWhitelist", []interface{}{}, &returnList, params.MaxGasForGetWhiteList, header, state)
_, err := contract_comm.MakeStaticCall(params.FeeCurrencyWhitelistRegistryId, getWhitelistFuncABI, "getWhitelist", []interface{}{}, &returnList, params.MaxGasForGetWhiteList, header, state)
if err != nil {
if err == errors.ErrSmartContractNotDeployed {
log.Warn("Registry address lookup failed", "err", err)
Expand All @@ -239,7 +239,7 @@ func retrieveWhitelist(header *types.Header, state vm.StateDB) ([]common.Address
func IsWhitelisted(currencyAddress common.Address, header *types.Header, state vm.StateDB) bool {
whitelist, err := retrieveWhitelist(header, state)
if err != nil {
log.Warn("Failed to get gas currency whitelist", "err", err)
log.Warn("Failed to get fee currency whitelist", "err", err)
return true
}
return containsCurrency(currencyAddress, whitelist)
Expand All @@ -257,7 +257,7 @@ func containsCurrency(currencyAddr common.Address, currencyList []common.Address
func CurrencyWhitelist(header *types.Header, state vm.StateDB) ([]common.Address, error) {
whitelist, err := retrieveWhitelist(header, state)
if err != nil {
log.Warn("Failed to get gas currency whitelist", "err", err)
log.Warn("Failed to get fee currency whitelist", "err", err)
}
return whitelist, err
}
2 changes: 1 addition & 1 deletion contract_comm/evm.go
Expand Up @@ -34,7 +34,7 @@ import (
// NOTE: Any changes made to this file should be duplicated to core/evm.go!

var (
emptyMessage = types.NewMessage(common.HexToAddress("0x0"), nil, 0, common.Big0, 0, common.Big0, nil, nil, []byte{}, false)
emptyMessage = types.NewMessage(common.HexToAddress("0x0"), nil, 0, common.Big0, 0, common.Big0, nil, nil, common.Big0, []byte{}, false)
internalEvmHandlerSingleton *InternalEVMHandler
)

Expand Down
3 changes: 2 additions & 1 deletion core/bench_test.go
Expand Up @@ -86,7 +86,7 @@ func genValueTx(nbytes int) func(int, *BlockGen) {
toaddr := common.Address{}
data := make([]byte, nbytes)
gas, _ := IntrinsicGas(data, false, false, nil, nil, nil)
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(benchRootAddr), toaddr, big.NewInt(1), gas, nil, nil, nil, data), types.HomesteadSigner{}, benchRootKey)
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(benchRootAddr), toaddr, big.NewInt(1), gas, nil, nil, nil, nil, data), types.HomesteadSigner{}, benchRootKey)
gen.AddTx(tx)
}
}
Expand Down Expand Up @@ -128,6 +128,7 @@ func genTxRing(naccounts int) func(int, *BlockGen) {
nil,
nil,
nil,
nil,
)
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, ringKeys[from])
gen.AddTx(tx)
Expand Down

0 comments on commit c3e4005

Please sign in to comment.