From 729c5e48a86e0a3bf4cb130eb98006216fb78311 Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Thu, 2 Nov 2023 21:59:01 +0100 Subject: [PATCH 01/12] Added MultiGasPool --- core/celo_multi_gaspool.go | 58 +++++++++++++ core/celo_multi_gaspool_test.go | 139 ++++++++++++++++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100644 core/celo_multi_gaspool.go create mode 100644 core/celo_multi_gaspool_test.go diff --git a/core/celo_multi_gaspool.go b/core/celo_multi_gaspool.go new file mode 100644 index 0000000000..3eee0be536 --- /dev/null +++ b/core/celo_multi_gaspool.go @@ -0,0 +1,58 @@ +package core + +import ( + "github.com/celo-org/celo-blockchain/common" +) + +type FeeCurrency = common.Address + +// MultiGasPool tracks the amount of gas available during execution +// of the transactions in a block per fee currency. The zero value is a pool +// with zero gas available. +type MultiGasPool struct { + pools map[FeeCurrency]*GasPool + defaultPool *GasPool +} + +type FeeCurrencyLimitMapping = map[FeeCurrency]float64 + +// NewMultiGasPool creates a multi-fee currency gas pool and a default fallback +// pool for any unconfigured currencies and CELO +func NewMultiGasPool( + block_gas_limit uint64, + whitelist []FeeCurrency, + defaultLimit float64, + limitsMapping FeeCurrencyLimitMapping, +) MultiGasPool { + pools := make(map[FeeCurrency]*GasPool, len(whitelist)) + + for i := range whitelist { + currency := whitelist[i] + fraction, ok := limitsMapping[currency] + if !ok { + fraction = defaultLimit + } + + pools[currency] = new(GasPool).AddGas( + uint64(float64(block_gas_limit) * fraction), + ) + } + + // A special case for CELO which doesn't have a limit + celoPool := new(GasPool).AddGas(block_gas_limit) + + return MultiGasPool{ + pools: pools, + defaultPool: celoPool, + } +} + +// PoolFor returns a configured pool for the given fee currency or the default +// one otherwise +func (mgp MultiGasPool) PoolFor(feeCurrency *FeeCurrency) *GasPool { + if feeCurrency == nil || mgp.pools[*feeCurrency] == nil { + return mgp.defaultPool + } + + return mgp.pools[*feeCurrency] +} diff --git a/core/celo_multi_gaspool_test.go b/core/celo_multi_gaspool_test.go new file mode 100644 index 0000000000..a57f732b96 --- /dev/null +++ b/core/celo_multi_gaspool_test.go @@ -0,0 +1,139 @@ +package core + +import ( + "testing" + + "github.com/celo-org/celo-blockchain/common" +) + +func TestMultiCurrencyGasPool(t *testing.T) { + block_gas_limit := uint64(1_000) + sub_gas_amount := 100 + + cusd_token := common.HexToAddress("0x765DE816845861e75A25fCA122bb6898B8B1282a") + ceur_token := common.HexToAddress("0xD8763CBa276a3738E6DE85b4b3bF5FDed6D6cA73") + + testCases := []struct { + name string + whitelist []common.Address + feeCurrency *FeeCurrency + defaultLimit float64 + limits FeeCurrencyLimitMapping + defaultPoolExpected bool + expectedValue uint64 + }{ + { + name: "Empty whitelist, empty mapping, CELO uses default pool", + feeCurrency: nil, + whitelist: []FeeCurrency{}, + defaultLimit: 0.9, + limits: map[FeeCurrency]float64{}, + defaultPoolExpected: true, + expectedValue: 900, // block_gas_limit - sub_gas_amount + }, + { + name: "Non-empty whitelist, non-empty mapping, CELO uses default pool", + feeCurrency: nil, + whitelist: []FeeCurrency{ + cusd_token, + }, + defaultLimit: 0.9, + limits: map[FeeCurrency]float64{ + cusd_token: 0.5, + }, + defaultPoolExpected: true, + expectedValue: 900, // block_gas_limit - sub_gas_amount + }, + { + name: "Empty whitelist, empty mapping, non-whitelisted currency fallbacks to the default pool", + feeCurrency: &cusd_token, + whitelist: []FeeCurrency{}, + defaultLimit: 0.9, + limits: map[FeeCurrency]float64{}, + defaultPoolExpected: true, + expectedValue: 900, // block_gas_limit - sub_gas_amount + }, + { + name: "Non-empty whitelist, non-empty mapping, non-whitelisted currency uses default pool", + feeCurrency: &ceur_token, + whitelist: []FeeCurrency{ + cusd_token, + }, + defaultLimit: 0.9, + limits: map[FeeCurrency]float64{ + cusd_token: 0.5, + }, + defaultPoolExpected: true, + expectedValue: 900, // block_gas_limit - sub_gas_amount + }, + { + name: "Non-empty whitelist, empty mapping, whitelisted currency uses default limit", + feeCurrency: &cusd_token, + whitelist: []FeeCurrency{ + cusd_token, + }, + defaultLimit: 0.9, + limits: map[FeeCurrency]float64{}, + defaultPoolExpected: false, + expectedValue: 800, // block_gas_limit * defaultLimit - sub_gas_amount + }, + { + name: "Non-empty whitelist, non-empty mapping, configured whitelisted currency uses configured limits", + feeCurrency: &cusd_token, + whitelist: []FeeCurrency{ + cusd_token, + }, + defaultLimit: 0.9, + limits: map[FeeCurrency]float64{ + cusd_token: 0.5, + }, + defaultPoolExpected: false, + expectedValue: 400, // block_gas_limit * 0.5 - sub_gas_amount + }, + { + name: "Non-empty whitelist, non-empty mapping, unconfigured whitelisted currency uses default limit", + feeCurrency: &ceur_token, + whitelist: []FeeCurrency{ + cusd_token, + ceur_token, + }, + defaultLimit: 0.9, + limits: map[FeeCurrency]float64{ + cusd_token: 0.5, + }, + defaultPoolExpected: false, + expectedValue: 800, // block_gas_limit * 0.5 - sub_gas_amount + }, + } + + for _, c := range testCases { + t.Run(c.name, func(t *testing.T) { + mgp := NewMultiGasPool( + block_gas_limit, + c.whitelist, + c.defaultLimit, + c.limits, + ) + + pool := mgp.PoolFor(c.feeCurrency) + pool.SubGas(uint64(sub_gas_amount)) + + if c.defaultPoolExpected { + result := mgp.defaultPool.Gas() + if result != c.expectedValue { + t.Error("Default pool expected", c.expectedValue, "got", result) + } + } else { + pool := mgp.pools[*c.feeCurrency] + result := pool.Gas() + + if result != c.expectedValue { + t.Error( + "Expected pool", c.feeCurrency, "value", c.expectedValue, + "got", result, + ) + } + } + }) + } +} From bebf3aec5234466d9a7acc69ec33eef0c793c30a Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Thu, 2 Nov 2023 22:04:58 +0100 Subject: [PATCH 02/12] Added default configuration --- miner/celo_defaults.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 miner/celo_defaults.go diff --git a/miner/celo_defaults.go b/miner/celo_defaults.go new file mode 100644 index 0000000000..861209042b --- /dev/null +++ b/miner/celo_defaults.go @@ -0,0 +1,20 @@ +package miner + +import ( + "github.com/celo-org/celo-blockchain/common" + "github.com/celo-org/celo-blockchain/params" +) + +// cStables addresses on mainnet +var cUSD_TOKEN = common.HexToAddress("0x765DE816845861e75A25fCA122bb6898B8B1282a") +var cEUR_TOKEN = common.HexToAddress("0xD8763CBa276a3738E6DE85b4b3bF5FDed6D6cA73") +var cREAL_TOKEN = common.HexToAddress("0xe8537a3d056DA446677B9E9d6c5dB704EaAb4787") + +// default limits configuration +var DefaultFeeCurrencyLimits = map[uint64]map[common.Address]float64{ + params.MainnetNetworkId: { + cUSD_TOKEN: 0.9, + cEUR_TOKEN: 0.5, + cREAL_TOKEN: 0.1, + }, +} From 1563a7813910639cc64a438c350282bc0b0c6342 Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Thu, 2 Nov 2023 22:00:34 +0100 Subject: [PATCH 03/12] Added new flags --- cmd/geth/main.go | 2 ++ cmd/geth/usage.go | 2 ++ cmd/utils/flags.go | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 0e2c964717..d662b96f40 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -162,6 +162,8 @@ var ( utils.ProxyEnodeURLPairsFlag, utils.LegacyProxyEnodeURLPairsFlag, utils.ProxyAllowPrivateIPFlag, + utils.CeloFeeCurrencyDefault, + utils.CeloFeeCurrencyLimits, } rpcFlags = []cli.Flag{ diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 8aab205a15..ef8f979e49 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -171,6 +171,8 @@ var AppHelpFlagGroups = []flags.FlagGroup{ utils.MiningEnabledFlag, utils.MinerValidatorFlag, utils.MinerExtraDataFlag, + utils.CeloFeeCurrencyDefault, + utils.CeloFeeCurrencyLimits, }, }, { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 549f5e10bc..f9f7a83557 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -421,6 +421,16 @@ var ( Name: "miner.extradata", Usage: "Block extra data set by the miner (default = client version)", } + CeloFeeCurrencyDefault = cli.Float64Flag{ + Name: "celo.feecurrency.default", + Usage: "Default fraction of block gas limit available for TXs paid with a whitelisted currency", + Value: 0.9, + } + CeloFeeCurrencyLimits = cli.StringFlag{ + Name: "celo.feecurrency.limits", + Usage: "Comma separated currency address-to-block percentage mappings (
=)", + } + // Account settings UnlockedAccountFlag = cli.StringFlag{ @@ -1433,6 +1443,37 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) { if ctx.GlobalIsSet(MinerExtraDataFlag.Name) { cfg.ExtraData = []byte(ctx.GlobalString(MinerExtraDataFlag.Name)) } + + cfg.FeeCurrencyDefault = ctx.GlobalFloat64(CeloFeeCurrencyDefault.Name) + + defaultLimits, ok := miner.DefaultFeeCurrencyLimits[getNetworkId(ctx)] + if !ok { + defaultLimits = make(map[common.Address]float64) + } + + cfg.FeeCurrencyLimits = defaultLimits + + if ctx.GlobalIsSet(CeloFeeCurrencyLimits.Name) { + feeCurrencyLimits := ctx.GlobalString(CeloFeeCurrencyLimits.Name) + + for _, entry := range strings.Split(feeCurrencyLimits, ",") { + parts := strings.Split(entry, "=") + if len(parts) != 2 { + Fatalf("Invalid fee currency limits entry: %s", entry) + } + var address common.Address + if err := address.UnmarshalText([]byte(parts[0])); err != nil { + Fatalf("Invalid fee currency address hash %s: %v", parts[0], err) + } + + fraction, err := strconv.ParseFloat(parts[1], 64) + if err != nil { + Fatalf("Invalid block limit fraction %s: %v", parts[1], err) + } + + cfg.FeeCurrencyLimits[address] = fraction + } + } } func setWhitelist(ctx *cli.Context, cfg *ethconfig.Config) { From 45a4394d78c904bc4d7c7cec786915960664f42e Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Thu, 2 Nov 2023 22:00:55 +0100 Subject: [PATCH 04/12] Implemented the limit per fee currency --- miner/block.go | 50 ++++++++++++++++++++++++++++++++++++++++++++------ miner/miner.go | 6 ++++-- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/miner/block.go b/miner/block.go index 8efed03943..3aefde0890 100644 --- a/miner/block.go +++ b/miner/block.go @@ -41,12 +41,13 @@ import ( type blockState struct { signer types.Signer - state *state.StateDB // apply state changes here - tcount int // tx count in cycle - gasPool *core.GasPool // available gas used to pack transactions - bytesBlock *core.BytesBlock // available bytes used to pack transactions - gasLimit uint64 - sysCtx *core.SysContractCallCtx + state *state.StateDB // apply state changes here + tcount int // tx count in cycle + gasPool *core.GasPool // available gas used to pack transactions + bytesBlock *core.BytesBlock // available bytes used to pack transactions + multiGasPool core.MultiGasPool // available gas to pay for with currency + gasLimit uint64 + sysCtx *core.SysContractCallCtx header *types.Header txs []*types.Transaction @@ -112,6 +113,20 @@ func prepareBlock(w *worker) (*blockState, error) { txFeeRecipient: txFeeRecipient, } b.gasPool = new(core.GasPool).AddGas(b.gasLimit) + + whitelist, err := currency.CurrencyWhitelist(vmRunner) + if err != nil { + log.Warn("Can't fetch currency whitelist", "error", err, "block", header.Number.Uint64()) + whitelist = []common.Address{} + } + + b.multiGasPool = core.NewMultiGasPool( + b.gasLimit, + whitelist, + w.config.FeeCurrencyDefault, + w.config.FeeCurrencyLimits, + ) + if w.chainConfig.IsGingerbread(header.Number) { header.GasLimit = b.gasLimit header.Difficulty = big.NewInt(0) @@ -250,6 +265,17 @@ loop: if tx == nil { break } + // Short-circuit if the transaction is using more gas allocated for the + // given fee currency. + if b.multiGasPool.PoolFor(tx.FeeCurrency()).Gas() < tx.Gas() { + log.Trace( + "Skipping transaction which requires more gas than is left in the pool", + "hash", tx.Hash(), "gas", b.multiGasPool.PoolFor(tx.FeeCurrency()).Gas(), + "txgas", tx.Gas(), + ) + txs.Pop() + continue + } // Short-circuit if the transaction requires more gas than we have in the pool. // If we didn't short-circuit here, we would get core.ErrGasLimitReached below. // Short-circuiting here saves us the trouble of checking the GPM and so on when the tx can't be included @@ -321,6 +347,18 @@ loop: return err } } + + err = b.multiGasPool.PoolFor(tx.FeeCurrency()).SubGas(tx.Gas()) + // Should never happen as we check it above + if err != nil { + log.Warn( + "Unexpectedly reached limit for fee currency", + "hash", tx.Hash(), "gas", b.multiGasPool.PoolFor(tx.FeeCurrency()).Gas(), + "txgas", tx.Gas(), + ) + return err + } + txs.Shift() default: diff --git a/miner/miner.go b/miner/miner.go index 6e22cdf230..939eb5b73e 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -43,8 +43,10 @@ type Backend interface { // Config is the configuration parameters of mining. type Config struct { - Validator common.Address `toml:",omitempty"` // Public address for block signing and randomness (default = first account) - ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner + Validator common.Address `toml:",omitempty"` // Public address for block signing and randomness (default = first account) + ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner + FeeCurrencyDefault float64 // Default fraction of block gas limit + FeeCurrencyLimits map[common.Address]float64 // Fee currency-to-limit fraction mapping } // Miner creates blocks and searches for proof-of-work values. From d9b093f23acb41cd420e5da4b095f8f50d4aabb9 Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Thu, 2 Nov 2023 21:26:29 +0100 Subject: [PATCH 05/12] Fixed tests --- test/node.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/node.go b/test/node.go index d03c85aabc..74e3f9b879 100644 --- a/test/node.go +++ b/test/node.go @@ -26,6 +26,7 @@ import ( "github.com/celo-org/celo-blockchain/eth/downloader" "github.com/celo-org/celo-blockchain/eth/tracers" "github.com/celo-org/celo-blockchain/ethclient" + "github.com/celo-org/celo-blockchain/miner" "github.com/celo-org/celo-blockchain/mycelo/env" "github.com/celo-org/celo-blockchain/mycelo/genesis" "github.com/celo-org/celo-blockchain/node" @@ -86,6 +87,9 @@ var ( DefaultLookbackWindow: 3, BlockPeriod: 0, }, + Miner: miner.Config{ + FeeCurrencyDefault: 0.9, + }, } ) From 922027cd1301a2071b6b5823789a6aa951b2f0ce Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Mon, 6 Nov 2023 13:54:34 +0100 Subject: [PATCH 06/12] Fixed PR comments --- core/sys_context.go | 11 +++++++++++ miner/block.go | 26 ++++++++++---------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/core/sys_context.go b/core/sys_context.go index a20689428c..b33a3d7781 100644 --- a/core/sys_context.go +++ b/core/sys_context.go @@ -73,6 +73,17 @@ func (sc *SysContractCallCtx) GetIntrinsicGasForAlternativeFeeCurrency() uint64 return sc.nonCeloCurrencyIntrinsicGas } +// GetWhitelistedCurrencies retrieves intrinsic gas for non-native fee currencies. +func (sc *SysContractCallCtx) GetWhitelistedCurrencies() []common.Address { + whitelist := make([]common.Address, len(sc.whitelistedCurrencies)) + + for c := range sc.whitelistedCurrencies { + whitelist = append(whitelist, c) + } + + return whitelist +} + // IsWhitelisted indicates if the fee currency is whitelisted, or it's native token(CELO). func (sc *SysContractCallCtx) IsWhitelisted(feeCurrency *common.Address) bool { if feeCurrency == nil { diff --git a/miner/block.go b/miner/block.go index 3aefde0890..b4a397eca0 100644 --- a/miner/block.go +++ b/miner/block.go @@ -114,19 +114,6 @@ func prepareBlock(w *worker) (*blockState, error) { } b.gasPool = new(core.GasPool).AddGas(b.gasLimit) - whitelist, err := currency.CurrencyWhitelist(vmRunner) - if err != nil { - log.Warn("Can't fetch currency whitelist", "error", err, "block", header.Number.Uint64()) - whitelist = []common.Address{} - } - - b.multiGasPool = core.NewMultiGasPool( - b.gasLimit, - whitelist, - w.config.FeeCurrencyDefault, - w.config.FeeCurrencyLimits, - ) - if w.chainConfig.IsGingerbread(header.Number) { header.GasLimit = b.gasLimit header.Difficulty = big.NewInt(0) @@ -142,6 +129,13 @@ func prepareBlock(w *worker) (*blockState, error) { } b.sysCtx = core.NewSysContractCallCtx(header, state.Copy(), w.chain) + b.multiGasPool = core.NewMultiGasPool( + b.gasLimit, + b.sysCtx.GetWhitelistedCurrencies(), + w.config.FeeCurrencyDefault, + w.config.FeeCurrencyLimits, + ) + // Play our part in generating the random beacon. if w.isRunning() && random.IsRunning(vmRunner) { istanbul, ok := w.engine.(consensus.Istanbul) @@ -269,9 +263,9 @@ loop: // given fee currency. if b.multiGasPool.PoolFor(tx.FeeCurrency()).Gas() < tx.Gas() { log.Trace( - "Skipping transaction which requires more gas than is left in the pool", - "hash", tx.Hash(), "gas", b.multiGasPool.PoolFor(tx.FeeCurrency()).Gas(), - "txgas", tx.Gas(), + "Skipping transaction which requires more gas than is left in the pool for a specific fee currency", + "currency", tx.FeeCurrency(), "tx hash", tx.Hash(), + "gas", b.multiGasPool.PoolFor(tx.FeeCurrency()).Gas(), "txgas", tx.Gas(), ) txs.Pop() continue From e219e33ca42996ffa80c417f67344aa9ad3f26f5 Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Mon, 6 Nov 2023 17:33:29 +0100 Subject: [PATCH 07/12] Changed fraction for cREAL --- miner/celo_defaults.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miner/celo_defaults.go b/miner/celo_defaults.go index 861209042b..a523a0d0ce 100644 --- a/miner/celo_defaults.go +++ b/miner/celo_defaults.go @@ -15,6 +15,6 @@ var DefaultFeeCurrencyLimits = map[uint64]map[common.Address]float64{ params.MainnetNetworkId: { cUSD_TOKEN: 0.9, cEUR_TOKEN: 0.5, - cREAL_TOKEN: 0.1, + cREAL_TOKEN: 0.5, }, } From 38123453fe9860a0152357ade3fe4bcf399b1a52 Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Tue, 7 Nov 2023 09:54:54 +0100 Subject: [PATCH 08/12] Fixed a typo --- core/sys_context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/sys_context.go b/core/sys_context.go index b33a3d7781..820c42fe16 100644 --- a/core/sys_context.go +++ b/core/sys_context.go @@ -75,7 +75,7 @@ func (sc *SysContractCallCtx) GetIntrinsicGasForAlternativeFeeCurrency() uint64 // GetWhitelistedCurrencies retrieves intrinsic gas for non-native fee currencies. func (sc *SysContractCallCtx) GetWhitelistedCurrencies() []common.Address { - whitelist := make([]common.Address, len(sc.whitelistedCurrencies)) + whitelist := make([]common.Address, 0, len(sc.whitelistedCurrencies)) for c := range sc.whitelistedCurrencies { whitelist = append(whitelist, c) From e85b75ece8ab2aa07b2edf0c72765029189c2a83 Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Wed, 22 Nov 2023 17:31:41 +0100 Subject: [PATCH 09/12] Use gas used to subtract from the gas pool --- miner/block.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/miner/block.go b/miner/block.go index b4a397eca0..039bfb97ec 100644 --- a/miner/block.go +++ b/miner/block.go @@ -342,13 +342,22 @@ loop: } } - err = b.multiGasPool.PoolFor(tx.FeeCurrency()).SubGas(tx.Gas()) + if len(b.receipts) == 0 { + // this shouldn't happen as if there was no error on commitTransaction + // a new receipt gets added + log.Warn("Unexpectedly empty receipts list") + return fmt.Errorf("No new receipts added for tx %s", tx.Hash()) + } + + receipt := b.receipts[len(b.receipts)-1] + + err = b.multiGasPool.PoolFor(tx.FeeCurrency()).SubGas(receipt.GasUsed) // Should never happen as we check it above if err != nil { log.Warn( "Unexpectedly reached limit for fee currency", "hash", tx.Hash(), "gas", b.multiGasPool.PoolFor(tx.FeeCurrency()).Gas(), - "txgas", tx.Gas(), + "tx gas used", receipt.GasUsed, ) return err } From 5bae68ad811f060990ad0e76245d0d4a9fbb3f54 Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Thu, 23 Nov 2023 11:53:25 +0100 Subject: [PATCH 10/12] A nicer way to get gasUsed --- miner/block.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/miner/block.go b/miner/block.go index 039bfb97ec..96e774f1c9 100644 --- a/miner/block.go +++ b/miner/block.go @@ -307,7 +307,10 @@ loop: // Start executing the transaction b.state.Prepare(tx.Hash(), b.tcount) + availableGas := b.gasPool.Gas() logs, err := b.commitTransaction(w, tx, txFeeRecipient) + gasUsed := availableGas - b.gasPool.Gas() + switch { case errors.Is(err, core.ErrGasLimitReached): // Pop the current out-of-gas transaction without shifting in the next from the account @@ -342,22 +345,13 @@ loop: } } - if len(b.receipts) == 0 { - // this shouldn't happen as if there was no error on commitTransaction - // a new receipt gets added - log.Warn("Unexpectedly empty receipts list") - return fmt.Errorf("No new receipts added for tx %s", tx.Hash()) - } - - receipt := b.receipts[len(b.receipts)-1] - - err = b.multiGasPool.PoolFor(tx.FeeCurrency()).SubGas(receipt.GasUsed) + err = b.multiGasPool.PoolFor(tx.FeeCurrency()).SubGas(gasUsed) // Should never happen as we check it above if err != nil { log.Warn( "Unexpectedly reached limit for fee currency", "hash", tx.Hash(), "gas", b.multiGasPool.PoolFor(tx.FeeCurrency()).Gas(), - "tx gas used", receipt.GasUsed, + "tx gas used", gasUsed, ) return err } From 6434d6d53a0f801fe85a8b71923262ab51e60098 Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Mon, 4 Dec 2023 15:05:18 +0100 Subject: [PATCH 11/12] Changed the default percentage --- cmd/utils/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index f9f7a83557..5d6be25a73 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -424,7 +424,7 @@ var ( CeloFeeCurrencyDefault = cli.Float64Flag{ Name: "celo.feecurrency.default", Usage: "Default fraction of block gas limit available for TXs paid with a whitelisted currency", - Value: 0.9, + Value: 0.5, } CeloFeeCurrencyLimits = cli.StringFlag{ Name: "celo.feecurrency.limits", From 347d8bc00ecb10d876f7d55c4a5084dafb00024d Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Thu, 7 Dec 2023 15:17:05 +0100 Subject: [PATCH 12/12] Made flag description more specific --- cmd/utils/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 5d6be25a73..b0a10908dd 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -423,7 +423,7 @@ var ( } CeloFeeCurrencyDefault = cli.Float64Flag{ Name: "celo.feecurrency.default", - Usage: "Default fraction of block gas limit available for TXs paid with a whitelisted currency", + Usage: "Default fraction of block gas limit available for TXs paid with a whitelisted alternative currency", Value: 0.5, } CeloFeeCurrencyLimits = cli.StringFlag{