Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Servicechain tx fee hardfork #2018

Closed
3 changes: 3 additions & 0 deletions blockchain/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
effectiveGasPrice := st.gasPrice
txFee := getBurnAmountMagma(new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveGasPrice))
st.state.AddBalance(st.evm.Context.Rewardbase, txFee)
} else if rules.IsServiceChainTxFee {
effectiveGasPrice := msg.EffectiveGasPrice(nil)
st.state.AddBalance(st.evm.Context.Rewardbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveGasPrice))
} else {
effectiveGasPrice := msg.EffectiveGasPrice(nil)
st.state.AddBalance(st.evm.Context.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveGasPrice))
Expand Down
4 changes: 4 additions & 0 deletions cmd/homi/setup/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ var HomiFlags = []cli.Flag{
altsrc.NewInt64Flag(cancunCompatibleBlockNumberFlag),
altsrc.NewInt64Flag(kip103CompatibleBlockNumberFlag),
altsrc.NewStringFlag(kip103ContractAddressFlag),
altsrc.NewInt64Flag(serviceChainTxFeeCompatibleBlockNumberFlag),
}

var SetupCommand = &cli.Command{
Expand Down Expand Up @@ -687,6 +688,9 @@ func Gen(ctx *cli.Context) error {
genesisJson.Config.Kip103CompatibleBlock = big.NewInt(ctx.Int64(kip103CompatibleBlockNumberFlag.Name))
genesisJson.Config.Kip103ContractAddress = common.HexToAddress(ctx.String(kip103ContractAddressFlag.Name))

// ServiceChainTxFee hardfork is optional
genesisJson.Config.ServiceChainTxFeeCompatibleBlock = big.NewInt(ctx.Int64(serviceChainTxFeeCompatibleBlockNumberFlag.Name))

genesisJsonBytes, _ = json.MarshalIndent(genesisJson, "", " ")
genValidatorKeystore(privKeys)
lastIssuedPortNum = uint16(ctx.Int(p2pPortFlag.Name))
Expand Down
7 changes: 7 additions & 0 deletions cmd/homi/setup/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,11 @@ var (
Usage: "kip103 contract address",
Aliases: []string{"genesis.hardfork.kip103-contract-address"},
}

serviceChainTxFeeCompatibleBlockNumberFlag = &cli.Int64Flag{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the delayed input. The current name appears ambiguous in its purpose. Have you considered renaming it for clarity, perhaps as 'servicechain-consensus-rewardfix'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.
I changes hardfork name to ServiceChainRewardFix in a96d57c
However, I will leave this conversation open to hear the opinions of other reviewers

Name: "servicechaintxfee-compatible-blocknumber",
Usage: "ServiceChainTxFeeCompatible blockNumber",
Value: 0,
Aliases: []string{"genesis.hardfork.servicechaintxfee-compatible-blocknumber"},
}
)
1 change: 1 addition & 0 deletions governance/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ func getChainConfig(governance Engine, num *rpc.BlockNumber) *params.ChainConfig
config.CancunCompatibleBlock = latestConfig.CancunCompatibleBlock
config.Kip103CompatibleBlock = latestConfig.Kip103CompatibleBlock
config.Kip103ContractAddress = latestConfig.Kip103ContractAddress
config.ServiceChainTxFeeCompatibleBlock = latestConfig.ServiceChainTxFeeCompatibleBlock
config.RandaoCompatibleBlock = latestConfig.RandaoCompatibleBlock

return config
Expand Down
17 changes: 17 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ type ChainConfig struct {
RandaoCompatibleBlock *big.Int `json:"randaoCompatibleBlock,omitempty"` // RandaoCompatible activate block (nil = no fork)
RandaoRegistry *RegistryConfig `json:"randaoRegistry,omitempty"` // Registry initial states

// ServiceChainTxFee is an optional hardfork
ServiceChainTxFeeCompatibleBlock *big.Int `json:"serviceChainTxFeeCompatibleBlock,omitempty"` // ServiceChainTxFeeCompatible switch block (nil = no fork, 0 already on)

// Various consensus engines
Gxhash *GxhashConfig `json:"gxhash,omitempty"` // (deprecated) not supported engine
Clique *CliqueConfig `json:"clique,omitempty"`
Expand Down Expand Up @@ -400,6 +403,15 @@ func (c *ChainConfig) IsRandaoForkBlockParent(num *big.Int) bool {
return c.RandaoCompatibleBlock.Cmp(nextNum) == 0 // randao == num + 1
}

// IsServiceChainTxFeeForkEnabled returns whether num is either equal to the ServiceChainTxFee block or greater.
func (c *ChainConfig) IsServiceChainTxFeeForkEnabled(num *big.Int) bool {
if c.ServiceChainTxFeeCompatibleBlock == nil || num == nil {
return false
}

return isForked(c.ServiceChainTxFeeCompatibleBlock, 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 @@ -485,6 +497,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
if isForkIncompatible(c.RandaoCompatibleBlock, newcfg.RandaoCompatibleBlock, head) {
return newCompatError("Randao Block", c.RandaoCompatibleBlock, newcfg.RandaoCompatibleBlock)
}
if isForkIncompatible(c.ServiceChainTxFeeCompatibleBlock, newcfg.ServiceChainTxFeeCompatibleBlock, head) {
return newCompatError("SerivceChainTxFee Block", c.ServiceChainTxFeeCompatibleBlock, newcfg.ServiceChainTxFeeCompatibleBlock)
}
return nil
}

Expand Down Expand Up @@ -606,6 +621,7 @@ type Rules struct {
IsShanghai bool
IsCancun bool
IsRandao bool
IsServiceChainTxFee bool
}

// Rules ensures c's ChainID is not nil.
Expand All @@ -624,6 +640,7 @@ func (c *ChainConfig) Rules(num *big.Int) Rules {
IsShanghai: c.IsShanghaiForkEnabled(num),
IsCancun: c.IsCancunForkEnabled(num),
IsRandao: c.IsRandaoForkEnabled(num),
IsServiceChainTxFee: c.IsServiceChainTxFeeForkEnabled(num),
}
}

Expand Down
7 changes: 6 additions & 1 deletion reward/reward_distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ func GetBlockReward(header *types.Header, rules params.Rules, pset *params.GovPa
spec.Proposer = spec.Proposer.Add(spec.Proposer, txFeeRemained)
spec.TotalFee = spec.TotalFee.Add(spec.TotalFee, txFee)
incrementRewardsMap(spec.Rewards, header.Rewardbase, txFeeRemained)
} else if rules.IsServiceChainTxFee {
txFee := GetTotalTxFee(header, rules, pset)
spec.Proposer = spec.Proposer.Add(spec.Proposer, txFee)
spec.TotalFee = spec.TotalFee.Add(spec.TotalFee, txFee)
incrementRewardsMap(spec.Rewards, header.Rewardbase, txFee)
} else {
txFee := GetTotalTxFee(header, rules, pset)
spec.Proposer = spec.Proposer.Add(spec.Proposer, txFee)
Expand Down Expand Up @@ -261,7 +266,7 @@ func CalcDeferredRewardSimple(header *types.Header, rules params.Rules, pset *pa
// However, the fees must be compensated to calculate actual rewards paid.

// bug-fixed logic after Magma
if !rc.deferredTxFee && rc.rules.IsMagma {
if !rc.deferredTxFee && (rc.rules.IsMagma || rc.rules.IsServiceChainTxFee) {
JayChoi1736 marked this conversation as resolved.
Show resolved Hide resolved
proposer := new(big.Int).Set(minted)
logger.Debug("CalcDeferredRewardSimple after Kore when deferredTxFee=false returns",
"proposer", proposer)
Expand Down
Loading