Skip to content

Commit

Permalink
Fixed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Rodygin committed Nov 6, 2023
1 parent f7e3037 commit 4ce90e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
11 changes: 11 additions & 0 deletions core/sys_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 10 additions & 16 deletions miner/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4ce90e8

Please sign in to comment.