Skip to content

Commit

Permalink
Merge branch 'develop' into develop-tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
uprendis committed Sep 20, 2023
2 parents 5173adf + 11d2d1c commit d05a7ec
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 23 deletions.
8 changes: 8 additions & 0 deletions cmd/opera/launcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"errors"
"fmt"
"math/big"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -545,6 +546,13 @@ func mayMakeAllConfigs(ctx *cli.Context) (*config, error) {

// Process DBs defaults in the end because they are applied only in absence of config or flags
cfg = setDBConfigDefault(cfg, cacheRatio)
// Sanitize GPO config
if cfg.Opera.GPO.MinGasTip == nil || cfg.Opera.GPO.MinGasTip.Sign() == 0 {
cfg.Opera.GPO.MinGasTip = new(big.Int).SetUint64(cfg.TxPool.PriceLimit)
}
if cfg.Opera.GPO.MinGasTip.Cmp(new(big.Int).SetUint64(cfg.TxPool.PriceLimit)) < 0 {
log.Warn(fmt.Sprintf("GPO minimum gas tip (Opera.GPO.MinGasTip=%s) is lower than txpool minimum gas tip (TxPool.PriceLimit=%d)", cfg.Opera.GPO.MinGasTip.String(), cfg.TxPool.PriceLimit))
}

if err := cfg.Opera.Validate(); err != nil {
return nil, err
Expand Down
30 changes: 25 additions & 5 deletions ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"math/big"
"math/rand"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -99,6 +100,7 @@ type feeHistoryResult struct {
Reward [][]*hexutil.Big `json:"reward,omitempty"`
BaseFee []*hexutil.Big `json:"baseFeePerGas,omitempty"`
GasUsedRatio []float64 `json:"gasUsedRatio"`
Note string `json:"note"`
}

var errInvalidPercentile = errors.New("invalid reward percentile")
Expand Down Expand Up @@ -138,17 +140,35 @@ func (s *PublicEthereumAPI) FeeHistory(ctx context.Context, blockCount rpc.Decim

baseFee := s.b.MinGasPrice()

tips := make([]*hexutil.Big, 0, len(rewardPercentiles))
tips := make([]*big.Int, 0, len(rewardPercentiles))
for _, p := range rewardPercentiles {
tip := s.b.SuggestGasTipCap(ctx, uint64(gasprice.DecimalUnit*p/100.0))
tips = append(tips, (*hexutil.Big)(tip))
tips = append(tips, tip)
}
res.OldestBlock.ToInt().SetUint64(uint64(oldest))
for i := uint64(0); i < uint64(last-oldest+1); i++ {
res.Reward = append(res.Reward, tips)
// randomize the output to mimic the ETH API eth_feeHistory for compatibility reasons
rTips := make([]*hexutil.Big, 0, len(tips))
for _, t := range tips {
rTip := t
// don't randomize last iteration
if i < uint64(last-oldest) {
// increase by up to 2% randomly
rTip = new(big.Int).Mul(t, big.NewInt(int64(rand.Intn(gasprice.DecimalUnit/50)+gasprice.DecimalUnit)))
rTip.Div(rTip, big.NewInt(gasprice.DecimalUnit))
}
rTips = append(rTips, (*hexutil.Big)(rTip))
}
res.Reward = append(res.Reward, rTips)
res.BaseFee = append(res.BaseFee, (*hexutil.Big)(baseFee))
res.GasUsedRatio = append(res.GasUsedRatio, 0.99)
}
r := rand.New(rand.NewSource(int64(oldest) + int64(i)))
res.GasUsedRatio = append(res.GasUsedRatio, 0.9+r.Float64()*0.1)
}
res.Note = `In the FTM network, the eth_feeHistory method operates slightly differently due to the network's unique consensus mechanism. ` +
`Here, instead of returning a range of gas tip values from requested blocks, ` +
`it provides a singular estimated gas tip based on a defined confidence level (indicated by the percentile parameter). ` +
`This approach means that while you will receive replicated (and randomized) reward values across the requested blocks, ` +
`the average or median of these values remains consistent with the intended gas tip.`
return res, nil
}

Expand Down
8 changes: 2 additions & 6 deletions evmcore/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ type TxPoolConfig struct {
Journal string // Journal of local transactions to survive node restarts
Rejournal time.Duration // Time interval to regenerate the local transaction journal

PriceLimit uint64 // Minimum gas price to enforce for acceptance into the pool
PriceLimit uint64 // Minimum gas tip to enforce for acceptance into the pool
PriceBump uint64 // Minimum price bump percentage to replace an already existing transaction (nonce)

AccountSlots uint64 // Number of executable transaction slots guaranteed per account
Expand All @@ -170,7 +170,7 @@ var DefaultTxPoolConfig = TxPoolConfig{
Journal: "transactions.rlp",
Rejournal: time.Hour,

PriceLimit: 1,
PriceLimit: 0,
PriceBump: 10,

AccountSlots: 16,
Expand All @@ -189,10 +189,6 @@ func (config *TxPoolConfig) sanitize() TxPoolConfig {
log.Warn("Sanitizing invalid txpool journal time", "provided", conf.Rejournal, "updated", time.Second)
conf.Rejournal = time.Second
}
if conf.PriceLimit < 1 {
log.Warn("Sanitizing invalid txpool price limit", "provided", conf.PriceLimit, "updated", DefaultTxPoolConfig.PriceLimit)
conf.PriceLimit = DefaultTxPoolConfig.PriceLimit
}
if conf.PriceBump < 1 {
log.Warn("Sanitizing invalid txpool price bump", "provided", conf.PriceBump, "updated", DefaultTxPoolConfig.PriceBump)
conf.PriceBump = DefaultTxPoolConfig.PriceBump
Expand Down
1 change: 1 addition & 0 deletions gossip/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func DefaultConfig(scale cachescale.Func) Config {
GPO: gasprice.Config{
MaxGasPrice: gasprice.DefaultMaxGasPrice,
MinGasPrice: new(big.Int),
MinGasTip: new(big.Int),
DefaultCertainty: 0.5 * gasprice.DecimalUnit,
},

Expand Down
27 changes: 22 additions & 5 deletions gossip/emitter/emitter_llr.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,26 @@ func (em *Emitter) addLlrBlockVotes(e *inter.MutableEventPayload) {
if prevInFile != nil && start < *prevInFile+1 {
start = *prevInFile + 1
}
records := make([]hash.Hash, 0, 16)
records := make([]hash.Hash, 0, basiccheck.MaxBlockVotesPerEvent)
epochEnd := false
var epoch idx.Epoch
for b := start; len(records) < basiccheck.MaxBlockVotesPerEvent; b++ {
record := em.world.GetBlockRecordHash(b)
if record == nil {
break
}
blockEpoch := em.world.GetBlockEpoch(b)
if epoch == 0 {
if !em.isEpochValidator(blockEpoch) {
continue
}
epoch = blockEpoch
start = b
}
if epoch != blockEpoch || blockEpoch == 0 {
epochEnd = true
break
}
record := em.world.GetBlockRecordHash(b)
if record == nil {
break
}
records = append(records, *record)
}

Expand Down Expand Up @@ -73,6 +77,9 @@ func (em *Emitter) addLlrEpochVote(e *inter.MutableEventPayload) {
if prevInFile != nil && target < *prevInFile+1 {
target = *prevInFile + 1
}
if !em.isEpochValidator(target) {
return
}
vote := em.world.GetEpochRecordHash(target)
if vote == nil {
return
Expand Down Expand Up @@ -106,3 +113,13 @@ func (em *Emitter) skipLlrEpochVote() bool {
// otherwise, poor validators have a small chance to vote
return rand.Intn(30) != 0
}

func (em *Emitter) isEpochValidator(epoch idx.Epoch) bool {
es := em.world.GetHistoryEpochState(epoch)
if es == nil {
return false
}

_, ok := es.ValidatorProfiles[em.config.Validator.ID]
return ok
}
15 changes: 15 additions & 0 deletions gossip/emitter/mock/world.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions gossip/emitter/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"

"github.com/Fantom-foundation/go-opera/inter"
"github.com/Fantom-foundation/go-opera/inter/iblockproc"
"github.com/Fantom-foundation/go-opera/opera"
"github.com/Fantom-foundation/go-opera/valkeystore"
"github.com/Fantom-foundation/go-opera/vecmt"
Expand Down Expand Up @@ -69,6 +70,7 @@ type Reader interface {
LlrReader
GetLatestBlockIndex() idx.Block
GetEpochValidators() (*pos.Validators, idx.Epoch)
GetHistoryEpochState(epoch idx.Epoch) *iblockproc.EpochState
GetEvent(hash.Event) *inter.Event
GetEventPayload(hash.Event) *inter.EventPayload
GetLastEvent(epoch idx.Epoch, from idx.ValidatorID) *hash.Event
Expand Down
8 changes: 5 additions & 3 deletions gossip/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
type Config struct {
MaxGasPrice *big.Int `toml:",omitempty"`
MinGasPrice *big.Int `toml:",omitempty"`
MinGasTip *big.Int `toml:",omitempty"`
DefaultCertainty uint64 `toml:",omitempty"`
}

Expand Down Expand Up @@ -107,7 +108,8 @@ func sanitizeBigInt(val, min, max, _default *big.Int, name string) *big.Int {
// gasprice for newly created transaction.
func NewOracle(params Config) *Oracle {
params.MaxGasPrice = sanitizeBigInt(params.MaxGasPrice, nil, nil, DefaultMaxGasPrice, "MaxGasPrice")
params.MinGasPrice = sanitizeBigInt(params.MinGasPrice, nil, nil, new(big.Int), "MinGasPrice")
params.MinGasPrice = sanitizeBigInt(params.MinGasPrice, nil, params.MaxGasPrice, new(big.Int), "MinGasPrice")
params.MinGasTip = sanitizeBigInt(params.MinGasTip, nil, new(big.Int).Sub(params.MaxGasPrice, params.MinGasPrice), new(big.Int), "MinGasTip")
params.DefaultCertainty = sanitizeBigInt(new(big.Int).SetUint64(params.DefaultCertainty), big.NewInt(0), DecimalUnitBn, big.NewInt(DecimalUnit/2), "DefaultCertainty").Uint64()
tCache, _ := lru.New(100)
return &Oracle{
Expand Down Expand Up @@ -148,8 +150,8 @@ func (gpo *Oracle) suggestTip(certainty uint64) *big.Int {
}

tip := new(big.Int).Sub(combined, minPrice)
if tip.Sign() < 0 {
return new(big.Int)
if tip.Cmp(gpo.cfg.MinGasTip) < 0 {
return new(big.Int).Set(gpo.cfg.MinGasTip)
}
return tip
}
Expand Down
8 changes: 4 additions & 4 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
)

func init() {
params.VersionMajor = 1 // Major version component of the current release
params.VersionMinor = 1 // Minor version component of the current release
params.VersionPatch = 3 // Patch version component of the current release
params.VersionMeta = "txtracing-rc.3.1" // Version metadata to append to the version string
params.VersionMajor = 1 // Major version component of the current release
params.VersionMinor = 1 // Minor version component of the current release
params.VersionPatch = 3 // Patch version component of the current release
params.VersionMeta = "txtracing-rc.4" // Version metadata to append to the version string
}

func BigToString(b *big.Int) string {
Expand Down

0 comments on commit d05a7ec

Please sign in to comment.