Skip to content

Commit e34bb9c

Browse files
author
eric
committed
1.dev and self-test the requirement of new economic system
2. fix bug that get gasPrice from contract
1 parent c81fbfa commit e34bb9c

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

consensus/parlia/parlia.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,15 +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 != nil && p.chainConfig.Parlia.StopMintBlock.Cmp(blockNumber) >= 0 {
1058-
return big.NewInt(0)
1057+
if p.chainConfig.Parlia.StopMintBlock != nil && p.chainConfig.Parlia.StopMintBlock.Cmp(blockNumber) <= 0 {
1058+
return nil
10591059
}
10601060
blockRewards := p.chainConfig.Parlia.BlockRewards
10611061
if blockRewards != nil && blockRewards.Cmp(common.Big0) > 0 {
10621062
return blockRewards
10631063
}
10641064
}
1065-
return big.NewInt(0)
1065+
return nil
10661066
}
10671067

10681068
// slash spoiled validators
@@ -1074,7 +1074,7 @@ func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, he
10741074
state.AddBalance(coinbase, balance)
10751075
rewards := big.NewInt(0).Abs(balance)
10761076
blockRewards := p.BlockRewards(header.Number)
1077-
if blockRewards.Cmp(common.Big0) > 0 {
1077+
if blockRewards != nil {
10781078
rewards = rewards.Add(rewards, blockRewards)
10791079
state.AddBalance(coinbase, blockRewards)
10801080
}

core/tx_pool.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,16 +1291,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
12911291
}
12921292
}
12931293
}
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-
}
1294+
13041295
// Inject any transactions discarded due to reorgs
13051296
log.Debug("Reinjecting stale transactions", "count", len(reinject))
13061297
senderCacher.recover(pool.signer, reinject)
@@ -1310,6 +1301,20 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
13101301
next := new(big.Int).Add(newHead.Number, big.NewInt(1))
13111302
pool.istanbul = pool.chainconfig.IsIstanbul(next)
13121303
pool.eip2718 = pool.chainconfig.IsBerlin(next)
1304+
if pool.chainconfig.IsFncy2(next) {
1305+
gasPrice, err := pool.gasPriceFunc(pool.chain.CurrentBlock().Hash())
1306+
if err != nil {
1307+
log.Warn("Failed to get gasPrice", "err", err)
1308+
} else {
1309+
if gasPrice != nil && gasPrice.Cmp(common.Big0) > 0 {
1310+
if pool.gasPrice.Cmp(gasPrice) != 0 {
1311+
log.Debug("Set gasPrice ", " old gasPrice", pool.gasPrice, " new gasPrice", gasPrice)
1312+
pool.SetGasPrice(gasPrice)
1313+
}
1314+
}
1315+
}
1316+
}
1317+
13131318
}
13141319

13151320
// promoteExecutables moves transactions that have become processable from the

eth/backend.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,10 @@ func getCurrentGasPriceFunc(ee *ethapi.PublicBlockChainAPI) func(common.Hash) (*
632632
return nil, err
633633
}
634634
out := big.NewInt(0)
635-
if err := chainConfig.UnpackIntoInterface(out, method, result); err != nil {
635+
if err := chainConfig.UnpackIntoInterface(&out, method, result); err != nil {
636636
return nil, err
637637
}
638638
return out, nil
639-
640639
}
641640
}
642641

eth/tracers/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config
544544
}
545545
if i == len(block.Transactions())-1 && tx.To().Hex() == systemcontract.ValidatorContract {
546546
blockRewards := posa.BlockRewards(block.Header().Number)
547-
if blockRewards.Cmp(common.Big0) > 0 {
547+
if blockRewards != nil {
548548
statedb.AddBalance(vmctx.Coinbase, blockRewards)
549549
}
550550
}
@@ -660,7 +660,7 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
660660
}
661661
if i == len(txs)-1 && tx.To().Hex() == systemcontract.ValidatorContract {
662662
blockRewards := posa.BlockRewards(block.Header().Number)
663-
if blockRewards.Cmp(common.Big0) > 0 {
663+
if blockRewards != nil {
664664
statedb.AddBalance(block.Header().Coinbase, blockRewards)
665665
}
666666
}
@@ -790,7 +790,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
790790
}
791791
if i == len(block.Transactions())-1 && tx.To().Hex() == systemcontract.ValidatorContract {
792792
blockRewards := posa.BlockRewards(block.Header().Number)
793-
if blockRewards.Cmp(common.Big0) > 0 {
793+
if blockRewards != nil {
794794
statedb.AddBalance(vmctx.Coinbase, blockRewards)
795795
}
796796
}
@@ -963,7 +963,7 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex
963963
}
964964
if txctx.TxIndex == txctx.TxCount-1 && message.To().Hex() == systemcontract.ValidatorContract {
965965
blockRewards := posa.BlockRewards(vmctx.BlockNumber)
966-
if blockRewards.Cmp(common.Big0) > 0 {
966+
if blockRewards != nil {
967967
statedb.AddBalance(vmctx.Coinbase, blockRewards)
968968
}
969969
}

internal/ethapi/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ func (s *PublicBlockChainAPI) replay(ctx context.Context, block *types.Block, ac
12361236
}
12371237
if i == len(block.Transactions())-1 && tx.To().Hex() == systemcontract.ValidatorContract {
12381238
blockRewards := posa.BlockRewards(block.Header().Number)
1239-
if blockRewards.Cmp(common.Big0) > 0 {
1239+
if blockRewards != nil {
12401240
statedb.AddBalance(context.Coinbase, blockRewards)
12411241
}
12421242
}

0 commit comments

Comments
 (0)