Skip to content

Commit

Permalink
Unify Bor burntContract with Gnosis eip1559FeeCollector (#5798)
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis committed Oct 21, 2022
1 parent 64a3156 commit da354bc
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 50 deletions.
10 changes: 5 additions & 5 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,12 @@ func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (*Executi
} else {
st.state.AddBalance(st.evm.Context().Coinbase, amount)
}
if rules.IsLondon && rules.IsEip1559FeeCollector {
burntContractAddress := *st.evm.ChainConfig().Eip1559FeeCollector
burnAmount := new(uint256.Int).Mul(new(uint256.Int).SetUint64(st.gasUsed()), st.evm.Context().BaseFee)
st.state.AddBalance(burntContractAddress, burnAmount)
}
if st.isBor {
if rules.IsLondon {
burntContractAddress := common.HexToAddress(st.evm.ChainConfig().Bor.CalculateBurntContract(st.evm.Context().BlockNumber))
burnAmount := new(uint256.Int).Mul(new(uint256.Int).SetUint64(st.gasUsed()), st.evm.Context().BaseFee)
st.state.AddBalance(burntContractAddress, burnAmount)
}
// Deprecating transfer log and will be removed in future fork. PLEASE DO NOT USE this transfer log going forward. Parameters won't get updated as expected going forward with EIP1559
// add transfer log
output1 := input1.Clone()
Expand Down
5 changes: 2 additions & 3 deletions params/chainspecs/bor-devnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"muirGlacierBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"eip1559FeeCollectorTransition": 23850000,
"eip1559FeeCollector": "0x70bca57f4579f58670ab2d18ef16e02c17553c38",
"bor": {
"period": {
"0": 5
Expand All @@ -33,9 +35,6 @@
}
}
},
"burntContract": {
"23850000": "0x70bca57f4579f58670ab2d18ef16e02c17553c38"
},
"jaipurBlock": 0
}
}
5 changes: 2 additions & 3 deletions params/chainspecs/bor-mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"muirGlacierBlock": 3395000,
"berlinBlock": 14750000,
"londonBlock": 23850000,
"eip1559FeeCollectorTransition": 23850000,
"eip1559FeeCollector": "0x70bca57f4579f58670ab2d18ef16e02c17553c38",
"bor": {
"period": {
"0": 2
Expand Down Expand Up @@ -44,9 +46,6 @@
}
}
},
"burntContract": {
"23850000": "0x70bca57f4579f58670ab2d18ef16e02c17553c38"
},
"jaipurBlock": 23850000
}
}
2 changes: 2 additions & 0 deletions params/chainspecs/gnosis.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"posdaoBlock": 9186425,
"berlinBlock": 16101500,
"londonBlock": 19040000,
"eip1559FeeCollectorTransition": 19040000,
"eip1559FeeCollector": "0x6BBe78ee9e474842Dbd4AB4987b3CeFE88426A92",
"aura": {
"DBPath": "",
"InMemory": false,
Expand Down
5 changes: 2 additions & 3 deletions params/chainspecs/mumbai.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"muirGlacierBlock": 2722000,
"berlinBlock": 13996000,
"londonBlock": 22640000,
"eip1559FeeCollectorTransition": 22640000,
"eip1559FeeCollector": "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38",
"bor": {
"period": {
"0": 2,
Expand All @@ -36,9 +38,6 @@
}
}
},
"burntContract": {
"22640000": "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38"
},
"jaipurBlock": 22770000
}
}
63 changes: 27 additions & 36 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ type ChainConfig struct {
// Gnosis Chain fork blocks
PosdaoBlock *big.Int `json:"posdaoBlock,omitempty"`

Eip1559FeeCollector *common.Address `json:"eip1559FeeCollector,omitempty"` // (Optional) Address where burnt EIP-1559 fees go to
Eip1559FeeCollectorTransition *big.Int `json:"eip1559FeeCollectorTransition,omitempty"` // (Optional) Block from which burnt EIP-1559 fees go to the Eip1559FeeCollector

// Various consensus engines
Ethash *EthashConfig `json:"ethash,omitempty"`
Clique *CliqueConfig `json:"clique,omitempty"`
Expand Down Expand Up @@ -327,8 +330,7 @@ type BorConfig struct {

OverrideStateSyncRecords map[string]int `json:"overrideStateSyncRecords"` // override state records count
BlockAlloc map[string]interface{} `json:"blockAlloc"`
BurntContract map[string]string `json:"burntContract"` // governance contract where the token will be sent to and burnt in london fork
JaipurBlock uint64 `json:"jaipurBlock"` // Jaipur switch block (nil = no fork, 0 = already on jaipur)
JaipurBlock uint64 `json:"jaipurBlock"` // Jaipur switch block (nil = no fork, 0 = already on jaipur)
}

// String implements the stringer interface, returning the consensus engine details.
Expand Down Expand Up @@ -364,22 +366,6 @@ func (c *BorConfig) calculateBorConfigHelper(field map[string]uint64, number uin
return field[keys[len(keys)-1]]
}

func (c *BorConfig) CalculateBurntContract(number uint64) string {
keys := make([]string, 0, len(c.BurntContract))
for k := range c.BurntContract {
keys = append(keys, k)
}
sort.Strings(keys)
for i := 0; i < len(keys)-1; i++ {
valUint, _ := strconv.ParseUint(keys[i], 10, 64)
valUintNext, _ := strconv.ParseUint(keys[i+1], 10, 64)
if number > valUint && number < valUintNext {
return c.BurntContract[keys[i]]
}
}
return c.BurntContract[keys[len(keys)-1]]
}

// String implements the fmt.Stringer interface.
func (c *ChainConfig) String() string {
var engine interface{}
Expand Down Expand Up @@ -618,6 +604,10 @@ func (c *ChainConfig) IsCancun(num uint64) bool {
return isForked(c.CancunBlock, num)
}

func (c *ChainConfig) IsEip1559FeeCollector(num uint64) bool {
return c.Eip1559FeeCollector != nil && isForked(c.Eip1559FeeCollectorTransition, num)
}

// CheckCompatible checks whether scheduled fork transitions have been imported
// with a mismatching chain configuration.
func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError {
Expand Down Expand Up @@ -843,9 +833,9 @@ type Rules struct {
IsHomestead, IsTangerineWhistle, IsSpuriousDragon bool
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
IsBerlin, IsLondon, IsShanghai, IsCancun bool
IsNano, IsMoran bool
IsEip1559FeeCollector bool
IsParlia, IsStarknet, IsAura bool
IsNano bool
IsMoran bool
}

// Rules ensures c's ChainID is not nil.
Expand All @@ -855,22 +845,23 @@ func (c *ChainConfig) Rules(num uint64) *Rules {
chainID = new(big.Int)
}
return &Rules{
ChainID: new(big.Int).Set(chainID),
IsHomestead: c.IsHomestead(num),
IsTangerineWhistle: c.IsTangerineWhistle(num),
IsSpuriousDragon: c.IsSpuriousDragon(num),
IsByzantium: c.IsByzantium(num),
IsConstantinople: c.IsConstantinople(num),
IsPetersburg: c.IsPetersburg(num),
IsIstanbul: c.IsIstanbul(num),
IsBerlin: c.IsBerlin(num),
IsLondon: c.IsLondon(num),
IsShanghai: c.IsShanghai(num),
IsCancun: c.IsCancun(num),
IsNano: c.IsNano(num),
IsMoran: c.IsMoran(num),
IsParlia: c.Parlia != nil,
IsAura: c.Aura != nil,
ChainID: new(big.Int).Set(chainID),
IsHomestead: c.IsHomestead(num),
IsTangerineWhistle: c.IsTangerineWhistle(num),
IsSpuriousDragon: c.IsSpuriousDragon(num),
IsByzantium: c.IsByzantium(num),
IsConstantinople: c.IsConstantinople(num),
IsPetersburg: c.IsPetersburg(num),
IsIstanbul: c.IsIstanbul(num),
IsBerlin: c.IsBerlin(num),
IsLondon: c.IsLondon(num),
IsShanghai: c.IsShanghai(num),
IsCancun: c.IsCancun(num),
IsNano: c.IsNano(num),
IsMoran: c.IsMoran(num),
IsEip1559FeeCollector: c.IsEip1559FeeCollector(num),
IsParlia: c.Parlia != nil,
IsAura: c.Aura != nil,
}
}

Expand Down

0 comments on commit da354bc

Please sign in to comment.