Skip to content

Commit

Permalink
Allow setting min eip 1559 base fees
Browse files Browse the repository at this point in the history
  • Loading branch information
mycodecrafting committed Apr 30, 2024
1 parent 8b99135 commit c81c88e
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
7 changes: 6 additions & 1 deletion consensus/misc/eip1559/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator()))
baseFee := num.Sub(parent.BaseFee, num)

return math.BigMax(baseFee, common.Big0)
lowerBound := common.Big0
if config.AstriaMinBaseFees != nil {
lowerBound = config.AstriaMinBaseFees.ValueAt(parent.Number.Uint64() + 1)
}

return math.BigMax(baseFee, lowerBound)
}
}
5 changes: 4 additions & 1 deletion genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
"astriaCelestiaInitialHeight": 2,
"astriaCelestiaHeightVariance": 10,
"astriaBridgeAddresses": [],
"astriaBridgeAllowedAssetDenom": "nria"
"astriaBridgeAllowedAssetDenom": "nria",
"astriaMinBaseFees": {
"1": "1000000000"
}
},
"difficulty": "10000000",
"gasLimit": "8000000",
Expand Down
67 changes: 67 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package params

import (
"encoding/json"
"fmt"
"math/big"
"sort"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -345,6 +347,7 @@ type ChainConfig struct {
AstriaCelestiaHeightVariance uint32 `json:"astriaCelestiaHeightVariance,omitempty"`
AstriaBridgeAddresses []hexutil.Bytes `json:"astriaBridgeAddresses,omitempty"`
AstriaBridgeAllowedAssetDenom string `json:"astriaBridgeAllowedAssetDenom,omitempty"`
AstriaMinBaseFees *BaseFeeConfig `json:"astriaMinBaseFees,omitempty"`
}

func (c *ChainConfig) AstriaExtraData() []byte {
Expand All @@ -368,6 +371,70 @@ func (c *ChainConfig) AstriaExtraData() []byte {
return extra
}

type BaseFeeConfig struct {
heights map[uint64]*big.Int
current *big.Int
initialized bool
}

func (c *BaseFeeConfig) ValueAt(height uint64) *big.Int {
c.init()
if value, exists := c.heights[height]; exists {
return value
}
return c.current
}

func (c *BaseFeeConfig) init() {
if c.initialized {
return
}

if len(c.heights) < 1 {
return
}

heights := []uint64{}
for k := range c.heights {
heights = append(heights, k)
}

sort.Slice(heights, func(i, j int) bool { return heights[i] < heights[j] })

c.current = big.NewInt(0)
lastHeight := heights[len(heights)-1]

for i := uint64(0); i <= lastHeight; i++ {
if _, exists := c.heights[i]; exists {
c.current = c.heights[i]
} else {
c.heights[i] = c.current
}
}

c.initialized = true
}

func (c BaseFeeConfig) MarshalJSON() ([]byte, error) {
distinctHeights := make(map[uint64]*big.Int)
for k, v := range c.heights {
if _, exists := distinctHeights[k]; !exists {
distinctHeights[k] = v
}
}
return json.Marshal(distinctHeights)
}

func (c *BaseFeeConfig) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &c.heights); err != nil {
return err
}

c.init()

return nil
}

// EthashConfig is the consensus engine configs for proof-of-work based sealing.
type EthashConfig struct{}

Expand Down

0 comments on commit c81c88e

Please sign in to comment.