Skip to content

Commit f039053

Browse files
author
eric
committed
The new economic system and support required by the gas fee are added to the contract
1 parent 443e3d8 commit f039053

File tree

9 files changed

+1521
-585
lines changed

9 files changed

+1521
-585
lines changed

consensus/parlia/abi.go

Lines changed: 1123 additions & 538 deletions
Large diffs are not rendered by default.

consensus/parlia/parlia.go

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,12 +1054,15 @@ func (p *Parlia) getCurrentValidators(blockHash common.Hash) ([]common.Address,
10541054
}
10551055
func (p *Parlia) BlockRewards(blockNumber *big.Int) *big.Int {
10561056
if rules := p.chainConfig.Rules(blockNumber); rules.HasBlockRewards {
1057+
if p.chainConfig.Parlia.StopMintBlock.Cmp(blockNumber) >= 0 {
1058+
return big.NewInt(0)
1059+
}
10571060
blockRewards := p.chainConfig.Parlia.BlockRewards
10581061
if blockRewards != nil && blockRewards.Cmp(common.Big0) > 0 {
10591062
return blockRewards
10601063
}
10611064
}
1062-
return nil
1065+
return big.NewInt(0)
10631066
}
10641067

10651068
// slash spoiled validators
@@ -1070,17 +1073,15 @@ func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, he
10701073
state.SetBalance(consensus.SystemAddress, big.NewInt(0))
10711074
state.AddBalance(coinbase, balance)
10721075
rewards := big.NewInt(0).Abs(balance)
1073-
if rules := p.chainConfig.Rules(header.Number); rules.HasBlockRewards {
1074-
blockRewards := p.chainConfig.Parlia.BlockRewards
1075-
// if we have enabled block rewards and rewards are greater than 0 then
1076-
if blockRewards != nil && blockRewards.Cmp(common.Big0) > 0 {
1077-
state.AddBalance(coinbase, blockRewards)
1078-
rewards = rewards.Add(rewards, blockRewards)
1079-
}
1080-
}
1076+
blockRewards := p.BlockRewards(header.Number)
1077+
rewards = rewards.Add(rewards, blockRewards)
10811078
if rewards.Cmp(common.Big0) <= 0 {
10821079
return nil
10831080
}
1081+
if p.chainConfig.IsFncy2(header.Number) {
1082+
1083+
return p.distributeRewards(rewards, blockRewards, balance, val, state, header, chain, txs, receipts, receivedTxs, usedGas, mining)
1084+
}
10841085
// remove 1/16 reward according to netmarble
10851086
//doDistributeSysReward := state.GetBalance(common.HexToAddress(systemcontract.SystemRewardContract)).Cmp(maxSystemBalance) < 0
10861087
//if doDistributeSysReward {
@@ -1160,6 +1161,27 @@ func (p *Parlia) distributeToSystem(amount *big.Int, state *state.StateDB, heade
11601161
return p.applyTransaction(msg, state, header, chain, txs, receipts, receivedTxs, usedGas, mining)
11611162
}
11621163

1164+
// slash spoiled validators
1165+
func (p *Parlia) distributeRewards(amount *big.Int, blockRewards *big.Int, gasFee *big.Int, validator common.Address,
1166+
state *state.StateDB, header *types.Header, chain core.ChainContext,
1167+
txs *[]*types.Transaction, receipts *[]*types.Receipt, receivedTxs *[]*types.Transaction, usedGas *uint64, mining bool) error {
1168+
// method
1169+
method := "distributeRewards"
1170+
1171+
// get packed data
1172+
data, err := p.validatorSetABI.Pack(method,
1173+
validator, blockRewards, gasFee,
1174+
)
1175+
if err != nil {
1176+
log.Error("Unable to pack tx for distributeRewards", "error", err)
1177+
return err
1178+
}
1179+
// get system message
1180+
msg := p.getSystemMessage(header.Coinbase, common.HexToAddress(systemcontract.ValidatorContract), data, amount)
1181+
// apply message
1182+
return p.applyTransaction(msg, state, header, chain, txs, receipts, receivedTxs, usedGas, mining)
1183+
}
1184+
11631185
// slash spoiled validators
11641186
func (p *Parlia) distributeToValidator(amount *big.Int, validator common.Address,
11651187
state *state.StateDB, header *types.Header, chain core.ChainContext,

core/tx_pool.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ type TxPool struct {
253253

254254
gasFreeAddressMap map[common.Address]uint // from address that can join tx_pool for free
255255
gasFreeAddressMapFunc func(common.Hash) (map[common.Address]uint, error) // add func to get gasFreeAddressMap
256+
gasPriceFunc func(common.Hash) (*big.Int, error) // add func to get gas price, do nothing when return 0
256257

257258
pending map[common.Address]*txList // All currently processable transactions
258259
queue map[common.Address]*txList // Queued but non-processable transactions
@@ -283,11 +284,17 @@ func getNoGasFreeAddressMapFunc() func(common.Hash) (map[common.Address]uint, er
283284
return gasFreeToAddressMap, nil
284285
}
285286
}
287+
func getGasPriceFunc() func(common.Hash) (*big.Int, error) {
288+
return func(blockHash common.Hash) (*big.Int, error) {
289+
return big.NewInt(0), nil
290+
}
291+
}
292+
286293
func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain blockChain) *TxPool {
287294

288-
return NewEnhanceTxPool(config, chainconfig, chain, getNoGasFreeAddressMapFunc())
295+
return NewEnhanceTxPool(config, chainconfig, chain, getNoGasFreeAddressMapFunc(), getGasPriceFunc())
289296
}
290-
func NewEnhanceTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain blockChain, gasFreeAddressMapFunc func(common.Hash) (map[common.Address]uint, error)) *TxPool {
297+
func NewEnhanceTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain blockChain, gasFreeAddressMapFunc func(common.Hash) (map[common.Address]uint, error), gasPriceFunc func(common.Hash) (*big.Int, error)) *TxPool {
291298
// Sanitize the input to ensure no vulnerable gas prices are set
292299
config = (&config).sanitize()
293300
// Create the transaction pool with its initial settings
@@ -309,6 +316,7 @@ func NewEnhanceTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chai
309316
gasPrice: new(big.Int).SetUint64(config.PriceLimit),
310317
gasFreeAddressMap: make(map[common.Address]uint),
311318
gasFreeAddressMapFunc: gasFreeAddressMapFunc,
319+
gasPriceFunc: gasPriceFunc,
312320
}
313321
pool.locals = newAccountSet(pool.signer)
314322
for _, addr := range config.Locals {
@@ -1283,7 +1291,16 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
12831291
}
12841292
}
12851293
}
1286-
1294+
gasPrice, err := pool.gasPriceFunc(pool.chain.CurrentBlock().Hash())
1295+
if err != nil {
1296+
log.Warn("Failed to get gasPrice", "err", err)
1297+
} else {
1298+
if gasPrice != nil && gasPrice.Cmp(common.Big0) > 0 {
1299+
if pool.gasPrice.Cmp(gasPrice) != 0 {
1300+
pool.SetGasPrice(gasPrice)
1301+
}
1302+
}
1303+
}
12871304
// Inject any transactions discarded due to reorgs
12881305
log.Debug("Reinjecting stale transactions", "count", len(reinject))
12891306
senderCacher.recover(pool.signer, reinject)

core/vm/evm.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,11 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
515515
ret, err := run(evm, contract, nil, false)
516516

517517
// Check whether the max code size has been exceeded, assign err if the case.
518-
if err == nil && evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSize {
518+
maxCodeSize := params.MaxCodeSize
519+
if evm.chainRules.IsEIP3860 {
520+
maxCodeSize = params.MaxCodeSize * 2
521+
}
522+
if err == nil && evm.chainRules.IsEIP158 && len(ret) > maxCodeSize {
519523
err = ErrMaxCodeSizeExceeded
520524
}
521525

0 commit comments

Comments
 (0)