Skip to content

Commit

Permalink
Support feynman hardfork (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
blxdyx authored Mar 1, 2024
1 parent 9eaa5c8 commit 6030452
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
30 changes: 29 additions & 1 deletion chain/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type Config struct {
// Mainnet fork scheduling switched from block numbers to timestamps after The Merge
ShanghaiTime *big.Int `json:"shanghaiTime,omitempty"`
KeplerTime *big.Int `json:"keplerTime,omitempty"`
FeynmanTime *big.Int `json:"feynmanTime,omitempty"`
CancunTime *big.Int `json:"cancunTime,omitempty"`
ShardingForkTime *big.Int `json:"shardingForkTime,omitempty"`
PragueTime *big.Int `json:"pragueTime,omitempty"`
Expand Down Expand Up @@ -101,7 +102,7 @@ func (c *Config) String() string {
engine := c.getEngine()

if c.Consensus == ParliaConsensus {
return fmt.Sprintf("{ChainID: %v Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Euler: %v, Gibbs: %v, Nano: %v, Moran: %v, Planck: %v, Luban: %v, Plato: %v, Hertz: %v, Hertzfix: %v, ShanghaiTime: %v, KeplerTime %v, Engine: %v}",
return fmt.Sprintf("{ChainID: %v Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Euler: %v, Gibbs: %v, Nano: %v, Moran: %v, Planck: %v, Luban: %v, Plato: %v, Hertz: %v, Hertzfix: %v, ShanghaiTime: %v, KeplerTime %v, FeynmanTime %v, Engine: %v}",
c.ChainID,
c.RamanujanBlock,
c.NielsBlock,
Expand All @@ -118,6 +119,7 @@ func (c *Config) String() string {
c.HertzfixBlock,
c.ShanghaiTime,
c.KeplerTime,
c.FeynmanTime,
engine,
)
}
Expand Down Expand Up @@ -356,6 +358,14 @@ func (c *Config) IsOnHertz(num *big.Int) bool {
return numEqual(c.HertzBlock, num)
}

func (c *Config) IsHertzfix(num uint64) bool {
return isForked(c.HertzfixBlock, num)
}

func (c *Config) IsOnHertzfix(num uint64) bool {
return isForked(c.HertzfixBlock, num)
}

// IsKepler returns whether time is either equal to the IsKepler fork time or greater.
func (c *Config) IsKepler(num uint64, time uint64) bool {
return c.IsLondon(num) && isForked(c.KeplerTime, time)
Expand All @@ -369,6 +379,20 @@ func (c *Config) IsOnKepler(currentBlockNumber *big.Int, lastBlockTime uint64, c
return !c.IsKepler(lastBlockNumber.Uint64(), lastBlockTime) && c.IsKepler(currentBlockNumber.Uint64(), currentBlockTime)
}

// IsFeynman returns whether time is either equal to the Feynman fork time or greater.
func (c *Config) IsFeynman(num uint64, time uint64) bool {
return c.IsLondon(num) && isForked(c.FeynmanTime, time)
}

// IsOnFeynman returns whether currentBlockTime is either equal to the Feynman fork time or greater firstly.
func (c *Config) IsOnFeynman(currentBlockNumber *big.Int, lastBlockTime uint64, currentBlockTime uint64) bool {
lastBlockNumber := new(big.Int)
if currentBlockNumber.Cmp(big.NewInt(1)) >= 0 {
lastBlockNumber.Sub(currentBlockNumber, big.NewInt(1))
}
return !c.IsFeynman(lastBlockNumber.Uint64(), lastBlockTime) && c.IsFeynman(currentBlockNumber.Uint64(), currentBlockTime)
}

// CheckCompatible checks whether scheduled fork transitions have been imported
// with a mismatching chain configuration.
func (c *Config) CheckCompatible(newcfg *Config, height uint64) *ConfigCompatError {
Expand Down Expand Up @@ -724,6 +748,8 @@ type Rules struct {
IsBerlin, IsLondon, IsShanghai, IsKepler, IsCancun bool
IsSharding, IsPrague bool
IsNano, IsMoran, IsGibbs, IsPlanck, IsLuban, IsPlato, IsHertz bool
IsHertzfix bool
IsFeynman bool
IsEip1559FeeCollector bool
IsParlia, IsAura bool
}
Expand Down Expand Up @@ -755,7 +781,9 @@ func (c *Config) Rules(num uint64, time uint64) *Rules {
IsLuban: c.IsLuban(num),
IsPlato: c.IsPlato(num),
IsHertz: c.IsHertz(num),
IsHertzfix: c.IsHertzfix(num),
IsKepler: c.IsKepler(num, time),
IsFeynman: c.IsFeynman(num, time),
IsEip1559FeeCollector: c.IsEip1559FeeCollector(num),
IsAura: c.Aura != nil,
IsParlia: true,
Expand Down
10 changes: 5 additions & 5 deletions txpool/txpoolcfg/txpoolcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Config struct {
MinFeeCap uint64
AccountSlots uint64 // Number of executable transaction slots guaranteed per account
PriceBump uint64 // Price bump percentage to replace an already existing transaction
OverrideShanghaiTime *big.Int
OverrideFeynmanTime *big.Int
}

var DefaultConfig = Config{
Expand All @@ -31,8 +31,8 @@ var DefaultConfig = Config{
BaseFeeSubPoolLimit: 10_000,
QueuedSubPoolLimit: 10_000,

MinFeeCap: 1,
AccountSlots: 16, //TODO: to choose right value (16 to be compatible with Geth)
PriceBump: 10, // Price bump percentage to replace an already existing transaction
OverrideShanghaiTime: nil,
MinFeeCap: 1,
AccountSlots: 16, //TODO: to choose right value (16 to be compatible with Geth)
PriceBump: 10, // Price bump percentage to replace an already existing transaction
OverrideFeynmanTime: nil,
}
4 changes: 2 additions & 2 deletions txpool/txpooluitl/all_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func AllComponents(ctx context.Context, cfg txpoolcfg.Config, cache kvcache.Cach
chainID, _ := uint256.FromBig(chainConfig.ChainID)

shanghaiTime := chainConfig.ShanghaiTime
if cfg.OverrideShanghaiTime != nil {
shanghaiTime = cfg.OverrideShanghaiTime
if cfg.OverrideFeynmanTime != nil {
shanghaiTime = cfg.OverrideFeynmanTime
}

txPool, err := txpool.New(newTxs, chainDB, cfg, cache, *chainID, shanghaiTime)
Expand Down

0 comments on commit 6030452

Please sign in to comment.